diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2025-09-02 02:12:18 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-02 02:12:18 +0000 |
| commit | d97640c8a4e3b9ee1d4e80770fefbc7c77c4dd0a (patch) | |
| tree | 3b0e541490acc8942dc7b1babe0f6a83287202fe | |
| parent | 7250a1a4b47033a52b0d426f4bca3990ac45161f (diff) | |
| parent | 8f3c6acb228f40c4bb81b75e90bb84d7579432ad (diff) | |
| download | rust-d97640c8a4e3b9ee1d4e80770fefbc7c77c4dd0a.tar.gz rust-d97640c8a4e3b9ee1d4e80770fefbc7c77c4dd0a.zip | |
Fix `alloc_instead_of_core` FP when `alloc` is an alias (#15581)
Closes rust-lang/rust-clippy#15579 changelog: `alloc_instead_of_core` fix FP when `alloc` is an alias
| -rw-r--r-- | clippy_lints/src/std_instead_of_core.rs | 2 | ||||
| -rw-r--r-- | tests/ui/std_instead_of_core.fixed | 7 | ||||
| -rw-r--r-- | tests/ui/std_instead_of_core.rs | 7 |
3 files changed, 16 insertions, 0 deletions
diff --git a/clippy_lints/src/std_instead_of_core.rs b/clippy_lints/src/std_instead_of_core.rs index e9534bc63a6..8c4a50041e6 100644 --- a/clippy_lints/src/std_instead_of_core.rs +++ b/clippy_lints/src/std_instead_of_core.rs @@ -126,6 +126,8 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports { && !is_from_proc_macro(cx, &first_segment.ident) && !matches!(def_kind, DefKind::Macro(_)) && let Some(last_segment) = path.segments.last() + && let Res::Def(DefKind::Mod, crate_def_id) = first_segment.res + && crate_def_id.is_crate_root() { let (lint, used_mod, replace_with) = match first_segment.ident.name { sym::std => match cx.tcx.crate_name(def_id.krate) { diff --git a/tests/ui/std_instead_of_core.fixed b/tests/ui/std_instead_of_core.fixed index 603ab0accb0..c27cec55824 100644 --- a/tests/ui/std_instead_of_core.fixed +++ b/tests/ui/std_instead_of_core.fixed @@ -89,3 +89,10 @@ fn msrv_1_76(_: std::net::IpAddr) {} #[clippy::msrv = "1.77"] fn msrv_1_77(_: core::net::IpAddr) {} //~^ std_instead_of_core + +#[warn(clippy::alloc_instead_of_core)] +fn issue15579() { + use std::alloc; + + let layout = alloc::Layout::new::<u8>(); +} diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs index b6d4abad9f8..7d53f7fc307 100644 --- a/tests/ui/std_instead_of_core.rs +++ b/tests/ui/std_instead_of_core.rs @@ -89,3 +89,10 @@ fn msrv_1_76(_: std::net::IpAddr) {} #[clippy::msrv = "1.77"] fn msrv_1_77(_: std::net::IpAddr) {} //~^ std_instead_of_core + +#[warn(clippy::alloc_instead_of_core)] +fn issue15579() { + use std::alloc; + + let layout = alloc::Layout::new::<u8>(); +} |
