Skip to content

Commit a72e2a7

Browse files
committed
Auto merge of #155239 - JonathanBrouwer:rollup-XUNKT4X, r=JonathanBrouwer
Rollup of 10 pull requests Successful merges: - #155227 (`rust-analyzer` subtree update) - #153335 (Add #![unstable_removed(..)] attribute to track removed features) - #154932 (Handle RTN projections in assoc type restriction diagnostics) - #155096 (delegation: support proper interaction of user-specified args and impl Traits) - #155106 (cg_llvm: scalable vectors with `simd_cast` and `simd_select`) - #155140 (add regression test for OpenOptionsExt downstream compat) - #155182 (Make the expansion of guard metavars begin guard non-terminals) - #155226 (delegation: revert execution of hir_crate_items before delayed lowering) - #153997 (Use closures more consistently in `dep_graph.rs`.) - #155003 (update thin-vec)
2 parents 14196db + f8a8c9e commit a72e2a7

File tree

199 files changed

+8679
-3688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+8679
-3688
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5540,9 +5540,9 @@ dependencies = [
55405540

55415541
[[package]]
55425542
name = "thin-vec"
5543-
version = "0.2.14"
5543+
version = "0.2.15"
55445544
source = "registry+https://github.com/rust-lang/crates.io-index"
5545-
checksum = "144f754d318415ac792f9d69fc87abbbfc043ce2ef041c60f16ad828f638717d"
5545+
checksum = "da322882471314edc77fa5232c587bcb87c9df52bfd0d7d4826f8868ead61899"
55465546

55475547
[[package]]
55485548
name = "thiserror"

compiler/rustc_abi/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ use bitflags::bitflags;
4747
#[cfg(feature = "nightly")]
4848
use rustc_data_structures::stable_hasher::StableOrd;
4949
#[cfg(feature = "nightly")]
50+
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
51+
#[cfg(feature = "nightly")]
5052
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, msg};
5153
use rustc_hashes::Hash64;
5254
use rustc_index::{Idx, IndexSlice, IndexVec};
@@ -1775,6 +1777,24 @@ impl NumScalableVectors {
17751777
}
17761778
}
17771779

1780+
#[cfg(feature = "nightly")]
1781+
impl IntoDiagArg for NumScalableVectors {
1782+
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1783+
DiagArgValue::Str(std::borrow::Cow::Borrowed(match self.0 {
1784+
0 => panic!("`NumScalableVectors(0)` is illformed"),
1785+
1 => "one",
1786+
2 => "two",
1787+
3 => "three",
1788+
4 => "four",
1789+
5 => "five",
1790+
6 => "six",
1791+
7 => "seven",
1792+
8 => "eight",
1793+
_ => panic!("`NumScalableVectors(N)` for N>8 is illformed"),
1794+
}))
1795+
}
1796+
}
1797+
17781798
/// The way we represent values to the backend
17791799
///
17801800
/// Previously this was conflated with the "ABI" a type is given, as in the platform-specific ABI.

compiler/rustc_ast/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ rustc_macros = { path = "../rustc_macros" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_span = { path = "../rustc_span" }
1717
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
18-
thin-vec = "0.2.12"
18+
thin-vec = "0.2.15"
1919
tracing = "0.1"
2020
# tidy-alphabetical-end

compiler/rustc_ast_lowering/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ rustc_session = { path = "../rustc_session" }
2323
rustc_span = { path = "../rustc_span" }
2424
rustc_target = { path = "../rustc_target" }
2525
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
26-
thin-vec = "0.2.12"
26+
thin-vec = "0.2.15"
2727
tracing = "0.1"
2828
# tidy-alphabetical-end

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
433433
// also nested delegations may need to access information about this code (#154332),
434434
// so it is better to leave this code as opposed to bodies of extern functions,
435435
// which are completely erased from existence.
436-
// FIXME(fn_delegation): fix `help` in error message (see `inner-attr.stderr`)
437436
if param_count == 0
438437
&& let Some(block) = block
439438
{

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,38 @@ use rustc_span::{Ident, Span};
1010

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

13-
pub(super) enum DelegationGenerics<T> {
13+
#[derive(Clone, Copy)]
14+
pub(super) enum DelegationGenericsKind {
1415
/// User-specified args are present: `reuse foo::<String>;`.
1516
UserSpecified,
1617
/// The default case when no user-specified args are present: `reuse Trait::foo;`.
17-
Default(T),
18+
Default,
1819
/// In free-to-trait reuse, when user specified args for trait `reuse Trait::<i32>::foo;`
1920
/// in this case we need to both generate `Self` and process user args.
20-
SelfAndUserSpecified(T),
21+
SelfAndUserSpecified,
2122
/// In delegations from trait impl to other entities like free functions or trait functions,
2223
/// we want to generate a function whose generics matches generics of signature function
2324
/// in trait.
24-
TraitImpl(T, bool /* Has user-specified args */),
25+
TraitImpl(bool /* Has user-specified args */),
26+
}
27+
28+
pub(super) struct DelegationGenerics<T> {
29+
generics: T,
30+
kind: DelegationGenericsKind,
31+
}
32+
33+
impl<'hir> DelegationGenerics<&'hir [ty::GenericParamDef]> {
34+
fn default(generics: &'hir [ty::GenericParamDef]) -> Self {
35+
DelegationGenerics { generics, kind: DelegationGenericsKind::Default }
36+
}
37+
38+
fn user_specified(generics: &'hir [ty::GenericParamDef]) -> Self {
39+
DelegationGenerics { generics, kind: DelegationGenericsKind::UserSpecified }
40+
}
41+
42+
fn trait_impl(generics: &'hir [ty::GenericParamDef], user_specified: bool) -> Self {
43+
DelegationGenerics { generics, kind: DelegationGenericsKind::TraitImpl(user_specified) }
44+
}
2545
}
2646

2747
/// Used for storing either ty generics or their uplifted HIR version. First we obtain
@@ -54,20 +74,19 @@ pub(super) struct GenericArgsPropagationDetails {
5474
pub(super) use_args_in_sig_inheritance: bool,
5575
}
5676

57-
impl<T> DelegationGenerics<T> {
58-
fn args_propagation_details(&self) -> GenericArgsPropagationDetails {
77+
impl DelegationGenericsKind {
78+
fn args_propagation_details(self) -> GenericArgsPropagationDetails {
5979
match self {
60-
DelegationGenerics::UserSpecified | DelegationGenerics::SelfAndUserSpecified { .. } => {
61-
GenericArgsPropagationDetails {
62-
should_propagate: false,
63-
use_args_in_sig_inheritance: true,
64-
}
65-
}
66-
DelegationGenerics::TraitImpl(_, user_specified) => GenericArgsPropagationDetails {
67-
should_propagate: !*user_specified,
80+
DelegationGenericsKind::UserSpecified
81+
| DelegationGenericsKind::SelfAndUserSpecified => GenericArgsPropagationDetails {
82+
should_propagate: false,
83+
use_args_in_sig_inheritance: true,
84+
},
85+
DelegationGenericsKind::TraitImpl(user_specified) => GenericArgsPropagationDetails {
86+
should_propagate: !user_specified,
6887
use_args_in_sig_inheritance: false,
6988
},
70-
DelegationGenerics::Default(_) => GenericArgsPropagationDetails {
89+
DelegationGenericsKind::Default => GenericArgsPropagationDetails {
7190
should_propagate: true,
7291
use_args_in_sig_inheritance: false,
7392
},
@@ -81,25 +100,9 @@ impl<'hir> HirOrTyGenerics<'hir> {
81100
ctx: &mut LoweringContext<'_, 'hir, impl ResolverAstLoweringExt<'hir>>,
82101
span: Span,
83102
) -> &mut HirOrTyGenerics<'hir> {
84-
if let HirOrTyGenerics::Ty(params) = self {
85-
let mut uplift_params = |generics: &'hir [ty::GenericParamDef]| {
86-
ctx.uplift_delegation_generic_params(span, generics)
87-
};
88-
89-
let hir_generics = match params {
90-
DelegationGenerics::UserSpecified => DelegationGenerics::UserSpecified,
91-
DelegationGenerics::Default(params) => {
92-
DelegationGenerics::Default(uplift_params(params))
93-
}
94-
DelegationGenerics::SelfAndUserSpecified(params) => {
95-
DelegationGenerics::SelfAndUserSpecified(uplift_params(params))
96-
}
97-
DelegationGenerics::TraitImpl(params, user_specified) => {
98-
DelegationGenerics::TraitImpl(uplift_params(params), *user_specified)
99-
}
100-
};
101-
102-
*self = HirOrTyGenerics::Hir(hir_generics);
103+
if let HirOrTyGenerics::Ty(ty) = self {
104+
let params = ctx.uplift_delegation_generic_params(span, ty.generics);
105+
*self = HirOrTyGenerics::Hir(DelegationGenerics { generics: params, kind: ty.kind });
103106
}
104107

105108
self
@@ -108,12 +111,7 @@ impl<'hir> HirOrTyGenerics<'hir> {
108111
fn hir_generics_or_empty(&self) -> &'hir hir::Generics<'hir> {
109112
match self {
110113
HirOrTyGenerics::Ty(_) => hir::Generics::empty(),
111-
HirOrTyGenerics::Hir(hir_generics) => match hir_generics {
112-
DelegationGenerics::UserSpecified => hir::Generics::empty(),
113-
DelegationGenerics::Default(generics)
114-
| DelegationGenerics::SelfAndUserSpecified(generics)
115-
| DelegationGenerics::TraitImpl(generics, _) => generics,
116-
},
114+
HirOrTyGenerics::Hir(hir) => hir.generics,
117115
}
118116
}
119117

@@ -127,21 +125,16 @@ impl<'hir> HirOrTyGenerics<'hir> {
127125
HirOrTyGenerics::Ty(_) => {
128126
bug!("Attempting to get generic args before uplifting to HIR")
129127
}
130-
HirOrTyGenerics::Hir(hir_generics) => match hir_generics {
131-
DelegationGenerics::UserSpecified => hir::GenericArgs::NONE,
132-
DelegationGenerics::Default(generics)
133-
| DelegationGenerics::SelfAndUserSpecified(generics)
134-
| DelegationGenerics::TraitImpl(generics, _) => {
135-
ctx.create_generics_args_from_params(generics.params, add_lifetimes, span)
136-
}
137-
},
128+
HirOrTyGenerics::Hir(hir) => {
129+
ctx.create_generics_args_from_params(hir.generics.params, add_lifetimes, span)
130+
}
138131
}
139132
}
140133

141134
pub(super) fn args_propagation_details(&self) -> GenericArgsPropagationDetails {
142135
match self {
143-
HirOrTyGenerics::Ty(ty_generics) => ty_generics.args_propagation_details(),
144-
HirOrTyGenerics::Hir(hir_generics) => hir_generics.args_propagation_details(),
136+
HirOrTyGenerics::Ty(ty) => ty.kind.args_propagation_details(),
137+
HirOrTyGenerics::Hir(hir) => hir.kind.args_propagation_details(),
145138
}
146139
}
147140
}
@@ -231,9 +224,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
231224
if matches!(delegation_parent_kind, DefKind::Impl { of_trait: true }) {
232225
// Considering parent generics, during signature inheritance
233226
// we will take those args that are in trait impl header trait ref.
234-
let parent = GenericsGenerationResult::new(DelegationGenerics::TraitImpl(&[], true));
227+
let parent = DelegationGenerics::trait_impl(&[], true);
228+
let parent = GenericsGenerationResult::new(parent);
235229

236-
let child = DelegationGenerics::TraitImpl(sig_params, child_user_specified);
230+
let child = DelegationGenerics::trait_impl(sig_params, child_user_specified);
237231
let child = GenericsGenerationResult::new(child);
238232

239233
return GenericsGenerationResults { parent, child };
@@ -257,22 +251,28 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
257251
if segments[len - 2].args.is_some() {
258252
if generate_self {
259253
// Take only first Self parameter, it is trait so Self must be present.
260-
DelegationGenerics::SelfAndUserSpecified(&sig_parent_params[..1])
254+
DelegationGenerics {
255+
kind: DelegationGenericsKind::SelfAndUserSpecified,
256+
generics: &sig_parent_params[..1],
257+
}
261258
} else {
262-
DelegationGenerics::UserSpecified
259+
DelegationGenerics::user_specified(&[])
263260
}
264261
} else {
265262
let skip_self = usize::from(!generate_self);
266-
DelegationGenerics::Default(&sig_parent_params[skip_self..])
263+
DelegationGenerics::default(&sig_parent_params[skip_self..])
267264
}
268265
} else {
269-
DelegationGenerics::<&'hir [ty::GenericParamDef]>::Default(&[])
266+
DelegationGenerics::default(&[])
270267
};
271268

272269
let child_generics = if child_user_specified {
273-
DelegationGenerics::UserSpecified
270+
let synth_params_index =
271+
sig_params.iter().position(|p| p.kind.is_synthetic()).unwrap_or(sig_params.len());
272+
273+
DelegationGenerics::user_specified(&sig_params[synth_params_index..])
274274
} else {
275-
DelegationGenerics::Default(sig_params)
275+
DelegationGenerics::default(sig_params)
276276
};
277277

278278
GenericsGenerationResults {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(super) enum Owners<'a, 'hir> {
3838
}
3939

4040
impl<'hir> Owners<'_, 'hir> {
41-
pub(super) fn get_or_insert_mut(&mut self, def_id: LocalDefId) -> &mut hir::MaybeOwner<'hir> {
41+
fn get_or_insert_mut(&mut self, def_id: LocalDefId) -> &mut hir::MaybeOwner<'hir> {
4242
match self {
4343
Owners::IndexVec(index_vec) => {
4444
index_vec.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom)

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use std::mem;
3939
use std::sync::Arc;
4040

4141
use rustc_ast::node_id::NodeMap;
42-
use rustc_ast::visit::AssocCtxt;
4342
use rustc_ast::{self as ast, *};
4443
use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
4544
use rustc_data_structures::fingerprint::Fingerprint;
@@ -634,29 +633,13 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
634633
let mut delayed_ids: FxIndexSet<LocalDefId> = Default::default();
635634

636635
for def_id in ast_index.indices() {
637-
let delayed_owner_kind = match &ast_index[def_id] {
638-
AstOwner::Item(Item { kind: ItemKind::Delegation(_), .. }) => {
639-
Some(hir::DelayedOwnerKind::Item)
636+
match &ast_index[def_id] {
637+
AstOwner::Item(Item { kind: ItemKind::Delegation { .. }, .. })
638+
| AstOwner::AssocItem(Item { kind: AssocItemKind::Delegation { .. }, .. }, _) => {
639+
delayed_ids.insert(def_id);
640640
}
641-
AstOwner::AssocItem(Item { kind: AssocItemKind::Delegation(_), .. }, ctx) => {
642-
Some(match ctx {
643-
AssocCtxt::Trait => hir::DelayedOwnerKind::TraitItem,
644-
AssocCtxt::Impl { .. } => hir::DelayedOwnerKind::ImplItem,
645-
})
646-
}
647-
_ => None,
641+
_ => lowerer.lower_node(def_id),
648642
};
649-
650-
if let Some(kind) = delayed_owner_kind {
651-
delayed_ids.insert(def_id);
652-
653-
let owner = lowerer.owners.get_or_insert_mut(def_id);
654-
if let hir::MaybeOwner::Phantom = owner {
655-
*owner = hir::MaybeOwner::Delayed(kind)
656-
}
657-
} else {
658-
lowerer.lower_node(def_id);
659-
}
660643
}
661644

662645
// Don't hash unless necessary, because it's expensive.

compiler/rustc_ast_passes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ rustc_macros = { path = "../rustc_macros" }
1818
rustc_session = { path = "../rustc_session" }
1919
rustc_span = { path = "../rustc_span" }
2020
rustc_target = { path = "../rustc_target" }
21-
thin-vec = "0.2.12"
21+
thin-vec = "0.2.15"
2222
# tidy-alphabetical-end

compiler/rustc_ast_pretty/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ rustc_span = { path = "../rustc_span" }
1313

1414
[dev-dependencies]
1515
# tidy-alphabetical-start
16-
thin-vec = "0.2.12"
16+
thin-vec = "0.2.15"
1717
# tidy-alphabetical-end

0 commit comments

Comments
 (0)