From 4547b622d8d29df964fa2914213088b148c498fc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:32 +0200 Subject: Merging upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_infer/src/traits/engine.rs | 10 +------ .../rustc_infer/src/traits/error_reporting/mod.rs | 4 +-- compiler/rustc_infer/src/traits/mod.rs | 33 ++++++++++++---------- compiler/rustc_infer/src/traits/util.rs | 28 ++++++++++-------- 4 files changed, 37 insertions(+), 38 deletions(-) (limited to 'compiler/rustc_infer/src/traits') diff --git a/compiler/rustc_infer/src/traits/engine.rs b/compiler/rustc_infer/src/traits/engine.rs index b2b985a22..d3519f4b3 100644 --- a/compiler/rustc_infer/src/traits/engine.rs +++ b/compiler/rustc_infer/src/traits/engine.rs @@ -8,14 +8,6 @@ use super::FulfillmentError; use super::{ObligationCause, PredicateObligation}; pub trait TraitEngine<'tcx>: 'tcx { - fn normalize_projection_type( - &mut self, - infcx: &InferCtxt<'tcx>, - param_env: ty::ParamEnv<'tcx>, - projection_ty: ty::ProjectionTy<'tcx>, - cause: ObligationCause<'tcx>, - ) -> Ty<'tcx>; - /// Requires that `ty` must implement the trait with `def_id` in /// the given environment. This trait must not have any type /// parameters (except for `Self`). @@ -27,7 +19,7 @@ pub trait TraitEngine<'tcx>: 'tcx { def_id: DefId, cause: ObligationCause<'tcx>, ) { - let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) }; + let trait_ref = infcx.tcx.mk_trait_ref(def_id, [ty]); self.register_predicate_obligation( infcx, Obligation { diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index f8b5009a5..4d5351958 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -1,7 +1,7 @@ use super::ObjectSafetyViolation; use crate::infer::InferCtxt; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -56,7 +56,7 @@ pub fn report_object_safety_error<'tcx>( ); err.span_label(span, format!("`{}` cannot be made into an object", trait_str)); - let mut reported_violations = FxHashSet::default(); + let mut reported_violations = FxIndexSet::default(); let mut multi_span = vec![]; let mut messages = vec![]; for violation in violations { diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs index c8600ded9..026713b6a 100644 --- a/compiler/rustc_infer/src/traits/mod.rs +++ b/compiler/rustc_infer/src/traits/mod.rs @@ -10,7 +10,7 @@ pub mod util; use rustc_hir as hir; 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; pub use self::FulfillmentErrorCode::*; @@ -70,8 +70,8 @@ impl<'tcx> PredicateObligation<'tcx> { pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> PredicateObligation<'tcx> { self.param_env = self.param_env.without_const(); - if let ty::PredicateKind::Trait(trait_pred) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() { - self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Trait(trait_pred.without_const()))); + if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() { + self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred.without_const())))); } self } @@ -124,38 +124,41 @@ pub enum FulfillmentErrorCode<'tcx> { impl<'tcx, O> Obligation<'tcx, O> { pub fn new( + tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - predicate: O, + predicate: impl ToPredicate<'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( + tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, recursion_depth: usize, param_env: ty::ParamEnv<'tcx>, - predicate: O, + predicate: impl ToPredicate<'tcx, O>, ) -> Obligation<'tcx, O> { + let predicate = predicate.to_predicate(tcx); Obligation { cause, param_env, recursion_depth, predicate } } pub fn misc( + tcx: TyCtxt<'tcx>, span: Span, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, - trait_ref: O, + trait_ref: impl ToPredicate<'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

(&self, value: P) -> Obligation<'tcx, P> { - Obligation { - cause: self.cause.clone(), - param_env: self.param_env, - recursion_depth: self.recursion_depth, - predicate: value, - } + pub fn with

( + &self, + tcx: TyCtxt<'tcx>, + value: impl ToPredicate<'tcx, P>, + ) -> Obligation<'tcx, P> { + Obligation::with_depth(tcx, self.cause.clone(), self.recursion_depth, self.param_env, value) } } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index e12c069dc..512e6079f 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -141,7 +141,7 @@ impl<'tcx> Elaborator<'tcx> { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data) => { + ty::PredicateKind::Clause(ty::Clause::Trait(data)) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); @@ -184,7 +184,7 @@ impl<'tcx> Elaborator<'tcx> { // Currently, we do not "elaborate" predicates like `X -> Y`, // though conceivably we might. } - ty::PredicateKind::Projection(..) => { + ty::PredicateKind::Clause(ty::Clause::Projection(..)) => { // Nothing to elaborate in a projection predicate. } ty::PredicateKind::ClosureKind(..) => { @@ -198,10 +198,13 @@ impl<'tcx> Elaborator<'tcx> { // Currently, we do not elaborate const-equate // predicates. } - ty::PredicateKind::RegionOutlives(..) => { + ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) => { // Nothing to elaborate from `'a: 'b`. } - ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => { + ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate( + ty_max, + r_min, + ))) => { // We know that `T: 'a` for some type `T`. We can // often elaborate this. For example, if we know that // `[U]: 'a`, that implies that `U: 'a`. Similarly, if @@ -231,16 +234,16 @@ impl<'tcx> Elaborator<'tcx> { if r.is_late_bound() { None } else { - Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate( - r, r_min, + Some(ty::PredicateKind::Clause(ty::Clause::RegionOutlives( + ty::OutlivesPredicate(r, r_min), ))) } } Component::Param(p) => { let ty = tcx.mk_ty_param(p.index, p.name); - Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate( - ty, r_min, + Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives( + ty::OutlivesPredicate(ty, r_min), ))) } @@ -248,8 +251,8 @@ impl<'tcx> Elaborator<'tcx> { Component::Opaque(def_id, substs) => { let ty = tcx.mk_opaque(def_id, substs); - Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate( - ty, r_min, + Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives( + ty::OutlivesPredicate(ty, r_min), ))) } @@ -258,8 +261,8 @@ impl<'tcx> Elaborator<'tcx> { // With this, we can deduce that `::Assoc: 'a`. let ty = tcx.mk_projection(projection.item_def_id, projection.substs); - Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate( - ty, r_min, + Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives( + ty::OutlivesPredicate(ty, r_min), ))) } @@ -285,6 +288,7 @@ impl<'tcx> Elaborator<'tcx> { ty::PredicateKind::TypeWellFormedFromEnv(..) => { // Nothing to elaborate } + ty::PredicateKind::Ambiguous => {} } } } -- cgit v1.2.3