-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Improve documentation for built-in macros #62243
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
Changes from all commits
15042a3
22d6d8a
ab112ca
987be89
920a17a
3274507
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,7 +410,7 @@ mod builtin { | |
/// | ||
/// [`panic!`]: ../std/macro.panic.html | ||
#[stable(feature = "compile_error_macro", since = "1.20.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! compile_error { | ||
|
||
($msg:expr) => ({ /* compiler built-in */ }); | ||
($msg:expr,) => ({ /* compiler built-in */ }); | ||
|
@@ -462,7 +462,7 @@ mod builtin { | |
/// assert_eq!(s, format!("hello {}", "world")); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! format_args { | ||
($fmt:expr) => ({ /* compiler built-in */ }); | ||
($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }); | ||
|
@@ -500,7 +500,7 @@ mod builtin { | |
/// error: what's that?! | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! env { | ||
($name:expr) => ({ /* compiler built-in */ }); | ||
($name:expr,) => ({ /* compiler built-in */ }); | ||
|
@@ -526,7 +526,7 @@ mod builtin { | |
/// println!("the secret key might be: {:?}", key); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! option_env { | ||
($name:expr) => ({ /* compiler built-in */ }); | ||
($name:expr,) => ({ /* compiler built-in */ }); | ||
|
@@ -557,7 +557,7 @@ mod builtin { | |
/// # } | ||
/// ``` | ||
#[unstable(feature = "concat_idents_macro", issue = "29599")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! concat_idents { | ||
($($e:ident),+) => ({ /* compiler built-in */ }); | ||
($($e:ident,)+) => ({ /* compiler built-in */ }); | ||
|
@@ -579,7 +579,7 @@ mod builtin { | |
/// assert_eq!(s, "test10btrue"); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! concat { | ||
($($e:expr),*) => ({ /* compiler built-in */ }); | ||
($($e:expr,)*) => ({ /* compiler built-in */ }); | ||
|
@@ -607,7 +607,7 @@ mod builtin { | |
/// println!("defined on line: {}", current_line); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! line { () => ({ /* compiler built-in */ }) } | ||
|
||
/// Expands to the column number at which it was invoked. | ||
|
@@ -632,7 +632,7 @@ mod builtin { | |
/// println!("defined on column: {}", current_col); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! column { () => ({ /* compiler built-in */ }) } | ||
|
||
/// Expands to the file name in which it was invoked. | ||
|
@@ -656,7 +656,7 @@ mod builtin { | |
/// println!("defined in file: {}", this_file); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! file { () => ({ /* compiler built-in */ }) } | ||
|
||
/// Stringifies its arguments. | ||
|
@@ -675,7 +675,7 @@ mod builtin { | |
/// assert_eq!(one_plus_one, "1 + 1"); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! stringify { ($($t:tt)*) => ({ /* compiler built-in */ }) } | ||
|
||
/// Includes a utf8-encoded file as a string. | ||
|
@@ -709,7 +709,7 @@ mod builtin { | |
/// | ||
/// Compiling 'main.rs' and running the resulting binary will print "adiós". | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! include_str { | ||
($file:expr) => ({ /* compiler built-in */ }); | ||
($file:expr,) => ({ /* compiler built-in */ }); | ||
|
@@ -746,7 +746,7 @@ mod builtin { | |
/// | ||
/// Compiling 'main.rs' and running the resulting binary will print "adiós". | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! include_bytes { | ||
($file:expr) => ({ /* compiler built-in */ }); | ||
($file:expr,) => ({ /* compiler built-in */ }); | ||
|
@@ -770,7 +770,7 @@ mod builtin { | |
/// test::foo(); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! module_path { () => ({ /* compiler built-in */ }) } | ||
|
||
/// Evaluates boolean combinations of configuration flags at compile-time. | ||
|
@@ -794,7 +794,7 @@ mod builtin { | |
/// }; | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) } | ||
|
||
/// Parses a file as an expression or an item according to the context. | ||
|
@@ -837,7 +837,7 @@ mod builtin { | |
/// Compiling 'main.rs' and running the resulting binary will print | ||
/// "🙈🙊🙉🙈🙊🙉". | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! include { | ||
($file:expr) => ({ /* compiler built-in */ }); | ||
($file:expr,) => ({ /* compiler built-in */ }); | ||
|
@@ -889,7 +889,7 @@ mod builtin { | |
/// assert!(a + b == 30, "a = {}, b = {}", a, b); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_doc_only_macro] | ||
#[rustc_builtin_macro] | ||
macro_rules! assert { | ||
($cond:expr) => ({ /* compiler built-in */ }); | ||
($cond:expr,) => ({ /* compiler built-in */ }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#![feature(decl_macro, rustc_attrs)] | ||
|
||
#[rustc_transparent_macro] | ||
#[rustc_macro_transparency = "transparent"] | ||
pub macro dollar_crate() { | ||
let s = $crate::S; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#![feature(decl_macro, rustc_attrs)] | ||
|
||
#[rustc_macro_transparency = "transparent"] | ||
macro transparent() { | ||
struct Transparent; | ||
let transparent = 0; | ||
} | ||
#[rustc_macro_transparency = "semitransparent"] | ||
macro semitransparent() { | ||
struct SemiTransparent; | ||
let semitransparent = 0; | ||
} | ||
#[rustc_macro_transparency = "opaque"] | ||
macro opaque() { | ||
struct Opaque; | ||
let opaque = 0; | ||
} | ||
|
||
fn main() { | ||
transparent!(); | ||
semitransparent!(); | ||
opaque!(); | ||
|
||
Transparent; // OK | ||
SemiTransparent; // OK | ||
Opaque; //~ ERROR cannot find value `Opaque` in this scope | ||
|
||
transparent; // OK | ||
semitransparent; //~ ERROR cannot find value `semitransparent` in this scope | ||
opaque; //~ ERROR cannot find value `opaque` in this scope | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0425]: cannot find value `Opaque` in this scope | ||
--> $DIR/rustc-macro-transparency.rs:26:5 | ||
| | ||
LL | Opaque; | ||
| ^^^^^^ help: a local variable with a similar name exists: `opaque` | ||
|
||
error[E0425]: cannot find value `semitransparent` in this scope | ||
--> $DIR/rustc-macro-transparency.rs:29:5 | ||
| | ||
LL | semitransparent; | ||
| ^^^^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0425]: cannot find value `opaque` in this scope | ||
--> $DIR/rustc-macro-transparency.rs:30:5 | ||
| | ||
LL | opaque; | ||
| ^^^^^^ not found in this scope | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
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.
Is this needed anymore? The
macro_rules!
->macro
change would mean!def.legacy
is nowtrue
.Uh oh!
There was an error while loading. Please reload this page.
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.
No, this is no longer needed (UPD: for libcore, it's still needed for libstd).