@@ -13,7 +13,6 @@ use rustc_parse::validate_attr;
1313use rustc_session:: lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ;
1414use rustc_session:: lint:: LintBuffer ;
1515use rustc_session:: Session ;
16- use rustc_span:: source_map:: Spanned ;
1716use rustc_span:: symbol:: { kw, sym} ;
1817use rustc_span:: Span ;
1918use std:: mem;
@@ -234,16 +233,11 @@ impl<'a> AstValidator<'a> {
234233 }
235234 }
236235
237- fn check_trait_fn_not_const ( & self , constness : Spanned < Constness > ) {
238- if constness. node == Constness :: Const {
239- struct_span_err ! (
240- self . session,
241- constness. span,
242- E0379 ,
243- "trait fns cannot be declared const"
244- )
245- . span_label ( constness. span , "trait fns cannot be const" )
246- . emit ( ) ;
236+ fn check_trait_fn_not_const ( & self , constness : Const ) {
237+ if let Const :: Yes ( span) = constness {
238+ struct_span_err ! ( self . session, span, E0379 , "trait fns cannot be declared const" )
239+ . span_label ( span, "trait fns cannot be const" )
240+ . emit ( ) ;
247241 }
248242 }
249243
@@ -487,7 +481,7 @@ impl<'a> AstValidator<'a> {
487481 ( Some ( FnCtxt :: Foreign ) , _) => return ,
488482 ( Some ( FnCtxt :: Free ) , Some ( header) ) => match header. ext {
489483 Extern :: Explicit ( StrLit { symbol_unescaped : sym:: C , .. } ) | Extern :: Implicit
490- if header. unsafety == Unsafety :: Unsafe =>
484+ if matches ! ( header. unsafety, Unsafe :: Yes ( _ ) ) =>
491485 {
492486 return ;
493487 }
@@ -514,12 +508,13 @@ impl<'a> AstValidator<'a> {
514508 /// FIXME(const_generics): Is this really true / necessary? Discuss with @varkor.
515509 /// At any rate, the restriction feels too syntactic. Consider moving it to e.g. typeck.
516510 fn check_const_fn_const_generic ( & self , span : Span , sig : & FnSig , generics : & Generics ) {
517- if sig. header . constness . node == Constness :: Const {
511+ if let Const :: Yes ( const_span ) = sig. header . constness {
518512 // Look for const generics and error if we find any.
519513 for param in & generics. params {
520514 if let GenericParamKind :: Const { .. } = param. kind {
521515 self . err_handler ( )
522516 . struct_span_err ( span, "const parameters are not permitted in `const fn`" )
517+ . span_label ( const_span, "`const fn` because of this" )
523518 . emit ( ) ;
524519 }
525520 }
@@ -754,13 +749,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
754749 . help ( "use `auto trait Trait {}` instead" )
755750 . emit ( ) ;
756751 }
757- if unsafety == Unsafety :: Unsafe && polarity == ImplPolarity :: Negative {
752+ if let ( Unsafe :: Yes ( span ) , ImplPolarity :: Negative ) = ( unsafety , polarity ) {
758753 struct_span_err ! (
759754 this. session,
760755 item. span,
761756 E0198 ,
762757 "negative impls cannot be unsafe"
763758 )
759+ . span_label ( span, "unsafe because of this" )
764760 . emit ( ) ;
765761 }
766762
@@ -782,13 +778,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
782778 & item. vis ,
783779 Some ( "place qualifiers on individual impl items instead" ) ,
784780 ) ;
785- if unsafety == Unsafety :: Unsafe {
781+ if let Unsafe :: Yes ( span ) = unsafety {
786782 struct_span_err ! (
787783 self . session,
788784 item. span,
789785 E0197 ,
790786 "inherent impls cannot be unsafe"
791787 )
788+ . span_label ( span, "unsafe because of this" )
792789 . emit ( ) ;
793790 }
794791 if polarity == ImplPolarity :: Negative {
@@ -800,9 +797,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
800797 . note ( "only trait implementations may be annotated with default" )
801798 . emit ( ) ;
802799 }
803- if constness == Constness :: Const {
800+ if let Const :: Yes ( span ) = constness {
804801 self . err_handler ( )
805802 . struct_span_err ( item. span , "inherent impls cannot be `const`" )
803+ . span_label ( span, "`const` because of this" )
806804 . note ( "only trait implementations may be annotated with `const`" )
807805 . emit ( ) ;
808806 }
0 commit comments