Skip to content

Commit 02e547e

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 046b67b commit 02e547e

File tree

17 files changed

+48
-20
lines changed

17 files changed

+48
-20
lines changed

compiler/rustc_ast_lowering/src/item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1596,12 +1596,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
15961596
}),
15971597
)),
15981598
)),
1599+
// FIXME(effects) we might not need a default.
15991600
default: Some(hir::AnonConst {
16001601
def_id: anon_const,
16011602
hir_id: const_id,
16021603
body: const_body,
16031604
}),
16041605
is_host_effect: true,
1606+
synthetic: true,
16051607
},
16061608
colon_span: None,
16071609
pure_wrt_drop: false,

compiler/rustc_ast_lowering/src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21122112
param: &GenericParam,
21132113
source: hir::GenericParamSource,
21142114
) -> hir::GenericParam<'hir> {
2115-
let (name, kind) = self.lower_generic_param_kind(param, source);
2115+
let (name, kind) = self.lower_generic_param_kind(
2116+
param,
2117+
source,
2118+
attr::contains_name(&param.attrs, sym::rustc_runtime),
2119+
);
21162120

21172121
let hir_id = self.lower_node_id(param.id);
21182122
self.lower_attrs(hir_id, &param.attrs);
@@ -2132,6 +2136,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21322136
&mut self,
21332137
param: &GenericParam,
21342138
source: hir::GenericParamSource,
2139+
is_host_effect: bool,
21352140
) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
21362141
match &param.kind {
21372142
GenericParamKind::Lifetime => {
@@ -2197,7 +2202,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21972202

21982203
(
21992204
hir::ParamName::Plain(self.lower_ident(param.ident)),
2200-
hir::GenericParamKind::Const { ty, default, is_host_effect: false },
2205+
hir::GenericParamKind::Const { ty, default, is_host_effect, synthetic: false },
22012206
)
22022207
}
22032208
}

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+1-2
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

+1
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
651651
rustc_attr!(
652652
rustc_const_panic_str, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
653653
),
654+
rustc_attr!(rustc_runtime, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
654655

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

compiler/rustc_hir/src/hir.rs

+1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
865865
match param.kind {
866866
GenericParamKind::Lifetime { .. } => {}
867867
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
868-
GenericParamKind::Const { ref ty, ref default, is_host_effect: _ } => {
868+
GenericParamKind::Const { ref ty, ref default, is_host_effect: _, synthetic: _ } => {
869869
visitor.visit_ty(ty);
870870
if let Some(ref default) = default {
871871
visitor.visit_const_param_default(param.hir_id, default);

compiler/rustc_hir_analysis/src/astconv/generics.rs

+1-1
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

+15-3
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

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

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

917922
if tcx.features().adt_const_params {

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+4-2
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);

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
963963
self.visit_ty(ty);
964964
}
965965
}
966-
GenericParamKind::Const { ty, default, is_host_effect: _ } => {
966+
GenericParamKind::Const { ty, default, .. } => {
967967
self.visit_ty(ty);
968968
if let Some(default) = default {
969969
self.visit_body(self.tcx.hir().body(default.body));

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ impl<'a> State<'a> {
21042104
self.print_type(default);
21052105
}
21062106
}
2107-
GenericParamKind::Const { ty, ref default, is_host_effect: _ } => {
2107+
GenericParamKind::Const { ty, ref default, is_host_effect: _, synthetic: _ } => {
21082108
self.word_space(":");
21092109
self.print_type(ty);
21102110
if let Some(default) = default {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13011301
self.fcx.ty_infer(Some(param), inf.span).into()
13021302
}
13031303
(
1304-
&GenericParamDefKind::Const { has_default, is_host_effect },
1304+
&GenericParamDefKind::Const { has_default, is_host_effect, .. },
13051305
GenericArg::Infer(inf),
13061306
) => {
13071307
let tcx = self.fcx.tcx();
@@ -1349,7 +1349,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13491349
self.fcx.var_for_def(self.span, param)
13501350
}
13511351
}
1352-
GenericParamDefKind::Const { has_default, is_host_effect } => {
1352+
GenericParamDefKind::Const { has_default, is_host_effect, .. } => {
13531353
if has_default {
13541354
// N.B. this is a bit of a hack. `infer_args` is passed depending on
13551355
// whether the user has provided generic args. E.g. for `Vec::new`

compiler/rustc_middle/src/ty/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{Clause, InstantiatedPredicates, ParamConst, ParamTy, Ty, TyCtxt};
1212
pub enum GenericParamDefKind {
1313
Lifetime,
1414
Type { has_default: bool, synthetic: bool },
15-
Const { has_default: bool, is_host_effect: bool },
15+
Const { has_default: bool, is_host_effect: bool, synthetic: bool },
1616
}
1717

1818
impl GenericParamDefKind {

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
561561
ty::GenericParamDefKind::Type { has_default, synthetic } => {
562562
GenericParamDefKind::Type { has_default: *has_default, synthetic: *synthetic }
563563
}
564-
ty::GenericParamDefKind::Const { has_default, is_host_effect: _ } => {
564+
ty::GenericParamDefKind::Const { has_default, is_host_effect: _, synthetic: _ } => {
565565
GenericParamDefKind::Const { has_default: *has_default }
566566
}
567567
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ symbols! {
14571457
rustc_reallocator,
14581458
rustc_regions,
14591459
rustc_reservation_impl,
1460+
rustc_runtime,
14601461
rustc_safe_intrinsic,
14611462
rustc_serialize,
14621463
rustc_skip_array_during_method_dispatch,

library/core/src/marker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,11 @@ pub mod effects {
10251025
pub struct Runtime;
10261026

10271027
#[lang = "EffectsCompat"]
1028-
pub trait Compat<const RUNTIME: bool> {}
1028+
pub trait Compat<#[rustc_runtime] const RUNTIME: bool = true> {}
10291029

10301030
impl Compat<false> for NoRuntime {}
10311031
impl Compat<true> for Runtime {}
1032-
impl<const RUNTIME: bool> Compat<RUNTIME> for Maybe {}
1032+
impl<#[rustc_runtime] const RUNTIME: bool> Compat<RUNTIME> for Maybe {}
10331033

10341034
#[lang = "EffectsEq"]
10351035
pub trait EffectsEq<T: ?Sized> {}

0 commit comments

Comments
 (0)