-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't skip inference for type in offset_of!
#111696
don't skip inference for type in offset_of!
#111696
Conversation
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
@@ -3077,7 +3077,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
fields: &[Ident], | |||
expr: &'tcx hir::Expr<'tcx>, | |||
) -> Ty<'tcx> { | |||
let container = self.to_ty(container).normalized; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be erasing regions this early in typeck... Why not erase later, like during writeback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I just replace this assert with the erase? Nevermind, this also checks for infer types and not just infer regions.
rust/compiler/rustc_hir_typeck/src/writeback.rs
Lines 696 to 702 in 9052ca9
if cfg!(debug_assertions) && container.has_infer() { | |
span_bug!( | |
hir_id.to_span(self.fcx.tcx), | |
"writeback: `{:?}` has inference variables", | |
container | |
); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we shouldn't be skipping inference here in the first place, because this leads to another error-to-ICE for this code:
#![feature(offset_of)]
struct Foo<T> {
x: T,
}
fn main() {
let _ = core::mem::offset_of!(Foo<_>, x);
}
offset_of!(Delta<Alpha>, z); //~ ERROR the size for values of type | ||
offset_of!(Delta<Extern>, z); //~ ERROR the size for values of type | ||
offset_of!(Delta<dyn Trait>, z); //~ ERROR the size for values of type | ||
offset_of!(Delta<Box<dyn Trait>>, z); // compiles fine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR this might not actually ensure that the line compiles fine. I mean it does compile fine, but there is deduplication active for the "unsized" error, which means that if some type causes the error multiple times inside the same function, the error is only emitted once. That's why I moved the delta related stuff into its own function.
So maybe the best would be to move the Box<dyn Trait>
stuff into its own function.
dd2f636
to
6be4dc9
Compare
offset_of!
, take 2offset_of!
r=me when that dependency lands r? @compiler-errors @bors delegate+ |
bors wake up @bors delegate+ |
6be4dc9
to
7cdb23b
Compare
@bors r=compiler-errors |
☀️ Test successful - checks-actions |
Finished benchmarking commit (a11235d): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 643.686s -> 644.164s (0.07%) |
Fixes #111678 by no longer skipping inference on the type in
offset_of!
. Simply erasing the regions the during writeback isn't enough and can cause ICEs. A test case for this is included.This reverts #111661, because it becomes redundant, since inference already erases the regions.