Skip to content

Commit dabbc7f

Browse files
committed
Reuse cached layout from PostAnalysis when possible.
1 parent 090d210 commit dabbc7f

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ fn layout_of<'tcx>(
6666
return tcx.layout_of(typing_env.as_query_input(ty));
6767
}
6868

69+
match typing_env.typing_mode() {
70+
ty::TypingMode::Codegen => {
71+
let with_postanalysis =
72+
ty::TypingEnv::new(typing_env.param_env, ty::TypingMode::PostAnalysis);
73+
let res = tcx.layout_of(with_postanalysis.as_query_input(ty));
74+
match res {
75+
Err(LayoutError::TooGeneric(_)) => {}
76+
_ => return res,
77+
};
78+
}
79+
ty::TypingMode::Coherence
80+
| ty::TypingMode::Analysis { .. }
81+
| ty::TypingMode::Borrowck { .. }
82+
| ty::TypingMode::PostBorrowckAnalysis { .. }
83+
| ty::TypingMode::ErasedNotCoherence(_)
84+
| ty::TypingMode::PostAnalysis => {}
85+
}
86+
6987
let cx = LayoutCx::new(tcx, typing_env);
7088

7189
let layout = layout_of_uncached(&cx, ty)?;

tests/ui/recursion/recursion_limit/zero-overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//~ ERROR overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome>
1+
//~ ERROR queries overflow the depth limit!
22
//~| HELP consider increasing the recursion limit
33
//@ build-fail
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error[E0275]: overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome>`
1+
error: queries overflow the depth limit!
22
|
33
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`zero_overflow`)
4+
= note: query depth increased by 2 when computing layout of `isize`
45

56
error: aborting due to 1 previous error
67

7-
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)