@@ -313,12 +313,42 @@ of the public API of the standard library, but are used to implement it.
313
313
` rustlib ` is part of the search path for linkers, but ` lib ` will never be part
314
314
of the search path.
315
315
316
+ #### -Z force-unstable-if-unmarked
317
+
316
318
Since ` rustlib ` is part of the search path, it means we have to be careful
317
319
about which crates are included in it. In particular, all crates except for
318
320
the standard library are built with the flag ` -Z force-unstable-if-unmarked ` ,
319
321
which means that you have to use ` #![feature(rustc_private)] ` in order to
320
322
load it (as opposed to the standard library, which is always available).
321
323
324
+ The ` -Z force-unstable-if-unmarked ` flag has a variety of purposes to help
325
+ enforce that the correct crates are marked as unstable. It was introduced
326
+ primarily to allow rustc and the standard library to link to arbitrary crates
327
+ on crates.io which do not themselves use ` staged_api ` . ` rustc ` also relies on
328
+ this flag to mark all of its crates as unstable with the ` rustc_private `
329
+ feature so that each crate does not need to be carefully marked with
330
+ ` unstable ` .
331
+
332
+ This flag is automatically applied to all of ` rustc ` and the standard library
333
+ by the bootstrap scripts. This is needed because the compiler and all of its
334
+ dependencies are shipped in the sysroot to all users.
335
+
336
+ This flag has the following effects:
337
+
338
+ - Marks the crate as "unstable" with the ` rustc_private ` feature if it is not
339
+ itself marked as stable or unstable.
340
+ - Allows these crates to access other forced-unstable crates without any need
341
+ for attributes. Normally a crate would need a ` #![feature(rustc_private)] `
342
+ attribute to use other unstable crates. However, that would make it
343
+ impossible for a crate from crates.io to access its own dependencies since
344
+ that crate won't have a ` feature(rustc_private) ` attribute, but * everything*
345
+ is compiled with ` -Z force-unstable-if-unmarked ` .
346
+
347
+ Code which does not use ` -Z force-unstable-if-unmarked ` should include the
348
+ ` #![feature(rustc_private)] ` crate attribute to access these force-unstable
349
+ crates. This is needed for things that link ` rustc ` , such as ` miri ` , ` rls ` , or
350
+ ` clippy ` .
351
+
322
352
You can find more discussion about sysroots in:
323
353
- The [ rustdoc PR] explaining why it uses ` extern crate ` for dependencies loaded from sysroot
324
354
- [ Discussions about sysroot on Zulip] ( https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/deps.20in.20sysroot/ )
0 commit comments