2023-09-30 10:47:57 -05:00
|
|
|
//@aux-build:proc_macro_derive.rs
|
2022-07-01 23:59:03 -05:00
|
|
|
#![warn(clippy::std_instead_of_core)]
|
|
|
|
#![allow(unused_imports)]
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
|
2023-09-30 10:47:57 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macro_derive;
|
|
|
|
|
2022-07-01 23:59:03 -05:00
|
|
|
#[warn(clippy::std_instead_of_core)]
|
|
|
|
fn std_instead_of_core() {
|
|
|
|
// Regular import
|
|
|
|
use std::hash::Hasher;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-01 23:59:03 -05:00
|
|
|
// Absolute path
|
|
|
|
use ::std::hash::Hash;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-24 19:17:55 -05:00
|
|
|
// Don't lint on `env` macro
|
|
|
|
use std::env;
|
2022-07-01 23:59:03 -05:00
|
|
|
|
|
|
|
// Multiple imports
|
|
|
|
use std::fmt::{Debug, Result};
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-01 23:59:03 -05:00
|
|
|
|
|
|
|
// Function calls
|
|
|
|
let ptr = std::ptr::null::<u32>();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-01 23:59:03 -05:00
|
|
|
let ptr_mut = ::std::ptr::null_mut::<usize>();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-01 23:59:03 -05:00
|
|
|
|
|
|
|
// Types
|
|
|
|
let cell = std::cell::Cell::new(8u32);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-01 23:59:03 -05:00
|
|
|
let cell_absolute = ::std::cell::Cell::new(8u32);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-24 19:17:55 -05:00
|
|
|
|
|
|
|
let _ = std::env!("PATH");
|
2022-09-27 13:21:14 -05:00
|
|
|
|
|
|
|
// do not lint until `error_in_core` is stable
|
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
// lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
|
|
|
|
use std::iter::Iterator;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `core`
|
2022-07-01 23:59:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[warn(clippy::std_instead_of_alloc)]
|
|
|
|
fn std_instead_of_alloc() {
|
2022-07-24 19:17:55 -05:00
|
|
|
// Only lint once.
|
|
|
|
use std::vec;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `alloc`
|
2022-07-01 23:59:03 -05:00
|
|
|
use std::vec::Vec;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `std` instead of `alloc`
|
2022-07-01 23:59:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[warn(clippy::alloc_instead_of_core)]
|
|
|
|
fn alloc_instead_of_core() {
|
|
|
|
use alloc::slice::from_ref;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: used import from `alloc` instead of `core`
|
2022-07-01 23:59:03 -05:00
|
|
|
}
|
|
|
|
|
2023-09-30 10:47:57 -05:00
|
|
|
mod std_in_proc_macro_derive {
|
|
|
|
#[warn(clippy::alloc_instead_of_core)]
|
|
|
|
#[allow(unused)]
|
|
|
|
#[derive(ImplStructWithStdDisplay)]
|
|
|
|
struct B {}
|
|
|
|
}
|
|
|
|
|
2022-07-01 23:59:03 -05:00
|
|
|
fn main() {
|
|
|
|
std_instead_of_core();
|
|
|
|
std_instead_of_alloc();
|
|
|
|
alloc_instead_of_core();
|
|
|
|
}
|