-
Notifications
You must be signed in to change notification settings - Fork 13.3k
lit_to_const
: gracefully bubble up type errors.
#69330
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { | |
// create a dummy value and continue compiling | ||
Const::from_bits(self.tcx, 0, self.param_env.and(ty)) | ||
Comment on lines
148
to
149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oli-obk This isn't new in this PR but I wonder why this isn't undef or something (I guess that might cause ICEs?). Maybe we need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have such an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding one is probably a good idea (but can be done in a separate PR). |
||
} | ||
Err(LitToConstError::TypeError) => bug!("const_eval_literal: had type error"), | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// This is a regression test for #69310, which was injected by #68118. | ||
// The issue here was that as a performance optimization, | ||
// we call the query `lit_to_const(input);`. | ||
// However, the literal `input.lit` would not be of the type expected by `input.ty`. | ||
// As a result, we immediately called `bug!(...)` instead of bubbling up the problem | ||
// so that it could be handled by the caller of `lit_to_const` (`ast_const_to_const`). | ||
|
||
fn main() {} | ||
|
||
const A: [(); 0.1] = [()]; //~ ERROR mismatched types | ||
const B: [(); b"a"] = [()]; //~ ERROR mismatched types |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-69310-array-size-lit-wrong-ty.rs:10:15 | ||
| | ||
LL | const A: [(); 0.1] = [()]; | ||
| ^^^ expected `usize`, found floating-point number | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69310-array-size-lit-wrong-ty.rs:11:15 | ||
| | ||
LL | const B: [(); b"a"] = [()]; | ||
| ^^^^ expected `usize`, found `&[u8; 1]` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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.
Reminder to self that reviewing this is best done in "No Whitespace" mode.
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.
Indeed :)