Skip to content

Commit 902cef4

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

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-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
@@ -127,6 +127,13 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
127127
&& !matches!(def_kind, DefKind::Macro(_))
128128
&& let Some(last_segment) = path.segments.last()
129129
{
130+
if let Res::Def(DefKind::Mod, crate_def_id) = first_segment.res
131+
&& let crate_name = cx.tcx.crate_name(crate_def_id.krate)
132+
&& crate_name != first_segment.ident.name
133+
{
134+
return;
135+
}
136+
130137
let (lint, used_mod, replace_with) = match first_segment.ident.name {
131138
sym::std => match cx.tcx.crate_name(def_id.krate) {
132139
sym::core => (STD_INSTEAD_OF_CORE, "std", "core"),

tests/ui/std_instead_of_core.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ 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+
fn issue15579() {
94+
use std::alloc;
95+
96+
let layout = alloc::Layout::new::<u8>();
97+
}

tests/ui/std_instead_of_core.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ 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+
fn issue15579() {
94+
use std::alloc;
95+
96+
let layout = alloc::Layout::new::<u8>();
97+
}

0 commit comments

Comments
 (0)