fix OOM when ty::Instance
is used in query description
This commit is contained in:
parent
11035f9f52
commit
274674819c
@ -293,12 +293,16 @@ impl<'tcx> InstanceDef<'tcx> {
|
||||
fn fmt_instance(
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
instance: &Instance<'_>,
|
||||
type_length: rustc_session::Limit,
|
||||
type_length: Option<rustc_session::Limit>,
|
||||
) -> fmt::Result {
|
||||
ty::tls::with(|tcx| {
|
||||
let args = tcx.lift(instance.args).expect("could not lift for printing");
|
||||
|
||||
let mut cx = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length);
|
||||
let mut cx = if let Some(type_length) = type_length {
|
||||
FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
|
||||
} else {
|
||||
FmtPrinter::new(tcx, Namespace::ValueNS)
|
||||
};
|
||||
cx.print_def_path(instance.def_id(), args)?;
|
||||
let s = cx.into_buffer();
|
||||
f.write_str(&s)
|
||||
@ -324,13 +328,13 @@ pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);
|
||||
|
||||
impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt_instance(f, self.0, rustc_session::Limit(self.1))
|
||||
fmt_instance(f, self.0, Some(rustc_session::Limit(self.1)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Display for Instance<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit()))
|
||||
fmt_instance(f, self, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
mod m {
|
||||
pub struct Uuid(());
|
||||
|
||||
impl Uuid {
|
||||
pub fn encode_buffer() -> [u8; LENGTH] {
|
||||
[]
|
||||
}
|
||||
}
|
||||
const LENGTH: usize = 0;
|
||||
}
|
||||
|
||||
pub use m::Uuid;
|
10
tests/ui/resolve/suggest-constructor-cycle-error.rs
Normal file
10
tests/ui/resolve/suggest-constructor-cycle-error.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// aux-build:suggest-constructor-cycle-error.rs
|
||||
//~^ cycle detected when getting the resolver for lowering [E0391]
|
||||
|
||||
// Regression test for https://github.com/rust-lang/rust/issues/119625
|
||||
|
||||
extern crate suggest_constructor_cycle_error as a;
|
||||
|
||||
const CONST_NAME: a::Uuid = a::Uuid(());
|
||||
|
||||
fn main() {}
|
15
tests/ui/resolve/suggest-constructor-cycle-error.stderr
Normal file
15
tests/ui/resolve/suggest-constructor-cycle-error.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error[E0391]: cycle detected when getting the resolver for lowering
|
||||
|
|
||||
= note: ...which requires normalizing `[u8; suggest_constructor_cycle_error::::m::{impl#0}::encode_buffer::{constant#0}]`...
|
||||
note: ...which requires resolving instance `suggest_constructor_cycle_error::m::Uuid::encode_buffer::{constant#0}`...
|
||||
--> $DIR/auxiliary/suggest-constructor-cycle-error.rs:5:40
|
||||
|
|
||||
LL | pub fn encode_buffer() -> [u8; LENGTH] {
|
||||
| ^^^^^^
|
||||
= note: ...which requires calculating the lang items map...
|
||||
= note: ...which again requires getting the resolver for lowering, completing the cycle
|
||||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0391`.
|
Loading…
x
Reference in New Issue
Block a user