2023-10-06 10:35:45 -05:00
|
|
|
//@aux-build:proc_macro_derive.rs
|
2024-03-07 10:19:29 -06:00
|
|
|
|
2023-09-12 11:13:53 -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;
|
|
|
|
|
2023-09-12 11:13:53 -05:00
|
|
|
#[warn(clippy::std_instead_of_core)]
|
|
|
|
fn std_instead_of_core() {
|
|
|
|
// Regular import
|
|
|
|
use core::hash::Hasher;
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
// Absolute path
|
|
|
|
use ::core::hash::Hash;
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
// Don't lint on `env` macro
|
2024-03-21 16:20:40 -05:00
|
|
|
use std::env;
|
2023-09-12 11:13:53 -05:00
|
|
|
|
|
|
|
// Multiple imports
|
|
|
|
use core::fmt::{Debug, Result};
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
|
2024-03-07 10:19:29 -06:00
|
|
|
// Multiple imports multiline
|
|
|
|
#[rustfmt::skip]
|
|
|
|
use core::{
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
fmt::Write as _,
|
|
|
|
ptr::read_unaligned,
|
|
|
|
};
|
|
|
|
|
2023-09-12 11:13:53 -05:00
|
|
|
// Function calls
|
|
|
|
let ptr = core::ptr::null::<u32>();
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
let ptr_mut = ::core::ptr::null_mut::<usize>();
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
|
|
|
|
// Types
|
|
|
|
let cell = core::cell::Cell::new(8u32);
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
let cell_absolute = ::core::cell::Cell::new(8u32);
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
|
|
|
|
let _ = std::env!("PATH");
|
|
|
|
|
2024-06-06 19:37:05 -05:00
|
|
|
use core::error::Error;
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2023-09-12 11:13:53 -05:00
|
|
|
|
|
|
|
// lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
|
|
|
|
use core::iter::Iterator;
|
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
|
|
|
}
|
|
|
|
|
|
|
|
#[warn(clippy::std_instead_of_alloc)]
|
|
|
|
fn std_instead_of_alloc() {
|
|
|
|
// Only lint once.
|
|
|
|
use alloc::vec;
|
|
|
|
//~^ ERROR: used import from `std` instead of `alloc`
|
|
|
|
use alloc::vec::Vec;
|
|
|
|
//~^ ERROR: used import from `std` instead of `alloc`
|
|
|
|
}
|
|
|
|
|
|
|
|
#[warn(clippy::alloc_instead_of_core)]
|
|
|
|
fn alloc_instead_of_core() {
|
|
|
|
use core::slice::from_ref;
|
|
|
|
//~^ ERROR: used import from `alloc` instead of `core`
|
|
|
|
}
|
|
|
|
|
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 {}
|
|
|
|
}
|
|
|
|
|
2023-09-12 11:13:53 -05:00
|
|
|
fn main() {
|
|
|
|
std_instead_of_core();
|
|
|
|
std_instead_of_alloc();
|
|
|
|
alloc_instead_of_core();
|
|
|
|
}
|