Simplify a bunch of trait ref obligation creations
This commit is contained in:
parent
08afabddac
commit
42cc8e8f4e
10 changed files with 17 additions and 40 deletions
|
@ -10,7 +10,7 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
|
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
|
||||||
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
|
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
|
||||||
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef, TypeVisitable};
|
use rustc_middle::ty::{Binder, TraitRef, TypeVisitable};
|
||||||
use rustc_mir_dataflow::{self, Analysis};
|
use rustc_mir_dataflow::{self, Analysis};
|
||||||
use rustc_span::{sym, Span, Symbol};
|
use rustc_span::{sym, Span, Symbol};
|
||||||
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
|
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
|
||||||
|
@ -735,11 +735,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
|
let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
|
||||||
let poly_trait_pred = Binder::dummy(TraitPredicate {
|
let poly_trait_pred =
|
||||||
trait_ref,
|
Binder::dummy(trait_ref).with_constness(ty::BoundConstness::ConstIfConst);
|
||||||
constness: ty::BoundConstness::ConstIfConst,
|
|
||||||
polarity: ty::ImplPolarity::Positive,
|
|
||||||
});
|
|
||||||
let obligation =
|
let obligation =
|
||||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);
|
Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);
|
||||||
|
|
||||||
|
@ -828,9 +825,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
tcx,
|
tcx,
|
||||||
ObligationCause::dummy_with_span(*fn_span),
|
ObligationCause::dummy_with_span(*fn_span),
|
||||||
param_env,
|
param_env,
|
||||||
tcx.mk_predicate(
|
poly_trait_pred,
|
||||||
poly_trait_pred.map_bound(ty::PredicateKind::Trait),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// improve diagnostics by showing what failed. Our requirements are stricter this time
|
// improve diagnostics by showing what failed. Our requirements are stricter this time
|
||||||
|
|
|
@ -13,10 +13,9 @@ use rustc_middle::mir;
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, TraitPredicate,
|
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, Ty,
|
||||||
Ty,
|
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{Binder, BoundConstness, ImplPolarity, TraitRef};
|
use rustc_middle::ty::{Binder, TraitRef};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{BytePos, Pos, Span, Symbol};
|
use rustc_span::{BytePos, Pos, Span, Symbol};
|
||||||
|
@ -150,11 +149,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
tcx,
|
tcx,
|
||||||
ObligationCause::dummy(),
|
ObligationCause::dummy(),
|
||||||
param_env,
|
param_env,
|
||||||
Binder::dummy(TraitPredicate {
|
Binder::dummy(trait_ref),
|
||||||
trait_ref,
|
|
||||||
constness: BoundConstness::NotConst,
|
|
||||||
polarity: ImplPolarity::Positive,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let infcx = tcx.infer_ctxt().build();
|
let infcx = tcx.infer_ctxt().build();
|
||||||
|
|
|
@ -157,11 +157,8 @@ impl Qualif for NeedsNonConstDrop {
|
||||||
cx.tcx,
|
cx.tcx,
|
||||||
ObligationCause::dummy_with_span(cx.body.span),
|
ObligationCause::dummy_with_span(cx.body.span),
|
||||||
cx.param_env,
|
cx.param_env,
|
||||||
ty::Binder::dummy(ty::TraitPredicate {
|
ty::Binder::dummy(cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]))
|
||||||
trait_ref: cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]),
|
.with_constness(ty::BoundConstness::ConstIfConst),
|
||||||
constness: ty::BoundConstness::ConstIfConst,
|
|
||||||
polarity: ty::ImplPolarity::Positive,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let infcx = cx.tcx.infer_ctxt().build();
|
||||||
|
|
|
@ -1784,7 +1784,7 @@ fn receiver_is_implemented<'tcx>(
|
||||||
let tcx = wfcx.tcx();
|
let tcx = wfcx.tcx();
|
||||||
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));
|
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));
|
||||||
|
|
||||||
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref.without_const());
|
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref);
|
||||||
|
|
||||||
if wfcx.infcx.predicate_must_hold_modulo_regions(&obligation) {
|
if wfcx.infcx.predicate_must_hold_modulo_regions(&obligation) {
|
||||||
true
|
true
|
||||||
|
|
|
@ -2149,11 +2149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.tcx,
|
self.tcx,
|
||||||
traits::ObligationCause::dummy(),
|
traits::ObligationCause::dummy(),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
ty::Binder::dummy(ty::TraitPredicate {
|
ty::Binder::dummy(trait_ref),
|
||||||
trait_ref,
|
|
||||||
constness: ty::BoundConstness::NotConst,
|
|
||||||
polarity: ty::ImplPolarity::Positive,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
match SelectionContext::new(&self).select(&obligation) {
|
match SelectionContext::new(&self).select(&obligation) {
|
||||||
Ok(Some(traits::ImplSource::UserDefined(impl_source))) => {
|
Ok(Some(traits::ImplSource::UserDefined(impl_source))) => {
|
||||||
|
|
|
@ -348,7 +348,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
poly_trait_ref.without_const(),
|
poly_trait_ref,
|
||||||
),
|
),
|
||||||
substs,
|
substs,
|
||||||
)
|
)
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
||||||
tcx,
|
tcx,
|
||||||
cause.clone(),
|
cause.clone(),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
ty::Binder::dummy(trait_ref).without_const(),
|
ty::Binder::dummy(trait_ref),
|
||||||
);
|
);
|
||||||
if !self.infcx.predicate_may_hold(&obligation) {
|
if !self.infcx.predicate_may_hold(&obligation) {
|
||||||
debug!("overloaded_deref_ty: cannot match obligation");
|
debug!("overloaded_deref_ty: cannot match obligation");
|
||||||
|
|
|
@ -723,8 +723,7 @@ fn receiver_is_dispatchable<'tcx>(
|
||||||
let obligation = {
|
let obligation = {
|
||||||
let predicate = ty::Binder::dummy(
|
let predicate = ty::Binder::dummy(
|
||||||
tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]),
|
tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]),
|
||||||
)
|
);
|
||||||
.without_const();
|
|
||||||
|
|
||||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
|
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
|
||||||
};
|
};
|
||||||
|
|
|
@ -731,12 +731,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
// <ty as Deref>
|
// <ty as Deref>
|
||||||
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
|
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
|
||||||
|
|
||||||
let obligation = traits::Obligation::new(
|
let obligation =
|
||||||
tcx,
|
traits::Obligation::new(tcx, cause.clone(), param_env, ty::Binder::dummy(trait_ref));
|
||||||
cause.clone(),
|
|
||||||
param_env,
|
|
||||||
ty::Binder::dummy(trait_ref).without_const(),
|
|
||||||
);
|
|
||||||
if !self.infcx.predicate_may_hold(&obligation) {
|
if !self.infcx.predicate_may_hold(&obligation) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,9 +698,8 @@ fn matches_preds<'tcx>(
|
||||||
cx.tcx,
|
cx.tcx,
|
||||||
ObligationCause::dummy(),
|
ObligationCause::dummy(),
|
||||||
cx.param_env,
|
cx.param_env,
|
||||||
cx.tcx.mk_predicate(Binder::bind_with_vars(
|
cx.tcx.mk_predicate(Binder::dummy(
|
||||||
PredicateKind::Projection(p.with_self_ty(cx.tcx, ty)),
|
PredicateKind::Projection(p.with_self_ty(cx.tcx, ty)),
|
||||||
List::empty(),
|
|
||||||
)),
|
)),
|
||||||
)),
|
)),
|
||||||
ExistentialPredicate::AutoTrait(p) => infcx
|
ExistentialPredicate::AutoTrait(p) => infcx
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue