blob: a7555704fbe0130a2c40440ff042e46e68d51121 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
//@aux-build:proc_macro_derive.rs
#![warn(clippy::std_instead_of_core)]
#![allow(unused_imports)]
extern crate alloc;
#[macro_use]
extern crate proc_macro_derive;
#[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
use std::env;
// Multiple imports
use core::fmt::{Debug, Result};
//~^ ERROR: used import from `std` instead of `core`
// 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");
// 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 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`
}
mod std_in_proc_macro_derive {
#[warn(clippy::alloc_instead_of_core)]
#[allow(unused)]
#[derive(ImplStructWithStdDisplay)]
struct B {}
}
fn main() {
std_instead_of_core();
std_instead_of_alloc();
alloc_instead_of_core();
}
|