Skip to content

Fix #12438 std_instead_of_core regression #12447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clippy_lints/src/std_instead_of_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
sym::core => (STD_INSTEAD_OF_CORE, "std", "core"),
sym::alloc => (STD_INSTEAD_OF_ALLOC, "std", "alloc"),
_ => {
self.prev_span = first_segment.ident.span;
return;
},
},
sym::alloc => {
if cx.tcx.crate_name(def_id.krate) == sym::core {
(ALLOC_INSTEAD_OF_CORE, "alloc", "core")
} else {
self.prev_span = first_segment.ident.span;
return;
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/std_instead_of_core.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn std_instead_of_core() {
use ::core::hash::Hash;
//~^ ERROR: used import from `std` instead of `core`
// Don't lint on `env` macro
use core::env;
use std::env;

// Multiple imports
use core::fmt::{Debug, Result};
Expand Down
8 changes: 1 addition & 7 deletions tests/ui/std_instead_of_core.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ error: used import from `std` instead of `core`
LL | use ::std::hash::Hash;
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:20:9
|
LL | use std::env;
| ^^^ help: consider importing the item from `core`: `core`

error: used import from `std` instead of `core`
--> tests/ui/std_instead_of_core.rs:23:9
|
Expand Down Expand Up @@ -85,5 +79,5 @@ LL | use alloc::slice::from_ref;
= note: `-D clippy::alloc-instead-of-core` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]`

error: aborting due to 13 previous errors
error: aborting due to 12 previous errors