Skip to content

Commit 31a1946

Browse files
Update design for PR rust-lang#16123: Add explicit_default_arguments lint
1 parent 4d6fa3c commit 31a1946

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed

pr-analysis-16123.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# PR #16123: Workflow Design Impact Analysis
2+
3+
## Affected Workflows
4+
- **cargo-clippy**: The PR adds a new lint to `clippy_lints/src/`, which is a relevant file for this workflow. The new lint will be executed during `cargo clippy` runs, potentially emitting new diagnostics for projects using type aliases with explicit default generic arguments. Evidence: Changed files include `clippy_lints/src/*`.
5+
6+
- **clippy-driver**: Similar to `cargo-clippy`, the new LateLintPass is registered and will run during the compiler pipeline in `clippy-driver` invocations. Evidence: `clippy_lints/src/` is relevant, and registration updates in `lib.rs`.
7+
8+
- **testing**: New UI test files added in `tests/ui/explicit_default_arguments*`, which will be processed by the `compile-test` binary in the UI tests loop. Evidence: Changed files in `tests/ui/`.
9+
10+
- **lint-development**: Primary workflow impacted; the PR implements and integrates a new lint `explicit_default_arguments`, including module creation, declaration, registration in `declared_lints.rs` and `lib.rs`, and UI tests. Evidence: Matches workflow description and relevant files `clippy_lints/src/`, `tests/ui/`, `declared_lints.rs` updated.
11+
12+
- **release-process**: CHANGELOG.md updated with a new entry and link for the lint. Evidence: Changed `CHANGELOG.md`, relevant file for changelog updates during releases.
13+
14+
## cargo-clippy Analysis
15+
### Summary of design changes
16+
No structural changes to components, sequences, or flows. The PR extends the lint set by adding metadata to `declared_lints::LINTS` and a registration call in `register_lint_passes`, integrating the new style lint into existing registration and execution paths. The lint checks for redundant explicit default generic arguments in type alias usages by recursively walking types in HIR items (fns, impls, structs, etc.) using paired Ty and hir::Ty analysis.
17+
18+
How implemented: New `explicit_default_arguments.rs` with `LateLintPass` impl, custom `walk_ty_recursive` function handling various type kinds (Adt, FnPtr, Dynamic, Projection, Opaque, Tuple, etc.), matching generic args to alias defaults.
19+
20+
Benefits: Encourages concise code by linting e.g., `Result<()>` when `type Result<T=()>` has default, reducing clutter. Implications: Minor perf impact from type walking, new lint available in style category.
21+
22+
Mermaid diagrams needing update: The sequence diagram highlights the registration steps affected by additions (no removal/change).
23+
24+
```mermaid
25+
sequenceDiagram
26+
participant U as User
27+
participant CC as "cargo-clippy"
28+
participant C as cargo
29+
participant CD as "clippy-driver"
30+
participant RI as rustc_interface
31+
participant LS as "Lint Store"
32+
participant CL as "Clippy Lints (clippy_lints)"
33+
participant Config as "clippy_config"
34+
35+
U->>CC: cargo clippy [options]
36+
note right of CC: Parse args, set mode<br/>Set env vars
37+
CC->>C: cargo check/fix [user args]
38+
C->>CD: Invoke as rustc wrapper
39+
CD->>RI: run_compiler with ClippyCallbacks
40+
RI->>CD: config()
41+
CD->>Config: load conf
42+
Config-->>CD: Conf
43+
note right of CD: Adjust opts
44+
CD->>LS: register_lints
45+
LS->>CL: Register LINTS
46+
note over LS,CL: green addition: + EXPLICIT_DEFAULT_ARGUMENTS_INFO
47+
CL-->>LS: metadata registered
48+
LS->>CL: register_lint_passes(conf)
49+
note over LS,CL: green addition: + ExplicitDefaultArguments pass
50+
CL-->>LS: passes registered
51+
note over RI: Pipeline executes lints
52+
note over RI,CL: green: new lint executes in late phase on types
53+
alt --fix
54+
note over CL,RI: yellow: potential future fixes
55+
else check
56+
RI->>U: diagnostics (green: + new lint diags)
57+
end
58+
```
59+
60+
## clippy-driver Analysis
61+
### Summary of design changes
62+
Similar to cargo-clippy; no design alterations. The new lint is added as a LateLintPass in the registration flow, extending the late passes executed during type checking and MIR phases. The custom type walker enables deep analysis of generic args in complex types (trait objects, projections, GATs in impl traits per recent commit).
63+
64+
Benefits: Enables standalone or IDE use of the new lint for direct file linting. Implications: Same as above, integrated into driver for non-Cargo setups.
65+
66+
Mermaid diagrams needing update: Main execution and lint execution flows extended with new pass.
67+
68+
```mermaid
69+
sequenceDiagram
70+
participant U as User
71+
participant D as clippy-driver
72+
participant RD as rustc_driver
73+
participant C as Config & Callbacks
74+
participant LS as Lint Store
75+
participant CP as Compilation Pipeline
76+
participant L as Lint Passes
77+
78+
U->>D: clippy-driver file.rs [options]
79+
D->>D: Parse args
80+
alt Clippy enabled
81+
D->>RD: run_compiler with ClippyCallbacks
82+
RD->>C: config - load conf, opts
83+
C->>LS: register_lint_passes
84+
note over C,LS: green: + new late lint pass registration
85+
RD->>C: psess_created - track deps
86+
RD->>CP: Run phases
87+
loop Phases
88+
CP->>L: Execute passes
89+
note over CP,L: green: + execution of new ExplicitDefaultArguments
90+
L->>CP: diagnostics
91+
end
92+
else Rustc mode
93+
D->>RD: standard rustc
94+
end
95+
CP->>D: output
96+
D->>U: diagnostics
97+
```
98+
99+
## testing Analysis
100+
### Summary of design changes
101+
No changes to design; PR adds new test cases ( .rs, .stderr, .fixed, .stdout ) in `tests/ui/explicit_default_arguments` to verify lint triggers, messages, spans, and fixes across various item kinds (fns, structs, impls, etc.). These are processed in the UI tests category loop by `compile-test.rs` using ui_test framework, comparing outputs and potentially blessing.
102+
103+
How implemented: Test files simulate code with explicit default args in type aliases, expected outputs from lint emissions.
104+
105+
Benefits: Ensures the new lint's correctness, covers edge cases like recursive types, GATs, trait objects (with noted limitations). Implications: Expanded test suite, must pass `cargo test` before merge.
106+
107+
Mermaid diagrams needing update: UI tests sequence diagram's loop includes new tests.
108+
109+
```mermaid
110+
sequenceDiagram
111+
participant U as User/Developer
112+
participant C as Cargo
113+
participant CT as Compile-Test
114+
participant CD as Clippy-Driver
115+
participant FS as File System
116+
participant R as Rustc Pipeline
117+
118+
U->>C: cargo test
119+
C->>CT: Run compile-test main()
120+
loop For each UI test category (ui, etc.)
121+
note over CT: green addition: includes new explicit_default_arguments tests
122+
CT->>CT: Configure ui_test for dir
123+
CT->>CD: Spawn clippy-driver on test.rs
124+
CD->>R: Compile with lints
125+
R->>CD: Lints emit to stderr
126+
CD->>CT: Output files
127+
CT->>FS: Compare .stderr etc.
128+
alt Mismatch & bless
129+
CT->>FS: Update expected files
130+
end
131+
CT->>CT: Validate
132+
end
133+
CT-->>C: pass/fail
134+
```
135+
136+
## lint-development Analysis
137+
### Summary of design changes
138+
No fundamental changes to the workflow design or automation tools (e.g., `cargo dev new_lint`, `update_lints`). The PR manually adds the lint module, declaration via `declare_clippy_lint!`, UI test dir, updates to `lib.rs` (mod and register call), and `declared_lints.rs` (LINTS entry), following the integration pattern. The lint's recursive type walker is a self-contained impl in the pass, using existing `clippy_utils` and rustc APIs, without new utils or macros.
139+
140+
How implemented: `check_item` collects Ty/hir::Ty pairs from items/generics/fn sigs/impl items/trait items, walks recursively matching kinds, checks alias generics for explicit defaults matching resolved.
141+
142+
Benefits: Streamlines lint development for type-related analyses; new lint promotes idiomatic use of type alias defaults. Implications: As draft, needs `cargo dev update_lints` run, full tests, fmt; limitation on bounds in trait objects/impl types noted.
143+
144+
Mermaid diagrams needing update: Integration sequence extended with new lint; scaffolding used manually but diagram shows tool flow (no change needed as optional).
145+
146+
```mermaid
147+
sequenceDiagram
148+
participant User
149+
participant "cargo clippy" as CargoClippy
150+
participant "clippy-driver" as Driver
151+
participant "clippy_lints" as LintsCrate
152+
participant "LintStore" as Store
153+
participant Compiler as Rustc
154+
User->>CargoClippy: run cargo clippy on project
155+
CargoClippy->>Driver: invoke driver
156+
Driver->>LintsCrate: load & call register_lint_passes on store
157+
note over Driver,LintsCrate: green: registers new ExplicitDefaultArguments
158+
LintsCrate->>Store: extend early and late passes with lint impls
159+
note over LintsCrate,Store: green addition: + new ExplicitDefaultArguments late pass
160+
Driver->>Store: create LintListBuilder, insert declared_lints LINTS, register lints and groups
161+
note over Driver,Store: green addition: + EXPLICIT_DEFAULT_ARGUMENTS_INFO in LINTS
162+
Driver->>Compiler: run with registered lints
163+
Store->>Compiler: execute lint passes during compilation phases
164+
note over Store,Compiler: green addition: execution includes new lint pass
165+
Compiler->>User: output diagnostics from lints
166+
note over Compiler,User: green addition: + diagnostics from explicit_default_arguments if triggered
167+
```
168+
169+
## release-process Analysis
170+
### Summary of design changes
171+
No changes to the release steps or tools. The PR proactively adds a changelog entry `changelog: [`explicit_default_arguments`]: TODO` and link in the lints list, which will be curated/expanded during the "Update CHANGELOG.md" step using `fetch_prs_between.sh` and manual editing for categories like New Lints.
172+
173+
How implemented: Minimal placeholder in CHANGELOG.md for future release notes.
174+
175+
Benefits: Prepares documentation for the new lint's introduction. Implications: Will be included in next release changelog after completion.
176+
177+
Mermaid diagrams needing update: The sequence diagram's changelog update step now incorporates this PR's contribution.
178+
179+
```mermaid
180+
sequenceDiagram
181+
participant M as Maintainer
182+
participant CR as ClippyRepo
183+
participant GH as GitHub
184+
rect rgb(204,229,255)
185+
note over M,GH: 5. Update CHANGELOG.md
186+
M->>+GH: execute fetch_prs_between.sh for PRs
187+
GH->>-M: provide formatted PR details and links
188+
note over GH,M: green addition: includes details from #16123 (new lint PR)
189+
M->>CR: curate content, edit CHANGELOG.md sections
190+
note over M,CR: green addition: add/expand entry for explicit_default_arguments lint
191+
note over M,CR: green: new lint mentioned in New Lints category
192+
M->>CR: commit/push updates
193+
end
194+
```

0 commit comments

Comments
 (0)