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

View file

@ -10,7 +10,7 @@ use rustc_hir::def::Res::Def;
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 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, '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,

View file

@ -3,7 +3,7 @@ use rustc_infer::infer::canonical::QueryRegionConstraints;
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 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
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,

View file

@ -16,7 +16,7 @@ use rustc_infer::infer::canonical::QueryRegionConstraints;
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 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
};
self.infcx.next_region_var(
BoundRegion(
RegionVariableOrigin::BoundRegion(
term.source_info.span,
br.kind,
BoundRegionConversionTime::FnCall,

View file

@ -9,7 +9,7 @@ use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan, pluralize, struct_
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(),
),
);

View file

@ -11,7 +11,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
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,
);
})
}

View file

@ -10,7 +10,7 @@ use rustc_hir as hir;
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))

View file

@ -7,7 +7,7 @@ use rustc_hir::def::{self, CtorKind, Namespace, Res};
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 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(

View file

@ -44,7 +44,7 @@ use rustc_hir as hir;
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 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
} 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 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
(&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 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
return Err(TypeError::Mismatch);
}
}
Err(traits::Unimplemented) => {
Err(SelectionError::Unimplemented) => {
debug!("coerce_unsized: early return - can't prove obligation");
return Err(TypeError::Mismatch);
}

View file

@ -22,8 +22,7 @@ use rustc_hir::lang_items::LangItem;
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 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),

View file

@ -11,7 +11,7 @@ use rustc_hir::{ExprKind, HirId, LangItem, Node, QPath};
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::TupleArgumentsFlag::*;
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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
};

View file

@ -15,7 +15,7 @@ use rustc_hir::{self as hir, HirId, ItemLocalMap};
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 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
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)
}

View file

@ -9,7 +9,9 @@ use rustc_hir_analysis::hir_ty_lowering::generics::{
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 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
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 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
}
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 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
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,
)
}
}

View file

@ -11,7 +11,7 @@ use rustc_errors::{Applicability, Diag, SubdiagMessage};
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 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);

View file

@ -12,7 +12,7 @@ use rustc_hir::HirId;
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 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
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 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
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 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
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 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
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) =

View file

@ -22,7 +22,7 @@ use rustc_hir::def_id::DefId;
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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();

View file

@ -16,7 +16,7 @@ use rustc_hir::{
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// 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)
}

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 @@ impl<'tcx> InferCtxt<'tcx> {
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 @@ impl<'tcx> InferCtxt<'tcx> {
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 @@ impl<'tcx> TypeTrace<'tcx> {
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 @@ impl<'tcx> SubregionOrigin<'tcx> {
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`"),
}
}
}

View file

@ -141,7 +141,7 @@ impl<'tcx> InferCtxt<'tcx> {
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() {

View file

@ -14,7 +14,7 @@ use tracing::{debug, instrument};
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 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
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);

View file

@ -5,6 +5,7 @@ use rustc_middle::ty::{
};
use super::{FixupError, FixupResult, InferCtxt};
use crate::infer::TyOrConstInferVar;
///////////////////////////////////////////////////////////////////////////
// OPPORTUNISTIC VAR RESOLVER
@ -144,13 +145,17 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
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);
}

View file

@ -20,8 +20,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
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::{

View file

@ -909,11 +909,11 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
}
}
(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,
}
}

View file

@ -5,7 +5,6 @@ use rustc_span::Span;
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 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
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)),

View file

@ -5,6 +5,7 @@ use rustc_hir::def::{Namespace, Res};
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 tracing::debug;
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 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
_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

View file

@ -27,7 +27,10 @@ use crate::errors::{
};
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
.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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
err
}
infer::Reborrow(span) => {
SubregionOrigin::Reborrow(span) => {
let reference_valid = note_and_explain::RegionExplanation::new(
self.tcx,
generic_param_scope,
@ -369,7 +372,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
);
err
}
infer::AscribeUserTypeProvePredicate(span) => {
SubregionOrigin::AscribeUserTypeProvePredicate(span) => {
let instantiated = note_and_explain::RegionExplanation::new(
self.tcx,
generic_param_scope,
@ -618,7 +629,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// 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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
)
}
}
infer::Subtype(box trace) => {
SubregionOrigin::Subtype(box trace) => {
let terr = TypeError::RegionsPlaceholderMismatch;
return self.report_and_explain_type_error(
trace,
@ -945,8 +956,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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!(

View file

@ -47,8 +47,8 @@ use crate::infer::{self, InferCtxt, InferCtxtExt as _};
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
}
SignatureMismatch(box SignatureMismatchData {
SelectionError::SignatureMismatch(box SignatureMismatchData {
found_trait_ref,
expected_trait_ref,
terr: terr @ TypeError::CyclicTy(_),
@ -669,7 +669,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
expected_trait_ref,
terr,
),
SignatureMismatch(box SignatureMismatchData {
SelectionError::SignatureMismatch(box SignatureMismatchData {
found_trait_ref,
expected_trait_ref,
terr: _,
@ -690,7 +690,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// 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");
}

View file

@ -20,7 +20,7 @@ use super::project::{self, ProjectAndUnifyResult};
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 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
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())
}

View file

@ -84,9 +84,6 @@ impl<'tcx> ProjectionCandidateSet<'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 @@ impl<'tcx> ProjectionCandidateSet<'tcx> {
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 @@ impl<'tcx> ProjectionCandidateSet<'tcx> {
// 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 @@ impl<'tcx> ProjectionCandidateSet<'tcx> {
// We only ever get here when we moved from a single candidate
// to ambiguous.
let () = convert_to_ambiguous;
*self = Ambiguous;
*self = ProjectionCandidateSet::Ambiguous;
false
}
}

View file

@ -11,7 +11,7 @@ use std::ops::ControlFlow;
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::normalize::{normalize_with_depth, normalize_with_depth_to};
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.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 @@ impl<'cx, 'tcx> SelectionContext<'cx, '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 @@ impl<'cx, 'tcx> SelectionContext<'cx, '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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
});
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) -> 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(_, &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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(&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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.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.

View file

@ -39,7 +39,7 @@ use super::coherence::{self, Conflict};
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::infer::{InferCtxt, InferOk, TypeFreshener};
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
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");

View file

@ -273,8 +273,6 @@ impl<'tcx> Graph {
// 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 @@ impl<'tcx> Graph {
)?;
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 @@ impl<'tcx> Graph {
}
break;
}
ShouldRecurseOn(new_parent) => {
Inserted::ShouldRecurseOn(new_parent) => {
parent = new_parent;
}
}

View file

@ -10,7 +10,7 @@ use rustc_middle::ty::{self, PseudoCanonicalInput, TyCtxt, TypeVisitableExt, Upc
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)
}