Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk
Revert lazy TAIT PR Revert https://github.com/rust-lang/rust/pull/92306 (sorry `@Aaron1011,` will include your changes in the fix PR) Revert https://github.com/rust-lang/rust/pull/93783 Revert https://github.com/rust-lang/rust/pull/92007 fixes https://github.com/rust-lang/rust/issues/93788 fixes https://github.com/rust-lang/rust/issues/93794 fixes https://github.com/rust-lang/rust/issues/93821 fixes https://github.com/rust-lang/rust/issues/93831 fixes https://github.com/rust-lang/rust/issues/93841
This commit is contained in:
commit
6499c5e7fc
370 changed files with 2487 additions and 3626 deletions
|
@ -33,7 +33,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
/// purpose of this function is to do that translation.
|
||||
///
|
||||
/// (*) C1 and C2 were introduced in the comments on
|
||||
/// `register_member_constraints`. Read that comment for more context.
|
||||
/// `constrain_opaque_type`. Read that comment for more context.
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
|
@ -48,10 +48,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
instantiated_ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) -> Ty<'tcx> {
|
||||
if self.is_tainted_by_errors() {
|
||||
return self.tcx.ty_error();
|
||||
}
|
||||
|
||||
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
|
||||
|
||||
// Use substs to build up a reverse map from regions to their
|
||||
|
@ -71,6 +67,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
// after producing an error for each of them.
|
||||
let definition_ty = instantiated_ty.fold_with(&mut ReverseMapper::new(
|
||||
self.tcx,
|
||||
self.is_tainted_by_errors(),
|
||||
def_id,
|
||||
map,
|
||||
instantiated_ty,
|
||||
|
@ -85,6 +82,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
struct ReverseMapper<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
||||
/// If errors have already been reported in this fn, we suppress
|
||||
/// our own errors because they are sometimes derivative.
|
||||
tainted_by_errors: bool,
|
||||
|
||||
opaque_type_def_id: DefId,
|
||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
||||
map_missing_regions_to_empty: bool,
|
||||
|
@ -99,6 +100,7 @@ struct ReverseMapper<'tcx> {
|
|||
impl<'tcx> ReverseMapper<'tcx> {
|
||||
fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
tainted_by_errors: bool,
|
||||
opaque_type_def_id: DefId,
|
||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
||||
hidden_ty: Ty<'tcx>,
|
||||
|
@ -106,6 +108,7 @@ impl<'tcx> ReverseMapper<'tcx> {
|
|||
) -> Self {
|
||||
Self {
|
||||
tcx,
|
||||
tainted_by_errors,
|
||||
opaque_type_def_id,
|
||||
map,
|
||||
map_missing_regions_to_empty: false,
|
||||
|
@ -164,7 +167,9 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||
match self.map.get(&r.into()).map(|k| k.unpack()) {
|
||||
Some(GenericArgKind::Lifetime(r1)) => r1,
|
||||
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
|
||||
None if self.map_missing_regions_to_empty => self.tcx.lifetimes.re_root_empty,
|
||||
None if self.map_missing_regions_to_empty || self.tainted_by_errors => {
|
||||
self.tcx.lifetimes.re_root_empty
|
||||
}
|
||||
None if generics.parent.is_some() => {
|
||||
if let Some(hidden_ty) = self.hidden_ty.take() {
|
||||
unexpected_hidden_region_diagnostic(
|
||||
|
@ -354,7 +359,6 @@ crate fn required_region_bounds<'tcx>(
|
|||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::OpaqueType(..)
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
|
||||
// Search for a bound of the form `erased_self_ty
|
||||
|
|
|
@ -853,7 +853,6 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::OpaqueType(..)
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -90,11 +90,6 @@ pub fn codegen_fulfill_obligation<'tcx>(
|
|||
});
|
||||
let impl_source = drain_fulfillment_cx_or_panic(&infcx, &mut fulfill_cx, impl_source);
|
||||
|
||||
// We may constrain the hidden types of opaque types in this query, but this is
|
||||
// not information our callers need, as all that information is handled by borrowck
|
||||
// and typeck.
|
||||
drop(infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types());
|
||||
|
||||
debug!("Cache miss: {:?} => {:?}", trait_ref, impl_source);
|
||||
Ok(&*tcx.arena.alloc(impl_source))
|
||||
})
|
||||
|
|
|
@ -775,10 +775,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
span,
|
||||
"TypeWellFormedFromEnv predicate should only exist in the environment"
|
||||
),
|
||||
|
||||
ty::PredicateKind::OpaqueType(..) => {
|
||||
todo!("{:#?}", obligation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1328,7 +1328,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
ty::Generator(..) => "generator",
|
||||
_ => "function",
|
||||
};
|
||||
let span = self.tcx.sess.source_map().guess_head_span(span);
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
span,
|
||||
|
@ -1681,7 +1680,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
));
|
||||
|
||||
let original_span = err.span.primary_span().unwrap();
|
||||
let original_span = self.tcx.sess.source_map().guess_head_span(original_span);
|
||||
let mut span = MultiSpan::from_span(original_span);
|
||||
|
||||
let message = outer_generator
|
||||
|
|
|
@ -397,9 +397,6 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
|
||||
bug!("TypeWellFormedFromEnv is only used for Chalk")
|
||||
}
|
||||
ty::PredicateKind::OpaqueType(..) => {
|
||||
todo!("{:#?}", obligation);
|
||||
}
|
||||
},
|
||||
Some(pred) => match pred {
|
||||
ty::PredicateKind::Trait(data) => {
|
||||
|
@ -645,20 +642,6 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
|
||||
bug!("TypeWellFormedFromEnv is only used for Chalk")
|
||||
}
|
||||
ty::PredicateKind::OpaqueType(a, b) => {
|
||||
match self.selcx.infcx().handle_opaque_type(
|
||||
a,
|
||||
b,
|
||||
&obligation.cause,
|
||||
obligation.param_env,
|
||||
) {
|
||||
Ok(value) => ProcessResult::Changed(mk_pending(value.obligations)),
|
||||
Err(err) => ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
|
||||
ExpectedFound::new(true, a, b),
|
||||
err,
|
||||
)),
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -313,7 +313,6 @@ fn predicate_references_self<'tcx>(
|
|||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::OpaqueType(..)
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +347,6 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
|||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::OpaqueType(..)
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => false,
|
||||
}
|
||||
})
|
||||
|
|
|
@ -3,8 +3,7 @@ use crate::infer::{InferCtxt, InferOk};
|
|||
use crate::traits::engine::TraitEngineExt as _;
|
||||
use crate::traits::query::type_op::TypeOpOutput;
|
||||
use crate::traits::query::Fallible;
|
||||
use crate::traits::TraitEngine;
|
||||
use rustc_infer::infer::region_constraints::RegionConstraintData;
|
||||
use crate::traits::{ObligationCause, TraitEngine};
|
||||
use rustc_infer::traits::TraitEngineExt as _;
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
|
||||
|
@ -32,9 +31,6 @@ where
|
|||
G: Fn() -> String,
|
||||
{
|
||||
type Output = R;
|
||||
/// We can't do any custom error reporting for `CustomTypeOp`, so
|
||||
/// we can use `!` to enforce that the implementation never provides it.
|
||||
type ErrorInfo = !;
|
||||
|
||||
/// Processes the operation and all resulting obligations,
|
||||
/// returning the final result along with any region constraints
|
||||
|
@ -44,7 +40,7 @@ where
|
|||
info!("fully_perform({:?})", self);
|
||||
}
|
||||
|
||||
Ok(scrape_region_constraints(infcx, || (self.closure)(infcx))?.0)
|
||||
scrape_region_constraints(infcx, || (self.closure)(infcx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,11 +55,12 @@ where
|
|||
|
||||
/// Executes `op` and then scrapes out all the "old style" region
|
||||
/// constraints that result, creating query-region-constraints.
|
||||
pub fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>(
|
||||
fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>(
|
||||
infcx: &InferCtxt<'_, 'tcx>,
|
||||
op: impl FnOnce() -> Fallible<InferOk<'tcx, R>>,
|
||||
) -> Fallible<(TypeOpOutput<'tcx, Op>, RegionConstraintData<'tcx>)> {
|
||||
) -> Fallible<TypeOpOutput<'tcx, Op>> {
|
||||
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
|
||||
let dummy_body_id = ObligationCause::dummy().body_id;
|
||||
|
||||
// During NLL, we expect that nobody will register region
|
||||
// obligations **except** as part of a custom type op (and, at the
|
||||
|
@ -78,6 +75,7 @@ pub fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>(
|
|||
);
|
||||
|
||||
let InferOk { value, obligations } = infcx.commit_if_ok(|_| op())?;
|
||||
debug_assert!(obligations.iter().all(|o| o.cause.body_id == dummy_body_id));
|
||||
fulfill_cx.register_predicate_obligations(infcx, obligations);
|
||||
let errors = fulfill_cx.select_all_or_error(infcx);
|
||||
if !errors.is_empty() {
|
||||
|
@ -101,18 +99,12 @@ pub fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>(
|
|||
);
|
||||
|
||||
if region_constraints.is_empty() {
|
||||
Ok((
|
||||
TypeOpOutput { output: value, constraints: None, error_info: None },
|
||||
region_constraint_data,
|
||||
))
|
||||
Ok(TypeOpOutput { output: value, constraints: None, canonicalized_query: None })
|
||||
} else {
|
||||
Ok((
|
||||
TypeOpOutput {
|
||||
output: value,
|
||||
constraints: Some(Rc::new(region_constraints)),
|
||||
error_info: None,
|
||||
},
|
||||
region_constraint_data,
|
||||
))
|
||||
Ok(TypeOpOutput {
|
||||
output: value,
|
||||
constraints: Some(Rc::new(region_constraints)),
|
||||
canonicalized_query: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ pub use rustc_middle::traits::query::type_op::*;
|
|||
/// cannot be completed).
|
||||
pub trait TypeOp<'tcx>: Sized + fmt::Debug {
|
||||
type Output;
|
||||
type ErrorInfo;
|
||||
|
||||
/// Processes the operation and all resulting obligations,
|
||||
/// returning the final result along with any region constraints
|
||||
|
@ -42,8 +41,9 @@ pub struct TypeOpOutput<'tcx, Op: TypeOp<'tcx>> {
|
|||
pub output: Op::Output,
|
||||
/// Any region constraints from performing the type op.
|
||||
pub constraints: Option<Rc<QueryRegionConstraints<'tcx>>>,
|
||||
/// Used for error reporting to be able to rerun the query
|
||||
pub error_info: Option<Op::ErrorInfo>,
|
||||
/// The canonicalized form of the query.
|
||||
/// This for error reporting to be able to rerun the query.
|
||||
pub canonicalized_query: Option<Canonical<'tcx, Op>>,
|
||||
}
|
||||
|
||||
/// "Query type ops" are type ops that are implemented using a
|
||||
|
@ -119,11 +119,10 @@ where
|
|||
Q: QueryTypeOp<'tcx>,
|
||||
{
|
||||
type Output = Q::QueryResponse;
|
||||
type ErrorInfo = Canonical<'tcx, ParamEnvAnd<'tcx, Q>>;
|
||||
|
||||
fn fully_perform(self, infcx: &InferCtxt<'_, 'tcx>) -> Fallible<TypeOpOutput<'tcx, Self>> {
|
||||
let mut region_constraints = QueryRegionConstraints::default();
|
||||
let (output, error_info, mut obligations, _) =
|
||||
let (output, canonicalized_query, mut obligations, _) =
|
||||
Q::fully_perform_into(self, infcx, &mut region_constraints)?;
|
||||
|
||||
// Typically, instantiating NLL query results does not
|
||||
|
@ -161,6 +160,6 @@ where
|
|||
let region_constraints =
|
||||
if region_constraints.is_empty() { None } else { Some(Rc::new(region_constraints)) };
|
||||
|
||||
Ok(TypeOpOutput { output, constraints: region_constraints, error_info })
|
||||
Ok(TypeOpOutput { output, constraints: region_constraints, canonicalized_query })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,7 +254,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
};
|
||||
|
||||
if obligation.predicate.skip_binder().self_ty().is_ty_var() {
|
||||
debug!(ty = ?obligation.predicate.skip_binder().self_ty(), "ambiguous inference var or opaque type");
|
||||
// Self is a type variable (e.g., `_: AsRef<str>`).
|
||||
//
|
||||
// This is somewhat problematic, as the current scheme can't really
|
||||
|
|
|
@ -37,7 +37,6 @@ use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
|
|||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::thir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::ty::fast_reject::{self, SimplifyParams, StripReferences};
|
||||
use rustc_middle::ty::fold::BottomUpFolder;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::relate::TypeRelation;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef};
|
||||
|
@ -698,19 +697,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
|
||||
bug!("TypeWellFormedFromEnv is only used for chalk")
|
||||
}
|
||||
ty::PredicateKind::OpaqueType(a, b) => {
|
||||
match self.infcx().handle_opaque_type(
|
||||
a,
|
||||
b,
|
||||
&obligation.cause,
|
||||
obligation.param_env,
|
||||
) {
|
||||
Ok(res) => {
|
||||
self.evaluate_predicates_recursively(previous_stack, res.obligations)
|
||||
}
|
||||
Err(_) => Ok(EvaluatedToErr),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1351,7 +1337,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self, param_env, cache_fresh_trait_pred, dep_node), level = "debug")]
|
||||
fn insert_candidate_cache(
|
||||
&mut self,
|
||||
mut param_env: ty::ParamEnv<'tcx>,
|
||||
|
@ -1392,7 +1377,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
/// a projection, look at the bounds of `T::Bar`, see if we can find a
|
||||
/// `Baz` bound. We return indexes into the list returned by
|
||||
/// `tcx.item_bounds` for any applicable bounds.
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn match_projection_obligation_against_definition_bounds(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
|
@ -1400,7 +1384,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
let poly_trait_predicate = self.infcx().resolve_vars_if_possible(obligation.predicate);
|
||||
let placeholder_trait_predicate =
|
||||
self.infcx().replace_bound_vars_with_placeholders(poly_trait_predicate);
|
||||
debug!(?placeholder_trait_predicate);
|
||||
debug!(
|
||||
?placeholder_trait_predicate,
|
||||
"match_projection_obligation_against_definition_bounds"
|
||||
);
|
||||
|
||||
let tcx = self.infcx.tcx;
|
||||
let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() {
|
||||
|
@ -1451,7 +1438,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
})
|
||||
.collect();
|
||||
|
||||
debug!(?matching_bounds);
|
||||
debug!(?matching_bounds, "match_projection_obligation_against_definition_bounds");
|
||||
matching_bounds
|
||||
}
|
||||
|
||||
|
@ -1481,7 +1468,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
});
|
||||
self.infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
.define_opaque_types(false)
|
||||
.sup(ty::Binder::dummy(placeholder_trait_ref), trait_bound)
|
||||
.map(|InferOk { obligations: _, value: () }| {
|
||||
// This method is called within a probe, so we can't have
|
||||
|
@ -1537,7 +1523,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
self.infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
.define_opaque_types(false)
|
||||
.sup(obligation.predicate, infer_projection)
|
||||
.map_or(false, |InferOk { obligations, value: () }| {
|
||||
self.evaluate_predicates_recursively(
|
||||
|
@ -2096,22 +2081,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
match self.match_impl(impl_def_id, obligation) {
|
||||
Ok(substs) => substs,
|
||||
Err(()) => {
|
||||
self.infcx.tcx.sess.delay_span_bug(
|
||||
obligation.cause.span,
|
||||
&format!(
|
||||
"Impl {:?} was matchable against {:?} but now is not",
|
||||
impl_def_id, obligation
|
||||
),
|
||||
bug!(
|
||||
"Impl {:?} was matchable against {:?} but now is not",
|
||||
impl_def_id,
|
||||
obligation
|
||||
);
|
||||
let value = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
|
||||
let err = self.tcx().ty_error();
|
||||
let value = value.fold_with(&mut BottomUpFolder {
|
||||
tcx: self.tcx(),
|
||||
ty_op: |_| err,
|
||||
lt_op: |l| l,
|
||||
ct_op: |c| c,
|
||||
});
|
||||
Normalized { value, obligations: vec![] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2248,11 +2222,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
) -> Result<Vec<PredicateObligation<'tcx>>, ()> {
|
||||
self.infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
// We don't want predicates for opaque types to just match all other types,
|
||||
// if there is an obligation on the opaque type, then that obligation must be met
|
||||
// opaquely. Otherwise we'd match any obligation to the opaque type and then error
|
||||
// out later.
|
||||
.define_opaque_types(false)
|
||||
.sup(obligation.predicate.to_poly_trait_ref(), poly_trait_ref)
|
||||
.map(|InferOk { obligations, .. }| obligations)
|
||||
.map_err(|_| ())
|
||||
|
|
|
@ -146,10 +146,6 @@ pub fn predicate_obligations<'a, 'tcx>(
|
|||
wf.compute(c1.into());
|
||||
wf.compute(c2.into());
|
||||
}
|
||||
ty::PredicateKind::OpaqueType(opaque, ty) => {
|
||||
wf.compute(opaque.into());
|
||||
wf.compute(ty.into());
|
||||
}
|
||||
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
|
||||
bug!("TypeWellFormedFromEnv is only used for Chalk")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue