From d8e01c042532ea03c1c69b0f0a6e66e69d402f6c Mon Sep 17 00:00:00 2001 From: Boxy Date: Sat, 18 May 2024 23:26:33 +0100 Subject: [PATCH 1/4] Add ability to branch on whether `DebugWithInfcx` has an `Infcx` --- .../rustc_middle/src/ty/structural_impls.rs | 19 ++++--- compiler/rustc_type_ir/src/const_kind.rs | 19 ++++--- compiler/rustc_type_ir/src/debug.rs | 50 ++++++++++--------- compiler/rustc_type_ir/src/ty_kind.rs | 20 ++++---- 4 files changed, 60 insertions(+), 48 deletions(-) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 7d24824d568f4..d3790ba6e0304 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -83,17 +83,17 @@ impl fmt::Debug for ty::LateParamRegion { } } +impl<'tcx> fmt::Debug for Ty<'tcx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + with_no_trimmed_paths!(self.kind().fmt(f)) + } +} impl<'tcx> ty::DebugWithInfcx> for Ty<'tcx> { fn fmt>>( this: WithInfcx<'_, Infcx, &Self>, f: &mut core::fmt::Formatter<'_>, ) -> core::fmt::Result { - this.data.fmt(f) - } -} -impl<'tcx> fmt::Debug for Ty<'tcx> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - with_no_trimmed_paths!(fmt::Debug::fmt(self.kind(), f)) + this.map(|ty| ty.kind()).fmt(f) } } @@ -264,9 +264,12 @@ impl<'tcx> DebugWithInfcx> for ty::RegionVid { this: WithInfcx<'_, Infcx, &Self>, f: &mut core::fmt::Formatter<'_>, ) -> core::fmt::Result { - match this.infcx.universe_of_lt(*this.data) { - Some(universe) => write!(f, "'?{}_{}", this.data.index(), universe.index()), + match this.infcx { None => write!(f, "{:?}", this.data), + Some(infcx) => match infcx.universe_of_lt(*this.data) { + Some(universe) => write!(f, "'?{}_{}", this.data.index(), universe.index()), + None => write!(f, "'?{}_..", this.data.index()), + }, } } } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index af07e9ff96bf8..a0ce890b0bb31 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -180,15 +180,18 @@ impl DebugWithInfcx for InferConst { this: WithInfcx<'_, Infcx, &Self>, f: &mut core::fmt::Formatter<'_>, ) -> core::fmt::Result { - match *this.data { - InferConst::Var(vid) => match this.infcx.universe_of_ct(vid) { - None => write!(f, "{:?}", this.data), - Some(universe) => write!(f, "?{}_{}c", vid.index(), universe.index()), + match this.infcx { + None => write!(f, "{:?}", this.data), + Some(infcx) => match *this.data { + InferConst::Var(vid) => match infcx.universe_of_ct(vid) { + None => write!(f, "?{}_..c", vid.index()), + Some(universe) => write!(f, "?{}_{}c", vid.index(), universe.index()), + }, + InferConst::EffectVar(vid) => write!(f, "?{}e", vid.index()), + InferConst::Fresh(_) => { + unreachable!() + } }, - InferConst::EffectVar(vid) => write!(f, "?{}e", vid.index()), - InferConst::Fresh(_) => { - unreachable!() - } } } } diff --git a/compiler/rustc_type_ir/src/debug.rs b/compiler/rustc_type_ir/src/debug.rs index 9298360f749ac..ccd5632a0d3d4 100644 --- a/compiler/rustc_type_ir/src/debug.rs +++ b/compiler/rustc_type_ir/src/debug.rs @@ -1,51 +1,55 @@ use crate::{ConstVid, InferCtxtLike, Interner, TyVid, UniverseIndex}; use core::fmt; -use std::marker::PhantomData; - -pub struct NoInfcx(PhantomData); +pub struct NoInfcx(core::convert::Infallible, core::marker::PhantomData); impl InferCtxtLike for NoInfcx { type Interner = I; fn interner(&self) -> Self::Interner { - unreachable!() + match self.0 {} } fn universe_of_ty(&self, _ty: TyVid) -> Option { - None + match self.0 {} } - fn universe_of_lt(&self, _lt: I::InferRegion) -> Option { - None + fn root_ty_var(&self, _vid: TyVid) -> TyVid { + match self.0 {} } - fn universe_of_ct(&self, _ct: ConstVid) -> Option { - None + fn probe_ty_var(&self, _vid: TyVid) -> Option<::Ty> { + match self.0 {} } - fn root_ty_var(&self, vid: TyVid) -> TyVid { - vid + fn universe_of_lt( + &self, + _lt: ::InferRegion, + ) -> Option { + match self.0 {} } - fn probe_ty_var(&self, _vid: TyVid) -> Option { - None + fn opportunistic_resolve_lt_var( + &self, + _vid: ::InferRegion, + ) -> Option<::Region> { + match self.0 {} } - fn opportunistic_resolve_lt_var(&self, _vid: I::InferRegion) -> Option { - None + fn universe_of_ct(&self, _ct: ConstVid) -> Option { + match self.0 {} } - fn root_ct_var(&self, vid: ConstVid) -> ConstVid { - vid + fn root_ct_var(&self, _vid: ConstVid) -> ConstVid { + match self.0 {} } - fn probe_ct_var(&self, _vid: ConstVid) -> Option { - None + fn probe_ct_var(&self, _vid: ConstVid) -> Option<::Const> { + match self.0 {} } fn defining_opaque_types(&self) -> ::DefiningOpaqueTypes { - Default::default() + match self.0 {} } } @@ -96,7 +100,7 @@ impl> DebugWithInfcx for [T] { pub struct WithInfcx<'a, Infcx: InferCtxtLike, T> { pub data: T, - pub infcx: &'a Infcx, + pub infcx: Option<&'a Infcx>, } impl Copy for WithInfcx<'_, Infcx, T> {} @@ -109,13 +113,13 @@ impl Clone for WithInfcx<'_, Infcx, T> { impl<'a, I: Interner, T> WithInfcx<'a, NoInfcx, T> { pub fn with_no_infcx(data: T) -> Self { - Self { data, infcx: &NoInfcx(PhantomData) } + Self { data, infcx: None } } } impl<'a, Infcx: InferCtxtLike, T> WithInfcx<'a, Infcx, T> { pub fn new(data: T, infcx: &'a Infcx) -> Self { - Self { data, infcx } + Self { data, infcx: Some(infcx) } } pub fn wrap(self, u: U) -> WithInfcx<'a, Infcx, U> { diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 629ea9fb839c9..154c04ac33beb 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -415,7 +415,6 @@ impl DebugWithInfcx for TyKind { } } -// This is manually implemented because a derive would require `I: Debug` impl fmt::Debug for TyKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { WithInfcx::with_no_infcx(self).fmt(f) @@ -924,15 +923,18 @@ impl DebugWithInfcx for InferTy { this: WithInfcx<'_, Infcx, &Self>, f: &mut fmt::Formatter<'_>, ) -> fmt::Result { - match this.data { - InferTy::TyVar(vid) => { - if let Some(universe) = this.infcx.universe_of_ty(*vid) { - write!(f, "?{}_{}t", vid.index(), universe.index()) - } else { - write!(f, "{:?}", this.data) + match this.infcx { + None => write!(f, "{:?}", this.data), + Some(infcx) => match this.data { + InferTy::TyVar(vid) => { + if let Some(universe) = infcx.universe_of_ty(*vid) { + write!(f, "?{}_{}t", vid.index(), universe.index()) + } else { + write!(f, "{}_..t", vid.index()) + } } - } - _ => write!(f, "{:?}", this.data), + _ => write!(f, "{:?}", this.data), + }, } } } From 5167f7e453c5c9cda0563016da53867e4936447d Mon Sep 17 00:00:00 2001 From: Boxy Date: Sat, 18 May 2024 23:30:21 +0100 Subject: [PATCH 2/4] Allow formatting `TraitRef` and `TraitPredicate` with an `Infcx` --- compiler/rustc_middle/src/ty/context.rs | 14 +++++ compiler/rustc_type_ir/src/interner.rs | 2 + compiler/rustc_type_ir/src/ir_print.rs | 2 +- compiler/rustc_type_ir/src/predicate.rs | 78 ++++++++++++++++++++++++- 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 69681930be657..f405dd4f08005 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -4,6 +4,7 @@ pub mod tls; +use hir::def::Namespace; pub use rustc_type_ir::lift::Lift; use crate::arena::Arena; @@ -27,6 +28,7 @@ use crate::traits::solve::{ ExternalConstraints, ExternalConstraintsData, PredefinedOpaques, PredefinedOpaquesData, }; use crate::ty::predicate::ExistentialPredicateStableCmpExt as _; +use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer}; use crate::ty::{ self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, ConstData, GenericParamDefKind, ImplPolarity, List, ListWithCachedTypeInfo, ParamConst, ParamTy, Pattern, @@ -89,6 +91,18 @@ use std::ops::{Bound, Deref}; #[allow(rustc::usage_of_ty_tykind)] impl<'tcx> Interner for TyCtxt<'tcx> { type DefId = DefId; + fn print_def_path(defid: Self::DefId, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + ty::tls::with(|tcx| { + with_no_trimmed_paths!({ + // this namespace is..... not strictly correct lol + let s = FmtPrinter::print_string(tcx, Namespace::TypeNS, |cx| { + cx.print_def_path(defid, &[]) + })?; + f.write_str(&s) + }) + }) + } + type AdtDef = ty::AdtDef<'tcx>; type GenericArgs = ty::GenericArgsRef<'tcx>; diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 9acf7c04dd61c..66e6dd741a0d4 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -29,6 +29,8 @@ pub trait Interner: + IrPrint> { type DefId: Copy + Debug + Hash + Eq; + fn print_def_path(defid: Self::DefId, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result; + type AdtDef: Copy + Debug + Hash + Eq; type GenericArgs: GenericArgs; diff --git a/compiler/rustc_type_ir/src/ir_print.rs b/compiler/rustc_type_ir/src/ir_print.rs index af4b9eef14b92..0a1ea90eab2f2 100644 --- a/compiler/rustc_type_ir/src/ir_print.rs +++ b/compiler/rustc_type_ir/src/ir_print.rs @@ -48,4 +48,4 @@ define_display_via_print!( FnSig, ); -define_debug_via_print!(TraitRef, ExistentialTraitRef, ExistentialProjection); +define_debug_via_print!(ExistentialTraitRef, ExistentialProjection); diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index c0619d782c681..bca8cbd165104 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -40,6 +40,44 @@ pub struct TraitRef { _use_trait_ref_new_instead: (), } +impl fmt::Debug for TraitRef { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + WithInfcx::with_no_infcx(self).fmt(f) + } +} +impl DebugWithInfcx for TraitRef { + fn fmt>( + this: WithInfcx<'_, Infcx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + // If we ever wind up with a malformed `TraitRef` it might be good to not ICE in its Debug impl(?) + if this.data.args.len() == 0 { + return f + .debug_tuple("TraitRef") + .field(&this.data.def_id) + .field(&this.data.args) + .finish(); + } + + write!(f, "({:?} as ", this.map(|trait_ref| trait_ref.args[0]))?; + I::print_def_path(this.data.def_id, f)?; + + match this.data.args.len() { + 0 => unreachable!(), + 1 => write!(f, ")"), // the first arg is the self type + 2 => write!(f, "<{:?}>)", this.map(|trait_ref| trait_ref.args[1])), + 3.. => { + write!(f, "<{:?}", this.map(|trait_ref| trait_ref.args[1]))?; + for arg in &this.data.args[2..] { + let arg = this.wrap(arg); + write!(f, ", {:?}", arg)?; + } + write!(f, ">)") + } + } + } +} + impl TraitRef { pub fn new( interner: I, @@ -114,8 +152,46 @@ impl TraitPredicate { impl fmt::Debug for TraitPredicate { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + WithInfcx::with_no_infcx(self).fmt(f) + } +} +impl DebugWithInfcx for TraitPredicate { + fn fmt>( + this: WithInfcx<'_, Infcx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { // FIXME(effects) printing? - write!(f, "TraitPredicate({:?}, polarity:{:?})", self.trait_ref, self.polarity) + + // If we ever wind up with a malformed `TraitRef` it might be good to not ICE in its Debug impl(?) + if this.data.trait_ref.args.len() == 0 { + return f + .debug_tuple("TraitPredicate") + .field(&this.data.trait_ref.def_id) + .field(&this.data.trait_ref.args) + .field(&this.data.polarity) + .finish(); + } + + write!(f, "({:?}: ", this.map(|pred| pred.trait_ref.args[0]))?; + match this.data.polarity { + PredicatePolarity::Positive => (), + PredicatePolarity::Negative => write!(f, "!")?, + }; + I::print_def_path(this.data.trait_ref.def_id, f)?; + + match this.data.trait_ref.args.len() { + 0 => unreachable!(), + 1 => write!(f, ")"), // the first arg is the self type + 2 => write!(f, "<{:?}>)", this.map(|trait_ref| trait_ref.trait_ref.args[1])), + 3.. => { + write!(f, "<{:?}", this.map(|trait_ref| trait_ref.trait_ref.args[1]))?; + for arg in &this.data.trait_ref.args[2..] { + let arg = this.wrap(arg); + write!(f, ", {:?}", arg)?; + } + write!(f, ">)") + } + } } } From a5bad9223567c97996a5669bdabea048fb138ef9 Mon Sep 17 00:00:00 2001 From: Boxy Date: Sat, 18 May 2024 23:42:32 +0100 Subject: [PATCH 3/4] bless tests --- tests/ui/traits/cache-reached-depth-ice.rs | 2 +- tests/ui/traits/cache-reached-depth-ice.stderr | 2 +- .../issue-83538-tainted-cache-after-cycle.rs | 8 ++++---- .../issue-83538-tainted-cache-after-cycle.stderr | 8 ++++---- tests/ui/traits/issue-85360-eval-obligation-ice.rs | 9 ++++++--- .../traits/issue-85360-eval-obligation-ice.stderr | 4 ++-- tests/ui/traits/project-modulo-regions.rs | 14 ++++++++++---- .../project-modulo-regions.with_clause.stderr | 8 ++++---- .../project-modulo-regions.without_clause.stderr | 8 ++++---- .../type-alias-impl-trait/in-where-clause.stderr | 2 +- 10 files changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/ui/traits/cache-reached-depth-ice.rs b/tests/ui/traits/cache-reached-depth-ice.rs index 8c2391113d719..3560e9391eb5e 100644 --- a/tests/ui/traits/cache-reached-depth-ice.rs +++ b/tests/ui/traits/cache-reached-depth-ice.rs @@ -41,5 +41,5 @@ fn test() {} fn main() { test::(); - //~^ ERROR evaluate(Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) + //~^ ERROR evaluate(Binder { value: (A: std::marker::Send), bound_vars: [] }) = Ok(EvaluatedToOk) } diff --git a/tests/ui/traits/cache-reached-depth-ice.stderr b/tests/ui/traits/cache-reached-depth-ice.stderr index e84ebc91ae169..4631d3f722f81 100644 --- a/tests/ui/traits/cache-reached-depth-ice.stderr +++ b/tests/ui/traits/cache-reached-depth-ice.stderr @@ -1,4 +1,4 @@ -error: evaluate(Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) +error: evaluate(Binder { value: (A: std::marker::Send), bound_vars: [] }) = Ok(EvaluatedToOk) --> $DIR/cache-reached-depth-ice.rs:43:5 | LL | fn test() {} diff --git a/tests/ui/traits/issue-83538-tainted-cache-after-cycle.rs b/tests/ui/traits/issue-83538-tainted-cache-after-cycle.rs index 5136aef4f7aa7..7134a7900c14e 100644 --- a/tests/ui/traits/issue-83538-tainted-cache-after-cycle.rs +++ b/tests/ui/traits/issue-83538-tainted-cache-after-cycle.rs @@ -57,10 +57,10 @@ fn main() { // Key is that Vec is "ok" and Third<'_, Ty> is "ok modulo regions": forward(); - //~^ ERROR evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) - //~| ERROR evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) + //~^ ERROR evaluate(Binder { value: (std::vec::Vec: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOk) + //~| ERROR evaluate(Binder { value: (Third<'?0, Ty>: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) reverse(); - //~^ ERROR evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) - //~| ERROR evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) + //~^ ERROR evaluate(Binder { value: (std::vec::Vec: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOk) + //~| ERROR evaluate(Binder { value: (Third<'?2, Ty>: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) } diff --git a/tests/ui/traits/issue-83538-tainted-cache-after-cycle.stderr b/tests/ui/traits/issue-83538-tainted-cache-after-cycle.stderr index 96baec76a17ec..9eb95de746c4b 100644 --- a/tests/ui/traits/issue-83538-tainted-cache-after-cycle.stderr +++ b/tests/ui/traits/issue-83538-tainted-cache-after-cycle.stderr @@ -1,4 +1,4 @@ -error: evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) +error: evaluate(Binder { value: (std::vec::Vec: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOk) --> $DIR/issue-83538-tainted-cache-after-cycle.rs:59:5 | LL | Vec: Unpin, @@ -7,7 +7,7 @@ LL | Vec: Unpin, LL | forward(); | ^^^^^^^ -error: evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) +error: evaluate(Binder { value: (Third<'?0, Ty>: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) --> $DIR/issue-83538-tainted-cache-after-cycle.rs:59:5 | LL | Third<'a, Ty>: Unpin, @@ -16,7 +16,7 @@ LL | Third<'a, Ty>: Unpin, LL | forward(); | ^^^^^^^ -error: evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) +error: evaluate(Binder { value: (Third<'?2, Ty>: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) --> $DIR/issue-83538-tainted-cache-after-cycle.rs:63:5 | LL | Third<'a, Ty>: Unpin, @@ -25,7 +25,7 @@ LL | Third<'a, Ty>: Unpin, LL | reverse(); | ^^^^^^^ -error: evaluate(Binder { value: TraitPredicate( as std::marker::Unpin>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) +error: evaluate(Binder { value: (std::vec::Vec: std::marker::Unpin), bound_vars: [] }) = Ok(EvaluatedToOk) --> $DIR/issue-83538-tainted-cache-after-cycle.rs:63:5 | LL | Vec: Unpin, diff --git a/tests/ui/traits/issue-85360-eval-obligation-ice.rs b/tests/ui/traits/issue-85360-eval-obligation-ice.rs index 931879a672262..d2920e47088b1 100644 --- a/tests/ui/traits/issue-85360-eval-obligation-ice.rs +++ b/tests/ui/traits/issue-85360-eval-obligation-ice.rs @@ -7,10 +7,10 @@ use core::marker::PhantomData; fn main() { test::>>(make()); - //~^ ERROR evaluate(Binder { value: TraitPredicate(> as std::marker::Sized>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) + //~^ ERROR evaluate(Binder { value: (MaskedStorage>: std::marker::Sized), bound_vars: [] }) = Ok(EvaluatedToOk) test::>>(make()); - //~^ ERROR evaluate(Binder { value: TraitPredicate(> as std::marker::Sized>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) + //~^ ERROR evaluate(Binder { value: (MaskedStorage>: std::marker::Sized), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) } #[rustc_evaluate_where_clauses] @@ -59,7 +59,10 @@ struct GenericComp2 { _t: T, } -impl Component for GenericComp2 where for<'a> &'a bool: 'a { +impl Component for GenericComp2 +where + for<'a> &'a bool: 'a, +{ type Storage = VecStorage; } diff --git a/tests/ui/traits/issue-85360-eval-obligation-ice.stderr b/tests/ui/traits/issue-85360-eval-obligation-ice.stderr index d2b00a45a4f15..ddb4e753c037b 100644 --- a/tests/ui/traits/issue-85360-eval-obligation-ice.stderr +++ b/tests/ui/traits/issue-85360-eval-obligation-ice.stderr @@ -1,4 +1,4 @@ -error: evaluate(Binder { value: TraitPredicate(> as std::marker::Sized>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) +error: evaluate(Binder { value: (MaskedStorage>: std::marker::Sized), bound_vars: [] }) = Ok(EvaluatedToOk) --> $DIR/issue-85360-eval-obligation-ice.rs:9:5 | LL | test::>>(make()); @@ -7,7 +7,7 @@ LL | test::>>(make()); LL | fn test(_: T) {} | ----- predicate -error: evaluate(Binder { value: TraitPredicate(> as std::marker::Sized>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) +error: evaluate(Binder { value: (MaskedStorage>: std::marker::Sized), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) --> $DIR/issue-85360-eval-obligation-ice.rs:12:5 | LL | test::>>(make()); diff --git a/tests/ui/traits/project-modulo-regions.rs b/tests/ui/traits/project-modulo-regions.rs index 3af5fbc7ea76d..815610fae5b77 100644 --- a/tests/ui/traits/project-modulo-regions.rs +++ b/tests/ui/traits/project-modulo-regions.rs @@ -21,7 +21,10 @@ struct Bar; // The `where` clause on this impl will cause us to produce `EvaluatedToOkModuloRegions` // when evaluating a projection involving this impl #[cfg(with_clause)] -impl MyTrait for Bar where for<'b> &'b (): 'b { +impl MyTrait for Bar +where + for<'b> &'b (): 'b, +{ type Assoc = bool; } @@ -42,14 +45,17 @@ impl HelperTrait for Helper where ::Assoc: Sized {} // Evaluating this 'where' clause will (recursively) end up evaluating // `for<'b> &'b (): 'b`, which will produce `EvaluatedToOkModuloRegions` #[rustc_evaluate_where_clauses] -fn test(val: MyStruct) where Helper: HelperTrait { +fn test(val: MyStruct) +where + Helper: HelperTrait, +{ panic!() } fn foo(val: MyStruct) { test(val); - //[with_clause]~^ ERROR evaluate(Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) - //[without_clause]~^^ ERROR evaluate(Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) + //[with_clause]~^ ERROR evaluate(Binder { value: (Helper: HelperTrait), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) + //[without_clause]~^^ ERROR evaluate(Binder { value: (Helper: HelperTrait), bound_vars: [] }) = Ok(EvaluatedToOk) } fn main() {} diff --git a/tests/ui/traits/project-modulo-regions.with_clause.stderr b/tests/ui/traits/project-modulo-regions.with_clause.stderr index 0e3081ddfdfeb..e5d504d7ef3ae 100644 --- a/tests/ui/traits/project-modulo-regions.with_clause.stderr +++ b/tests/ui/traits/project-modulo-regions.with_clause.stderr @@ -1,8 +1,8 @@ -error: evaluate(Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) - --> $DIR/project-modulo-regions.rs:50:5 +error: evaluate(Binder { value: (Helper: HelperTrait), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions) + --> $DIR/project-modulo-regions.rs:56:5 | -LL | fn test(val: MyStruct) where Helper: HelperTrait { - | ----------- predicate +LL | Helper: HelperTrait, + | ----------- predicate ... LL | test(val); | ^^^^ diff --git a/tests/ui/traits/project-modulo-regions.without_clause.stderr b/tests/ui/traits/project-modulo-regions.without_clause.stderr index 830a07c4f5f79..d9c4fbebb08e5 100644 --- a/tests/ui/traits/project-modulo-regions.without_clause.stderr +++ b/tests/ui/traits/project-modulo-regions.without_clause.stderr @@ -1,8 +1,8 @@ -error: evaluate(Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk) - --> $DIR/project-modulo-regions.rs:50:5 +error: evaluate(Binder { value: (Helper: HelperTrait), bound_vars: [] }) = Ok(EvaluatedToOk) + --> $DIR/project-modulo-regions.rs:56:5 | -LL | fn test(val: MyStruct) where Helper: HelperTrait { - | ----------- predicate +LL | Helper: HelperTrait, + | ----------- predicate ... LL | test(val); | ^^^^ diff --git a/tests/ui/type-alias-impl-trait/in-where-clause.stderr b/tests/ui/type-alias-impl-trait/in-where-clause.stderr index 9c08b8f127d27..d192d4e0dc3ca 100644 --- a/tests/ui/type-alias-impl-trait/in-where-clause.stderr +++ b/tests/ui/type-alias-impl-trait/in-where-clause.stderr @@ -16,7 +16,7 @@ LL | / fn foo() -> Bar LL | | where LL | | Bar: Send, | |______________^ - = note: ...which requires revealing opaque types in `[Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }]`... + = note: ...which requires revealing opaque types in `[Binder { value: (Alias(Opaque, AliasTy { args: [], def_id: DefId(0:7 ~ in_where_clause[cb1b]::Bar::{opaque#0}) }): core::marker::Send), bound_vars: [] }]`... = note: ...which again requires computing type of `Bar::{opaque#0}`, completing the cycle note: cycle used when checking that `Bar::{opaque#0}` is well-formed --> $DIR/in-where-clause.rs:5:12 From 876d1818e29b1bf0ac2cabf1b00584e6b84bf35e Mon Sep 17 00:00:00 2001 From: Boxy Date: Sun, 19 May 2024 12:59:43 +0100 Subject: [PATCH 4/4] merge import --- compiler/rustc_middle/src/ty/context.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index f405dd4f08005..5aff0ae47310f 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -4,7 +4,6 @@ pub mod tls; -use hir::def::Namespace; pub use rustc_type_ir::lift::Lift; use crate::arena::Arena; @@ -54,7 +53,7 @@ use rustc_errors::{ Applicability, Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, LintDiagnostic, MultiSpan, }; use rustc_hir as hir; -use rustc_hir::def::DefKind; +use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::definitions::Definitions; use rustc_hir::intravisit::Visitor;