Introduce built-in macros through libcore
This commit is contained in:
parent
4268e7ee22
commit
8eaf17bca2
46 changed files with 499 additions and 969 deletions
|
|
@ -254,8 +254,8 @@ impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync + 'a> {
|
||||
/// Converts a type of [`Error`] + [`Send`] + [`Sync`] into a box of dyn [`Error`] +
|
||||
/// [`Send`] + [`Sync`].
|
||||
/// Converts a type of [`Error`] + [`trait@Send`] + [`trait@Sync`] into a box of
|
||||
/// dyn [`Error`] + [`trait@Send`] + [`trait@Sync`].
|
||||
///
|
||||
/// [`Error`]: ../error/trait.Error.html
|
||||
///
|
||||
|
|
@ -298,7 +298,7 @@ impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync +
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl From<String> for Box<dyn Error + Send + Sync> {
|
||||
/// Converts a [`String`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
|
||||
/// Converts a [`String`] into a box of dyn [`Error`] + [`trait@Send`] + [`trait@Sync`].
|
||||
///
|
||||
/// [`Error`]: ../error/trait.Error.html
|
||||
///
|
||||
|
|
@ -362,7 +362,7 @@ impl From<String> for Box<dyn Error> {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
|
||||
/// Converts a [`str`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
|
||||
/// Converts a [`str`] into a box of dyn [`Error`] + [`trait@Send`] + [`trait@Sync`].
|
||||
///
|
||||
/// [`Error`]: ../error/trait.Error.html
|
||||
///
|
||||
|
|
@ -405,7 +405,7 @@ impl From<&str> for Box<dyn Error> {
|
|||
|
||||
#[stable(feature = "cow_box_error", since = "1.22.0")]
|
||||
impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a> {
|
||||
/// Converts a [`Cow`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
|
||||
/// Converts a [`Cow`] into a box of dyn [`Error`] + [`trait@Send`] + [`trait@Sync`].
|
||||
///
|
||||
/// [`Cow`]: ../borrow/enum.Cow.html
|
||||
/// [`Error`]: ../error/trait.Error.html
|
||||
|
|
|
|||
|
|
@ -221,14 +221,15 @@
|
|||
|
||||
#![cfg_attr(test, feature(print_internals, set_stdio, test, update_panic_count))]
|
||||
#![cfg_attr(all(target_vendor = "fortanix", target_env = "sgx"),
|
||||
feature(global_asm, slice_index_methods,
|
||||
decl_macro, coerce_unsized, sgx_platform, ptr_wrapping_offset_from))]
|
||||
feature(slice_index_methods, decl_macro, coerce_unsized,
|
||||
sgx_platform, ptr_wrapping_offset_from))]
|
||||
#![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"),
|
||||
feature(fixed_size_array, maybe_uninit_extra))]
|
||||
|
||||
// std is implemented with unstable features, many of which are internal
|
||||
// compiler details that will never be stable
|
||||
// NB: the following list is sorted to minimize merge conflicts.
|
||||
#![cfg_attr(not(bootstrap), feature(__rust_unstable_column))]
|
||||
#![feature(alloc_error_handler)]
|
||||
#![feature(alloc_layout_extra)]
|
||||
#![feature(allocator_api)]
|
||||
|
|
@ -251,6 +252,7 @@
|
|||
#![feature(const_cstr_unchecked)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![feature(doc_alias)]
|
||||
#![feature(doc_cfg)]
|
||||
#![feature(doc_keyword)]
|
||||
|
|
@ -262,7 +264,9 @@
|
|||
#![feature(exhaustive_patterns)]
|
||||
#![feature(external_doc)]
|
||||
#![feature(fn_traits)]
|
||||
#![feature(format_args_nl)]
|
||||
#![feature(generator_trait)]
|
||||
#![feature(global_asm)]
|
||||
#![feature(hash_raw_entry)]
|
||||
#![feature(hashmap_internals)]
|
||||
#![feature(int_error_internals)]
|
||||
|
|
@ -272,6 +276,7 @@
|
|||
#![feature(libc)]
|
||||
#![feature(link_args)]
|
||||
#![feature(linkage)]
|
||||
#![feature(log_syntax)]
|
||||
#![feature(maybe_uninit_ref)]
|
||||
#![feature(maybe_uninit_slice)]
|
||||
#![feature(mem_take)]
|
||||
|
|
@ -303,6 +308,7 @@
|
|||
#![feature(thread_local)]
|
||||
#![feature(todo_macro)]
|
||||
#![feature(toowned_clone_into)]
|
||||
#![feature(trace_macros)]
|
||||
#![feature(try_reserve)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(untagged_unions)]
|
||||
|
|
@ -510,6 +516,36 @@ mod std_detect;
|
|||
#[cfg(not(test))]
|
||||
pub use std_detect::detect;
|
||||
|
||||
// Document built-in macros in the crate root for consistency with libcore and existing tradition.
|
||||
// FIXME: Attribute and derive macros are not reexported because rustdoc renders them
|
||||
// as reexports rather than as macros, and that's not what we want.
|
||||
#[cfg(rustdoc)]
|
||||
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
|
||||
pub use crate::prelude::v1::{
|
||||
__rust_unstable_column,
|
||||
asm,
|
||||
assert,
|
||||
cfg,
|
||||
column,
|
||||
compile_error,
|
||||
concat,
|
||||
concat_idents,
|
||||
env,
|
||||
file,
|
||||
format_args,
|
||||
format_args_nl,
|
||||
global_asm,
|
||||
include,
|
||||
include_bytes,
|
||||
include_str,
|
||||
line,
|
||||
log_syntax,
|
||||
module_path,
|
||||
option_env,
|
||||
stringify,
|
||||
trace_macros,
|
||||
};
|
||||
|
||||
// Include a number of private modules that exist solely to provide
|
||||
// the rustdoc documentation for primitive types. Using `include!`
|
||||
// because rustdoc only looks for these modules at the crate level.
|
||||
|
|
|
|||
|
|
@ -365,534 +365,3 @@ macro_rules! assert_approx_eq {
|
|||
"{} is not approximately equal to {}", *a, *b);
|
||||
})
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[cfg(rustdoc)]
|
||||
mod builtin {
|
||||
|
||||
/// Causes compilation to fail with the given error message when encountered.
|
||||
///
|
||||
/// This macro should be used when a crate uses a conditional compilation strategy to provide
|
||||
/// better error messages for erroneous conditions. It's the compiler-level form of [`panic!`],
|
||||
/// which emits an error at *runtime*, rather than during compilation.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Two such examples are macros and `#[cfg]` environments.
|
||||
///
|
||||
/// Emit better compiler error if a macro is passed invalid values. Without the final branch,
|
||||
/// the compiler would still emit an error, but the error's message would not mention the two
|
||||
/// valid values.
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// macro_rules! give_me_foo_or_bar {
|
||||
/// (foo) => {};
|
||||
/// (bar) => {};
|
||||
/// ($x:ident) => {
|
||||
/// compile_error!("This macro only accepts `foo` or `bar`");
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// give_me_foo_or_bar!(neither);
|
||||
/// // ^ will fail at compile time with message "This macro only accepts `foo` or `bar`"
|
||||
/// ```
|
||||
///
|
||||
/// Emit compiler error if one of a number of features isn't available.
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// #[cfg(not(any(feature = "foo", feature = "bar")))]
|
||||
/// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.");
|
||||
/// ```
|
||||
///
|
||||
/// [`panic!`]: ../std/macro.panic.html
|
||||
#[stable(feature = "compile_error_macro", since = "1.20.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! compile_error {
|
||||
($msg:expr) => ({ /* compiler built-in */ });
|
||||
($msg:expr,) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Constructs parameters for the other string-formatting macros.
|
||||
///
|
||||
/// This macro functions by taking a formatting string literal containing
|
||||
/// `{}` for each additional argument passed. `format_args!` prepares the
|
||||
/// additional parameters to ensure the output can be interpreted as a string
|
||||
/// and canonicalizes the arguments into a single type. Any value that implements
|
||||
/// the [`Display`] trait can be passed to `format_args!`, as can any
|
||||
/// [`Debug`] implementation be passed to a `{:?}` within the formatting string.
|
||||
///
|
||||
/// This macro produces a value of type [`fmt::Arguments`]. This value can be
|
||||
/// passed to the macros within [`std::fmt`] for performing useful redirection.
|
||||
/// All other formatting macros ([`format!`], [`write!`], [`println!`], etc) are
|
||||
/// proxied through this one. `format_args!`, unlike its derived macros, avoids
|
||||
/// heap allocations.
|
||||
///
|
||||
/// You can use the [`fmt::Arguments`] value that `format_args!` returns
|
||||
/// in `Debug` and `Display` contexts as seen below. The example also shows
|
||||
/// that `Debug` and `Display` format to the same thing: the interpolated
|
||||
/// format string in `format_args!`.
|
||||
///
|
||||
/// ```rust
|
||||
/// let debug = format!("{:?}", format_args!("{} foo {:?}", 1, 2));
|
||||
/// let display = format!("{}", format_args!("{} foo {:?}", 1, 2));
|
||||
/// assert_eq!("1 foo 2", display);
|
||||
/// assert_eq!(display, debug);
|
||||
/// ```
|
||||
///
|
||||
/// For more information, see the documentation in [`std::fmt`].
|
||||
///
|
||||
/// [`Display`]: ../std/fmt/trait.Display.html
|
||||
/// [`Debug`]: ../std/fmt/trait.Debug.html
|
||||
/// [`fmt::Arguments`]: ../std/fmt/struct.Arguments.html
|
||||
/// [`std::fmt`]: ../std/fmt/index.html
|
||||
/// [`format!`]: ../std/macro.format.html
|
||||
/// [`write!`]: ../std/macro.write.html
|
||||
/// [`println!`]: ../std/macro.println.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::fmt;
|
||||
///
|
||||
/// let s = fmt::format(format_args!("hello {}", "world"));
|
||||
/// assert_eq!(s, format!("hello {}", "world"));
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! format_args {
|
||||
($fmt:expr) => ({ /* compiler built-in */ });
|
||||
($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Inspects an environment variable at compile time.
|
||||
///
|
||||
/// This macro will expand to the value of the named environment variable at
|
||||
/// compile time, yielding an expression of type `&'static str`.
|
||||
///
|
||||
/// If the environment variable is not defined, then a compilation error
|
||||
/// will be emitted. To not emit a compile error, use the [`option_env!`]
|
||||
/// macro instead.
|
||||
///
|
||||
/// [`option_env!`]: ../std/macro.option_env.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let path: &'static str = env!("PATH");
|
||||
/// println!("the $PATH variable at the time of compiling was: {}", path);
|
||||
/// ```
|
||||
///
|
||||
/// You can customize the error message by passing a string as the second
|
||||
/// parameter:
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// let doc: &'static str = env!("documentation", "what's that?!");
|
||||
/// ```
|
||||
///
|
||||
/// If the `documentation` environment variable is not defined, you'll get
|
||||
/// the following error:
|
||||
///
|
||||
/// ```text
|
||||
/// error: what's that?!
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! env {
|
||||
($name:expr) => ({ /* compiler built-in */ });
|
||||
($name:expr,) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Optionally inspects an environment variable at compile time.
|
||||
///
|
||||
/// If the named environment variable is present at compile time, this will
|
||||
/// expand into an expression of type `Option<&'static str>` whose value is
|
||||
/// `Some` of the value of the environment variable. If the environment
|
||||
/// variable is not present, then this will expand to `None`. See
|
||||
/// [`Option<T>`][option] for more information on this type.
|
||||
///
|
||||
/// A compile time error is never emitted when using this macro regardless
|
||||
/// of whether the environment variable is present or not.
|
||||
///
|
||||
/// [option]: ../std/option/enum.Option.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let key: Option<&'static str> = option_env!("SECRET_KEY");
|
||||
/// println!("the secret key might be: {:?}", key);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! option_env {
|
||||
($name:expr) => ({ /* compiler built-in */ });
|
||||
($name:expr,) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Concatenates identifiers into one identifier.
|
||||
///
|
||||
/// This macro takes any number of comma-separated identifiers, and
|
||||
/// concatenates them all into one, yielding an expression which is a new
|
||||
/// identifier. Note that hygiene makes it such that this macro cannot
|
||||
/// capture local variables. Also, as a general rule, macros are only
|
||||
/// allowed in item, statement or expression position. That means while
|
||||
/// you may use this macro for referring to existing variables, functions or
|
||||
/// modules etc, you cannot define a new one with it.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(concat_idents)]
|
||||
///
|
||||
/// # fn main() {
|
||||
/// fn foobar() -> u32 { 23 }
|
||||
///
|
||||
/// let f = concat_idents!(foo, bar);
|
||||
/// println!("{}", f());
|
||||
///
|
||||
/// // fn concat_idents!(new, fun, name) { } // not usable in this way!
|
||||
/// # }
|
||||
/// ```
|
||||
#[unstable(feature = "concat_idents_macro", issue = "29599")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! concat_idents {
|
||||
($($e:ident),+) => ({ /* compiler built-in */ });
|
||||
($($e:ident,)+) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Concatenates literals into a static string slice.
|
||||
///
|
||||
/// This macro takes any number of comma-separated literals, yielding an
|
||||
/// expression of type `&'static str` which represents all of the literals
|
||||
/// concatenated left-to-right.
|
||||
///
|
||||
/// Integer and floating point literals are stringified in order to be
|
||||
/// concatenated.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let s = concat!("test", 10, 'b', true);
|
||||
/// assert_eq!(s, "test10btrue");
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! concat {
|
||||
($($e:expr),*) => ({ /* compiler built-in */ });
|
||||
($($e:expr,)*) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Expands to the line number on which it was invoked.
|
||||
///
|
||||
/// With [`column!`] and [`file!`], these macros provide debugging information for
|
||||
/// developers about the location within the source.
|
||||
///
|
||||
/// The expanded expression has type `u32` and is 1-based, so the first line
|
||||
/// in each file evaluates to 1, the second to 2, etc. This is consistent
|
||||
/// with error messages by common compilers or popular editors.
|
||||
/// The returned line is *not necessarily* the line of the `line!` invocation itself,
|
||||
/// but rather the first macro invocation leading up to the invocation
|
||||
/// of the `line!` macro.
|
||||
///
|
||||
/// [`column!`]: macro.column.html
|
||||
/// [`file!`]: macro.file.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let current_line = line!();
|
||||
/// println!("defined on line: {}", current_line);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! line { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Expands to the column number at which it was invoked.
|
||||
///
|
||||
/// With [`line!`] and [`file!`], these macros provide debugging information for
|
||||
/// developers about the location within the source.
|
||||
///
|
||||
/// The expanded expression has type `u32` and is 1-based, so the first column
|
||||
/// in each line evaluates to 1, the second to 2, etc. This is consistent
|
||||
/// with error messages by common compilers or popular editors.
|
||||
/// The returned column is *not necessarily* the line of the `column!` invocation itself,
|
||||
/// but rather the first macro invocation leading up to the invocation
|
||||
/// of the `column!` macro.
|
||||
///
|
||||
/// [`line!`]: macro.line.html
|
||||
/// [`file!`]: macro.file.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let current_col = column!();
|
||||
/// println!("defined on column: {}", current_col);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! column { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Expands to the file name in which it was invoked.
|
||||
///
|
||||
/// With [`line!`] and [`column!`], these macros provide debugging information for
|
||||
/// developers about the location within the source.
|
||||
///
|
||||
///
|
||||
/// The expanded expression has type `&'static str`, and the returned file
|
||||
/// is not the invocation of the `file!` macro itself, but rather the
|
||||
/// first macro invocation leading up to the invocation of the `file!`
|
||||
/// macro.
|
||||
///
|
||||
/// [`line!`]: macro.line.html
|
||||
/// [`column!`]: macro.column.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let this_file = file!();
|
||||
/// println!("defined in file: {}", this_file);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! file { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Stringifies its arguments.
|
||||
///
|
||||
/// This macro will yield an expression of type `&'static str` which is the
|
||||
/// stringification of all the tokens passed to the macro. No restrictions
|
||||
/// are placed on the syntax of the macro invocation itself.
|
||||
///
|
||||
/// Note that the expanded results of the input tokens may change in the
|
||||
/// future. You should be careful if you rely on the output.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let one_plus_one = stringify!(1 + 1);
|
||||
/// assert_eq!(one_plus_one, "1 + 1");
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! stringify { ($($t:tt)*) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Includes a utf8-encoded file as a string.
|
||||
///
|
||||
/// The file is located relative to the current file. (similarly to how
|
||||
/// modules are found)
|
||||
///
|
||||
/// This macro will yield an expression of type `&'static str` which is the
|
||||
/// contents of the file.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Assume there are two files in the same directory with the following
|
||||
/// contents:
|
||||
///
|
||||
/// File 'spanish.in':
|
||||
///
|
||||
/// ```text
|
||||
/// adiós
|
||||
/// ```
|
||||
///
|
||||
/// File 'main.rs':
|
||||
///
|
||||
/// ```ignore (cannot-doctest-external-file-dependency)
|
||||
/// fn main() {
|
||||
/// let my_str = include_str!("spanish.in");
|
||||
/// assert_eq!(my_str, "adiós\n");
|
||||
/// print!("{}", my_str);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Compiling 'main.rs' and running the resulting binary will print "adiós".
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! include_str {
|
||||
($file:expr) => ({ /* compiler built-in */ });
|
||||
($file:expr,) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Includes a file as a reference to a byte array.
|
||||
///
|
||||
/// The file is located relative to the current file. (similarly to how
|
||||
/// modules are found)
|
||||
///
|
||||
/// This macro will yield an expression of type `&'static [u8; N]` which is
|
||||
/// the contents of the file.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Assume there are two files in the same directory with the following
|
||||
/// contents:
|
||||
///
|
||||
/// File 'spanish.in':
|
||||
///
|
||||
/// ```text
|
||||
/// adiós
|
||||
/// ```
|
||||
///
|
||||
/// File 'main.rs':
|
||||
///
|
||||
/// ```ignore (cannot-doctest-external-file-dependency)
|
||||
/// fn main() {
|
||||
/// let bytes = include_bytes!("spanish.in");
|
||||
/// assert_eq!(bytes, b"adi\xc3\xb3s\n");
|
||||
/// print!("{}", String::from_utf8_lossy(bytes));
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Compiling 'main.rs' and running the resulting binary will print "adiós".
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! include_bytes {
|
||||
($file:expr) => ({ /* compiler built-in */ });
|
||||
($file:expr,) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Expands to a string that represents the current module path.
|
||||
///
|
||||
/// The current module path can be thought of as the hierarchy of modules
|
||||
/// leading back up to the crate root. The first component of the path
|
||||
/// returned is the name of the crate currently being compiled.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// mod test {
|
||||
/// pub fn foo() {
|
||||
/// assert!(module_path!().ends_with("test"));
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// test::foo();
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! module_path { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Evaluates boolean combinations of configuration flags at compile-time.
|
||||
///
|
||||
/// In addition to the `#[cfg]` attribute, this macro is provided to allow
|
||||
/// boolean expression evaluation of configuration flags. This frequently
|
||||
/// leads to less duplicated code.
|
||||
///
|
||||
/// The syntax given to this macro is the same syntax as the [`cfg`]
|
||||
/// attribute.
|
||||
///
|
||||
/// [`cfg`]: ../reference/conditional-compilation.html#the-cfg-attribute
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let my_directory = if cfg!(windows) {
|
||||
/// "windows-specific-directory"
|
||||
/// } else {
|
||||
/// "unix-directory"
|
||||
/// };
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Parses a file as an expression or an item according to the context.
|
||||
///
|
||||
/// The file is located relative to the current file (similarly to how
|
||||
/// modules are found).
|
||||
///
|
||||
/// Using this macro is often a bad idea, because if the file is
|
||||
/// parsed as an expression, it is going to be placed in the
|
||||
/// surrounding code unhygienically. This could result in variables
|
||||
/// or functions being different from what the file expected if
|
||||
/// there are variables or functions that have the same name in
|
||||
/// the current file.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Assume there are two files in the same directory with the following
|
||||
/// contents:
|
||||
///
|
||||
/// File 'monkeys.in':
|
||||
///
|
||||
/// ```ignore (only-for-syntax-highlight)
|
||||
/// ['🙈', '🙊', '🙉']
|
||||
/// .iter()
|
||||
/// .cycle()
|
||||
/// .take(6)
|
||||
/// .collect::<String>()
|
||||
/// ```
|
||||
///
|
||||
/// File 'main.rs':
|
||||
///
|
||||
/// ```ignore (cannot-doctest-external-file-dependency)
|
||||
/// fn main() {
|
||||
/// let my_string = include!("monkeys.in");
|
||||
/// assert_eq!("🙈🙊🙉🙈🙊🙉", my_string);
|
||||
/// println!("{}", my_string);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Compiling 'main.rs' and running the resulting binary will print
|
||||
/// "🙈🙊🙉🙈🙊🙉".
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! include {
|
||||
($file:expr) => ({ /* compiler built-in */ });
|
||||
($file:expr,) => ({ /* compiler built-in */ });
|
||||
}
|
||||
|
||||
/// Asserts that a boolean expression is `true` at runtime.
|
||||
///
|
||||
/// This will invoke the [`panic!`] macro if the provided expression cannot be
|
||||
/// evaluated to `true` at runtime.
|
||||
///
|
||||
/// # Uses
|
||||
///
|
||||
/// Assertions are always checked in both debug and release builds, and cannot
|
||||
/// be disabled. See [`debug_assert!`] for assertions that are not enabled in
|
||||
/// release builds by default.
|
||||
///
|
||||
/// Unsafe code relies on `assert!` to enforce run-time invariants that, if
|
||||
/// violated could lead to unsafety.
|
||||
///
|
||||
/// Other use-cases of `assert!` include testing and enforcing run-time
|
||||
/// invariants in safe code (whose violation cannot result in unsafety).
|
||||
///
|
||||
/// # Custom Messages
|
||||
///
|
||||
/// This macro has a second form, where a custom panic message can
|
||||
/// be provided with or without arguments for formatting. See [`std::fmt`]
|
||||
/// for syntax for this form.
|
||||
///
|
||||
/// [`panic!`]: macro.panic.html
|
||||
/// [`debug_assert!`]: macro.debug_assert.html
|
||||
/// [`std::fmt`]: ../std/fmt/index.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// // the panic message for these assertions is the stringified value of the
|
||||
/// // expression given.
|
||||
/// assert!(true);
|
||||
///
|
||||
/// fn some_computation() -> bool { true } // a very simple function
|
||||
///
|
||||
/// assert!(some_computation());
|
||||
///
|
||||
/// // assert with a custom message
|
||||
/// let x = true;
|
||||
/// assert!(x, "x wasn't true!");
|
||||
///
|
||||
/// let a = 3; let b = 27;
|
||||
/// assert!(a + b == 30, "a = {}, b = {}", a, b);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! assert {
|
||||
($cond:expr) => ({ /* compiler built-in */ });
|
||||
($cond:expr,) => ({ /* compiler built-in */ });
|
||||
($cond:expr, $($arg:tt)+) => ({ /* compiler built-in */ });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,13 @@
|
|||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
// Re-exported core operators
|
||||
#[cfg(bootstrap)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::marker::{Copy, Send, Sized, Sync, Unpin};
|
||||
pub use crate::marker::Copy;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::marker::{Send, Sized, Sync, Unpin};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::ops::{Drop, Fn, FnMut, FnOnce};
|
||||
|
|
@ -20,15 +24,18 @@ pub use crate::ops::{Drop, Fn, FnMut, FnOnce};
|
|||
pub use crate::mem::drop;
|
||||
|
||||
// Re-exported types and traits
|
||||
#[cfg(bootstrap)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::clone::Clone;
|
||||
#[cfg(bootstrap)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::cmp::{PartialEq, PartialOrd, Eq, Ord};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::convert::{AsRef, AsMut, Into, From};
|
||||
#[cfg(bootstrap)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::default::Default;
|
||||
|
|
@ -45,6 +52,60 @@ pub use crate::option::Option::{self, Some, None};
|
|||
#[doc(no_inline)]
|
||||
pub use crate::result::Result::{self, Ok, Err};
|
||||
|
||||
// Re-exported built-in macros
|
||||
#[cfg(not(bootstrap))]
|
||||
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
|
||||
#[doc(no_inline)]
|
||||
pub use core::prelude::v1::{
|
||||
__rust_unstable_column,
|
||||
asm,
|
||||
assert,
|
||||
cfg,
|
||||
column,
|
||||
compile_error,
|
||||
concat,
|
||||
concat_idents,
|
||||
env,
|
||||
file,
|
||||
format_args,
|
||||
format_args_nl,
|
||||
global_asm,
|
||||
include,
|
||||
include_bytes,
|
||||
include_str,
|
||||
line,
|
||||
log_syntax,
|
||||
module_path,
|
||||
option_env,
|
||||
stringify,
|
||||
trace_macros,
|
||||
};
|
||||
|
||||
// FIXME: Attribute and derive macros are not documented because for them rustdoc generates
|
||||
// dead links which fail link checker testing.
|
||||
#[cfg(not(bootstrap))]
|
||||
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
|
||||
#[allow(deprecated)]
|
||||
#[doc(hidden)]
|
||||
pub use core::prelude::v1::{
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Decodable,
|
||||
Default,
|
||||
Encodable,
|
||||
Eq,
|
||||
Hash,
|
||||
Ord,
|
||||
PartialEq,
|
||||
PartialOrd,
|
||||
RustcDecodable,
|
||||
RustcEncodable,
|
||||
bench,
|
||||
global_allocator,
|
||||
test,
|
||||
test_case,
|
||||
};
|
||||
|
||||
// The file so far is equivalent to src/libcore/prelude/v1.rs,
|
||||
// and below to src/liballoc/prelude.rs.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue