Closed
Description
This code runs fine on edition 2015, and has no warnings with #![warn(rust_2018_compatibility)]
, but fails to compile on edition 2018 (playground):
#![no_implicit_prelude]
fn main() {
assert!(true);
}
error message:
error: cannot find macro `panic!` in this scope
--> src/main.rs:4:5
|
4 | assert!(true);
| ^^^^^^^^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?
Activity
[-]assert! in edition 2018 has a non-hygenic use of panic![/-][+]assert! in edition 2018 has a non-hygienic use of panic![/+]Centril commentedon Dec 1, 2018
cc @petrochenkov
petrochenkov commentedon Dec 1, 2018
This isn't a problem with
assert
alone, most of std/core and built-in macros call other macros unhygienically (some were recently fixed though #55597).I was actually going to fix this systematically, it's just not a highest priority work.
Also, using
$crate::panic!()
etc in std macros is technically a breaking change, because especially creative users could override standard panics and other macros with their own versions, so we'll probably need a crater run.Nemo157 commentedon Dec 1, 2018
assert
isn't actually astd
macro, it's a builtin (otherwise it would have to be called asstd::assert!
above). I was surprised to find thatstd::assert_eq!
actually has a hygienic use ofpanic!
whileassert!
doesn't. IMO it would be nice to actually remove builtins from Rust's public API and hide them all behindcore
macros, (e.g.macro_rules! assert { ($tt:tt) => { _builtin_assert!($tt) } }
), but that's probably a breaking change at this point.petrochenkov commentedon Dec 1, 2018
assert_eq
also callspanic
unhygienically (not via$crate::panic!()
).+1
Probably not (modulo
no_implicit_prelude
which is pretty much unused).IIRC, the main problem was documentation - it should show actual accepted inputs rather than
$tt:tt
, but that should be solvable somehow.Nemo157 commentedon Dec 1, 2018
That's surprising, it appears to work in edition 2018 with
no_implicit_prelude
still somehow...petrochenkov commentedon Dec 1, 2018
Well, standard library is still built with Rust 2015, and on 2015 macros from
#[macro_use] extern crate ...
are still available with#[no_implicit_prelude]
(#55630).I think we can fix that, but it will also need some breakage estimation with crater.
Nemo157 commentedon Apr 22, 2019
#58702 appears to have extended the non-hygienity to other
core
macros, for crates using both edition 2015 and 2018:Nemo157 commentedon Apr 22, 2019
The non-hygienity even extends to the
panic
macro itself,::std::panic!()
expands topanic!("explicit panic")
and giveserror: cannot find macro
panic!in this scope
.petrochenkov commentedon Jun 7, 2019
For all macros beside
panic
the underlying issue is fixed in #61629.panic
is special, #61629 describes the situation in more detail.Rollup merge of rust-lang#61629 - petrochenkov:stdmac, r=alexcrichton
Rollup merge of rust-lang#61629 - petrochenkov:stdmac, r=alexcrichton
petrochenkov commentedon Jun 13, 2019
I'm going to close this in favor of #61567 (which doesn't have a discussion distracting from the primary issue).