Skip to content

Commit d97640c

Browse files
authored
Fix alloc_instead_of_core FP when alloc is an alias (#15581)
Closes #15579 changelog: `alloc_instead_of_core` fix FP when `alloc` is an alias
2 parents 7250a1a + 8f3c6ac commit d97640c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clippy_lints/src/std_instead_of_core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
126126
&& !is_from_proc_macro(cx, &first_segment.ident)
127127
&& !matches!(def_kind, DefKind::Macro(_))
128128
&& let Some(last_segment) = path.segments.last()
129+
&& let Res::Def(DefKind::Mod, crate_def_id) = first_segment.res
130+
&& crate_def_id.is_crate_root()
129131
{
130132
let (lint, used_mod, replace_with) = match first_segment.ident.name {
131133
sym::std => match cx.tcx.crate_name(def_id.krate) {

tests/ui/std_instead_of_core.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,10 @@ fn msrv_1_76(_: std::net::IpAddr) {}
8989
#[clippy::msrv = "1.77"]
9090
fn msrv_1_77(_: core::net::IpAddr) {}
9191
//~^ std_instead_of_core
92+
93+
#[warn(clippy::alloc_instead_of_core)]
94+
fn issue15579() {
95+
use std::alloc;
96+
97+
let layout = alloc::Layout::new::<u8>();
98+
}

tests/ui/std_instead_of_core.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,10 @@ fn msrv_1_76(_: std::net::IpAddr) {}
8989
#[clippy::msrv = "1.77"]
9090
fn msrv_1_77(_: std::net::IpAddr) {}
9191
//~^ std_instead_of_core
92+
93+
#[warn(clippy::alloc_instead_of_core)]
94+
fn issue15579() {
95+
use std::alloc;
96+
97+
let layout = alloc::Layout::new::<u8>();
98+
}

0 commit comments

Comments
 (0)