@@ -1312,46 +1312,70 @@ pub(crate) mod builtin {
1312
1312
/* compiler built-in */
1313
1313
} ;
1314
1314
}
1315
-
1315
+
1316
1316
/// Parses a file as an expression or an item according to the context.
1317
1317
///
1318
- /// The file is located relative to the current file (similarly to how
1319
- /// modules are found). The provided path is interpreted in a platform-specific
1320
- /// way at compile time. So, for instance, an invocation with a Windows path
1321
- /// containing backslashes `\` would not compile correctly on Unix.
1322
- ///
1323
- /// Using this macro is often a bad idea, because if the file is
1324
- /// parsed as an expression, it is going to be placed in the
1325
- /// surrounding code unhygienically. This could result in variables
1326
- /// or functions being different from what the file expected if
1327
- /// there are variables or functions that have the same name in
1328
- /// the current file.
1318
+ /// <div class="example-wrap" style="display:inline-block">
1319
+ /// <pre class="compile_fail" style="white-space:normal;font:inherit;">
1320
+ ///
1321
+ /// **Warning**: For multi-file Rust projects, the `include!` macro is probably not what you
1322
+ /// are looking for. Usually, multi-file Rust projects use
1323
+ /// [modules](https://doc.rust-lang.org/reference/items/modules.html). Multi-file projects and
1324
+ /// modules are explained in the Rust-by-Example book
1325
+ /// [here](https://doc.rust-lang.org/rust-by-example/mod/split.html) and the module system is
1326
+ /// explained in the Rust Book
1327
+ /// [here](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html).
1328
+ ///
1329
+ /// </pre>
1330
+ /// </div>
1331
+ ///
1332
+ /// If the included file is parsed as an expression, it is placed in the surrounding code
1333
+ /// [unhygienically](https://doc.rust-lang.org/reference/macros-by-example.html#hygiene). This
1334
+ /// could result in variables or functions being different from what the file expected if there
1335
+ /// are variables or functions that have the same name in the current file.
1336
+ ///
1337
+ /// The included file is located relative to the current file (similarly to how modules are
1338
+ /// found). The provided path is interpreted in a platform-specific way at compile time. So,
1339
+ /// for instance, an invocation with a Windows path containing backslashes `\` would not
1340
+ /// compile correctly on Unix.
1329
1341
///
1342
+ /// # Uses
1343
+ ///
1344
+ /// The `include!` macro is primarily used for two purposes. It is used to include
1345
+ /// documentation that is written in a separate file and it is used to include [build artifacts
1346
+ /// usually as a result from the `build.rs`
1347
+ /// script](https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script).
1348
+ ///
1349
+ /// When using the `include` macro to include stretches of documentation, remember that the
1350
+ /// included file still needs to be a valid rust syntax. It is also possible to
1351
+ /// use the [`include_str`] macro as `#![doc = include_str!("...")]` (at the module level) or
1352
+ /// `#[doc = include_str!("...")]` (at the item level) to include documentation from a plain
1353
+ /// text or markdown file.
1354
+ ///
1330
1355
/// # Examples
1331
- ///
1332
- /// Assume there are two files in the same directory with the following
1333
- /// contents:
1334
- ///
1356
+ ///
1357
+ /// Assume there are two files in the same directory with the following contents:
1358
+ ///
1335
1359
/// File 'monkeys.in':
1336
- ///
1360
+ ///
1337
1361
/// ```ignore (only-for-syntax-highlight)
1338
1362
/// ['🙈', '🙊', '🙉']
1339
1363
/// .iter()
1340
1364
/// .cycle()
1341
1365
/// .take(6)
1342
1366
/// .collect::<String>()
1343
1367
/// ```
1344
- ///
1368
+ ///
1345
1369
/// File 'main.rs':
1346
- ///
1370
+ ///
1347
1371
/// ```ignore (cannot-doctest-external-file-dependency)
1348
1372
/// fn main() {
1349
1373
/// let my_string = include!("monkeys.in");
1350
1374
/// assert_eq!("🙈🙊🙉🙈🙊🙉", my_string);
1351
1375
/// println!("{my_string}");
1352
1376
/// }
1353
1377
/// ```
1354
- ///
1378
+ ///
1355
1379
/// Compiling 'main.rs' and running the resulting binary will print
1356
1380
/// "🙈🙊🙉🙈🙊🙉".
1357
1381
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments