@@ -8,11 +8,13 @@ use crate::hir::def_id::DefId;
8
8
use crate :: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
9
9
use crate :: hir:: DUMMY_HIR_ID ;
10
10
use 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 } ;
12
12
use crate :: ty:: query:: Providers ;
13
13
use crate :: ty:: TyCtxt ;
14
14
15
+ use errors:: { error_code, struct_span_err} ;
15
16
use rustc_span:: Span ;
17
+
16
18
use std:: fmt:: { self , Display } ;
17
19
use syntax:: { attr, symbol:: sym} ;
18
20
@@ -192,7 +194,7 @@ impl CheckAttrVisitor<'tcx> {
192
194
self . tcx . codegen_fn_attrs ( self . tcx . hir ( ) . local_def_id ( hir_id) ) ;
193
195
}
194
196
195
- self . check_repr ( attrs, span, target, item) ;
197
+ self . check_repr ( attrs, span, target, item, hir_id ) ;
196
198
self . check_used ( attrs, target) ;
197
199
}
198
200
@@ -353,6 +355,7 @@ impl CheckAttrVisitor<'tcx> {
353
355
span : & Span ,
354
356
target : Target ,
355
357
item : Option < & Item < ' _ > > ,
358
+ hir_id : HirId ,
356
359
) {
357
360
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
358
361
// ```
@@ -428,21 +431,29 @@ impl CheckAttrVisitor<'tcx> {
428
431
// Error on repr(transparent, <anything else>).
429
432
if is_transparent && hints. len ( ) > 1 {
430
433
let hint_spans: Vec < _ > = hint_spans. clone ( ) . collect ( ) ;
431
- span_err ! (
434
+ struct_span_err ! (
432
435
self . tcx. sess,
433
436
hint_spans,
434
437
E0692 ,
435
438
"transparent {} cannot have other repr hints" ,
436
439
target
437
- ) ;
440
+ )
441
+ . emit ( ) ;
438
442
}
439
443
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
440
444
if ( int_reprs > 1 )
441
445
|| ( is_simd && is_c)
442
446
|| ( int_reprs == 1 && is_c && item. map_or ( false , |item| is_c_like_enum ( item) ) )
443
447
{
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 ( ) ;
446
457
}
447
458
}
448
459
0 commit comments