Auto merge of #91354 - fee1-dead:const_env, r=spastorino
Cleanup: Eliminate ConstnessAnd This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature. We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`. This is a continuation of https://github.com/rust-lang/rust/pull/90274. r? `@oli-obk` cc `@spastorino` `@ecstatic-morse`
This commit is contained in:
commit
18bb8c61a9
49 changed files with 380 additions and 430 deletions
|
@ -1,9 +1,8 @@
|
|||
use crate::infer::InferCtxt;
|
||||
use crate::traits::Obligation;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, WithConstness};
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty};
|
||||
|
||||
use super::FulfillmentError;
|
||||
use super::{ObligationCause, PredicateObligation};
|
||||
|
@ -48,26 +47,9 @@ pub trait TraitEngine<'tcx>: 'tcx {
|
|||
|
||||
fn select_all_or_error(&mut self, infcx: &InferCtxt<'_, 'tcx>) -> Vec<FulfillmentError<'tcx>>;
|
||||
|
||||
fn select_all_with_constness_or_error(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'_, 'tcx>,
|
||||
_constness: hir::Constness,
|
||||
) -> Vec<FulfillmentError<'tcx>> {
|
||||
self.select_all_or_error(infcx)
|
||||
}
|
||||
|
||||
fn select_where_possible(&mut self, infcx: &InferCtxt<'_, 'tcx>)
|
||||
-> Vec<FulfillmentError<'tcx>>;
|
||||
|
||||
// FIXME(fee1-dead) this should not provide a default body for chalk as chalk should be updated
|
||||
fn select_with_constness_where_possible(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'_, 'tcx>,
|
||||
_constness: hir::Constness,
|
||||
) -> Vec<FulfillmentError<'tcx>> {
|
||||
self.select_where_possible(infcx)
|
||||
}
|
||||
|
||||
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
|
||||
|
||||
fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships>;
|
||||
|
|
|
@ -69,6 +69,16 @@ impl PredicateObligation<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl TraitObligation<'tcx> {
|
||||
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
|
||||
pub fn is_const(&self) -> bool {
|
||||
match (self.predicate.skip_binder().constness, self.param_env.constness()) {
|
||||
(ty::BoundConstness::ConstIfConst, hir::Constness::Const) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
static_assert_size!(PredicateObligation<'_>, 32);
|
||||
|
|
|
@ -3,7 +3,7 @@ use smallvec::smallvec;
|
|||
use crate::infer::outlives::components::{push_outlives_components, Component};
|
||||
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
||||
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
|
||||
use rustc_middle::ty::{self, ToPredicate, TyCtxt};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
|
||||
|
@ -328,8 +328,8 @@ pub fn transitive_bounds_that_define_assoc_type<'tcx>(
|
|||
));
|
||||
for (super_predicate, _) in super_predicates.predicates {
|
||||
let subst_predicate = super_predicate.subst_supertrait(tcx, &trait_ref);
|
||||
if let Some(binder) = subst_predicate.to_opt_poly_trait_ref() {
|
||||
stack.push(binder.value);
|
||||
if let Some(binder) = subst_predicate.to_opt_poly_trait_pred() {
|
||||
stack.push(binder.map_bound(|t| t.trait_ref));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,8 +362,8 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
|
|||
|
||||
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
|
||||
while let Some(obligation) = self.base_iterator.next() {
|
||||
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
|
||||
return Some(data.value);
|
||||
if let Some(data) = obligation.predicate.to_opt_poly_trait_pred() {
|
||||
return Some(data.map_bound(|t| t.trait_ref));
|
||||
}
|
||||
}
|
||||
None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue