Skip to content

Commit 9e1d78d

Browse files
Remove associated type based effects logic
1 parent 7ed1a51 commit 9e1d78d

File tree

83 files changed

+115
-2002
lines changed

Some content is hidden

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

83 files changed

+115
-2002
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_const_eval/src/check_consts/qualifs.rs

+3-49
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ use rustc_errors::ErrorGuaranteed;
66
use rustc_hir::LangItem;
77
use rustc_infer::infer::TyCtxtInferExt;
88
use rustc_middle::mir::*;
9-
use rustc_middle::traits::BuiltinImplSource;
109
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty};
1110
use rustc_middle::{bug, mir};
12-
use rustc_trait_selection::traits::{
13-
ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext,
14-
};
15-
use tracing::{instrument, trace};
11+
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
12+
use tracing::instrument;
1613

1714
use super::ConstCx;
1815

@@ -195,50 +192,7 @@ impl Qualif for NeedsNonConstDrop {
195192
return false;
196193
}
197194

198-
// FIXME(effects): If `destruct` is not a `const_trait`,
199-
// or effects are disabled in this crate, then give up.
200-
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, Some(cx.body.span));
201-
if !cx.tcx.has_host_param(destruct_def_id) || !cx.tcx.features().effects {
202-
return NeedsDrop::in_any_value_of_ty(cx, ty);
203-
}
204-
205-
let obligation = Obligation::new(
206-
cx.tcx,
207-
ObligationCause::dummy_with_span(cx.body.span),
208-
cx.param_env,
209-
ty::TraitRef::new(cx.tcx, destruct_def_id, [
210-
ty::GenericArg::from(ty),
211-
ty::GenericArg::from(cx.tcx.expected_host_effect_param_for_body(cx.def_id())),
212-
]),
213-
);
214-
215-
let infcx = cx.tcx.infer_ctxt().build();
216-
let mut selcx = SelectionContext::new(&infcx);
217-
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
218-
// If we couldn't select a const destruct candidate, then it's bad
219-
return true;
220-
};
221-
222-
trace!(?impl_src);
223-
224-
if !matches!(
225-
impl_src,
226-
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_)
227-
) {
228-
// If our const destruct candidate is not ConstDestruct or implied by the param env,
229-
// then it's bad
230-
return true;
231-
}
232-
233-
if impl_src.borrow_nested_obligations().is_empty() {
234-
return false;
235-
}
236-
237-
// If we had any errors, then it's bad
238-
let ocx = ObligationCtxt::new(&infcx);
239-
ocx.register_obligations(impl_src.nested_obligations());
240-
let errors = ocx.select_all_or_error();
241-
!errors.is_empty()
195+
NeedsDrop::in_any_value_of_ty(cx, ty)
242196
}
243197

244198
fn in_adt_inherently<'tcx>(

compiler/rustc_feature/src/builtin_attrs.rs

-4
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
840840
rustc_const_panic_str, Normal, template!(Word), WarnFollowing,
841841
EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
842842
),
843-
rustc_attr!(
844-
rustc_runtime, Normal, template!(Word), WarnFollowing,
845-
EncodeCrossCrate::No, INTERNAL_UNSTABLE
846-
),
847843

848844
// ==========================================================================
849845
// Internal attributes, Layout related:

compiler/rustc_hir/src/hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ pub enum GenericParamKind<'hir> {
583583
ty: &'hir Ty<'hir>,
584584
/// Optional default value for the const generic param
585585
default: Option<&'hir ConstArg<'hir>>,
586-
is_host_effect: bool,
587586
synthetic: bool,
588587
},
589588
}

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

-138
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: ty::BoundConstness,
55-
predicate_filter: PredicateFilter,
5648
) {
5749
let clause = (
5850
bound_trait_ref
@@ -68,136 +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-
(_, ty::BoundConstness::Const) => tcx.consts.false_,
92-
// body owners that can have trait bounds
93-
(DefKind::Const | DefKind::Fn | DefKind::AssocFn, ty::BoundConstness::ConstIfConst) => {
94-
tcx.expected_host_effect_param_for_body(defining_def_id)
95-
}
96-
97-
(_, ty::BoundConstness::NotConst) => {
98-
if !tcx.is_const_trait(bound_trait_ref.def_id()) {
99-
return;
100-
}
101-
tcx.consts.true_
102-
}
103-
(DefKind::Trait, ty::BoundConstness::ConstIfConst) => {
104-
// we are in a trait, where `bound_trait_ref` could be:
105-
// (1) a super trait `trait Foo: ~const Bar`.
106-
// - This generates `<Self as Foo>::Effects: TyCompat<<Self as Bar>::Effects>`
107-
//
108-
// (2) a where clause `where for<..> Something: ~const Bar`.
109-
// - This generates `for<..> <Self as Foo>::Effects: TyCompat<<Something as Bar>::Effects>`
110-
let Some(own_fx) = tcx.associated_type_for_effects(defining_def_id) else {
111-
tcx.dcx().span_delayed_bug(span, "should not have allowed `~const` on a trait that doesn't have `#[const_trait]`");
112-
return;
113-
};
114-
let own_fx_ty = Ty::new_projection(
115-
tcx,
116-
own_fx,
117-
ty::GenericArgs::identity_for_item(tcx, own_fx),
118-
);
119-
let Some(their_fx) = tcx.associated_type_for_effects(bound_trait_ref.def_id())
120-
else {
121-
tcx.dcx().span_delayed_bug(span, "`~const` on trait without Effects assoc");
122-
return;
123-
};
124-
let their_fx_ty =
125-
Ty::new_projection(tcx, their_fx, bound_trait_ref.skip_binder().args);
126-
let compat = tcx.require_lang_item(LangItem::EffectsTyCompat, Some(span));
127-
let clause = bound_trait_ref
128-
.map_bound(|_| {
129-
let trait_ref = ty::TraitRef::new(tcx, compat, [own_fx_ty, their_fx_ty]);
130-
ty::ClauseKind::Trait(ty::TraitPredicate {
131-
trait_ref,
132-
polarity: ty::PredicatePolarity::Positive,
133-
})
134-
})
135-
.upcast(tcx);
136-
137-
self.clauses.push((clause, span));
138-
return;
139-
}
140-
141-
(DefKind::Impl { of_trait: true }, ty::BoundConstness::ConstIfConst) => {
142-
// this is a where clause on an impl header.
143-
// push `<T as Tr>::Effects` into the set for the `Min` bound.
144-
let Some(assoc) = tcx.associated_type_for_effects(bound_trait_ref.def_id()) else {
145-
tcx.dcx().span_delayed_bug(span, "`~const` on trait without Effects assoc");
146-
return;
147-
};
148-
149-
let ty = bound_trait_ref
150-
.map_bound(|trait_ref| Ty::new_projection(tcx, assoc, trait_ref.args));
151-
152-
// When the user has written `for<'a, T> X<'a, T>: ~const Foo`, replace the
153-
// binders to dummy ones i.e. `X<'static, ()>` so they can be referenced in
154-
// the `Min` associated type properly (which doesn't allow using `for<>`)
155-
// This should work for any bound variables as long as they don't have any
156-
// bounds e.g. `for<T: Trait>`.
157-
// FIXME(effects) reconsider this approach to allow compatibility with `for<T: Tr>`
158-
let ty = tcx.replace_bound_vars_uncached(ty, FnMutDelegate {
159-
regions: &mut |_| tcx.lifetimes.re_static,
160-
types: &mut |_| tcx.types.unit,
161-
consts: &mut |_| unimplemented!("`~const` does not support const binders"),
162-
});
163-
164-
self.effects_min_tys.insert(ty, span);
165-
return;
166-
}
167-
// for
168-
// ```
169-
// trait Foo { type Bar: ~const Trait }
170-
// ```
171-
// ensure that `<Self::Bar as Trait>::Effects: TyCompat<Self::Effects>`.
172-
//
173-
// FIXME(effects) this is equality for now, which wouldn't be helpful for a non-const implementor
174-
// that uses a `Bar` that implements `Trait` with `Maybe` effects.
175-
(DefKind::AssocTy, ty::BoundConstness::ConstIfConst) => {
176-
// FIXME(effects): implement this
177-
return;
178-
}
179-
// probably illegal in this position.
180-
(_, ty::BoundConstness::ConstIfConst) => {
181-
tcx.dcx().span_delayed_bug(span, "invalid `~const` encountered");
182-
return;
183-
}
184-
};
185-
// create a new projection type `<T as Tr>::Effects`
186-
let Some(assoc) = tcx.associated_type_for_effects(bound_trait_ref.def_id()) else {
187-
tcx.dcx().span_delayed_bug(
188-
span,
189-
"`~const` trait bound has no effect assoc yet no errors encountered?",
190-
);
191-
return;
192-
};
193-
let self_ty = Ty::new_projection(tcx, assoc, bound_trait_ref.skip_binder().args);
194-
// make `<T as Tr>::Effects: Compat<runtime>`
195-
let new_trait_ref =
196-
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::EffectsCompat, Some(span)), [
197-
ty::GenericArg::from(self_ty),
198-
compat_val.into(),
199-
]);
200-
self.clauses.push((bound_trait_ref.rebind(new_trait_ref).upcast(tcx), span));
20163
}
20264

20365
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 {

0 commit comments

Comments
 (0)