-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
lit_to_const
: gracefully bubble up type errors.
#69330
Conversation
ast::LitKind::ByteStr(ref data) => { | ||
if let ty::Ref(_, ref_ty, _) = ty.kind { | ||
match ref_ty.kind { | ||
ty::Slice(_) => { | ||
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>); | ||
let allocation = tcx.intern_const_alloc(allocation); | ||
ConstValue::Slice { data: allocation, start: 0, end: data.len() } | ||
} | ||
ty::Array(_, _) => { | ||
let id = tcx.allocate_bytes(data); | ||
ConstValue::Scalar(Scalar::Ptr(id.into())) | ||
} | ||
_ => { | ||
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty) | ||
} | ||
} | ||
} else { | ||
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty) | ||
} | ||
(ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Slice(_), .. }, _)) => { | ||
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>); | ||
let allocation = tcx.intern_const_alloc(allocation); | ||
ConstValue::Slice { data: allocation, start: 0, end: data.len() } |
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 :)
// create a dummy value and continue compiling | ||
Const::from_bits(self.tcx, 0, self.param_env.and(ty)) |
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.
@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 ty::ConstKind::Err
(if we don't have it already)?
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.
We don't have such an ::Err
variant, https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/enum.ConstKind.html.
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.
Adding one is probably a good idea (but can be done in a separate PR).
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.
r=me modulo nits
f040e15
to
748dd45
Compare
📌 Commit 748dd45 has been approved by |
☀️ Test successful - checks-azure |
discussed in T-compiler meeting. beta-accepted. |
[beta] backports This backports the following PRs: * ci: switch macOS builders to 10.15 #68863 * Backport release notes of 1.41.1 #69468 * Cherry-pick the LLVM fix for #69225 #69450 * `lit_to_const`: gracefully bubble up type errors. #69330 * [beta] bootstrap from 1.41.1 stable #69518 * bootstrap: Configure cmake when building sanitizer runtimes #69104 r? @ghost
Fixes #69310 which was injected by #68118.
r? @pnkfelix @varkor @eddyb
cc @Skinny121