Skip to content

Commit a16d491

Browse files
Remove associated type based effects logic
1 parent 8aca4ba commit a16d491

File tree

73 files changed

+85
-1519
lines changed

Some content is hidden

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

73 files changed

+85
-1519
lines changed

compiler/rustc_ast_lowering/src/item.rs

+19-186
Large diffs are not rendered by default.

compiler/rustc_ast_lowering/src/lib.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,10 @@ struct LoweringContext<'a, 'hir> {
154154
/// defined on the TAIT, so we have type Foo<'a1> = ... and we establish a mapping in this
155155
/// field from the original parameter 'a to the new parameter 'a1.
156156
generics_def_id_map: Vec<LocalDefIdMap<LocalDefId>>,
157-
158-
host_param_id: Option<LocalDefId>,
159-
ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
160157
}
161158

162159
impl<'a, 'hir> LoweringContext<'a, 'hir> {
163-
fn new(
164-
tcx: TyCtxt<'hir>,
165-
resolver: &'a mut ResolverAstLowering,
166-
ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
167-
) -> Self {
160+
fn new(tcx: TyCtxt<'hir>, resolver: &'a mut ResolverAstLowering) -> Self {
168161
Self {
169162
// Pseudo-globals.
170163
tcx,
@@ -204,8 +197,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
204197
// interact with `gen`/`async gen` blocks
205198
allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
206199
generics_def_id_map: Default::default(),
207-
host_param_id: None,
208-
ast_index,
209200
}
210201
}
211202

@@ -2054,11 +2045,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20542045
param: &GenericParam,
20552046
source: hir::GenericParamSource,
20562047
) -> hir::GenericParam<'hir> {
2057-
let (name, kind) = self.lower_generic_param_kind(
2058-
param,
2059-
source,
2060-
attr::contains_name(&param.attrs, sym::rustc_runtime),
2061-
);
2048+
let (name, kind) = self.lower_generic_param_kind(param, source);
20622049

20632050
let hir_id = self.lower_node_id(param.id);
20642051
self.lower_attrs(hir_id, &param.attrs);
@@ -2078,7 +2065,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20782065
&mut self,
20792066
param: &GenericParam,
20802067
source: hir::GenericParamSource,
2081-
is_host_effect: bool,
20822068
) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
20832069
match &param.kind {
20842070
GenericParamKind::Lifetime => {
@@ -2144,7 +2130,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21442130

21452131
(
21462132
hir::ParamName::Plain(self.lower_ident(param.ident)),
2147-
hir::GenericParamKind::Const { ty, default, is_host_effect, synthetic: false },
2133+
hir::GenericParamKind::Const { ty, default, synthetic: false },
21482134
)
21492135
}
21502136
}

compiler/rustc_feature/src/builtin_attrs.rs

-4
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
838838
rustc_const_panic_str, Normal, template!(Word), WarnFollowing,
839839
EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
840840
),
841-
rustc_attr!(
842-
rustc_runtime, Normal, template!(Word), WarnFollowing,
843-
EncodeCrossCrate::No, INTERNAL_UNSTABLE
844-
),
845841

846842
// ==========================================================================
847843
// Internal attributes, Layout related:

compiler/rustc_hir/src/hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@ pub enum GenericParamKind<'hir> {
580580
ty: &'hir Ty<'hir>,
581581
/// Optional default value for the const generic param
582582
default: Option<&'hir ConstArg<'hir>>,
583-
is_host_effect: bool,
584583
synthetic: bool,
585584
},
586585
}

compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(
935935
match param.kind {
936936
GenericParamKind::Lifetime { .. } => {}
937937
GenericParamKind::Type { ref default, .. } => visit_opt!(visitor, visit_ty, default),
938-
GenericParamKind::Const { ref ty, ref default, is_host_effect: _, synthetic: _ } => {
938+
GenericParamKind::Const { ref ty, ref default, synthetic: _ } => {
939939
try_visit!(visitor.visit_ty(ty));
940940
if let Some(ref default) = default {
941941
try_visit!(visitor.visit_const_param_default(param.hir_id, default));

compiler/rustc_hir/src/lang_items.rs

-8
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,6 @@ language_item_table! {
415415

416416
String, sym::String, string, Target::Struct, GenericRequirement::None;
417417
CStr, sym::CStr, c_str, Target::Struct, GenericRequirement::None;
418-
419-
EffectsRuntime, sym::EffectsRuntime, effects_runtime, Target::Struct, GenericRequirement::None;
420-
EffectsNoRuntime, sym::EffectsNoRuntime, effects_no_runtime, Target::Struct, GenericRequirement::None;
421-
EffectsMaybe, sym::EffectsMaybe, effects_maybe, Target::Struct, GenericRequirement::None;
422-
EffectsIntersection, sym::EffectsIntersection, effects_intersection, Target::Trait, GenericRequirement::None;
423-
EffectsIntersectionOutput, sym::EffectsIntersectionOutput, effects_intersection_output, Target::AssocTy, GenericRequirement::None;
424-
EffectsCompat, sym::EffectsCompat, effects_compat, Target::Trait, GenericRequirement::Exact(1);
425-
EffectsTyCompat, sym::EffectsTyCompat, effects_ty_compat, Target::Trait, GenericRequirement::Exact(1);
426418
}
427419

428420
pub enum GenericRequirement {

compiler/rustc_hir_analysis/src/bounds.rs

-139
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
44
use rustc_data_structures::fx::FxIndexMap;
55
use rustc_hir::LangItem;
6-
use rustc_hir::def::DefKind;
7-
use rustc_middle::ty::fold::FnMutDelegate;
86
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
97
use rustc_span::Span;
10-
use rustc_span::def_id::DefId;
11-
12-
use crate::hir_ty_lowering::PredicateFilter;
138

149
/// Collects together a list of type bounds. These lists of bounds occur in many places
1510
/// in Rust's syntax:
@@ -47,12 +42,9 @@ impl<'tcx> Bounds<'tcx> {
4742
pub(crate) fn push_trait_bound(
4843
&mut self,
4944
tcx: TyCtxt<'tcx>,
50-
defining_def_id: DefId,
5145
bound_trait_ref: ty::PolyTraitRef<'tcx>,
5246
span: Span,
5347
polarity: ty::PredicatePolarity,
54-
constness: Option<ty::BoundConstness>,
55-
predicate_filter: PredicateFilter,
5648
) {
5749
let clause = (
5850
bound_trait_ref
@@ -68,137 +60,6 @@ impl<'tcx> Bounds<'tcx> {
6860
} else {
6961
self.clauses.push(clause);
7062
}
71-
72-
// FIXME(effects): Lift this out of `push_trait_bound`, and move it somewhere else.
73-
// Perhaps moving this into `lower_poly_trait_ref`, just like we lower associated
74-
// type bounds.
75-
if !tcx.features().effects() {
76-
return;
77-
}
78-
match predicate_filter {
79-
PredicateFilter::SelfOnly | PredicateFilter::SelfThatDefines(_) => {
80-
return;
81-
}
82-
PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {
83-
// Ok.
84-
}
85-
}
86-
87-
// For `T: ~const Tr` or `T: const Tr`, we need to add an additional bound on the
88-
// associated type of `<T as Tr>` and make sure that the effect is compatible.
89-
let compat_val = match (tcx.def_kind(defining_def_id), constness) {
90-
// FIXME(effects): revisit the correctness of this
91-
(_, Some(ty::BoundConstness::Const)) => tcx.consts.false_,
92-
// body owners that can have trait bounds
93-
(
94-
DefKind::Const | DefKind::Fn | DefKind::AssocFn,
95-
Some(ty::BoundConstness::ConstIfConst),
96-
) => tcx.expected_host_effect_param_for_body(defining_def_id),
97-
98-
(_, None) => {
99-
if !tcx.is_const_trait(bound_trait_ref.def_id()) {
100-
return;
101-
}
102-
tcx.consts.true_
103-
}
104-
(DefKind::Trait, Some(ty::BoundConstness::ConstIfConst)) => {
105-
// we are in a trait, where `bound_trait_ref` could be:
106-
// (1) a super trait `trait Foo: ~const Bar`.
107-
// - This generates `<Self as Foo>::Effects: TyCompat<<Self as Bar>::Effects>`
108-
//
109-
// (2) a where clause `where for<..> Something: ~const Bar`.
110-
// - This generates `for<..> <Self as Foo>::Effects: TyCompat<<Something as Bar>::Effects>`
111-
let Some(own_fx) = tcx.associated_type_for_effects(defining_def_id) else {
112-
tcx.dcx().span_delayed_bug(span, "should not have allowed `~const` on a trait that doesn't have `#[const_trait]`");
113-
return;
114-
};
115-
let own_fx_ty = Ty::new_projection(
116-
tcx,
117-
own_fx,
118-
ty::GenericArgs::identity_for_item(tcx, own_fx),
119-
);
120-
let Some(their_fx) = tcx.associated_type_for_effects(bound_trait_ref.def_id())
121-
else {
122-
tcx.dcx().span_delayed_bug(span, "`~const` on trait without Effects assoc");
123-
return;
124-
};
125-
let their_fx_ty =
126-
Ty::new_projection(tcx, their_fx, bound_trait_ref.skip_binder().args);
127-
let compat = tcx.require_lang_item(LangItem::EffectsTyCompat, Some(span));
128-
let clause = bound_trait_ref
129-
.map_bound(|_| {
130-
let trait_ref = ty::TraitRef::new(tcx, compat, [own_fx_ty, their_fx_ty]);
131-
ty::ClauseKind::Trait(ty::TraitPredicate {
132-
trait_ref,
133-
polarity: ty::PredicatePolarity::Positive,
134-
})
135-
})
136-
.upcast(tcx);
137-
138-
self.clauses.push((clause, span));
139-
return;
140-
}
141-
142-
(DefKind::Impl { of_trait: true }, Some(ty::BoundConstness::ConstIfConst)) => {
143-
// this is a where clause on an impl header.
144-
// push `<T as Tr>::Effects` into the set for the `Min` bound.
145-
let Some(assoc) = tcx.associated_type_for_effects(bound_trait_ref.def_id()) else {
146-
tcx.dcx().span_delayed_bug(span, "`~const` on trait without Effects assoc");
147-
return;
148-
};
149-
150-
let ty = bound_trait_ref
151-
.map_bound(|trait_ref| Ty::new_projection(tcx, assoc, trait_ref.args));
152-
153-
// When the user has written `for<'a, T> X<'a, T>: ~const Foo`, replace the
154-
// binders to dummy ones i.e. `X<'static, ()>` so they can be referenced in
155-
// the `Min` associated type properly (which doesn't allow using `for<>`)
156-
// This should work for any bound variables as long as they don't have any
157-
// bounds e.g. `for<T: Trait>`.
158-
// FIXME(effects) reconsider this approach to allow compatibility with `for<T: Tr>`
159-
let ty = tcx.replace_bound_vars_uncached(ty, FnMutDelegate {
160-
regions: &mut |_| tcx.lifetimes.re_static,
161-
types: &mut |_| tcx.types.unit,
162-
consts: &mut |_| unimplemented!("`~const` does not support const binders"),
163-
});
164-
165-
self.effects_min_tys.insert(ty, span);
166-
return;
167-
}
168-
// for
169-
// ```
170-
// trait Foo { type Bar: ~const Trait }
171-
// ```
172-
// ensure that `<Self::Bar as Trait>::Effects: TyCompat<Self::Effects>`.
173-
//
174-
// FIXME(effects) this is equality for now, which wouldn't be helpful for a non-const implementor
175-
// that uses a `Bar` that implements `Trait` with `Maybe` effects.
176-
(DefKind::AssocTy, Some(ty::BoundConstness::ConstIfConst)) => {
177-
// FIXME(effects): implement this
178-
return;
179-
}
180-
// probably illegal in this position.
181-
(_, Some(ty::BoundConstness::ConstIfConst)) => {
182-
tcx.dcx().span_delayed_bug(span, "invalid `~const` encountered");
183-
return;
184-
}
185-
};
186-
// create a new projection type `<T as Tr>::Effects`
187-
let Some(assoc) = tcx.associated_type_for_effects(bound_trait_ref.def_id()) else {
188-
tcx.dcx().span_delayed_bug(
189-
span,
190-
"`~const` trait bound has no effect assoc yet no errors encountered?",
191-
);
192-
return;
193-
};
194-
let self_ty = Ty::new_projection(tcx, assoc, bound_trait_ref.skip_binder().args);
195-
// make `<T as Tr>::Effects: Compat<runtime>`
196-
let new_trait_ref =
197-
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::EffectsCompat, Some(span)), [
198-
ty::GenericArg::from(self_ty),
199-
compat_val.into(),
200-
]);
201-
self.clauses.push((bound_trait_ref.rebind(new_trait_ref).upcast(tcx), span));
20263
}
20364

20465
pub(crate) fn push_projection_bound(

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,9 @@ fn equate_intrinsic_type<'tcx>(
5858

5959
// the host effect param should be invisible as it shouldn't matter
6060
// whether effects is enabled for the intrinsic provider crate.
61-
let consts_count = if generics.host_effect_index.is_some() {
62-
own_counts.consts - 1
63-
} else {
64-
own_counts.consts
65-
};
66-
6761
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
6862
&& gen_count_ok(own_counts.types, n_tps, "type")
69-
&& gen_count_ok(consts_count, n_cts, "const")
63+
&& gen_count_ok(own_counts.consts, n_cts, "const")
7064
{
7165
let _ = check_function_signature(
7266
tcx,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

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

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

924919
if tcx.features().unsized_const_params() {

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+4-29
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
5353
param_def_id_to_index,
5454
has_self: opaque_ty_generics.has_self,
5555
has_late_bound_regions: opaque_ty_generics.has_late_bound_regions,
56-
host_effect_index: parent_generics.host_effect_index,
5756
};
5857
}
5958

@@ -161,7 +160,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
161160
param_def_id_to_index,
162161
has_self: generics.has_self,
163162
has_late_bound_regions: generics.has_late_bound_regions,
164-
host_effect_index: None,
165163
};
166164
} else {
167165
// HACK(eddyb) this provides the correct generics when
@@ -292,12 +290,10 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
292290
let has_self = opt_self.is_some();
293291
let mut parent_has_self = false;
294292
let mut own_start = has_self as u32;
295-
let mut host_effect_index = None;
296293
let parent_count = parent_def_id.map_or(0, |def_id| {
297294
let generics = tcx.generics_of(def_id);
298295
assert!(!has_self);
299296
parent_has_self = generics.has_self;
300-
host_effect_index = generics.host_effect_index;
301297
own_start = generics.count() as u32;
302298
generics.parent_count + generics.own_params.len()
303299
});
@@ -361,12 +357,8 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
361357
kind,
362358
})
363359
}
364-
GenericParamKind::Const { ty: _, default, is_host_effect, synthetic } => {
365-
if !matches!(allow_defaults, Defaults::Allowed)
366-
&& default.is_some()
367-
// `host` effect params are allowed to have defaults.
368-
&& !is_host_effect
369-
{
360+
GenericParamKind::Const { ty: _, default, synthetic } => {
361+
if !matches!(allow_defaults, Defaults::Allowed) && default.is_some() {
370362
tcx.dcx().span_err(
371363
param.span,
372364
"defaults for const parameters are only allowed in \
@@ -376,27 +368,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
376368

377369
let index = next_index();
378370

379-
if is_host_effect {
380-
if let Some(idx) = host_effect_index {
381-
tcx.dcx().span_delayed_bug(
382-
param.span,
383-
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"),
384-
);
385-
}
386-
387-
host_effect_index = Some(index as usize);
388-
}
389-
390371
Some(ty::GenericParamDef {
391372
index,
392373
name: param.name.ident().name,
393374
def_id: param.def_id.to_def_id(),
394375
pure_wrt_drop: param.pure_wrt_drop,
395-
kind: ty::GenericParamDefKind::Const {
396-
has_default: default.is_some(),
397-
is_host_effect,
398-
synthetic,
399-
},
376+
kind: ty::GenericParamDefKind::Const { has_default: default.is_some(), synthetic },
400377
})
401378
}
402379
}));
@@ -459,7 +436,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
459436
param_def_id_to_index,
460437
has_self: has_self || parent_has_self,
461438
has_late_bound_regions: has_late_bound_regions(tcx, node),
462-
host_effect_index,
463439
}
464440
}
465441

@@ -540,8 +516,7 @@ impl<'v> Visitor<'v> for AnonConstInParamTyDetector {
540516
type Result = ControlFlow<()>;
541517

542518
fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) -> Self::Result {
543-
if let GenericParamKind::Const { ty, default: _, is_host_effect: _, synthetic: _ } = p.kind
544-
{
519+
if let GenericParamKind::Const { ty, default: _, synthetic: _ } = p.kind {
545520
let prev = self.in_param_ty;
546521
self.in_param_ty = true;
547522
let res = self.visit_ty(ty);

0 commit comments

Comments
 (0)