Skip to content

Commit ced04ff

Browse files
Rollup merge of rust-lang#38457 - frewsxcv:include, r=GuillaumeGomez
Improvements to 'include' macro documentation. None
2 parents 74c42ac + 4a354ab commit ced04ff

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/libstd/macros.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,23 +458,38 @@ pub mod builtin {
458458

459459
/// Parse a file as an expression or an item according to the context.
460460
///
461-
/// The file is located relative to the current file. (similarly to how
462-
/// modules are found)
461+
/// The file is located relative to the current file (similarly to how
462+
/// modules are found).
463463
///
464464
/// Using this macro is often a bad idea, because if the file is
465465
/// parsed as an expression, it is going to be placed in the
466-
/// surrounding code unhygenically. This could result in variables
466+
/// surrounding code unhygienically. This could result in variables
467467
/// or functions being different from what the file expected if
468468
/// there are variables or functions that have the same name in
469469
/// the current file.
470470
///
471471
/// # Examples
472472
///
473+
/// Assume there are two files in the same directory with the following
474+
/// contents:
475+
///
476+
/// File 'my_str.in':
477+
///
473478
/// ```ignore
474-
/// fn foo() {
475-
/// include!("/path/to/a/file")
479+
/// "Hello World!"
480+
/// ```
481+
///
482+
/// File 'main.rs':
483+
///
484+
/// ```ignore
485+
/// fn main() {
486+
/// let my_str = include!("my_str.in");
487+
/// println!("{}", my_str);
476488
/// }
477489
/// ```
490+
///
491+
/// Compiling 'main.rs' and running the resulting binary will print "Hello
492+
/// World!".
478493
#[stable(feature = "rust1", since = "1.0.0")]
479494
#[macro_export]
480495
macro_rules! include { ($file:expr) => ({ /* compiler built-in */ }) }

0 commit comments

Comments
 (0)