Skip to content

Commit ab1d244

Browse files
committed
Auto merge of #147838 - matthiaskrgr:rollup-r8r148d, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #140153 (Implement `Debug` for `EncodeWide`) - #145724 (the `#[track_caller]` shim should not inherit `#[no_mangle]`) - #147258 (iter repeat: panic on last) - #147454 (Fix backtraces with `-C panic=abort` on qnx; emit unwind tables by default) - #147468 (Implement fs api set_times and set_times_nofollow) - #147764 (Undo CopyForDeref assertion in const qualif) - #147805 (use module_child index as disambiguator for external items) - #147824 (docs: update Motor OS target docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 32892a3 + 706f5fb commit ab1d244

29 files changed

Lines changed: 729 additions & 90 deletions

File tree

‎compiler/rustc_codegen_cranelift/src/abi/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
467467
true
468468
}else{
469469
instance.is_some_and(|inst| {
470-
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
470+
fx.tcx.codegen_instance_attrs(inst.def).flags.contains(CodegenFnAttrFlags::COLD)
471471
})
472472
};
473473
if is_cold {

‎compiler/rustc_codegen_ssa/src/mir/block.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
200200
let fn_ty = bx.fn_decl_backend_type(fn_abi);
201201

202202
let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs(){
203-
Some(bx.tcx().codegen_fn_attrs(fx.instance.def_id()))
203+
Some(bx.tcx().codegen_instance_attrs(fx.instance.def))
204204
}else{
205205
None
206206
};
207+
let fn_attrs = fn_attrs.as_deref();
207208

208209
if !fn_abi.can_unwind{
209210
unwind = mir::UnwindAction::Unreachable;

‎compiler/rustc_const_eval/src/check_consts/qualifs.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ where
234234

235235
Rvalue::Discriminant(place) => in_place::<Q,_>(cx, in_local, place.as_ref()),
236236

237-
Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in runtime MIR"),
237+
Rvalue::CopyForDeref(place) => in_place::<Q,_>(cx, in_local, place.as_ref()),
238238

239239
Rvalue::Use(operand)
240240
| Rvalue::Repeat(operand, _)

‎compiler/rustc_middle/src/middle/codegen_fn_attrs.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ impl<'tcx> TyCtxt<'tcx> {
1313
self,
1414
instance_kind:InstanceKind<'_>,
1515
) -> Cow<'tcx,CodegenFnAttrs>{
16+
// NOTE: we try to not clone the `CodegenFnAttrs` when that is not needed.
17+
// The `to_mut` method used below clones the inner value.
1618
letmut attrs = Cow::Borrowed(self.codegen_fn_attrs(instance_kind.def_id()));
1719

1820
// Drop the `#[naked]` attribute on non-item `InstanceKind`s, like the shims that
@@ -23,6 +25,28 @@ impl<'tcx> TyCtxt<'tcx> {
2325
}
2426
}
2527

28+
// A shim created by `#[track_caller]` should not inherit any attributes
29+
// that modify the symbol name. Failing to remove these attributes from
30+
// the shim leads to errors like `symbol `foo` is already defined`.
31+
//
32+
// A `ClosureOnceShim` with the track_caller attribute does not have a symbol,
33+
// and therefore can be skipped here.
34+
ifletInstanceKind::ReifyShim(_, _) = instance_kind
35+
&& attrs.flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
36+
{
37+
if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE){
38+
attrs.to_mut().flags.remove(CodegenFnAttrFlags::NO_MANGLE);
39+
}
40+
41+
if attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL){
42+
attrs.to_mut().flags.remove(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
43+
}
44+
45+
if attrs.symbol_name.is_some(){
46+
attrs.to_mut().symbol_name = None;
47+
}
48+
}
49+
2650
attrs
2751
}
2852
}

‎compiler/rustc_mir_transform/src/inline.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
245245
fnon_inline_failure(&self,callsite:&CallSite<'tcx>,reason:&'staticstr){
246246
let tcx = self.tcx();
247247
letInlineAttr::Force{ attr_span,reason: justification } =
248-
tcx.codegen_fn_attrs(callsite.callee.def_id()).inline
248+
tcx.codegen_instance_attrs(callsite.callee.def).inline
249249
else{
250250
bug!("called on item without required inlining");
251251
};
@@ -603,7 +603,8 @@ fn try_inlining<'tcx, I: Inliner<'tcx>>(
603603
let tcx = inliner.tcx();
604604
check_mir_is_available(inliner, caller_body, callsite.callee)?;
605605

606-
let callee_attrs = tcx.codegen_fn_attrs(callsite.callee.def_id());
606+
let callee_attrs = tcx.codegen_instance_attrs(callsite.callee.def);
607+
let callee_attrs = callee_attrs.as_ref();
607608
check_inline::is_inline_valid_on_fn(tcx, callsite.callee.def_id())?;
608609
check_codegen_attributes(inliner, callsite, callee_attrs)?;
609610
inliner.check_codegen_attributes_extra(callee_attrs)?;

‎compiler/rustc_resolve/src/build_reduced_graph.rs‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
7777
parent:Module<'ra>,
7878
ident:Ident,
7979
ns:Namespace,
80+
child_index:usize,
8081
res:Res,
8182
vis:Visibility<DefId>,
8283
span:Span,
@@ -86,10 +87,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8687
// Even if underscore names cannot be looked up, we still need to add them to modules,
8788
// because they can be fetched by glob imports from those modules, and bring traits
8889
// into scope both directly and through glob imports.
89-
let key = BindingKey::new_disambiguated(ident, ns, || {
90-
parent.underscore_disambiguator.update_unchecked(|d| d + 1);
91-
parent.underscore_disambiguator.get()
92-
});
90+
let key =
91+
BindingKey::new_disambiguated(ident, ns, || (child_index + 1).try_into().unwrap());// 0 indicates no underscore
9392
ifself
9493
.resolution_or_default(parent, key)
9594
.borrow_mut_unchecked()
@@ -233,9 +232,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
233232
}
234233

235234
pub(crate)fnbuild_reduced_graph_external(&self,module:Module<'ra>){
236-
for child inself.tcx.module_children(module.def_id()){
235+
for(i,child)inself.tcx.module_children(module.def_id()).into_iter().enumerate(){
237236
let parent_scope = ParentScope::module(module,self.arenas);
238-
self.build_reduced_graph_for_external_crate_res(child, parent_scope)
237+
self.build_reduced_graph_for_external_crate_res(child, parent_scope, i)
239238
}
240239
}
241240

@@ -244,6 +243,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
244243
&self,
245244
child:&ModChild,
246245
parent_scope:ParentScope<'ra>,
246+
child_index:usize,
247247
){
248248
let parent = parent_scope.module;
249249
letModChild{ ident, res, vis,ref reexport_chain } = *child;
@@ -272,7 +272,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
272272
_,
273273
)
274274
| Res::PrimTy(..)
275-
| Res::ToolMod => self.define_extern(parent, ident,TypeNS, res, vis, span, expansion),
275+
| Res::ToolMod => {
276+
self.define_extern(parent, ident,TypeNS, child_index, res, vis, span, expansion)
277+
}
276278
Res::Def(
277279
DefKind::Fn
278280
| DefKind::AssocFn
@@ -281,9 +283,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
281283
| DefKind::AssocConst
282284
| DefKind::Ctor(..),
283285
_,
284-
) => self.define_extern(parent, ident,ValueNS, res, vis, span, expansion),
286+
) => self.define_extern(parent, ident,ValueNS,child_index,res, vis, span, expansion),
285287
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
286-
self.define_extern(parent, ident,MacroNS, res, vis, span, expansion)
288+
self.define_extern(parent, ident,MacroNS,child_index,res, vis, span, expansion)
287289
}
288290
Res::Def(
289291
DefKind::TyParam

‎compiler/rustc_target/src/spec/base/nto_qnx.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub(crate) fn opts() -> TargetOptions {
1212
has_thread_local:false,
1313
linker:Some("qcc".into()),
1414
os:"nto".into(),
15+
// We want backtraces to work by default and they rely on unwind tables
16+
// (regardless of `-C panic` strategy).
17+
default_uwtable:true,
1518
position_independent_executables:true,
1619
static_position_independent_executables:true,
1720
relro_level:RelroLevel::Full,

‎library/alloc/src/wtf8/tests.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,17 @@ fn wtf8_encode_wide_size_hint() {
579579
assert!(iter.next().is_none());
580580
}
581581

582+
#[test]
583+
fnwtf8_encode_wide_debug(){
584+
letmut string = Wtf8Buf::from_str("aé ");
585+
string.push(CodePoint::from_u32(0xD83D).unwrap());
586+
string.push_char('💩');
587+
assert_eq!(
588+
format!("{:?}", string.encode_wide()),
589+
r#"EncodeWide(['a', 'é', ' ', 0xD83D, 0xD83D, 0xDCA9])"#
590+
);
591+
}
592+
582593
#[test]
583594
fnwtf8_clone_into(){
584595
letmut string = Wtf8Buf::new();

‎library/core/src/iter/sources/repeat.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ impl<A: Clone> Iterator for Repeat<A> {
101101
Some(self.element.clone())
102102
}
103103

104+
#[track_caller]
104105
fnlast(self) -> Option<A>{
105-
Some(self.element)
106+
panic!("iterator is infinite");
106107
}
107108

108109
#[track_caller]

‎library/core/src/wtf8.rs‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,36 @@ impl Iterator for EncodeWide<'_> {
562562
}
563563
}
564564

565+
#[stable(feature = "encode_wide_fused_iterator", since = "1.62.0")]
566+
implFusedIteratorforEncodeWide<'_>{}
567+
568+
#[stable(feature = "encode_wide_debug", since = "CURRENT_RUSTC_VERSION")]
565569
impl fmt::DebugforEncodeWide<'_>{
566570
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
567-
f.debug_struct("EncodeWide").finish_non_exhaustive()
571+
structCodeUnit(u16);
572+
impl fmt::DebugforCodeUnit{
573+
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
574+
// This output attempts to balance readability with precision.
575+
// Render characters which take only one WTF-16 code unit using
576+
// `char` syntax and everything else as code units with hex
577+
// integer syntax (including paired and unpaired surrogate
578+
// halves). Since Rust has no `char`-like type for WTF-16, this
579+
// isn't perfect, so if this output isn't suitable, it is open
580+
// to being changed (see #140153).
581+
match char::from_u32(self.0asu32){
582+
Some(c) => write!(f,"{c:?}"),
583+
None => write!(f,"0x{:04X}",self.0),
584+
}
585+
}
586+
}
587+
588+
write!(f,"EncodeWide(")?;
589+
f.debug_list().entries(self.clone().map(CodeUnit)).finish()?;
590+
write!(f,")")?;
591+
Ok(())
568592
}
569593
}
570594

571-
#[stable(feature = "encode_wide_fused_iterator", since = "1.62.0")]
572-
implFusedIteratorforEncodeWide<'_>{}
573-
574595
implHashforCodePoint{
575596
#[inline]
576597
fnhash<H:Hasher>(&self,state:&mutH){

0 commit comments

Comments
 (0)