Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 73a7018

Browse files
committed
Mark effects marker traits' runtime params as is_host_param.
This avoids mix up when we create inference params for them and try to equate those to effect inference params.
1 parent 431403d commit 73a7018

File tree

17 files changed

+50
-22
lines changed

17 files changed

+50
-22
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,12 +1599,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
15991599
}),
16001600
)),
16011601
)),
1602+
// FIXME(effects) we might not need a default.
16021603
default: Some(hir::AnonConst {
16031604
def_id: anon_const,
16041605
hir_id: const_id,
16051606
body: const_body,
16061607
}),
16071608
is_host_effect: true,
1609+
synthetic: true,
16081610
},
16091611
colon_span: None,
16101612
pure_wrt_drop: false,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20762076
param: &GenericParam,
20772077
source: hir::GenericParamSource,
20782078
) -> hir::GenericParam<'hir> {
2079-
let (name, kind) = self.lower_generic_param_kind(param, source);
2079+
let (name, kind) = self.lower_generic_param_kind(
2080+
param,
2081+
source,
2082+
attr::contains_name(&param.attrs, sym::rustc_runtime),
2083+
);
20802084

20812085
let hir_id = self.lower_node_id(param.id);
20822086
self.lower_attrs(hir_id, &param.attrs);
@@ -2096,6 +2100,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20962100
&mut self,
20972101
param: &GenericParam,
20982102
source: hir::GenericParamSource,
2103+
is_host_effect: bool,
20992104
) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
21002105
match &param.kind {
21012106
GenericParamKind::Lifetime => {
@@ -2161,7 +2166,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21612166

21622167
(
21632168
hir::ParamName::Plain(self.lower_ident(param.ident)),
2164-
hir::GenericParamKind::Const { ty, default, is_host_effect: false },
2169+
hir::GenericParamKind::Const { ty, default, is_host_effect, synthetic: false },
21652170
)
21662171
}
21672172
}

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
4343
hir::Constness::Const
4444
}
4545
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }) => tcx
46-
.generics_of(def_id)
47-
.host_effect_index
46+
.associated_type_for_effects(def_id)
4847
.map_or(hir::Constness::NotConst, |_| hir::Constness::Const),
4948
hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => {
5049
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
650650
rustc_attr!(
651651
rustc_const_panic_str, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
652652
),
653+
rustc_attr!(rustc_runtime, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
653654

654655
// ==========================================================================
655656
// Internal attributes, Layout related:

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ pub enum GenericParamKind<'hir> {
485485
/// Optional default value for the const generic param
486486
default: Option<AnonConst>,
487487
is_host_effect: bool,
488+
synthetic: bool,
488489
},
489490
}
490491

compiler/rustc_hir/src/intravisit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,11 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(
897897
}
898898
match param.kind {
899899
GenericParamKind::Lifetime { .. } => {}
900-
GenericParamKind::Type { ref default, .. } => visit_opt!(visitor, visit_ty, default),
901-
GenericParamKind::Const { ref ty, ref default, is_host_effect: _ } => {
900+
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
901+
GenericParamKind::Const { ref ty, ref default, is_host_effect: _, synthetic: _ } => {
902902
try_visit!(visitor.visit_ty(ty));
903903
if let Some(ref default) = default {
904-
visitor.visit_const_param_default(param.hir_id, default);
904+
try_visit!(visitor.visit_const_param_default(param.hir_id, default));
905905
}
906906
}
907907
}

compiler/rustc_hir_analysis/src/astconv/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ pub(crate) fn check_generic_arg_count(
448448
.params
449449
.iter()
450450
.filter(|param| {
451-
matches!(param.kind, ty::GenericParamDefKind::Const { is_host_effect: true, .. })
451+
matches!(param.kind, ty::GenericParamDefKind::Const { synthetic: true, .. })
452452
})
453453
.count();
454454
let named_const_param_count = param_counts.consts - synth_const_param_count;

compiler/rustc_hir_analysis/src/bounds.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,20 @@ impl<'tcx> Bounds<'tcx> {
7575
tcx.impl_trait_ref(defining_def_id).unwrap().instantiate_identity()
7676
};
7777
// create a new projection type `<T as TraitForBound>::Effects`
78-
let assoc = tcx.associated_type_for_effects(trait_ref.def_id()).unwrap();
78+
let Some(assoc) = tcx.associated_type_for_effects(trait_ref.def_id()) else {
79+
tcx.dcx().span_delayed_bug(
80+
span,
81+
"`~const` trait bound has no effect assoc yet no errors encountered?",
82+
);
83+
return;
84+
};
7985
let self_ty = Ty::new_projection(tcx, assoc, trait_ref.skip_binder().args);
8086
// we might have `~const Tr` where `Tr` isn't a `#[const_trait]`.
8187
let Some(assoc_def) = tcx.associated_type_for_effects(trait_we_are_in.def_id)
8288
else {
8389
tcx.dcx().span_delayed_bug(
8490
span,
85-
"`~const` bound trait has no effect param yet no errors encountered?",
91+
"`~const` trait bound has no effect assoc yet no errors encountered?",
8692
);
8793
return;
8894
};
@@ -104,7 +110,13 @@ impl<'tcx> Bounds<'tcx> {
104110
}
105111
} {
106112
// create a new projection type `<T as Tr>::Effects`
107-
let assoc = tcx.associated_type_for_effects(trait_ref.def_id()).unwrap();
113+
let Some(assoc) = tcx.associated_type_for_effects(trait_ref.def_id()) else {
114+
tcx.dcx().span_delayed_bug(
115+
span,
116+
"`~const` trait bound has no effect assoc yet no errors encountered?",
117+
);
118+
return;
119+
};
108120
let self_ty = Ty::new_projection(tcx, assoc, trait_ref.skip_binder().args);
109121
// make `<T as Tr>::Effects: Compat<runtime>`
110122
let new_trait_ref = ty::TraitRef::new(

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,12 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
912912
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => Ok(()),
913913

914914
// Const parameters are well formed if their type is structural match.
915-
hir::GenericParamKind::Const { ty: hir_ty, default: _, is_host_effect: _ } => {
915+
hir::GenericParamKind::Const {
916+
ty: hir_ty,
917+
default: _,
918+
is_host_effect: _,
919+
synthetic: _,
920+
} => {
916921
let ty = tcx.type_of(param.def_id).instantiate_identity();
917922

918923
if tcx.features().adt_const_params {

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
298298
kind,
299299
})
300300
}
301-
GenericParamKind::Const { ty: _, default, is_host_effect } => {
301+
GenericParamKind::Const { ty: _, default, is_host_effect, synthetic } => {
302302
if !matches!(allow_defaults, Defaults::Allowed)
303303
&& default.is_some()
304304
// `host` effect params are allowed to have defaults.
@@ -332,6 +332,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
332332
kind: ty::GenericParamDefKind::Const {
333333
has_default: default.is_some(),
334334
is_host_effect,
335+
synthetic,
335336
},
336337
})
337338
}
@@ -504,7 +505,8 @@ struct AnonConstInParamTyDetector {
504505

505506
impl<'v> Visitor<'v> for AnonConstInParamTyDetector {
506507
fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) {
507-
if let GenericParamKind::Const { ty, default: _, is_host_effect: _ } = p.kind {
508+
if let GenericParamKind::Const { ty, default: _, is_host_effect: _, synthetic: _ } = p.kind
509+
{
508510
let prev = self.in_param_ty;
509511
self.in_param_ty = true;
510512
self.visit_ty(ty);

0 commit comments

Comments
 (0)