Skip to content

Commit 87af232

Browse files
authored
Auto merge of #37325 - newpavlov:master, r=frewsxcv
libcore documentation for builtin macros Fixes: #36272 Additionally I've edited docstring for `include!` a bit. (related PR #36404) Unfortunately it seems there is no sane way to reexport empty macros definitions for their docstrings. To avoid copying the whole documentation for builtin macros I've only copied description and added links to `std` macro pages.
2 parents 40f79ba + 34576da commit 87af232

File tree

2 files changed

+152
-7
lines changed

2 files changed

+152
-7
lines changed

src/libcore/macros.rs

+140
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,143 @@ macro_rules! unreachable {
509509
macro_rules! unimplemented {
510510
() => (panic!("not yet implemented"))
511511
}
512+
513+
/// Built-in macros to the compiler itself.
514+
///
515+
/// These macros do not have any corresponding definition with a `macro_rules!`
516+
/// macro, but are documented here. Their implementations can be found hardcoded
517+
/// into libsyntax itself.
518+
///
519+
/// For more information, see documentation for `std`'s macros.
520+
#[cfg(dox)]
521+
pub mod builtin {
522+
/// The core macro for formatted string creation & output.
523+
///
524+
/// For more information, see the documentation for [`std::format_args!`].
525+
///
526+
/// [`std::format_args!`]: ../std/macro.format_args.html
527+
#[stable(feature = "rust1", since = "1.0.0")]
528+
#[macro_export]
529+
macro_rules! format_args { ($fmt:expr, $($args:tt)*) => ({
530+
/* compiler built-in */
531+
}) }
532+
533+
/// Inspect an environment variable at compile time.
534+
///
535+
/// For more information, see the documentation for [`std::env!`].
536+
///
537+
/// [`std::env!`]: ../std/macro.env.html
538+
#[stable(feature = "rust1", since = "1.0.0")]
539+
#[macro_export]
540+
macro_rules! env { ($name:expr) => ({ /* compiler built-in */ }) }
541+
542+
/// Optionally inspect an environment variable at compile time.
543+
///
544+
/// For more information, see the documentation for [`std::option_env!`].
545+
///
546+
/// [`std::option_env!`]: ../std/macro.option_env.html
547+
#[stable(feature = "rust1", since = "1.0.0")]
548+
#[macro_export]
549+
macro_rules! option_env { ($name:expr) => ({ /* compiler built-in */ }) }
550+
551+
/// Concatenate identifiers into one identifier.
552+
///
553+
/// For more information, see the documentation for [`std::concat_idents!`].
554+
///
555+
/// [`std::concat_idents!`]: ../std/macro.concat_idents.html
556+
#[unstable(feature = "concat_idents", issue = "29599")]
557+
#[macro_export]
558+
macro_rules! concat_idents {
559+
($($e:ident),*) => ({ /* compiler built-in */ })
560+
}
561+
562+
/// Concatenates literals into a static string slice.
563+
///
564+
/// For more information, see the documentation for [`std::concat!`].
565+
///
566+
/// [`std::concat!`]: ../std/macro.concat.html
567+
#[stable(feature = "rust1", since = "1.0.0")]
568+
#[macro_export]
569+
macro_rules! concat { ($($e:expr),*) => ({ /* compiler built-in */ }) }
570+
571+
/// A macro which expands to the line number on which it was invoked.
572+
///
573+
/// For more information, see the documentation for [`std::line!`].
574+
///
575+
/// [`std::line!`]: ../std/macro.line.html
576+
#[stable(feature = "rust1", since = "1.0.0")]
577+
#[macro_export]
578+
macro_rules! line { () => ({ /* compiler built-in */ }) }
579+
580+
/// A macro which expands to the column number on which it was invoked.
581+
///
582+
/// For more information, see the documentation for [`std::column!`].
583+
///
584+
/// [`std::column!`]: ../std/macro.column.html
585+
#[stable(feature = "rust1", since = "1.0.0")]
586+
#[macro_export]
587+
macro_rules! column { () => ({ /* compiler built-in */ }) }
588+
589+
/// A macro which expands to the file name from which it was invoked.
590+
///
591+
/// For more information, see the documentation for [`std::file!`].
592+
///
593+
/// [`std::file!`]: ../std/macro.file.html
594+
#[stable(feature = "rust1", since = "1.0.0")]
595+
#[macro_export]
596+
macro_rules! file { () => ({ /* compiler built-in */ }) }
597+
598+
/// A macro which stringifies its argument.
599+
///
600+
/// For more information, see the documentation for [`std::stringify!`].
601+
///
602+
/// [`std::stringify!`]: ../std/macro.stringify.html
603+
#[stable(feature = "rust1", since = "1.0.0")]
604+
#[macro_export]
605+
macro_rules! stringify { ($t:tt) => ({ /* compiler built-in */ }) }
606+
607+
/// Includes a utf8-encoded file as a string.
608+
///
609+
/// For more information, see the documentation for [`std::include_str!`].
610+
///
611+
/// [`std::include_str!`]: ../std/macro.include_str.html
612+
#[stable(feature = "rust1", since = "1.0.0")]
613+
#[macro_export]
614+
macro_rules! include_str { ($file:expr) => ({ /* compiler built-in */ }) }
615+
616+
/// Includes a file as a reference to a byte array.
617+
///
618+
/// For more information, see the documentation for [`std::include_bytes!`].
619+
///
620+
/// [`std::include_bytes!`]: ../std/macro.include_bytes.html
621+
#[stable(feature = "rust1", since = "1.0.0")]
622+
#[macro_export]
623+
macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }
624+
625+
/// Expands to a string that represents the current module path.
626+
///
627+
/// For more information, see the documentation for [`std::module_path!`].
628+
///
629+
/// [`std::module_path!`]: ../std/macro.module_path.html
630+
#[stable(feature = "rust1", since = "1.0.0")]
631+
#[macro_export]
632+
macro_rules! module_path { () => ({ /* compiler built-in */ }) }
633+
634+
/// Boolean evaluation of configuration flags.
635+
///
636+
/// For more information, see the documentation for [`std::cfg!`].
637+
///
638+
/// [`std::cfg!`]: ../std/macro.cfg.html
639+
#[stable(feature = "rust1", since = "1.0.0")]
640+
#[macro_export]
641+
macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) }
642+
643+
/// Parse a file as an expression or an item according to the context.
644+
///
645+
/// For more information, see the documentation for [`std::include!`].
646+
///
647+
/// [`std::include!`]: ../std/macro.include.html
648+
#[stable(feature = "rust1", since = "1.0.0")]
649+
#[macro_export]
650+
macro_rules! include { ($file:expr) => ({ /* compiler built-in */ }) }
651+
}

src/libstd/macros.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,11 @@ pub mod builtin {
381381

382382
/// Includes a utf8-encoded file as a string.
383383
///
384+
/// The file is located relative to the current file. (similarly to how
385+
/// modules are found)
386+
///
384387
/// This macro will yield an expression of type `&'static str` which is the
385-
/// contents of the filename specified. The file is located relative to the
386-
/// current file (similarly to how modules are found),
388+
/// contents of the file.
387389
///
388390
/// # Examples
389391
///
@@ -396,9 +398,11 @@ pub mod builtin {
396398

397399
/// Includes a file as a reference to a byte array.
398400
///
401+
/// The file is located relative to the current file. (similarly to how
402+
/// modules are found)
403+
///
399404
/// This macro will yield an expression of type `&'static [u8; N]` which is
400-
/// the contents of the filename specified. The file is located relative to
401-
/// the current file (similarly to how modules are found),
405+
/// the contents of the file.
402406
///
403407
/// # Examples
404408
///
@@ -452,9 +456,10 @@ pub mod builtin {
452456
#[macro_export]
453457
macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) }
454458

455-
/// Parse the file provided in the argument as an expression or an
456-
/// item according to the context. This file is located relative
457-
/// to the current file (similarly to how modules are found).
459+
/// Parse a file as an expression or an item according to the context.
460+
///
461+
/// The file is located relative to the current file. (similarly to how
462+
/// modules are found)
458463
///
459464
/// Using this macro is often a bad idea, because if the file is
460465
/// parsed as an expression, it is going to be placed in the

0 commit comments

Comments
 (0)