rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`std_instead_of_core` suggests non-compiling variant if original code used legacy re-export

Open tiptenbrink opened this issue 3 months ago • 1 comments

Summary

The std_instead_of_core lint checks availability based on the resolved definition, but for the suggestion where to change it to it just replaces the std path with core.

In the case where the code referenced a legacy re-export that doesn't exist in core, this means it will produce a non-existing definition.

--fix tries to actually apply it and then fails and tells me to report it here, so here I am.

Reproducer

Code:

#![no_std]
#![warn(clippy::std_instead_of_core)]
extern crate std;
use std::collections::Bound::{Excluded, Included};
pub const A: core::ops::Bound<u8> = Excluded(1);
pub const B: core::ops::Bound<u8> = Included(1);
cargo clippy --fix --allow-no-vcs --broken-code

Current output:

tip@ys7imh9-pop:~/files/localp/clippy-bound-repro/boundtest$ cargo clippy --fix --allow-no-vcs --broken-code
    Checking boundtest v0.0.0 (/home/tip/files/localp/clippy-bound-repro/boundtest)
error: errors present after applying fixes to crate `boundtest`
 --> src/lib.rs
  = cause: error[E0433]: cannot find `collections` in `core`
            --> src/lib.rs:4:11
             |
           4 | use core::collections::Bound::{Excluded, Included};
             |           ^^^^^^^^^^^ could not find `collections` in `core`


           error: aborting due to 1 previous error


           For more information about this error, try `rustc --explain E0433`.
help: to report this as a bug, open an issue at https://github.com/rust-lang/rust-clippy/issues, quoting the full output of this command
help: to possibly apply more fixes, pass in the `--broken-code` flag
note: original diagnostics will follow:
warning: used import from `std` instead of `core`
 --> src/lib.rs:4:5
  |
4 | use std::collections::Bound::{Excluded, Included};
  |     ^^^ help: consider importing the item from `core`: `core`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_core
note: the lint level is defined here
 --> src/lib.rs:2:9
  |
2 | #![warn(clippy::std_instead_of_core)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `boundtest` (lib) generated 1 warning (run `cargo clippy --fix --lib -p boundtest -- --no-deps` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.16s
tip@ys7imh9-pop:~/files/localp/clippy-bound-repro/boundtest$

Desired output:

That it fixes it to use core::ops::Bound::{Excluded, Included};

Version

rustc 1.97.1 (8bab26f4f 2026-07-14) (built from a source tarball)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: x86_64-unknown-linux-gnu
release: 1.97.1
LLVM version: 21.1.8

Additional Labels

@rustbot label +I-suggestion-causes-error

tiptenbrink avatar Aug 22 '26 12:08 tiptenbrink

@rustbot claim

kennywillbe avatar Aug 28 '26 23:08 kennywillbe