Skip to content

Commit cc3d4f4

Browse files
committed
Auto merge of #156253 - JonathanBrouwer:rollup-F1llwAn, r=JonathanBrouwer
Rollup of 3 pull requests Successful merges: - #156061 (Support `-Cpanic=unwind` on WASI targets) - #156236 (resolve: Remove `MacroData`) - #155981 (Use special DefIds for aliases)
2 parents 365c0e1 + 0a193e1 commit cc3d4f4

37 files changed

Lines changed: 464 additions & 320 deletions

File tree

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub struct MacroRulesMacroExpander {
170170
transparency: Transparency,
171171
kinds: MacroKinds,
172172
rules: Vec<MacroRule>,
173+
macro_rules: bool,
173174
}
174175

175176
impl MacroRulesMacroExpander {
@@ -189,6 +190,14 @@ impl MacroRulesMacroExpander {
189190
self.kinds
190191
}
191192

193+
pub fn nrules(&self) -> usize {
194+
self.rules.len()
195+
}
196+
197+
pub fn is_macro_rules(&self) -> bool {
198+
self.macro_rules
199+
}
200+
192201
pub fn expand_derive(
193202
&self,
194203
cx: &mut ExtCtxt<'_>,
@@ -714,13 +723,12 @@ pub fn compile_declarative_macro(
714723
span: Span,
715724
node_id: NodeId,
716725
edition: Edition,
717-
) -> (SyntaxExtension, usize) {
726+
) -> SyntaxExtension {
718727
let mk_syn_ext = |kind| {
719728
let is_local = is_defined_in_current_crate(node_id);
720729
SyntaxExtension::new(sess, kind, span, Vec::new(), edition, ident.name, attrs, is_local)
721730
};
722-
let dummy_syn_ext =
723-
|guar| (mk_syn_ext(SyntaxExtensionKind::Bang(Arc::new(DummyBang(guar)))), 0);
731+
let dummy_syn_ext = |guar| mk_syn_ext(SyntaxExtensionKind::Bang(Arc::new(DummyBang(guar))));
724732

725733
let macro_rules = macro_def.macro_rules;
726734
let exp_sep = if macro_rules { exp!(Semi) } else { exp!(Comma) };
@@ -857,9 +865,6 @@ pub fn compile_declarative_macro(
857865
return dummy_syn_ext(guar);
858866
}
859867

860-
// Return the number of rules for unused rule linting, if this is a local macro.
861-
let nrules = if is_defined_in_current_crate(node_id) { rules.len() } else { 0 };
862-
863868
let on_unmatch_args = find_attr!(
864869
attrs,
865870
OnUnmatchArgs { directive, .. } => directive.clone()
@@ -875,8 +880,9 @@ pub fn compile_declarative_macro(
875880
on_unmatch_args,
876881
transparency,
877882
rules,
883+
macro_rules,
878884
};
879-
(mk_syn_ext(SyntaxExtensionKind::MacroRules(Arc::new(exp))), nrules)
885+
mk_syn_ext(SyntaxExtensionKind::MacroRules(Arc::new(exp)))
880886
}
881887

882888
fn check_no_eof(sess: &Session, p: &Parser<'_>, msg: &'static str) -> Option<ErrorGuaranteed> {

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind};
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::lang_items::LangItem;
1010
use rustc_span::{DUMMY_SP, Span, Symbol};
11-
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
11+
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
1212
use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, Unnormalized, search_graph};
1313

1414
use crate::dep_graph::{DepKind, DepNodeIndex};
@@ -39,6 +39,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
3939
type AdtId = DefId;
4040
type ImplId = DefId;
4141
type UnevaluatedConstId = DefId;
42+
type TraitAssocTyId = DefId;
43+
type TraitAssocConstId = DefId;
44+
type TraitAssocTermId = DefId;
45+
type OpaqueTyId = DefId;
46+
type LocalOpaqueTyId = LocalDefId;
47+
type FreeTyAliasId = DefId;
48+
type FreeConstAliasId = DefId;
49+
type FreeTermAliasId = DefId;
50+
type ImplOrTraitAssocTyId = DefId;
51+
type ImplOrTraitAssocConstId = DefId;
52+
type ImplOrTraitAssocTermId = DefId;
53+
type InherentAssocTyId = DefId;
54+
type InherentAssocConstId = DefId;
55+
type InherentAssocTermId = DefId;
4256
type Span = Span;
4357

4458
type GenericArgs = ty::GenericArgsRef<'tcx>;
@@ -288,7 +302,15 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
288302
self.mk_type_list_from_iter(args)
289303
}
290304

291-
fn parent(self, def_id: DefId) -> DefId {
305+
fn projection_parent(self, def_id: Self::TraitAssocTermId) -> Self::TraitId {
306+
self.parent(def_id)
307+
}
308+
309+
fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTyId) -> DefId {
310+
self.parent(def_id)
311+
}
312+
313+
fn inherent_alias_term_parent(self, def_id: Self::InherentAssocTermId) -> Self::ImplId {
292314
self.parent(def_id)
293315
}
294316

@@ -446,7 +468,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
446468
!self.codegen_fn_attrs(def_id).target_features.is_empty()
447469
}
448470

449-
fn require_lang_item(self, lang_item: SolverLangItem) -> DefId {
471+
fn require_projection_lang_item(self, lang_item: SolverProjectionLangItem) -> DefId {
450472
self.require_lang_item(solver_lang_item_to_lang_item(lang_item), DUMMY_SP)
451473
}
452474

@@ -458,7 +480,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
458480
self.require_lang_item(solver_adt_lang_item_to_lang_item(lang_item), DUMMY_SP)
459481
}
460482

461-
fn is_lang_item(self, def_id: DefId, lang_item: SolverLangItem) -> bool {
483+
fn is_projection_lang_item(self, def_id: DefId, lang_item: SolverProjectionLangItem) -> bool {
462484
self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
463485
}
464486

@@ -478,7 +500,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
478500
self.is_sizedness_trait(def_id)
479501
}
480502

481-
fn as_lang_item(self, def_id: DefId) -> Option<SolverLangItem> {
503+
fn as_projection_lang_item(self, def_id: DefId) -> Option<SolverProjectionLangItem> {
482504
lang_item_to_solver_lang_item(self.lang_items().from_def_id(def_id)?)
483505
}
484506

@@ -757,7 +779,7 @@ macro_rules! bidirectional_lang_item_map {
757779
}
758780

759781
bidirectional_lang_item_map! {
760-
SolverLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
782+
SolverProjectionLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
761783

762784
// tidy-alphabetical-start
763785
AsyncFnKindUpvars,
@@ -766,7 +788,6 @@ bidirectional_lang_item_map! {
766788
CallRefFuture,
767789
CoroutineReturn,
768790
CoroutineYield,
769-
DynMetadata,
770791
FieldBase,
771792
FieldType,
772793
FutureOutput,
@@ -778,6 +799,7 @@ bidirectional_lang_item_map! {
778799
SolverAdtLangItem, fn lang_item_to_solver_adt_lang_item, fn solver_adt_lang_item_to_lang_item;
779800

780801
// tidy-alphabetical-start
802+
DynMetadata,
781803
Option,
782804
Poll,
783805
// tidy-alphabetical-end
@@ -791,7 +813,6 @@ bidirectional_lang_item_map! {
791813
AsyncFnKindHelper,
792814
AsyncFnMut,
793815
AsyncFnOnce,
794-
AsyncFnOnceOutput,
795816
AsyncIterator,
796817
BikeshedGuaranteedNoDrop,
797818
Clone,

compiler/rustc_next_trait_solver/src/delegate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
6969

7070
fn add_item_bounds_for_hidden_type(
7171
&self,
72-
def_id: <Self::Interner as Interner>::DefId,
72+
def_id: <Self::Interner as Interner>::OpaqueTyId,
7373
args: <Self::Interner as Interner>::GenericArgs,
7474
param_env: <Self::Interner as Interner>::ParamEnv,
7575
hidden_ty: <Self::Interner as Interner>::Ty,
@@ -79,7 +79,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
7979
fn fetch_eligible_assoc_item(
8080
&self,
8181
goal_trait_ref: ty::TraitRef<Self::Interner>,
82-
trait_assoc_def_id: <Self::Interner as Interner>::DefId,
82+
trait_assoc_def_id: <Self::Interner as Interner>::TraitAssocTermId,
8383
impl_def_id: <Self::Interner as Interner>::ImplId,
8484
) -> FetchEligibleAssocItemResponse<Self::Interner>;
8585

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use derive_where::derive_where;
55
use rustc_type_ir::data_structures::HashMap;
66
use rustc_type_ir::inherent::*;
7-
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem};
7+
use rustc_type_ir::lang_items::{SolverProjectionLangItem, SolverTraitLangItem};
88
use rustc_type_ir::solve::SizedTraitKind;
99
use rustc_type_ir::solve::inspect::ProbeKind;
1010
use rustc_type_ir::{
@@ -106,7 +106,9 @@ where
106106
// We can resolve the `impl Trait` to its concrete type,
107107
// which enforces a DAG between the functions requiring
108108
// the auto trait bounds in question.
109-
Ok(ty::Binder::dummy(vec![cx.type_of(def_id).instantiate(cx, args).skip_norm_wip()]))
109+
Ok(ty::Binder::dummy(vec![
110+
cx.type_of(def_id.into()).instantiate(cx, args).skip_norm_wip(),
111+
]))
110112
}
111113
}
112114
}
@@ -541,7 +543,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
541543
);
542544
}
543545

544-
let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
546+
let future_output_def_id =
547+
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
545548
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
546549
Ok((
547550
bound_sig.rebind(AsyncCallableRelevantTypes {
@@ -596,7 +599,8 @@ fn fn_item_to_async_callable<I: Interner>(
596599
let nested = vec![
597600
bound_sig.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()])).upcast(cx),
598601
];
599-
let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
602+
let future_output_def_id =
603+
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
600604
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
601605
Ok((
602606
bound_sig.rebind(AsyncCallableRelevantTypes {
@@ -642,7 +646,8 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
642646
args: ty::CoroutineClosureArgs<I>,
643647
sig: ty::CoroutineClosureSignature<I>,
644648
) -> I::Ty {
645-
let upvars_projection_def_id = cx.require_lang_item(SolverLangItem::AsyncFnKindUpvars);
649+
let upvars_projection_def_id =
650+
cx.require_projection_lang_item(SolverProjectionLangItem::AsyncFnKindUpvars);
646651
let tupled_upvars_ty = Ty::new_projection(
647652
cx,
648653
upvars_projection_def_id,
@@ -920,7 +925,10 @@ where
920925
// show up in the bounds, but just ones that come from substituting
921926
// `Self` with the dyn type.
922927
let proj = proj.with_self_ty(cx, trait_ref.self_ty());
923-
replace_projection_with.entry(proj.def_id()).or_default().push(bound.rebind(proj));
928+
replace_projection_with
929+
.entry(proj.def_id().into())
930+
.or_default()
931+
.push(bound.rebind(proj));
924932
}
925933
}
926934

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ where
702702
original_typing_mode: TypingMode<I>,
703703
parent_opaque_types: &[(OpaqueTypeKey<I>, I::Ty)],
704704
) -> RerunDecision {
705-
let parent_opaque_defids = parent_opaque_types.iter().map(|(key, _)| key.def_id);
705+
let parent_opaque_defids = parent_opaque_types.iter().map(|(key, _)| key.def_id.into());
706706
let opaque_in_storage = |opaques: I::LocalDefIds, defids: SmallCopyList<_>| {
707707
if defids.as_ref().is_empty() {
708708
RerunDecision::No
@@ -1357,7 +1357,7 @@ where
13571357
pub(super) fn fetch_eligible_assoc_item(
13581358
&self,
13591359
goal_trait_ref: ty::TraitRef<I>,
1360-
trait_assoc_def_id: I::DefId,
1360+
trait_assoc_def_id: I::TraitAssocTermId,
13611361
impl_def_id: I::ImplId,
13621362
) -> FetchEligibleAssocItemResponse<I> {
13631363
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
@@ -1374,7 +1374,7 @@ where
13741374

13751375
pub(super) fn add_item_bounds_for_hidden_type(
13761376
&mut self,
1377-
opaque_def_id: I::DefId,
1377+
opaque_def_id: I::OpaqueTyId,
13781378
opaque_args: I::GenericArgs,
13791379
param_env: I::ParamEnv,
13801380
hidden_ty: I::Ty,

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ where
357357
}
358358
}
359359

360-
fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool {
360+
fn opaque_type_is_rigid(&self, def_id: I::OpaqueTyId) -> bool {
361361
match self
362362
.typing_mode()
363363
// Caller should handle erased mode
@@ -370,7 +370,7 @@ where
370370
TypingMode::Analysis { defining_opaque_types_and_generators: non_rigid_opaques }
371371
| TypingMode::Borrowck { defining_opaque_types: non_rigid_opaques }
372372
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: non_rigid_opaques } => {
373-
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id))
373+
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id.into()))
374374
}
375375
}
376376
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ where
1313
pub(super) fn normalize_anon_const(
1414
&mut self,
1515
goal: Goal<I, ty::NormalizesTo<I>>,
16+
def_id: I::UnevaluatedConstId,
1617
) -> QueryResult<I> {
1718
let uv = goal.predicate.alias.expect_ct(self.cx());
1819
self.evaluate_const_and_instantiate_normalizes_to_term(goal, uv)

compiler/rustc_next_trait_solver/src/solve/normalizes_to/free_alias.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ where
3232

3333
let actual = match free_alias.kind(cx) {
3434
ty::AliasTermKind::FreeTy { def_id } => {
35-
cx.type_of(def_id).instantiate(cx, free_alias.args).skip_norm_wip().into()
36-
}
37-
ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id) => {
38-
cx.const_of_item(def_id).instantiate(cx, free_alias.args).skip_norm_wip().into()
35+
cx.type_of(def_id.into()).instantiate(cx, free_alias.args).skip_norm_wip().into()
3936
}
37+
ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id.into()) => cx
38+
.const_of_item(def_id.into())
39+
.instantiate(cx, free_alias.args)
40+
.skip_norm_wip()
41+
.into(),
4042
ty::AliasTermKind::FreeConst { .. } => {
4143
return self.evaluate_const_and_instantiate_normalizes_to_term(
4244
goal,

compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ where
1818
pub(super) fn normalize_inherent_associated_term(
1919
&mut self,
2020
goal: Goal<I, ty::NormalizesTo<I>>,
21+
def_id: I::InherentAssocTermId,
2122
) -> QueryResult<I> {
2223
let cx = self.cx();
2324
let inherent = goal.predicate.alias;
2425

25-
let impl_def_id = cx.parent(inherent.def_id());
26-
let impl_args = self.fresh_args_for_item(impl_def_id);
26+
let impl_def_id = cx.inherent_alias_term_parent(def_id);
27+
let impl_args = self.fresh_args_for_item(impl_def_id.into());
2728

2829
// Equate impl header and add impl where clauses
2930
self.eq(
3031
goal.param_env,
3132
inherent.self_ty(),
32-
cx.type_of(impl_def_id).instantiate(cx, impl_args).skip_norm_wip(),
33+
cx.type_of(impl_def_id.into()).instantiate(cx, impl_args).skip_norm_wip(),
3334
)?;
3435

3536
// Equate IAT with the RHS of the project goal
@@ -46,19 +47,21 @@ where
4647
// to be very careful when changing the impl where-clauses to be productive.
4748
self.add_goals(
4849
GoalSource::Misc,
49-
cx.predicates_of(inherent.def_id())
50+
cx.predicates_of(def_id.into())
5051
.iter_instantiated(cx, inherent_args)
5152
.map(Unnormalized::skip_norm_wip)
5253
.map(|pred| goal.with(cx, pred)),
5354
);
5455

5556
let normalized = match inherent.kind(cx) {
5657
ty::AliasTermKind::InherentTy { def_id } => {
57-
cx.type_of(def_id).instantiate(cx, inherent_args).skip_norm_wip().into()
58-
}
59-
ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id) => {
60-
cx.const_of_item(def_id).instantiate(cx, inherent_args).skip_norm_wip().into()
58+
cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
6159
}
60+
ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id.into()) => cx
61+
.const_of_item(def_id.into())
62+
.instantiate(cx, inherent_args)
63+
.skip_norm_wip()
64+
.into(),
6265
ty::AliasTermKind::InherentConst { .. } => {
6366
// FIXME(gca): This is dead code at the moment. It should eventually call
6467
// self.evaluate_const like projected consts do in consider_impl_candidate in

0 commit comments

Comments
 (0)