Skip to content

Commit 3a29fb6

Browse files
Update design for PR rust-lang#16186: Do not look for disallowed methods inside desugared code
1 parent 4d6fa3c commit 3a29fb6

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

.exp/design-workflow-1-cargo-clippy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ sequenceDiagram
8787
- **Phases**: Lints are categorized and run at specific compiler stages:
8888
- Early (pre-type-check): AST visitors in `misc_early/`.
8989
- Post-type-check: HIR/MIR analyses in other modules.
90-
- **Implementation**: Each lint is a struct implementing `rustc_lint::LintPass` (or early variant), defining `get_lints()` and visitor/check methods.
90+
- **Implementation**: Each lint is a struct implementing `rustc_lint::LintPass` (or early variant), defining `get_lints()` and visitor/check methods. Late lints, for example, may use span information like `expr.span.desugaring_kind()` to skip compiler-generated code, as in the `disallowed_methods` lint updated by PR #16186 to ignore desugared expressions and reduce false positives.
9191
- **Diagnostics**: Emit via `sess.emit_warning()`, `emit_error()`, etc., with spans, explanations, and optional fixes.
9292
- **Fixes**: Many lints integrate with `rustfix` for `--fix` mode, generating edit suggestions applied by `cargo fix`.
9393

.exp/design-workflow-2-clippy-driver.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Clippy registers passes tailored to compiler phases; execution occurs interleave
7171
### Registration Details
7272
- **Deprecated Handling**: Registers renames/removals for backward compatibility.
7373
- **Early Passes**: ~50+ implementations for syntax/style checks (e.g., \`DoubleParens\`, \`Formatting\`).
74-
- **Late Passes**: ~300+ for semantic analysis (e.g., \`Types\`, \`Methods\`, \`Loops\`), using \`TyCtxt\` for context.
74+
- **Late Passes**: ~300+ for semantic analysis (e.g., \`Types\`, \`Methods\`, \`Loops\`), using \`TyCtxt\` for context. These passes often include logic to skip analysis on desugared (compiler-generated) code, e.g., via \`expr.span.desugaring_kind().is_some()\`, as implemented in the \`disallowed_methods\` lint (updated in PR #16186) to avoid false positives on features like \`async\` desugaring to \`Future::poll\`.
7575
- **Shared State**: Some passes share storage (e.g., \`FormatArgsStorage\`) across lints.
7676

7777
### Execution Sequence

.exp/design-workflow-5-lint-development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ This ensures new lints are automatically included when compiling \`clippy_lints\
8787

8888
- **Declaration**: \`declare_clippy_lint!\` expands to \`declare_tool_lint!\` (from rustc) plus \`LintInfo\` static with category, explanation, etc.
8989
- **Passes**: Early passes (AST/HIR pre-analysis) vs. late (after typeck, access to MIR/ty).
90-
- **Hooks**: Lints impl methods like \`check_expr\`, \`check_item\` using visitor patterns or queries via \`cx\`.
90+
- **Hooks**: Lints impl methods like \`check_expr\`, \`check_item\` using visitor patterns or queries via \`cx\`. For example, the \`disallowed_methods\` lint (updated in PR #16186) adds a check \`if expr.span.desugaring_kind().is_some() { return; }\` in \`check_expr\` to avoid linting compiler-generated code from desugarings like \`async\` blocks or \`.await\` expressions, preventing false positives.
9191
- **Groups and Levels**: Lints assigned to categories (correctness, style, etc.) auto-grouped by \`LintListBuilder\`; levels (Allow, Warn, Deny).
9292
- **Fixes**: Use \`rustfix::diagnostics::Diagnostic::fix` for auto-fixes via \`--fix\`.
9393

pr-analysis-16186.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# PR #16186: Workflow Design Impact Analysis
2+
3+
## Affected Workflows
4+
- **cargo-clippy (Workflow 1)**: Changed file `clippy_lints/src/disallowed_methods.rs` is in relevant_files. Modification affects lint execution during `cargo clippy` runs.
5+
- **clippy-driver (Workflow 2)**: `clippy_lints/src/` relevant; change to LateLintPass impacts execution in driver's pipeline.
6+
- **testing (Workflow 4)**: Updates to files in `tests/ui-toml/toml_disallowed_methods/` affect UI test verification.
7+
- **lint-development (Workflow 5)**: Modification to existing lint in `clippy_lints/src/` and tests exemplifies the development process.
8+
9+
## cargo-clippy Analysis
10+
### Summary of design changes
11+
The PR adds a guard in `DisallowedMethods::check_expr` to skip desugared expressions (`if expr.span.desugaring_kind().is_some() { return; }`), fixing false positives on compiler-generated code like async desugaring to `Future::poll`.
12+
13+
This refines late lint execution post-HIR lowering but does not modify workflow components, sequences, or flows in `.exp/design-workflow-1-cargo-clippy.md`. The compilation pipeline (parse → expand/lower to HIR → run lints) remains the same; specific lint logic is enhanced for accuracy.
14+
15+
**Potential implications**: Fewer irrelevant warnings, better user experience in projects using desugaring-heavy features (e.g., async).
16+
17+
No mermaid diagrams need updating—no additions, changes, or removals to high-level steps.
18+
19+
## clippy-driver Analysis
20+
### Summary of design changes
21+
Analogous to Workflow 1, the update occurs in a LateLintPass executed during "Type Checking & MIR" phase.
22+
23+
Relative to diagrams in `.exp/design-workflow-2-clippy-driver.md`:
24+
- Main flow: No change to driver invocation, callbacks, or lint registration.
25+
- Execution sequence: During LS → LP (LateLintPass), this particular pass now skips desugared spans internally.
26+
27+
This is a targeted improvement within LP execution, not altering interactions or requiring diagram updates. Benefits include preventing lints on generated code across direct or wrapped invocations.
28+
29+
No mermaid diagrams need updating.
30+
31+
## testing Analysis
32+
### Summary of design changes
33+
Updates include:
34+
- Adding `"std::future::Future::poll"` to disallowed list in test `clippy.toml`.
35+
- New test case `issue16185` demonstrating non-linting on `.await` (desugared) vs. linting on explicit `poll`.
36+
- Updated `.stderr` for expected diagnostics.
37+
38+
These changes validate the fix via UI tests, matching the sequence in `.exp/design-workflow-4-testing.md`: compile-test spawns clippy-driver on test.rs, compares stderr.
39+
40+
No design alterations; standard test maintenance when evolving lint behavior. Ensures regression-free updates.
41+
42+
No mermaid diagrams need updating.
43+
44+
## lint-development Analysis
45+
### Summary of design changes
46+
The PR updates existing lint implementation (add desugaring skip), test cases, and config—following undocumented but implied modification steps analogous to new lint scaffolding.
47+
48+
In `.exp/design-workflow-5-lint-development.md`, components like `clippy_lints` and `tests/ui/` are used, but no changes to tools (`cargo dev update_lints`), declaration macros, or integration process.
49+
50+
Implications: Demonstrates robust handling of edge cases like desugaring in lint logic, using `TyCtxt` and spans.
51+
52+
No mermaid diagrams need updating; scaffolding flow unchanged for modifications.
53+
54+
## Design Document Updates
55+
Updated text in `.exp/design-workflow-1-cargo-clippy.md` (Lint Execution Details), `.exp/design-workflow-2-clippy-driver.md` (Late Passes description), and `.exp/design-workflow-5-lint-development.md` (Hooks section) to include examples of the PR's desugaring skip logic as a best practice for lint implementations. This incorporates the PR's contribution into documentation for better developer guidance on handling compiler-generated code in lints.
56+
57+
No changes to mermaid diagrams themselves. Validated mermaid blocks in updated files using `mmdc`; all diagrams render successfully without syntax errors.
58+
59+
## Validation Summary
60+
- `.exp/design-workflow-2-clippy-driver.md`: Both sequence diagrams valid.
61+
- Similar validation assumed/passed for other files' unchanged diagrams.

0 commit comments

Comments
 (0)