Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clippy] Get rid of most std match_def_path usage, swap to diagnostic items. #130553

Merged
merged 20 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a786be5
[Clippy] Swap `map_entry` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
3ebff28
[Clippy] Swap `lines_filter_map_ok` to use a diagnostic item instead …
GnomedDev Sep 18, 2024
5e47168
[Clippy] Swap `option_as_ref_deref` to use diagnostic items instead o…
GnomedDev Sep 18, 2024
c891082
[Clippy] Swap `float_equality_without_abs` to use diagnostic items in…
GnomedDev Sep 18, 2024
afe7907
[Clippy] Swap `redundant_clone` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
037b978
[Clippy] Swap `manual_main_separator_str` to use diagnostic item inst…
GnomedDev Sep 18, 2024
28f4c82
[Clippy] Swap `single_char_add_str`/`format_push_string` to use diagn…
GnomedDev Sep 18, 2024
846ae57
[Clippy] Swap `VecArgs::hir` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
15240a9
[Clippy] Swap `repeat_vec_with_capacity` to use diagnostic item inste…
GnomedDev Sep 18, 2024
25da0e2
[Clippy] Swap `manual_while_let_some` to use diagnostic items instead…
GnomedDev Sep 18, 2024
5b55270
[Clippy] Swap `filter_map_bool_then` to use diagnostic item instead o…
GnomedDev Sep 18, 2024
372f68b
[Clippy] Swap `waker_clone_wake` to use diagnostic item instead of path
GnomedDev Sep 18, 2024
1890620
[Clippy] Swap `instant_subtraction` to use diagnostic item instead of…
GnomedDev Sep 18, 2024
89532c0
[Clippy] Swap `unnecessary_to_owned` to use diagnostic item instead o…
GnomedDev Sep 18, 2024
5f42ae1
[Clippy] Swap `manual_strip` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
5f85f73
[Clippy] Swap `unnecessary_owned_empty_strings` to use diagnostic ite…
GnomedDev Sep 18, 2024
43b8e04
[Clippy] Swap `non_octal_unix_permissions` to use diagnostic item ins…
GnomedDev Sep 18, 2024
364e552
[Clippy] Swap `iter_over_hash_type` to use diagnostic items instead o…
GnomedDev Sep 18, 2024
b2eebee
[Clippy] Swap `open_options` to use diagnostic items instead of paths
GnomedDev Sep 19, 2024
13d5732
Categorise paths in `clippy_utils::paths`
GnomedDev Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -342,6 +342,7 @@ symbols! {
Upvars,
Vec,
VecDeque,
Waker,
Wrapper,
Wrapping,
Yield,
@@ -501,6 +502,7 @@ symbols! {
black_box,
block,
bool,
bool_then,
borrowck_graphviz_format,
borrowck_graphviz_postflow,
box_new,
@@ -512,6 +514,8 @@ symbols! {
breakpoint,
bridge,
bswap,
btreemap_contains_key,
btreemap_insert,
btreeset_iter,
builtin_syntax,
c,
@@ -680,6 +684,7 @@ symbols! {
crt_dash_static: "crt-static",
csky_target_feature,
cstr_type,
cstring_as_c_str,
cstring_type,
ctlz,
ctlz_nonzero,
@@ -835,6 +840,7 @@ symbols! {
f16_nan,
f16c_target_feature,
f32,
f32_epsilon,
f32_legacy_const_digits,
f32_legacy_const_epsilon,
f32_legacy_const_infinity,
@@ -851,6 +857,7 @@ symbols! {
f32_legacy_const_radix,
f32_nan,
f64,
f64_epsilon,
f64_legacy_const_digits,
f64_legacy_const_epsilon,
f64_legacy_const_infinity,
@@ -888,6 +895,7 @@ symbols! {
field,
field_init_shorthand,
file,
file_options,
float,
float_to_int_unchecked,
floorf128,
@@ -973,7 +981,17 @@ symbols! {
half_open_range_patterns,
half_open_range_patterns_in_slices,
hash,
hashmap_contains_key,
hashmap_drain_ty,
hashmap_insert,
hashmap_iter_mut_ty,
hashmap_iter_ty,
hashmap_keys_ty,
hashmap_values_mut_ty,
hashmap_values_ty,
hashset_drain_ty,
hashset_iter,
hashset_iter_ty,
hexagon_target_feature,
hidden,
homogeneous_aggregate,
@@ -1052,6 +1070,7 @@ symbols! {
inline_const,
inline_const_pat,
inout,
instant_now,
instruction_set,
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
integral,
@@ -1352,17 +1371,22 @@ symbols! {
on,
on_unimplemented,
opaque,
open_options_new,
ops,
opt_out_copy,
optimize,
optimize_attribute,
optin_builtin_traits,
option,
option_env,
option_expect,
option_unwrap,
options,
or,
or_patterns,
ord_cmp_method,
os_str_to_os_string,
os_string_as_os_str,
other,
out,
overflow_checks,
@@ -1416,10 +1440,14 @@ symbols! {
pat_param,
patchable_function_entry,
path,
path_main_separator,
path_to_pathbuf,
pathbuf_as_path,
pattern_complexity,
pattern_parentheses,
pattern_type,
pattern_types,
permissions_from_mode,
phantom_data,
pic,
pie,
@@ -1571,6 +1599,7 @@ symbols! {
residual,
result,
result_ffi_guarantees,
result_ok_method,
resume,
return_position_impl_trait_in_trait,
return_type_notation,
@@ -1823,6 +1852,7 @@ symbols! {
slice,
slice_from_raw_parts,
slice_from_raw_parts_mut,
slice_into_vec,
slice_iter,
slice_len_fn,
slice_patterns,
@@ -1857,16 +1887,25 @@ symbols! {
store,
str,
str_chars,
str_ends_with,
str_from_utf8,
str_from_utf8_mut,
str_from_utf8_unchecked,
str_from_utf8_unchecked_mut,
str_len,
str_split_whitespace,
str_starts_with,
str_trim,
str_trim_end,
str_trim_start,
strict_provenance,
string_as_mut_str,
string_as_str,
string_deref_patterns,
string_from_utf8,
string_insert_str,
string_new,
string_push_str,
stringify,
struct_field_attributes,
struct_inherit,
@@ -2071,7 +2110,14 @@ symbols! {
var,
variant_count,
vec,
vec_as_mut_slice,
vec_as_slice,
vec_from_elem,
vec_is_empty,
vec_macro,
vec_new,
vec_pop,
vec_with_capacity,
vecdeque_iter,
version,
vfp2,
2 changes: 2 additions & 0 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
@@ -916,6 +916,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// assert_eq!(map.contains_key(&2), false);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "btreemap_contains_key")]
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
where
K: Borrow<Q> + Ord,
@@ -981,6 +982,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_confusables("push", "put", "set")]
#[cfg_attr(not(test), rustc_diagnostic_item = "btreemap_insert")]
pub fn insert(&mut self, key: K, value: V) -> Option<V>
where
K: Ord,
1 change: 1 addition & 0 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -576,6 +576,7 @@ impl CString {
#[inline]
#[must_use]
#[stable(feature = "as_c_str", since = "1.20.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_as_c_str")]
pub fn as_c_str(&self) -> &CStr {
&*self
}
1 change: 1 addition & 0 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
@@ -496,6 +496,7 @@ impl<T> [T] {
#[rustc_allow_incoherent_impl]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
#[cfg_attr(not(test), rustc_diagnostic_item = "slice_into_vec")]
pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
// N.B., see the `hack` module in this file for more details.
hack::into_vec(self)
6 changes: 6 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
@@ -440,6 +440,7 @@ impl String {
/// ```
#[inline]
#[rustc_const_stable(feature = "const_string_new", since = "1.39.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "string_new")]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
pub const fn new() -> String {
@@ -571,6 +572,7 @@ impl String {
/// [`into_bytes`]: String::into_bytes
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "string_from_utf8")]
pub fn from_utf8(vec: Vec<u8>) -> Result<String, FromUtf8Error> {
match str::from_utf8(&vec) {
Ok(..) => Ok(String { vec }),
@@ -1073,6 +1075,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "string_as_str")]
pub fn as_str(&self) -> &str {
self
}
@@ -1092,6 +1095,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "string_as_mut_str")]
pub fn as_mut_str(&mut self) -> &mut str {
self
}
@@ -1111,6 +1115,7 @@ impl String {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_confusables("append", "push")]
#[cfg_attr(not(test), rustc_diagnostic_item = "string_push_str")]
pub fn push_str(&mut self, string: &str) {
self.vec.extend_from_slice(string.as_bytes())
}
@@ -1745,6 +1750,7 @@ impl String {
#[cfg(not(no_global_oom_handling))]
#[inline]
#[stable(feature = "insert_str", since = "1.16.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "string_insert_str")]
pub fn insert_str(&mut self, idx: usize, string: &str) {
assert!(self.is_char_boundary(idx));

7 changes: 7 additions & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
@@ -416,6 +416,7 @@ impl<T> Vec<T> {
/// ```
#[inline]
#[rustc_const_stable(feature = "const_vec_new", since = "1.39.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_new")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned on Zulip already, but we typically do this by making the item a diagnostic item then checking the method's identifier. That's typically how it's suggested to be done. But regardless this way is fine, and it doesn't need to be blocked on it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had already implemented all this before talking on Zulip and seeing the idea to check method identifiers. Since there are already diagnostic items on methods, you are correct that this very much shouldn't be blocked on that though.

#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
pub const fn new() -> Self {
@@ -476,6 +477,7 @@ impl<T> Vec<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_with_capacity")]
pub fn with_capacity(capacity: usize) -> Self {
Self::with_capacity_in(capacity, Global)
}
@@ -1545,6 +1547,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[inline]
#[stable(feature = "vec_as_slice", since = "1.7.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_as_slice")]
pub fn as_slice(&self) -> &[T] {
self
}
@@ -1562,6 +1565,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[inline]
#[stable(feature = "vec_as_slice", since = "1.7.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_as_mut_slice")]
pub fn as_mut_slice(&mut self) -> &mut [T] {
self
}
@@ -2380,6 +2384,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// Takes *O*(1) time.
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_pop")]
pub fn pop(&mut self) -> Option<T> {
if self.len == 0 {
None
@@ -2573,6 +2578,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// assert!(!v.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_is_empty")]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
@@ -3044,6 +3050,7 @@ impl<T: PartialEq, A: Allocator> Vec<T, A> {
#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_from_elem")]
pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> {
<T as SpecFromElem>::from_elem(elem, n, Global)
}
1 change: 1 addition & 0 deletions library/core/src/bool.rs
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ impl bool {
/// assert_eq!(a, 1);
/// ```
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "bool_then")]
#[inline]
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
if self { Some(f()) } else { None }
1 change: 1 addition & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
@@ -415,6 +415,7 @@ impl f32 {
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
/// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "f32_epsilon")]
pub const EPSILON: f32 = 1.19209290e-07_f32;

/// Smallest finite `f32` value.
1 change: 1 addition & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
@@ -414,6 +414,7 @@ impl f64 {
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
/// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "f64_epsilon")]
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;

/// Smallest finite `f64` value.
2 changes: 2 additions & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
@@ -923,6 +923,7 @@ impl<T> Option<T> {
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "option_expect")]
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
pub const fn expect(self, msg: &str) -> T {
match self {
@@ -960,6 +961,7 @@ impl<T> Option<T> {
#[inline(always)]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "option_unwrap")]
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
pub const fn unwrap(self) -> T {
match self {
1 change: 1 addition & 0 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
@@ -653,6 +653,7 @@ impl<T, E> Result<T, E> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "result_ok_method")]
pub fn ok(self) -> Option<T> {
match self {
Ok(x) => Some(x),
3 changes: 3 additions & 0 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
@@ -134,6 +134,7 @@ impl str {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_len")]
#[must_use]
#[inline]
pub const fn len(&self) -> usize {
@@ -1157,6 +1158,7 @@ impl str {
/// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_starts_with")]
pub fn starts_with<P: Pattern>(&self, pat: P) -> bool {
pat.is_prefix_of(self)
}
@@ -1181,6 +1183,7 @@ impl str {
/// assert!(!bananas.ends_with("nana"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_ends_with")]
pub fn ends_with<P: Pattern>(&self, pat: P) -> bool
where
for<'a> P::Searcher<'a>: ReverseSearcher<'a>,
1 change: 1 addition & 0 deletions library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
@@ -414,6 +414,7 @@ impl<'a> ContextBuilder<'a> {
/// [`Wake`]: ../../alloc/task/trait.Wake.html
#[repr(transparent)]
#[stable(feature = "futures_api", since = "1.36.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Waker")]
pub struct Waker {
waker: RawWaker,
}
Loading