File tree 1 file changed +16
-0
lines changed
compiler/rustc_macros/src/diagnostics
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,22 @@ impl<'a> DiagnosticDerive<'a> {
30
30
pub ( crate ) fn into_tokens ( self ) -> TokenStream {
31
31
let DiagnosticDerive { mut structure, mut builder } = self ;
32
32
33
+ if matches ! ( structure. ast( ) . data, syn:: Data :: Struct ( _) ) {
34
+ assert_eq ! ( structure. variants( ) . len( ) , 1 , "a struct can only have one variant" ) ;
35
+ if !structure. variants ( ) [ 0 ]
36
+ . ast ( )
37
+ . attrs
38
+ . iter ( )
39
+ . any ( |attr| attr. path ( ) . segments . last ( ) . unwrap ( ) . ident == "must_use" )
40
+ {
41
+ span_err (
42
+ structure. ast ( ) . span ( ) . unwrap ( ) ,
43
+ "You must mark diagnostic structs with `#[must_use]`" ,
44
+ )
45
+ . emit ( ) ;
46
+ }
47
+ }
48
+
33
49
let slugs = RefCell :: new ( Vec :: new ( ) ) ;
34
50
let implementation = builder. each_variant ( & mut structure, |mut builder, variant| {
35
51
let preamble = builder. preamble ( variant) ;
You can’t perform that action at this time.
0 commit comments