@@ -13,7 +13,7 @@ use rustc_ast::walk_list;
13
13
use rustc_ast:: * ;
14
14
use rustc_ast_pretty:: pprust:: { self , State } ;
15
15
use rustc_data_structures:: fx:: FxHashMap ;
16
- use rustc_errors:: { error_code, pluralize, struct_span_err, Applicability , Diagnostic } ;
16
+ use rustc_errors:: { error_code, fluent , pluralize, struct_span_err, Applicability , Diagnostic } ;
17
17
use rustc_parse:: validate_attr;
18
18
use rustc_session:: lint:: builtin:: {
19
19
DEPRECATED_WHERE_CLAUSE_LOCATION , MISSING_ABI , PATTERNS_IN_FNS_WITHOUT_BODY ,
@@ -27,7 +27,7 @@ use rustc_target::spec::abi;
27
27
use std:: mem;
28
28
use std:: ops:: { Deref , DerefMut } ;
29
29
30
- use crate :: errors:: ForbiddenLet ;
30
+ use crate :: errors:: * ;
31
31
32
32
const MORE_EXTERN : & str =
33
33
"for more information, visit https://doc.rust-lang.org/std/keyword.extern.html" ;
@@ -149,7 +149,7 @@ impl<'a> AstValidator<'a> {
149
149
DEPRECATED_WHERE_CLAUSE_LOCATION ,
150
150
id,
151
151
where_clauses. 0 . 1 ,
152
- "where clause not allowed here" ,
152
+ fluent :: ast_passes :: deprecated_where_clause_location ,
153
153
BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation (
154
154
where_clauses. 1 . 1 . shrink_to_hi ( ) ,
155
155
suggestion,
@@ -179,10 +179,7 @@ impl<'a> AstValidator<'a> {
179
179
AssocConstraintKind :: Equality { .. } => { }
180
180
AssocConstraintKind :: Bound { .. } => {
181
181
if self . is_assoc_ty_bound_banned {
182
- self . err_handler ( ) . span_err (
183
- constraint. span ,
184
- "associated type bounds are not allowed within structs, enums, or unions" ,
185
- ) ;
182
+ self . session . emit_err ( ForbiddenAssocConstraint { span : constraint. span } ) ;
186
183
}
187
184
}
188
185
}
@@ -254,31 +251,26 @@ impl<'a> AstValidator<'a> {
254
251
fn check_lifetime ( & self , ident : Ident ) {
255
252
let valid_names = [ kw:: UnderscoreLifetime , kw:: StaticLifetime , kw:: Empty ] ;
256
253
if !valid_names. contains ( & ident. name ) && ident. without_first_quote ( ) . is_reserved ( ) {
257
- self . err_handler ( ) . span_err ( ident. span , "lifetimes cannot use keyword names" ) ;
254
+ self . session . emit_err ( KeywordLifetime { span : ident. span } ) ;
258
255
}
259
256
}
260
257
261
258
fn check_label ( & self , ident : Ident ) {
262
259
if ident. without_first_quote ( ) . is_reserved ( ) {
263
- self . err_handler ( )
264
- . span_err ( ident. span , & format ! ( "invalid label name `{}`" , ident. name) ) ;
260
+ self . session . emit_err ( InvalidLabel { span : ident. span , name : ident. name } ) ;
265
261
}
266
262
}
267
263
268
- fn invalid_visibility ( & self , vis : & Visibility , note : Option < & str > ) {
264
+ fn invalid_visibility ( & self , vis : & Visibility , note : Option < InvalidVisibilityNote > ) {
269
265
if let VisibilityKind :: Inherited = vis. kind {
270
266
return ;
271
267
}
272
268
273
- let mut err =
274
- struct_span_err ! ( self . session, vis. span, E0449 , "unnecessary visibility qualifier" ) ;
275
- if vis. kind . is_pub ( ) {
276
- err. span_label ( vis. span , "`pub` not permitted here because it's implied" ) ;
277
- }
278
- if let Some ( note) = note {
279
- err. note ( note) ;
280
- }
281
- err. emit ( ) ;
269
+ self . session . emit_err ( InvalidVisibility {
270
+ span : vis. span ,
271
+ implied : if vis. kind . is_pub ( ) { Some ( vis. span ) } else { None } ,
272
+ note,
273
+ } ) ;
282
274
}
283
275
284
276
fn check_decl_no_pat ( decl : & FnDecl , mut report_err : impl FnMut ( Span , Option < Ident > , bool ) ) {
@@ -1154,7 +1146,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1154
1146
1155
1147
self . invalid_visibility (
1156
1148
& item. vis ,
1157
- Some ( "place qualifiers on individual impl items instead" ) ,
1149
+ Some ( InvalidVisibilityNote :: IndividualImplItems ) ,
1158
1150
) ;
1159
1151
if let Unsafe :: Yes ( span) = unsafety {
1160
1152
error ( span, "unsafe" ) . code ( error_code ! ( E0197 ) ) . emit ( ) ;
@@ -1222,7 +1214,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1222
1214
let old_item = mem:: replace ( & mut self . extern_mod , Some ( item) ) ;
1223
1215
self . invalid_visibility (
1224
1216
& item. vis ,
1225
- Some ( "place qualifiers on individual foreign items instead" ) ,
1217
+ Some ( InvalidVisibilityNote :: IndividualForeignItems ) ,
1226
1218
) ;
1227
1219
if let Unsafe :: Yes ( span) = unsafety {
1228
1220
self . err_handler ( ) . span_err ( span, "extern block cannot be declared unsafe" ) ;
0 commit comments