From 2f10103ec00a15b3b4a1ff83bb108ce3b45e8078 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 31 May 2025 15:43:05 -0700 Subject: [PATCH 01/11] Unwrap no_implicit_prelude --- src/names/preludes.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index 63d08af1b4..0d6ce56ef5 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -155,10 +155,7 @@ r[names.preludes.no_implicit_prelude] ## The `no_implicit_prelude` attribute r[names.preludes.no_implicit_prelude.intro] -The *`no_implicit_prelude` [attribute]* may be applied at the crate level or -on a module to indicate that it should not automatically bring the [standard -library prelude], [extern prelude], or [tool prelude] into scope for that -module or any of its descendants. +The *`no_implicit_prelude` [attribute]* may be applied at the crate level or on a module to indicate that it should not automatically bring the [standard library prelude], [extern prelude], or [tool prelude] into scope for that module or any of its descendants. r[names.preludes.no_implicit_prelude.lang] This attribute does not affect the [language prelude]. From 0fe507dddf07517a812bcab77029a6cc8f930641 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 31 May 2025 15:54:34 -0700 Subject: [PATCH 02/11] Add an example for no_implicit_prelude --- src/names/preludes.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/names/preludes.md b/src/names/preludes.md index 0d6ce56ef5..364724fd92 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -157,6 +157,18 @@ r[names.preludes.no_implicit_prelude] r[names.preludes.no_implicit_prelude.intro] The *`no_implicit_prelude` [attribute]* may be applied at the crate level or on a module to indicate that it should not automatically bring the [standard library prelude], [extern prelude], or [tool prelude] into scope for that module or any of its descendants. +> [!EXAMPLE] +> ```rust +> // It can be applied to the crate root to apply to all modules. +> #![no_implicit_prelude] +> +> // Or it can be applied to a module to only affect that module or any of its descendants. +> #[no_implicit_prelude] +> mod example { +> // ... +> } +> ``` + r[names.preludes.no_implicit_prelude.lang] This attribute does not affect the [language prelude]. From b5e3e2680af1432f166a8a472d070bd03e4c2bf1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 31 May 2025 15:55:11 -0700 Subject: [PATCH 03/11] Add explicit rules for no_implicit_prelude This is to follow the attribute template. --- src/names/preludes.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/names/preludes.md b/src/names/preludes.md index 364724fd92..db5eedc837 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -169,6 +169,21 @@ The *`no_implicit_prelude` [attribute]* may be applied at the crate level or on > } > ``` +r[names.preludes.no_implicit_prelude.syntax] +The `no_implicit_prelude` attribute uses the [MetaWord] syntax and thus does not take any inputs. + +r[names.preludes.no_implicit_prelude.allowed-positions] +The `no_implicit_prelude` attribute may only be applied to the crate level or a module. + +> [!NOTE] +> `rustc` currently warns in other positions, but this may be rejected in the future. + +r[names.preludes.no_implicit_prelude.duplicates] +Duplicate instances of the `no_implicit_prelude` attribute have no effect. + +> [!NOTE] +> `rustc` currently warns on subsequent duplicate `no_implicit_prelude` attributes. + r[names.preludes.no_implicit_prelude.lang] This attribute does not affect the [language prelude]. From a2b8f937e4f83a62316efb2815f0be95c91326f5 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 31 May 2025 15:56:23 -0700 Subject: [PATCH 04/11] Rewrite no_implicit_prelude to move to a specific rule This rewrites the intro to be a little more general, and moves the description of the behavior to a specific rule that can be cited. --- src/names/preludes.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index db5eedc837..4f2ae167b2 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -155,7 +155,7 @@ r[names.preludes.no_implicit_prelude] ## The `no_implicit_prelude` attribute r[names.preludes.no_implicit_prelude.intro] -The *`no_implicit_prelude` [attribute]* may be applied at the crate level or on a module to indicate that it should not automatically bring the [standard library prelude], [extern prelude], or [tool prelude] into scope for that module or any of its descendants. +The *`no_implicit_prelude` [attribute]* is used to prevent implicit preludes from being brought into scope. > [!EXAMPLE] > ```rust @@ -184,6 +184,9 @@ Duplicate instances of the `no_implicit_prelude` attribute have no effect. > [!NOTE] > `rustc` currently warns on subsequent duplicate `no_implicit_prelude` attributes. +r[names.preludes.no_implicit_prelude.excluded-preludes] +The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], and the [tool prelude] from being brought into scope for the module or any of its descendants. + r[names.preludes.no_implicit_prelude.lang] This attribute does not affect the [language prelude]. From 0ed80f7bc2df8db56a7300ebbb943fbdaf5e3e90 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 31 May 2025 15:57:08 -0700 Subject: [PATCH 05/11] Be explicit in the wording here --- src/names/preludes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index 4f2ae167b2..1fc4fb1044 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -188,7 +188,7 @@ r[names.preludes.no_implicit_prelude.excluded-preludes] The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], and the [tool prelude] from being brought into scope for the module or any of its descendants. r[names.preludes.no_implicit_prelude.lang] -This attribute does not affect the [language prelude]. +The `no_implicit_prelude` attribute does not affect the [language prelude]. r[names.preludes.no_implicit_prelude.edition2018] > [!EDITION-2018] From 70fa8bd0fc196dcac2481bbf55d738184112e22a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 22 Sep 2025 13:24:41 -0700 Subject: [PATCH 06/11] Minor update of `no_implicit_prelude` More closely align with the template, and some minor word tweaks. --- src/names/preludes.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index 1fc4fb1044..4351d16249 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -151,6 +151,7 @@ r[names.preludes.tool.intro] The tool prelude includes tool names for external tools in the [type namespace]. See the [tool attributes] section for more details. + r[names.preludes.no_implicit_prelude] ## The `no_implicit_prelude` attribute @@ -170,19 +171,19 @@ The *`no_implicit_prelude` [attribute]* is used to prevent implicit preludes fro > ``` r[names.preludes.no_implicit_prelude.syntax] -The `no_implicit_prelude` attribute uses the [MetaWord] syntax and thus does not take any inputs. +The `no_implicit_prelude` attribute uses the [MetaWord] syntax. r[names.preludes.no_implicit_prelude.allowed-positions] The `no_implicit_prelude` attribute may only be applied to the crate level or a module. > [!NOTE] -> `rustc` currently warns in other positions, but this may be rejected in the future. +> `rustc` ignores use in other positions but lints against it. This may become an error in the future. r[names.preludes.no_implicit_prelude.duplicates] -Duplicate instances of the `no_implicit_prelude` attribute have no effect. +The `no_implicit_prelude` attribute may be used any number of times on a form. > [!NOTE] -> `rustc` currently warns on subsequent duplicate `no_implicit_prelude` attributes. +> `rustc` lints against any use following the first. r[names.preludes.no_implicit_prelude.excluded-preludes] The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], and the [tool prelude] from being brought into scope for the module or any of its descendants. From 9ca5c57e2535a770e399ef2a9f154df07c58506e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 8 Nov 2025 19:05:50 -0800 Subject: [PATCH 07/11] Fix no_implicit_prelude to document the *current* edition in the main text This follows our style guide where the main text should document the current edition, and the edition blocks should note the differences to previous editions. --- src/names/preludes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index 4351d16249..d97aa53db9 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -186,7 +186,7 @@ The `no_implicit_prelude` attribute may be used any number of times on a form. > `rustc` lints against any use following the first. r[names.preludes.no_implicit_prelude.excluded-preludes] -The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], and the [tool prelude] from being brought into scope for the module or any of its descendants. +The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], [`macro_use` prelude], and the [tool prelude] from being brought into scope for the module or any of its descendants. r[names.preludes.no_implicit_prelude.lang] The `no_implicit_prelude` attribute does not affect the [language prelude]. From 69707f462a8f20b39d919087b2a3f34b9b3c4959 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 11 Nov 2025 23:19:00 +0000 Subject: [PATCH 08/11] Wrap and reword `no_implicit_prelude` code comments One of the comments in the example stretched out a bit far; let's wrap that and reword the comments in the example for clarity and flow. --- src/names/preludes.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index d97aa53db9..e2bcda3df3 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -160,10 +160,12 @@ The *`no_implicit_prelude` [attribute]* is used to prevent implicit preludes fro > [!EXAMPLE] > ```rust -> // It can be applied to the crate root to apply to all modules. +> // The attribute can be applied to the crate root to affect +> // all modules. > #![no_implicit_prelude] > -> // Or it can be applied to a module to only affect that module or any of its descendants. +> // Or it can be applied to a module to only affect that module +> // and its descendants. > #[no_implicit_prelude] > mod example { > // ... From 60b75862e1541dc79e6d99d76e05f8b6ca035fa2 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 11 Nov 2025 23:21:51 +0000 Subject: [PATCH 09/11] Revise `no_implicit_prelude.allowed-positions` text It's more clear to say either that something can be applied "at the crate level" or "to the crate" than "to the crate level". Let's pick the latter and adjust for better grammatical parallelism. --- src/names/preludes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index e2bcda3df3..bdc9209642 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -176,7 +176,7 @@ r[names.preludes.no_implicit_prelude.syntax] The `no_implicit_prelude` attribute uses the [MetaWord] syntax. r[names.preludes.no_implicit_prelude.allowed-positions] -The `no_implicit_prelude` attribute may only be applied to the crate level or a module. +The `no_implicit_prelude` attribute may only be applied to the crate or to a module. > [!NOTE] > `rustc` ignores use in other positions but lints against it. This may become an error in the future. From ee8065669e8f91643fa8e4f502220efbb49c2501 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 11 Nov 2025 23:24:40 +0000 Subject: [PATCH 10/11] Revise `no_implicit_prelude.excluded-preludes` text Rather than saying "or any of its descendants", we can say "and its descendants" to express the same thing more concisely. Let's do that. --- src/names/preludes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index bdc9209642..65a3700b90 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -188,7 +188,7 @@ The `no_implicit_prelude` attribute may be used any number of times on a form. > `rustc` lints against any use following the first. r[names.preludes.no_implicit_prelude.excluded-preludes] -The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], [`macro_use` prelude], and the [tool prelude] from being brought into scope for the module or any of its descendants. +The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], [`macro_use` prelude], and the [tool prelude] from being brought into scope for the module and its descendants. r[names.preludes.no_implicit_prelude.lang] The `no_implicit_prelude` attribute does not affect the [language prelude]. From a5a9f03bf8f9da3d5241881f42870c883eb315a8 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 11 Nov 2025 23:26:43 +0000 Subject: [PATCH 11/11] Bring `no_implicit_prelude.edition2018` into present The remainder of this note is in the present tense, so saying that something "will" happen starting in the 2018 edition makes it sound as though that will happen in the future, even if what we mean is that the compiler "will" do it in the 2018 edition and later. Let's use the present tense here in emphatic form to distinguish this, and let's expand "it" for clarity. --- src/names/preludes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index 65a3700b90..3a2c3ff17c 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -195,7 +195,7 @@ The `no_implicit_prelude` attribute does not affect the [language prelude]. r[names.preludes.no_implicit_prelude.edition2018] > [!EDITION-2018] -> In the 2015 edition, the `no_implicit_prelude` attribute does not affect the [`macro_use` prelude], and all macros exported from the standard library are still included in the `macro_use` prelude. Starting in the 2018 edition, it will remove the `macro_use` prelude. +> In the 2015 edition, the `no_implicit_prelude` attribute does not affect the [`macro_use` prelude], and all macros exported from the standard library are still included in the `macro_use` prelude. Starting in the 2018 edition, the attribute does remove the `macro_use` prelude. [`extern crate`]: ../items/extern-crates.md [`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute