Skip to content

Commit

Permalink
Fix used_underscore_items lint uses of foreign functions (#14205)
Browse files Browse the repository at this point in the history
Fixed #14156

changelog: none
  • Loading branch information
Jarcho authored Feb 15, 2025
2 parents 4e899e1 + b167895 commit 0dd5c4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use clippy_utils::{
};
use rustc_errors::Applicability;
use rustc_hir::def::Res;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{
BinOpKind, BindingMode, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind,
Expand Down Expand Up @@ -286,7 +285,8 @@ fn used_underscore_items<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if name.starts_with('_')
&& !name.starts_with("__")
&& !definition_span.from_expansion()
&& def_id.krate == LOCAL_CRATE
&& def_id.is_local()
&& !cx.tcx.is_foreign_item(def_id)
{
span_lint_and_then(
cx,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/used_underscore_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ fn external_item_call() {

external_item::_exernal_foo();
}

// should not lint foreign functions.
// issue #14156
extern "C" {
pub fn _exit(code: i32) -> !;
}

fn _f() {
unsafe { _exit(1) }
}

0 comments on commit 0dd5c4d

Please sign in to comment.