Skip to content

Commit cde2934

Browse files
author
The rustc-josh-sync Cronjob Bot
committed
Merge ref 'ce63e5d9ea20' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: ce63e5d9ea20f15a70c6fdc4d4de7aee352fd965 Filtered ref: 3be97ed Upstream diff: rust-lang/rust@dfe1b8c...ce63e5d This merge was created using https://github.com/rust-lang/josh-sync.
2 parents fec3b64 + 3be97ed commit cde2934

File tree

3 files changed

+49
-42
lines changed

3 files changed

+49
-42
lines changed

src/bug-fix-procedure.md

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -91,40 +91,46 @@ future-compatibility warnings. These are a special category of lint warning.
9191
Adding a new future-compatibility warning can be done as follows.
9292

9393
```rust
94-
// 1. Define the lint in `compiler/rustc_middle/src/lint/builtin.rs`:
94+
// 1. Define the lint in `compiler/rustc_lint/src/builtin.rs` and
95+
// add the metadata for the future incompatibility:
9596
declare_lint! {
96-
pub YOUR_ERROR_HERE,
97+
pub YOUR_LINT_HERE,
9798
Warn,
9899
"illegal use of foo bar baz"
100+
@future_incompatible = FutureIncompatibleInfo {
101+
reason: fcw!(FutureReleaseError #1234) // your tracking issue here!
102+
},
99103
}
100104

101-
// 2. Add to the list of HardwiredLints in the same file:
102-
impl LintPass for HardwiredLints {
103-
fn get_lints(&self) -> LintArray {
104-
lint_array!(
105-
..,
106-
YOUR_ERROR_HERE
107-
)
108-
}
105+
// 2. Add a decidacted lint pass for it.
106+
// This step can be skipped if you emit the lint as part of an existing pass.
107+
108+
#[derive(Default)]
109+
pub struct MyLintPass {
110+
...
109111
}
110112

111-
// 3. Register the lint in `compiler/rustc_lint/src/lib.rs`:
112-
store.register_future_incompatible(sess, vec![
113-
...,
114-
FutureIncompatibleInfo {
115-
id: LintId::of(YOUR_ERROR_HERE),
116-
reference: "issue #1234", // your tracking issue here!
113+
impl {Early,Late}LintPass for MyLintPass {
114+
...
115+
}
116+
117+
impl_lint_pass!(MyLintPass => [YOUR_LINT_HERE]);
118+
119+
// 3. emit the lint somewhere in your lint pass:
120+
cx.emit_span_lint(
121+
YOUR_LINT_HERE,
122+
pat.span,
123+
// some diagnostic struct
124+
MyDiagnostic {
125+
...
117126
},
118-
]);
119-
120-
// 4. Report the lint:
121-
tcx.lint_node(
122-
lint::builtin::YOUR_ERROR_HERE,
123-
path_id,
124-
binding.span,
125-
format!("some helper message here"));
127+
);
128+
126129
```
127130

131+
Finally, register the lint in `compiler/rustc_lint/src/lib.rs`.
132+
There are many examples in that file that already show how to do so.
133+
128134
#### Helpful techniques
129135

130136
It can often be challenging to filter out new warnings from older, pre-existing
@@ -221,7 +227,10 @@ The first reference you will likely find is the lint definition [in
221227
declare_lint! {
222228
pub OVERLAPPING_INHERENT_IMPLS,
223229
Deny, // this may also say Warning
224-
"two overlapping inherent impls define an item with the same name were erroneously allowed"
230+
"two overlapping inherent impls define an item with the same name were erroneously allowed",
231+
@future_incompatible = FutureIncompatibleInfo {
232+
reason: fcw!(FutureReleaseError #1234), // your tracking issue here!
233+
},
225234
}
226235
```
227236

@@ -231,19 +240,6 @@ the file as [part of a `lint_array!`][lintarraysource]; remove it too.
231240

232241
[lintarraysource]: https://github.com/rust-lang/rust/blob/085d71c3efe453863739c1fb68fd9bd1beff214f/src/librustc/lint/builtin.rs#L252-L290
233242

234-
Next, you see [a reference to `OVERLAPPING_INHERENT_IMPLS` in
235-
`rustc_lint/src/lib.rs`][futuresource]. This is defining the lint as a "future
236-
compatibility lint":
237-
238-
```rust
239-
FutureIncompatibleInfo {
240-
id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
241-
reference: "issue #36889 <https://github.com/rust-lang/rust/issues/36889>",
242-
},
243-
```
244-
245-
Remove this too.
246-
247243
#### Add the lint to the list of removed lints.
248244

249245
In `compiler/rustc_lint/src/lib.rs` there is a list of "renamed and removed lints".
@@ -269,6 +265,8 @@ self.tcx.sess.add_lint(lint::builtin::OVERLAPPING_INHERENT_IMPLS,
269265
msg);
270266
```
271267

268+
You'll also often find `node_span_lint` used for this.
269+
272270
We want to convert this into an error. In some cases, there may be an
273271
existing error for this scenario. In others, we will need to allocate a
274272
fresh diagnostic code. [Instructions for allocating a fresh diagnostic
@@ -285,6 +283,17 @@ struct_span_code_err!(self.dcx(), self.tcx.span_of_impl(item1).unwrap(), E0592,
285283
.emit();
286284
```
287285

286+
Or better: a structured diagnostic like this:
287+
288+
```rust
289+
#[derive(Diagnostic)]
290+
struct MyDiagnostic {
291+
#[label]
292+
span: Span,
293+
...
294+
}
295+
```
296+
288297
#### Update tests
289298

290299
Finally, run the test suite. These should be some tests that used to reference

src/diagnostics.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,7 @@ declare_lint! {
732732
Allow,
733733
"detects anonymous parameters",
734734
@future_incompatible = FutureIncompatibleInfo {
735-
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
736-
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
735+
reason: fcw!(EditionError 2018 "slug-of-edition-guide-page")
737736
};
738737
}
739738
```

src/guides/editions.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ declare_lint! {
179179
Allow,
180180
"detects edition keywords being used as an identifier",
181181
@future_incompatible = FutureIncompatibleInfo {
182-
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
183-
reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>",
182+
reason: fcw!(EditionError 2018 "slug-of-edition-guide-page")
184183
};
185184
}
186185
```

0 commit comments

Comments
 (0)