Auto merge of #104555 - matthiaskrgr:rollup-tncyca8, r=matthiaskrgr

Rollup of 11 pull requests

Successful merges:

 - #103852 (Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl`)
 - #104366 (Simplify settings theme choice)
 - #104433 (Fix `emit_unused_delims_expr` ICE)
 - #104444 (Fix ICE in in_operand for ty error)
 - #104483 (Convert predicates into Predicate in the Obligation constructor)
 - #104496 (Don't attempt to normalize compiler backtraces)
 - #104503 (rustdoc: remove redundant font-color CSS on `.where`)
 - #104508 (Check `dyn*` return type correctly)
 - #104515 (ICE fixing, remove is_tainted_by_errors since we have ty_error for delay bug)
 - #104532 (Migrate tooltip style to CSS variables)
 - #104545 (Readd the matches_macro diag item)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2022-11-18 10:06:28 +00:00
commit 9d46c7a3e6
73 changed files with 640 additions and 372 deletions

View File

@ -7,9 +7,7 @@ use rustc_infer::infer::{DefiningAnchor, InferCtxt};
use rustc_infer::traits::{Obligation, ObligationCause}; use rustc_infer::traits::{Obligation, ObligationCause};
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{ use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
self, OpaqueHiddenType, OpaqueTypeKey, ToPredicate, Ty, TyCtxt, TypeFoldable,
};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
use rustc_trait_selection::traits::ObligationCtxt; use rustc_trait_selection::traits::ObligationCtxt;
@ -256,8 +254,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
// Require the hidden type to be well-formed with only the generics of the opaque type. // Require the hidden type to be well-formed with only the generics of the opaque type.
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
// hidden type is well formed even without those bounds. // hidden type is well formed even without those bounds.
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into())) let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
.to_predicate(infcx.tcx);
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id()); let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
@ -282,6 +279,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
} }
ocx.register_obligation(Obligation::misc( ocx.register_obligation(Obligation::misc(
infcx.tcx,
instantiated_ty.span, instantiated_ty.span,
body_id, body_id,
param_env, param_env,

View File

@ -92,8 +92,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
trait_ref, trait_ref,
constness: ty::BoundConstness::NotConst, constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Positive, polarity: ty::ImplPolarity::Positive,
})) })),
.to_predicate(self.tcx()),
locations, locations,
category, category,
); );
@ -122,14 +121,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
pub(super) fn prove_predicates( pub(super) fn prove_predicates(
&mut self, &mut self,
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>, predicates: impl IntoIterator<
Item = impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
>,
locations: Locations, locations: Locations,
category: ConstraintCategory<'tcx>, category: ConstraintCategory<'tcx>,
) { ) {
for predicate in predicates { for predicate in predicates {
let predicate = predicate.to_predicate(self.tcx());
debug!("prove_predicates(predicate={:?}, locations={:?})", predicate, locations,);
self.prove_predicate(predicate, locations, category); self.prove_predicate(predicate, locations, category);
} }
} }
@ -137,11 +135,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
pub(super) fn prove_predicate( pub(super) fn prove_predicate(
&mut self, &mut self,
predicate: ty::Predicate<'tcx>, predicate: impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
locations: Locations, locations: Locations,
category: ConstraintCategory<'tcx>, category: ConstraintCategory<'tcx>,
) { ) {
let param_env = self.param_env; let param_env = self.param_env;
let predicate = predicate.to_predicate(self.tcx());
self.fully_perform_op( self.fully_perform_op(
locations, locations,
category, category,

View File

@ -33,8 +33,7 @@ use rustc_middle::ty::subst::{SubstsRef, UserSubsts};
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic, self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
OpaqueHiddenType, OpaqueTypeKey, RegionVid, ToPredicate, Ty, TyCtxt, UserType, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
UserTypeAnnotationIndex,
}; };
use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -1069,8 +1068,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
} }
self.prove_predicate( self.prove_predicate(
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into())) ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into())),
.to_predicate(self.tcx()),
Locations::All(span), Locations::All(span),
ConstraintCategory::TypeAnnotation, ConstraintCategory::TypeAnnotation,
); );

View File

@ -732,7 +732,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
polarity: ty::ImplPolarity::Positive, polarity: ty::ImplPolarity::Positive,
}); });
let obligation = let obligation =
Obligation::new(ObligationCause::dummy(), param_env, poly_trait_pred); Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);
let implsrc = { let implsrc = {
let infcx = tcx.infer_ctxt().build(); let infcx = tcx.infer_ctxt().build();
@ -816,6 +816,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
if !nonconst_call_permission { if !nonconst_call_permission {
let obligation = Obligation::new( let obligation = Obligation::new(
tcx,
ObligationCause::dummy_with_span(*fn_span), ObligationCause::dummy_with_span(*fn_span),
param_env, param_env,
tcx.mk_predicate( tcx.mk_predicate(

View File

@ -147,6 +147,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
} }
Adt(..) => { Adt(..) => {
let obligation = Obligation::new( let obligation = Obligation::new(
tcx,
ObligationCause::dummy(), ObligationCause::dummy(),
param_env, param_env,
Binder::dummy(TraitPredicate { Binder::dummy(TraitPredicate {

View File

@ -156,6 +156,7 @@ impl Qualif for NeedsNonConstDrop {
let destruct = cx.tcx.require_lang_item(LangItem::Destruct, None); let destruct = cx.tcx.require_lang_item(LangItem::Destruct, None);
let obligation = Obligation::new( let obligation = Obligation::new(
cx.tcx,
ObligationCause::dummy(), ObligationCause::dummy(),
cx.param_env, cx.param_env,
ty::Binder::dummy(ty::TraitPredicate { ty::Binder::dummy(ty::TraitPredicate {
@ -351,7 +352,11 @@ where
// FIXME(valtrees): check whether const qualifs should behave the same // FIXME(valtrees): check whether const qualifs should behave the same
// way for type and mir constants. // way for type and mir constants.
let uneval = match constant.literal { let uneval = match constant.literal {
ConstantKind::Ty(ct) if matches!(ct.kind(), ty::ConstKind::Param(_)) => None, ConstantKind::Ty(ct)
if matches!(ct.kind(), ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) =>
{
None
}
ConstantKind::Ty(c) => bug!("expected ConstKind::Param here, found {:?}", c), ConstantKind::Ty(c) => bug!("expected ConstKind::Param here, found {:?}", c),
ConstantKind::Unevaluated(uv, _) => Some(uv), ConstantKind::Unevaluated(uv, _) => Some(uv),
ConstantKind::Val(..) => None, ConstantKind::Val(..) => None,

View File

@ -19,9 +19,7 @@ use rustc_middle::middle::stability::EvalResult;
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES}; use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::util::{Discr, IntTypeExt}; use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{ use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
self, ParamEnv, ToPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
};
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS}; use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{self, Span}; use rustc_span::{self, Span};
@ -464,9 +462,8 @@ fn check_opaque_meets_bounds<'tcx>(
// Additionally require the hidden type to be well-formed with only the generics of the opaque type. // Additionally require the hidden type to be well-formed with only the generics of the opaque type.
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
// hidden type is well formed even without those bounds. // hidden type is well formed even without those bounds.
let predicate = let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(hidden_ty.into()));
ty::Binder::dummy(ty::PredicateKind::WellFormed(hidden_ty.into())).to_predicate(tcx); ocx.register_obligation(Obligation::new(tcx, misc_cause, param_env, predicate));
ocx.register_obligation(Obligation::new(misc_cause, param_env, predicate));
// Check that all obligations are satisfied by the implementation's // Check that all obligations are satisfied by the implementation's
// version. // version.

View File

@ -238,7 +238,7 @@ fn compare_predicate_entailment<'tcx>(
kind: impl_m.kind, kind: impl_m.kind,
}, },
); );
ocx.register_obligation(traits::Obligation::new(cause, param_env, predicate)); ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
} }
// We now need to check that the signature of the impl method is // We now need to check that the signature of the impl method is
@ -521,7 +521,13 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
let num_trait_substs = trait_to_impl_substs.len(); let num_trait_substs = trait_to_impl_substs.len();
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len(); let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
let ty = tcx.fold_regions(ty, |region, _| { let ty = tcx.fold_regions(ty, |region, _| {
let (ty::ReFree(_) | ty::ReEarlyBound(_)) = region.kind() else { return region; }; match region.kind() {
// Remap all free regions, which correspond to late-bound regions in the function.
ty::ReFree(_) => {}
// Remap early-bound regions as long as they don't come from the `impl` itself.
ty::ReEarlyBound(ebr) if tcx.parent(ebr.def_id) != impl_m.container_id(tcx) => {}
_ => return region,
}
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind()) let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
else { else {
tcx tcx
@ -605,6 +611,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
); );
self.ocx.register_obligation(traits::Obligation::new( self.ocx.register_obligation(traits::Obligation::new(
self.tcx(),
ObligationCause::new( ObligationCause::new(
self.span, self.span,
self.body_id, self.body_id,
@ -1579,7 +1586,7 @@ fn compare_type_predicate_entailment<'tcx>(
}, },
); );
ocx.register_obligations(obligations); ocx.register_obligations(obligations);
ocx.register_obligation(traits::Obligation::new(cause, param_env, predicate)); ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
} }
// Check that all obligations are satisfied by the implementation's // Check that all obligations are satisfied by the implementation's
@ -1784,7 +1791,7 @@ pub fn check_type_bounds<'tcx>(
.subst_iter_copied(tcx, rebased_substs) .subst_iter_copied(tcx, rebased_substs)
.map(|(concrete_ty_bound, span)| { .map(|(concrete_ty_bound, span)| {
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound); debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound) traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
}) })
.collect(); .collect();
debug!("check_type_bounds: item_bounds={:?}", obligations); debug!("check_type_bounds: item_bounds={:?}", obligations);

View File

@ -14,8 +14,8 @@ use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtKind, DefIdTree, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, self, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
TypeSuperVisitable, TypeVisitable, TypeVisitor, TypeVisitable, TypeVisitor,
}; };
use rustc_middle::ty::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::{GenericArgKind, InternalSubsts};
use rustc_session::parse::feature_err; use rustc_session::parse::feature_err;
@ -75,9 +75,10 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
// for a type to be WF, we do not need to check if const trait predicates satisfy. // for a type to be WF, we do not need to check if const trait predicates satisfy.
let param_env = self.param_env.without_const(); let param_env = self.param_env.without_const();
self.ocx.register_obligation(traits::Obligation::new( self.ocx.register_obligation(traits::Obligation::new(
self.tcx(),
cause, cause,
param_env, param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(self.tcx()), ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)),
)); ));
} }
} }
@ -1111,12 +1112,12 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
traits::MiscObligation, traits::MiscObligation,
); );
wfcx.register_obligation(traits::Obligation::new( wfcx.register_obligation(traits::Obligation::new(
tcx,
cause, cause,
wfcx.param_env, wfcx.param_env,
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable( ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(
ty::Const::from_anon_const(tcx, discr_def_id.expect_local()), ty::Const::from_anon_const(tcx, discr_def_id.expect_local()),
)) )),
.to_predicate(tcx),
)); ));
} }
} }
@ -1453,7 +1454,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
wfcx.body_id, wfcx.body_id,
traits::ItemObligation(def_id.to_def_id()), traits::ItemObligation(def_id.to_def_id()),
); );
traits::Obligation::new(cause, wfcx.param_env, pred) traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
}); });
let predicates = predicates.0.instantiate_identity(tcx); let predicates = predicates.0.instantiate_identity(tcx);
@ -1783,8 +1784,7 @@ fn receiver_is_implemented<'tcx>(
substs: tcx.mk_substs_trait(receiver_ty, &[]), substs: tcx.mk_substs_trait(receiver_ty, &[]),
}); });
let obligation = let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref.without_const());
traits::Obligation::new(cause, wfcx.param_env, trait_ref.without_const().to_predicate(tcx));
if wfcx.infcx.predicate_must_hold_modulo_regions(&obligation) { if wfcx.infcx.predicate_must_hold_modulo_regions(&obligation) {
true true
@ -1931,6 +1931,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
} }
let obligation = traits::Obligation::new( let obligation = traits::Obligation::new(
tcx,
traits::ObligationCause::new(span, self.body_id, traits::TrivialBound), traits::ObligationCause::new(span, self.body_id, traits::TrivialBound),
empty_env, empty_env,
pred, pred,

View File

@ -5,7 +5,7 @@ use rustc_hir::{ForeignItem, ForeignItemKind, HirId};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::{ObligationCause, WellFormedLoc}; use rustc_infer::traits::{ObligationCause, WellFormedLoc};
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, Region, ToPredicate, TyCtxt, TypeFoldable, TypeFolder}; use rustc_middle::ty::{self, Region, TyCtxt, TypeFoldable, TypeFolder};
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
@ -74,10 +74,10 @@ fn diagnostic_hir_wf_check<'tcx>(
let errors = traits::fully_solve_obligation( let errors = traits::fully_solve_obligation(
&infcx, &infcx,
traits::Obligation::new( traits::Obligation::new(
self.tcx,
cause, cause,
self.param_env, self.param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(tcx_ty.into())) ty::Binder::dummy(ty::PredicateKind::WellFormed(tcx_ty.into())),
.to_predicate(self.tcx),
), ),
); );
if !errors.is_empty() { if !errors.is_empty() {

View File

@ -4,7 +4,7 @@ use rustc_errors::{Applicability, Diagnostic, MultiSpan};
use rustc_hir::{self as hir, ExprKind}; use rustc_hir::{self as hir, ExprKind};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::traits::Obligation; use rustc_infer::traits::Obligation;
use rustc_middle::ty::{self, ToPredicate, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_trait_selection::traits::{ use rustc_trait_selection::traits::{
@ -538,23 +538,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.bound_explicit_item_bounds(rpit_def_id) .bound_explicit_item_bounds(rpit_def_id)
.subst_iter_copied(self.tcx, substs) .subst_iter_copied(self.tcx, substs)
{ {
let pred = match pred.kind().skip_binder() { let pred = pred.kind().rebind(match pred.kind().skip_binder() {
ty::PredicateKind::Trait(mut trait_pred) => { ty::PredicateKind::Trait(mut trait_pred) => {
assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty); assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty);
trait_pred.trait_ref.substs = trait_pred.trait_ref.substs =
self.tcx.mk_substs_trait(ty, &trait_pred.trait_ref.substs[1..]); self.tcx.mk_substs_trait(ty, &trait_pred.trait_ref.substs[1..]);
pred.kind().rebind(trait_pred).to_predicate(self.tcx) ty::PredicateKind::Trait(trait_pred)
} }
ty::PredicateKind::Projection(mut proj_pred) => { ty::PredicateKind::Projection(mut proj_pred) => {
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty); assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
proj_pred.projection_ty.substs = self proj_pred.projection_ty.substs = self
.tcx .tcx
.mk_substs_trait(ty, &proj_pred.projection_ty.substs[1..]); .mk_substs_trait(ty, &proj_pred.projection_ty.substs[1..]);
pred.kind().rebind(proj_pred).to_predicate(self.tcx) ty::PredicateKind::Projection(proj_pred)
} }
_ => continue, _ => continue,
}; });
if !self.predicate_must_hold_modulo_regions(&Obligation::new( if !self.predicate_must_hold_modulo_regions(&Obligation::new(
self.tcx,
ObligationCause::misc(span, self.body_id), ObligationCause::misc(span, self.body_id),
self.param_env, self.param_env,
pred, pred,

View File

@ -380,6 +380,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
predicates.predicates.iter().zip(&predicates.spans) predicates.predicates.iter().zip(&predicates.spans)
{ {
let obligation = Obligation::new( let obligation = Obligation::new(
self.tcx,
ObligationCause::dummy_with_span(callee_expr.span), ObligationCause::dummy_with_span(callee_expr.span),
self.param_env, self.param_env,
*predicate, *predicate,

View File

@ -102,7 +102,7 @@ pub(super) fn check_fn<'a, 'tcx>(
inherited.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig); inherited.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
if let ty::Dynamic(..) = declared_ret_ty.kind() { if let ty::Dynamic(_, _, ty::Dyn) = declared_ret_ty.kind() {
// FIXME: We need to verify that the return type is `Sized` after the return expression has // FIXME: We need to verify that the return type is `Sized` after the return expression has
// been evaluated so that we have types available for all the nodes being returned, but that // been evaluated so that we have types available for all the nodes being returned, but that
// requires the coerced evaluated type to be stored. Moving `check_return_expr` before this // requires the coerced evaluated type to be stored. Moving `check_return_expr` before this

View File

@ -55,7 +55,7 @@ use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::relate::RelateResult; use rustc_middle::ty::relate::RelateResult;
use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, ToPredicate, Ty, TypeAndMut}; use rustc_middle::ty::{self, Ty, TypeAndMut};
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::{self, BytePos, DesugaringKind, Span}; use rustc_span::{self, BytePos, DesugaringKind, Span};
@ -278,13 +278,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
for &source_ty in &[a, b] { for &source_ty in &[a, b] {
if source_ty != target_ty { if source_ty != target_ty {
obligations.push(Obligation::new( obligations.push(Obligation::new(
self.tcx(),
self.cause.clone(), self.cause.clone(),
self.param_env, self.param_env,
ty::Binder::dummy(ty::PredicateKind::Coerce(ty::CoercePredicate { ty::Binder::dummy(ty::PredicateKind::Coerce(ty::CoercePredicate {
a: source_ty, a: source_ty,
b: target_ty, b: target_ty,
})) })),
.to_predicate(self.tcx()),
)); ));
} }
} }
@ -669,7 +669,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
continue; continue;
} }
}; };
match selcx.select(&obligation.with(trait_pred)) { match selcx.select(&obligation.with(selcx.tcx(), trait_pred)) {
// Uncertain or unimplemented. // Uncertain or unimplemented.
Ok(None) => { Ok(None) => {
if trait_pred.def_id() == unsize_did { if trait_pred.def_id() == unsize_did {
@ -783,10 +783,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// and then require that the resulting predicate (e.g., `usize: Clone`) // and then require that the resulting predicate (e.g., `usize: Clone`)
// holds (it does). // holds (it does).
let predicate = predicate.with_self_ty(self.tcx, a); let predicate = predicate.with_self_ty(self.tcx, a);
Obligation::new(self.cause.clone(), self.param_env, predicate) Obligation::new(self.tcx, self.cause.clone(), self.param_env, predicate)
}) })
// Enforce the region bound (e.g., `usize: 'static`, in our example). // Enforce the region bound (e.g., `usize: 'static`, in our example).
.chain([Obligation::new( .chain([Obligation::new(
self.tcx,
self.cause.clone(), self.cause.clone(),
self.param_env, self.param_env,
self.tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::TypeOutlives( self.tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::TypeOutlives(

View File

@ -22,8 +22,7 @@ use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtKind, CanonicalUserType, DefIdTree, EarlyBinder, GenericParamDefKind, ToPredicate, Ty, self, AdtKind, CanonicalUserType, DefIdTree, EarlyBinder, GenericParamDefKind, Ty, UserType,
UserType,
}; };
use rustc_middle::ty::{GenericArgKind, InternalSubsts, SubstsRef, UserSelfTy, UserSubsts}; use rustc_middle::ty::{GenericArgKind, InternalSubsts, SubstsRef, UserSelfTy, UserSubsts};
use rustc_session::lint; use rustc_session::lint;
@ -559,9 +558,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// WF obligations never themselves fail, so no real need to give a detailed cause: // WF obligations never themselves fail, so no real need to give a detailed cause:
let cause = traits::ObligationCause::new(span, self.body_id, code); let cause = traits::ObligationCause::new(span, self.body_id, code);
self.register_predicate(traits::Obligation::new( self.register_predicate(traits::Obligation::new(
self.tcx,
cause, cause,
self.param_env, self.param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(self.tcx), ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)),
)); ));
} }

View File

@ -73,7 +73,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.typeck_results.borrow().expr_ty_adjusted(expr); let ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
let ty = self.resolve_vars_if_possible(ty); let ty = self.resolve_vars_if_possible(ty);
if ty.has_non_region_infer() { if ty.has_non_region_infer() {
assert!(self.is_tainted_by_errors());
self.tcx.ty_error() self.tcx.ty_error()
} else { } else {
self.tcx.erase_regions(ty) self.tcx.erase_regions(ty)
@ -2150,6 +2149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
), ),
); );
let obligation = traits::Obligation::new( let obligation = traits::Obligation::new(
self.tcx,
traits::ObligationCause::dummy(), traits::ObligationCause::dummy(),
self.param_env, self.param_env,
ty::Binder::dummy(ty::TraitPredicate { ty::Binder::dummy(ty::TraitPredicate {

View File

@ -1090,14 +1090,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(into_def_id) = self.tcx.get_diagnostic_item(sym::Into) if let Some(into_def_id) = self.tcx.get_diagnostic_item(sym::Into)
&& self.predicate_must_hold_modulo_regions(&traits::Obligation::new( && self.predicate_must_hold_modulo_regions(&traits::Obligation::new(
self.tcx,
self.misc(expr.span), self.misc(expr.span),
self.param_env, self.param_env,
ty::Binder::dummy(ty::TraitRef { ty::Binder::dummy(ty::TraitRef {
def_id: into_def_id, def_id: into_def_id,
substs: self.tcx.mk_substs_trait(expr_ty, &[expected_ty.into()]), substs: self.tcx.mk_substs_trait(expr_ty, &[expected_ty.into()]),
}) })
.to_poly_trait_predicate() .to_poly_trait_predicate(),
.to_predicate(self.tcx),
)) ))
{ {
let sugg = if expr.precedence().order() >= PREC_POSTFIX { let sugg = if expr.precedence().order() >= PREC_POSTFIX {

View File

@ -20,7 +20,7 @@ use rustc_hir::def_id::DefId;
use rustc_infer::infer::{self, InferOk}; use rustc_infer::infer::{self, InferOk};
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef}; use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::{self, DefIdTree, GenericParamDefKind, ToPredicate, Ty, TypeVisitable}; use rustc_middle::ty::{self, DefIdTree, GenericParamDefKind, Ty, TypeVisitable};
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
@ -293,10 +293,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let poly_trait_ref = ty::Binder::dummy(trait_ref); let poly_trait_ref = ty::Binder::dummy(trait_ref);
( (
traits::Obligation::misc( traits::Obligation::misc(
self.tcx,
span, span,
self.body_id, self.body_id,
self.param_env, self.param_env,
poly_trait_ref.without_const().to_predicate(self.tcx), poly_trait_ref.without_const(),
), ),
substs, substs,
) )
@ -335,6 +336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
( (
traits::Obligation::new( traits::Obligation::new(
self.tcx,
traits::ObligationCause::new( traits::ObligationCause::new(
span, span,
self.body_id, self.body_id,
@ -346,7 +348,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}, },
), ),
self.param_env, self.param_env,
poly_trait_ref.without_const().to_predicate(self.tcx), poly_trait_ref.without_const(),
), ),
substs, substs,
) )
@ -523,9 +525,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
method_ty, obligation method_ty, obligation
); );
obligations.push(traits::Obligation::new( obligations.push(traits::Obligation::new(
tcx,
cause, cause,
self.param_env, self.param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(method_ty.into())).to_predicate(tcx), ty::Binder::dummy(ty::PredicateKind::WellFormed(method_ty.into())),
)); ));
let callee = MethodCallee { def_id, substs, sig: fn_sig }; let callee = MethodCallee { def_id, substs, sig: fn_sig };

View File

@ -19,7 +19,8 @@ use rustc_middle::middle::stability;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::AssocItem; use rustc_middle::ty::AssocItem;
use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{self, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitable}; use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeFoldable, TypeVisitable};
use rustc_middle::ty::{InternalSubsts, SubstsRef}; use rustc_middle::ty::{InternalSubsts, SubstsRef};
use rustc_session::lint; use rustc_session::lint;
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
@ -1429,7 +1430,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> { ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
let cause = traits::ObligationCause::misc(self.span, self.body_id); let cause = traits::ObligationCause::misc(self.span, self.body_id);
let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate(); let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate();
let obligation = traits::Obligation::new(cause, self.param_env, predicate); let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
traits::SelectionContext::new(self).select(&obligation) traits::SelectionContext::new(self).select(&obligation)
} }
@ -1560,7 +1561,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let predicate = let predicate =
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx); ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx);
parent_pred = Some(predicate); parent_pred = Some(predicate);
let obligation = traits::Obligation::new(cause, self.param_env, predicate); let obligation =
traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
if !self.predicate_may_hold(&obligation) { if !self.predicate_may_hold(&obligation) {
result = ProbeResult::NoMatch; result = ProbeResult::NoMatch;
if self.probe(|_| { if self.probe(|_| {

View File

@ -23,7 +23,7 @@ use rustc_middle::traits::util::supertraits;
use rustc_middle::ty::fast_reject::DeepRejectCtxt; use rustc_middle::ty::fast_reject::DeepRejectCtxt;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::print::with_crate_prefix; use rustc_middle::ty::print::with_crate_prefix;
use rustc_middle::ty::{self, DefIdTree, GenericArgKind, ToPredicate, Ty, TyCtxt, TypeVisitable}; use rustc_middle::ty::{self, DefIdTree, GenericArgKind, Ty, TyCtxt, TypeVisitable};
use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef}; use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef};
use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::Symbol; use rustc_span::Symbol;
@ -80,10 +80,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs); let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs);
let poly_trait_ref = ty::Binder::dummy(trait_ref); let poly_trait_ref = ty::Binder::dummy(trait_ref);
let obligation = Obligation::misc( let obligation = Obligation::misc(
tcx,
span, span,
self.body_id, self.body_id,
self.param_env, self.param_env,
poly_trait_ref.without_const().to_predicate(tcx), poly_trait_ref.without_const(),
); );
self.predicate_may_hold(&obligation) self.predicate_may_hold(&obligation)
}) })

View File

@ -581,9 +581,9 @@ impl<'tcx> InferCtxt<'tcx> {
span_bug!(cause.span, "unexpected const outlives {:?}", predicate); span_bug!(cause.span, "unexpected const outlives {:?}", predicate);
} }
}; };
let predicate = predicate.0.rebind(atom).to_predicate(self.tcx); let predicate = predicate.0.rebind(atom);
Obligation::new(cause, param_env, predicate) Obligation::new(self.tcx, cause, param_env, predicate)
} }
/// Given two sets of values for the same set of canonical variables, unify them. /// Given two sets of values for the same set of canonical variables, unify them.

View File

@ -37,7 +37,7 @@ use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeVisitable}; use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitable};
use rustc_middle::ty::{IntType, UintType}; use rustc_middle::ty::{IntType, UintType};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -347,10 +347,10 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
if needs_wf { if needs_wf {
self.obligations.push(Obligation::new( self.obligations.push(Obligation::new(
self.tcx(),
self.trace.cause.clone(), self.trace.cause.clone(),
self.param_env, self.param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(b_ty.into())) ty::Binder::dummy(ty::PredicateKind::WellFormed(b_ty.into())),
.to_predicate(self.infcx.tcx),
)); ));
} }
@ -444,9 +444,10 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
ty::PredicateKind::ConstEquate(b, a) ty::PredicateKind::ConstEquate(b, a)
}; };
self.obligations.push(Obligation::new( self.obligations.push(Obligation::new(
self.tcx(),
self.trace.cause.clone(), self.trace.cause.clone(),
self.param_env, self.param_env,
ty::Binder::dummy(predicate).to_predicate(self.tcx()), ty::Binder::dummy(predicate),
)); ));
} }
} }

View File

@ -595,7 +595,12 @@ impl<'tcx> InferCtxt<'tcx> {
} }
// Require that the predicate holds for the concrete type. // Require that the predicate holds for the concrete type.
debug!(?predicate); debug!(?predicate);
obligations.push(traits::Obligation::new(cause.clone(), param_env, predicate)); obligations.push(traits::Obligation::new(
self.tcx,
cause.clone(),
param_env,
predicate,
));
} }
Ok(InferOk { value: (), obligations }) Ok(InferOk { value: (), obligations })
} }

View File

@ -1,5 +1,5 @@
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::{self, ToPredicate, Ty}; use rustc_middle::ty::{self, Ty};
use crate::traits::{Obligation, PredicateObligation}; use crate::traits::{Obligation, PredicateObligation};
@ -28,12 +28,8 @@ impl<'tcx> InferCtxt<'tcx> {
}); });
let projection = let projection =
ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, term: ty_var.into() }); ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, term: ty_var.into() });
let obligation = Obligation::with_depth( let obligation =
cause, Obligation::with_depth(self.tcx, cause, recursion_depth, param_env, projection);
recursion_depth,
param_env,
projection.to_predicate(self.tcx),
);
obligations.push(obligation); obligations.push(obligation);
ty_var ty_var
} }

View File

@ -6,7 +6,7 @@ use crate::traits::Obligation;
use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::TyVar; use rustc_middle::ty::TyVar;
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use std::mem; use std::mem;
/// Ensures `a` is made a subtype of `b`. Returns `a` on success. /// Ensures `a` is made a subtype of `b`. Returns `a` on success.
@ -95,14 +95,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
// can't make progress on `A <: B` if both A and B are // can't make progress on `A <: B` if both A and B are
// type variables, so record an obligation. // type variables, so record an obligation.
self.fields.obligations.push(Obligation::new( self.fields.obligations.push(Obligation::new(
self.tcx(),
self.fields.trace.cause.clone(), self.fields.trace.cause.clone(),
self.fields.param_env, self.fields.param_env,
ty::Binder::dummy(ty::PredicateKind::Subtype(ty::SubtypePredicate { ty::Binder::dummy(ty::PredicateKind::Subtype(ty::SubtypePredicate {
a_is_expected: self.a_is_expected, a_is_expected: self.a_is_expected,
a, a,
b, b,
})) })),
.to_predicate(self.tcx()),
)); ));
Ok(a) Ok(a)

View File

@ -10,7 +10,7 @@ pub mod util;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{self, Const, Ty, TyCtxt}; use rustc_middle::ty::{self, Const, ToPredicate, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
pub use self::FulfillmentErrorCode::*; pub use self::FulfillmentErrorCode::*;
@ -124,38 +124,41 @@ pub enum FulfillmentErrorCode<'tcx> {
impl<'tcx, O> Obligation<'tcx, O> { impl<'tcx, O> Obligation<'tcx, O> {
pub fn new( pub fn new(
tcx: TyCtxt<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
predicate: O, predicate: impl ToPredicate<'tcx, O>,
) -> Obligation<'tcx, O> { ) -> Obligation<'tcx, O> {
Obligation { cause, param_env, recursion_depth: 0, predicate } Self::with_depth(tcx, cause, 0, param_env, predicate)
} }
pub fn with_depth( pub fn with_depth(
tcx: TyCtxt<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
recursion_depth: usize, recursion_depth: usize,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
predicate: O, predicate: impl ToPredicate<'tcx, O>,
) -> Obligation<'tcx, O> { ) -> Obligation<'tcx, O> {
let predicate = predicate.to_predicate(tcx);
Obligation { cause, param_env, recursion_depth, predicate } Obligation { cause, param_env, recursion_depth, predicate }
} }
pub fn misc( pub fn misc(
tcx: TyCtxt<'tcx>,
span: Span, span: Span,
body_id: hir::HirId, body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
trait_ref: O, trait_ref: impl ToPredicate<'tcx, O>,
) -> Obligation<'tcx, O> { ) -> Obligation<'tcx, O> {
Obligation::new(ObligationCause::misc(span, body_id), param_env, trait_ref) Obligation::new(tcx, ObligationCause::misc(span, body_id), param_env, trait_ref)
} }
pub fn with<P>(&self, value: P) -> Obligation<'tcx, P> { pub fn with<P>(
Obligation { &self,
cause: self.cause.clone(), tcx: TyCtxt<'tcx>,
param_env: self.param_env, value: impl ToPredicate<'tcx, P>,
recursion_depth: self.recursion_depth, ) -> Obligation<'tcx, P> {
predicate: value, Obligation::with_depth(tcx, self.cause.clone(), self.recursion_depth, self.param_env, value)
}
} }
} }

View File

@ -108,6 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// then we must've taken advantage of the hack in `project_and_unify_types` where // then we must've taken advantage of the hack in `project_and_unify_types` where
// we replace opaques with inference vars. Emit a warning! // we replace opaques with inference vars. Emit a warning!
if !infcx.predicate_must_hold_modulo_regions(&traits::Obligation::new( if !infcx.predicate_must_hold_modulo_regions(&traits::Obligation::new(
cx.tcx,
traits::ObligationCause::dummy(), traits::ObligationCause::dummy(),
cx.param_env, cx.param_env,
assoc_pred, assoc_pred,

View File

@ -533,16 +533,14 @@ trait UnusedDelimLint {
right_pos: Option<BytePos>, right_pos: Option<BytePos>,
) { ) {
let spans = match value.kind { let spans = match value.kind {
ast::ExprKind::Block(ref block, None) if block.stmts.len() > 0 => { ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => {
let start = block.stmts[0].span; if let StmtKind::Expr(expr) = &block.stmts[0].kind
let end = block.stmts[block.stmts.len() - 1].span; && let ExprKind::Err = expr.kind
if let Some(start) = start.find_ancestor_inside(value.span)
&& let Some(end) = end.find_ancestor_inside(value.span)
{ {
Some(( return
value.span.with_hi(start.lo()), }
value.span.with_lo(end.hi()), if let Some(span) = block.stmts[0].span.find_ancestor_inside(value.span) {
)) Some((value.span.with_hi(span.lo()), value.span.with_lo(span.hi())))
} else { } else {
None None
} }

View File

@ -1125,42 +1125,42 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> {
} }
} }
pub trait ToPredicate<'tcx> { pub trait ToPredicate<'tcx, Predicate> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>; fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate;
} }
impl<'tcx> ToPredicate<'tcx> for Predicate<'tcx> { impl<'tcx, T> ToPredicate<'tcx, T> for T {
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T {
self self
} }
} }
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> { impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tcx>> {
#[inline(always)] #[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
tcx.mk_predicate(self) tcx.mk_predicate(self)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyTraitPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateKind::Trait).to_predicate(tcx) self.map_bound(PredicateKind::Trait).to_predicate(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyRegionOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateKind::RegionOutlives).to_predicate(tcx) self.map_bound(PredicateKind::RegionOutlives).to_predicate(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyTypeOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateKind::TypeOutlives).to_predicate(tcx) self.map_bound(PredicateKind::TypeOutlives).to_predicate(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateKind::Projection).to_predicate(tcx) self.map_bound(PredicateKind::Projection).to_predicate(tcx)
} }

View File

@ -893,6 +893,7 @@ symbols! {
masked, masked,
match_beginning_vert, match_beginning_vert,
match_default_bindings, match_default_bindings,
matches_macro,
maxnumf32, maxnumf32,
maxnumf64, maxnumf64,
may_dangle, may_dangle,

View File

@ -3,8 +3,8 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
use crate::traits::{self, TraitEngine, TraitEngineExt}; use crate::traits::{self, TraitEngine, TraitEngineExt};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_middle::ty::TypeVisitable;
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt}; use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt};
use rustc_middle::ty::{ToPredicate, TypeVisitable};
use rustc_session::Limit; use rustc_session::Limit;
use rustc_span::def_id::LOCAL_CRATE; use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::Span; use rustc_span::Span;
@ -130,9 +130,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
let cause = traits::ObligationCause::misc(self.span, self.body_id); let cause = traits::ObligationCause::misc(self.span, self.body_id);
let obligation = traits::Obligation::new( let obligation = traits::Obligation::new(
tcx,
cause.clone(), cause.clone(),
self.param_env, self.param_env,
ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx), ty::Binder::dummy(trait_ref).without_const(),
); );
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");

View File

@ -96,8 +96,12 @@ impl<'tcx> AutoTraitFinder<'tcx> {
PolyTraitRef::to_poly_trait_predicate, PolyTraitRef::to_poly_trait_predicate,
PolyTraitRef::to_poly_trait_predicate_negative_polarity, PolyTraitRef::to_poly_trait_predicate_negative_polarity,
] { ] {
let result = let result = selcx.select(&Obligation::new(
selcx.select(&Obligation::new(ObligationCause::dummy(), orig_env, f(&trait_pred))); tcx,
ObligationCause::dummy(),
orig_env,
f(&trait_pred),
));
if let Ok(Some(ImplSource::UserDefined(_))) = result { if let Ok(Some(ImplSource::UserDefined(_))) = result {
debug!( debug!(
"find_auto_trait_generics({:?}): \ "find_auto_trait_generics({:?}): \
@ -280,8 +284,12 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// Call `infcx.resolve_vars_if_possible` to see if we can // Call `infcx.resolve_vars_if_possible` to see if we can
// get rid of any inference variables. // get rid of any inference variables.
let obligation = let obligation = infcx.resolve_vars_if_possible(Obligation::new(
infcx.resolve_vars_if_possible(Obligation::new(dummy_cause.clone(), new_env, pred)); tcx,
dummy_cause.clone(),
new_env,
pred,
));
let result = select.select(&obligation); let result = select.select(&obligation);
match result { match result {
@ -706,7 +714,10 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// and turn them into an explicit negative impl for our type. // and turn them into an explicit negative impl for our type.
debug!("Projecting and unifying projection predicate {:?}", predicate); debug!("Projecting and unifying projection predicate {:?}", predicate);
match project::poly_project_and_unify_type(select, &obligation.with(p)) { match project::poly_project_and_unify_type(
select,
&obligation.with(self.tcx, p),
) {
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => { ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
debug!( debug!(
"evaluate_nested_obligations: Unable to unify predicate \ "evaluate_nested_obligations: Unable to unify predicate \

View File

@ -40,7 +40,7 @@ pub fn codegen_select_candidate<'tcx>(
let obligation_cause = ObligationCause::dummy(); let obligation_cause = ObligationCause::dummy();
let obligation = let obligation =
Obligation::new(obligation_cause, param_env, trait_ref.to_poly_trait_predicate()); Obligation::new(tcx, obligation_cause, param_env, trait_ref.to_poly_trait_predicate());
let selection = match selcx.select(&obligation) { let selection = match selcx.select(&obligation) {
Ok(Some(selection)) => selection, Ok(Some(selection)) => selection,

View File

@ -32,7 +32,7 @@ pub fn recompute_applicable_impls<'tcx>(
impl_predicates impl_predicates
.predicates .predicates
.iter() .iter()
.map(|&predicate| Obligation::new(dummy_cause.clone(), param_env, predicate)), .map(|&predicate| Obligation::new(tcx, dummy_cause.clone(), param_env, predicate)),
); );
ocx.select_where_possible().is_empty() ocx.select_where_possible().is_empty()

View File

@ -344,14 +344,14 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}); });
let substs = self.tcx.mk_substs_trait(ty.skip_binder(), &[var.into()]); let substs = self.tcx.mk_substs_trait(ty.skip_binder(), &[var.into()]);
let obligation = Obligation::new( let obligation = Obligation::new(
self.tcx,
ObligationCause::dummy(), ObligationCause::dummy(),
param_env, param_env,
ty.rebind(ty::TraitPredicate { ty.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef::new(trait_def_id, substs), trait_ref: ty::TraitRef::new(trait_def_id, substs),
constness, constness,
polarity, polarity,
}) }),
.to_predicate(self.tcx),
); );
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.tcx); let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.tcx);
fulfill_cx.register_predicate_obligation(self, obligation); fulfill_cx.register_predicate_obligation(self, obligation);
@ -984,7 +984,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
); );
trait_pred trait_pred
}); });
let unit_obligation = obligation.with(predicate.to_predicate(tcx)); let unit_obligation = obligation.with(tcx, predicate);
if self.predicate_may_hold(&unit_obligation) { if self.predicate_may_hold(&unit_obligation) {
err.note( err.note(
"this error might have been caused by changes to \ "this error might have been caused by changes to \
@ -2012,7 +2012,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
..*tr ..*tr
}); });
Obligation::new(ObligationCause::dummy(), param_env, trait_pred.to_predicate(self.tcx)) Obligation::new(self.tcx, ObligationCause::dummy(), param_env, trait_pred)
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
@ -2100,11 +2100,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
) )
}; };
let obligation = Obligation::new( let obligation = obligation.with(self.tcx, trait_ref.to_poly_trait_predicate());
obligation.cause.clone(),
obligation.param_env,
trait_ref.to_poly_trait_predicate(),
);
let mut selcx = SelectionContext::with_query_mode( let mut selcx = SelectionContext::with_query_mode(
&self, &self,
crate::traits::TraitQueryMode::Standard, crate::traits::TraitQueryMode::Standard,
@ -2534,11 +2530,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
) )
.value; .value;
let obligation = Obligation::new( let obligation =
ObligationCause::dummy(), Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred);
param_env,
cleaned_pred.to_predicate(selcx.tcx()),
);
self.predicate_may_hold(&obligation) self.predicate_may_hold(&obligation)
}) })

View File

@ -301,7 +301,7 @@ pub trait TypeErrCtxtExt<'tcx> {
obligated_types: &mut Vec<Ty<'tcx>>, obligated_types: &mut Vec<Ty<'tcx>>,
seen_requirements: &mut FxHashSet<DefId>, seen_requirements: &mut FxHashSet<DefId>,
) where ) where
T: fmt::Display; T: fmt::Display + ToPredicate<'tcx, T>;
/// Suggest to await before try: future? => future.await? /// Suggest to await before try: future? => future.await?
fn suggest_await_before_try( fn suggest_await_before_try(
@ -334,7 +334,7 @@ pub trait TypeErrCtxtExt<'tcx> {
); );
} }
fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, String) { fn predicate_constraint(generics: &hir::Generics<'_>, pred: ty::Predicate<'_>) -> (Span, String) {
( (
generics.tail_span_for_predicate_suggestion(), generics.tail_span_for_predicate_suggestion(),
format!("{} {}", generics.add_where_or_trailing_comma(), pred), format!("{} {}", generics.add_where_or_trailing_comma(), pred),
@ -416,7 +416,7 @@ fn suggest_restriction<'tcx>(
}, },
// `fn foo(t: impl Trait)` // `fn foo(t: impl Trait)`
// ^ suggest `where <T as Trait>::A: Bound` // ^ suggest `where <T as Trait>::A: Bound`
predicate_constraint(hir_generics, trait_pred.to_predicate(tcx).to_string()), predicate_constraint(hir_generics, trait_pred.to_predicate(tcx)),
]; ];
sugg.extend(ty_spans.into_iter().map(|s| (s, type_param_name.to_string()))); sugg.extend(ty_spans.into_iter().map(|s| (s, type_param_name.to_string())));
@ -440,9 +440,7 @@ fn suggest_restriction<'tcx>(
.find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })), .find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })),
super_traits, super_traits,
) { ) {
(_, None) => { (_, None) => predicate_constraint(hir_generics, trait_pred.to_predicate(tcx)),
predicate_constraint(hir_generics, trait_pred.to_predicate(tcx).to_string())
}
(None, Some((ident, []))) => ( (None, Some((ident, []))) => (
ident.span.shrink_to_hi(), ident.span.shrink_to_hi(),
format!(": {}", trait_pred.print_modifiers_and_trait_path()), format!(": {}", trait_pred.print_modifiers_and_trait_path()),
@ -1162,7 +1160,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
for predicate in predicates.iter() { for predicate in predicates.iter() {
if !self.predicate_must_hold_modulo_regions( if !self.predicate_must_hold_modulo_regions(
&obligation.with(predicate.with_self_ty(self.tcx, self_ref_ty)), &obligation.with(self.tcx, predicate.with_self_ty(self.tcx, self_ref_ty)),
) { ) {
return; return;
} }
@ -1523,7 +1521,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let self_ty_satisfies_dyn_predicates = |self_ty| { let self_ty_satisfies_dyn_predicates = |self_ty| {
predicates.iter().all(|predicate| { predicates.iter().all(|predicate| {
let pred = predicate.with_self_ty(self.tcx, self_ty); let pred = predicate.with_self_ty(self.tcx, self_ty);
let obl = Obligation::new(cause.clone(), param_env, pred); let obl = Obligation::new(self.tcx, cause.clone(), param_env, pred);
self.predicate_may_hold(&obl) self.predicate_may_hold(&obl)
}) })
}; };
@ -2704,7 +2702,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
obligated_types.push(ty); obligated_types.push(ty);
let parent_predicate = parent_trait_ref.to_predicate(tcx); let parent_predicate = parent_trait_ref;
if !self.is_recursive_obligation(obligated_types, &data.parent_code) { if !self.is_recursive_obligation(obligated_types, &data.parent_code) {
// #74711: avoid a stack overflow // #74711: avoid a stack overflow
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
@ -2766,7 +2764,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
_ => err.note(&msg), _ => err.note(&msg),
}; };
let mut parent_predicate = parent_trait_pred.to_predicate(tcx); let mut parent_predicate = parent_trait_pred;
let mut data = &data.derived; let mut data = &data.derived;
let mut count = 0; let mut count = 0;
seen_requirements.insert(parent_def_id); seen_requirements.insert(parent_def_id);
@ -2826,7 +2824,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
ObligationCauseCode::DerivedObligation(ref data) => { ObligationCauseCode::DerivedObligation(ref data) => {
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
let parent_predicate = parent_trait_ref.to_predicate(tcx); let parent_predicate = parent_trait_ref;
// #74711: avoid a stack overflow // #74711: avoid a stack overflow
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
self.note_obligation_cause_code( self.note_obligation_cause_code(
@ -3070,9 +3068,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
..*tr ..*tr
}); });
let field_obl = Obligation::new( let field_obl = Obligation::new(
self.tcx,
obligation.cause.clone(), obligation.cause.clone(),
obligation.param_env, obligation.param_env,
trait_pred.to_predicate(self.tcx), trait_pred,
); );
self.predicate_must_hold_modulo_regions(&field_obl) self.predicate_must_hold_modulo_regions(&field_obl)
}) })

View File

@ -9,7 +9,6 @@ use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::{self, Binder, Const, Ty, TypeVisitable}; use rustc_middle::ty::{self, Binder, Const, Ty, TypeVisitable};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -296,7 +295,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
&mut obligations, &mut obligations,
); );
if predicate != obligation.predicate { if predicate != obligation.predicate {
obligations.push(obligation.with(predicate)); obligations.push(obligation.with(infcx.tcx, predicate));
return ProcessResult::Changed(mk_pending(obligations)); return ProcessResult::Changed(mk_pending(obligations));
} }
} }
@ -307,7 +306,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
// This means we need to pass it the bound version of our // This means we need to pass it the bound version of our
// predicate. // predicate.
ty::PredicateKind::Trait(trait_ref) => { ty::PredicateKind::Trait(trait_ref) => {
let trait_obligation = obligation.with(binder.rebind(trait_ref)); let trait_obligation = obligation.with(infcx.tcx, binder.rebind(trait_ref));
self.process_trait_obligation( self.process_trait_obligation(
obligation, obligation,
@ -316,7 +315,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
) )
} }
ty::PredicateKind::Projection(data) => { ty::PredicateKind::Projection(data) => {
let project_obligation = obligation.with(binder.rebind(data)); let project_obligation = obligation.with(infcx.tcx, binder.rebind(data));
self.process_projection_obligation( self.process_projection_obligation(
obligation, obligation,
@ -335,9 +334,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
| ty::PredicateKind::ConstEquate(..) => { | ty::PredicateKind::ConstEquate(..) => {
let pred = let pred =
ty::Binder::dummy(infcx.replace_bound_vars_with_placeholders(binder)); ty::Binder::dummy(infcx.replace_bound_vars_with_placeholders(binder));
ProcessResult::Changed(mk_pending(vec![ ProcessResult::Changed(mk_pending(vec![obligation.with(infcx.tcx, pred)]))
obligation.with(pred.to_predicate(self.selcx.tcx())),
]))
} }
ty::PredicateKind::TypeWellFormedFromEnv(..) => { ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk") bug!("TypeWellFormedFromEnv is only used for Chalk")
@ -345,7 +342,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
}, },
Some(pred) => match pred { Some(pred) => match pred {
ty::PredicateKind::Trait(data) => { ty::PredicateKind::Trait(data) => {
let trait_obligation = obligation.with(Binder::dummy(data)); let trait_obligation = obligation.with(infcx.tcx, Binder::dummy(data));
self.process_trait_obligation( self.process_trait_obligation(
obligation, obligation,
@ -370,7 +367,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
} }
ty::PredicateKind::Projection(ref data) => { ty::PredicateKind::Projection(ref data) => {
let project_obligation = obligation.with(Binder::dummy(*data)); let project_obligation = obligation.with(infcx.tcx, Binder::dummy(*data));
self.process_projection_obligation( self.process_projection_obligation(
obligation, obligation,
@ -697,7 +694,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
} }
// Let the caller handle the recursion // Let the caller handle the recursion
ProjectAndUnifyResult::Recursive => ProcessResult::Changed(mk_pending(vec![ ProjectAndUnifyResult::Recursive => ProcessResult::Changed(mk_pending(vec![
project_obligation.with(project_obligation.predicate.to_predicate(tcx)), project_obligation.with(tcx, project_obligation.predicate),
])), ])),
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => { ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
ProcessResult::Error(CodeProjectionError(e)) ProcessResult::Error(CodeProjectionError(e))

View File

@ -440,7 +440,7 @@ pub fn impossible_predicates<'tcx>(
let ocx = ObligationCtxt::new(&infcx); let ocx = ObligationCtxt::new(&infcx);
let predicates = ocx.normalize(ObligationCause::dummy(), param_env, predicates); let predicates = ocx.normalize(ObligationCause::dummy(), param_env, predicates);
for predicate in predicates { for predicate in predicates {
let obligation = Obligation::new(ObligationCause::dummy(), param_env, predicate); let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
ocx.register_obligation(obligation); ocx.register_obligation(obligation);
} }
let errors = ocx.select_all_or_error(); let errors = ocx.select_all_or_error();
@ -530,6 +530,7 @@ fn is_impossible_method<'tcx>(
let predicates_for_trait = predicates.predicates.iter().filter_map(|(pred, span)| { let predicates_for_trait = predicates.predicates.iter().filter_map(|(pred, span)| {
if pred.visit_with(&mut visitor).is_continue() { if pred.visit_with(&mut visitor).is_continue() {
Some(Obligation::new( Some(Obligation::new(
tcx,
ObligationCause::dummy_with_span(*span), ObligationCause::dummy_with_span(*span),
param_env, param_env,
ty::EarlyBinder(*pred).subst(tcx, impl_trait_ref.substs), ty::EarlyBinder(*pred).subst(tcx, impl_trait_ref.substs),

View File

@ -723,10 +723,9 @@ fn receiver_is_dispatchable<'tcx>(
def_id: dispatch_from_dyn_did, def_id: dispatch_from_dyn_did,
substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]), substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]),
}) })
.without_const() .without_const();
.to_predicate(tcx);
Obligation::new(ObligationCause::dummy(), param_env, predicate) Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
}; };
let infcx = tcx.infer_ctxt().build(); let infcx = tcx.infer_ctxt().build();

View File

@ -200,7 +200,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
infcx.replace_bound_vars_with_placeholders(obligation.predicate); infcx.replace_bound_vars_with_placeholders(obligation.predicate);
let new_universe = infcx.universe(); let new_universe = infcx.universe();
let placeholder_obligation = obligation.with(placeholder_predicate); let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
match project_and_unify_type(selcx, &placeholder_obligation) { match project_and_unify_type(selcx, &placeholder_obligation) {
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e), ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
ProjectAndUnifyResult::Holds(obligations) ProjectAndUnifyResult::Holds(obligations)
@ -517,6 +517,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
let recursion_limit = self.tcx().recursion_limit(); let recursion_limit = self.tcx().recursion_limit();
if !recursion_limit.value_within_limit(self.depth) { if !recursion_limit.value_within_limit(self.depth) {
let obligation = Obligation::with_depth( let obligation = Obligation::with_depth(
self.tcx(),
self.cause.clone(), self.cause.clone(),
recursion_limit.0, recursion_limit.0,
self.param_env, self.param_env,
@ -573,6 +574,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
&& !self.tcx().sess.opts.actually_rustdoc && !self.tcx().sess.opts.actually_rustdoc
{ {
let obligation = Obligation::with_depth( let obligation = Obligation::with_depth(
self.selcx.tcx(),
self.cause.clone(), self.cause.clone(),
recursion_limit.0, recursion_limit.0,
self.param_env, self.param_env,
@ -1110,7 +1112,8 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
} }
} }
let obligation = Obligation::with_depth(cause.clone(), depth, param_env, projection_ty); let obligation =
Obligation::with_depth(selcx.tcx(), cause.clone(), depth, param_env, projection_ty);
match project(selcx, &obligation) { match project(selcx, &obligation) {
Ok(Projected::Progress(Progress { Ok(Projected::Progress(Progress {
@ -1343,8 +1346,8 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs }) ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs })
.to_poly_trait_predicate(); .to_poly_trait_predicate();
let _ = let _ = selcx.infcx().commit_if_ok(|_| {
selcx.infcx().commit_if_ok(|_| match selcx.select(&obligation.with(trait_predicate)) { match selcx.select(&obligation.with(tcx, trait_predicate)) {
Ok(Some(super::ImplSource::UserDefined(data))) => { Ok(Some(super::ImplSource::UserDefined(data))) => {
candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait( candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait(
ImplTraitInTraitCandidate::Impl(data), ImplTraitInTraitCandidate::Impl(data),
@ -1364,7 +1367,8 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
candidate_set.mark_error(e); candidate_set.mark_error(e);
return Err(()); return Err(());
} }
}); }
});
} }
} }
@ -1538,7 +1542,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// If we are resolving `<T as TraitRef<...>>::Item == Type`, // If we are resolving `<T as TraitRef<...>>::Item == Type`,
// start out by selecting the predicate `T as TraitRef<...>`: // start out by selecting the predicate `T as TraitRef<...>`:
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx())); let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
let trait_obligation = obligation.with(poly_trait_ref.to_poly_trait_predicate()); let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref.to_poly_trait_predicate());
let _ = selcx.infcx().commit_if_ok(|_| { let _ = selcx.infcx().commit_if_ok(|_| {
let impl_source = match selcx.select(&trait_obligation) { let impl_source = match selcx.select(&trait_obligation) {
Ok(Some(impl_source)) => impl_source, Ok(Some(impl_source)) => impl_source,
@ -1705,12 +1709,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
ty::Param(_) | ty::Projection(..) | ty::Opaque(..) ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
if selcx.infcx().predicate_must_hold_modulo_regions( if selcx.infcx().predicate_must_hold_modulo_regions(
&obligation.with( &obligation.with(
selcx.tcx(),
ty::Binder::dummy(ty::TraitRef::new( ty::Binder::dummy(ty::TraitRef::new(
selcx.tcx().require_lang_item(LangItem::Sized, None), selcx.tcx().require_lang_item(LangItem::Sized, None),
selcx.tcx().mk_substs_trait(self_ty, &[]), selcx.tcx().mk_substs_trait(self_ty, &[]),
)) ))
.without_const() .without_const(),
.to_predicate(selcx.tcx()),
), ),
) => ) =>
{ {
@ -1966,13 +1970,8 @@ fn confirm_pointee_candidate<'cx, 'tcx>(
tcx.require_lang_item(LangItem::Sized, None), tcx.require_lang_item(LangItem::Sized, None),
tcx.mk_substs_trait(self_ty, &[]), tcx.mk_substs_trait(self_ty, &[]),
)) ))
.without_const() .without_const();
.to_predicate(tcx); obligations.push(obligation.with(tcx, sized_predicate));
obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
sized_predicate,
));
} }
let substs = tcx.mk_substs([self_ty.into()].iter()); let substs = tcx.mk_substs([self_ty.into()].iter());
@ -2289,6 +2288,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
obligations.extend(std::iter::zip(predicates.predicates, predicates.spans).map( obligations.extend(std::iter::zip(predicates.predicates, predicates.spans).map(
|(pred, span)| { |(pred, span)| {
Obligation::with_depth( Obligation::with_depth(
tcx,
ObligationCause::new( ObligationCause::new(
obligation.cause.span, obligation.cause.span,
obligation.cause.body_id, obligation.cause.body_id,
@ -2342,6 +2342,7 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
nested, nested,
); );
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(
tcx,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
obligation.param_env, obligation.param_env,

View File

@ -208,6 +208,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
let recursion_limit = self.tcx().recursion_limit(); let recursion_limit = self.tcx().recursion_limit();
if !recursion_limit.value_within_limit(self.anon_depth) { if !recursion_limit.value_within_limit(self.anon_depth) {
let obligation = Obligation::with_depth( let obligation = Obligation::with_depth(
self.tcx(),
self.cause.clone(), self.cause.clone(),
recursion_limit.0, recursion_limit.0,
self.param_env, self.param_env,

View File

@ -1,8 +1,8 @@
use crate::infer::InferCtxt; use crate::infer::InferCtxt;
use crate::traits::query::evaluate_obligation::InferCtxtExt; use crate::traits::query::evaluate_obligation::InferCtxtExt;
use crate::traits::{ObligationCause, PredicateObligation}; use crate::traits::PredicateObligation;
use rustc_infer::traits::TraitEngine; use rustc_infer::traits::TraitEngine;
use rustc_middle::ty::{self, ToPredicate}; use rustc_middle::ty;
pub(crate) fn update<'tcx, T>( pub(crate) fn update<'tcx, T>(
engine: &mut T, engine: &mut T,
@ -25,9 +25,7 @@ pub(crate) fn update<'tcx, T>(
// Then construct a new obligation with Self = () added // Then construct a new obligation with Self = () added
// to the ParamEnv, and see if it holds. // to the ParamEnv, and see if it holds.
let o = rustc_infer::traits::Obligation::new( let o = obligation.with(infcx.tcx,
ObligationCause::dummy(),
obligation.param_env,
obligation obligation
.predicate .predicate
.kind() .kind()
@ -38,8 +36,7 @@ pub(crate) fn update<'tcx, T>(
constness: tpred.constness, constness: tpred.constness,
polarity: tpred.polarity, polarity: tpred.polarity,
}) })
) ),
.to_predicate(infcx.tcx),
); );
// Don't report overflow errors. Otherwise equivalent to may_hold. // Don't report overflow errors. Otherwise equivalent to may_hold.
if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) && result.may_apply() { if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) && result.may_apply() {

View File

@ -13,7 +13,7 @@ use rustc_infer::traits::ObligationCause;
use rustc_infer::traits::{Obligation, SelectionError, TraitObligation}; use rustc_infer::traits::{Obligation, SelectionError, TraitObligation};
use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT; use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, ToPredicate, Ty, TypeVisitable}; use rustc_middle::ty::{self, Ty, TypeVisitable};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use crate::traits; use crate::traits;
@ -718,9 +718,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}; };
let obligation = traits::Obligation::new( let obligation = traits::Obligation::new(
tcx,
cause.clone(), cause.clone(),
param_env, param_env,
ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx), 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;

View File

@ -194,6 +194,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut obligations, &mut obligations,
); );
obligations.push(Obligation::with_depth( obligations.push(Obligation::with_depth(
self.tcx(),
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
obligation.param_env, obligation.param_env,
@ -482,11 +483,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
super_trait, super_trait,
&mut nested, &mut nested,
); );
nested.push(Obligation::new( nested.push(obligation.with(tcx, normalized_super_trait));
obligation.cause.clone(),
obligation.param_env,
normalized_super_trait,
));
} }
let assoc_types: Vec<_> = tcx let assoc_types: Vec<_> = tcx
@ -581,11 +578,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
subst_bound, subst_bound,
&mut nested, &mut nested,
); );
nested.push(Obligation::new( nested.push(obligation.with(tcx, normalized_bound));
obligation.cause.clone(),
obligation.param_env,
normalized_bound,
));
} }
} }
@ -644,9 +637,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.tcx().mk_substs_trait(output_ty, &[]), self.tcx().mk_substs_trait(output_ty, &[]),
)); ));
nested.push(Obligation::new( nested.push(Obligation::new(
self.infcx.tcx,
cause, cause,
obligation.param_env, obligation.param_env,
tr.to_poly_trait_predicate().to_predicate(self.tcx()), tr.to_poly_trait_predicate(),
)); ));
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested }) Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
@ -727,11 +721,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// FIXME: Chalk // FIXME: Chalk
if !self.tcx().sess.opts.unstable_opts.chalk { if !self.tcx().sess.opts.unstable_opts.chalk {
nested.push(Obligation::new( nested.push(obligation.with(
obligation.cause.clone(), self.tcx(),
obligation.param_env, ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)),
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind))
.to_predicate(self.tcx()),
)); ));
} }
@ -860,10 +852,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
); );
let outlives = ty::OutlivesPredicate(r_a, r_b); let outlives = ty::OutlivesPredicate(r_a, r_b);
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(
tcx,
cause, cause,
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
obligation.param_env, obligation.param_env,
obligation.predicate.rebind(outlives).to_predicate(tcx), obligation.predicate.rebind(outlives),
)); ));
} }
_ => bug!(), _ => bug!(),
@ -957,10 +950,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
); );
let outlives = ty::OutlivesPredicate(r_a, r_b); let outlives = ty::OutlivesPredicate(r_a, r_b);
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(
tcx,
cause, cause,
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
obligation.param_env, obligation.param_env,
obligation.predicate.rebind(outlives).to_predicate(tcx), obligation.predicate.rebind(outlives),
)); ));
} }
@ -979,6 +973,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let predicate_to_obligation = |predicate| { let predicate_to_obligation = |predicate| {
Obligation::with_depth( Obligation::with_depth(
tcx,
cause.clone(), cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
obligation.param_env, obligation.param_env,
@ -1255,20 +1250,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
cause.clone(), cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
self_ty self_ty.rebind(ty::TraitPredicate {
.rebind(ty::TraitPredicate { trait_ref: ty::TraitRef {
trait_ref: ty::TraitRef { def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
def_id: self.tcx().require_lang_item(LangItem::Destruct, None), substs: self.tcx().mk_substs_trait(nested_ty, &[]),
substs: self.tcx().mk_substs_trait(nested_ty, &[]), },
}, constness: ty::BoundConstness::ConstIfConst,
constness: ty::BoundConstness::ConstIfConst, polarity: ty::ImplPolarity::Positive,
polarity: ty::ImplPolarity::Positive, }),
})
.to_predicate(tcx),
&mut nested, &mut nested,
); );
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(
tcx,
cause.clone(), cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
obligation.param_env, obligation.param_env,
@ -1280,18 +1274,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// since it's either not `const Drop` (and we raise an error during selection), // since it's either not `const Drop` (and we raise an error during selection),
// or it's an ADT (and we need to check for a custom impl during selection) // or it's an ADT (and we need to check for a custom impl during selection)
_ => { _ => {
let predicate = self_ty let predicate = self_ty.rebind(ty::TraitPredicate {
.rebind(ty::TraitPredicate { trait_ref: ty::TraitRef {
trait_ref: ty::TraitRef { def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
def_id: self.tcx().require_lang_item(LangItem::Destruct, None), substs: self.tcx().mk_substs_trait(nested_ty, &[]),
substs: self.tcx().mk_substs_trait(nested_ty, &[]), },
}, constness: ty::BoundConstness::ConstIfConst,
constness: ty::BoundConstness::ConstIfConst, polarity: ty::ImplPolarity::Positive,
polarity: ty::ImplPolarity::Positive, });
})
.to_predicate(tcx);
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(
tcx,
cause.clone(), cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
obligation.param_env, obligation.param_env,

View File

@ -445,7 +445,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::PredicateKind::Trait(t) => { ty::PredicateKind::Trait(t) => {
let t = bound_predicate.rebind(t); let t = bound_predicate.rebind(t);
debug_assert!(!t.has_escaping_bound_vars()); debug_assert!(!t.has_escaping_bound_vars());
let obligation = obligation.with(t); let obligation = obligation.with(self.tcx(), t);
self.evaluate_trait_predicate_recursively(previous_stack, obligation) self.evaluate_trait_predicate_recursively(previous_stack, obligation)
} }
@ -596,7 +596,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::PredicateKind::Projection(data) => { ty::PredicateKind::Projection(data) => {
let data = bound_predicate.rebind(data); let data = bound_predicate.rebind(data);
let project_obligation = obligation.with(data); let project_obligation = obligation.with(self.tcx(), data);
match project::poly_project_and_unify_type(self, &project_obligation) { match project::poly_project_and_unify_type(self, &project_obligation) {
ProjectAndUnifyResult::Holds(mut subobligations) => { ProjectAndUnifyResult::Holds(mut subobligations) => {
'compute_res: { 'compute_res: {

View File

@ -4,7 +4,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeVisitable}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
use rustc_span::Span; use rustc_span::Span;
use std::iter; use std::iter;
@ -324,7 +324,7 @@ impl<'tcx> WfPredicates<'tcx> {
extend_cause_with_original_assoc_item_obligation( extend_cause_with_original_assoc_item_obligation(
tcx, trait_ref, item, &mut cause, predicate, tcx, trait_ref, item, &mut cause, predicate,
); );
traits::Obligation::with_depth(cause, depth, param_env, predicate) traits::Obligation::with_depth(tcx, cause, depth, param_env, predicate)
}; };
if let Elaborate::All = elaborate { if let Elaborate::All = elaborate {
@ -356,10 +356,11 @@ impl<'tcx> WfPredicates<'tcx> {
} }
} }
traits::Obligation::with_depth( traits::Obligation::with_depth(
tcx,
cause, cause,
depth, depth,
param_env, param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(tcx), ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)),
) )
}), }),
); );
@ -407,10 +408,11 @@ impl<'tcx> WfPredicates<'tcx> {
.filter(|arg| !arg.has_escaping_bound_vars()) .filter(|arg| !arg.has_escaping_bound_vars())
.map(|arg| { .map(|arg| {
traits::Obligation::with_depth( traits::Obligation::with_depth(
tcx,
cause.clone(), cause.clone(),
depth, depth,
param_env, param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(tcx), ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)),
) )
}), }),
); );
@ -424,10 +426,11 @@ impl<'tcx> WfPredicates<'tcx> {
substs: self.tcx.mk_substs_trait(subty, &[]), substs: self.tcx.mk_substs_trait(subty, &[]),
}; };
self.out.push(traits::Obligation::with_depth( self.out.push(traits::Obligation::with_depth(
self.tcx,
cause, cause,
self.recursion_depth, self.recursion_depth,
self.param_env, self.param_env,
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx), ty::Binder::dummy(trait_ref).without_const(),
)); ));
} }
} }
@ -454,10 +457,10 @@ impl<'tcx> WfPredicates<'tcx> {
self.out.extend(obligations); self.out.extend(obligations);
let predicate = let predicate =
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct)) ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct));
.to_predicate(self.tcx());
let cause = self.cause(traits::WellFormed(None)); let cause = self.cause(traits::WellFormed(None));
self.out.push(traits::Obligation::with_depth( self.out.push(traits::Obligation::with_depth(
self.tcx(),
cause, cause,
self.recursion_depth, self.recursion_depth,
self.param_env, self.param_env,
@ -468,11 +471,11 @@ impl<'tcx> WfPredicates<'tcx> {
let cause = self.cause(traits::WellFormed(None)); let cause = self.cause(traits::WellFormed(None));
self.out.push(traits::Obligation::with_depth( self.out.push(traits::Obligation::with_depth(
self.tcx(),
cause, cause,
self.recursion_depth, self.recursion_depth,
self.param_env, self.param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(ct.into())) ty::Binder::dummy(ty::PredicateKind::WellFormed(ct.into())),
.to_predicate(self.tcx()),
)); ));
} }
ty::ConstKind::Error(_) ty::ConstKind::Error(_)
@ -556,13 +559,13 @@ impl<'tcx> WfPredicates<'tcx> {
if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() { if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
let cause = self.cause(traits::ReferenceOutlivesReferent(ty)); let cause = self.cause(traits::ReferenceOutlivesReferent(ty));
self.out.push(traits::Obligation::with_depth( self.out.push(traits::Obligation::with_depth(
self.tcx(),
cause, cause,
depth, depth,
param_env, param_env,
ty::Binder::dummy(ty::PredicateKind::TypeOutlives( ty::Binder::dummy(ty::PredicateKind::TypeOutlives(
ty::OutlivesPredicate(rty, r), ty::OutlivesPredicate(rty, r),
)) )),
.to_predicate(self.tcx()),
)); ));
} }
} }
@ -656,11 +659,11 @@ impl<'tcx> WfPredicates<'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
self.out.extend(component_traits.map(|did| { self.out.extend(component_traits.map(|did| {
traits::Obligation::with_depth( traits::Obligation::with_depth(
tcx,
cause.clone(), cause.clone(),
depth, depth,
param_env, param_env,
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(did)) ty::Binder::dummy(ty::PredicateKind::ObjectSafe(did)),
.to_predicate(tcx),
) )
})); }));
} }
@ -681,11 +684,11 @@ impl<'tcx> WfPredicates<'tcx> {
ty::Infer(_) => { ty::Infer(_) => {
let cause = self.cause(traits::WellFormed(None)); let cause = self.cause(traits::WellFormed(None));
self.out.push(traits::Obligation::with_depth( self.out.push(traits::Obligation::with_depth(
self.tcx(),
cause, cause,
self.recursion_depth, self.recursion_depth,
param_env, param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into())) ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into())),
.to_predicate(self.tcx()),
)); ));
} }
} }
@ -724,7 +727,13 @@ impl<'tcx> WfPredicates<'tcx> {
if remap_constness { if remap_constness {
pred = pred.without_const(self.tcx); pred = pred.without_const(self.tcx);
} }
traits::Obligation::with_depth(cause, self.recursion_depth, self.param_env, pred) traits::Obligation::with_depth(
self.tcx,
cause,
self.recursion_depth,
self.param_env,
pred,
)
}) })
.filter(|pred| !pred.has_escaping_bound_vars()) .filter(|pred| !pred.has_escaping_bound_vars())
.collect() .collect()
@ -794,10 +803,11 @@ impl<'tcx> WfPredicates<'tcx> {
let outlives = let outlives =
ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound)); ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound));
self.out.push(traits::Obligation::with_depth( self.out.push(traits::Obligation::with_depth(
self.tcx,
cause, cause,
self.recursion_depth, self.recursion_depth,
self.param_env, self.param_env,
outlives.to_predicate(self.tcx), outlives,
)); ));
} }
} }

View File

@ -26,7 +26,7 @@ fn evaluate_obligation<'tcx>(
let ParamEnvAnd { param_env, value: predicate } = goal; let ParamEnvAnd { param_env, value: predicate } = goal;
let mut selcx = SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical); let mut selcx = SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical);
let obligation = Obligation::new(ObligationCause::dummy(), param_env, predicate); let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
selcx.evaluate_root_obligation(&obligation) selcx.evaluate_root_obligation(&obligation)
} }

View File

@ -91,7 +91,12 @@ impl<'me, 'tcx> AscribeUserTypeCx<'me, 'tcx> {
} }
fn prove_predicate(&self, predicate: Predicate<'tcx>, cause: ObligationCause<'tcx>) { fn prove_predicate(&self, predicate: Predicate<'tcx>, cause: ObligationCause<'tcx>) {
self.ocx.register_obligation(Obligation::new(cause, self.param_env, predicate)); self.ocx.register_obligation(Obligation::new(
self.ocx.infcx.tcx,
cause,
self.param_env,
predicate,
));
} }
fn tcx(&self) -> TyCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> {
@ -256,5 +261,5 @@ pub fn type_op_prove_predicate_with_cause<'tcx>(
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
) { ) {
let (param_env, ProvePredicate { predicate }) = key.into_parts(); let (param_env, ProvePredicate { predicate }) = key.into_parts();
ocx.register_obligation(Obligation::new(cause, param_env, predicate)); ocx.register_obligation(Obligation::new(ocx.infcx.tcx, cause, param_env, predicate));
} }

View File

@ -338,6 +338,7 @@ pub macro debug_assert_matches($($arg:tt)*) {
/// ``` /// ```
#[macro_export] #[macro_export]
#[stable(feature = "matches_macro", since = "1.42.0")] #[stable(feature = "matches_macro", since = "1.42.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "matches_macro")]
macro_rules! matches { macro_rules! matches {
($expression:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => { ($expression:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
match $expression { match $expression {

View File

@ -76,6 +76,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
for predicate in predicates { for predicate in predicates {
debug!("testing predicate {:?}", predicate); debug!("testing predicate {:?}", predicate);
let obligation = traits::Obligation::new( let obligation = traits::Obligation::new(
infcx.tcx,
traits::ObligationCause::dummy(), traits::ObligationCause::dummy(),
param_env, param_env,
predicate, predicate,

View File

@ -217,10 +217,7 @@ h1 a,
.search-results a, .search-results a,
.module-item .stab, .module-item .stab,
.import-item .stab, .import-item .stab,
.result-name .primitive > i, .result-name .keyword > i, .result-name .primitive > i, .result-name .keyword > i {
.method .where,
.fn .where,
.where.fmt-newline {
color: var(--main-color); color: var(--main-color);
} }
@ -1162,6 +1159,8 @@ pre.rust .doccomment {
width: max-content; width: max-content;
top: -2px; top: -2px;
z-index: 1; z-index: 1;
background-color: var(--tooltip-background-color);
color: var(--tooltip-color);
} }
.example-wrap .tooltip::before { .example-wrap .tooltip::before {
@ -1170,10 +1169,10 @@ pre.rust .doccomment {
top: 50%; top: 50%;
left: 16px; left: 16px;
margin-top: -5px; margin-top: -5px;
border-width: 5px;
border-style: solid;
display: none; display: none;
z-index: 1; z-index: 1;
border: 5px solid transparent;
border-right-color: var(--tooltip-background-color);
} }
.example-wrap.ignore .tooltip::after { .example-wrap.ignore .tooltip::after {

View File

@ -65,6 +65,8 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--test-arrow-hover-background-color: rgba(57, 175, 215, 0.368); --test-arrow-hover-background-color: rgba(57, 175, 215, 0.368);
--target-background-color: rgba(255, 236, 164, 0.06); --target-background-color: rgba(255, 236, 164, 0.06);
--target-border-color: rgba(255, 180, 76, 0.85); --target-border-color: rgba(255, 180, 76, 0.85);
--tooltip-background-color: #314559;
--tooltip-color: #c5c5c5;
--rust-logo-filter: drop-shadow(1px 0 0px #fff) --rust-logo-filter: drop-shadow(1px 0 0px #fff)
drop-shadow(0 1px 0 #fff) drop-shadow(0 1px 0 #fff)
drop-shadow(-1px 0 0 #fff) drop-shadow(-1px 0 0 #fff)
@ -160,15 +162,6 @@ details.rustdoc-toggle > summary::before {
color: #788797; color: #788797;
} }
.tooltip::after {
background-color: #314559;
color: #c5c5c5;
}
.tooltip::before {
border-color: transparent #314559 transparent transparent;
}
#titles > button.selected { #titles > button.selected {
background-color: #141920 !important; background-color: #141920 !important;
border-bottom: 1px solid #ffb44c !important; border-bottom: 1px solid #ffb44c !important;

View File

@ -60,6 +60,8 @@
--test-arrow-hover-background-color: #4e8bca; --test-arrow-hover-background-color: #4e8bca;
--target-background-color: #494a3d; --target-background-color: #494a3d;
--target-border-color: #bb7410; --target-border-color: #bb7410;
--tooltip-background-color: #000;
--tooltip-color: #fff;
--rust-logo-filter: drop-shadow(1px 0 0px #fff) --rust-logo-filter: drop-shadow(1px 0 0px #fff)
drop-shadow(0 1px 0 #fff) drop-shadow(0 1px 0 #fff)
drop-shadow(-1px 0 0 #fff) drop-shadow(-1px 0 0 #fff)
@ -82,16 +84,6 @@ details.rustdoc-toggle > summary::before {
filter: invert(100%); filter: invert(100%);
} }
.tooltip::after {
background-color: #000;
color: #fff;
border-color: #000;
}
.tooltip::before {
border-color: transparent black transparent transparent;
}
#titles > button:not(.selected) { #titles > button:not(.selected) {
background-color: #252525; background-color: #252525;
border-top-color: #252525; border-top-color: #252525;

View File

@ -58,8 +58,10 @@
--test-arrow-background-color: rgba(78, 139, 202, 0.2); --test-arrow-background-color: rgba(78, 139, 202, 0.2);
--test-arrow-hover-color: #f5f5f5; --test-arrow-hover-color: #f5f5f5;
--test-arrow-hover-background-color: #4e8bca; --test-arrow-hover-background-color: #4e8bca;
--target-background-color: #fdFfd3; --target-background-color: #fdffd3;
--target-border-color: #ad7c37; --target-border-color: #ad7c37;
--tooltip-background-color: #fdffd3;
--tooltip-color: #fff;
--rust-logo-filter: initial; --rust-logo-filter: initial;
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */ /* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
--crate-search-div-filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg) --crate-search-div-filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg)
@ -75,15 +77,6 @@ body.source .example-wrap pre.rust a {
background: #eee; background: #eee;
} }
.tooltip::after {
background-color: #000;
color: #fff;
}
.tooltip::before {
border-color: transparent black transparent transparent;
}
#titles > button:not(.selected) { #titles > button:not(.selected) {
background-color: #e6e6e6; background-color: #e6e6e6;
border-top-color: #e6e6e6; border-top-color: #e6e6e6;

View File

@ -9,13 +9,16 @@
const isSettingsPage = window.location.pathname.endsWith("/settings.html"); const isSettingsPage = window.location.pathname.endsWith("/settings.html");
function changeSetting(settingName, value) { function changeSetting(settingName, value) {
if (settingName === "theme") {
const useSystem = value === "system preference" ? "true" : "false";
updateLocalStorage("use-system-theme", useSystem);
}
updateLocalStorage(settingName, value); updateLocalStorage(settingName, value);
switch (settingName) { switch (settingName) {
case "theme": case "theme":
case "preferred-dark-theme": case "preferred-dark-theme":
case "preferred-light-theme": case "preferred-light-theme":
case "use-system-theme":
updateSystemTheme(); updateSystemTheme();
updateLightAndDark(); updateLightAndDark();
break; break;
@ -45,7 +48,6 @@
} }
function showLightAndDark() { function showLightAndDark() {
addClass(document.getElementById("theme").parentElement, "hidden");
removeClass(document.getElementById("preferred-light-theme").parentElement, "hidden"); removeClass(document.getElementById("preferred-light-theme").parentElement, "hidden");
removeClass(document.getElementById("preferred-dark-theme").parentElement, "hidden"); removeClass(document.getElementById("preferred-dark-theme").parentElement, "hidden");
} }
@ -53,11 +55,11 @@
function hideLightAndDark() { function hideLightAndDark() {
addClass(document.getElementById("preferred-light-theme").parentElement, "hidden"); addClass(document.getElementById("preferred-light-theme").parentElement, "hidden");
addClass(document.getElementById("preferred-dark-theme").parentElement, "hidden"); addClass(document.getElementById("preferred-dark-theme").parentElement, "hidden");
removeClass(document.getElementById("theme").parentElement, "hidden");
} }
function updateLightAndDark() { function updateLightAndDark() {
if (getSettingValue("use-system-theme") !== "false") { const useSystem = getSettingValue("use-system-theme");
if (useSystem === "true" || (useSystem === null && getSettingValue("theme") === null)) {
showLightAndDark(); showLightAndDark();
} else { } else {
hideLightAndDark(); hideLightAndDark();
@ -91,7 +93,18 @@
}); });
onEachLazy(settingsElement.querySelectorAll("input[type=\"radio\"]"), elem => { onEachLazy(settingsElement.querySelectorAll("input[type=\"radio\"]"), elem => {
const settingId = elem.name; const settingId = elem.name;
const settingValue = getSettingValue(settingId); let settingValue = getSettingValue(settingId);
if (settingId === "theme") {
const useSystem = getSettingValue("use-system-theme");
if (useSystem === "true" || settingValue === null) {
if (useSystem !== "false") {
settingValue = "system preference";
} else {
// This is the default theme.
settingValue = "light";
}
}
}
if (settingValue !== null && settingValue !== "null") { if (settingValue !== null && settingValue !== "null") {
elem.checked = settingValue === elem.value; elem.checked = settingValue === elem.value;
} }
@ -120,26 +133,30 @@
if (setting["options"] !== undefined) { if (setting["options"] !== undefined) {
// This is a select setting. // This is a select setting.
output += `<div class="radio-line" id="${js_data_name}">\ output += `\
<span class="setting-name">${setting_name}</span>\ <div class="radio-line" id="${js_data_name}">
<div class="choices">`; <span class="setting-name">${setting_name}</span>
<div class="choices">`;
onEach(setting["options"], option => { onEach(setting["options"], option => {
const checked = option === setting["default"] ? " checked" : ""; const checked = option === setting["default"] ? " checked" : "";
const full = `${js_data_name}-${option.replace(/ /g,"-")}`;
output += `<label for="${js_data_name}-${option}" class="choice">\ output += `\
<input type="radio" name="${js_data_name}" \ <label for="${full}" class="choice">
id="${js_data_name}-${option}" value="${option}"${checked}>\ <input type="radio" name="${js_data_name}"
<span>${option}</span>\ id="${full}" value="${option}"${checked}>
</label>`; <span>${option}</span>
</label>`;
}); });
output += "</div></div>"; output += "</div></div>";
} else { } else {
// This is a toggle. // This is a toggle.
const checked = setting["default"] === true ? " checked" : ""; const checked = setting["default"] === true ? " checked" : "";
output += `<label class="toggle">\ output += `\
<input type="checkbox" id="${js_data_name}"${checked}>\ <label class="toggle">\
<span class="label">${setting_name}</span>\ <input type="checkbox" id="${js_data_name}"${checked}>\
</label>`; <span class="label">${setting_name}</span>\
</label>`;
} }
output += "</div>"; output += "</div>";
} }
@ -156,16 +173,11 @@
theme_names.push("light", "dark", "ayu"); theme_names.push("light", "dark", "ayu");
const settings = [ const settings = [
{
"name": "Use system theme",
"js_name": "use-system-theme",
"default": true,
},
{ {
"name": "Theme", "name": "Theme",
"js_name": "theme", "js_name": "theme",
"default": "light", "default": "system preference",
"options": theme_names, "options": theme_names.concat("system preference"),
}, },
{ {
"name": "Preferred light theme", "name": "Preferred light theme",

View File

@ -4,7 +4,7 @@ show-text: true
define-function: ( define-function: (
"check-colors", "check-colors",
(theme), (theme, background, color, border),
[ [
// Setting the theme. // Setting the theme.
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}), ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
@ -30,6 +30,25 @@ define-function: (
".docblock .example-wrap.compile_fail", ".docblock .example-wrap.compile_fail",
{"border-left": "2px solid rgb(255, 0, 0)"}, {"border-left": "2px solid rgb(255, 0, 0)"},
)), )),
("assert-css", (
".docblock .example-wrap.compile_fail .tooltip::after",
{
"content": '"This example deliberately fails to compile"',
"text-align": "center",
"padding": "5px 3px 3px",
"background-color": |background|,
"color": |color|,
"border": "1px solid " + |border|,
},
)),
("assert-css", (
".docblock .example-wrap.compile_fail .tooltip::before",
{
"border-width": "5px",
"border-style": "solid",
"border-color": "rgba(0, 0, 0, 0) " + |background| + " rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)",
},
)),
// should_panic block // should_panic block
("assert-css", ( ("assert-css", (
@ -51,6 +70,25 @@ define-function: (
".docblock .example-wrap.should_panic", ".docblock .example-wrap.should_panic",
{"border-left": "2px solid rgb(255, 0, 0)"}, {"border-left": "2px solid rgb(255, 0, 0)"},
)), )),
("assert-css", (
".docblock .example-wrap.should_panic .tooltip::after",
{
"content": '"This example panics"',
"text-align": "center",
"padding": "5px 3px 3px",
"background-color": |background|,
"color": |color|,
"border": "1px solid " + |border|,
},
)),
("assert-css", (
".docblock .example-wrap.should_panic .tooltip::before",
{
"border-width": "5px",
"border-style": "solid",
"border-color": "rgba(0, 0, 0, 0) " + |background| + " rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)",
},
)),
// ignore block // ignore block
("assert-css", ( ("assert-css", (
@ -72,9 +110,43 @@ define-function: (
".docblock .example-wrap.ignore", ".docblock .example-wrap.ignore",
{"border-left": "2px solid rgb(255, 142, 0)"}, {"border-left": "2px solid rgb(255, 142, 0)"},
)), )),
("assert-css", (
".docblock .example-wrap.ignore .tooltip::after",
{
"content": '"This example is not tested"',
"text-align": "center",
"padding": "5px 3px 3px",
"background-color": |background|,
"color": |color|,
"border": "1px solid " + |border|,
},
)),
("assert-css", (
".docblock .example-wrap.ignore .tooltip::before",
{
"border-width": "5px",
"border-style": "solid",
"border-color": "rgba(0, 0, 0, 0) " + |background| + " rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)",
},
)),
], ],
) )
call-function: ("check-colors", ("ayu")) call-function: ("check-colors", {
call-function: ("check-colors", ("dark")) "theme": "ayu",
call-function: ("check-colors", ("light")) "background": "rgb(49, 69, 89)",
"color": "rgb(197, 197, 197)",
"border": "rgb(92, 103, 115)",
})
call-function: ("check-colors", {
"theme": "dark",
"background": "rgb(0, 0, 0)",
"color": "rgb(255, 255, 255)",
"border": "rgb(224, 224, 224)",
})
call-function: ("check-colors", {
"theme": "light",
"background": "rgb(253, 255, 211)",
"color": "rgb(255, 255, 255)",
"border": "rgb(224, 224, 224)",
})

View File

@ -37,8 +37,7 @@ click: "#settings-menu"
wait-for: "#settings" wait-for: "#settings"
// We check that the "Use system theme" is disabled. // We check that the "Use system theme" is disabled.
assert-property: ("#use-system-theme", {"checked": "false"}) assert-property: ("#theme-system-preference", {"checked": "false"})
assert: "//*[@class='setting-line']//span[text()='Use system theme']"
// Meaning that only the "theme" menu is showing up. // Meaning that only the "theme" menu is showing up.
assert: ".setting-line:not(.hidden) #theme" assert: ".setting-line:not(.hidden) #theme"
assert: ".setting-line.hidden #preferred-dark-theme" assert: ".setting-line.hidden #preferred-dark-theme"
@ -115,13 +114,6 @@ assert-css: (
"border-color": "rgb(221, 221, 221)", "border-color": "rgb(221, 221, 221)",
}, },
) )
assert-css: (
"#use-system-theme",
{
"background-color": "rgba(0, 0, 0, 0)",
"border-color": "rgb(221, 221, 221)",
}
)
// Let's start with the hover for toggles. // Let's start with the hover for toggles.
move-cursor-to: "#auto-hide-large-items" move-cursor-to: "#auto-hide-large-items"
assert-css: ( assert-css: (
@ -131,14 +123,6 @@ assert-css: (
"border-color": "rgb(33, 150, 243)", "border-color": "rgb(33, 150, 243)",
}, },
) )
move-cursor-to: "#use-system-theme"
assert-css: (
"#use-system-theme",
{
"background-color": "rgba(0, 0, 0, 0)",
"border-color": "rgb(33, 150, 243)",
}
)
move-cursor-to: "#settings-menu > a" move-cursor-to: "#settings-menu > a"
// Let's now check with the focus for toggles. // Let's now check with the focus for toggles.
focus: "#auto-hide-large-items" focus: "#auto-hide-large-items"
@ -150,15 +134,6 @@ assert-css: (
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px", "box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
}, },
) )
focus: "#use-system-theme"
assert-css: (
"#use-system-theme",
{
"background-color": "rgba(0, 0, 0, 0)",
"border-color": "rgb(221, 221, 221)",
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
},
)
// Now we check we both focus and hover for toggles. // Now we check we both focus and hover for toggles.
move-cursor-to: "#auto-hide-large-items" move-cursor-to: "#auto-hide-large-items"
focus: "#auto-hide-large-items" focus: "#auto-hide-large-items"
@ -170,24 +145,12 @@ assert-css: (
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px", "box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
}, },
) )
move-cursor-to: "#use-system-theme"
focus: "#use-system-theme"
assert-css: (
"#use-system-theme",
{
"background-color": "rgba(0, 0, 0, 0)",
"border-color": "rgb(33, 150, 243)",
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
},
)
// We now switch the display. // We now switch the display.
click: "#use-system-theme" click: "#theme-system-preference"
// Wait for the hidden element to show up. // Wait for the hidden element to show up.
wait-for: ".setting-line:not(.hidden) #preferred-dark-theme" wait-for: ".setting-line:not(.hidden) #preferred-dark-theme"
assert: ".setting-line:not(.hidden) #preferred-light-theme" assert: ".setting-line:not(.hidden) #preferred-light-theme"
// Check that the theme picking is hidden.
assert: ".setting-line.hidden #theme"
// We check their text as well. // We check their text as well.
assert-text: ("#preferred-dark-theme .setting-name", "Preferred dark theme") assert-text: ("#preferred-dark-theme .setting-name", "Preferred dark theme")

View File

@ -2,31 +2,66 @@
goto: "file://" + |DOC_PATH| + "/test_docs/index.html" goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "dark"} local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "dark"}
reload: reload:
store-value: (background_light, "rgb(255, 255, 255)")
store-value: (background_dark, "rgb(53, 53, 53)")
store-value: (background_ayu, "rgb(15, 20, 25)")
click: "#settings-menu" click: "#settings-menu"
wait-for: "#theme-ayu" wait-for: "#theme-ayu"
click: "#theme-ayu" click: "#theme-ayu"
// should be the ayu theme so let's check the color. // should be the ayu theme so let's check the color.
wait-for-css: ("body", { "background-color": "rgb(15, 20, 25)" }) wait-for-css: ("body", { "background-color": |background_ayu| })
assert-local-storage: { "rustdoc-theme": "ayu" } assert-local-storage: { "rustdoc-theme": "ayu" }
click: "#theme-light" click: "#theme-light"
// should be the light theme so let's check the color. // should be the light theme so let's check the color.
wait-for-css: ("body", { "background-color": "rgb(255, 255, 255)" }) wait-for-css: ("body", { "background-color": |background_light| })
assert-local-storage: { "rustdoc-theme": "light" } assert-local-storage: { "rustdoc-theme": "light" }
click: "#theme-dark" click: "#theme-dark"
// Should be the dark theme so let's check the color. // Should be the dark theme so let's check the color.
wait-for-css: ("body", { "background-color": "rgb(53, 53, 53)" }) wait-for-css: ("body", { "background-color": |background_dark| })
assert-local-storage: { "rustdoc-theme": "dark" } assert-local-storage: { "rustdoc-theme": "dark" }
local-storage: {
"rustdoc-preferred-light-theme": "light",
"rustdoc-preferred-dark-theme": "light",
}
goto: "file://" + |DOC_PATH| + "/settings.html" goto: "file://" + |DOC_PATH| + "/settings.html"
wait-for: "#settings" wait-for: "#settings"
click: "#theme-light" click: "#theme-light"
wait-for-css: ("body", { "background-color": "rgb(255, 255, 255)" }) wait-for-css: ("body", { "background-color": |background_light| })
assert-local-storage: { "rustdoc-theme": "light" } assert-local-storage: { "rustdoc-theme": "light" }
click: "#theme-dark" click: "#theme-dark"
wait-for-css: ("body", { "background-color": "rgb(53, 53, 53)" }) wait-for-css: ("body", { "background-color": |background_dark| })
assert-local-storage: { "rustdoc-theme": "dark" } assert-local-storage: { "rustdoc-theme": "dark" }
click: "#theme-ayu" click: "#theme-ayu"
wait-for-css: ("body", { "background-color": "rgb(15, 20, 25)" }) wait-for-css: ("body", { "background-color": |background_ayu| })
assert-local-storage: { "rustdoc-theme": "ayu" } assert-local-storage: { "rustdoc-theme": "ayu" }
assert-local-storage-false: { "rustdoc-use-system-theme": "true" }
click: "#theme-system-preference"
wait-for: ".setting-line:not(.hidden) #preferred-light-theme"
assert-local-storage: { "rustdoc-use-system-theme": "true" }
// We click on both preferred light and dark themes to be sure that there is a change.
click: "#preferred-light-theme-dark"
click: "#preferred-dark-theme-dark"
wait-for-css: ("body", { "background-color": |background_dark| })
reload:
// Ensure that the "preferred themes" are still displayed.
wait-for: ".setting-line:not(.hidden) #preferred-light-theme"
click: "#theme-light"
wait-for-css: ("body", { "background-color": |background_light| })
assert-local-storage: { "rustdoc-theme": "light" }
// Ensure it's now hidden again
wait-for: ".setting-line.hidden #preferred-light-theme"
// And ensure the theme was rightly set.
wait-for-css: ("body", { "background-color": |background_light| })
assert-local-storage: { "rustdoc-theme": "light" }
reload:
wait-for: "#settings"
assert: ".setting-line.hidden #preferred-light-theme"

View File

@ -0,0 +1,17 @@
// check-pass
// edition:2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
pub trait Foo {
async fn foo(&mut self);
}
struct MyFoo<'a>(&'a mut ());
impl<'a> Foo for MyFoo<'a> {
async fn foo(&mut self) {}
}
fn main() {}

View File

@ -0,0 +1,15 @@
// check-pass
// edition:2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
pub trait Foo {
async fn foo(&mut self);
}
impl<T: Foo> Foo for &mut T {
async fn foo(&mut self) {}
}
fn main() {}

View File

@ -0,0 +1,10 @@
fn f1() -> impl Sized { & 2E } //~ ERROR expected at least one digit in exponent
fn f2() -> impl Sized { && 2E } //~ ERROR expected at least one digit in exponent
fn f3() -> impl Sized { &'a 2E } //~ ERROR expected at least one digit in exponent
//~^ ERROR borrow expressions cannot be annotated with lifetimes
fn f4() -> impl Sized { &'static 2E } //~ ERROR expected at least one digit in exponent
//~^ ERROR borrow expressions cannot be annotated with lifetimes
fn f5() -> impl Sized { *& 2E } //~ ERROR expected at least one digit in exponent
fn f6() -> impl Sized { &'_ 2E } //~ ERROR expected at least one digit in exponent
//~^ ERROR borrow expressions cannot be annotated with lifetimes
fn main() {}

View File

@ -0,0 +1,65 @@
error: expected at least one digit in exponent
--> $DIR/issue-104390.rs:1:27
|
LL | fn f1() -> impl Sized { & 2E }
| ^^
error: expected at least one digit in exponent
--> $DIR/issue-104390.rs:2:28
|
LL | fn f2() -> impl Sized { && 2E }
| ^^
error: expected at least one digit in exponent
--> $DIR/issue-104390.rs:3:29
|
LL | fn f3() -> impl Sized { &'a 2E }
| ^^
error: expected at least one digit in exponent
--> $DIR/issue-104390.rs:5:34
|
LL | fn f4() -> impl Sized { &'static 2E }
| ^^
error: expected at least one digit in exponent
--> $DIR/issue-104390.rs:7:28
|
LL | fn f5() -> impl Sized { *& 2E }
| ^^
error: expected at least one digit in exponent
--> $DIR/issue-104390.rs:8:29
|
LL | fn f6() -> impl Sized { &'_ 2E }
| ^^
error: borrow expressions cannot be annotated with lifetimes
--> $DIR/issue-104390.rs:3:25
|
LL | fn f3() -> impl Sized { &'a 2E }
| ^--^^^
| |
| annotated with lifetime here
| help: remove the lifetime annotation
error: borrow expressions cannot be annotated with lifetimes
--> $DIR/issue-104390.rs:5:25
|
LL | fn f4() -> impl Sized { &'static 2E }
| ^-------^^^
| |
| annotated with lifetime here
| help: remove the lifetime annotation
error: borrow expressions cannot be annotated with lifetimes
--> $DIR/issue-104390.rs:8:25
|
LL | fn f6() -> impl Sized { &'_ 2E }
| ^--^^^
| |
| annotated with lifetime here
| help: remove the lifetime annotation
error: aborting due to 9 previous errors

View File

@ -0,0 +1,10 @@
// check-pass
#![feature(dyn_star)]
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
fn _foo() -> dyn* Unpin {
4usize
}
fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/return.rs:3:12
|
LL | #![feature(dyn_star)]
| ^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,11 @@
fn main() {
{ unsafe 92 } //~ ERROR expected `{`, found `92`
}
fn foo() {
{ mod 92 } //~ ERROR expected identifier, found `92`
}
fn bar() {
{ trait 92 } //~ ERROR expected identifier, found `92`
}

View File

@ -0,0 +1,27 @@
error: expected `{`, found `92`
--> $DIR/issue-104392.rs:2:14
|
LL | { unsafe 92 }
| ------ ^^ expected `{`
| |
| while parsing this `unsafe` expression
|
help: try placing this code inside a block
|
LL | { unsafe { 92 } }
| + +
error: expected identifier, found `92`
--> $DIR/issue-104392.rs:6:11
|
LL | { mod 92 }
| ^^ expected identifier
error: expected identifier, found `92`
--> $DIR/issue-104392.rs:10:13
|
LL | { trait 92 }
| ^^ expected identifier
error: aborting due to 3 previous errors

View File

@ -1,9 +1,6 @@
// check-fail // check-fail
// failure-status: 101 // failure-status: 101
// normalize-stderr-test "note: .*" -> "" // dont-check-compiler-stderr
// normalize-stderr-test "thread 'rustc' .*" -> ""
// normalize-stderr-test " .*\n" -> ""
// normalize-stderr-test " .*\n" -> ""
// known-bug: #103899 // known-bug: #103899
trait BaseWithAssoc { trait BaseWithAssoc {

View File

@ -1,12 +0,0 @@
stack
error:
query#0#1end

View File

@ -0,0 +1,16 @@
// needs-asm-support
// only-x86_64
struct W<T: ?Sized>(Oops);
//~^ ERROR cannot find type `Oops` in this scope
unsafe fn test() {
let j = W(());
let pointer = &j as *const _;
core::arch::asm!(
"nop",
in("eax") pointer,
);
}
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0412]: cannot find type `Oops` in this scope
--> $DIR/issue-104510-ice.rs:4:21
|
LL | struct W<T: ?Sized>(Oops);
| ^^^^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0412`.

View File

@ -1156,7 +1156,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
} }
let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty); let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty);
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
let infcx = cx.tcx.infer_ctxt().build(); let infcx = cx.tcx.infer_ctxt().build();
infcx.predicate_must_hold_modulo_regions(&obligation) infcx.predicate_must_hold_modulo_regions(&obligation)
}) })

View File

@ -419,7 +419,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
if trait_predicates.any(|predicate| { if trait_predicates.any(|predicate| {
let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst); let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst);
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
!cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation) !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
}) { }) {
return false; return false;

View File

@ -695,6 +695,7 @@ fn matches_preds<'tcx>(
.type_implements_trait(p.def_id, ty, p.substs, cx.param_env) .type_implements_trait(p.def_id, ty, p.substs, cx.param_env)
.must_apply_modulo_regions(), .must_apply_modulo_regions(),
ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new( ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new(
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::bind_with_vars(