Remove some glob imports from the type system

This commit is contained in:
Michael Goulet
2025-06-17 17:55:06 +00:00
parent 2801f9aaf9
commit 44254c8cd7
32 changed files with 243 additions and 185 deletions
@@ -10,7 +10,7 @@
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::VisitorExt;
use rustc_hir::{PolyTraitRef, TyKind, WhereBoundPredicate};
use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
use rustc_infer::infer::{NllRegionVariableOrigin, SubregionOrigin};
use rustc_middle::bug;
use rustc_middle::hir::place::PlaceBase;
use rustc_middle::mir::{AnnotationSource, ConstraintCategory, ReturnConstraint};
@@ -329,7 +329,8 @@ pub(crate) fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) {
self.infcx.tcx,
type_test.generic_kind.to_ty(self.infcx.tcx),
);
let origin = RelateParamBound(type_test_span, generic_ty, None);
let origin =
SubregionOrigin::RelateParamBound(type_test_span, generic_ty, None);
self.buffer_error(self.infcx.err_ctxt().construct_generic_bound_failure(
self.body.source.def_id().expect_local(),
type_test_span,
@@ -3,7 +3,7 @@
use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
use rustc_infer::infer::{InferCtxt, SubregionOrigin};
use rustc_infer::traits::query::type_op::DeeplyNormalize;
use rustc_middle::bug;
use rustc_middle::ty::{
@@ -172,7 +172,7 @@ fn convert(
ty::Region::new_var(tcx, universal_regions.implicit_region_bound());
// we don't actually use this for anything, but
// the `TypeOutlives` code needs an origin.
let origin = infer::RelateParamBound(self.span, t1, None);
let origin = SubregionOrigin::RelateParamBound(self.span, t1, None);
TypeOutlives::new(
&mut *self,
tcx,
@@ -16,7 +16,7 @@
use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::region_constraints::RegionConstraintData;
use rustc_infer::infer::{
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin,
};
use rustc_infer::traits::PredicateObligations;
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
@@ -794,7 +794,7 @@ fn visit_terminator(&mut self, term: &Terminator<'tcx>, term_location: Location)
};
self.infcx.next_region_var(
BoundRegion(
RegionVariableOrigin::BoundRegion(
term.source_info.span,
br.kind,
BoundRegionConversionTime::FnCall,
@@ -9,7 +9,7 @@
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::VisitorExt;
use rustc_hir::{self as hir, AmbigArg, GenericParamKind, ImplItemKind, intravisit};
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_infer::infer::{self, BoundRegionConversionTime, InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::util;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{
@@ -311,7 +311,7 @@ fn compare_method_predicate_entailment<'tcx>(
let unnormalized_impl_sig = infcx.instantiate_binder_with_fresh_vars(
impl_m_span,
infer::HigherRankedType,
BoundRegionConversionTime::HigherRankedType,
tcx.fn_sig(impl_m.def_id).instantiate_identity(),
);
@@ -518,7 +518,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
param_env,
infcx.instantiate_binder_with_fresh_vars(
return_span,
infer::HigherRankedType,
BoundRegionConversionTime::HigherRankedType,
tcx.fn_sig(impl_m.def_id).instantiate_identity(),
),
);
@@ -11,7 +11,7 @@
use rustc_hir::lang_items::LangItem;
use rustc_hir::{AmbigArg, ItemKind};
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin, TyCtxtInferExt};
use rustc_lint_defs::builtin::SUPERTRAIT_ITEM_SHADOWING_DEFINITION;
use rustc_macros::LintDiagnostic;
use rustc_middle::mir::interpret::ErrorHandled;
@@ -739,7 +739,7 @@ fn ty_known_to_outlive<'tcx>(
infcx.register_type_outlives_constraint_inner(infer::TypeOutlivesConstraint {
sub_region: region,
sup_type: ty,
origin: infer::RelateParamBound(DUMMY_SP, ty, None),
origin: SubregionOrigin::RelateParamBound(DUMMY_SP, ty, None),
});
})
}
@@ -755,7 +755,11 @@ fn region_known_to_outlive<'tcx>(
region_b: ty::Region<'tcx>,
) -> bool {
test_region_obligations(tcx, id, param_env, wf_tys, |infcx| {
infcx.sub_regions(infer::RelateRegionParamBound(DUMMY_SP, None), region_b, region_a);
infcx.sub_regions(
SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None),
region_b,
region_a,
);
})
}
@@ -10,7 +10,7 @@
use rustc_hir::ItemKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_infer::infer::{self, RegionResolutionError, TyCtxtInferExt};
use rustc_infer::infer::{self, RegionResolutionError, SubregionOrigin, TyCtxtInferExt};
use rustc_infer::traits::Obligation;
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
use rustc_middle::ty::print::PrintTraitRefExt as _;
@@ -415,7 +415,7 @@ pub(crate) fn coerce_unsized_info<'tcx>(
};
let (source, target, trait_def_id, kind, field_span) = match (source.kind(), target.kind()) {
(&ty::Ref(r_a, ty_a, mutbl_a), &ty::Ref(r_b, ty_b, mutbl_b)) => {
infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a);
infcx.sub_regions(SubregionOrigin::RelateObjectBound(span), r_b, r_a);
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b };
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ref(tcx, r_b, ty))
+8 -4
View File
@@ -7,7 +7,7 @@
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, HirId, LangItem};
use rustc_hir_analysis::autoderef::Autoderef;
use rustc_infer::infer;
use rustc_infer::infer::BoundRegionConversionTime;
use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode};
use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
@@ -219,7 +219,7 @@ fn try_overloaded_call_step(
let closure_sig = args.as_closure().sig();
let closure_sig = self.instantiate_binder_with_fresh_vars(
call_expr.span,
infer::FnCall,
BoundRegionConversionTime::FnCall,
closure_sig,
);
let adjustments = self.adjust_steps(autoderef);
@@ -246,7 +246,7 @@ fn try_overloaded_call_step(
let closure_args = args.as_coroutine_closure();
let coroutine_closure_sig = self.instantiate_binder_with_fresh_vars(
call_expr.span,
infer::FnCall,
BoundRegionConversionTime::FnCall,
closure_args.coroutine_closure_sig(),
);
let tupled_upvars_ty = self.next_ty_var(callee_expr.span);
@@ -545,7 +545,11 @@ fn confirm_builtin_call(
// renormalize the associated types at this point, since they
// previously appeared within a `Binder<>` and hence would not
// have been normalized before.
let fn_sig = self.instantiate_binder_with_fresh_vars(call_expr.span, infer::FnCall, fn_sig);
let fn_sig = self.instantiate_binder_with_fresh_vars(
call_expr.span,
BoundRegionConversionTime::FnCall,
fn_sig,
);
let fn_sig = self.normalize(call_expr.span, fn_sig);
self.check_argument_types(
+4 -4
View File
@@ -44,7 +44,7 @@
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_infer::infer::relate::RelateResult;
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
use rustc_infer::infer::{DefineOpaqueTypes, InferOk, InferResult, RegionVariableOrigin};
use rustc_infer::traits::{
IfExpressionCause, MatchExpressionArmCause, Obligation, PredicateObligation,
PredicateObligations, SelectionError,
@@ -431,7 +431,7 @@ fn coerce_borrowed_pointer(
} else {
if r_borrow_var.is_none() {
// create var lazily, at most once
let coercion = Coercion(span);
let coercion = RegionVariableOrigin::Coercion(span);
let r = self.next_region_var(coercion);
r_borrow_var = Some(r); // [4] above
}
@@ -549,7 +549,7 @@ fn coerce_unsized(&self, mut source: Ty<'tcx>, mut target: Ty<'tcx>) -> CoerceRe
(&ty::Ref(_, ty_a, mutbl_a), &ty::Ref(_, _, mutbl_b)) => {
coerce_mutbls(mutbl_a, mutbl_b)?;
let coercion = Coercion(self.cause.span);
let coercion = RegionVariableOrigin::Coercion(self.cause.span);
let r_borrow = self.next_region_var(coercion);
// We don't allow two-phase borrows here, at least for initial
@@ -672,7 +672,7 @@ fn coerce_unsized(&self, mut source: Ty<'tcx>, mut target: Ty<'tcx>) -> CoerceRe
return Err(TypeError::Mismatch);
}
}
Err(traits::Unimplemented) => {
Err(SelectionError::Unimplemented) => {
debug!("coerce_unsized: early return - can't prove obligation");
return Err(TypeError::Mismatch);
}
+2 -3
View File
@@ -22,8 +22,7 @@
use rustc_hir::{ExprKind, HirId, QPath};
use rustc_hir_analysis::NoVariantNamed;
use rustc_hir_analysis::hir_ty_lowering::{FeedConstTy, HirTyLowerer as _};
use rustc_infer::infer;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk, RegionVariableOrigin};
use rustc_infer::traits::query::NoSolution;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -705,7 +704,7 @@ fn check_expr_addr_of(
// this time with enough precision to check that the value
// whose address was taken can actually be made to live as long
// as it needs to live.
let region = self.next_region_var(infer::BorrowRegion(expr.span));
let region = self.next_region_var(RegionVariableOrigin::BorrowRegion(expr.span));
match kind {
hir::BorrowKind::Ref => Ty::new_ref(self.tcx, region, ty, mutbl),
hir::BorrowKind::Pin => Ty::new_pinned_ref(self.tcx, region, ty, mutbl),
@@ -11,7 +11,7 @@
use rustc_hir_analysis::check::potentially_plural_count;
use rustc_hir_analysis::hir_ty_lowering::{HirTyLowerer, PermitVariants};
use rustc_index::IndexVec;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TypeTrace};
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TypeTrace};
use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
@@ -30,7 +30,6 @@
use crate::coercion::CoerceMany;
use crate::errors::SuggestPtrNullMut;
use crate::fn_ctxt::arg_matrix::{ArgMatrix, Compatibility, Error, ExpectedIdx, ProvidedIdx};
use crate::fn_ctxt::infer::FnCall;
use crate::gather_locals::Declaration;
use crate::inline_asm::InlineAsmCtxt;
use crate::method::probe::IsSuggestion;
@@ -657,7 +656,11 @@ fn has_error_or_infer<'tcx>(tys: impl IntoIterator<Item = Ty<'tcx>>) -> bool {
let args = self.infcx.fresh_args_for_item(call_name.span, assoc.def_id);
let fn_sig = tcx.fn_sig(assoc.def_id).instantiate(tcx, args);
self.instantiate_binder_with_fresh_vars(call_name.span, FnCall, fn_sig);
self.instantiate_binder_with_fresh_vars(
call_name.span,
BoundRegionConversionTime::FnCall,
fn_sig,
);
}
None
};
+5 -3
View File
@@ -15,7 +15,7 @@
use rustc_hir_analysis::hir_ty_lowering::{
HirTyLowerer, InherentAssocCandidate, RegionInferReason,
};
use rustc_infer::infer;
use rustc_infer::infer::{self, RegionVariableOrigin};
use rustc_infer::traits::{DynCompatibilityViolation, Obligation};
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
use rustc_session::Session;
@@ -244,8 +244,10 @@ fn item_def_id(&self) -> LocalDefId {
fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> ty::Region<'tcx> {
let v = match reason {
RegionInferReason::Param(def) => infer::RegionParameterDefinition(span, def.name),
_ => infer::MiscVariable(span),
RegionInferReason::Param(def) => {
RegionVariableOrigin::RegionParameterDefinition(span, def.name)
}
_ => RegionVariableOrigin::MiscVariable(span),
};
self.next_region_var(v)
}
@@ -9,7 +9,9 @@
use rustc_hir_analysis::hir_ty_lowering::{
FeedConstTy, GenericArgsLowerer, HirTyLowerer, IsMethodCall, RegionInferReason,
};
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk};
use rustc_infer::infer::{
BoundRegionConversionTime, DefineOpaqueTypes, InferOk, RegionVariableOrigin,
};
use rustc_lint::builtin::SUPERTRAIT_ITEM_SHADOWING_USAGE;
use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::adjustment::{
@@ -194,7 +196,7 @@ fn adjust_self_ty(
match pick.autoref_or_ptr_adjustment {
Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
let region = self.next_region_var(infer::Autoref(self.span));
let region = self.next_region_var(RegionVariableOrigin::Autoref(self.span));
// Type we're wrapping in a reference, used later for unsizing
let base_ty = target;
@@ -239,7 +241,7 @@ fn adjust_self_ty(
}
Some(probe::AutorefOrPtrAdjustment::ReborrowPin(mutbl)) => {
let region = self.next_region_var(infer::Autoref(self.span));
let region = self.next_region_var(RegionVariableOrigin::Autoref(self.span));
target = match target.kind() {
ty::Adt(pin, args) if self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) => {
@@ -752,6 +754,10 @@ fn instantiate_binder_with_fresh_vars<T>(&self, value: ty::Binder<'tcx, T>) -> T
where
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
{
self.fcx.instantiate_binder_with_fresh_vars(self.span, infer::FnCall, value)
self.fcx.instantiate_binder_with_fresh_vars(
self.span,
BoundRegionConversionTime::FnCall,
value,
)
}
}
+6 -3
View File
@@ -11,7 +11,7 @@
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace};
use rustc_hir::def_id::DefId;
use rustc_infer::infer::{self, InferOk};
use rustc_infer::infer::{BoundRegionConversionTime, InferOk};
use rustc_infer::traits::PredicateObligations;
use rustc_middle::query::Providers;
use rustc_middle::traits::ObligationCause;
@@ -400,8 +400,11 @@ pub(super) fn lookup_method_for_operator(
// function signature so that normalization does not need to deal
// with bound regions.
let fn_sig = tcx.fn_sig(def_id).instantiate(self.tcx, args);
let fn_sig =
self.instantiate_binder_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig);
let fn_sig = self.instantiate_binder_with_fresh_vars(
obligation.cause.span,
BoundRegionConversionTime::FnCall,
fn_sig,
);
let InferOk { value: fn_sig, obligations: o } =
self.at(&obligation.cause, self.param_env).normalize(fn_sig);
+13 -6
View File
@@ -12,7 +12,7 @@
use rustc_hir::def::DefKind;
use rustc_hir_analysis::autoderef::{self, Autoderef};
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
use rustc_infer::traits::ObligationCauseCode;
use rustc_middle::middle::stability;
use rustc_middle::query::Providers;
@@ -995,7 +995,11 @@ fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool
ty::AssocKind::Fn { .. } => self.probe(|_| {
let args = self.fresh_args_for_item(self.span, method.def_id);
let fty = self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args);
let fty = self.instantiate_binder_with_fresh_vars(self.span, infer::FnCall, fty);
let fty = self.instantiate_binder_with_fresh_vars(
self.span,
BoundRegionConversionTime::FnCall,
fty,
);
self.can_eq(self.param_env, fty.output(), expected)
}),
_ => false,
@@ -1756,8 +1760,11 @@ fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> Ca
CandidateSource::Trait(candidate.item.container_id(self.tcx))
}
TraitCandidate(trait_ref) => self.probe(|_| {
let trait_ref =
self.instantiate_binder_with_fresh_vars(self.span, infer::FnCall, trait_ref);
let trait_ref = self.instantiate_binder_with_fresh_vars(
self.span,
BoundRegionConversionTime::FnCall,
trait_ref,
);
let (xform_self_ty, _) =
self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
// Guide the trait selection to show impls that have methods whose type matches
@@ -1873,7 +1880,7 @@ fn consider_probe(
let trait_ref = self.instantiate_binder_with_fresh_vars(
self.span,
infer::FnCall,
BoundRegionConversionTime::FnCall,
poly_trait_ref,
);
let trait_ref = ocx.normalize(cause, self.param_env, trait_ref);
@@ -1936,7 +1943,7 @@ fn consider_probe(
ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
let trait_ref = self.instantiate_binder_with_fresh_vars(
self.span,
infer::FnCall,
BoundRegionConversionTime::FnCall,
poly_trait_ref,
);
(xform_self_ty, xform_ret_ty) =
@@ -22,7 +22,7 @@
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{self as hir, ExprKind, HirId, Node, PathSegment, QPath};
use rustc_infer::infer::{self, RegionVariableOrigin};
use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin};
use rustc_middle::bug;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
use rustc_middle::ty::print::{
@@ -1951,7 +1951,11 @@ fn find_likely_intended_associated_item(
if def_kind == DefKind::AssocFn {
let ty_args = self.infcx.fresh_args_for_item(span, similar_candidate.def_id);
let fn_sig = tcx.fn_sig(similar_candidate.def_id).instantiate(tcx, ty_args);
let fn_sig = self.instantiate_binder_with_fresh_vars(span, infer::FnCall, fn_sig);
let fn_sig = self.instantiate_binder_with_fresh_vars(
span,
BoundRegionConversionTime::FnCall,
fn_sig,
);
if similar_candidate.is_method() {
if let Some(args) = args
&& fn_sig.inputs()[1..].len() == args.len()
@@ -2033,7 +2037,7 @@ pub(crate) fn confusable_method_name(
self.tcx.fn_sig(inherent_method.def_id).instantiate(self.tcx, args);
let fn_sig = self.instantiate_binder_with_fresh_vars(
item_name.span,
infer::FnCall,
BoundRegionConversionTime::FnCall,
fn_sig,
);
let name = inherent_method.name();
+2 -2
View File
@@ -16,7 +16,7 @@
PatExprKind, PatKind, expr_needs_parens,
};
use rustc_hir_analysis::autoderef::report_autoderef_recursion_limit_error;
use rustc_infer::infer;
use rustc_infer::infer::RegionVariableOrigin;
use rustc_middle::traits::PatternOriginExpr;
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_middle::{bug, span_bug};
@@ -2777,7 +2777,7 @@ fn check_pat_ref(
/// Create a reference type with a fresh region variable.
fn new_ref_ty(&self, span: Span, mutbl: Mutability, ty: Ty<'tcx>) -> Ty<'tcx> {
let region = self.next_region_var(infer::PatternRegion(span));
let region = self.next_region_var(RegionVariableOrigin::PatternRegion(span));
Ty::new_ref(self.tcx, region, ty, mutbl)
}
+27 -29
View File
@@ -1,9 +1,6 @@
use std::cell::{Cell, RefCell};
use std::fmt;
pub use BoundRegionConversionTime::*;
pub use RegionVariableOrigin::*;
pub use SubregionOrigin::*;
pub use at::DefineOpaqueTypes;
use free_regions::RegionRelations;
pub use freshen::TypeFreshener;
@@ -467,21 +464,19 @@ pub struct FixupError {
impl fmt::Display for FixupError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TyOrConstInferVar::*;
match self.unresolved {
TyInt(_) => write!(
TyOrConstInferVar::TyInt(_) => write!(
f,
"cannot determine the type of this integer; \
add a suffix to specify the type explicitly"
),
TyFloat(_) => write!(
TyOrConstInferVar::TyFloat(_) => write!(
f,
"cannot determine the type of this number; \
add a suffix to specify the type explicitly"
),
Ty(_) => write!(f, "unconstrained type"),
Const(_) => write!(f, "unconstrained const value"),
TyOrConstInferVar::Ty(_) => write!(f, "unconstrained type"),
TyOrConstInferVar::Const(_) => write!(f, "unconstrained const value"),
}
}
}
@@ -865,7 +860,10 @@ pub fn var_for_def(&self, span: Span, param: &ty::GenericParamDef) -> GenericArg
GenericParamDefKind::Lifetime => {
// Create a region inference variable for the given
// region parameter definition.
self.next_region_var(RegionParameterDefinition(span, param.name)).into()
self.next_region_var(RegionVariableOrigin::RegionParameterDefinition(
span, param.name,
))
.into()
}
GenericParamDefKind::Type { .. } => {
// Create a type inference variable for the given
@@ -1172,7 +1170,7 @@ pub fn instantiate_binder_with_fresh_vars<T>(
let arg: ty::GenericArg<'_> = match bound_var_kind {
ty::BoundVariableKind::Ty(_) => self.next_ty_var(span).into(),
ty::BoundVariableKind::Region(br) => {
self.next_region_var(BoundRegion(span, br, lbrct)).into()
self.next_region_var(RegionVariableOrigin::BoundRegion(span, br, lbrct)).into()
}
ty::BoundVariableKind::Const => self.next_const_var(span).into(),
};
@@ -1472,15 +1470,15 @@ pub fn consts(
impl<'tcx> SubregionOrigin<'tcx> {
pub fn span(&self) -> Span {
match *self {
Subtype(ref a) => a.span(),
RelateObjectBound(a) => a,
RelateParamBound(a, ..) => a,
RelateRegionParamBound(a, _) => a,
Reborrow(a) => a,
ReferenceOutlivesReferent(_, a) => a,
CompareImplItemObligation { span, .. } => span,
AscribeUserTypeProvePredicate(span) => span,
CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
SubregionOrigin::Subtype(ref a) => a.span(),
SubregionOrigin::RelateObjectBound(a) => a,
SubregionOrigin::RelateParamBound(a, ..) => a,
SubregionOrigin::RelateRegionParamBound(a, _) => a,
SubregionOrigin::Reborrow(a) => a,
SubregionOrigin::ReferenceOutlivesReferent(_, a) => a,
SubregionOrigin::CompareImplItemObligation { span, .. } => span,
SubregionOrigin::AscribeUserTypeProvePredicate(span) => span,
SubregionOrigin::CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
}
}
@@ -1528,15 +1526,15 @@ pub fn from_obligation_cause<F>(cause: &traits::ObligationCause<'tcx>, default:
impl RegionVariableOrigin {
pub fn span(&self) -> Span {
match *self {
MiscVariable(a)
| PatternRegion(a)
| BorrowRegion(a)
| Autoref(a)
| Coercion(a)
| RegionParameterDefinition(a, ..)
| BoundRegion(a, ..)
| UpvarRegion(_, a) => a,
Nll(..) => bug!("NLL variable used with `span`"),
RegionVariableOrigin::MiscVariable(a)
| RegionVariableOrigin::PatternRegion(a)
| RegionVariableOrigin::BorrowRegion(a)
| RegionVariableOrigin::Autoref(a)
| RegionVariableOrigin::Coercion(a)
| RegionVariableOrigin::RegionParameterDefinition(a, ..)
| RegionVariableOrigin::BoundRegion(a, ..)
| RegionVariableOrigin::UpvarRegion(_, a) => a,
RegionVariableOrigin::Nll(..) => bug!("NLL variable used with `span`"),
}
}
}
@@ -141,7 +141,7 @@ pub fn register_type_outlives_constraint(
debug!(?sup_type, ?sub_region, ?cause);
let origin = SubregionOrigin::from_obligation_cause(cause, || {
infer::RelateParamBound(
SubregionOrigin::RelateParamBound(
cause.span,
sup_type,
match cause.code().peel_derives() {
@@ -14,7 +14,7 @@
use self::CombineMapType::*;
use self::UndoLog::*;
use super::{MiscVariable, RegionVariableOrigin, Rollback, SubregionOrigin};
use super::{RegionVariableOrigin, Rollback, SubregionOrigin};
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, Snapshot};
use crate::infer::unify_key::{RegionVariableValue, RegionVidKey};
@@ -580,7 +580,7 @@ fn combine_vars(
let a_universe = self.universe(a);
let b_universe = self.universe(b);
let c_universe = cmp::max(a_universe, b_universe);
let c = self.new_region_var(c_universe, MiscVariable(origin.span()));
let c = self.new_region_var(c_universe, RegionVariableOrigin::MiscVariable(origin.span()));
self.combine_map(t).insert(vars, c);
self.undo_log.push(AddCombination(t, vars));
let new_r = ty::Region::new_var(tcx, c);
+10 -5
View File
@@ -5,6 +5,7 @@
};
use super::{FixupError, FixupResult, InferCtxt};
use crate::infer::TyOrConstInferVar;
///////////////////////////////////////////////////////////////////////////
// OPPORTUNISTIC VAR RESOLVER
@@ -144,13 +145,17 @@ fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
if !t.has_infer() {
Ok(t) // micro-optimize -- if there is nothing in this type that this fold affects...
} else {
use super::TyOrConstInferVar::*;
let t = self.infcx.shallow_resolve(t);
match *t.kind() {
ty::Infer(ty::TyVar(vid)) => Err(FixupError { unresolved: Ty(vid) }),
ty::Infer(ty::IntVar(vid)) => Err(FixupError { unresolved: TyInt(vid) }),
ty::Infer(ty::FloatVar(vid)) => Err(FixupError { unresolved: TyFloat(vid) }),
ty::Infer(ty::TyVar(vid)) => {
Err(FixupError { unresolved: TyOrConstInferVar::Ty(vid) })
}
ty::Infer(ty::IntVar(vid)) => {
Err(FixupError { unresolved: TyOrConstInferVar::TyInt(vid) })
}
ty::Infer(ty::FloatVar(vid)) => {
Err(FixupError { unresolved: TyOrConstInferVar::TyFloat(vid) })
}
ty::Infer(_) => {
bug!("Unexpected type in full type resolver: {:?}", t);
}
-2
View File
@@ -20,8 +20,6 @@
use rustc_span::Span;
use thin_vec::ThinVec;
pub use self::ImplSource::*;
pub use self::SelectionError::*;
pub use self::engine::{FromSolverError, ScrubbedTraitError, TraitEngine};
pub(crate) use self::project::UndoLog;
pub use self::project::{
@@ -909,11 +909,11 @@ fn generic_arg_is_target(&self, arg: GenericArg<'tcx>) -> bool {
}
}
(GenericArgKind::Const(inner_ct), TermKind::Const(target_ct)) => {
use ty::InferConst::*;
match (inner_ct.kind(), target_ct.kind()) {
(ty::ConstKind::Infer(Var(a_vid)), ty::ConstKind::Infer(Var(b_vid))) => {
self.tecx.root_const_var(a_vid) == self.tecx.root_const_var(b_vid)
}
(
ty::ConstKind::Infer(ty::InferConst::Var(a_vid)),
ty::ConstKind::Infer(ty::InferConst::Var(b_vid)),
) => self.tecx.root_const_var(a_vid) == self.tecx.root_const_var(b_vid),
_ => false,
}
}
@@ -5,7 +5,6 @@
use crate::error_reporting::TypeErrCtxt;
use crate::infer::RegionResolutionError;
use crate::infer::RegionResolutionError::*;
mod different_lifetimes;
pub mod find_anon_type;
@@ -83,8 +82,10 @@ pub fn try_report(&self) -> Option<ErrorGuaranteed> {
pub(super) fn regions(&self) -> Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)> {
match (&self.error, self.regions) {
(Some(ConcreteFailure(origin, sub, sup)), None) => Some((origin.span(), *sub, *sup)),
(Some(SubSupConflict(_, _, origin, sub, _, sup, _)), None) => {
(Some(RegionResolutionError::ConcreteFailure(origin, sub, sup)), None) => {
Some((origin.span(), *sub, *sup))
}
(Some(RegionResolutionError::SubSupConflict(_, _, origin, sub, _, sup, _)), None) => {
Some((origin.span(), *sub, *sup))
}
(None, Some((span, sub, sup))) => Some((span, sub, sup)),
@@ -5,6 +5,7 @@
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{Visitor, walk_ty};
use rustc_hir::{self as hir, AmbigArg};
use rustc_infer::infer::SubregionOrigin;
use rustc_middle::hir::nested_filter;
use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::error::ExpectedFound;
@@ -16,7 +17,7 @@
use crate::error_reporting::infer::nice_region_error::NiceRegionError;
use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlighted;
use crate::errors::{ConsiderBorrowingParamHelp, RelationshipHelp, TraitImplDiff};
use crate::infer::{RegionResolutionError, Subtype, ValuePairs};
use crate::infer::{RegionResolutionError, ValuePairs};
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
/// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
@@ -32,7 +33,8 @@ pub(super) fn try_report_impl_not_conforming_to_trait(&self) -> Option<ErrorGuar
_sup,
_,
) = error.clone()
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
&& let (SubregionOrigin::Subtype(sup_trace), SubregionOrigin::Subtype(sub_trace)) =
(&sup_origin, &sub_origin)
&& let &ObligationCauseCode::CompareImplItem { trait_item_def_id, .. } =
sub_trace.cause.code()
&& sub_trace.values == sup_trace.values
@@ -27,7 +27,10 @@
};
use crate::fluent_generated as fluent;
use crate::infer::region_constraints::GenericKind;
use crate::infer::{self, InferCtxt, RegionResolutionError, RegionVariableOrigin, SubregionOrigin};
use crate::infer::{
BoundRegionConversionTime, InferCtxt, RegionResolutionError, RegionVariableOrigin,
SubregionOrigin,
};
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
pub fn report_region_errors(
@@ -219,21 +222,21 @@ fn process_errors(
pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOrigin<'tcx>) {
match *origin {
infer::Subtype(ref trace) => RegionOriginNote::WithRequirement {
SubregionOrigin::Subtype(ref trace) => RegionOriginNote::WithRequirement {
span: trace.cause.span,
requirement: ObligationCauseAsDiagArg(trace.cause.clone()),
expected_found: self.values_str(trace.values, &trace.cause, err.long_ty_path()),
}
.add_to_diag(err),
infer::Reborrow(span) => {
SubregionOrigin::Reborrow(span) => {
RegionOriginNote::Plain { span, msg: fluent::trait_selection_reborrow }
.add_to_diag(err)
}
infer::RelateObjectBound(span) => {
SubregionOrigin::RelateObjectBound(span) => {
RegionOriginNote::Plain { span, msg: fluent::trait_selection_relate_object_bound }
.add_to_diag(err);
}
infer::ReferenceOutlivesReferent(ty, span) => {
SubregionOrigin::ReferenceOutlivesReferent(ty, span) => {
RegionOriginNote::WithName {
span,
msg: fluent::trait_selection_reference_outlives_referent,
@@ -242,7 +245,7 @@ pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOr
}
.add_to_diag(err);
}
infer::RelateParamBound(span, ty, opt_span) => {
SubregionOrigin::RelateParamBound(span, ty, opt_span) => {
RegionOriginNote::WithName {
span,
msg: fluent::trait_selection_relate_param_bound,
@@ -258,24 +261,24 @@ pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOr
.add_to_diag(err);
}
}
infer::RelateRegionParamBound(span, _) => {
SubregionOrigin::RelateRegionParamBound(span, _) => {
RegionOriginNote::Plain {
span,
msg: fluent::trait_selection_relate_region_param_bound,
}
.add_to_diag(err);
}
infer::CompareImplItemObligation { span, .. } => {
SubregionOrigin::CompareImplItemObligation { span, .. } => {
RegionOriginNote::Plain {
span,
msg: fluent::trait_selection_compare_impl_item_obligation,
}
.add_to_diag(err);
}
infer::CheckAssociatedTypeBounds { ref parent, .. } => {
SubregionOrigin::CheckAssociatedTypeBounds { ref parent, .. } => {
self.note_region_origin(err, parent);
}
infer::AscribeUserTypeProvePredicate(span) => {
SubregionOrigin::AscribeUserTypeProvePredicate(span) => {
RegionOriginNote::Plain {
span,
msg: fluent::trait_selection_ascribe_user_type_prove_predicate,
@@ -293,7 +296,7 @@ pub(super) fn report_concrete_failure(
sup: Region<'tcx>,
) -> Diag<'a> {
let mut err = match origin {
infer::Subtype(box trace) => {
SubregionOrigin::Subtype(box trace) => {
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
let mut err = self.report_and_explain_type_error(
trace,
@@ -347,7 +350,7 @@ pub(super) fn report_concrete_failure(
}
err
}
infer::Reborrow(span) => {
SubregionOrigin::Reborrow(span) => {
let reference_valid = note_and_explain::RegionExplanation::new(
self.tcx,
generic_param_scope,
@@ -369,7 +372,7 @@ pub(super) fn report_concrete_failure(
notes: reference_valid.into_iter().chain(content_valid).collect(),
})
}
infer::RelateObjectBound(span) => {
SubregionOrigin::RelateObjectBound(span) => {
let object_valid = note_and_explain::RegionExplanation::new(
self.tcx,
generic_param_scope,
@@ -391,7 +394,7 @@ pub(super) fn report_concrete_failure(
notes: object_valid.into_iter().chain(pointer_valid).collect(),
})
}
infer::RelateParamBound(span, ty, opt_span) => {
SubregionOrigin::RelateParamBound(span, ty, opt_span) => {
let prefix = match sub.kind() {
ty::ReStatic => note_and_explain::PrefixKind::TypeSatisfy,
_ => note_and_explain::PrefixKind::TypeOutlive,
@@ -415,7 +418,7 @@ pub(super) fn report_concrete_failure(
note,
})
}
infer::RelateRegionParamBound(span, ty) => {
SubregionOrigin::RelateRegionParamBound(span, ty) => {
let param_instantiated = note_and_explain::RegionExplanation::new(
self.tcx,
generic_param_scope,
@@ -457,7 +460,7 @@ pub(super) fn report_concrete_failure(
notes: param_instantiated.into_iter().chain(param_must_outlive).collect(),
})
}
infer::ReferenceOutlivesReferent(ty, span) => {
SubregionOrigin::ReferenceOutlivesReferent(ty, span) => {
let pointer_valid = note_and_explain::RegionExplanation::new(
self.tcx,
generic_param_scope,
@@ -480,7 +483,11 @@ pub(super) fn report_concrete_failure(
notes: pointer_valid.into_iter().chain(data_valid).collect(),
})
}
infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => {
SubregionOrigin::CompareImplItemObligation {
span,
impl_item_def_id,
trait_item_def_id,
} => {
let mut err = self.report_extra_impl_obligation(
span,
impl_item_def_id,
@@ -499,7 +506,11 @@ pub(super) fn report_concrete_failure(
}
err
}
infer::CheckAssociatedTypeBounds { impl_item_def_id, trait_item_def_id, parent } => {
SubregionOrigin::CheckAssociatedTypeBounds {
impl_item_def_id,
trait_item_def_id,
parent,
} => {
let mut err = self.report_concrete_failure(generic_param_scope, *parent, sub, sup);
// Don't mention the item name if it's an RPITIT, since that'll just confuse
@@ -520,7 +531,7 @@ pub(super) fn report_concrete_failure(
);
err
}
infer::AscribeUserTypeProvePredicate(span) => {
SubregionOrigin::AscribeUserTypeProvePredicate(span) => {
let instantiated = note_and_explain::RegionExplanation::new(
self.tcx,
generic_param_scope,
@@ -618,7 +629,7 @@ pub(super) fn report_placeholder_failure(
// I can't think how to do better than this right now. -nikomatsakis
debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure");
match placeholder_origin {
infer::Subtype(box ref trace)
SubregionOrigin::Subtype(box ref trace)
if matches!(
&trace.cause.code().peel_derives(),
ObligationCauseCode::WhereClause(..)
@@ -648,7 +659,7 @@ pub(super) fn report_placeholder_failure(
)
}
}
infer::Subtype(box trace) => {
SubregionOrigin::Subtype(box trace) => {
let terr = TypeError::RegionsPlaceholderMismatch;
return self.report_and_explain_type_error(
trace,
@@ -945,8 +956,8 @@ fn report_sub_sup_conflict(
debug!("report_sub_sup_conflict: sup_region={:?}", sup_region);
debug!("report_sub_sup_conflict: sup_origin={:?}", sup_origin);
if let infer::Subtype(ref sup_trace) = sup_origin
&& let infer::Subtype(ref sub_trace) = sub_origin
if let SubregionOrigin::Subtype(ref sup_trace) = sup_origin
&& let SubregionOrigin::Subtype(ref sub_trace) = sub_origin
&& let Some((sup_expected, sup_found)) =
self.values_str(sup_trace.values, &sup_trace.cause, err.long_ty_path())
&& let Some((sub_expected, sub_found)) =
@@ -1004,30 +1015,38 @@ fn report_inference_failure(&self, var_origin: RegionVariableOrigin) -> Diag<'_>
s
};
let var_description = match var_origin {
infer::MiscVariable(_) => String::new(),
infer::PatternRegion(_) => " for pattern".to_string(),
infer::BorrowRegion(_) => " for borrow expression".to_string(),
infer::Autoref(_) => " for autoref".to_string(),
infer::Coercion(_) => " for automatic coercion".to_string(),
infer::BoundRegion(_, br, infer::FnCall) => {
RegionVariableOrigin::MiscVariable(_) => String::new(),
RegionVariableOrigin::PatternRegion(_) => " for pattern".to_string(),
RegionVariableOrigin::BorrowRegion(_) => " for borrow expression".to_string(),
RegionVariableOrigin::Autoref(_) => " for autoref".to_string(),
RegionVariableOrigin::Coercion(_) => " for automatic coercion".to_string(),
RegionVariableOrigin::BoundRegion(_, br, BoundRegionConversionTime::FnCall) => {
format!(" for lifetime parameter {}in function call", br_string(br))
}
infer::BoundRegion(_, br, infer::HigherRankedType) => {
RegionVariableOrigin::BoundRegion(
_,
br,
BoundRegionConversionTime::HigherRankedType,
) => {
format!(" for lifetime parameter {}in generic type", br_string(br))
}
infer::BoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!(
RegionVariableOrigin::BoundRegion(
_,
br,
BoundRegionConversionTime::AssocTypeProjection(def_id),
) => format!(
" for lifetime parameter {}in trait containing associated type `{}`",
br_string(br),
self.tcx.associated_item(def_id).name()
),
infer::RegionParameterDefinition(_, name) => {
RegionVariableOrigin::RegionParameterDefinition(_, name) => {
format!(" for lifetime parameter `{name}`")
}
infer::UpvarRegion(ref upvar_id, _) => {
RegionVariableOrigin::UpvarRegion(ref upvar_id, _) => {
let var_name = self.tcx.hir_name(upvar_id.var_path.hir_id);
format!(" for capture of `{var_name}` by closure")
}
infer::Nll(..) => bug!("NLL variable found in lexical phase"),
RegionVariableOrigin::Nll(..) => bug!("NLL variable found in lexical phase"),
};
struct_span_code_err!(
@@ -47,8 +47,8 @@
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
use crate::traits::{
MismatchedProjectionTypes, NormalizeExt, Obligation, ObligationCause, ObligationCauseCode,
ObligationCtxt, Overflow, PredicateObligation, SelectionContext, SelectionError,
SignatureMismatch, TraitDynIncompatible, elaborate, specialization_graph,
ObligationCtxt, PredicateObligation, SelectionContext, SelectionError, elaborate,
specialization_graph,
};
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
@@ -659,7 +659,7 @@ pub fn report_selection_error(
}
}
SignatureMismatch(box SignatureMismatchData {
SelectionError::SignatureMismatch(box SignatureMismatchData {
found_trait_ref,
expected_trait_ref,
terr: terr @ TypeError::CyclicTy(_),
@@ -669,7 +669,7 @@ pub fn report_selection_error(
expected_trait_ref,
terr,
),
SignatureMismatch(box SignatureMismatchData {
SelectionError::SignatureMismatch(box SignatureMismatchData {
found_trait_ref,
expected_trait_ref,
terr: _,
@@ -690,7 +690,7 @@ pub fn report_selection_error(
def_id,
),
TraitDynIncompatible(did) => {
SelectionError::TraitDynIncompatible(did) => {
let violations = self.tcx.dyn_compatibility_violations(did);
report_dyn_incompatibility(self.tcx, span, None, did, violations)
}
@@ -710,12 +710,12 @@ pub fn report_selection_error(
// Already reported in the query.
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(guar)) |
// Already reported.
Overflow(OverflowError::Error(guar)) => {
SelectionError::Overflow(OverflowError::Error(guar)) => {
self.set_tainted_by_errors(guar);
return guar
},
Overflow(_) => {
SelectionError::Overflow(_) => {
bug!("overflow should be handled before the `report_selection_error` path");
}
@@ -20,7 +20,7 @@
use super::select::SelectionContext;
use super::{
EvaluationResult, FulfillmentError, FulfillmentErrorCode, PredicateObligation,
ScrubbedTraitError, Unimplemented, const_evaluatable, wf,
ScrubbedTraitError, const_evaluatable, wf,
};
use crate::error_reporting::InferCtxtErrorExt;
use crate::infer::{InferCtxt, TyOrConstInferVar};
@@ -456,7 +456,9 @@ fn process_obligation(
ty::PredicateKind::DynCompatible(trait_def_id) => {
if !self.selcx.tcx().is_dyn_compatible(trait_def_id) {
ProcessResult::Error(FulfillmentErrorCode::Select(Unimplemented))
ProcessResult::Error(FulfillmentErrorCode::Select(
SelectionError::Unimplemented,
))
} else {
ProcessResult::Changed(Default::default())
}
@@ -84,9 +84,6 @@ fn mark_error(&mut self, err: SelectionError<'tcx>) {
// was discarded -- this could be because of ambiguity, or because
// a higher-priority candidate is already there.
fn push_candidate(&mut self, candidate: ProjectionCandidate<'tcx>) -> bool {
use self::ProjectionCandidate::*;
use self::ProjectionCandidateSet::*;
// This wacky variable is just used to try and
// make code readable and avoid confusing paths.
// It is assigned a "value" of `()` only on those
@@ -98,12 +95,12 @@ fn push_candidate(&mut self, candidate: ProjectionCandidate<'tcx>) -> bool {
let convert_to_ambiguous;
match self {
None => {
*self = Single(candidate);
ProjectionCandidateSet::None => {
*self = ProjectionCandidateSet::Single(candidate);
return true;
}
Single(current) => {
ProjectionCandidateSet::Single(current) => {
// Duplicates can happen inside ParamEnv. In the case, we
// perform a lazy deduplication.
if current == &candidate {
@@ -118,16 +115,18 @@ fn push_candidate(&mut self, candidate: ProjectionCandidate<'tcx>) -> bool {
// clauses are the safer choice. See the comment on
// `select::SelectionCandidate` and #21974 for more details.
match (current, candidate) {
(ParamEnv(..), ParamEnv(..)) => convert_to_ambiguous = (),
(ParamEnv(..), _) => return false,
(_, ParamEnv(..)) => bug!(
(ProjectionCandidate::ParamEnv(..), ProjectionCandidate::ParamEnv(..)) => {
convert_to_ambiguous = ()
}
(ProjectionCandidate::ParamEnv(..), _) => return false,
(_, ProjectionCandidate::ParamEnv(..)) => bug!(
"should never prefer non-param-env candidates over param-env candidates"
),
(_, _) => convert_to_ambiguous = (),
}
}
Ambiguous | Error(..) => {
ProjectionCandidateSet::Ambiguous | ProjectionCandidateSet::Error(..) => {
return false;
}
}
@@ -135,7 +134,7 @@ fn push_candidate(&mut self, candidate: ProjectionCandidate<'tcx>) -> bool {
// We only ever get here when we moved from a single candidate
// to ambiguous.
let () = convert_to_ambiguous;
*self = Ambiguous;
*self = ProjectionCandidateSet::Ambiguous;
false
}
}
@@ -11,7 +11,7 @@
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::lang_items::LangItem;
use rustc_infer::infer::{DefineOpaqueTypes, HigherRankedType, InferOk};
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk};
use rustc_infer::traits::ObligationCauseCode;
use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
use rustc_middle::ty::{
@@ -28,8 +28,7 @@
use crate::traits::util::{self, closure_trait_ref_and_return_type};
use crate::traits::{
ImplSource, ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause,
PolyTraitObligation, PredicateObligation, Selection, SelectionError, SignatureMismatch,
TraitDynIncompatible, TraitObligation, Unimplemented,
PolyTraitObligation, PredicateObligation, Selection, SelectionError, TraitObligation,
};
impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
@@ -176,7 +175,7 @@ fn confirm_projection_candidate(
let candidate = self.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span,
HigherRankedType,
BoundRegionConversionTime::HigherRankedType,
candidate,
);
let mut obligations = PredicateObligations::new();
@@ -194,7 +193,7 @@ fn confirm_projection_candidate(
.at(&obligation.cause, obligation.param_env)
.eq(DefineOpaqueTypes::No, placeholder_trait_predicate, candidate)
.map(|InferOk { obligations, .. }| obligations)
.map_err(|_| Unimplemented)?,
.map_err(|_| SelectionError::Unimplemented)?,
);
// FIXME(compiler-errors): I don't think this is needed.
@@ -374,7 +373,7 @@ fn flatten_answer_tree<'tcx>(
assume = crate::traits::evaluate_const(self.infcx, assume, obligation.param_env)
}
let Some(assume) = rustc_transmute::Assume::from_const(self.infcx.tcx, assume) else {
return Err(Unimplemented);
return Err(SelectionError::Unimplemented);
};
let dst = predicate.trait_ref.args.type_at(0);
@@ -386,7 +385,7 @@ fn flatten_answer_tree<'tcx>(
transmute_env.is_transmutable(rustc_transmute::Types { dst, src }, assume);
let fully_flattened = match maybe_transmutable {
Answer::No(_) => Err(Unimplemented)?,
Answer::No(_) => Err(SelectionError::Unimplemented)?,
Answer::If(cond) => flatten_answer_tree(self.tcx(), obligation, cond, assume),
Answer::Yes => PredicateObligations::new(),
};
@@ -500,7 +499,7 @@ fn confirm_object_candidate(
});
let object_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span,
HigherRankedType,
BoundRegionConversionTime::HigherRankedType,
object_trait_ref,
);
let object_trait_ref = object_trait_ref.with_self_ty(self.tcx(), self_ty);
@@ -513,7 +512,7 @@ fn confirm_object_candidate(
let upcast_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span,
HigherRankedType,
BoundRegionConversionTime::HigherRankedType,
unnormalized_upcast_trait_ref,
);
let upcast_trait_ref = normalize_with_depth_to(
@@ -530,7 +529,7 @@ fn confirm_object_candidate(
.at(&obligation.cause, obligation.param_env)
.eq(DefineOpaqueTypes::No, trait_predicate.trait_ref, upcast_trait_ref)
.map(|InferOk { obligations, .. }| obligations)
.map_err(|_| Unimplemented)?,
.map_err(|_| SelectionError::Unimplemented)?,
);
// Check supertraits hold. This is so that their associated type bounds
@@ -962,7 +961,7 @@ fn equate_trait_refs(
) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
let found_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span,
HigherRankedType,
BoundRegionConversionTime::HigherRankedType,
found_trait_ref,
);
// Normalize the obligation and expected trait refs together, because why not
@@ -986,7 +985,7 @@ fn equate_trait_refs(
obligations
})
.map_err(|terr| {
SignatureMismatch(Box::new(SignatureMismatchData {
SelectionError::SignatureMismatch(Box::new(SignatureMismatchData {
expected_trait_ref: obligation_trait_ref,
found_trait_ref,
terr,
@@ -1090,7 +1089,7 @@ fn confirm_builtin_unsize_candidate(
.infcx
.at(&obligation.cause, obligation.param_env)
.sup(DefineOpaqueTypes::Yes, target, source_trait)
.map_err(|_| Unimplemented)?;
.map_err(|_| SelectionError::Unimplemented)?;
// Register one obligation for 'a: 'b.
let outlives = ty::OutlivesPredicate(r_a, r_b);
@@ -1109,7 +1108,7 @@ fn confirm_builtin_unsize_candidate(
(_, &ty::Dynamic(data, r, ty::Dyn)) => {
let mut object_dids = data.auto_traits().chain(data.principal_def_id());
if let Some(did) = object_dids.find(|did| !tcx.is_dyn_compatible(*did)) {
return Err(TraitDynIncompatible(did));
return Err(SelectionError::TraitDynIncompatible(did));
}
let predicate_to_obligation = |predicate| {
@@ -1189,7 +1188,7 @@ fn confirm_builtin_unsize_candidate(
.infcx
.at(&obligation.cause, obligation.param_env)
.eq(DefineOpaqueTypes::Yes, b, a)
.map_err(|_| Unimplemented)?;
.map_err(|_| SelectionError::Unimplemented)?;
ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
}
@@ -1198,7 +1197,7 @@ fn confirm_builtin_unsize_candidate(
(&ty::Adt(def, args_a), &ty::Adt(_, args_b)) => {
let unsizing_params = tcx.unsizing_params_for_adt(def.did());
if unsizing_params.is_empty() {
return Err(Unimplemented);
return Err(SelectionError::Unimplemented);
}
let tail_field = def.non_enum_variant().tail();
@@ -1237,7 +1236,7 @@ fn confirm_builtin_unsize_candidate(
.infcx
.at(&obligation.cause, obligation.param_env)
.eq(DefineOpaqueTypes::Yes, target, new_struct)
.map_err(|_| Unimplemented)?;
.map_err(|_| SelectionError::Unimplemented)?;
nested.extend(obligations);
// Construct the nested `TailField<T>: Unsize<TailField<U>>` predicate.
@@ -39,7 +39,7 @@
use super::project::ProjectionTermObligation;
use super::util::closure_trait_ref_and_return_type;
use super::{
ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow,
ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode,
PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult,
TraitQueryMode, const_evaluatable, project, util, wf,
};
@@ -48,9 +48,7 @@
use crate::solve::InferCtxtSelectExt as _;
use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to};
use crate::traits::project::{ProjectAndUnifyResult, ProjectionCacheKeyExt};
use crate::traits::{
EvaluateConstErr, ProjectionCacheKey, Unimplemented, effects, sizedness_fast_path,
};
use crate::traits::{EvaluateConstErr, ProjectionCacheKey, effects, sizedness_fast_path};
mod _match;
mod candidate_assembly;
@@ -454,8 +452,12 @@ fn candidate_from_obligation_no_cache<'o>(
Ok(Some(EvaluatedCandidate { candidate: c, evaluation: eval }))
}
Ok(_) => Ok(None),
Err(OverflowError::Canonical) => Err(Overflow(OverflowError::Canonical)),
Err(OverflowError::Error(e)) => Err(Overflow(OverflowError::Error(e))),
Err(OverflowError::Canonical) => {
Err(SelectionError::Overflow(OverflowError::Canonical))
}
Err(OverflowError::Error(e)) => {
Err(SelectionError::Overflow(OverflowError::Error(e)))
}
})
.flat_map(Result::transpose)
.collect::<Result<Vec<_>, _>>()?;
@@ -479,7 +481,7 @@ fn candidate_from_obligation_no_cache<'o>(
debug!(?stack.obligation.predicate, "found error type in predicate, treating as ambiguous");
Ok(None)
} else {
Err(Unimplemented)
Err(SelectionError::Unimplemented)
}
} else {
let has_non_region_infer = stack.obligation.predicate.has_non_region_infer();
@@ -1222,7 +1224,9 @@ fn evaluate_stack<'o>(
match self.candidate_from_obligation(stack) {
Ok(Some(c)) => self.evaluate_candidate(stack, &c),
Ok(None) => Ok(EvaluatedToAmbig),
Err(Overflow(OverflowError::Canonical)) => Err(OverflowError::Canonical),
Err(SelectionError::Overflow(OverflowError::Canonical)) => {
Err(OverflowError::Canonical)
}
Err(..) => Ok(EvaluatedToErr),
}
}
@@ -1536,7 +1540,7 @@ fn check_candidate_cache(
return Some(res);
} else if cfg!(debug_assertions) {
match infcx.selection_cache.get(&(param_env, pred), tcx) {
None | Some(Err(Overflow(OverflowError::Canonical))) => {}
None | Some(Err(SelectionError::Overflow(OverflowError::Canonical))) => {}
res => bug!("unexpected local cache result: {res:?}"),
}
}
@@ -1592,7 +1596,7 @@ fn insert_candidate_cache(
}
if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
if let Err(Overflow(OverflowError::Canonical)) = candidate {
if let Err(SelectionError::Overflow(OverflowError::Canonical)) = candidate {
// Don't cache overflow globally; we only produce this in certain modes.
} else {
debug!(?pred, ?candidate, "insert_candidate_cache global");
@@ -273,8 +273,6 @@ fn insert(
// Descend the specialization tree, where `parent` is the current parent node.
loop {
use self::Inserted::*;
let insert_result = self.children.entry(parent).or_default().insert(
tcx,
impl_def_id,
@@ -283,11 +281,11 @@ fn insert(
)?;
match insert_result {
BecameNewSibling(opt_lint) => {
Inserted::BecameNewSibling(opt_lint) => {
last_lint = opt_lint;
break;
}
ReplaceChildren(grand_children_to_be) => {
Inserted::ReplaceChildren(grand_children_to_be) => {
// We currently have
//
// P
@@ -326,7 +324,7 @@ fn insert(
}
break;
}
ShouldRecurseOn(new_parent) => {
Inserted::ShouldRecurseOn(new_parent) => {
parent = new_parent;
}
}
+2 -2
View File
@@ -10,7 +10,7 @@
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::traits::{
ImplSource, Obligation, ObligationCause, ObligationCtxt, ScrubbedTraitError, SelectionContext,
Unimplemented, sizedness_fast_path,
SelectionError, sizedness_fast_path,
};
use tracing::debug;
@@ -47,7 +47,7 @@ pub(crate) fn codegen_select_candidate<'tcx>(
let selection = match selcx.select(&obligation) {
Ok(Some(selection)) => selection,
Ok(None) => return Err(CodegenObligationError::Ambiguity),
Err(Unimplemented) => return Err(CodegenObligationError::Unimplemented),
Err(SelectionError::Unimplemented) => return Err(CodegenObligationError::Unimplemented),
Err(e) => {
bug!("Encountered error `{:?}` selecting `{:?}` during codegen", e, trait_ref)
}