-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Allow blocks in const expressions #14183
Conversation
StmtExpr(ref expr, _) => block_span_err(expr.span), | ||
StmtSemi(ref semi, _) => block_span_err(semi.span), | ||
StmtMac(..) => v.tcx.sess.span_bug(e.span, | ||
"unexpanded statement macro in const?!") |
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 think macro_rules!
macros may stick around un-expanded. Can you add a test case too make sure we don't ICE here?
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.
Do you mean macro_rules!
itself, or macros generated by it? For the latter there is a testcase 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.
Yeah, macro_rules!
itself
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.
Added a testcase, doesn't seem to ICE. :)
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.
Excellent, thanks!
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.
Or actually, can you add another test with the macro tagged with #[macro_export]
? Those seem to be the ones that stick around.
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.
static BLOCK_MACRO_RULES_EXPORTED: uint = {
#[macro_export]
macro_rules! baz {
() => (612)
}
baz!()
};
gives me the error
/home/marvin/dev/rust/fork/rust/src/test/run-pass/const-block-item.rs:51:19: 51:20 error: expected item after attributes
/home/marvin/dev/rust/fork/rust/src/test/run-pass/const-block-item.rs:51 #[macro_export]
^
Am I doing something wrong?
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.
Oh cool, looks like the parser doesn't even accept that currently (it wouldn't make much sense anyway I think). Thanks for checking!
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 get the same error in a regular function as well:
pub fn main() {
#[macro_export]
macro_rules! baz {
() => (612)
}
}
Only blocks with tail expressions that are const expressions and items are allowed.
Closes #14184 (std: Move the owned module from core to std) Closes #14183 (Allow blocks in const expressions) Closes #14176 (Add tests for from_bits.) Closes #14175 (Replaced ~T by Box<T> in manual) Closes #14173 (Implements Default trait for BigInt and BigUint) Closes #14171 (Fix #8391) Closes #14159 (Clean up unicode code in libstd) Closes #14126 (docs: Add a not found page) Closes #14123 (add a line to the example to clarify semantics) Closes #14106 (Pretty printer improvements) Closes #14083 (rustllvm: Add LLVMRustArrayType) Closes #13957 (io: Implement process wait timeouts)
Change `bytes!()` to return { static BYTES: &'static [u8] = &[...]; BYTES } This gives it the `'static` lifetime, whereas before it had an rvalue lifetime. Until recently this would have prevented assigning `bytes!()` to a static, as in static FOO: &'static [u8] = bytes!(1,2,3); but rust-lang#14183 fixed it so blocks are now allowed in constant expressions (with restrictions). Fixes rust-lang#11641.
Change `bytes!()` to return { static BYTES: &'static [u8] = &[...]; BYTES } This gives it the `'static` lifetime, whereas before it had an rvalue lifetime. Until recently this would have prevented assigning `bytes!()` to a static, as in static FOO: &'static [u8] = bytes!(1,2,3); but #14183 fixed it so blocks are now allowed in constant expressions (with restrictions). Fixes #11641.
minor: Try to improve the `rustfmt.overrideCommand` docs Closes rust-lang#14078
Only blocks with tail expressions that are const expressions
and items are allowed.
Implements rust-lang/rfcs#71 (#14181)