Skip to content

Commit 612a114

Browse files
committed
remove constness from TraitPredicate
1 parent c026d6a commit 612a114

File tree

47 files changed

+154
-318
lines changed

Some content is hidden

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

47 files changed

+154
-318
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9292
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Trait(
9393
ty::TraitPredicate {
9494
trait_ref,
95-
constness: ty::BoundConstness::NotConst,
9695
polarity: ty::ImplPolarity::Positive,
9796
},
9897
))),

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
754754
return;
755755
}
756756

757+
// TODO this needs constness
757758
let trait_ref = TraitRef::from_method(tcx, trait_id, fn_args);
758-
let trait_ref = trait_ref.with_constness(ty::BoundConstness::ConstIfConst);
759759
let obligation =
760760
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
761761

@@ -766,7 +766,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
766766
};
767767

768768
match implsrc {
769-
Ok(Some(ImplSource::Param(_, ty::BoundConstness::ConstIfConst))) => {
769+
// TODO hmm?
770+
Ok(Some(ImplSource::Param(_))) => {
770771
debug!(
771772
"const_trait_impl: provided {:?} via where-clause in {:?}",
772773
trait_ref, param_env

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ impl Qualif for NeedsNonConstDrop {
157157
cx.tcx,
158158
ObligationCause::dummy_with_span(cx.body.span),
159159
cx.param_env,
160-
ty::TraitRef::from_lang_item(cx.tcx, LangItem::Destruct, cx.body.span, [ty])
161-
.with_constness(ty::BoundConstness::ConstIfConst),
160+
// TODO this needs constness
161+
ty::TraitRef::from_lang_item(cx.tcx, LangItem::Destruct, cx.body.span, [ty]),
162162
);
163163

164164
let infcx = cx.tcx.infer_ctxt().build();
@@ -172,7 +172,7 @@ impl Qualif for NeedsNonConstDrop {
172172

173173
if !matches!(
174174
impl_src,
175-
ImplSource::Builtin(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
175+
ImplSource::Builtin(_) | ImplSource::Param(_)
176176
) {
177177
// If our const destruct candidate is not ConstDestruct or implied by the param env,
178178
// then it's bad

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
356356
generic_args: &'a hir::GenericArgs<'_>,
357357
infer_args: bool,
358358
self_ty: Option<Ty<'tcx>>,
359+
// TODO actually use this constness
359360
constness: ty::BoundConstness,
360361
) -> (GenericArgsRef<'tcx>, GenericArgCountResult) {
361362
// If the type is parameterized by this region, then replace this
@@ -707,13 +708,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
707708

708709
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
709710

711+
// TODO this needs constness
710712
let poly_trait_ref = ty::Binder::bind_with_vars(
711713
ty::TraitRef::new(tcx, trait_def_id, generic_args),
712714
bound_vars,
713715
);
714716

715717
debug!(?poly_trait_ref, ?assoc_bindings);
716-
bounds.push_trait_bound(tcx, poly_trait_ref, span, constness, polarity);
718+
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
717719

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

compiler/rustc_hir_analysis/src/astconv/object_safety.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
6565
trait_bounds.push((
6666
bound_pred.rebind(trait_pred.trait_ref),
6767
span,
68-
trait_pred.constness,
6968
));
7069
}
7170
ty::ClauseKind::Projection(proj) => {
@@ -86,7 +85,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
8685
// Expand trait aliases recursively and check that only one regular (non-auto) trait
8786
// is used and no 'maybe' bounds are used.
8887
let expanded_traits =
89-
traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b, _)| (a, b)));
88+
traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b)| (a, b)));
9089

9190
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits
9291
.filter(|i| i.trait_ref().self_ty().skip_binder() == dummy_self)
@@ -126,7 +125,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
126125
if regular_traits.is_empty() && auto_traits.is_empty() {
127126
let trait_alias_span = trait_bounds
128127
.iter()
129-
.map(|&(trait_ref, _, _)| trait_ref.def_id())
128+
.map(|&(trait_ref, _)| trait_ref.def_id())
130129
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
131130
.map(|trait_ref| tcx.def_span(trait_ref));
132131
let reported =
@@ -157,10 +156,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
157156

158157
let regular_traits_refs_spans = trait_bounds
159158
.into_iter()
160-
.filter(|(trait_ref, _, _)| !tcx.trait_is_auto(trait_ref.def_id()));
159+
.filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
161160

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

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,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ fn check_impl<'tcx>(
11871187
// `#[rustc_reservation_impl]` impls are not real impls and
11881188
// therefore don't need to be WF (the trait's `Self: Trait` predicate
11891189
// won't hold).
1190+
// TODO constness?
11901191
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
11911192
let trait_ref = wfcx.normalize(
11921193
ast_trait_ref.path.span,
@@ -1195,10 +1196,6 @@ fn check_impl<'tcx>(
11951196
);
11961197
let trait_pred = ty::TraitPredicate {
11971198
trait_ref,
1198-
constness: match constness {
1199-
hir::Constness::Const => ty::BoundConstness::ConstIfConst,
1200-
hir::Constness::NotConst => ty::BoundConstness::NotConst,
1201-
},
12021199
polarity: ty::ImplPolarity::Positive,
12031200
};
12041201
let mut obligations = traits::wf::trait_obligations(

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,10 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
3838
// an obligation and instead be skipped. Otherwise we'd use
3939
// `tcx.def_span(def_id);`
4040

41-
let constness = if tcx.has_attr(def_id, sym::const_trait) {
42-
ty::BoundConstness::ConstIfConst
43-
} else {
44-
ty::BoundConstness::NotConst
45-
};
46-
4741
let span = rustc_span::DUMMY_SP;
4842
result.predicates =
4943
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),
44+
ty::TraitRef::identity(tcx, def_id).to_predicate(tcx),
5145
span,
5246
))));
5347
}
@@ -203,7 +197,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
203197
// (see below). Recall that a default impl is not itself an impl, but rather a
204198
// set of defaults that can be incorporated into another impl.
205199
if let Some(trait_ref) = is_default_impl_trait {
206-
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)));
207201
}
208202

209203
// Collect the region predicates that were declared inline as
@@ -776,7 +770,7 @@ pub(super) fn type_param_predicates(
776770
let identity_trait_ref =
777771
ty::TraitRef::identity(tcx, item_def_id.to_def_id());
778772
extend =
779-
Some((identity_trait_ref.without_const().to_predicate(tcx), item.span));
773+
Some((identity_trait_ref.to_predicate(tcx), item.span));
780774
}
781775
generics
782776
}

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -448,26 +448,22 @@ fn trait_predicates_eq<'tcx>(
448448
_ => return predicate1 == predicate2,
449449
};
450450

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-
};
451+
// TODO
452+
let predicates_equal_modulo_constness = predicate1 == predicate2;
458453

459454
if !predicates_equal_modulo_constness {
460455
return false;
461456
}
462457

463458
// Check that the predicate on the specializing impl is at least as const as
464459
// the one on the base.
465-
match (trait_pred2.constness, trait_pred1.constness) {
460+
// TODO
461+
/*match (trait_pred2.constness, trait_pred1.constness) {
466462
(ty::BoundConstness::ConstIfConst, ty::BoundConstness::NotConst) => {
467463
tcx.sess.emit_err(errors::MissingTildeConst { span });
468464
}
469465
_ => {}
470-
}
466+
}*/
471467

472468
true
473469
}
@@ -482,7 +478,6 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
482478
// items.
483479
ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
484480
trait_ref,
485-
constness: _,
486481
polarity: _,
487482
})) => {
488483
if !matches!(
@@ -536,7 +531,6 @@ fn trait_predicate_kind<'tcx>(
536531
match predicate.kind().skip_binder() {
537532
ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
538533
trait_ref,
539-
constness: _,
540534
polarity: _,
541535
})) => Some(tcx.trait_def(trait_ref.def_id).specialization_kind),
542536
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))

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..] {

compiler/rustc_hir_typeck/src/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2992,7 +2992,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29922992
ty::Binder::dummy(ty::TraitPredicate {
29932993
trait_ref: impl_trait_ref,
29942994
polarity: ty::ImplPolarity::Positive,
2995-
constness: ty::BoundConstness::NotConst,
29962995
}),
29972996
|derived| {
29982997
traits::ImplDerivedObligation(Box::new(

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14661466
// N.B. We are remapping all predicates to non-const since we don't know if we just
14671467
// want them as function pointers or we are calling them from a const-context. The
14681468
// actual checking will occur in `rustc_const_eval::transform::check_consts`.
1469-
self.register_predicate(obligation.without_const(self.tcx));
1469+
// TODO: HMM?
1470+
self.register_predicate(obligation);
14701471
}
14711472
}
14721473

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1875,11 +1875,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18751875
error.obligation.predicate,
18761876
error.obligation.cause.clone(),
18771877
));
1878-
remap_cause.insert((
1878+
// TODO: UM WHAT?
1879+
1880+
/* remap_cause.insert((
18791881
before_span,
18801882
error.obligation.predicate.without_const(self.tcx),
18811883
error.obligation.cause.clone(),
1882-
));
1884+
)); */
18831885
} else {
18841886
// If it failed to be adjusted once around, it may be adjusted
18851887
// via the "remap cause" mapping the second time...

compiler/rustc_hir_typeck/src/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
346346
self.tcx,
347347
cause,
348348
self.param_env,
349-
poly_trait_ref.without_const(),
349+
poly_trait_ref,
350350
),
351351
args,
352352
)

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16001600
}
16011601
}
16021602
let predicate =
1603-
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx);
1603+
ty::Binder::dummy(trait_ref).to_predicate(self.tcx);
16041604
parent_pred = Some(predicate);
16051605
let obligation =
16061606
traits::Obligation::new(self.tcx, cause.clone(), self.param_env, predicate);

compiler/rustc_hir_typeck/src/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::traits::util::supertraits;
3030
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
3131
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
3232
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
33-
use rustc_middle::ty::IsSuggestable;
33+
use rustc_middle::ty::{IsSuggestable, ToPredicate};
3434
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeVisitableExt};
3535
use rustc_span::def_id::DefIdSet;
3636
use rustc_span::symbol::{kw, sym, Ident};
@@ -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
})

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
}

compiler/rustc_infer/src/traits/mod.rs

-16
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,9 @@ 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-
self.param_env = self.param_env.without_const();
83-
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() {
84-
self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred.without_const()))));
85-
}
86-
self
87-
}
8880
}
8981

9082
impl<'tcx> PolyTraitObligation<'tcx> {
91-
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
92-
pub fn is_const(&self) -> bool {
93-
matches!(
94-
(self.predicate.skip_binder().constness, self.param_env.constness()),
95-
(ty::BoundConstness::ConstIfConst, hir::Constness::Const)
96-
)
97-
}
98-
9983
pub fn derived_cause(
10084
&self,
10185
variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,

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)