File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
compiler/rustc_macros/src/diagnostics Expand file tree Collapse file tree 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> {
3030 pub ( crate ) fn into_tokens ( self ) -> TokenStream {
3131 let DiagnosticDerive { mut structure, mut builder } = self ;
3232
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+
3349 let slugs = RefCell :: new ( Vec :: new ( ) ) ;
3450 let implementation = builder. each_variant ( & mut structure, |mut builder, variant| {
3551 let preamble = builder. preamble ( variant) ;
You can’t perform that action at this time.
0 commit comments