Skip to content

Commit 2746748

Browse files
author
Lukas Markeffsky
committed
fix OOM when ty::Instance is used in query description
1 parent 11035f9 commit 2746748

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,16 @@ impl<'tcx> InstanceDef<'tcx> {
293293
fn fmt_instance(
294294
f: &mut fmt::Formatter<'_>,
295295
instance: &Instance<'_>,
296-
type_length: rustc_session::Limit,
296+
type_length: Option<rustc_session::Limit>,
297297
) -> fmt::Result {
298298
ty::tls::with(|tcx| {
299299
let args = tcx.lift(instance.args).expect("could not lift for printing");
300300

301-
let mut cx = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length);
301+
let mut cx = if let Some(type_length) = type_length {
302+
FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
303+
} else {
304+
FmtPrinter::new(tcx, Namespace::ValueNS)
305+
};
302306
cx.print_def_path(instance.def_id(), args)?;
303307
let s = cx.into_buffer();
304308
f.write_str(&s)
@@ -324,13 +328,13 @@ pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);
324328

325329
impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
326330
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
327-
fmt_instance(f, self.0, rustc_session::Limit(self.1))
331+
fmt_instance(f, self.0, Some(rustc_session::Limit(self.1)))
328332
}
329333
}
330334

331335
impl<'tcx> fmt::Display for Instance<'tcx> {
332336
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
333-
ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit()))
337+
fmt_instance(f, self, None)
334338
}
335339
}
336340

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
mod m {
2+
pub struct Uuid(());
3+
4+
impl Uuid {
5+
pub fn encode_buffer() -> [u8; LENGTH] {
6+
[]
7+
}
8+
}
9+
const LENGTH: usize = 0;
10+
}
11+
12+
pub use m::Uuid;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build:suggest-constructor-cycle-error.rs
2+
//~^ cycle detected when getting the resolver for lowering [E0391]
3+
4+
// Regression test for https://github.com/rust-lang/rust/issues/119625
5+
6+
extern crate suggest_constructor_cycle_error as a;
7+
8+
const CONST_NAME: a::Uuid = a::Uuid(());
9+
10+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0391]: cycle detected when getting the resolver for lowering
2+
|
3+
= note: ...which requires normalizing `[u8; suggest_constructor_cycle_error::::m::{impl#0}::encode_buffer::{constant#0}]`...
4+
note: ...which requires resolving instance `suggest_constructor_cycle_error::m::Uuid::encode_buffer::{constant#0}`...
5+
--> $DIR/auxiliary/suggest-constructor-cycle-error.rs:5:40
6+
|
7+
LL | pub fn encode_buffer() -> [u8; LENGTH] {
8+
| ^^^^^^
9+
= note: ...which requires calculating the lang items map...
10+
= note: ...which again requires getting the resolver for lowering, completing the cycle
11+
= 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
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)