44//! conflicts between multiple such attributes attached to the same
55//! item.
66
7- use crate :: errors:: {
8- self , AttrApplication , DebugVisualizerUnreadable , InvalidAttrAtCrateLevel , ObjectLifetimeErr ,
9- OnlyHasEffectOn , ProcMacroDiffArguments , ProcMacroInvalidAbi , ProcMacroMissingArguments ,
10- ProcMacroTypeError , ProcMacroUnsafe , TransparentIncompatible , UnrecognizedReprHint ,
11- } ;
7+ use crate :: errors;
128use rustc_ast:: { ast, AttrStyle , Attribute , LitKind , MetaItemKind , MetaItemLit , NestedMetaItem } ;
139use rustc_data_structures:: fx:: FxHashMap ;
1410use rustc_errors:: { fluent, Applicability , IntoDiagnosticArg , MultiSpan } ;
@@ -399,7 +395,7 @@ impl CheckAttrVisitor<'_> {
399395 UNUSED_ATTRIBUTES ,
400396 hir_id,
401397 attr. span ,
402- OnlyHasEffectOn {
398+ errors :: OnlyHasEffectOn {
403399 attr_name : attr. name_or_empty ( ) ,
404400 target_name : allowed_target. name ( ) . replace ( ' ' , "_" ) ,
405401 } ,
@@ -468,7 +464,7 @@ impl CheckAttrVisitor<'_> {
468464 ObjectLifetimeDefault :: Param ( def_id) => tcx. item_name ( def_id) . to_string ( ) ,
469465 ObjectLifetimeDefault :: Ambiguous => "Ambiguous" . to_owned ( ) ,
470466 } ;
471- tcx. sess . emit_err ( ObjectLifetimeErr { span : p. span , repr } ) ;
467+ tcx. sess . emit_err ( errors :: ObjectLifetimeErr { span : p. span , repr } ) ;
472468 }
473469 }
474470 }
@@ -1715,7 +1711,7 @@ impl CheckAttrVisitor<'_> {
17151711 match target {
17161712 Target :: Struct | Target :: Union | Target :: Enum => continue ,
17171713 _ => {
1718- self . tcx . sess . emit_err ( AttrApplication :: StructEnumUnion {
1714+ self . tcx . sess . emit_err ( errors :: AttrApplication :: StructEnumUnion {
17191715 hint_span : hint. span ( ) ,
17201716 span,
17211717 } ) ;
@@ -1736,16 +1732,18 @@ impl CheckAttrVisitor<'_> {
17361732 match target {
17371733 Target :: Struct | Target :: Union | Target :: Enum | Target :: Fn => continue ,
17381734 _ => {
1739- self . tcx . sess . emit_err ( AttrApplication :: StructEnumFunctionUnion {
1740- hint_span : hint. span ( ) ,
1741- span,
1742- } ) ;
1735+ self . tcx . sess . emit_err (
1736+ errors:: AttrApplication :: StructEnumFunctionUnion {
1737+ hint_span : hint. span ( ) ,
1738+ span,
1739+ } ,
1740+ ) ;
17431741 }
17441742 }
17451743 }
17461744 sym:: packed => {
17471745 if target != Target :: Struct && target != Target :: Union {
1748- self . tcx . sess . emit_err ( AttrApplication :: StructUnion {
1746+ self . tcx . sess . emit_err ( errors :: AttrApplication :: StructUnion {
17491747 hint_span : hint. span ( ) ,
17501748 span,
17511749 } ) ;
@@ -1756,9 +1754,10 @@ impl CheckAttrVisitor<'_> {
17561754 sym:: simd => {
17571755 is_simd = true ;
17581756 if target != Target :: Struct {
1759- self . tcx
1760- . sess
1761- . emit_err ( AttrApplication :: Struct { hint_span : hint. span ( ) , span } ) ;
1757+ self . tcx . sess . emit_err ( errors:: AttrApplication :: Struct {
1758+ hint_span : hint. span ( ) ,
1759+ span,
1760+ } ) ;
17621761 } else {
17631762 continue ;
17641763 }
@@ -1768,7 +1767,7 @@ impl CheckAttrVisitor<'_> {
17681767 match target {
17691768 Target :: Struct | Target :: Union | Target :: Enum => continue ,
17701769 _ => {
1771- self . tcx . sess . emit_err ( AttrApplication :: StructEnumUnion {
1770+ self . tcx . sess . emit_err ( errors :: AttrApplication :: StructEnumUnion {
17721771 hint_span : hint. span ( ) ,
17731772 span,
17741773 } ) ;
@@ -1789,15 +1788,16 @@ impl CheckAttrVisitor<'_> {
17891788 | sym:: usize => {
17901789 int_reprs += 1 ;
17911790 if target != Target :: Enum {
1792- self . tcx
1793- . sess
1794- . emit_err ( AttrApplication :: Enum { hint_span : hint. span ( ) , span } ) ;
1791+ self . tcx . sess . emit_err ( errors:: AttrApplication :: Enum {
1792+ hint_span : hint. span ( ) ,
1793+ span,
1794+ } ) ;
17951795 } else {
17961796 continue ;
17971797 }
17981798 }
17991799 _ => {
1800- self . tcx . sess . emit_err ( UnrecognizedReprHint { span : hint. span ( ) } ) ;
1800+ self . tcx . sess . emit_err ( errors :: UnrecognizedReprHint { span : hint. span ( ) } ) ;
18011801 continue ;
18021802 }
18031803 } ;
@@ -1810,9 +1810,10 @@ impl CheckAttrVisitor<'_> {
18101810 // Error on repr(transparent, <anything else>).
18111811 if is_transparent && hints. len ( ) > 1 {
18121812 let hint_spans: Vec < _ > = hint_spans. clone ( ) . collect ( ) ;
1813- self . tcx
1814- . sess
1815- . emit_err ( TransparentIncompatible { hint_spans, target : target. to_string ( ) } ) ;
1813+ self . tcx . sess . emit_err ( errors:: TransparentIncompatible {
1814+ hint_spans,
1815+ target : target. to_string ( ) ,
1816+ } ) ;
18161817 }
18171818 // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
18181819 if ( int_reprs > 1 )
@@ -1965,7 +1966,7 @@ impl CheckAttrVisitor<'_> {
19651966 match std:: fs:: File :: open ( & file) {
19661967 Ok ( _) => true ,
19671968 Err ( error) => {
1968- self . tcx . sess . emit_err ( DebugVisualizerUnreadable {
1969+ self . tcx . sess . emit_err ( errors :: DebugVisualizerUnreadable {
19691970 span : meta_item. span ,
19701971 file : & file,
19711972 error,
@@ -2175,20 +2176,23 @@ impl CheckAttrVisitor<'_> {
21752176 let drcx = DeepRejectCtxt { treat_obligation_params : TreatParams :: AsInfer } ;
21762177
21772178 if sig. abi != Abi :: Rust {
2178- tcx. sess . emit_err ( ProcMacroInvalidAbi { span : hir_sig. span , abi : sig. abi . name ( ) } ) ;
2179+ tcx. sess . emit_err ( errors:: ProcMacroInvalidAbi {
2180+ span : hir_sig. span ,
2181+ abi : sig. abi . name ( ) ,
2182+ } ) ;
21792183 self . abort . set ( true ) ;
21802184 }
21812185
21822186 if sig. unsafety == Unsafety :: Unsafe {
2183- tcx. sess . emit_err ( ProcMacroUnsafe { span : hir_sig. span } ) ;
2187+ tcx. sess . emit_err ( errors :: ProcMacroUnsafe { span : hir_sig. span } ) ;
21842188 self . abort . set ( true ) ;
21852189 }
21862190
21872191 let output = sig. output ( ) ;
21882192
21892193 // Typecheck the output
21902194 if !drcx. types_may_unify ( output, tokenstream) {
2191- tcx. sess . emit_err ( ProcMacroTypeError {
2195+ tcx. sess . emit_err ( errors :: ProcMacroTypeError {
21922196 span : hir_sig. decl . output . span ( ) ,
21932197 found : output,
21942198 kind,
@@ -2198,7 +2202,7 @@ impl CheckAttrVisitor<'_> {
21982202 }
21992203
22002204 if sig. inputs ( ) . len ( ) < expected_input_count {
2201- tcx. sess . emit_err ( ProcMacroMissingArguments {
2205+ tcx. sess . emit_err ( errors :: ProcMacroMissingArguments {
22022206 expected_input_count,
22032207 span : hir_sig. span ,
22042208 kind,
@@ -2213,7 +2217,7 @@ impl CheckAttrVisitor<'_> {
22132217 sig. inputs ( ) . iter ( ) . zip ( hir_sig. decl . inputs ) . take ( expected_input_count)
22142218 {
22152219 if !drcx. types_may_unify ( * arg, tokenstream) {
2216- tcx. sess . emit_err ( ProcMacroTypeError {
2220+ tcx. sess . emit_err ( errors :: ProcMacroTypeError {
22172221 span : input. span ,
22182222 found : * arg,
22192223 kind,
@@ -2228,7 +2232,7 @@ impl CheckAttrVisitor<'_> {
22282232 let body_id = tcx. hir ( ) . body_owned_by ( id. def_id ) ;
22292233 let excess = tcx. hir ( ) . body ( body_id) . params . get ( expected_input_count..) ;
22302234 if let Some ( excess @ [ begin @ end] | excess @ [ begin, .., end] ) = excess {
2231- tcx. sess . emit_err ( ProcMacroDiffArguments {
2235+ tcx. sess . emit_err ( errors :: ProcMacroDiffArguments {
22322236 span : begin. span . to ( end. span ) ,
22332237 count : excess. len ( ) ,
22342238 kind,
@@ -2378,7 +2382,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
23782382 if attr. style == AttrStyle :: Inner {
23792383 for attr_to_check in ATTRS_TO_CHECK {
23802384 if attr. has_name ( * attr_to_check) {
2381- tcx. sess . emit_err ( InvalidAttrAtCrateLevel {
2385+ tcx. sess . emit_err ( errors :: InvalidAttrAtCrateLevel {
23822386 span : attr. span ,
23832387 snippet : tcx. sess . source_map ( ) . span_to_snippet ( attr. span ) . ok ( ) ,
23842388 name : * attr_to_check,
0 commit comments