Skip to content

Commit 20747af

Browse files
committed
Auto merge of #114202 - fee1-dead-contrib:rm-constness-2, r=oli-obk
Remove `constness` from `TraitPredicate` Any ICEs or compiler errors created by this PR are expected and intended to be fixed in the future. r? `@oli-obk` cc #110395
2 parents 7637653 + 4fec845 commit 20747af

File tree

90 files changed

+446
-390
lines changed

Some content is hidden

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

90 files changed

+446
-390
lines changed

Diff for: compiler/rustc_borrowck/src/type_check/canonical.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9090
) {
9191
self.prove_predicate(
9292
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Trait(
93-
ty::TraitPredicate {
94-
trait_ref,
95-
constness: ty::BoundConstness::NotConst,
96-
polarity: ty::ImplPolarity::Positive,
97-
},
93+
ty::TraitPredicate { trait_ref, polarity: ty::ImplPolarity::Positive },
9894
))),
9995
locations,
10096
category,

Diff for: compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
746746
}
747747

748748
// Attempting to call a trait method?
749+
// FIXME(effects) do we need this?
749750
if let Some(trait_id) = tcx.trait_of_item(callee) {
750751
trace!("attempting to call a trait method");
751752
if !self.tcx.features().const_trait_impl {
@@ -761,7 +762,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
761762
}
762763

763764
let trait_ref = TraitRef::from_method(tcx, trait_id, fn_args);
764-
let trait_ref = trait_ref.with_constness(ty::BoundConstness::ConstIfConst);
765765
let obligation =
766766
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
767767

Diff for: compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ impl Qualif for NeedsNonConstDrop {
155155
return false;
156156
}
157157

158+
// FIXME(effects) constness
158159
let obligation = Obligation::new(
159160
cx.tcx,
160161
ObligationCause::dummy_with_span(cx.body.span),
161162
cx.param_env,
162-
ty::TraitRef::from_lang_item(cx.tcx, LangItem::Destruct, cx.body.span, [ty])
163-
.with_constness(ty::BoundConstness::ConstIfConst),
163+
ty::TraitRef::from_lang_item(cx.tcx, LangItem::Destruct, cx.body.span, [ty]),
164164
);
165165

166166
let infcx = cx.tcx.infer_ctxt().build();

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
713713
);
714714

715715
debug!(?poly_trait_ref, ?assoc_bindings);
716-
bounds.push_trait_bound(tcx, poly_trait_ref, span, constness, polarity);
716+
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
717717

718718
let mut dup_bindings = FxHashMap::default();
719719
for binding in &assoc_bindings {

Diff for: compiler/rustc_hir_analysis/src/astconv/object_safety.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
6262
match bound_pred.skip_binder() {
6363
ty::ClauseKind::Trait(trait_pred) => {
6464
assert_eq!(trait_pred.polarity, ty::ImplPolarity::Positive);
65-
trait_bounds.push((
66-
bound_pred.rebind(trait_pred.trait_ref),
67-
span,
68-
trait_pred.constness,
69-
));
65+
trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), span));
7066
}
7167
ty::ClauseKind::Projection(proj) => {
7268
projection_bounds.push((bound_pred.rebind(proj), span));
@@ -86,7 +82,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
8682
// Expand trait aliases recursively and check that only one regular (non-auto) trait
8783
// is used and no 'maybe' bounds are used.
8884
let expanded_traits =
89-
traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b, _)| (a, b)));
85+
traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b)| (a, b)));
9086

9187
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits
9288
.filter(|i| i.trait_ref().self_ty().skip_binder() == dummy_self)
@@ -126,7 +122,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
126122
if regular_traits.is_empty() && auto_traits.is_empty() {
127123
let trait_alias_span = trait_bounds
128124
.iter()
129-
.map(|&(trait_ref, _, _)| trait_ref.def_id())
125+
.map(|&(trait_ref, _)| trait_ref.def_id())
130126
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
131127
.map(|trait_ref| tcx.def_span(trait_ref));
132128
let reported =
@@ -157,10 +153,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
157153

158154
let regular_traits_refs_spans = trait_bounds
159155
.into_iter()
160-
.filter(|(trait_ref, _, _)| !tcx.trait_is_auto(trait_ref.def_id()));
156+
.filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
161157

162-
for (base_trait_ref, span, constness) in regular_traits_refs_spans {
163-
assert_eq!(constness, ty::BoundConstness::NotConst);
158+
for (base_trait_ref, span) in regular_traits_refs_spans {
164159
let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx);
165160
for pred in traits::elaborate(tcx, [base_pred]) {
166161
debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred);

Diff for: compiler/rustc_hir_analysis/src/bounds.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ impl<'tcx> Bounds<'tcx> {
4242
tcx: TyCtxt<'tcx>,
4343
trait_ref: ty::PolyTraitRef<'tcx>,
4444
span: Span,
45-
constness: ty::BoundConstness,
4645
polarity: ty::ImplPolarity,
4746
) {
4847
self.clauses.push((
4948
trait_ref
5049
.map_bound(|trait_ref| {
51-
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, constness, polarity })
50+
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
5251
})
5352
.to_predicate(tcx),
5453
span,

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
194194
// We match on both `ty::ImplPolarity` and `ast::ImplPolarity` just to get the `!` span.
195195
match (tcx.impl_polarity(def_id), impl_.polarity) {
196196
(ty::ImplPolarity::Positive, _) => {
197-
check_impl(tcx, item, impl_.self_ty, &impl_.of_trait, impl_.constness);
197+
check_impl(tcx, item, impl_.self_ty, &impl_.of_trait);
198198
}
199199
(ty::ImplPolarity::Negative, ast::ImplPolarity::Negative(span)) => {
200200
// FIXME(#27579): what amount of WF checking do we need for neg impls?
@@ -1191,7 +1191,6 @@ fn check_impl<'tcx>(
11911191
item: &'tcx hir::Item<'tcx>,
11921192
ast_self_ty: &hir::Ty<'_>,
11931193
ast_trait_ref: &Option<hir::TraitRef<'_>>,
1194-
constness: hir::Constness,
11951194
) {
11961195
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
11971196
match ast_trait_ref {
@@ -1205,14 +1204,8 @@ fn check_impl<'tcx>(
12051204
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
12061205
trait_ref,
12071206
);
1208-
let trait_pred = ty::TraitPredicate {
1209-
trait_ref,
1210-
constness: match constness {
1211-
hir::Constness::Const => ty::BoundConstness::ConstIfConst,
1212-
hir::Constness::NotConst => ty::BoundConstness::NotConst,
1213-
},
1214-
polarity: ty::ImplPolarity::Positive,
1215-
};
1207+
let trait_pred =
1208+
ty::TraitPredicate { trait_ref, polarity: ty::ImplPolarity::Positive };
12161209
let mut obligations = traits::wf::trait_obligations(
12171210
wfcx.infcx,
12181211
wfcx.param_env,

Diff for: compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_hir::intravisit::{self, Visitor};
1111
use rustc_middle::ty::{self, Ty, TyCtxt};
1212
use rustc_middle::ty::{GenericPredicates, Generics, ImplTraitInTraitData, ToPredicate};
13-
use rustc_span::symbol::{sym, Ident};
13+
use rustc_span::symbol::Ident;
1414
use rustc_span::{Span, Symbol, DUMMY_SP};
1515

1616
/// Returns a list of all type predicates (explicit and implicit) for the definition with
@@ -37,17 +37,10 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
3737
// from the trait itself that *shouldn't* be shown as the source of
3838
// an obligation and instead be skipped. Otherwise we'd use
3939
// `tcx.def_span(def_id);`
40-
41-
let constness = if tcx.has_attr(def_id, sym::const_trait) {
42-
ty::BoundConstness::ConstIfConst
43-
} else {
44-
ty::BoundConstness::NotConst
45-
};
46-
4740
let span = rustc_span::DUMMY_SP;
4841
result.predicates =
4942
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
50-
ty::TraitRef::identity(tcx, def_id).with_constness(constness).to_predicate(tcx),
43+
ty::TraitRef::identity(tcx, def_id).to_predicate(tcx),
5144
span,
5245
))));
5346
}
@@ -204,7 +197,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
204197
// (see below). Recall that a default impl is not itself an impl, but rather a
205198
// set of defaults that can be incorporated into another impl.
206199
if let Some(trait_ref) = is_default_impl_trait {
207-
predicates.insert((trait_ref.without_const().to_predicate(tcx), tcx.def_span(def_id)));
200+
predicates.insert((trait_ref.to_predicate(tcx), tcx.def_span(def_id)));
208201
}
209202

210203
// Collect the region predicates that were declared inline as
@@ -777,8 +770,7 @@ pub(super) fn type_param_predicates(
777770
if param_id == item_hir_id {
778771
let identity_trait_ref =
779772
ty::TraitRef::identity(tcx, item_def_id.to_def_id());
780-
extend =
781-
Some((identity_trait_ref.without_const().to_predicate(tcx), item.span));
773+
extend = Some((identity_trait_ref.to_predicate(tcx), item.span));
782774
}
783775
generics
784776
}

Diff for: compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+4-38
Original file line numberDiff line numberDiff line change
@@ -431,45 +431,13 @@ fn check_predicates<'tcx>(
431431
///
432432
/// So we make that check in this function and try to raise a helpful error message.
433433
fn trait_predicates_eq<'tcx>(
434-
tcx: TyCtxt<'tcx>,
434+
_tcx: TyCtxt<'tcx>,
435435
predicate1: ty::Predicate<'tcx>,
436436
predicate2: ty::Predicate<'tcx>,
437-
span: Span,
437+
_span: Span,
438438
) -> bool {
439-
let pred1_kind = predicate1.kind().skip_binder();
440-
let pred2_kind = predicate2.kind().skip_binder();
441-
let (trait_pred1, trait_pred2) = match (pred1_kind, pred2_kind) {
442-
(
443-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred1)),
444-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred2)),
445-
) => (pred1, pred2),
446-
// Just use plain syntactic equivalence if either of the predicates aren't
447-
// trait predicates or have bound vars.
448-
_ => return predicate1 == predicate2,
449-
};
450-
451-
let predicates_equal_modulo_constness = {
452-
let pred1_unconsted =
453-
ty::TraitPredicate { constness: ty::BoundConstness::NotConst, ..trait_pred1 };
454-
let pred2_unconsted =
455-
ty::TraitPredicate { constness: ty::BoundConstness::NotConst, ..trait_pred2 };
456-
pred1_unconsted == pred2_unconsted
457-
};
458-
459-
if !predicates_equal_modulo_constness {
460-
return false;
461-
}
462-
463-
// Check that the predicate on the specializing impl is at least as const as
464-
// the one on the base.
465-
match (trait_pred2.constness, trait_pred1.constness) {
466-
(ty::BoundConstness::ConstIfConst, ty::BoundConstness::NotConst) => {
467-
tcx.sess.emit_err(errors::MissingTildeConst { span });
468-
}
469-
_ => {}
470-
}
471-
472-
true
439+
// FIXME(effects)
440+
predicate1 == predicate2
473441
}
474442

475443
#[instrument(level = "debug", skip(tcx))]
@@ -482,7 +450,6 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
482450
// items.
483451
ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
484452
trait_ref,
485-
constness: _,
486453
polarity: _,
487454
})) => {
488455
if !matches!(
@@ -536,7 +503,6 @@ fn trait_predicate_kind<'tcx>(
536503
match predicate.kind().skip_binder() {
537504
ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
538505
trait_ref,
539-
constness: _,
540506
polarity: _,
541507
})) => Some(tcx.trait_def(trait_ref.def_id).specialization_kind),
542508
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))

Diff for: compiler/rustc_hir_analysis/src/variance/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
156156
match pred.kind().skip_binder() {
157157
ty::ClauseKind::Trait(ty::TraitPredicate {
158158
trait_ref: ty::TraitRef { def_id: _, args, .. },
159-
constness: _,
160159
polarity: _,
161160
}) => {
162161
for subst in &args[1..] {

Diff for: compiler/rustc_hir_typeck/src/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2988,7 +2988,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29882988
ty::Binder::dummy(ty::TraitPredicate {
29892989
trait_ref: impl_trait_ref,
29902990
polarity: ty::ImplPolarity::Positive,
2991-
constness: ty::BoundConstness::NotConst,
29922991
}),
29932992
|derived| {
29942993
traits::ImplDerivedObligation(Box::new(

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1461,10 +1461,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14611461
param_env,
14621462
bounds,
14631463
) {
1464-
// N.B. We are remapping all predicates to non-const since we don't know if we just
1465-
// want them as function pointers or we are calling them from a const-context. The
1466-
// actual checking will occur in `rustc_const_eval::transform::check_consts`.
1467-
self.register_predicate(obligation.without_const(self.tcx));
1464+
self.register_predicate(obligation);
14681465
}
14691466
}
14701467

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1856,19 +1856,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18561856
if self.adjust_fulfillment_error_for_expr_obligation(error)
18571857
|| before_span != error.obligation.cause.span
18581858
{
1859-
// Store both the predicate and the predicate *without constness*
1860-
// since sometimes we instantiate and check both of these in a
1861-
// method call, for example.
18621859
remap_cause.insert((
18631860
before_span,
18641861
error.obligation.predicate,
18651862
error.obligation.cause.clone(),
18661863
));
1867-
remap_cause.insert((
1868-
before_span,
1869-
error.obligation.predicate.without_const(self.tcx),
1870-
error.obligation.cause.clone(),
1871-
));
18721864
} else {
18731865
// If it failed to be adjusted once around, it may be adjusted
18741866
// via the "remap cause" mapping the second time...

Diff for: compiler/rustc_hir_typeck/src/method/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
341341

342342
// Construct an obligation
343343
let poly_trait_ref = ty::Binder::dummy(trait_ref);
344-
(
345-
traits::Obligation::new(
346-
self.tcx,
347-
cause,
348-
self.param_env,
349-
poly_trait_ref.without_const(),
350-
),
351-
args,
352-
)
344+
(traits::Obligation::new(self.tcx, cause, self.param_env, poly_trait_ref), args)
353345
}
354346

355347
/// `lookup_method_in_trait` is used for overloaded operators.

Diff for: compiler/rustc_hir_typeck/src/method/probe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1599,8 +1599,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15991599
}
16001600
}
16011601
}
1602-
let predicate =
1603-
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx);
1602+
let predicate = ty::Binder::dummy(trait_ref).to_predicate(self.tcx);
16041603
parent_pred = Some(predicate);
16051604
let obligation =
16061605
traits::Obligation::new(self.tcx, cause.clone(), self.param_env, predicate);

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9494
span,
9595
self.body_id,
9696
self.param_env,
97-
poly_trait_ref.without_const(),
97+
poly_trait_ref,
9898
);
9999
self.predicate_may_hold(&obligation)
100100
})

Diff for: compiler/rustc_infer/src/traits/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
2525
cause,
2626
recursion_depth: 0,
2727
param_env,
28-
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(infcx.tcx),
28+
predicate: ty::Binder::dummy(trait_ref).to_predicate(infcx.tcx),
2929
},
3030
);
3131
}

Diff for: compiler/rustc_infer/src/traits/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ impl<'tcx> PredicateObligation<'tcx> {
7777
recursion_depth: self.recursion_depth,
7878
})
7979
}
80-
81-
pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> PredicateObligation<'tcx> {
82-
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() {
83-
self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred.without_const()))));
84-
}
85-
self
86-
}
8780
}
8881

8982
impl<'tcx> PolyTraitObligation<'tcx> {

Diff for: compiler/rustc_infer/src/traits/util.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
264264
};
265265

266266
let obligations =
267-
predicates.predicates.iter().enumerate().map(|(index, &(mut clause, span))| {
268-
// when parent predicate is non-const, elaborate it to non-const predicates.
269-
if data.constness == ty::BoundConstness::NotConst {
270-
clause = clause.without_const(tcx);
271-
}
267+
predicates.predicates.iter().enumerate().map(|(index, &(clause, span))| {
272268
elaboratable.child_with_derived_cause(
273269
clause.subst_supertrait(tcx, &bound_predicate.rebind(data.trait_ref)),
274270
span,

0 commit comments

Comments
 (0)