2023-10-06 10:35:45 -05:00
|
|
|
//@aux-build:proc_macro_derive.rs
|
2024-03-07 10:19:29 -06:00
|
|
|
|
2022-07-18 02:39:37 -05:00
|
|
|
#![warn(clippy::std_instead_of_core)]
|
|
|
|
#![allow(unused_imports)]
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
|
2023-10-06 10:35:45 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macro_derive;
|
|
|
|
|
2022-07-18 02:39:37 -05:00
|
|
|
#[warn(clippy::std_instead_of_core)]
|
|
|
|
fn std_instead_of_core() {
|
|
|
|
// Regular import
|
|
|
|
use std::hash::Hasher;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-18 02:39:37 -05:00
|
|
|
// Absolute path
|
|
|
|
use ::std::hash::Hash;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-28 12:08:22 -05:00
|
|
|
// Don't lint on `env` macro
|
|
|
|
use std::env;
|
2022-07-18 02:39:37 -05:00
|
|
|
|
|
|
|
// Multiple imports
|
|
|
|
use std::fmt::{Debug, Result};
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-18 02:39:37 -05:00
|
|
|
|
2024-03-07 10:19:29 -06:00
|
|
|
// Multiple imports multiline
|
|
|
|
#[rustfmt::skip]
|
|
|
|
use std::{
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
fmt::Write as _,
|
|
|
|
ptr::read_unaligned,
|
|
|
|
};
|
|
|
|
|
2022-07-18 02:39:37 -05:00
|
|
|
// Function calls
|
|
|
|
let ptr = std::ptr::null::<u32>();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-18 02:39:37 -05:00
|
|
|
let ptr_mut = ::std::ptr::null_mut::<usize>();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-18 02:39:37 -05:00
|
|
|
|
|
|
|
// Types
|
|
|
|
let cell = std::cell::Cell::new(8u32);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-18 02:39:37 -05:00
|
|
|
let cell_absolute = ::std::cell::Cell::new(8u32);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-28 12:08:22 -05:00
|
|
|
|
|
|
|
let _ = std::env!("PATH");
|
2022-10-06 02:44:38 -05:00
|
|
|
|
|
|
|
use std::error::Error;
|
2024-06-06 19:37:05 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-10-06 02:44:38 -05:00
|
|
|
|
|
|
|
// lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
|
|
|
|
use std::iter::Iterator;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-18 02:39:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[warn(clippy::std_instead_of_alloc)]
|
|
|
|
fn std_instead_of_alloc() {
|
2022-07-28 12:08:22 -05:00
|
|
|
// Only lint once.
|
|
|
|
use std::vec;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `alloc`
|
2022-07-18 02:39:37 -05:00
|
|
|
use std::vec::Vec;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `alloc`
|
2022-07-18 02:39:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[warn(clippy::alloc_instead_of_core)]
|
|
|
|
fn alloc_instead_of_core() {
|
|
|
|
use alloc::slice::from_ref;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: used import from `alloc` instead of `core`
|
2022-07-18 02:39:37 -05:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:35:45 -05:00
|
|
|
mod std_in_proc_macro_derive {
|
|
|
|
#[warn(clippy::alloc_instead_of_core)]
|
|
|
|
#[allow(unused)]
|
|
|
|
#[derive(ImplStructWithStdDisplay)]
|
|
|
|
struct B {}
|
|
|
|
}
|
|
|
|
|
2024-07-26 10:57:00 -05:00
|
|
|
// Some intrinsics are usable on stable but live in an unstable module, but should still suggest
|
|
|
|
// replacing std -> core
|
|
|
|
fn intrinsic(a: *mut u8, b: *mut u8) {
|
|
|
|
unsafe {
|
|
|
|
std::intrinsics::copy(a, b, 1);
|
|
|
|
//~^ std_instead_of_core
|
|
|
|
}
|
2022-07-18 02:39:37 -05:00
|
|
|
}
|
2024-07-26 10:57:00 -05:00
|
|
|
|
|
|
|
#[clippy::msrv = "1.76"]
|
|
|
|
fn msrv_1_76(_: std::net::IpAddr) {}
|
|
|
|
|
|
|
|
#[clippy::msrv = "1.77"]
|
|
|
|
fn msrv_1_77(_: std::net::IpAddr) {}
|