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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Clippy] Swap float_equality_without_abs to use diagnostic items in…
…stead of paths
  • Loading branch information
GnomedDev committed Sep 19, 2024
commit c89108202933fcdd6631a04b16bfebff3b9896d1
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ symbols! {
f16_nan,
f16c_target_feature,
f32,
f32_epsilon,
f32_legacy_const_digits,
f32_legacy_const_epsilon,
f32_legacy_const_infinity,
Expand All @@ -854,6 +855,7 @@ symbols! {
f32_legacy_const_radix,
f32_nan,
f64,
f64_epsilon,
f64_legacy_const_digits,
f64_legacy_const_epsilon,
f64_legacy_const_infinity,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{match_def_path, paths, sugg};
use clippy_utils::sugg;
use rustc_ast::util::parser::AssocOp;
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::source_map::Spanned;
use rustc_span::{sym, source_map::Spanned};

use super::FLOAT_EQUALITY_WITHOUT_ABS;

Expand Down Expand Up @@ -36,7 +36,7 @@ pub(crate) fn check<'tcx>(
// right hand side matches either f32::EPSILON or f64::EPSILON
&& let ExprKind::Path(ref epsilon_path) = rhs.kind
&& let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id)
&& (match_def_path(cx, def_id, &paths::F32_EPSILON) || match_def_path(cx, def_id, &paths::F64_EPSILON))
&& ([sym::f32_epsilon, sym::f64_epsilon].into_iter().any(|sym| cx.tcx.is_diagnostic_item(sym, def_id)))

// values of the subtractions on the left hand side are of the type float
&& let t_val_l = cx.typeck_results().expr_ty(val_l)
Expand Down
2 changes: 0 additions & 2 deletions src/tools/clippy/clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"];
pub const F32_EPSILON: [&str; 4] = ["core", "f32", "<impl f32>", "EPSILON"];
pub const F64_EPSILON: [&str; 4] = ["core", "f64", "<impl f64>", "EPSILON"];
pub const FILE_OPTIONS: [&str; 4] = ["std", "fs", "File", "options"];
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const FUTURES_IO_ASYNCREADEXT: [&str; 3] = ["futures_util", "io", "AsyncReadExt"];
Expand Down