Skip to content

Commit 7a5dfbb

Browse files
authored
Unrolled build for #142787
Rollup merge of #142787 - samueltardieu:diag-items-for-clippy, r=Manishearth,Urgau Add diagnostic items for Clippy Clippy still uses some paths to access items from the standard library. Adding the missing diagnostic items allows removing the last remaining paths. Closes rust-lang/rust-clippy#5393
2 parents df4ad9e + 890ade5 commit 7a5dfbb

File tree

15 files changed

+30
-34
lines changed

15 files changed

+30
-34
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ symbols! {
641641
cfi_encoding,
642642
char,
643643
char_is_ascii,
644+
char_to_digit,
644645
child_id,
645646
child_kill,
646647
client,
@@ -1216,6 +1217,8 @@ symbols! {
12161217
intrinsics,
12171218
intrinsics_unaligned_volatile_load,
12181219
intrinsics_unaligned_volatile_store,
1220+
io_error_new,
1221+
io_errorkind,
12191222
io_stderr,
12201223
io_stdout,
12211224
irrefutable_let_patterns,
@@ -1305,6 +1308,7 @@ symbols! {
13051308
m68k_target_feature,
13061309
macro_at_most_once_rep,
13071310
macro_attributes_in_derive_output,
1311+
macro_concat,
13081312
macro_escape,
13091313
macro_export,
13101314
macro_lifetime_matcher,
@@ -1339,6 +1343,7 @@ symbols! {
13391343
maybe_uninit,
13401344
maybe_uninit_uninit,
13411345
maybe_uninit_zeroed,
1346+
mem_align_of,
13421347
mem_discriminant,
13431348
mem_drop,
13441349
mem_forget,
@@ -1706,6 +1711,7 @@ symbols! {
17061711
question_mark,
17071712
quote,
17081713
range_inclusive_new,
1714+
range_step,
17091715
raw_dylib,
17101716
raw_dylib_elf,
17111717
raw_eq,
@@ -2022,6 +2028,7 @@ symbols! {
20222028
slice,
20232029
slice_from_raw_parts,
20242030
slice_from_raw_parts_mut,
2031+
slice_from_ref,
20252032
slice_get_unchecked,
20262033
slice_into_vec,
20272034
slice_iter,

library/core/src/char/methods.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ impl char {
395395
/// ```
396396
#[stable(feature = "rust1", since = "1.0.0")]
397397
#[rustc_const_stable(feature = "const_char_convert", since = "1.67.0")]
398+
#[rustc_diagnostic_item = "char_to_digit"]
398399
#[must_use = "this returns the result of the operation, \
399400
without modifying the original"]
400401
#[inline]

library/core/src/iter/range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ unsafe_impl_trusted_step![AsciiChar char i8 i16 i32 i64 i128 isize u8 u16 u32 u6
2020
///
2121
/// The *successor* operation moves towards values that compare greater.
2222
/// The *predecessor* operation moves towards values that compare lesser.
23+
#[rustc_diagnostic_item = "range_step"]
2324
#[unstable(feature = "step_trait", issue = "42168")]
2425
pub trait Step: Clone + PartialOrd + Sized {
2526
/// Returns the bounds on the number of *successor* steps required to get from `start` to `end`

library/core/src/macros/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ pub(crate) mod builtin {
11921192
/// ```
11931193
#[stable(feature = "rust1", since = "1.0.0")]
11941194
#[rustc_builtin_macro]
1195+
#[rustc_diagnostic_item = "macro_concat"]
11951196
#[macro_export]
11961197
macro_rules! concat {
11971198
($($e:expr),* $(,)?) => {{ /* compiler built-in */ }};

library/core/src/mem/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
481481
#[stable(feature = "rust1", since = "1.0.0")]
482482
#[rustc_promotable]
483483
#[rustc_const_stable(feature = "const_align_of", since = "1.24.0")]
484+
#[rustc_diagnostic_item = "mem_align_of"]
484485
pub const fn align_of<T>() -> usize {
485486
intrinsics::align_of::<T>()
486487
}

library/core/src/slice/raw.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a m
198198
/// Converts a reference to T into a slice of length 1 (without copying).
199199
#[stable(feature = "from_ref", since = "1.28.0")]
200200
#[rustc_const_stable(feature = "const_slice_from_ref_shared", since = "1.63.0")]
201+
#[rustc_diagnostic_item = "slice_from_ref"]
201202
#[must_use]
202203
pub const fn from_ref<T>(s: &T) -> &[T] {
203204
array::from_ref(s)

library/std/src/io/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ struct Custom {
219219
/// the recognized error kinds and fail in those cases.
220220
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
221221
#[stable(feature = "rust1", since = "1.0.0")]
222+
#[cfg_attr(not(test), rustc_diagnostic_item = "io_errorkind")]
222223
#[allow(deprecated)]
223224
#[non_exhaustive]
224225
pub enum ErrorKind {
@@ -562,6 +563,7 @@ impl Error {
562563
/// let eof_error = Error::from(ErrorKind::UnexpectedEof);
563564
/// ```
564565
#[stable(feature = "rust1", since = "1.0.0")]
566+
#[cfg_attr(not(test), rustc_diagnostic_item = "io_error_new")]
565567
#[inline(never)]
566568
pub fn new<E>(kind: ErrorKind, error: E) -> Error
567569
where

src/tools/clippy/clippy_lints/src/casts/manual_dangling_ptr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::SpanRangeExt;
3-
use clippy_utils::{expr_or_init, path_def_id, paths, std_or_core};
3+
use clippy_utils::{expr_or_init, is_path_diagnostic_item, std_or_core, sym};
44
use rustc_ast::LitKind;
55
use rustc_errors::Applicability;
66
use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, Ty, TyKind};
@@ -53,8 +53,7 @@ fn is_expr_const_aligned(cx: &LateContext<'_>, expr: &Expr<'_>, to: &Ty<'_>) ->
5353

5454
fn is_align_of_call(cx: &LateContext<'_>, fun: &Expr<'_>, to: &Ty<'_>) -> bool {
5555
if let ExprKind::Path(QPath::Resolved(_, path)) = fun.kind
56-
&& let Some(fun_id) = path_def_id(cx, fun)
57-
&& paths::ALIGN_OF.matches(cx, fun_id)
56+
&& is_path_diagnostic_item(cx, fun, sym::mem_align_of)
5857
&& let Some(args) = path.segments.last().and_then(|seg| seg.args)
5958
&& let [GenericArg::Type(generic_ty)] = args.args
6059
{

src/tools/clippy/clippy_lints/src/manual_option_as_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
33
use clippy_utils::msrvs::Msrv;
4-
use clippy_utils::{is_none_arm, msrvs, paths, peel_hir_expr_refs, sym};
4+
use clippy_utils::{is_none_arm, msrvs, peel_hir_expr_refs, sym};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::{Arm, Expr, ExprKind, LangItem, Pat, PatKind, QPath, is_range_literal};
@@ -220,5 +220,5 @@ fn is_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
220220
}
221221

222222
fn is_slice_from_ref(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
223-
paths::SLICE_FROM_REF.matches_path(cx, expr)
223+
clippy_utils::is_path_diagnostic_item(cx, expr, sym::slice_from_ref)
224224
}

src/tools/clippy/clippy_lints/src/methods/io_other_error.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::msrvs::{self, Msrv};
3-
use clippy_utils::{expr_or_init, paths};
3+
use clippy_utils::{expr_or_init, is_path_diagnostic_item, sym};
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind, QPath};
66
use rustc_lint::LateContext;
@@ -10,8 +10,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args
1010
&& !expr.span.from_expansion()
1111
&& !error_kind.span.from_expansion()
1212
&& let ExprKind::Path(QPath::TypeRelative(_, new_segment)) = path.kind
13-
&& paths::IO_ERROR_NEW.matches_path(cx, path)
14-
&& paths::IO_ERRORKIND_OTHER_CTOR.matches_path(cx, expr_or_init(cx, error_kind))
13+
&& is_path_diagnostic_item(cx, path, sym::io_error_new)
14+
&& let ExprKind::Path(QPath::Resolved(_, init_path)) = &expr_or_init(cx, error_kind).kind
15+
&& let [.., error_kind_ty, error_kind_variant] = init_path.segments
16+
&& cx.tcx.is_diagnostic_item(sym::io_errorkind, error_kind_ty.res.def_id())
17+
&& error_kind_variant.ident.name == sym::Other
1518
&& msrv.meets(cx, msrvs::IO_ERROR_OTHER)
1619
{
1720
span_lint_and_then(

src/tools/clippy/clippy_lints/src/single_range_in_vec_init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::higher::VecArgs;
33
use clippy_utils::macros::root_macro_call_first_node;
44
use clippy_utils::source::SpanRangeExt;
55
use clippy_utils::ty::implements_trait;
6-
use clippy_utils::{is_no_std_crate, paths};
6+
use clippy_utils::{is_no_std_crate, sym};
77
use rustc_ast::{LitIntType, LitKind, UintTy};
88
use rustc_errors::Applicability;
99
use rustc_hir::{Expr, ExprKind, LangItem, QPath, StructTailExpr};
@@ -100,7 +100,7 @@ impl LateLintPass<'_> for SingleRangeInVecInit {
100100
&& let Some(start_snippet) = start.span.get_source_text(cx)
101101
&& let Some(end_snippet) = end.span.get_source_text(cx)
102102
{
103-
let should_emit_every_value = if let Some(step_def_id) = paths::ITER_STEP.only(cx)
103+
let should_emit_every_value = if let Some(step_def_id) = cx.tcx.get_diagnostic_item(sym::range_step)
104104
&& implements_trait(cx, ty, step_def_id, &[])
105105
{
106106
true

src/tools/clippy/clippy_lints/src/to_digit_is_some.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::msrvs::{self, Msrv};
44
use clippy_utils::source::snippet_with_applicability;
5-
use clippy_utils::{is_in_const_context, paths, sym};
5+
use clippy_utils::{is_in_const_context, is_path_diagnostic_item, sym};
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
88
use rustc_lint::{LateContext, LateLintPass};
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome {
6262
}
6363
},
6464
hir::ExprKind::Call(to_digits_call, [char_arg, radix_arg]) => {
65-
if paths::CHAR_TO_DIGIT.matches_path(cx, to_digits_call) {
65+
if is_path_diagnostic_item(cx, to_digits_call, sym::char_to_digit) {
6666
Some((false, char_arg, radix_arg))
6767
} else {
6868
None

src/tools/clippy/clippy_lints/src/useless_concat.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::macros::macro_backtrace;
3-
use clippy_utils::paths::CONCAT;
43
use clippy_utils::source::snippet_opt;
5-
use clippy_utils::tokenize_with_text;
4+
use clippy_utils::{sym, tokenize_with_text};
65
use rustc_ast::LitKind;
76
use rustc_errors::Applicability;
87
use rustc_hir::{Expr, ExprKind};
@@ -43,7 +42,7 @@ impl LateLintPass<'_> for UselessConcat {
4342
// Get the direct parent of the expression.
4443
&& let Some(macro_call) = macro_backtrace(expr.span).next()
4544
// Check if the `concat` macro from the `core` library.
46-
&& CONCAT.matches(cx, macro_call.def_id)
45+
&& cx.tcx.is_diagnostic_item(sym::macro_concat, macro_call.def_id)
4746
// We get the original code to parse it.
4847
&& let Some(original_code) = snippet_opt(cx, macro_call.span)
4948
// This check allows us to ensure that the code snippet:

src/tools/clippy/clippy_utils/src/paths.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,6 @@ path_macros! {
126126
macro_path: PathNS::Macro,
127127
}
128128

129-
// Paths in `core`/`alloc`/`std`. This should be avoided and cleaned up by adding diagnostic items.
130-
pub static ALIGN_OF: PathLookup = value_path!(core::mem::align_of);
131-
pub static CHAR_TO_DIGIT: PathLookup = value_path!(char::to_digit);
132-
pub static CONCAT: PathLookup = macro_path!(core::concat);
133-
pub static IO_ERROR_NEW: PathLookup = value_path!(std::io::Error::new);
134-
pub static IO_ERRORKIND_OTHER_CTOR: PathLookup = value_path!(std::io::ErrorKind::Other);
135-
pub static ITER_STEP: PathLookup = type_path!(core::iter::Step);
136-
pub static SLICE_FROM_REF: PathLookup = value_path!(core::slice::from_ref);
137-
138129
// Paths in external crates
139130
pub static FUTURES_IO_ASYNCREADEXT: PathLookup = type_path!(futures_util::AsyncReadExt);
140131
pub static FUTURES_IO_ASYNCWRITEEXT: PathLookup = type_path!(futures_util::AsyncWriteExt);

tests/ui/range/range-1.stderr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ error[E0277]: the trait bound `bool: Step` is not satisfied
1010
LL | for i in false..true {}
1111
| ^^^^^^^^^^^ the trait `Step` is not implemented for `bool`
1212
|
13-
= help: the following other types implement trait `Step`:
14-
Char
15-
Ipv4Addr
16-
Ipv6Addr
17-
char
18-
i128
19-
i16
20-
i32
21-
i64
22-
and 8 others
2313
= note: required for `std::ops::Range<bool>` to implement `Iterator`
2414
= note: required for `std::ops::Range<bool>` to implement `IntoIterator`
2515

0 commit comments

Comments
 (0)