Skip to content

Commit b167895

Browse files
committed
Fix used_underscore_items lint uses of foreign functions
1 parent 660d861 commit b167895

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clippy_lints/src/misc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use clippy_utils::{
77
};
88
use rustc_errors::Applicability;
99
use rustc_hir::def::Res;
10-
use rustc_hir::def_id::LOCAL_CRATE;
1110
use rustc_hir::intravisit::FnKind;
1211
use rustc_hir::{
1312
BinOpKind, BindingMode, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind,
@@ -287,7 +286,8 @@ fn used_underscore_items<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
287286
if name.starts_with('_')
288287
&& !name.starts_with("__")
289288
&& !definition_span.from_expansion()
290-
&& def_id.krate == LOCAL_CRATE
289+
&& def_id.is_local()
290+
&& !cx.tcx.is_foreign_item(def_id)
291291
{
292292
span_lint_and_then(
293293
cx,

tests/ui/used_underscore_items.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,13 @@ fn external_item_call() {
6161

6262
external_item::_exernal_foo();
6363
}
64+
65+
// should not lint foreign functions.
66+
// issue #14156
67+
extern "C" {
68+
pub fn _exit(code: i32) -> !;
69+
}
70+
71+
fn _f() {
72+
unsafe { _exit(1) }
73+
}

0 commit comments

Comments
 (0)