@@ -13,7 +13,7 @@ use rustc_ast::walk_list;
1313use rustc_ast:: * ;
1414use rustc_ast_pretty:: pprust:: { self , State } ;
1515use 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 } ;
1717use rustc_parse:: validate_attr;
1818use rustc_session:: lint:: builtin:: {
1919 DEPRECATED_WHERE_CLAUSE_LOCATION , MISSING_ABI , PATTERNS_IN_FNS_WITHOUT_BODY ,
@@ -27,7 +27,7 @@ use rustc_target::spec::abi;
2727use std:: mem;
2828use std:: ops:: { Deref , DerefMut } ;
2929
30- use crate :: errors:: ForbiddenLet ;
30+ use crate :: errors:: * ;
3131
3232const MORE_EXTERN : & str =
3333 "for more information, visit https://doc.rust-lang.org/std/keyword.extern.html" ;
@@ -149,7 +149,7 @@ impl<'a> AstValidator<'a> {
149149 DEPRECATED_WHERE_CLAUSE_LOCATION ,
150150 id,
151151 where_clauses. 0 . 1 ,
152- "where clause not allowed here" ,
152+ fluent :: ast_passes :: deprecated_where_clause_location ,
153153 BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation (
154154 where_clauses. 1 . 1 . shrink_to_hi ( ) ,
155155 suggestion,
@@ -179,10 +179,7 @@ impl<'a> AstValidator<'a> {
179179 AssocConstraintKind :: Equality { .. } => { }
180180 AssocConstraintKind :: Bound { .. } => {
181181 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 } ) ;
186183 }
187184 }
188185 }
@@ -254,31 +251,26 @@ impl<'a> AstValidator<'a> {
254251 fn check_lifetime ( & self , ident : Ident ) {
255252 let valid_names = [ kw:: UnderscoreLifetime , kw:: StaticLifetime , kw:: Empty ] ;
256253 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 } ) ;
258255 }
259256 }
260257
261258 fn check_label ( & self , ident : Ident ) {
262259 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 } ) ;
265261 }
266262 }
267263
268- fn invalid_visibility ( & self , vis : & Visibility , note : Option < & str > ) {
264+ fn invalid_visibility ( & self , vis : & Visibility , note : Option < InvalidVisibilityNote > ) {
269265 if let VisibilityKind :: Inherited = vis. kind {
270266 return ;
271267 }
272268
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+ } ) ;
282274 }
283275
284276 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> {
11541146
11551147 self . invalid_visibility (
11561148 & item. vis ,
1157- Some ( "place qualifiers on individual impl items instead" ) ,
1149+ Some ( InvalidVisibilityNote :: IndividualImplItems ) ,
11581150 ) ;
11591151 if let Unsafe :: Yes ( span) = unsafety {
11601152 error ( span, "unsafe" ) . code ( error_code ! ( E0197 ) ) . emit ( ) ;
@@ -1222,7 +1214,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12221214 let old_item = mem:: replace ( & mut self . extern_mod , Some ( item) ) ;
12231215 self . invalid_visibility (
12241216 & item. vis ,
1225- Some ( "place qualifiers on individual foreign items instead" ) ,
1217+ Some ( InvalidVisibilityNote :: IndividualForeignItems ) ,
12261218 ) ;
12271219 if let Unsafe :: Yes ( span) = unsafety {
12281220 self . err_handler ( ) . span_err ( span, "extern block cannot be declared unsafe" ) ;
0 commit comments