4
4
//! conflicts between multiple such attributes attached to the same
5
5
//! item.
6
6
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;
12
8
use rustc_ast:: { ast, AttrStyle , Attribute , LitKind , MetaItemKind , MetaItemLit , NestedMetaItem } ;
13
9
use rustc_data_structures:: fx:: FxHashMap ;
14
10
use rustc_errors:: { fluent, Applicability , IntoDiagnosticArg , MultiSpan } ;
@@ -399,7 +395,7 @@ impl CheckAttrVisitor<'_> {
399
395
UNUSED_ATTRIBUTES ,
400
396
hir_id,
401
397
attr. span ,
402
- OnlyHasEffectOn {
398
+ errors :: OnlyHasEffectOn {
403
399
attr_name : attr. name_or_empty ( ) ,
404
400
target_name : allowed_target. name ( ) . replace ( ' ' , "_" ) ,
405
401
} ,
@@ -468,7 +464,7 @@ impl CheckAttrVisitor<'_> {
468
464
ObjectLifetimeDefault :: Param ( def_id) => tcx. item_name ( def_id) . to_string ( ) ,
469
465
ObjectLifetimeDefault :: Ambiguous => "Ambiguous" . to_owned ( ) ,
470
466
} ;
471
- tcx. sess . emit_err ( ObjectLifetimeErr { span : p. span , repr } ) ;
467
+ tcx. sess . emit_err ( errors :: ObjectLifetimeErr { span : p. span , repr } ) ;
472
468
}
473
469
}
474
470
}
@@ -1715,7 +1711,7 @@ impl CheckAttrVisitor<'_> {
1715
1711
match target {
1716
1712
Target :: Struct | Target :: Union | Target :: Enum => continue ,
1717
1713
_ => {
1718
- self . tcx . sess . emit_err ( AttrApplication :: StructEnumUnion {
1714
+ self . tcx . sess . emit_err ( errors :: AttrApplication :: StructEnumUnion {
1719
1715
hint_span : hint. span ( ) ,
1720
1716
span,
1721
1717
} ) ;
@@ -1736,16 +1732,18 @@ impl CheckAttrVisitor<'_> {
1736
1732
match target {
1737
1733
Target :: Struct | Target :: Union | Target :: Enum | Target :: Fn => continue ,
1738
1734
_ => {
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
+ ) ;
1743
1741
}
1744
1742
}
1745
1743
}
1746
1744
sym:: packed => {
1747
1745
if target != Target :: Struct && target != Target :: Union {
1748
- self . tcx . sess . emit_err ( AttrApplication :: StructUnion {
1746
+ self . tcx . sess . emit_err ( errors :: AttrApplication :: StructUnion {
1749
1747
hint_span : hint. span ( ) ,
1750
1748
span,
1751
1749
} ) ;
@@ -1756,9 +1754,10 @@ impl CheckAttrVisitor<'_> {
1756
1754
sym:: simd => {
1757
1755
is_simd = true ;
1758
1756
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
+ } ) ;
1762
1761
} else {
1763
1762
continue ;
1764
1763
}
@@ -1768,7 +1767,7 @@ impl CheckAttrVisitor<'_> {
1768
1767
match target {
1769
1768
Target :: Struct | Target :: Union | Target :: Enum => continue ,
1770
1769
_ => {
1771
- self . tcx . sess . emit_err ( AttrApplication :: StructEnumUnion {
1770
+ self . tcx . sess . emit_err ( errors :: AttrApplication :: StructEnumUnion {
1772
1771
hint_span : hint. span ( ) ,
1773
1772
span,
1774
1773
} ) ;
@@ -1789,15 +1788,16 @@ impl CheckAttrVisitor<'_> {
1789
1788
| sym:: usize => {
1790
1789
int_reprs += 1 ;
1791
1790
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
+ } ) ;
1795
1795
} else {
1796
1796
continue ;
1797
1797
}
1798
1798
}
1799
1799
_ => {
1800
- self . tcx . sess . emit_err ( UnrecognizedReprHint { span : hint. span ( ) } ) ;
1800
+ self . tcx . sess . emit_err ( errors :: UnrecognizedReprHint { span : hint. span ( ) } ) ;
1801
1801
continue ;
1802
1802
}
1803
1803
} ;
@@ -1810,9 +1810,10 @@ impl CheckAttrVisitor<'_> {
1810
1810
// Error on repr(transparent, <anything else>).
1811
1811
if is_transparent && hints. len ( ) > 1 {
1812
1812
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
+ } ) ;
1816
1817
}
1817
1818
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
1818
1819
if ( int_reprs > 1 )
@@ -1965,7 +1966,7 @@ impl CheckAttrVisitor<'_> {
1965
1966
match std:: fs:: File :: open ( & file) {
1966
1967
Ok ( _) => true ,
1967
1968
Err ( error) => {
1968
- self . tcx . sess . emit_err ( DebugVisualizerUnreadable {
1969
+ self . tcx . sess . emit_err ( errors :: DebugVisualizerUnreadable {
1969
1970
span : meta_item. span ,
1970
1971
file : & file,
1971
1972
error,
@@ -2175,20 +2176,23 @@ impl CheckAttrVisitor<'_> {
2175
2176
let drcx = DeepRejectCtxt { treat_obligation_params : TreatParams :: AsInfer } ;
2176
2177
2177
2178
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
+ } ) ;
2179
2183
self . abort . set ( true ) ;
2180
2184
}
2181
2185
2182
2186
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 } ) ;
2184
2188
self . abort . set ( true ) ;
2185
2189
}
2186
2190
2187
2191
let output = sig. output ( ) ;
2188
2192
2189
2193
// Typecheck the output
2190
2194
if !drcx. types_may_unify ( output, tokenstream) {
2191
- tcx. sess . emit_err ( ProcMacroTypeError {
2195
+ tcx. sess . emit_err ( errors :: ProcMacroTypeError {
2192
2196
span : hir_sig. decl . output . span ( ) ,
2193
2197
found : output,
2194
2198
kind,
@@ -2198,7 +2202,7 @@ impl CheckAttrVisitor<'_> {
2198
2202
}
2199
2203
2200
2204
if sig. inputs ( ) . len ( ) < expected_input_count {
2201
- tcx. sess . emit_err ( ProcMacroMissingArguments {
2205
+ tcx. sess . emit_err ( errors :: ProcMacroMissingArguments {
2202
2206
expected_input_count,
2203
2207
span : hir_sig. span ,
2204
2208
kind,
@@ -2213,7 +2217,7 @@ impl CheckAttrVisitor<'_> {
2213
2217
sig. inputs ( ) . iter ( ) . zip ( hir_sig. decl . inputs ) . take ( expected_input_count)
2214
2218
{
2215
2219
if !drcx. types_may_unify ( * arg, tokenstream) {
2216
- tcx. sess . emit_err ( ProcMacroTypeError {
2220
+ tcx. sess . emit_err ( errors :: ProcMacroTypeError {
2217
2221
span : input. span ,
2218
2222
found : * arg,
2219
2223
kind,
@@ -2228,7 +2232,7 @@ impl CheckAttrVisitor<'_> {
2228
2232
let body_id = tcx. hir ( ) . body_owned_by ( id. def_id ) ;
2229
2233
let excess = tcx. hir ( ) . body ( body_id) . params . get ( expected_input_count..) ;
2230
2234
if let Some ( excess @ [ begin @ end] | excess @ [ begin, .., end] ) = excess {
2231
- tcx. sess . emit_err ( ProcMacroDiffArguments {
2235
+ tcx. sess . emit_err ( errors :: ProcMacroDiffArguments {
2232
2236
span : begin. span . to ( end. span ) ,
2233
2237
count : excess. len ( ) ,
2234
2238
kind,
@@ -2378,7 +2382,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
2378
2382
if attr. style == AttrStyle :: Inner {
2379
2383
for attr_to_check in ATTRS_TO_CHECK {
2380
2384
if attr. has_name ( * attr_to_check) {
2381
- tcx. sess . emit_err ( InvalidAttrAtCrateLevel {
2385
+ tcx. sess . emit_err ( errors :: InvalidAttrAtCrateLevel {
2382
2386
span : attr. span ,
2383
2387
snippet : tcx. sess . source_map ( ) . span_to_snippet ( attr. span ) . ok ( ) ,
2384
2388
name : * attr_to_check,
0 commit comments