Skip to content

Commit 65c28e5

Browse files
committed
fix: alloc_instead_of_core FP when alloc is an alias
1 parent b3d0a09 commit 65c28e5

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

clippy_lints/src/std_instead_of_core.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
137137
},
138138
},
139139
sym::alloc => {
140+
if let Res::Def(DefKind::Mod, crate_def_id) = first_segment.res
141+
&& let crate_name = cx.tcx.crate_name(crate_def_id.krate)
142+
&& crate_name != first_segment.ident.name
143+
{
144+
return;
145+
}
146+
140147
if cx.tcx.crate_name(def_id.krate) == sym::core {
141148
(ALLOC_INSTEAD_OF_CORE, "alloc", "core")
142149
} else {

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)