File tree Expand file tree Collapse file tree 3 files changed +43
-19
lines changed
rustc_error_messages/locales/en-US Expand file tree Collapse file tree 3 files changed +43
-19
lines changed Original file line number Diff line number Diff line change @@ -417,29 +417,18 @@ impl<'a> AstValidator<'a> {
417417 }
418418
419419 fn check_foreign_ty_genericless ( & self , generics : & Generics , where_span : Span ) {
420- let cannot_have = |span, descr, remove_descr| {
421- self . err_handler ( )
422- . struct_span_err (
423- span,
424- & format ! ( "`type`s inside `extern` blocks cannot have {}" , descr) ,
425- )
426- . span_suggestion (
427- span,
428- & format ! ( "remove the {}" , remove_descr) ,
429- "" ,
430- Applicability :: MaybeIncorrect ,
431- )
432- . span_label ( self . current_extern_span ( ) , "`extern` block begins here" )
433- . note ( MORE_EXTERN )
434- . emit ( ) ;
435- } ;
436-
437420 if !generics. params . is_empty ( ) {
438- cannot_have ( generics. span , "generic parameters" , "generic parameters" ) ;
421+ self . session . emit_err ( ForeignTyWithGenericParam {
422+ span : generics. span ,
423+ extern_span : self . current_extern_span ( ) ,
424+ } ) ;
439425 }
440426
441427 if !generics. where_clause . predicates . is_empty ( ) {
442- cannot_have ( where_span, "`where` clauses" , "`where` clause" ) ;
428+ self . session . emit_err ( ForeignTyWithWhereClause {
429+ span : where_span,
430+ extern_span : self . current_extern_span ( ) ,
431+ } ) ;
443432 }
444433 }
445434
Original file line number Diff line number Diff line change @@ -245,3 +245,25 @@ pub struct ImplAssocTyWithBound {
245245 #[ primary_span]
246246 pub span : Span ,
247247}
248+
249+ #[ derive( SessionDiagnostic ) ]
250+ #[ diag( ast_passes:: foreign_ty_with_generic_param) ]
251+ #[ note( ast_passes:: more_extern_note) ]
252+ pub struct ForeignTyWithGenericParam {
253+ #[ primary_span]
254+ #[ suggestion( code = "" , applicability = "maybe-incorrect" ) ]
255+ pub span : Span ,
256+ #[ label]
257+ pub extern_span : Span ,
258+ }
259+
260+ #[ derive( SessionDiagnostic ) ]
261+ #[ diag( ast_passes:: foreign_ty_with_where_clause) ]
262+ #[ note( ast_passes:: more_extern_note) ]
263+ pub struct ForeignTyWithWhereClause {
264+ #[ primary_span]
265+ #[ suggestion( code = "" , applicability = "maybe-incorrect" ) ]
266+ pub span : Span ,
267+ #[ label]
268+ pub extern_span : Span ,
269+ }
Original file line number Diff line number Diff line change 1+ ast_passes_more_extern_note =
2+ for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
3+
14ast_passes_forbidden_let =
25 `let` expressions are not supported here
36 .note = only supported directly in conditions of `if` and `while` expressions
@@ -99,3 +102,13 @@ ast_passes_foreign_ty_with_bound =
99102
100103ast_passes_impl_assoc_ty_with_bound =
101104 bounds on `type`s in `impl`s have no effect
105+
106+ ast_passes_foreign_ty_with_generic_param =
107+ `type`s inside `extern` blocks cannot have generic parameters
108+ .suggestion = remove the generic parameters
109+ .extern_block_label = `extern` block begins here
110+
111+ ast_passes_foreign_ty_with_where_clause =
112+ `type`s inside `extern` blocks cannot have `where` clauses
113+ .suggestion = remove the `where` clause
114+ .extern_block_label = `extern` block begins here
You can’t perform that action at this time.
0 commit comments