Skip to content

Commit 4f6750b

Browse files
authored
Rollup merge of #131968 - compiler-errors:old-effect-handling, r=fee1-dead
Rip out old effects var handling code from traits Traits no longer have an effect parameter, so this removes logic associated with it. It also removes logic surrounding confirming `~const Destruct` bounds, which I added a looooong time ago, and which I don't feel like we need anymore -- if it needs to be added back, it should be rewritten :D cc `@fee1-dead`
2 parents 09a22b8 + 6f6f91a commit 4f6750b

File tree

14 files changed

+34
-491
lines changed

14 files changed

+34
-491
lines changed

compiler/rustc_const_eval/src/check_consts/qualifs.rs

+4-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,8 @@ 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+
// FIXME(effects): Reimplement const drop checking.
196+
NeedsDrop::in_any_value_of_ty(cx, ty)
242197
}
243198

244199
fn in_adt_inherently<'tcx>(

compiler/rustc_hir_typeck/src/callee.rs

+1-34
Original file line numberDiff line numberDiff line change
@@ -537,40 +537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
537537
//
538538
// This check is here because there is currently no way to express a trait bound for `FnDef` types only.
539539
if let ty::FnDef(def_id, _args) = *arg_ty.kind() {
540-
let fn_once_def_id =
541-
self.tcx.require_lang_item(hir::LangItem::FnOnce, Some(span));
542-
let fn_once_output_def_id =
543-
self.tcx.require_lang_item(hir::LangItem::FnOnceOutput, Some(span));
544-
if self.tcx.has_host_param(fn_once_def_id) {
545-
let const_param: ty::GenericArg<'tcx> =
546-
([self.tcx.consts.false_, self.tcx.consts.true_])[idx].into();
547-
self.register_predicate(traits::Obligation::new(
548-
self.tcx,
549-
self.misc(span),
550-
self.param_env,
551-
ty::TraitRef::new(self.tcx, fn_once_def_id, [
552-
arg_ty.into(),
553-
fn_sig.inputs()[0].into(),
554-
const_param,
555-
]),
556-
));
557-
558-
self.register_predicate(traits::Obligation::new(
559-
self.tcx,
560-
self.misc(span),
561-
self.param_env,
562-
ty::ProjectionPredicate {
563-
projection_term: ty::AliasTerm::new(
564-
self.tcx,
565-
fn_once_output_def_id,
566-
[arg_ty.into(), fn_sig.inputs()[0].into(), const_param],
567-
),
568-
term: fn_sig.output().into(),
569-
},
570-
));
571-
572-
self.select_obligations_where_possible(|_| {});
573-
} else if idx == 0 && !self.tcx.is_const_fn_raw(def_id) {
540+
if idx == 0 && !self.tcx.is_const_fn_raw(def_id) {
574541
self.dcx().emit_err(errors::ConstSelectMustBeConst { span });
575542
}
576543
} else {

compiler/rustc_middle/src/traits/select.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ pub enum SelectionCandidate<'tcx> {
161161

162162
/// Implementation of a `Fn`-family trait by one of the anonymous
163163
/// types generated for a fn pointer type (e.g., `fn(int) -> int`)
164-
FnPointerCandidate {
165-
fn_host_effect: ty::Const<'tcx>,
166-
},
164+
FnPointerCandidate,
167165

168166
TraitAliasCandidate,
169167

@@ -180,9 +178,6 @@ pub enum SelectionCandidate<'tcx> {
180178
BuiltinObjectCandidate,
181179

182180
BuiltinUnsizeCandidate,
183-
184-
/// Implementation of `const Destruct`, optionally from a custom `impl const Drop`.
185-
ConstDestructCandidate(Option<DefId>),
186181
}
187182

188183
/// The result of trait evaluation. The order is important

compiler/rustc_middle/src/ty/util.rs

-18
Original file line numberDiff line numberDiff line change
@@ -907,24 +907,6 @@ impl<'tcx> TyCtxt<'tcx> {
907907
}
908908
}
909909

910-
/// Constructs generic args for an item, optionally appending a const effect param type
911-
pub fn with_opt_host_effect_param(
912-
self,
913-
caller_def_id: LocalDefId,
914-
callee_def_id: DefId,
915-
args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
916-
) -> ty::GenericArgsRef<'tcx> {
917-
let generics = self.generics_of(callee_def_id);
918-
assert_eq!(generics.parent, None);
919-
920-
let opt_const_param = generics
921-
.host_effect_index
922-
.is_some()
923-
.then(|| ty::GenericArg::from(self.expected_host_effect_param_for_body(caller_def_id)));
924-
925-
self.mk_args_from_iter(args.into_iter().map(|arg| arg.into()).chain(opt_const_param))
926-
}
927-
928910
/// Expand any [weak alias types][weak] contained within the given `value`.
929911
///
930912
/// This should be used over other normalization routines in situations where

compiler/rustc_mir_build/src/build/matches/test.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
454454
};
455455

456456
let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
457-
let method = trait_method(
458-
self.tcx,
459-
eq_def_id,
460-
sym::eq,
461-
self.tcx.with_opt_host_effect_param(self.def_id, eq_def_id, [compare_ty, compare_ty]),
462-
);
457+
let method = trait_method(self.tcx, eq_def_id, sym::eq, [compare_ty, compare_ty]);
463458

464459
let bool_ty = self.tcx.types.bool;
465460
let eq_result = self.temp(bool_ty, source_info.span);

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
4343
}
4444

4545
struct ConstToPat<'tcx> {
46-
id: hir::HirId,
4746
span: Span,
4847
param_env: ty::ParamEnv<'tcx>,
4948

@@ -62,7 +61,6 @@ impl<'tcx> ConstToPat<'tcx> {
6261
) -> Self {
6362
trace!(?pat_ctxt.typeck_results.hir_owner);
6463
ConstToPat {
65-
id,
6664
span,
6765
infcx,
6866
param_env: pat_ctxt.param_env,
@@ -149,15 +147,7 @@ impl<'tcx> ConstToPat<'tcx> {
149147
tcx,
150148
ObligationCause::dummy(),
151149
self.param_env,
152-
ty::TraitRef::new_from_args(
153-
tcx,
154-
partial_eq_trait_id,
155-
tcx.with_opt_host_effect_param(
156-
tcx.hir().enclosing_body_owner(self.id),
157-
partial_eq_trait_id,
158-
[ty, ty],
159-
),
160-
),
150+
ty::TraitRef::new(tcx, partial_eq_trait_id, [ty, ty]),
161151
);
162152

163153
// This *could* accept a type that isn't actually `PartialEq`, because region bounds get

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3701,12 +3701,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
37013701
}
37023702
_ => None,
37033703
};
3704-
// Also add host param, if present
3705-
let host = self.tcx.generics_of(trait_pred.def_id()).host_effect_index.map(|idx| trait_pred.skip_binder().trait_ref.args[idx]);
37063704
let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate {
37073705
trait_ref: ty::TraitRef::new(self.tcx,
37083706
trait_pred.def_id(),
3709-
[field_ty].into_iter().chain(trait_args).chain(host),
3707+
[field_ty].into_iter().chain(trait_args),
37103708
),
37113709
..*tr
37123710
});

compiler/rustc_trait_selection/src/traits/project.rs

+6-30
Original file line numberDiff line numberDiff line change
@@ -1642,24 +1642,9 @@ fn confirm_fn_pointer_candidate<'cx, 'tcx>(
16421642
sig,
16431643
);
16441644

1645-
let host_effect_param = match *fn_type.kind() {
1646-
ty::FnDef(def_id, args) => tcx
1647-
.generics_of(def_id)
1648-
.host_effect_index
1649-
.map_or(tcx.consts.true_, |idx| args.const_at(idx)),
1650-
ty::FnPtr(..) => tcx.consts.true_,
1651-
_ => unreachable!("only expected FnPtr or FnDef in `confirm_fn_pointer_candidate`"),
1652-
};
1653-
1654-
confirm_callable_candidate(
1655-
selcx,
1656-
obligation,
1657-
sig,
1658-
util::TupleArgumentsFlag::Yes,
1659-
host_effect_param,
1660-
)
1661-
.with_addl_obligations(nested)
1662-
.with_addl_obligations(obligations)
1645+
confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
1646+
.with_addl_obligations(nested)
1647+
.with_addl_obligations(obligations)
16631648
}
16641649

16651650
fn confirm_closure_candidate<'cx, 'tcx>(
@@ -1739,24 +1724,16 @@ fn confirm_closure_candidate<'cx, 'tcx>(
17391724

17401725
debug!(?obligation, ?closure_sig, ?obligations, "confirm_closure_candidate");
17411726

1742-
confirm_callable_candidate(
1743-
selcx,
1744-
obligation,
1745-
closure_sig,
1746-
util::TupleArgumentsFlag::No,
1747-
// FIXME(effects): This doesn't handle const closures correctly!
1748-
selcx.tcx().consts.true_,
1749-
)
1750-
.with_addl_obligations(nested)
1751-
.with_addl_obligations(obligations)
1727+
confirm_callable_candidate(selcx, obligation, closure_sig, util::TupleArgumentsFlag::No)
1728+
.with_addl_obligations(nested)
1729+
.with_addl_obligations(obligations)
17521730
}
17531731

17541732
fn confirm_callable_candidate<'cx, 'tcx>(
17551733
selcx: &mut SelectionContext<'cx, 'tcx>,
17561734
obligation: &ProjectionTermObligation<'tcx>,
17571735
fn_sig: ty::PolyFnSig<'tcx>,
17581736
flag: util::TupleArgumentsFlag,
1759-
fn_host_effect: ty::Const<'tcx>,
17601737
) -> Progress<'tcx> {
17611738
let tcx = selcx.tcx();
17621739

@@ -1771,7 +1748,6 @@ fn confirm_callable_candidate<'cx, 'tcx>(
17711748
obligation.predicate.self_ty(),
17721749
fn_sig,
17731750
flag,
1774-
fn_host_effect,
17751751
)
17761752
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
17771753
projection_term: ty::AliasTerm::new_from_args(tcx, fn_once_output_def_id, trait_ref.args),

0 commit comments

Comments
 (0)