@@ -8,11 +8,13 @@ use crate::hir::def_id::DefId;
88use crate :: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
99use crate :: hir:: DUMMY_HIR_ID ;
1010use crate :: hir:: { self , Attribute , HirId , Item , ItemKind , TraitItem , TraitItemKind } ;
11- use crate :: lint:: builtin:: UNUSED_ATTRIBUTES ;
11+ use crate :: lint:: builtin:: { CONFLICTING_REPR_HINTS , UNUSED_ATTRIBUTES } ;
1212use crate :: ty:: query:: Providers ;
1313use crate :: ty:: TyCtxt ;
1414
15+ use errors:: { error_code, struct_span_err} ;
1516use rustc_span:: Span ;
17+
1618use std:: fmt:: { self , Display } ;
1719use syntax:: { attr, symbol:: sym} ;
1820
@@ -192,7 +194,7 @@ impl CheckAttrVisitor<'tcx> {
192194 self . tcx . codegen_fn_attrs ( self . tcx . hir ( ) . local_def_id ( hir_id) ) ;
193195 }
194196
195- self . check_repr ( attrs, span, target, item) ;
197+ self . check_repr ( attrs, span, target, item, hir_id ) ;
196198 self . check_used ( attrs, target) ;
197199 }
198200
@@ -353,6 +355,7 @@ impl CheckAttrVisitor<'tcx> {
353355 span : & Span ,
354356 target : Target ,
355357 item : Option < & Item < ' _ > > ,
358+ hir_id : HirId ,
356359 ) {
357360 // Extract the names of all repr hints, e.g., [foo, bar, align] for:
358361 // ```
@@ -428,21 +431,29 @@ impl CheckAttrVisitor<'tcx> {
428431 // Error on repr(transparent, <anything else>).
429432 if is_transparent && hints. len ( ) > 1 {
430433 let hint_spans: Vec < _ > = hint_spans. clone ( ) . collect ( ) ;
431- span_err ! (
434+ struct_span_err ! (
432435 self . tcx. sess,
433436 hint_spans,
434437 E0692 ,
435438 "transparent {} cannot have other repr hints" ,
436439 target
437- ) ;
440+ )
441+ . emit ( ) ;
438442 }
439443 // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
440444 if ( int_reprs > 1 )
441445 || ( is_simd && is_c)
442446 || ( int_reprs == 1 && is_c && item. map_or ( false , |item| is_c_like_enum ( item) ) )
443447 {
444- let hint_spans: Vec < _ > = hint_spans. collect ( ) ;
445- span_warn ! ( self . tcx. sess, hint_spans, E0566 , "conflicting representation hints" ) ;
448+ self . tcx
449+ . struct_span_lint_hir (
450+ CONFLICTING_REPR_HINTS ,
451+ hir_id,
452+ hint_spans. collect :: < Vec < Span > > ( ) ,
453+ "conflicting representation hints" ,
454+ )
455+ . code ( error_code ! ( E0566 ) )
456+ . emit ( ) ;
446457 }
447458 }
448459
0 commit comments