Skip to content

Commit d69403a

Browse files
committed
Properly emit diagnostic for diagnostic::on_move being used without feature gate
1 parent 21925e9 commit d69403a

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_move.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl OnMoveParser {
2424
mode: Mode,
2525
) {
2626
if !cx.features().diagnostic_on_move() {
27+
// `UnknownDiagnosticAttribute` is emitted in rustc_resolve/macros.rs
2728
return;
2829
}
2930

compiler/rustc_resolve/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
715715
const DIAGNOSTIC_ATTRIBUTES: &[(Symbol, Option<Symbol>)] = &[
716716
(sym::on_unimplemented, None),
717717
(sym::do_not_recommend, None),
718-
(sym::on_move, None),
718+
(sym::on_move, Some(sym::diagnostic_on_move)),
719719
(sym::on_const, Some(sym::diagnostic_on_const)),
720720
(sym::on_unknown, Some(sym::diagnostic_on_unknown)),
721721
];

tests/ui/feature-gates/feature-gate-diagnostic-on-move.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
//! gate, but the fact that not adding the feature gate will cause the
33
//! diagnostic to not emit the custom diagnostic message
44
//!
5-
#[diagnostic::on_move(
6-
message = "Foo"
7-
)]
5+
#[diagnostic::on_move(message = "Foo")]
6+
//~^ WARN unknown diagnostic attribute
87
#[derive(Debug)]
98
struct Foo;
109

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
warning: unknown diagnostic attribute
2+
--> $DIR/feature-gate-diagnostic-on-move.rs:5:15
3+
|
4+
LL | #[diagnostic::on_move(message = "Foo")]
5+
| ^^^^^^^
6+
|
7+
= note: `#[warn(unknown_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default
8+
19
error[E0382]: use of moved value: `foo`
2-
--> $DIR/feature-gate-diagnostic-on-move.rs:16:15
10+
--> $DIR/feature-gate-diagnostic-on-move.rs:15:15
311
|
412
LL | let foo = Foo;
513
| --- move occurs because `foo` has type `Foo`, which does not implement the `Copy` trait
@@ -9,21 +17,21 @@ LL | let bar = foo;
917
| ^^^ value used here after move
1018
|
1119
note: consider changing this parameter type in function `takes_foo` to borrow instead if owning the value isn't necessary
12-
--> $DIR/feature-gate-diagnostic-on-move.rs:11:17
20+
--> $DIR/feature-gate-diagnostic-on-move.rs:10:17
1321
|
1422
LL | fn takes_foo(_: Foo) {}
1523
| --------- ^^^ this parameter takes ownership of the value
1624
| |
1725
| in this function
1826
note: if `Foo` implemented `Clone`, you could clone the value
19-
--> $DIR/feature-gate-diagnostic-on-move.rs:9:1
27+
--> $DIR/feature-gate-diagnostic-on-move.rs:8:1
2028
|
2129
LL | struct Foo;
2230
| ^^^^^^^^^^ consider implementing `Clone` for this type
2331
...
2432
LL | takes_foo(foo);
2533
| --- you could clone this value
2634

27-
error: aborting due to 1 previous error
35+
error: aborting due to 1 previous error; 1 warning emitted
2836

2937
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)