Comments (7)
A more minimal repo would be:
Even more minimal:
macro_rules! cycle {
($expr:expr) => { const X: () = $expr; }
}
fn main() { cycle!(X); } //~ ERROR cycle detected
macro_rules!
-macros aka decl macros 1.2 are only partially hygienic because only local variables follow macro hygiene but not items. When you define constant X
via a 1.2 macro, you can access it from other syntax contexts. That's what happens in the example above. Another example would be
macro_rules! def { () => { const X: () = (); } }
fn main() {
def!();
let _ = X; // successfully resolves `X` to the const item
}
Decl macros 2.0 (#![feature(decl_macro)]
) on the other hand are fully hygienic: Both locals and items are hygienic. For example, the following code succeeds compilation:
#![feature(decl_macro)]
macro cycle {
($expr:expr) => { const X: () = $expr; }
}
fn main() {
const X: () = ();
cycle!(X);
}
from rust.
TL;DR: Your example from the issue description passes compilation if you use decl macros 2.0 instead of 1.2 (which requires nightly): Playground.
from rust.
A more minimal repo would be:
macro_rules! cycle {
($expr:expr) => {{
const UTF8: &str = $expr;
}}
}
#[allow(unused)]
fn main() {
const UTF8: &str = "hello";
cycle!(UTF8);
}
from rust.
Not sure if it's relevant to this issue but the same error happens without the macro_rules!
:
#[allow(dead_code)]
fn main() {
const UTF8: &str = "hello";
{
const UTF8: &str = UTF8;
}
}
from rust.
This works as intended. [typing explainer...]
from rust.
Closing as works as intended :)
from rust.
I had a feeling this might get a "working as intended" but I'm glad to hear it gets fixed by macros 2.0!
from rust.
Related Issues (20)
- ICE: `No HirID for DefId(...)` with feature `generic_assert` HOT 2
- Nonsensical suggested type using chumsky select! (E0284) HOT 4
- Confusing error message on using `step_by` and `take` on infinite iterator
- ICE: kcfi: `expected item, found (root_crate)` HOT 1
- ICE: kcfi: `unexpected parent of trait or impl item or item not found: ForeignMod` HOT 1
- ICE: kcfi: `cannot get associated-item of DefKey..` HOT 3
- patterns: wrong tracking issue? HOT 20
- Tracking Issue for pattern types HOT 1
- Async closure internal compiler error HOT 2
- ICE: `unexpected bound var resolution for HirId(...): None` HOT 1
- Figure out the interaction of GVN and function/vtable pointers HOT 8
- rustdoc doesn't support reading from STDIN via the fake path `-` (dash)
- Rustdoc incorrectly fires `redundant_explicit_link` warning
- ICE: kcfi: `args not compatible with generics for Foo::Bar`
- ICE: kcfi: `encode_region: unexpected ''static'`
- RUST_BACKTRACE=full panic causes infinite loop on aarch64-pc-windows-msvc HOT 3
- Test failure when enabling vendoring HOT 1
- ICE: `Unsigned value 0x100 does not fit in 8 bits` HOT 2
- ICE: `Size::sub: 0 - 1 would result in negative size` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.