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

casting &[u8] to * const u8 doesn't work in const_eval #33457

Merged
merged 1 commit into from
May 9, 2016

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented May 6, 2016

fixes #33452

r? @eddyb

cc @Ms2ger

@@ -1117,6 +1117,10 @@ fn cast_const<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstVal, ty: ty::Ty) -> CastResult
Float(f) => cast_const_float(tcx, f, ty),
Char(c) => cast_const_int(tcx, Infer(c as u64), ty),
Function(_) => Err(UnimplementedConstVal("casting fn pointers")),
ByteStr(_) => match ty.sty {
ty::TyRawPtr(_) => Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr")),
Copy link
Member

@eddyb eddyb May 6, 2016

Choose a reason for hiding this comment

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

How does this help? Wouldn't it still error?
EDIT: I think... I see? Can't be done in const_eval but is still constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, and the const_err lint ignores some kinds of errors, since there's no point in informing the user that const_eval can't evaluate it unless they try to use it in an array length or pattern.

@eddyb
Copy link
Member

eddyb commented May 6, 2016

@bors r+

@bors
Copy link
Contributor

bors commented May 6, 2016

📌 Commit d818a08 has been approved by eddyb

@bluss
Copy link
Member

bluss commented May 6, 2016

b"" is actually a &[u8; 0] (and so on with the correct length), not a slice (&[u8]).

@Ms2ger
Copy link
Contributor

Ms2ger commented May 7, 2016

And travis complains:

/home/travis/build/rust-lang/rust/src/librustc_const_eval/eval.rs:1121: line longer than 100 chars

@eddyb
Copy link
Member

eddyb commented May 7, 2016

@bors r- Until the tidy failure is fixed.

@oli-obk
Copy link
Contributor Author

oli-obk commented May 9, 2016

done

@eddyb
Copy link
Member

eddyb commented May 9, 2016

@bors r+

@bors
Copy link
Contributor

bors commented May 9, 2016

📌 Commit 7461e45 has been approved by eddyb

@bors
Copy link
Contributor

bors commented May 9, 2016

⌛ Testing commit 7461e45 with merge faca79f...

bors added a commit that referenced this pull request May 9, 2016
casting `&[u8]` to `* const u8` doesn't work in const_eval

fixes #33452

r? @eddyb

cc @Ms2ger
@bors bors merged commit 7461e45 into rust-lang:master May 9, 2016
@oli-obk oli-obk deleted the const_err/cast_u8_ptr branch May 10, 2016 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

const_err warns about casting bytestring to raw pointer
5 participants