Skip to content

Commit 8e6971d

Browse files
committed
Rollup merge of rust-lang#52581 - petrochenkov:bmacrodoc, r=alexcrichton
Avoid using `#[macro_export]` for documenting builtin macros Use a special `rustc_*` attribute instead. cc rust-lang#52234
2 parents 0235707 + a18be44 commit 8e6971d

File tree

5 files changed

+43
-58
lines changed

5 files changed

+43
-58
lines changed

β€Žsrc/libcore/macros.rs

+17-32
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ macro_rules! unimplemented {
543543
/// into libsyntax itself.
544544
///
545545
/// For more information, see documentation for `std`'s macros.
546+
#[cfg(dox)]
546547
mod builtin {
547548

548549
/// Unconditionally causes compilation to fail with the given error message when encountered.
@@ -551,8 +552,7 @@ mod builtin {
551552
///
552553
/// [`std::compile_error!`]: ../std/macro.compile_error.html
553554
#[stable(feature = "compile_error_macro", since = "1.20.0")]
554-
#[macro_export]
555-
#[cfg(dox)]
555+
#[rustc_doc_only_macro]
556556
macro_rules! compile_error {
557557
($msg:expr) => ({ /* compiler built-in */ });
558558
($msg:expr,) => ({ /* compiler built-in */ });
@@ -564,8 +564,7 @@ mod builtin {
564564
///
565565
/// [`std::format_args!`]: ../std/macro.format_args.html
566566
#[stable(feature = "rust1", since = "1.0.0")]
567-
#[macro_export]
568-
#[cfg(dox)]
567+
#[rustc_doc_only_macro]
569568
macro_rules! format_args {
570569
($fmt:expr) => ({ /* compiler built-in */ });
571570
($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ });
@@ -577,8 +576,7 @@ mod builtin {
577576
///
578577
/// [`std::env!`]: ../std/macro.env.html
579578
#[stable(feature = "rust1", since = "1.0.0")]
580-
#[macro_export]
581-
#[cfg(dox)]
579+
#[rustc_doc_only_macro]
582580
macro_rules! env {
583581
($name:expr) => ({ /* compiler built-in */ });
584582
($name:expr,) => ({ /* compiler built-in */ });
@@ -590,8 +588,7 @@ mod builtin {
590588
///
591589
/// [`std::option_env!`]: ../std/macro.option_env.html
592590
#[stable(feature = "rust1", since = "1.0.0")]
593-
#[macro_export]
594-
#[cfg(dox)]
591+
#[rustc_doc_only_macro]
595592
macro_rules! option_env {
596593
($name:expr) => ({ /* compiler built-in */ });
597594
($name:expr,) => ({ /* compiler built-in */ });
@@ -603,8 +600,7 @@ mod builtin {
603600
///
604601
/// [`std::concat_idents!`]: ../std/macro.concat_idents.html
605602
#[unstable(feature = "concat_idents_macro", issue = "29599")]
606-
#[macro_export]
607-
#[cfg(dox)]
603+
#[rustc_doc_only_macro]
608604
macro_rules! concat_idents {
609605
($($e:ident),+) => ({ /* compiler built-in */ });
610606
($($e:ident,)+) => ({ /* compiler built-in */ });
@@ -616,8 +612,7 @@ mod builtin {
616612
///
617613
/// [`std::concat!`]: ../std/macro.concat.html
618614
#[stable(feature = "rust1", since = "1.0.0")]
619-
#[macro_export]
620-
#[cfg(dox)]
615+
#[rustc_doc_only_macro]
621616
macro_rules! concat {
622617
($($e:expr),*) => ({ /* compiler built-in */ });
623618
($($e:expr,)*) => ({ /* compiler built-in */ });
@@ -629,8 +624,7 @@ mod builtin {
629624
///
630625
/// [`std::line!`]: ../std/macro.line.html
631626
#[stable(feature = "rust1", since = "1.0.0")]
632-
#[macro_export]
633-
#[cfg(dox)]
627+
#[rustc_doc_only_macro]
634628
macro_rules! line { () => ({ /* compiler built-in */ }) }
635629

636630
/// A macro which expands to the column number on which it was invoked.
@@ -639,8 +633,7 @@ mod builtin {
639633
///
640634
/// [`std::column!`]: ../std/macro.column.html
641635
#[stable(feature = "rust1", since = "1.0.0")]
642-
#[macro_export]
643-
#[cfg(dox)]
636+
#[rustc_doc_only_macro]
644637
macro_rules! column { () => ({ /* compiler built-in */ }) }
645638

646639
/// A macro which expands to the file name from which it was invoked.
@@ -649,8 +642,7 @@ mod builtin {
649642
///
650643
/// [`std::file!`]: ../std/macro.file.html
651644
#[stable(feature = "rust1", since = "1.0.0")]
652-
#[macro_export]
653-
#[cfg(dox)]
645+
#[rustc_doc_only_macro]
654646
macro_rules! file { () => ({ /* compiler built-in */ }) }
655647

656648
/// A macro which stringifies its arguments.
@@ -659,8 +651,7 @@ mod builtin {
659651
///
660652
/// [`std::stringify!`]: ../std/macro.stringify.html
661653
#[stable(feature = "rust1", since = "1.0.0")]
662-
#[macro_export]
663-
#[cfg(dox)]
654+
#[rustc_doc_only_macro]
664655
macro_rules! stringify { ($($t:tt)*) => ({ /* compiler built-in */ }) }
665656

666657
/// Includes a utf8-encoded file as a string.
@@ -669,8 +660,7 @@ mod builtin {
669660
///
670661
/// [`std::include_str!`]: ../std/macro.include_str.html
671662
#[stable(feature = "rust1", since = "1.0.0")]
672-
#[macro_export]
673-
#[cfg(dox)]
663+
#[rustc_doc_only_macro]
674664
macro_rules! include_str {
675665
($file:expr) => ({ /* compiler built-in */ });
676666
($file:expr,) => ({ /* compiler built-in */ });
@@ -682,8 +672,7 @@ mod builtin {
682672
///
683673
/// [`std::include_bytes!`]: ../std/macro.include_bytes.html
684674
#[stable(feature = "rust1", since = "1.0.0")]
685-
#[macro_export]
686-
#[cfg(dox)]
675+
#[rustc_doc_only_macro]
687676
macro_rules! include_bytes {
688677
($file:expr) => ({ /* compiler built-in */ });
689678
($file:expr,) => ({ /* compiler built-in */ });
@@ -695,8 +684,7 @@ mod builtin {
695684
///
696685
/// [`std::module_path!`]: ../std/macro.module_path.html
697686
#[stable(feature = "rust1", since = "1.0.0")]
698-
#[macro_export]
699-
#[cfg(dox)]
687+
#[rustc_doc_only_macro]
700688
macro_rules! module_path { () => ({ /* compiler built-in */ }) }
701689

702690
/// Boolean evaluation of configuration flags, at compile-time.
@@ -705,8 +693,7 @@ mod builtin {
705693
///
706694
/// [`std::cfg!`]: ../std/macro.cfg.html
707695
#[stable(feature = "rust1", since = "1.0.0")]
708-
#[macro_export]
709-
#[cfg(dox)]
696+
#[rustc_doc_only_macro]
710697
macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) }
711698

712699
/// Parse a file as an expression or an item according to the context.
@@ -715,8 +702,7 @@ mod builtin {
715702
///
716703
/// [`std::include!`]: ../std/macro.include.html
717704
#[stable(feature = "rust1", since = "1.0.0")]
718-
#[macro_export]
719-
#[cfg(dox)]
705+
#[rustc_doc_only_macro]
720706
macro_rules! include {
721707
($file:expr) => ({ /* compiler built-in */ });
722708
($file:expr,) => ({ /* compiler built-in */ });
@@ -727,9 +713,8 @@ mod builtin {
727713
/// For more information, see the documentation for [`std::assert!`].
728714
///
729715
/// [`std::assert!`]: ../std/macro.assert.html
730-
#[macro_export]
716+
#[rustc_doc_only_macro]
731717
#[stable(feature = "rust1", since = "1.0.0")]
732-
#[cfg(dox)]
733718
macro_rules! assert {
734719
($cond:expr) => ({ /* compiler built-in */ });
735720
($cond:expr,) => ({ /* compiler built-in */ });

β€Žsrc/librustc/hir/lowering.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3191,7 +3191,8 @@ impl<'a> LoweringContext<'a> {
31913191
let mut vis = self.lower_visibility(&i.vis, None);
31923192
let attrs = self.lower_attrs(&i.attrs);
31933193
if let ItemKind::MacroDef(ref def) = i.node {
3194-
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") {
3194+
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") ||
3195+
attr::contains_name(&i.attrs, "rustc_doc_only_macro") {
31953196
let body = self.lower_token_stream(def.stream());
31963197
self.exported_macros.push(hir::MacroDef {
31973198
name,

β€Žsrc/librustdoc/clean/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1273,15 +1273,13 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
12731273
.resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
12741274
if let Ok(def) = res {
12751275
if let SyntaxExtension::DeclMacro { .. } = *resolver.get_macro(def) {
1276-
Some(def)
1277-
} else {
1278-
None
1276+
return Some(def);
12791277
}
1280-
} else if let Some(def) = resolver.all_macros.get(&Symbol::intern(path_str)) {
1281-
Some(*def)
1282-
} else {
1283-
None
12841278
}
1279+
if let Some(def) = resolver.all_macros.get(&Symbol::intern(path_str)) {
1280+
return Some(*def);
1281+
}
1282+
None
12851283
}
12861284

12871285
#[derive(Debug)]

β€Žsrc/libstd/macros.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ macro_rules! assert_approx_eq {
317317
/// macro, but are documented here. Their implementations can be found hardcoded
318318
/// into libsyntax itself.
319319
#[cfg(dox)]
320-
pub mod builtin {
320+
mod builtin {
321321

322322
/// Unconditionally causes compilation to fail with the given error message when encountered.
323323
///
@@ -355,7 +355,7 @@ pub mod builtin {
355355
///
356356
/// [`panic!`]: ../std/macro.panic.html
357357
#[stable(feature = "compile_error_macro", since = "1.20.0")]
358-
#[macro_export]
358+
#[rustc_doc_only_macro]
359359
macro_rules! compile_error {
360360
($msg:expr) => ({ /* compiler built-in */ });
361361
($msg:expr,) => ({ /* compiler built-in */ });
@@ -407,7 +407,7 @@ pub mod builtin {
407407
/// assert_eq!(s, format!("hello {}", "world"));
408408
/// ```
409409
#[stable(feature = "rust1", since = "1.0.0")]
410-
#[macro_export]
410+
#[rustc_doc_only_macro]
411411
macro_rules! format_args {
412412
($fmt:expr) => ({ /* compiler built-in */ });
413413
($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ });
@@ -445,7 +445,7 @@ pub mod builtin {
445445
/// error: what's that?!
446446
/// ```
447447
#[stable(feature = "rust1", since = "1.0.0")]
448-
#[macro_export]
448+
#[rustc_doc_only_macro]
449449
macro_rules! env {
450450
($name:expr) => ({ /* compiler built-in */ });
451451
($name:expr,) => ({ /* compiler built-in */ });
@@ -471,7 +471,7 @@ pub mod builtin {
471471
/// println!("the secret key might be: {:?}", key);
472472
/// ```
473473
#[stable(feature = "rust1", since = "1.0.0")]
474-
#[macro_export]
474+
#[rustc_doc_only_macro]
475475
macro_rules! option_env {
476476
($name:expr) => ({ /* compiler built-in */ });
477477
($name:expr,) => ({ /* compiler built-in */ });
@@ -502,7 +502,7 @@ pub mod builtin {
502502
/// # }
503503
/// ```
504504
#[unstable(feature = "concat_idents_macro", issue = "29599")]
505-
#[macro_export]
505+
#[rustc_doc_only_macro]
506506
macro_rules! concat_idents {
507507
($($e:ident),+) => ({ /* compiler built-in */ });
508508
($($e:ident,)+) => ({ /* compiler built-in */ });
@@ -524,7 +524,7 @@ pub mod builtin {
524524
/// assert_eq!(s, "test10btrue");
525525
/// ```
526526
#[stable(feature = "rust1", since = "1.0.0")]
527-
#[macro_export]
527+
#[rustc_doc_only_macro]
528528
macro_rules! concat {
529529
($($e:expr),*) => ({ /* compiler built-in */ });
530530
($($e:expr,)*) => ({ /* compiler built-in */ });
@@ -552,7 +552,7 @@ pub mod builtin {
552552
/// println!("defined on line: {}", current_line);
553553
/// ```
554554
#[stable(feature = "rust1", since = "1.0.0")]
555-
#[macro_export]
555+
#[rustc_doc_only_macro]
556556
macro_rules! line { () => ({ /* compiler built-in */ }) }
557557

558558
/// A macro which expands to the column number on which it was invoked.
@@ -577,7 +577,7 @@ pub mod builtin {
577577
/// println!("defined on column: {}", current_col);
578578
/// ```
579579
#[stable(feature = "rust1", since = "1.0.0")]
580-
#[macro_export]
580+
#[rustc_doc_only_macro]
581581
macro_rules! column { () => ({ /* compiler built-in */ }) }
582582

583583
/// A macro which expands to the file name from which it was invoked.
@@ -601,7 +601,7 @@ pub mod builtin {
601601
/// println!("defined in file: {}", this_file);
602602
/// ```
603603
#[stable(feature = "rust1", since = "1.0.0")]
604-
#[macro_export]
604+
#[rustc_doc_only_macro]
605605
macro_rules! file { () => ({ /* compiler built-in */ }) }
606606

607607
/// A macro which stringifies its arguments.
@@ -620,7 +620,7 @@ pub mod builtin {
620620
/// assert_eq!(one_plus_one, "1 + 1");
621621
/// ```
622622
#[stable(feature = "rust1", since = "1.0.0")]
623-
#[macro_export]
623+
#[rustc_doc_only_macro]
624624
macro_rules! stringify { ($($t:tt)*) => ({ /* compiler built-in */ }) }
625625

626626
/// Includes a utf8-encoded file as a string.
@@ -654,7 +654,7 @@ pub mod builtin {
654654
///
655655
/// Compiling 'main.rs' and running the resulting binary will print "adiΓ³s".
656656
#[stable(feature = "rust1", since = "1.0.0")]
657-
#[macro_export]
657+
#[rustc_doc_only_macro]
658658
macro_rules! include_str {
659659
($file:expr) => ({ /* compiler built-in */ });
660660
($file:expr,) => ({ /* compiler built-in */ });
@@ -691,7 +691,7 @@ pub mod builtin {
691691
///
692692
/// Compiling 'main.rs' and running the resulting binary will print "adiΓ³s".
693693
#[stable(feature = "rust1", since = "1.0.0")]
694-
#[macro_export]
694+
#[rustc_doc_only_macro]
695695
macro_rules! include_bytes {
696696
($file:expr) => ({ /* compiler built-in */ });
697697
($file:expr,) => ({ /* compiler built-in */ });
@@ -715,7 +715,7 @@ pub mod builtin {
715715
/// test::foo();
716716
/// ```
717717
#[stable(feature = "rust1", since = "1.0.0")]
718-
#[macro_export]
718+
#[rustc_doc_only_macro]
719719
macro_rules! module_path { () => ({ /* compiler built-in */ }) }
720720

721721
/// Boolean evaluation of configuration flags, at compile-time.
@@ -737,7 +737,7 @@ pub mod builtin {
737737
/// };
738738
/// ```
739739
#[stable(feature = "rust1", since = "1.0.0")]
740-
#[macro_export]
740+
#[rustc_doc_only_macro]
741741
macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) }
742742

743743
/// Parse a file as an expression or an item according to the context.
@@ -780,7 +780,7 @@ pub mod builtin {
780780
/// Compiling 'main.rs' and running the resulting binary will print
781781
/// "πŸ™ˆπŸ™ŠπŸ™‰πŸ™ˆπŸ™ŠπŸ™‰".
782782
#[stable(feature = "rust1", since = "1.0.0")]
783-
#[macro_export]
783+
#[rustc_doc_only_macro]
784784
macro_rules! include {
785785
($file:expr) => ({ /* compiler built-in */ });
786786
($file:expr,) => ({ /* compiler built-in */ });
@@ -833,7 +833,7 @@ pub mod builtin {
833833
/// assert!(a + b == 30, "a = {}, b = {}", a, b);
834834
/// ```
835835
#[stable(feature = "rust1", since = "1.0.0")]
836-
#[macro_export]
836+
#[rustc_doc_only_macro]
837837
macro_rules! assert {
838838
($cond:expr) => ({ /* compiler built-in */ });
839839
($cond:expr,) => ({ /* compiler built-in */ });

β€Žsrc/libsyntax/feature_gate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,8 @@ pub fn deprecated_attributes() -> Vec<&'static (&'static str, AttributeType, Att
687687
}
688688

689689
pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
690-
BUILTIN_ATTRIBUTES.iter().any(|&(builtin_name, _, _)| attr.check_name(builtin_name))
690+
BUILTIN_ATTRIBUTES.iter().any(|&(builtin_name, _, _)| attr.check_name(builtin_name)) ||
691+
attr.name().as_str().starts_with("rustc_")
691692
}
692693

693694
// Attributes that have a special meaning to rustc or rustdoc

0 commit comments

Comments
Β (0)