Skip to content

Commit 0dd5c4d

Browse files
authored
Fix used_underscore_items lint uses of foreign functions (rust-lang#14205)
Fixed rust-lang#14156 changelog: none
2 parents 4e899e1 + b167895 commit 0dd5c4d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clippy_lints/src/misc.rs

+2-2
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,
@@ -286,7 +285,8 @@ fn used_underscore_items<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
286285
if name.starts_with('_')
287286
&& !name.starts_with("__")
288287
&& !definition_span.from_expansion()
289-
&& def_id.krate == LOCAL_CRATE
288+
&& def_id.is_local()
289+
&& !cx.tcx.is_foreign_item(def_id)
290290
{
291291
span_lint_and_then(
292292
cx,

tests/ui/used_underscore_items.rs

+10
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)