Skip to content
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

Merged
merged 1 commit into from
Feb 21, 2020

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Feb 20, 2020

Fixes #69310 which was injected by #68118.

r? @pnkfelix @varkor @eddyb
cc @Skinny121

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 20, 2020
@Centril Centril added beta-nominated Nominated for backporting to the compiler in the beta channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 20, 2020
Comment on lines -30 to +33
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() }
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :)

Comment on lines 148 to 149
// create a dummy value and continue compiling
Const::from_bits(self.tcx, 0, self.param_env.and(ty))
Copy link
Member

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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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).

Copy link
Member

@eddyb eddyb left a 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

@Centril
Copy link
Contributor Author

Centril commented Feb 20, 2020

Nits fixed, r? @eddyb @bors r=eddyb

@bors
Copy link
Contributor

bors commented Feb 20, 2020

📌 Commit 748dd45 has been approved by eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned pnkfelix Feb 20, 2020
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 20, 2020
@bors
Copy link
Contributor

bors commented Feb 21, 2020

⌛ Testing commit 748dd45 with merge 212aa3e...

@bors
Copy link
Contributor

bors commented Feb 21, 2020

☀️ Test successful - checks-azure
Approved by: eddyb
Pushing 212aa3e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 21, 2020
@bors bors merged commit 212aa3e into rust-lang:master Feb 21, 2020
@Centril Centril deleted the literally-melting-ice branch February 21, 2020 15:54
@pnkfelix
Copy link
Member

discussed in T-compiler meeting. beta-accepted.

@pnkfelix pnkfelix added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Feb 27, 2020
@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Feb 28, 2020
bors added a commit that referenced this pull request Feb 28, 2020
[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

internal compiler error: src/librustc_mir_build/hair/constant.rs:60: impossible case reached
6 participants