With Rust 2018, this code works (Playground):
use std::panic;
use std::format;
use std::assert_eq;
Run Code Online (Sandbox Code Playgroud)
But this:
use std::assert;
Run Code Online (Sandbox Code Playgroud)
Results in this error:
error[E0432]: unresolved import `std::assert`
--> src/lib.rs:4:5
|
4 | use std::assert;
| ^^^^^^^^^^^ no `assert` in the root
Run Code Online (Sandbox Code Playgroud)
I read the edition guide about this topic and it says that use should work with macro_rules! macros and procedural macros. Thus, I'm confused.
useshould work withmacro_rules!macros and procedural macros
Except assert is neither of those:
Run Code Online (Sandbox Code Playgroud)/// Built-in macros to the compiler itself. /// /// These macros do not have any corresponding definition with a `macro_rules!` /// macro, but are documented here. Their implementations can be found hardcoded /// into libsyntax itself.
It is a compiler built-in:
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_doc_only_macro]
macro_rules! assert {
($cond:expr) => ({ /* compiler built-in */ });
($cond:expr,) => ({ /* compiler built-in */ });
($cond:expr, $($arg:tt)+) => ({ /* compiler built-in */ });
}
Run Code Online (Sandbox Code Playgroud)
Other faux-macros include:
compile_errorformat_argsenvoption_envconcat_identsconcatlinecolumnfilestringifyinclude_strinclude_bytesmodule_pathcfgincludeThe actual definition of assert is buried much lower in libsyntax_ext/assert.rs
Stabilize uniform paths on Rust 2018 (#56417) does mention these in passing:
Built-in macros, for example
use env. Currently an error due to some (fixable) implementation details of built-in macros. No known issues to resolve before stabilization (after the error is removed).
| 归档时间: |
|
| 查看次数: |
208 次 |
| 最近记录: |