2014-01-24 01:40:54 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
2014-02-16 23:40:26 -06:00
|
|
|
|
|
|
|
//! Standard library macros
|
|
|
|
//!
|
|
|
|
//! This modules contains a set of macros which are exported from the standard
|
|
|
|
//! library. Each macro is available for use when linking against the standard
|
|
|
|
//! library.
|
|
|
|
|
2015-01-22 20:22:03 -06:00
|
|
|
#![unstable(feature = "std_misc")]
|
2014-01-24 01:40:54 -06:00
|
|
|
|
2014-12-27 15:57:43 -06:00
|
|
|
/// The entry point for panic of Rust tasks.
|
|
|
|
///
|
|
|
|
/// This macro is used to inject panic into a Rust task, causing the task to
|
|
|
|
/// unwind and panic entirely. Each task's panic can be reaped as the
|
|
|
|
/// `Box<Any>` type, and the single-argument form of the `panic!` macro will be
|
|
|
|
/// the value which is transmitted.
|
|
|
|
///
|
|
|
|
/// The multi-argument form of this macro panics with a string and has the
|
|
|
|
/// `format!` syntax for building a string.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-12-27 15:57:43 -06:00
|
|
|
///
|
2015-03-26 15:30:33 -05:00
|
|
|
/// ```should_panic
|
2014-12-27 15:57:43 -06:00
|
|
|
/// # #![allow(unreachable_code)]
|
|
|
|
/// panic!();
|
|
|
|
/// panic!("this is a terrible mistake!");
|
2015-01-25 15:05:03 -06:00
|
|
|
/// panic!(4); // panic with the value of 4 to be collected elsewhere
|
2014-12-27 15:57:43 -06:00
|
|
|
/// panic!("this is a {} {message}", "fancy", message = "message");
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2015-01-23 23:48:20 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-04-08 17:48:46 -05:00
|
|
|
#[allow_internal_unstable]
|
2015-04-11 04:46:57 -05:00
|
|
|
/// The entry point for panic of Rust tasks.
|
|
|
|
///
|
|
|
|
/// This macro is used to inject panic into a Rust task, causing the task to
|
|
|
|
/// unwind and panic entirely. Each task's panic can be reaped as the
|
|
|
|
/// `Box<Any>` type, and the single-argument form of the `panic!` macro will be
|
|
|
|
/// the value which is transmitted.
|
|
|
|
///
|
|
|
|
/// The multi-argument form of this macro panics with a string and has the
|
|
|
|
/// `format!` syntax for building a string.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```should_panic
|
|
|
|
/// # #![allow(unreachable_code)]
|
|
|
|
/// panic!();
|
|
|
|
/// panic!("this is a terrible mistake!");
|
|
|
|
/// panic!(4); // panic with the value of 4 to be collected elsewhere
|
|
|
|
/// panic!("this is a {} {message}", "fancy", message = "message");
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
#[allow_internal_unstable]
|
|
|
|
macro_rules! panic {
|
|
|
|
() => ({
|
|
|
|
panic!("explicit panic")
|
|
|
|
});
|
|
|
|
($msg:expr) => ({
|
|
|
|
$crate::rt::begin_unwind($msg, {
|
|
|
|
// static requires less code at runtime, more constant data
|
|
|
|
static _FILE_LINE: (&'static str, u32) = (file!(), line!());
|
|
|
|
&_FILE_LINE
|
|
|
|
})
|
|
|
|
});
|
|
|
|
($fmt:expr, $($arg:tt)+) => ({
|
|
|
|
$crate::rt::begin_unwind_fmt(format_args!($fmt, $($arg)+), {
|
|
|
|
// The leading _'s are to avoid dead code warnings if this is
|
|
|
|
// used inside a dead function. Just `#[allow(dead_code)]` is
|
|
|
|
// insufficient, since the user may have
|
|
|
|
// `#[forbid(dead_code)]` and which cannot be overridden.
|
|
|
|
static _FILE_LINE: (&'static str, u32) = (file!(), line!());
|
2015-01-06 13:07:09 -06:00
|
|
|
&_FILE_LINE
|
|
|
|
})
|
2014-12-27 15:57:43 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-08 17:30:15 -05:00
|
|
|
/// Macro for printing to the standard output.
|
|
|
|
///
|
2014-12-27 15:57:43 -06:00
|
|
|
/// Equivalent to the `println!` macro except that a newline is not printed at
|
|
|
|
/// the end of the message.
|
2015-03-29 01:50:02 -05:00
|
|
|
///
|
|
|
|
/// Note that stdout is frequently line-buffered by default so it may be
|
|
|
|
/// necessary to use `io::stdout().flush()` to ensure the output is emitted
|
|
|
|
/// immediately.
|
2014-12-27 15:57:43 -06:00
|
|
|
#[macro_export]
|
2015-01-23 23:48:20 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-03-08 17:30:15 -05:00
|
|
|
#[allow_internal_unstable]
|
2014-12-27 15:57:43 -06:00
|
|
|
macro_rules! print {
|
2015-03-08 17:30:15 -05:00
|
|
|
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
|
2014-12-27 15:57:43 -06:00
|
|
|
}
|
|
|
|
|
2015-03-08 17:30:15 -05:00
|
|
|
/// Macro for printing to the standard output.
|
2014-12-27 15:57:43 -06:00
|
|
|
///
|
2015-03-08 17:30:15 -05:00
|
|
|
/// Use the `format!` syntax to write data to the standard output.
|
|
|
|
/// See `std::fmt` for more information.
|
2014-12-27 15:57:43 -06:00
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-12-27 15:57:43 -06:00
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// println!("hello there!");
|
|
|
|
/// println!("format {} arguments", "some");
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2015-01-23 23:48:20 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-12-27 15:57:43 -06:00
|
|
|
macro_rules! println {
|
2015-03-08 17:30:15 -05:00
|
|
|
($fmt:expr) => (print!(concat!($fmt, "\n")));
|
|
|
|
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
2014-12-27 15:57:43 -06:00
|
|
|
}
|
|
|
|
|
2014-02-16 23:40:26 -06:00
|
|
|
/// Helper macro for unwrapping `Result` values while returning early with an
|
2015-03-22 14:04:54 -05:00
|
|
|
/// error if the value of the expression is `Err`.
|
2014-01-29 18:33:57 -06:00
|
|
|
#[macro_export]
|
2015-01-23 23:48:20 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! try {
|
2015-01-06 13:07:09 -06:00
|
|
|
($expr:expr) => (match $expr {
|
|
|
|
$crate::result::Result::Ok(val) => val,
|
|
|
|
$crate::result::Result::Err(err) => {
|
2015-03-30 19:56:48 -05:00
|
|
|
return $crate::result::Result::Err($crate::convert::From::from(err))
|
2014-10-03 16:23:09 -05:00
|
|
|
}
|
|
|
|
})
|
2014-11-14 11:18:10 -06:00
|
|
|
}
|
2014-02-18 23:36:51 -06:00
|
|
|
|
2014-05-27 09:20:06 -05:00
|
|
|
/// A macro to select an event from a number of receivers.
|
2014-02-23 23:30:18 -06:00
|
|
|
///
|
|
|
|
/// This macro is used to wait for the first event to occur on a number of
|
2014-05-27 09:20:06 -05:00
|
|
|
/// receivers. It places no restrictions on the types of receivers given to
|
|
|
|
/// this macro, this can be viewed as a heterogeneous select.
|
2014-02-23 23:30:18 -06:00
|
|
|
///
|
2015-01-12 15:59:34 -06:00
|
|
|
/// # Examples
|
2014-02-23 23:30:18 -06:00
|
|
|
///
|
|
|
|
/// ```
|
2015-03-13 17:28:35 -05:00
|
|
|
/// # #![feature(std_misc)]
|
2015-02-17 17:10:25 -06:00
|
|
|
/// use std::thread;
|
2015-01-12 15:59:34 -06:00
|
|
|
/// use std::sync::mpsc;
|
|
|
|
///
|
|
|
|
/// // two placeholder functions for now
|
|
|
|
/// fn long_running_task() {}
|
|
|
|
/// fn calculate_the_answer() -> u32 { 42 }
|
2014-12-14 02:05:32 -06:00
|
|
|
///
|
2015-01-12 15:59:34 -06:00
|
|
|
/// let (tx1, rx1) = mpsc::channel();
|
|
|
|
/// let (tx2, rx2) = mpsc::channel();
|
2014-02-23 23:30:18 -06:00
|
|
|
///
|
2015-02-17 17:10:25 -06:00
|
|
|
/// thread::spawn(move|| { long_running_task(); tx1.send(()).unwrap(); });
|
|
|
|
/// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); });
|
2014-02-23 23:30:18 -06:00
|
|
|
///
|
2015-05-04 13:30:14 -05:00
|
|
|
/// select! {
|
2014-12-23 13:53:35 -06:00
|
|
|
/// _ = rx1.recv() => println!("the long running task finished first"),
|
2014-03-09 16:58:32 -05:00
|
|
|
/// answer = rx2.recv() => {
|
2014-12-23 13:53:35 -06:00
|
|
|
/// println!("the answer was: {}", answer.unwrap());
|
2014-02-23 23:30:18 -06:00
|
|
|
/// }
|
2015-05-04 13:30:14 -05:00
|
|
|
/// }
|
|
|
|
/// # drop(rx1.recv());
|
|
|
|
/// # drop(rx2.recv());
|
2014-02-23 23:30:18 -06:00
|
|
|
/// ```
|
|
|
|
///
|
2014-12-23 13:53:35 -06:00
|
|
|
/// For more information about select, see the `std::sync::mpsc::Select` structure.
|
2014-02-23 23:30:18 -06:00
|
|
|
#[macro_export]
|
2015-01-22 20:22:03 -06:00
|
|
|
#[unstable(feature = "std_misc")]
|
2014-02-23 23:30:18 -06:00
|
|
|
macro_rules! select {
|
|
|
|
(
|
2014-03-09 16:58:32 -05:00
|
|
|
$($name:pat = $rx:ident.$meth:ident() => $code:expr),+
|
2014-02-23 23:30:18 -06:00
|
|
|
) => ({
|
2014-09-15 21:29:47 -05:00
|
|
|
use $crate::sync::mpsc::Select;
|
2014-02-23 23:30:18 -06:00
|
|
|
let sel = Select::new();
|
2014-03-09 16:58:32 -05:00
|
|
|
$( let mut $rx = sel.handle(&$rx); )+
|
2014-02-23 23:30:18 -06:00
|
|
|
unsafe {
|
2014-03-09 16:58:32 -05:00
|
|
|
$( $rx.add(); )+
|
2014-02-23 23:30:18 -06:00
|
|
|
}
|
|
|
|
let ret = sel.wait();
|
2014-03-09 16:58:32 -05:00
|
|
|
$( if ret == $rx.id() { let $name = $rx.$meth(); $code } else )+
|
2014-02-23 23:30:18 -06:00
|
|
|
{ unreachable!() }
|
|
|
|
})
|
|
|
|
}
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
|
|
|
|
// When testing the standard library, we link to the liblog crate to get the
|
|
|
|
// logging macros. In doing so, the liblog crate was linked against the real
|
|
|
|
// version of libstd, and uses a different std::fmt module than the test crate
|
|
|
|
// uses. To get around this difference, we redefine the log!() macro here to be
|
|
|
|
// just a dumb version of what it should be.
|
|
|
|
#[cfg(test)]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! log {
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
($lvl:expr, $($args:tt)*) => (
|
|
|
|
if log_enabled!($lvl) { println!($($args)*) }
|
|
|
|
)
|
2014-11-14 11:18:10 -06:00
|
|
|
}
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// 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(dox)]
|
|
|
|
pub mod builtin {
|
|
|
|
/// The core macro for formatted string creation & output.
|
|
|
|
///
|
2014-12-27 15:57:43 -06:00
|
|
|
/// This macro produces a value of type `fmt::Arguments`. This value can be
|
|
|
|
/// passed to the functions in `std::fmt` for performing useful functions.
|
|
|
|
/// All other formatting macros (`format!`, `write!`, `println!`, etc) are
|
|
|
|
/// proxied through this one.
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// For more information, see the documentation in `std::fmt`.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
2015-03-12 21:42:38 -05:00
|
|
|
/// ```
|
2014-04-01 17:04:42 -05:00
|
|
|
/// use std::fmt;
|
|
|
|
///
|
2014-12-27 15:57:43 -06:00
|
|
|
/// let s = fmt::format(format_args!("hello {}", "world"));
|
2014-04-01 17:04:42 -05:00
|
|
|
/// assert_eq!(s, format!("hello {}", "world"));
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2015-01-06 18:16:35 -06:00
|
|
|
macro_rules! format_args { ($fmt:expr, $($args:tt)*) => ({
|
2014-04-01 17:04:42 -05:00
|
|
|
/* compiler built-in */
|
2014-11-14 11:18:10 -06:00
|
|
|
}) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// Inspect 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.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
2015-03-12 21:42:38 -05:00
|
|
|
/// ```
|
2014-09-16 15:51:01 -05:00
|
|
|
/// let path: &'static str = env!("PATH");
|
|
|
|
/// println!("the $PATH variable at the time of compiling was: {}", path);
|
2014-04-01 17:04:42 -05:00
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! env { ($name:expr) => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// Optionally inspect 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`.
|
|
|
|
///
|
|
|
|
/// A compile time error is never emitted when using this macro regardless
|
|
|
|
/// of whether the environment variable is present or not.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
2015-03-12 21:42:38 -05:00
|
|
|
/// ```
|
2014-04-01 17:04:42 -05:00
|
|
|
/// let key: Option<&'static str> = option_env!("SECRET_KEY");
|
2015-01-06 18:16:35 -06:00
|
|
|
/// println!("the secret key might be: {:?}", key);
|
2014-04-01 17:04:42 -05:00
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! option_env { ($name:expr) => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// Concatenate 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, and macros are only allowed in item,
|
|
|
|
/// statement or expression position, meaning this macro may be difficult to
|
|
|
|
/// use in some situations.
|
|
|
|
///
|
2015-01-12 15:59:34 -06:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```
|
2014-06-06 11:22:19 -05:00
|
|
|
/// #![feature(concat_idents)]
|
|
|
|
///
|
2015-01-17 12:58:54 -06:00
|
|
|
/// # fn main() {
|
2015-01-12 15:59:34 -06:00
|
|
|
/// fn foobar() -> u32 { 23 }
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// let f = concat_idents!(foo, bar);
|
|
|
|
/// println!("{}", f());
|
2015-01-17 12:58:54 -06:00
|
|
|
/// # }
|
2014-04-01 17:04:42 -05:00
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! concat_idents {
|
|
|
|
($($e:ident),*) => ({ /* compiler built-in */ })
|
|
|
|
}
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```
|
2015-01-25 15:05:03 -06:00
|
|
|
/// let s = concat!("test", 10, 'b', true);
|
2014-04-01 17:04:42 -05:00
|
|
|
/// assert_eq!(s, "test10btrue");
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! concat { ($($e:expr),*) => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// A macro which expands to the line number on which it was invoked.
|
|
|
|
///
|
2015-01-08 04:45:49 -06:00
|
|
|
/// The expanded expression has type `usize`, and the returned line is not
|
2014-04-01 17:04:42 -05:00
|
|
|
/// the invocation of the `line!()` macro itself, but rather the first macro
|
|
|
|
/// invocation leading up to the invocation of the `line!()` macro.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// let current_line = line!();
|
|
|
|
/// println!("defined on line: {}", current_line);
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! line { () => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// A macro which expands to the column number on which it was invoked.
|
|
|
|
///
|
2015-01-08 04:45:49 -06:00
|
|
|
/// The expanded expression has type `usize`, and the returned column is not
|
2014-11-18 06:03:58 -06:00
|
|
|
/// the invocation of the `column!()` macro itself, but rather the first macro
|
|
|
|
/// invocation leading up to the invocation of the `column!()` macro.
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```
|
2014-11-18 06:03:58 -06:00
|
|
|
/// let current_col = column!();
|
2014-04-01 17:04:42 -05:00
|
|
|
/// println!("defined on column: {}", current_col);
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! column { () => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// A macro which expands to the file name from which it was invoked.
|
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// let this_file = file!();
|
|
|
|
/// println!("defined in file: {}", this_file);
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! file { () => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// A macro which stringifies its argument.
|
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// let one_plus_one = stringify!(1 + 1);
|
|
|
|
/// assert_eq!(one_plus_one, "1 + 1");
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! stringify { ($t:tt) => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// Includes a utf8-encoded file as a string.
|
|
|
|
///
|
|
|
|
/// This macro will yield an expression of type `&'static str` which is the
|
|
|
|
/// contents of the filename specified. The file is located relative to the
|
|
|
|
/// current file (similarly to how modules are found),
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```rust,ignore
|
|
|
|
/// let secret_key = include_str!("secret-key.ascii");
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! include_str { ($file:expr) => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// Includes a file as a byte slice.
|
|
|
|
///
|
|
|
|
/// This macro will yield an expression of type `&'static [u8]` which is
|
|
|
|
/// the contents of the filename specified. The file is located relative to
|
|
|
|
/// the current file (similarly to how modules are found),
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
|
|
|
/// ```rust,ignore
|
2014-12-21 15:57:09 -06:00
|
|
|
/// let secret_key = include_bytes!("secret-key.bin");
|
2014-04-01 17:04:42 -05:00
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-12-21 15:57:09 -06:00
|
|
|
macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }
|
|
|
|
|
2014-04-01 17:04:42 -05:00
|
|
|
/// 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.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
2015-03-12 21:42:38 -05:00
|
|
|
/// ```
|
2014-04-01 17:04:42 -05:00
|
|
|
/// mod test {
|
|
|
|
/// pub fn foo() {
|
|
|
|
/// assert!(module_path!().ends_with("test"));
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// test::foo();
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! module_path { () => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
|
|
|
|
/// Boolean evaluation of configuration flags.
|
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
///
|
2015-03-11 20:11:40 -05:00
|
|
|
/// # Examples
|
2014-04-01 17:04:42 -05:00
|
|
|
///
|
2015-03-12 21:42:38 -05:00
|
|
|
/// ```
|
2014-04-01 17:04:42 -05:00
|
|
|
/// let my_directory = if cfg!(windows) {
|
|
|
|
/// "windows-specific-directory"
|
|
|
|
/// } else {
|
|
|
|
/// "unix-directory"
|
|
|
|
/// };
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
2014-11-14 11:18:10 -06:00
|
|
|
macro_rules! cfg { ($cfg:tt) => ({ /* compiler built-in */ }) }
|
2015-03-18 18:49:39 -05:00
|
|
|
|
|
|
|
/// Parse the current given file as an expression.
|
|
|
|
///
|
2015-05-04 12:21:27 -05:00
|
|
|
/// This is generally a bad idea, because it's going to behave unhygienically.
|
2015-03-18 18:49:39 -05:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```ignore
|
|
|
|
/// fn foo() {
|
|
|
|
/// include!("/path/to/a/file")
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! include { ($cfg:tt) => ({ /* compiler built-in */ }) }
|
2014-04-01 17:04:42 -05:00
|
|
|
}
|