@@ -3035,3 +3035,67 @@ impl EarlyLintPass for SpecialModuleName {
3035
3035
}
3036
3036
}
3037
3037
}
3038
+
3039
+ declare_lint ! {
3040
+ /// The `mixed_export_name_and_no_mangle` lint detects mixed usage of `export_name` and `no_mangle`
3041
+ /// where `no_mangle` is not used by the compiler.
3042
+ ///
3043
+ /// ### Example
3044
+ ///
3045
+ /// ```rust,compile_fail
3046
+ /// #[no_mangle]
3047
+ /// #[export_name = "foo"]
3048
+ /// pub fn bar() {}
3049
+ ///
3050
+ /// fn main() {}
3051
+ /// ```
3052
+ ///
3053
+ /// {{produces}}
3054
+ ///
3055
+ /// ### Explanation
3056
+ ///
3057
+ /// The compiler will not use the `no_mangle` attribute when generating the symbol name for the function,
3058
+ /// as the `export_name` attribute is used instead. This can lead to confusion and is unnecessary.
3059
+ ///
3060
+ MIXED_EXPORT_NAME_AND_NO_MANGLE ,
3061
+ Warn ,
3062
+ "mixed usage of export_name and no_mangle, where no_mangle is not used by the compiler"
3063
+ }
3064
+
3065
+ declare_lint_pass ! ( MixedExportNameAndNoMangle => [ MIXED_EXPORT_NAME_AND_NO_MANGLE ] ) ;
3066
+
3067
+ impl MixedExportNameAndNoMangle {
3068
+ fn report_mixed_export_name_and_no_mangle (
3069
+ & self ,
3070
+ cx : & EarlyContext < ' _ > ,
3071
+ span_export_name : Span ,
3072
+ span_no_mangle : Span ,
3073
+ ) {
3074
+ let decorate = crate :: lints:: BuiltinMixedExportNameAndNoMangle {
3075
+ export_name : span_export_name,
3076
+ no_mangle : span_no_mangle. clone ( ) ,
3077
+ removal_span : span_no_mangle,
3078
+ } ;
3079
+ cx. emit_span_lint ( MIXED_EXPORT_NAME_AND_NO_MANGLE , span_export_name, decorate) ;
3080
+ }
3081
+ }
3082
+
3083
+ impl EarlyLintPass for MixedExportNameAndNoMangle {
3084
+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: Item ) {
3085
+ match it. kind {
3086
+ ast:: ItemKind :: Fn ( ..) | ast:: ItemKind :: Static ( ..) => {
3087
+ let no_mangle = attr:: find_by_name ( & it. attrs , sym:: no_mangle) ;
3088
+ let export_name = attr:: find_by_name ( & it. attrs , sym:: export_name) ;
3089
+ if let ( Some ( no_mangle_attr) , Some ( export_name_attr) ) = ( no_mangle, export_name) {
3090
+ self . report_mixed_export_name_and_no_mangle (
3091
+ cx,
3092
+ export_name_attr. span ,
3093
+ no_mangle_attr. span ,
3094
+ ) ;
3095
+ }
3096
+ }
3097
+
3098
+ _ => { }
3099
+ }
3100
+ }
3101
+ }
0 commit comments