File tree 3 files changed +32
-14
lines changed
compiler/rustc_ast_passes
3 files changed +32
-14
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,10 @@ ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$de
79
79
.suggestion = remove the { $remove_descr }
80
80
.label = `extern` block begins here
81
81
82
+ ast_passes_extern_without_abi = extern declaration without an ABI
83
+ .label = ABI should be specified here
84
+ .suggestion = explicitly specify an ABI
85
+
82
86
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the { $channel } release channel
83
87
.suggestion = remove the attribute
84
88
.stable_since = the feature `{ $name } ` has been stable since `{ $since } ` and no longer requires an attribute to enable
Original file line number Diff line number Diff line change @@ -712,20 +712,25 @@ impl<'a> AstValidator<'a> {
712
712
}
713
713
714
714
fn maybe_lint_missing_abi ( & mut self , span : Span , id : NodeId ) {
715
- // FIXME(davidtwco): This is a hack to detect macros which produce spans of the
716
- // call site which do not have a macro backtrace. See #61963.
717
- if self
718
- . sess
719
- . source_map ( )
720
- . span_to_snippet ( span)
721
- . is_ok_and ( |snippet| !snippet. starts_with ( "#[" ) )
722
- {
723
- self . lint_buffer . buffer_lint (
724
- MISSING_ABI ,
725
- id,
726
- span,
727
- BuiltinLintDiag :: MissingAbi ( span, abi:: Abi :: FALLBACK ) ,
728
- )
715
+ if span. edition ( ) . at_least_rust_2024 ( ) {
716
+ self . dcx ( )
717
+ . emit_err ( errors:: MissingAbi { span, default_abi : abi:: Abi :: FALLBACK . name ( ) } ) ;
718
+ } else {
719
+ // FIXME(davidtwco): This is a hack to detect macros which produce spans of the
720
+ // call site which do not have a macro backtrace. See #61963.
721
+ if self
722
+ . sess
723
+ . source_map ( )
724
+ . span_to_snippet ( span)
725
+ . is_ok_and ( |snippet| !snippet. starts_with ( "#[" ) )
726
+ {
727
+ self . lint_buffer . buffer_lint (
728
+ MISSING_ABI ,
729
+ id,
730
+ span,
731
+ BuiltinLintDiag :: MissingAbi ( span, abi:: Abi :: FALLBACK ) ,
732
+ )
733
+ }
729
734
}
730
735
}
731
736
}
Original file line number Diff line number Diff line change @@ -833,3 +833,12 @@ pub(crate) struct DuplicatePreciseCapturing {
833
833
#[ label]
834
834
pub bound2 : Span ,
835
835
}
836
+
837
+ #[ derive( Diagnostic ) ]
838
+ #[ diag( ast_passes_extern_without_abi) ]
839
+ pub ( crate ) struct MissingAbi {
840
+ #[ primary_span]
841
+ #[ suggestion( code = "extern \" {default_abi}\" " , applicability = "machine-applicable" ) ]
842
+ pub span : Span ,
843
+ pub default_abi : & ' static str ,
844
+ }
You can’t perform that action at this time.
0 commit comments