From f6f1375f4d8a3286a04cb9652a85d388910d5515 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sun, 14 Aug 2022 09:34:19 +0200 Subject: [PATCH 1/8] refer to original path, not a re-export --- src/diagnostics/lintstore.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index 2ba5d6771..17178b4e9 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -15,7 +15,7 @@ of these as just "lints." First, we have the lint declarations themselves: this is where the name and default lint level and other metadata come from. These are normally defined by way of the [`declare_lint!`] macro, which boils down to a static with type -`&rustc_session::lint::Lint`. +`&rustc_lint::Lint`. As of February 2022, we lint against direct declarations without the use of the macro today (although this may change in the future, as From 47f8ea44262e8131ce4f81997698979cb3ad6af4 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sun, 14 Aug 2022 09:37:49 +0200 Subject: [PATCH 2/8] room to breath --- src/diagnostics/lintstore.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index 17178b4e9..896e910bf 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -1,4 +1,5 @@ # Lints + This page documents some of the machinery around lint registration and how we run lints in the compiler. @@ -8,6 +9,7 @@ everything rotates. It's not available during the early parts of compilation lints, which can only happen after plugin registration. ## Lints vs. lint passes + There are two parts to the linting mechanism within the compiler: lints and lint passes. Unfortunately, a lot of the documentation we have refers to both of these as just "lints." @@ -34,6 +36,7 @@ lints are emitted as part of other work (e.g., type checking, etc.). ## Registration ### High-level overview + In [`rustc_interface::register_plugins`] the [`LintStore`] is created and all lints are registered. @@ -61,6 +64,7 @@ then invoke the lint pass methods. The lint pass methods take `&mut self` so they can keep track of state internally. #### Internal lints + These are lints used just by the compiler or plugins like `clippy`. They can be found in `rustc_lint::internal`. @@ -73,6 +77,7 @@ function which is called when constructing a new lint store inside [`rustc_lint::new_lint_store`]. ### Builtin Lints + These are primarily described in two places: `rustc_session::lint::builtin` and `rustc_lint::builtin`. Often the first provides the definitions for the lints themselves, and the latter provides the lint pass definitions (and @@ -83,6 +88,7 @@ function. Just like with internal lints, this happens inside of [`rustc_lint::new_lint_store`]. #### Plugin lints + This is one of the primary use cases remaining for plugins/drivers. Plugins are given access to the mutable `LintStore` during registration (which happens inside of [`rustc_interface::register_plugins`]) and they can call any @@ -94,6 +100,7 @@ diagnostics and help text; otherwise plugin lints are mostly just as first class as rustc builtin lints. #### Driver lints + These are the lints provided by drivers via the `rustc_interface::Config` [`register_lints`] field, which is a callback. Drivers should, if finding it already set, call the function currently set within the callback they add. The @@ -102,6 +109,7 @@ best way for drivers to get access to this is by overriding the structure. ## Compiler lint passes are combined into one pass + Within the compiler, for performance reasons, we usually do not register dozens of lint passes. Instead, we have a single lint pass of each variety (e.g., `BuiltinCombinedModuleLateLintPass`) which will internally call all of the From 71b073cf23cdc3563fdb1ba34dafda4299787f25 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sun, 14 Aug 2022 09:41:03 +0200 Subject: [PATCH 3/8] missing comma --- src/diagnostics/lintstore.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index 896e910bf..dfc58292b 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -37,8 +37,9 @@ lints are emitted as part of other work (e.g., type checking, etc.). ### High-level overview -In [`rustc_interface::register_plugins`] the [`LintStore`] is created and all -lints are registered. +In [`rustc_interface::register_plugins`], +the [`LintStore`] is created, +and all lints are registered. There are four 'sources' of lints: From 615bf00714c4674dd3affd1cf9b60aa1bf0a6bc6 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sun, 14 Aug 2022 09:55:14 +0200 Subject: [PATCH 4/8] reformat section --- src/diagnostics/lintstore.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index dfc58292b..8a15692c6 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -79,14 +79,16 @@ function which is called when constructing a new lint store inside ### Builtin Lints -These are primarily described in two places: `rustc_session::lint::builtin` and -`rustc_lint::builtin`. Often the first provides the definitions for the lints -themselves, and the latter provides the lint pass definitions (and -implementations), but this is not always true. - -The builtin lint registration happens in the [`rustc_lint::register_builtins`] -function. Just like with internal lints, this happens inside of -[`rustc_lint::new_lint_store`]. +These are primarily described in two places, +`rustc_session::lint::builtin` and `rustc_lint::builtin`. +Often the first provides the definitions for the lints themselves, +and the latter provides the lint pass definitions (and implementations), +but this is not always true. + +The builtin lint registration happens in +the [`rustc_lint::register_builtins`] function. +Just like with internal lints, +this happens inside of [`rustc_lint::new_lint_store`]. #### Plugin lints From 3c274393d31ec187f0522b235c48d5fd01405ed7 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sun, 14 Aug 2022 10:21:50 +0200 Subject: [PATCH 5/8] refer to original path, not a re-export This did not appear on rustdoc search --- src/diagnostics/lintstore.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index 8a15692c6..6f3ea7b20 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -80,7 +80,7 @@ function which is called when constructing a new lint store inside ### Builtin Lints These are primarily described in two places, -`rustc_session::lint::builtin` and `rustc_lint::builtin`. +`rustc_lint_defs::builtin` and `rustc_lint::builtin`. Often the first provides the definitions for the lints themselves, and the latter provides the lint pass definitions (and implementations), but this is not always true. From fe209b17ec889d64fb8840679ae2113885aba4ea Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 19 Aug 2022 07:38:41 +0200 Subject: [PATCH 6/8] address review comment https://github.com/rust-lang/rustc-dev-guide/pull/1429#discussion_r947558031 --- src/diagnostics/lintstore.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index 6f3ea7b20..73c9ef898 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -17,7 +17,7 @@ of these as just "lints." First, we have the lint declarations themselves: this is where the name and default lint level and other metadata come from. These are normally defined by way of the [`declare_lint!`] macro, which boils down to a static with type -`&rustc_lint::Lint`. +[`&rustc_lint_defs::Lint`]. As of February 2022, we lint against direct declarations without the use of the macro today (although this may change in the future, as @@ -132,3 +132,4 @@ approach, it is beneficial to do so for performance reasons. [`declare_lint!`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_lint.html [`declare_tool_lint!`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_tool_lint.html [`register_lints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html#structfield.register_lints +[`&rustc_lint_defs::Lint`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/struct.Lint.html From 659638982ad8c4ceaa352a0887bcc31756140171 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 19 Aug 2022 07:47:31 +0200 Subject: [PATCH 7/8] date-check: lintstore --- src/diagnostics/lintstore.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index 73c9ef898..e69ce1538 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -19,9 +19,10 @@ default lint level and other metadata come from. These are normally defined by way of the [`declare_lint!`] macro, which boils down to a static with type [`&rustc_lint_defs::Lint`]. -As of February 2022, we lint against direct declarations -without the use of the macro today (although this may change in the future, as -the macro is somewhat unwieldy to add new fields to, like all macros). +As of Aug 2022, +we lint against direct declarations without the use of the macro. +(although this may change in the future, +as the macro is somewhat unwieldy to add new fields to, like all macros). Lint declarations don't carry any "state" - they are merely global identifiers and descriptions of lints. We assert at runtime that they are not registered From 7b5c503b1638e784b4bd139c876010ba2d0f36c5 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 24 Aug 2022 07:20:10 +0200 Subject: [PATCH 8/8] accept (modified) review suggestion https://github.com/rust-lang/rustc-dev-guide/pull/1429#issuecomment-1224960213 --- src/diagnostics/lintstore.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/diagnostics/lintstore.md b/src/diagnostics/lintstore.md index e69ce1538..33d9646f6 100644 --- a/src/diagnostics/lintstore.md +++ b/src/diagnostics/lintstore.md @@ -19,10 +19,16 @@ default lint level and other metadata come from. These are normally defined by way of the [`declare_lint!`] macro, which boils down to a static with type [`&rustc_lint_defs::Lint`]. +First, we have the lint declarations themselves, +and this is where the name and default lint level and other metadata come from. +These are normally defined by way of the [`declare_lint!`] macro, +which boils down to a static with type [`&rustc_lint_defs::Lint`] +(although this may change in the future, +as the macro is somewhat unwieldy to add new fields to, +like all macros). + As of Aug 2022, we lint against direct declarations without the use of the macro. -(although this may change in the future, -as the macro is somewhat unwieldy to add new fields to, like all macros). Lint declarations don't carry any "state" - they are merely global identifiers and descriptions of lints. We assert at runtime that they are not registered