|
1 | 1 | use clippy_utils::diagnostics::span_lint;
|
2 | 2 | use rustc_attr_data_structures::{AttributeKind, find_attr};
|
3 |
| -use rustc_hir as hir; |
4 |
| -use rustc_hir::Attribute; |
| 3 | +use rustc_hir::def_id::DefId; |
| 4 | +use rustc_hir::{self as hir, Attribute}; |
5 | 5 | use rustc_lint::{LateContext, LateLintPass, LintContext};
|
6 | 6 | use rustc_middle::ty::AssocItemContainer;
|
7 | 7 | use rustc_session::declare_lint_pass;
|
@@ -97,6 +97,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
97 | 97 | }
|
98 | 98 | match it.kind {
|
99 | 99 | hir::ItemKind::Fn { .. } => {
|
| 100 | + if fn_is_externally_exported(cx, it.owner_id.to_def_id()) { |
| 101 | + return; |
| 102 | + } |
| 103 | + |
100 | 104 | let desc = "a function";
|
101 | 105 | let attrs = cx.tcx.hir_attrs(it.hir_id());
|
102 | 106 | check_missing_inline_attrs(cx, attrs, it.span, desc);
|
@@ -173,3 +177,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
173 | 177 | check_missing_inline_attrs(cx, attrs, impl_item.span, desc);
|
174 | 178 | }
|
175 | 179 | }
|
| 180 | + |
| 181 | +/// Checks if this function is externally exported, where #[inline] wouldn't have the desired effect |
| 182 | +/// and a rustc warning would be triggered, see #15301 |
| 183 | +fn fn_is_externally_exported(cx: &LateContext<'_>, def_id: DefId) -> bool { |
| 184 | + let attrs = cx.tcx.codegen_fn_attrs(def_id); |
| 185 | + attrs.contains_extern_indicator() |
| 186 | +} |
0 commit comments