-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit b1d2f2c
Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk
Split up the `unknown_or_malformed_diagnostic_attributes` lint
This splits up the lint into the following lint group:
- `unknown_diagnostic_attributes` - triggers if the attribute is unknown to the current compiler
- `misplaced_diagnostic_attributes` - triggers if the attribute exists but it is not placed on the item kind it's meant for
- `malformed_diagnostic_attributes` - triggers if the attribute's syntax or options are invalid
- `malformed_diagnostic_format_literals` - triggers if the format string literal is invalid, for example if it has unpaired curly braces or invalid parameters
- this pr doesn't create it, but future lints for things like deprecations can also go here.
This PR does not start emitting lints in places that previously did not.
## Motivation
I want to have finer control over what `unknown_or_malformed_diagnostic_attributes` does
I have a project with fairly low msrv that is/will have a lower msrv than future diagnostic attributes. So lints will be emitted when I or others compile it on a lower msrv.
At this time, there are two options to silence these lints:
- `#[allow(unknown_or_malformed_diagnostic_attributes)]` - this risks diagnostic regressions if I (or others) mess up using the attribute, or if the attribute's syntax ever changes.
- write a build script to detect the compiler version and emit cfgs, and then conditionally enable the attribute:
```rust
#[cfg_attr(rust_version_99, diagnostic::new_attr_in_rust_99(thing = ..))]`
struct Foo;
```
or conditionally `allow` the lint:
```rust
// lib.rs
#![cfg_attr(not(current_rust), allow(unknown_or_malformed_diagnostic_attributes))]
```
I like to avoid using build scripts if I can, so the following works much better for me. That is what this PR will let me do in the future:
```rust
#[allow(unknown_diagnostic_attribute, reason = "attribute came out in rust 1.99 but msrv is 1.70")]
#[diagnostic::new_attr_in_rust_99(thing = ..)]`
struct Foo;File tree
25 files changed
+157
-59
lines changed- compiler
- rustc_lint_defs/src
- rustc_lint/src
- rustc_passes/src
- rustc_resolve/src
- rustc_trait_selection/src/error_reporting/traits
- src/tools/lint-docs/src
- tests/ui
- attributes
- diagnostic_namespace
- do_not_recommend
- on_unimplemented
25 files changed
+157
-59
lines changedLines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
339 | 339 |
| |
340 | 340 |
| |
341 | 341 |
| |
342 | + | ||
343 | + | ||
344 | + | ||
345 | + | ||
346 | + | ||
347 | + | ||
348 | + | ||
349 | + | ||
342 | 350 |
| |
343 | 351 |
| |
344 | 352 |
| |
|
Lines changed: 89 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
66 | + | ||
67 | + | ||
66 | 68 |
| |
69 | + | ||
67 | 70 |
| |
68 | 71 |
| |
69 | 72 |
| |
| |||
112 | 115 |
| |
113 | 116 |
| |
114 | 117 |
| |
118 | + | ||
115 | 119 |
| |
116 | - | ||
117 | 120 |
| |
118 | 121 |
| |
119 | 122 |
| |
| |||
4284 | 4287 |
| |
4285 | 4288 |
| |
4286 | 4289 |
| |
4287 | - | ||
4288 | - | ||
4290 | + | ||
4289 | 4291 |
| |
4290 | 4292 |
| |
4291 | 4293 |
| |
4292 | 4294 |
| |
4293 | - | ||
4294 | - | ||
4295 | - | ||
4295 | + | ||
4296 | + | ||
4296 | 4297 |
| |
4297 | 4298 |
| |
4298 | 4299 |
| |
4299 | 4300 |
| |
4301 | + | ||
4302 | + | ||
4303 | + | ||
4304 | + | ||
4305 | + | ||
4306 | + | ||
4307 | + | ||
4308 | + | ||
4309 | + | ||
4310 | + | ||
4311 | + | ||
4312 | + | ||
4313 | + | ||
4314 | + | ||
4315 | + | ||
4316 | + | ||
4317 | + | ||
4318 | + | ||
4319 | + | ||
4320 | + | ||
4321 | + | ||
4322 | + | ||
4323 | + | ||
4324 | + | ||
4325 | + | ||
4300 | 4326 |
| |
4301 | 4327 |
| |
4302 | 4328 |
| |
4303 | - | ||
4304 | - | ||
4305 | - | ||
4306 | - | ||
4307 | - | ||
4329 | + | ||
4330 | + | ||
4331 | + | ||
4332 | + | ||
4333 | + | ||
4334 | + | ||
4335 | + | ||
4308 | 4336 |
| |
4309 | - | ||
4337 | + | ||
4310 | 4338 |
| |
4311 | 4339 |
| |
4340 | + | ||
4341 | + | ||
4342 | + | ||
4343 | + | ||
4344 | + | ||
4345 | + | ||
4346 | + | ||
4347 | + | ||
4348 | + | ||
4349 | + | ||
4350 | + | ||
4351 | + | ||
4352 | + | ||
4353 | + | ||
4354 | + | ||
4355 | + | ||
4356 | + | ||
4357 | + | ||
4358 | + | ||
4359 | + | ||
4360 | + | ||
4361 | + | ||
4362 | + | ||
4363 | + | ||
4364 | + | ||
4365 | + | ||
4366 | + | ||
4367 | + | ||
4368 | + | ||
4369 | + | ||
4370 | + | ||
4371 | + | ||
4372 | + | ||
4373 | + | ||
4374 | + | ||
4375 | + | ||
4376 | + | ||
4377 | + | ||
4378 | + | ||
4379 | + | ||
4380 | + | ||
4381 | + | ||
4382 | + | ||
4383 | + | ||
4384 | + | ||
4385 | + | ||
4386 | + | ||
4387 | + | ||
4388 | + | ||
4312 | 4389 |
| |
4313 | 4390 |
| |
4314 | 4391 |
| |
|
Lines changed: 6 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
36 | - | ||
36 | + | ||
37 | 37 |
| |
38 | 38 |
| |
39 | 39 |
| |
| |||
460 | 460 |
| |
461 | 461 |
| |
462 | 462 |
| |
463 | - | ||
463 | + | ||
464 | + | ||
464 | 465 |
| |
465 | 466 |
| |
466 | 467 |
| |
| |||
477 | 478 |
| |
478 | 479 |
| |
479 | 480 |
| |
480 | - | ||
481 | + | ||
481 | 482 |
| |
482 | 483 |
| |
483 | 484 |
| |
484 | 485 |
| |
485 | 486 |
| |
486 | 487 |
| |
487 | 488 |
| |
488 | - | ||
489 | + | ||
489 | 490 |
| |
490 | 491 |
| |
491 | 492 |
| |
| |||
497 | 498 |
| |
498 | 499 |
| |
499 | 500 |
| |
500 | - | ||
501 | + | ||
501 | 502 |
| |
502 | 503 |
| |
503 | 504 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
24 | 24 |
| |
25 | 25 |
| |
26 | 26 |
| |
27 | - | ||
27 | + | ||
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
| |||
689 | 689 |
| |
690 | 690 |
| |
691 | 691 |
| |
692 | - | ||
692 | + | ||
693 | 693 |
| |
694 | 694 |
| |
695 | 695 |
| |
|
Lines changed: 9 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
14 | - | ||
14 | + | ||
15 | + | ||
16 | + | ||
15 | 17 |
| |
16 | 18 |
| |
17 | 19 |
| |
| |||
382 | 384 |
| |
383 | 385 |
| |
384 | 386 |
| |
385 | - | ||
387 | + | ||
386 | 388 |
| |
387 | 389 |
| |
388 | 390 |
| |
| |||
533 | 535 |
| |
534 | 536 |
| |
535 | 537 |
| |
536 | - | ||
538 | + | ||
537 | 539 |
| |
538 | 540 |
| |
539 | 541 |
| |
| |||
689 | 691 |
| |
690 | 692 |
| |
691 | 693 |
| |
692 | - | ||
694 | + | ||
693 | 695 |
| |
694 | 696 |
| |
695 | 697 |
| |
| |||
702 | 704 |
| |
703 | 705 |
| |
704 | 706 |
| |
705 | - | ||
707 | + | ||
706 | 708 |
| |
707 | 709 |
| |
708 | 710 |
| |
| |||
712 | 714 |
| |
713 | 715 |
| |
714 | 716 |
| |
715 | - | ||
717 | + | ||
716 | 718 |
| |
717 | 719 |
| |
718 | 720 |
| |
| |||
859 | 861 |
| |
860 | 862 |
| |
861 | 863 |
| |
862 | - | ||
864 | + | ||
863 | 865 |
| |
864 | 866 |
| |
865 | 867 |
| |
|
Lines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7 | 7 |
| |
8 | 8 |
| |
9 | 9 |
| |
10 | - | ||
10 | + | ||
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
| |||
69 | 69 |
| |
70 | 70 |
| |
71 | 71 |
| |
72 | - | ||
72 | + | ||
73 | 73 |
| |
74 | 74 |
| |
75 | 75 |
| |
| |||
82 | 82 |
| |
83 | 83 |
| |
84 | 84 |
| |
85 | - | ||
85 | + | ||
86 | 86 |
| |
87 | 87 |
| |
88 | 88 |
| |
| |||
92 | 92 |
| |
93 | 93 |
| |
94 | 94 |
| |
95 | - | ||
95 | + | ||
96 | 96 |
| |
97 | 97 |
| |
98 | 98 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
29 | + | ||
30 | + | ||
31 | + | ||
32 | + | ||
29 | 33 |
| |
30 | 34 |
| |
31 | 35 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
594 | 594 |
| |
595 | 595 |
| |
596 | 596 |
| |
597 | - | ||
597 | + | ||
598 | 598 |
| |
599 | 599 |
| |
600 | 600 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
9 | 9 |
| |
10 | 10 |
| |
11 | 11 |
| |
12 | + | ||
12 | 13 |
| |
13 | 14 |
| |
14 | 15 |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4 | 4 |
| |
5 | 5 |
| |
6 | 6 |
| |
7 | - | ||
7 | + | ||
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
|
0 commit comments