You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .exp/design-workflow-1-cargo-clippy.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ sequenceDiagram
79
79
- Ancestor directories.
80
80
- Code attributes.
81
81
- CLI flags passed via `CLIPPY_ARGS` (e.g., `-W clippy::perf`).
82
-
-**Application**: Used to filter and level lints during registration. Supports groups (correctness, style, perf, etc.) and MSRV specifications.
82
+
-**Application**: Used to filter and level lints during registration and to enable lint-specific behavior via access to `Conf` fields like `conf.msrv` for version-dependent logic (e.g., adjusting unsafe operation counts in `multiple_unsafe_ops_per_block` based on MSRV). Supports groups (correctness, style, perf, etc.) and MSRV specifications in `clippy.toml`.
83
83
-**Tracking**: Config files and env vars are added to `ParseSess`'s depinfo for incremental builds.
-**Configuration Loader (clippy_config)**: \`Conf::read\` parses \`clippy.toml\`, inline attributes (\`#[allow(clippy::lint)]\`), CLI overrides; provides fields like \`msrv\` for lints to access via constructors, influencing levels, params, and version-aware behavior.
28
28
-**Lint Utilities (clippy_utils)**: Reusable functions for lints (e.g., type queries, def path matching, expression analysis).
29
29
-**Rustc Infrastructure**: \`rustc_driver\`, \`rustc_interface\`, \`rustc_session\` for session management, diagnostics; \`rustc_lint\` for pass registration.
30
30
-**Development Helpers**: Tracks files/envs for incremental builds; ICE hook for bug reporting to GitHub.
@@ -102,7 +102,7 @@ sequenceDiagram
102
102
103
103
-**Performance Considerations**: MIR opt level set to 0 avoids optimizations that could obscure bugs (e.g., constant folding); disables specific passes like \`CheckNull\`. Trade-off: Slower compilation for accuracy.
104
104
-**Incremental Compilation**: Tracks runtime-accessed files (Cargo.toml, clippy.toml, driver exe) in \`file_depinfo\` and envs (CLIPPY_CONF_DIR, CLIPPY_ARGS) for Cargo-triggered rebuilds.
-**Configuration Flexibility**: Hierarchical (CLI > file > attributes); supports lint groups, custom params (e.g., max nesting depth), and MSRV settings in `clippy.toml` that lints can use via `conf.msrv` for version-aware behavior (e.g., `multiple_unsafe_ops_per_block` adjusts logic based on MSRV).
106
106
-**Fallback and Compatibility**: Supports plain rustc delegation for queries or suppressed lints; handles arg files (\`@path\`), sysroot env.
107
107
-**Extensibility**: Lints implement traits like \`EarlyLintPass\` or \`LateLintPass\`; new ones added via dev tools, auto-registered in \`lib.rs\`.
108
108
-**Diagnostics**: Leverages rustc's system for structured output (spans, suggestions via rustfix); colorized via anstream.
Copy file name to clipboardExpand all lines: .exp/design-workflow-5-lint-development.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,13 +11,13 @@ From analysis of source code (e.g., \`clippy_dev/src/new_lint.rs\`, \`clippy_dev
11
11
-**clippy_dev**: CLI tools (\`cargo dev\`) including \`new_lint\` for scaffolding and \`update_lints\` for generating registration code from parsed lint declarations.
12
12
-**clippy_lints**: Core library housing all lint implementations as structs implementing \`rustc_lint::EarlyLintPass\` or \`LateLintPass\`. Each lint file (\`src/<lint>.rs\` or in submodules like \`methods/\`) contains a \`declare_clippy_lint!\` invocation defining metadata (name, level, category, description, version, location).
13
13
-**declare_clippy_lint**: Crate providing the macro for lint declaration (generates \`Lint\` static and \`LintInfo\`) and \`LintListBuilder\` for bulk registration of individual lints and groups (e.g., \`clippy::all\`, \`clippy::correctness\`).
14
-
-**clippy_utils**: Shared utilities for common lint tasks (e.g., type queries, def path matching, expression analysis).
14
+
-**clippy_utils**: Shared utilities for common lint tasks (e.g., type queries, def path matching, expression analysis, MSRV checking via the `msrvs` module to enable version-specific lint behavior).
15
15
-**tests/ui/**: UI test infrastructure where each lint has a subdirectory with input \`.rs\` files and expected \`.stderr\` outputs (and \`.fixed\` for fixes) from Clippy runs to verify diagnostics.
16
16
-**clippy-driver** (in root \`src/driver.rs\`): Custom compiler driver that loads \`clippy_lints\`, uses generated \`declared_lints::LINTS\` to register lints via \`LintListBuilder\`, calls \`register_lint_passes\` to add passes, and hooks into rustc's pipeline.
17
17
-**lintcheck**: Separate tool (\`lintcheck/src/main.rs\`) for running lints on external crates listed in \`.toml\` files to detect regressions or false positives/negatives.
18
18
-**clippy_config**: Handles lint configuration from \`clippy.toml\` and attributes, used in passes.
19
19
20
-
Other aspects: Lints support configuration options, MSRV restrictions via attributes, categories for grouping, and integration with rustfix for auto-fixes.
20
+
Other aspects: Lints support configuration options (via `new(conf)` and lint-specific fields in `Conf`), MSRV-aware behavior via `conf.msrv` and attributes for restrictions, categories for grouping, and integration with rustfix for auto-fixes.
21
21
22
22
## Scaffolding Sequence Diagram
23
23
@@ -40,6 +40,9 @@ sequenceDiagram
40
40
UpdateTool->>LintImpl: Parse all declare clippy lint invocations
41
41
UpdateTool->>DeclaredLints: Update LINTS array including new lint
42
42
UpdateTool->>LibRs: Update mod declarations between comments
43
+
alt lint requires Conf access (e.g., for MSRV checks)
44
+
Developer->>LibRs: Manually update register_lint_passes instantiation to pass conf to new(conf)
45
+
end
43
46
UpdateTool->>README: Update lint counts and links
44
47
Note over UpdateTool: Handles deprecated and renamed lints too
45
48
\`\`\`
@@ -81,6 +84,8 @@ The \`update_lints\` tool parses all \`declare_clippy_lint!\` macros across \`cl
81
84
- Refresh docs (README.md, book/, CHANGELOG.md) with lint counts (rounded to 50) and markdown links.
82
85
- Manage deprecated/renamed lints in \`deprecated_lints.rs\` and dedicated UI tests.
83
86
87
+
For lints that require access to the configuration (\`Conf\`), such as to use \`conf.msrv\` for MSRV-dependent logic, the developer must manually update the instantiation of the lint pass in the \`register_lint_passes\` function in \`clippy_lints/src/lib.rs\`. Specifically, modify the closure to capture \`conf\` and pass it to the lint's \`new(conf)\` method, e.g., from \`Box::new(|_| Box::new(LintName))\` to \`Box::new(move |_| Box::new(LintName::new(conf)))\`. This step is not automated by \`update_lints\`.
88
+
84
89
This ensures new lints are automatically included when compiling \`clippy_lints\`.
85
90
86
91
### Lint Implementation Details
@@ -90,6 +95,7 @@ This ensures new lints are automatically included when compiling \`clippy_lints\
90
95
-**Hooks**: Lints impl methods like \`check_expr\`, \`check_item\` using visitor patterns or queries via \`cx\`.
91
96
-**Groups and Levels**: Lints assigned to categories (correctness, style, etc.) auto-grouped by \`LintListBuilder\`; levels (Allow, Warn, Deny).
92
97
-**Fixes**: Use \`rustfix::diagnostics::Diagnostic::fix` for auto-fixes via \`--fix\`.
98
+
-**Configuration Access**: Lints can implement a \`new(conf: &Conf)\` constructor to access runtime configuration, such as \`conf.msrv\` for adapting logic based on the project's minimum supported Rust version (configured in \`clippy.toml\`). This allows lints to provide accurate diagnostics respecting the MSRV, e.g., not flagging stabilized safe operations in older versions.
-**cargo-clippy (Workflow 1)**: Changed files include `clippy_config/src/conf.rs`, `clippy_lints/src/lib.rs`, and `clippy_lints/src/multiple_unsafe_ops_per_block.rs`, which are relevant to lint registration, configuration loading, and execution during Cargo subcommand runs. The PR makes the lint MSRV-aware, affecting diagnostic output based on configured MSRV.
5
+
-**clippy-driver (Workflow 2)**: Similar to Workflow 1, as the driver uses the same lint registration (`register_lint_passes` with `conf`) and utilities (`msrvs`), impacting direct compilations.
6
+
-**lint-development (Workflow 5)**: Primary impact; the PR demonstrates modifying an existing lint to use `Conf` and `msrvs` for version-specific logic, requiring manual update to `lib.rs` registration. Relevant files `clippy_lints/src/`, `clippy_utils/src/`, `tests/ui/`. Introduces process consideration for conf-dependent lints.
7
+
-**testing (Workflow 4)**: Updates UI test files (`tests/ui/multiple_unsafe_ops_per_block.*`) to validate the new MSRV-dependent behavior of the lint.
8
+
9
+
## Workflow 1 Analysis
10
+
### Summary of design changes
11
+
The PR enhances lint execution by allowing lints like `multiple_unsafe_ops_per_block` to use `conf.msrv` for conditional logic, e.g., not counting safe operations post-Rust 1.92 as unsafe if MSRV >=1.92. This is implemented via updated lint constructor taking `conf`, passed during registration. Benefits: Better accuracy across Rust versions. No new components or steps; leverages existing conf mechanism. Doc updated to highlight example usage in configuration application.
12
+
13
+
No changes to Mermaid diagram required.
14
+
15
+
## Workflow 2 Analysis
16
+
### Summary of design changes
17
+
Analogous to Workflow 1; the driver loads conf and passes to lints, now enabling MSRV-based adaptations in lint passes. Doc updated in configuration loader and flexibility sections to note `conf.msrv` usage and example.
18
+
19
+
No changes to Mermaid diagrams required.
20
+
21
+
## Workflow 4 Analysis
22
+
### Summary of design changes
23
+
The PR updates UI test inputs and expected outputs for `multiple_unsafe_ops_per_block` to reflect new MSRV logic, ensuring comprehensive test coverage for version-dependent cases. No structural changes to testing workflow or designs; routine update aligned with lint evolution.
24
+
25
+
No Mermaid updates needed (assuming doc has diagrams; validation passed).
26
+
27
+
## Workflow 5 Analysis
28
+
### Summary of design changes
29
+
Key changes:
30
+
- Added MSRV gate `SAFE_RAW_PTR_TO_UNION_FIELD` in `msrvs.rs` for lints to query version support.
31
+
- Lint now holds `Msrv` from `conf.msrv`, uses it in visitor to conditionally classify operations.
32
+
- Registration updated to `new(conf)`; lint added to `define_Conf!` list.
33
+
- This affects lint development process: when adding conf access (e.g., for MSRV), manual edit to `lib.rs` register_lint_passes needed post-`update_lints`.
34
+
- Benefits: Empowers lints with Rust evolution awareness, improving relevance.
0 commit comments