Skip to content

Commit 7c61a35

Browse files
committed
Auto merge of #155745 - JonathanBrouwer:rollup-D6OSAOt, r=JonathanBrouwer
Rollup of 12 pull requests Successful merges: - #149452 (Refactor out common code into a `IndexItem::new` constructor) - #155621 (Document #[diagnostic::on_move] in the unstable book.) - #155635 (delegation: rename `Self` generic param to `This` in recursive delegations) - #155730 (Some cleanups around per parent disambiguators) - #153537 (rustc_codegen_ssa: Define ELF flag value for sparc-unknown-linux-gnu) - #155219 (Do not suggest borrowing enclosing calls for nested where-clause obligations) - #155408 (rustdoc: Fix Managarm C Library name in cfg pretty printer) - #155571 (Enable AddressSanitizer on arm-unknown-linux-gnueabihf and armv7-unknown-linux-gnueabihf) - #155713 (test: Add a regression test for Apple platforms aborting on `free`) - #155723 (Fix tier level for 5 thumb bare-metal ARM targets) - #155735 (Fix typo by removing extra 'to') - #155736 (Remove `AllVariants` workaround for rust-analyzer)
2 parents acb65f3 + 2a885bb commit 7c61a35

35 files changed

Lines changed: 660 additions & 160 deletions

File tree

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
508508

509509
// FIXME(fn_delegation): proper support for parent generics propagation
510510
// in method call scenario.
511-
let segment = self.process_segment(span, &segment, &mut generics.child, false);
511+
let segment = self.process_segment(span, &segment, &mut generics.child);
512512
let segment = self.arena.alloc(segment);
513513

514514
self.arena.alloc(hir::Expr {
@@ -534,14 +534,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
534534

535535
new_path.segments = self.arena.alloc_from_iter(
536536
new_path.segments.iter().enumerate().map(|(idx, segment)| {
537-
let mut process_segment = |result, add_lifetimes| {
538-
self.process_segment(span, segment, result, add_lifetimes)
539-
};
540-
541537
if idx + 2 == len {
542-
process_segment(&mut generics.parent, true)
538+
self.process_segment(span, segment, &mut generics.parent)
543539
} else if idx + 1 == len {
544-
process_segment(&mut generics.child, false)
540+
self.process_segment(span, segment, &mut generics.child)
545541
} else {
546542
segment.clone()
547543
}
@@ -551,7 +547,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
551547
hir::QPath::Resolved(ty, self.arena.alloc(new_path))
552548
}
553549
hir::QPath::TypeRelative(ty, segment) => {
554-
let segment = self.process_segment(span, segment, &mut generics.child, false);
550+
let segment = self.process_segment(span, segment, &mut generics.child);
555551

556552
hir::QPath::TypeRelative(ty, self.arena.alloc(segment))
557553
}
@@ -584,13 +580,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
584580
span: Span,
585581
segment: &hir::PathSegment<'hir>,
586582
result: &mut GenericsGenerationResult<'hir>,
587-
add_lifetimes: bool,
588583
) -> hir::PathSegment<'hir> {
589584
let details = result.generics.args_propagation_details();
590585

591586
let segment = if details.should_propagate {
592587
let generics = result.generics.into_hir_generics(self, span);
593-
let args = generics.into_generic_args(self, add_lifetimes, span);
588+
let args = generics.into_generic_args(self, span);
594589

595590
// Needed for better error messages (`trait-impl-wrong-args-count.rs` test).
596591
let args = if args.is_empty() { None } else { Some(args) };

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def_id::DefId;
66
use rustc_middle::ty::GenericParamDefKind;
77
use rustc_middle::{bug, ty};
88
use rustc_span::symbol::kw;
9-
use rustc_span::{Ident, Span};
9+
use rustc_span::{Ident, Span, sym};
1010

1111
use crate::{LoweringContext, ResolverAstLoweringExt};
1212

@@ -25,22 +25,37 @@ pub(super) enum DelegationGenericsKind {
2525
TraitImpl(bool /* Has user-specified args */),
2626
}
2727

28+
#[derive(Debug, Clone, Copy)]
29+
pub(super) enum GenericsPosition {
30+
Parent,
31+
Child,
32+
}
33+
2834
pub(super) struct DelegationGenerics<T> {
2935
generics: T,
3036
kind: DelegationGenericsKind,
37+
pos: GenericsPosition,
3138
}
3239

3340
impl<'hir> DelegationGenerics<&'hir [ty::GenericParamDef]> {
34-
fn default(generics: &'hir [ty::GenericParamDef]) -> Self {
35-
DelegationGenerics { generics, kind: DelegationGenericsKind::Default }
41+
fn default(generics: &'hir [ty::GenericParamDef], pos: GenericsPosition) -> Self {
42+
DelegationGenerics { generics, pos, kind: DelegationGenericsKind::Default }
3643
}
3744

38-
fn user_specified(generics: &'hir [ty::GenericParamDef]) -> Self {
39-
DelegationGenerics { generics, kind: DelegationGenericsKind::UserSpecified }
45+
fn user_specified(generics: &'hir [ty::GenericParamDef], pos: GenericsPosition) -> Self {
46+
DelegationGenerics { generics, pos, kind: DelegationGenericsKind::UserSpecified }
4047
}
4148

42-
fn trait_impl(generics: &'hir [ty::GenericParamDef], user_specified: bool) -> Self {
43-
DelegationGenerics { generics, kind: DelegationGenericsKind::TraitImpl(user_specified) }
49+
fn trait_impl(
50+
generics: &'hir [ty::GenericParamDef],
51+
user_specified: bool,
52+
pos: GenericsPosition,
53+
) -> Self {
54+
DelegationGenerics {
55+
generics,
56+
pos,
57+
kind: DelegationGenericsKind::TraitImpl(user_specified),
58+
}
4459
}
4560
}
4661

@@ -103,8 +118,14 @@ impl<'hir> HirOrTyGenerics<'hir> {
103118
span: Span,
104119
) -> &mut HirOrTyGenerics<'hir> {
105120
if let HirOrTyGenerics::Ty(ty) = self {
106-
let params = ctx.uplift_delegation_generic_params(span, ty.generics);
107-
*self = HirOrTyGenerics::Hir(DelegationGenerics { generics: params, kind: ty.kind });
121+
let rename_self = matches!(ty.pos, GenericsPosition::Child);
122+
let params = ctx.uplift_delegation_generic_params(span, ty.generics, rename_self);
123+
124+
*self = HirOrTyGenerics::Hir(DelegationGenerics {
125+
generics: params,
126+
kind: ty.kind,
127+
pos: ty.pos,
128+
});
108129
}
109130

110131
self
@@ -120,14 +141,14 @@ impl<'hir> HirOrTyGenerics<'hir> {
120141
pub(super) fn into_generic_args(
121142
&self,
122143
ctx: &mut LoweringContext<'_, 'hir, impl ResolverAstLoweringExt<'hir>>,
123-
add_lifetimes: bool,
124144
span: Span,
125145
) -> &'hir hir::GenericArgs<'hir> {
126146
match self {
127147
HirOrTyGenerics::Ty(_) => {
128148
bug!("Attempting to get generic args before uplifting to HIR")
129149
}
130150
HirOrTyGenerics::Hir(hir) => {
151+
let add_lifetimes = matches!(hir.pos, GenericsPosition::Parent);
131152
ctx.create_generics_args_from_params(hir.generics.params, add_lifetimes, span)
132153
}
133154
}
@@ -227,10 +248,15 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
227248
if matches!(delegation_parent_kind, DefKind::Impl { of_trait: true }) {
228249
// Considering parent generics, during signature inheritance
229250
// we will take those args that are in trait impl header trait ref.
230-
let parent = DelegationGenerics::trait_impl(&[], true);
251+
let parent = DelegationGenerics::trait_impl(&[], true, GenericsPosition::Parent);
231252
let parent = GenericsGenerationResult::new(parent);
232253

233-
let child = DelegationGenerics::trait_impl(sig_params, child_user_specified);
254+
let child = DelegationGenerics::trait_impl(
255+
sig_params,
256+
child_user_specified,
257+
GenericsPosition::Child,
258+
);
259+
234260
let child = GenericsGenerationResult::new(child);
235261

236262
return GenericsGenerationResults {
@@ -263,25 +289,32 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
263289
DelegationGenerics {
264290
kind: DelegationGenericsKind::SelfAndUserSpecified,
265291
generics: &sig_parent_params[..1],
292+
pos: GenericsPosition::Parent,
266293
}
267294
} else {
268-
DelegationGenerics::user_specified(&[])
295+
DelegationGenerics::user_specified(&[], GenericsPosition::Parent)
269296
}
270297
} else {
271298
let skip_self = usize::from(!generate_self);
272-
DelegationGenerics::default(&sig_parent_params[skip_self..])
299+
DelegationGenerics::default(
300+
&sig_parent_params[skip_self..],
301+
GenericsPosition::Parent,
302+
)
273303
}
274304
} else {
275-
DelegationGenerics::default(&[])
305+
DelegationGenerics::default(&[], GenericsPosition::Parent)
276306
};
277307

278308
let child_generics = if child_user_specified {
279309
let synth_params_index =
280310
sig_params.iter().position(|p| p.kind.is_synthetic()).unwrap_or(sig_params.len());
281311

282-
DelegationGenerics::user_specified(&sig_params[synth_params_index..])
312+
DelegationGenerics::user_specified(
313+
&sig_params[synth_params_index..],
314+
GenericsPosition::Child,
315+
)
283316
} else {
284-
DelegationGenerics::default(sig_params)
317+
DelegationGenerics::default(sig_params, GenericsPosition::Child)
285318
};
286319

287320
GenericsGenerationResults {
@@ -296,6 +329,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
296329
&mut self,
297330
span: Span,
298331
params: &'hir [ty::GenericParamDef],
332+
rename_self: bool,
299333
) -> &'hir hir::Generics<'hir> {
300334
let params = self.arena.alloc_from_iter(params.iter().map(|p| {
301335
let def_kind = match p.kind {
@@ -304,7 +338,20 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
304338
GenericParamDefKind::Const { .. } => DefKind::ConstParam,
305339
};
306340

307-
let param_ident = Ident::new(p.name, span);
341+
// Rename Self generic param to This so it is properly propagated.
342+
// If the user will create a function `fn foo<Self>() {}` with generic
343+
// param "Self" then it will not be generated in HIR, the same thing
344+
// applies to traits, `trait Trait<Self> {}` will be represented as
345+
// `trait Trait {}` in HIR and "unexpected keyword `Self` in generic parameters"
346+
// error will be emitted.
347+
// Note that we do not rename `Self` to `This` after non-recursive reuse
348+
// from Trait, in this case the `Self` should not be propagated
349+
// (we rely that implicit `Self` generic param of a trait is named "Self")
350+
// and it is OK to have Self generic param generated during lowering.
351+
let param_name =
352+
if rename_self && p.name == kw::SelfUpper { sym::This } else { p.name };
353+
354+
let param_ident = Ident::new(param_name, span);
308355
let def_name = Some(param_ident.name);
309356
let node_id = self.next_node_id();
310357

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
396396
_ => EF_PPC64_ABI_UNKNOWN,
397397
}
398398
}
399+
Architecture::Sparc32Plus => elf::EF_SPARC_32PLUS,
399400
_ => 0,
400401
}
401402
}

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
use hir::def::DefKind;
1717
use rustc_ast::Mutability;
1818
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
19-
use rustc_hir::def_id::LocalDefIdMap;
20-
use rustc_hir::definitions::{
21-
DefPathData, PerParentDisambiguatorState, PerParentDisambiguatorsMap,
22-
};
19+
use rustc_hir::definitions::{DefPathData, PerParentDisambiguatorState};
2320
use rustc_hir::{self as hir};
2421
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2522
use rustc_middle::mir::interpret::{
@@ -108,7 +105,7 @@ fn intern_shallow<'tcx, M: CompileTimeMachine<'tcx>>(
108105
ecx: &mut InterpCx<'tcx, M>,
109106
alloc_id: AllocId,
110107
mutability: Mutability,
111-
disambiguators: Option<&mut LocalDefIdMap<PerParentDisambiguatorState>>,
108+
disambiguator: Option<&mut PerParentDisambiguatorState>,
112109
) -> Result<impl Iterator<Item = CtfeProvenance> + 'tcx, InternError> {
113110
trace!("intern_shallow {:?}", alloc_id);
114111
// remove allocation
@@ -132,7 +129,7 @@ fn intern_shallow<'tcx, M: CompileTimeMachine<'tcx>>(
132129
static_id,
133130
alloc_id,
134131
alloc,
135-
disambiguators.expect("disambiguators needed"),
132+
disambiguator.expect("disambiguator needed"),
136133
);
137134
} else {
138135
ecx.tcx.set_alloc_id_memory(alloc_id, alloc);
@@ -147,19 +144,18 @@ fn intern_as_new_static<'tcx>(
147144
static_id: LocalDefId,
148145
alloc_id: AllocId,
149146
alloc: ConstAllocation<'tcx>,
150-
disambiguators: &mut LocalDefIdMap<PerParentDisambiguatorState>,
147+
disambiguator: &mut PerParentDisambiguatorState,
151148
) {
152-
// `intern_const_alloc_recursive` is called once per static and it contains the `DisambiguatorState`.
149+
// `intern_const_alloc_recursive` is called once per static and it contains the `PerParentDisambiguatorState`.
153150
// The `<static_id>::{{nested}}` path is thus unique to `intern_const_alloc_recursive` and the
154-
// `DisambiguatorState` ensures the generated path is unique for this call as we generate
151+
// `PerParentDisambiguatorState` ensures the generated path is unique for this call as we generate
155152
// `<static_id>::{{nested#n}}` where `n` is the `n`th `intern_as_new_static` call.
156153
let feed = tcx.create_def(
157154
static_id,
158155
None,
159156
DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
160157
Some(DefPathData::NestedStatic),
161-
//FIXME(oli-obk): cleanup (https://github.com/rust-lang/rust/pull/155547#discussion_r3110792640)
162-
disambiguators.get_or_create(static_id),
158+
disambiguator,
163159
);
164160
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
165161

@@ -209,7 +205,9 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx>>(
209205
intern_kind: InternKind,
210206
ret: &MPlaceTy<'tcx>,
211207
) -> Result<(), InternError> {
212-
let mut disambiguators = Default::default();
208+
let mut disambiguator =
209+
ecx.machine.static_def_id().map(|id| PerParentDisambiguatorState::new(id));
210+
let mut disambiguator = disambiguator.as_mut();
213211

214212
// We are interning recursively, and for mutability we are distinguishing the "root" allocation
215213
// that we are starting in, and all other allocations that we are encountering recursively.
@@ -248,13 +246,15 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx>>(
248246
// This gives us the initial set of nested allocations, which will then all be processed
249247
// recursively in the loop below.
250248
let mut todo: Vec<_> = if is_static {
249+
assert!(disambiguator.is_some());
251250
// Do not steal the root allocation, we need it later to create the return value of `eval_static_initializer`.
252251
// But still change its mutability to match the requested one.
253252
let (kind, alloc) = ecx.memory.alloc_map.get_mut(&base_alloc_id).unwrap();
254253
prepare_alloc(*ecx.tcx, *kind, alloc, base_mutability)?;
255254
alloc.provenance().ptrs().iter().map(|&(_, prov)| prov).collect()
256255
} else {
257-
intern_shallow(ecx, base_alloc_id, base_mutability, Some(&mut disambiguators))?.collect()
256+
assert!(disambiguator.is_none());
257+
intern_shallow(ecx, base_alloc_id, base_mutability, None)?.collect()
258258
};
259259
// We need to distinguish "has just been interned" from "was already in `tcx`",
260260
// so we track this in a separate set.
@@ -336,7 +336,7 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx>>(
336336
// okay with losing some potential for immutability here. This can anyway only affect
337337
// `static mut`.
338338
just_interned.insert(alloc_id);
339-
let next = intern_shallow(ecx, alloc_id, inner_mutability, Some(&mut disambiguators))?;
339+
let next = intern_shallow(ecx, alloc_id, inner_mutability, disambiguator.as_deref_mut())?;
340340
todo.extend(next);
341341
}
342342
if found_bad_mutable_ptr {

compiler/rustc_session/src/config/print_request.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ pub enum PrintKind {
5050
}
5151

5252
impl PrintKind {
53-
/// FIXME: rust-analyzer doesn't support `#![feature(macro_derive)]` yet
54-
/// (<https://github.com/rust-lang/rust-analyzer/issues/21043>), which breaks autocomplete.
55-
/// Work around that by aliasing the trait constant to a regular constant.
56-
const ALL_VARIANTS: &[Self] = <Self as AllVariants>::ALL_VARIANTS;
57-
5853
fn name(self) -> &'static str {
5954
use PrintKind::*;
6055
match self {

compiler/rustc_target/src/spec/targets/arm_unknown_linux_gnueabihf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::spec::{Arch, CfgAbi, FloatAbi, Target, TargetMetadata, TargetOptions, base};
1+
use crate::spec::{
2+
Arch, CfgAbi, FloatAbi, SanitizerSet, Target, TargetMetadata, TargetOptions, base,
3+
};
24

35
pub(crate) fn target() -> Target {
46
Target {
@@ -24,6 +26,7 @@ pub(crate) fn target() -> Target {
2426
// linker error, so set it to `true` here.
2527
// FIXME(#146996): Remove this override once #146996 has been fixed.
2628
default_uwtable: false,
29+
supported_sanitizers: SanitizerSet::ADDRESS,
2730
..base::linux_gnu::opts()
2831
},
2932
}

compiler/rustc_target/src/spec/targets/armv7_unknown_linux_gnueabihf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::spec::{Arch, CfgAbi, FloatAbi, Target, TargetMetadata, TargetOptions, base};
1+
use crate::spec::{
2+
Arch, CfgAbi, FloatAbi, SanitizerSet, Target, TargetMetadata, TargetOptions, base,
3+
};
24

35
// This target is for glibc Linux on ARMv7 without NEON or
46
// thumb-mode. See the thumbv7neon variant for enabling both.
@@ -23,6 +25,7 @@ pub(crate) fn target() -> Target {
2325
max_atomic_width: Some(64),
2426
mcount: "\u{1}__gnu_mcount_nc".into(),
2527
llvm_mcount_intrinsic: Some("llvm.arm.gnu.eabi.mcount".into()),
28+
supported_sanitizers: SanitizerSet::ADDRESS,
2629
..base::linux_gnu::opts()
2730
},
2831
}

compiler/rustc_target/src/spec/targets/thumbv7a_none_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
77
llvm_target: "thumbv7a-none-eabi".into(),
88
metadata: TargetMetadata {
99
description: Some("Thumb-mode Bare Armv7-A".into()),
10-
tier: Some(2),
10+
tier: Some(3),
1111
host_tools: Some(false),
1212
std: Some(false),
1313
},

compiler/rustc_target/src/spec/targets/thumbv7a_none_eabihf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
77
llvm_target: "thumbv7a-none-eabihf".into(),
88
metadata: TargetMetadata {
99
description: Some("Thumb-mode Bare Armv7-A, hardfloat".into()),
10-
tier: Some(2),
10+
tier: Some(3),
1111
host_tools: Some(false),
1212
std: Some(false),
1313
},

compiler/rustc_target/src/spec/targets/thumbv7r_none_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
77
llvm_target: "thumbv7r-none-eabi".into(),
88
metadata: TargetMetadata {
99
description: Some("Thumb-mode Bare Armv7-R".into()),
10-
tier: Some(2),
10+
tier: Some(3),
1111
host_tools: Some(false),
1212
std: Some(false),
1313
},

0 commit comments

Comments
 (0)