From a90e548338aed531e6e3c0b17af188dc23bd1747 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 8 Jan 2020 16:47:57 +0900 Subject: [PATCH] Update Clippy --- .editorconfig | 3 + .travis.yml | 14 +- CHANGELOG.md | 2 + README.md | 2 +- clippy_lints/src/assign_ops.rs | 18 +- clippy_lints/src/atomic_ordering.rs | 102 +++++++++++ clippy_lints/src/attrs.rs | 6 +- clippy_lints/src/block_in_if_condition.rs | 11 +- clippy_lints/src/booleans.rs | 13 +- clippy_lints/src/cognitive_complexity.rs | 7 +- clippy_lints/src/collapsible_if.rs | 2 +- clippy_lints/src/copies.rs | 12 +- clippy_lints/src/default_trait_access.rs | 4 +- clippy_lints/src/drop_forget_ref.rs | 6 +- clippy_lints/src/else_if_without_else.rs | 4 +- clippy_lints/src/entry.rs | 7 +- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/eval_order_dependence.rs | 11 +- clippy_lints/src/fallible_impl_from.rs | 7 +- clippy_lints/src/format.rs | 4 +- clippy_lints/src/functions.rs | 11 +- clippy_lints/src/if_not_else.rs | 4 +- clippy_lints/src/implicit_return.rs | 6 +- .../src/infallible_destructuring_match.rs | 4 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/int_plus_one.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/let_if_seq.rs | 7 +- clippy_lints/src/let_underscore.rs | 6 +- clippy_lints/src/lib.rs | 11 +- clippy_lints/src/lifetimes.rs | 15 +- clippy_lints/src/loops.rs | 41 +++-- clippy_lints/src/map_clone.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 6 +- clippy_lints/src/matches.rs | 66 +++++-- clippy_lints/src/mem_discriminant.rs | 2 +- clippy_lints/src/mem_forget.rs | 2 +- clippy_lints/src/methods/mod.rs | 35 ++-- .../src/methods/option_map_unwrap_or.rs | 13 +- .../src/methods/unnecessary_filter_map.rs | 7 +- clippy_lints/src/minmax.rs | 2 +- clippy_lints/src/misc.rs | 14 +- clippy_lints/src/missing_const_for_fn.rs | 6 +- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/mul_add.rs | 4 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/mut_mut.rs | 9 +- clippy_lints/src/mutable_debug_assertion.rs | 7 +- clippy_lints/src/mutex_atomic.rs | 4 +- clippy_lints/src/needless_bool.rs | 2 +- clippy_lints/src/needless_continue.rs | 8 +- clippy_lints/src/needless_pass_by_value.rs | 7 +- clippy_lints/src/neg_multiply.rs | 4 +- clippy_lints/src/non_copy_const.rs | 8 +- clippy_lints/src/open_options.rs | 14 +- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/ranges.rs | 2 +- clippy_lints/src/redundant_clone.rs | 9 +- clippy_lints/src/returns.rs | 13 +- clippy_lints/src/shadow.rs | 2 +- .../src/slow_vector_initialization.rs | 7 +- clippy_lints/src/suspicious_trait_impl.rs | 7 +- clippy_lints/src/tabs_in_doc_comments.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- .../src/trivially_copy_pass_by_ref.rs | 2 +- clippy_lints/src/types.rs | 59 +++--- clippy_lints/src/unsafe_removed_from_name.rs | 2 +- clippy_lints/src/unused_self.rs | 7 +- clippy_lints/src/unwrap.rs | 16 +- clippy_lints/src/use_self.rs | 11 +- clippy_lints/src/utils/author.rs | 7 +- clippy_lints/src/utils/internal_lints.rs | 7 +- clippy_lints/src/utils/mod.rs | 35 ++-- clippy_lints/src/utils/ptr.rs | 7 +- clippy_lints/src/zero_div_zero.rs | 4 +- src/driver.rs | 1 - src/lintlist/mod.rs | 84 +++++---- tests/ui/absurd-extreme-comparisons.stderr | 34 ++-- tests/ui/assign_ops2.stderr | 18 +- tests/ui/atomic_ordering_bool.rs | 25 +++ tests/ui/atomic_ordering_bool.stderr | 35 ++++ tests/ui/atomic_ordering_int.rs | 86 +++++++++ tests/ui/atomic_ordering_int.stderr | 163 +++++++++++++++++ tests/ui/atomic_ordering_ptr.rs | 27 +++ tests/ui/atomic_ordering_ptr.stderr | 35 ++++ tests/ui/atomic_ordering_uint.rs | 86 +++++++++ tests/ui/atomic_ordering_uint.stderr | 163 +++++++++++++++++ tests/ui/block_in_if_condition.stderr | 6 +- tests/ui/cast.stderr | 44 ++--- tests/ui/cast_lossless_float.stderr | 22 +-- tests/ui/cast_lossless_integer.stderr | 38 ++-- tests/ui/cast_ref_to_mut.stderr | 6 +- tests/ui/cast_size.stderr | 36 ++-- tests/ui/cast_size_32bit.stderr | 40 ++--- tests/ui/cfg_attr_rustfmt.stderr | 4 +- tests/ui/cmp_nan.stderr | 48 ++--- tests/ui/cmp_null.stderr | 4 +- tests/ui/collapsible_else_if.fixed | 66 +++++++ tests/ui/collapsible_else_if.rs | 80 +++++++++ tests/ui/collapsible_else_if.stderr | 154 ++++++++++++++++ tests/ui/collapsible_if.fixed | 58 ------ tests/ui/collapsible_if.rs | 72 -------- tests/ui/collapsible_if.stderr | 169 +----------------- tests/ui/default_trait_access.stderr | 16 +- tests/ui/dlist.stderr | 12 +- tests/ui/drop_forget_copy.stderr | 12 +- tests/ui/drop_forget_ref.stderr | 36 ++-- tests/ui/else_if_without_else.stderr | 4 +- .../empty_line_after_outer_attribute.stderr | 12 +- tests/ui/expect.stderr | 4 +- tests/ui/float_cmp.stderr | 12 +- tests/ui/float_cmp_const.stderr | 28 +-- tests/ui/for_loop_fixable.stderr | 6 +- tests/ui/format.stderr | 26 +-- tests/ui/if_not_else.stderr | 4 +- tests/ui/if_same_then_else.stderr | 2 +- tests/ui/ifs_same_cond.stderr | 6 +- tests/ui/implicit_return.stderr | 22 +-- .../ui/infallible_destructuring_match.stderr | 6 +- tests/ui/into_iter_on_ref.stderr | 52 +++--- tests/ui/large_stack_arrays.stderr | 8 +- tests/ui/let_return.rs | 22 +++ tests/ui/let_return.stderr | 8 +- tests/ui/let_underscore.stderr | 24 +-- tests/ui/map_clone.stderr | 2 +- tests/ui/map_flatten.stderr | 2 +- tests/ui/match_as_ref.stderr | 6 +- tests/ui/match_bool.stderr | 12 +- tests/ui/match_same_arms.stderr | 4 +- tests/ui/matches.stderr | 12 +- tests/ui/mem_forget.stderr | 6 +- tests/ui/min_max.stderr | 14 +- tests/ui/missing-doc-impl.rs | 87 +++++++++ tests/ui/missing-doc-impl.stderr | 103 +++++++++++ tests/ui/missing-doc.rs | 81 +-------- tests/ui/missing-doc.stderr | 145 +++------------ .../could_be_const.stderr | 16 +- tests/ui/mul_add.stderr | 10 +- tests/ui/mul_add_fixable.stderr | 12 +- tests/ui/mutex_atomic.stderr | 14 +- tests/ui/needless_continue.stderr | 12 +- tests/ui/needless_pass_by_value.stderr | 8 +- tests/ui/needless_return.stderr | 24 +-- tests/ui/neg_multiply.stderr | 4 +- tests/ui/non_copy_const.stderr | 58 +++--- tests/ui/ok_expect.stderr | 10 +- tests/ui/open_options.stderr | 14 +- tests/ui/option_map_or_none.stderr | 8 +- tests/ui/option_map_unit_fn_fixable.stderr | 34 ++-- tests/ui/option_map_unwrap_or.stderr | 20 +-- tests/ui/range.stderr | 2 +- tests/ui/redundant_clone.fixed | 4 +- tests/ui/redundant_clone.stderr | 26 ++- tests/ui/result_map_unit_fn_fixable.stderr | 34 ++-- tests/ui/result_map_unwrap_or_else.stderr | 6 +- .../ui/same_functions_in_if_condition.stderr | 12 +- tests/ui/single_char_pattern.stderr | 54 +++--- tests/ui/types.stderr | 2 +- tests/ui/unnecessary_cast_fixable.stderr | 6 +- tests/ui/unnecessary_clone.stderr | 10 +- tests/ui/unsafe_removed_from_name.stderr | 6 +- tests/ui/unwrap.stderr | 4 +- tests/ui/useless_attribute.fixed | 57 ++++++ tests/ui/useless_attribute.rs | 12 +- tests/ui/useless_attribute.stderr | 12 +- tests/ui/wild_in_or_pats.rs | 36 ++++ tests/ui/wild_in_or_pats.stderr | 35 ++++ tests/ui/wildcard_enum_match_arm.fixed | 8 +- tests/ui/wildcard_enum_match_arm.rs | 8 +- tests/ui/wildcard_enum_match_arm.stderr | 10 +- tests/ui/zero_div_zero.stderr | 8 +- 171 files changed, 2471 insertions(+), 1302 deletions(-) create mode 100644 clippy_lints/src/atomic_ordering.rs create mode 100644 tests/ui/atomic_ordering_bool.rs create mode 100644 tests/ui/atomic_ordering_bool.stderr create mode 100644 tests/ui/atomic_ordering_int.rs create mode 100644 tests/ui/atomic_ordering_int.stderr create mode 100644 tests/ui/atomic_ordering_ptr.rs create mode 100644 tests/ui/atomic_ordering_ptr.stderr create mode 100644 tests/ui/atomic_ordering_uint.rs create mode 100644 tests/ui/atomic_ordering_uint.stderr create mode 100644 tests/ui/collapsible_else_if.fixed create mode 100644 tests/ui/collapsible_else_if.rs create mode 100644 tests/ui/collapsible_else_if.stderr create mode 100644 tests/ui/missing-doc-impl.rs create mode 100644 tests/ui/missing-doc-impl.stderr create mode 100644 tests/ui/useless_attribute.fixed create mode 100644 tests/ui/wild_in_or_pats.rs create mode 100644 tests/ui/wild_in_or_pats.stderr diff --git a/.editorconfig b/.editorconfig index 3a8d3f7d8a62..a13173544d80 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,3 +14,6 @@ indent_size = 4 [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.travis.yml b/.travis.yml index bbf084259ff0..bd3003d45977 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,13 +26,23 @@ env: before_install: - export CARGO_TARGET_DIR="$TRAVIS_BUILD_DIR/target" - - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly --profile=minimal + - | + case "$TRAVIS_OS_NAME" in + linux ) HOST=x86_64-unknown-linux-gnu;; + osx ) HOST=x86_64-apple-darwin;; + windows ) HOST=x86_64-pc-windows-msvc;; + esac + - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-host="$HOST" --default-toolchain=nightly --profile=minimal - export PATH="$HOME/.cargo/bin:$PATH" install: - | if [[ -z ${INTEGRATION} ]]; then if ! rustup component add rustfmt; then - cargo install --git https://github.com/rust-lang/rustfmt --bin rustfmt + TARGET=$(rustc -Vv | awk '/host/{print $2}') + NIGHTLY=$(curl -s "https://rust-lang.github.io/rustup-components-history/${TARGET}/rustfmt") + curl -sSL "https://static.rust-lang.org/dist/${NIGHTLY}/rustfmt-nightly-${TARGET}.tar.xz" | \ + tar -xJf - --strip-components=3 -C ~/.cargo/bin + rm -rf ~/.cargo/bin/doc fi if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then . $HOME/.nvm/nvm.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 874cb056bc9e..69694da15203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1134,6 +1134,7 @@ Released 2018-09-13 [`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division [`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array [`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref +[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering [`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref [`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex [`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons @@ -1360,6 +1361,7 @@ Released 2018-09-13 [`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator [`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies [`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm +[`wildcard_in_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_in_or_patterns [`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal [`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline [`writeln_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#writeln_empty_string diff --git a/README.md b/README.md index 3b4e22c3a392..4de256e9e72f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 344 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 346 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index f0a2ebfcf3c3..0fe10a1f589d 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -1,16 +1,16 @@ +use crate::utils::{ + get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq, +}; +use crate::utils::{higher, sugg}; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_session::declare_tool_lint; -use crate::utils::{ - get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq, -}; -use crate::utils::{higher, sugg}; - declare_clippy_lint! { /// **What it does:** Checks for `a = a op b` or `a = b commutative_op a` /// patterns. @@ -209,7 +209,7 @@ fn lint_misrefactored_assign_op( db.span_suggestion( expr.span, &format!( - "Did you mean {} = {} {} {} or {}? Consider replacing it with", + "Did you mean `{} = {} {} {}` or `{}`? Consider replacing it with", snip_a, snip_a, op.node.as_str(), @@ -246,6 +246,8 @@ struct ExprVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) { self.counter += 1; @@ -253,7 +255,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs new file mode 100644 index 000000000000..fe06c63a553c --- /dev/null +++ b/clippy_lints/src/atomic_ordering.rs @@ -0,0 +1,102 @@ +use crate::utils::{match_def_path, span_help_and_lint}; +use if_chain::if_chain; +use rustc::declare_lint_pass; +use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::ty; +use rustc_hir::def_id::DefId; +use rustc_hir::*; +use rustc_session::declare_tool_lint; + +declare_clippy_lint! { + /// **What it does:** Checks for usage of invalid atomic + /// ordering in Atomic*::{load, store} calls. + /// + /// **Why is this bad?** Using an invalid atomic ordering + /// will cause a panic at run-time. + /// + /// **Known problems:** None. + /// + /// **Example:** + /// ```rust,no_run + /// # use std::sync::atomic::{AtomicBool, Ordering}; + /// + /// let x = AtomicBool::new(true); + /// + /// let _ = x.load(Ordering::Release); + /// let _ = x.load(Ordering::AcqRel); + /// + /// x.store(false, Ordering::Acquire); + /// x.store(false, Ordering::AcqRel); + /// ``` + pub INVALID_ATOMIC_ORDERING, + correctness, + "usage of invalid atomic ordering in atomic load/store calls" +} + +declare_lint_pass!(AtomicOrdering => [INVALID_ATOMIC_ORDERING]); + +const ATOMIC_TYPES: [&str; 12] = [ + "AtomicBool", + "AtomicI8", + "AtomicI16", + "AtomicI32", + "AtomicI64", + "AtomicIsize", + "AtomicPtr", + "AtomicU8", + "AtomicU16", + "AtomicU32", + "AtomicU64", + "AtomicUsize", +]; + +fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { + if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables.expr_ty(expr).kind { + ATOMIC_TYPES + .iter() + .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) + } else { + false + } +} + +fn match_ordering_def_path(cx: &LateContext<'_, '_>, did: DefId, orderings: &[&str]) -> bool { + orderings + .iter() + .any(|ordering| match_def_path(cx, did, &["core", "sync", "atomic", "Ordering", ordering])) +} + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AtomicOrdering { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + if_chain! { + if let ExprKind::MethodCall(ref method_path, _, args) = &expr.kind; + let method = method_path.ident.name.as_str(); + if type_is_atomic(cx, &args[0]); + if method == "load" || method == "store"; + let ordering_arg = if method == "load" { &args[1] } else { &args[2] }; + if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; + if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); + then { + if method == "load" && + match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) { + span_help_and_lint( + cx, + INVALID_ATOMIC_ORDERING, + ordering_arg.span, + "atomic loads cannot have `Release` and `AcqRel` ordering", + "consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`" + ); + } else if method == "store" && + match_ordering_def_path(cx, ordering_def_id, &["Acquire", "AcqRel"]) { + span_help_and_lint( + cx, + INVALID_ATOMIC_ORDERING, + ordering_arg.span, + "atomic stores cannot have `Acquire` and `AcqRel` ordering", + "consider using ordering modes `Release`, `SeqCst` or `Relaxed`" + ); + } + } + } + } +} diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index ff5688f5b7ca..c57061c0bfa9 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -187,7 +187,7 @@ declare_clippy_lint! { /// ``` pub DEPRECATED_CFG_ATTR, complexity, - "usage of `cfg_attr(rustfmt)` instead of `tool_attributes`" + "usage of `cfg_attr(rustfmt)` instead of tool attributes" } declare_lint_pass!(Attributes => [ @@ -449,7 +449,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib EMPTY_LINE_AFTER_OUTER_ATTR, begin_of_attr_to_item, "Found an empty line after an outer attribute. \ - Perhaps you forgot to add a '!' to make it an inner attribute?", + Perhaps you forgot to add a `!` to make it an inner attribute?", ); } } @@ -520,7 +520,7 @@ impl EarlyLintPass for DeprecatedCfgAttribute { cx, DEPRECATED_CFG_ATTR, attr.span, - "`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes", + "`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes", "use", "#[rustfmt::skip]".to_string(), Applicability::MachineApplicable, diff --git a/clippy_lints/src/block_in_if_condition.rs b/clippy_lints/src/block_in_if_condition.rs index 2224054af355..721314fb6669 100644 --- a/clippy_lints/src/block_in_if_condition.rs +++ b/clippy_lints/src/block_in_if_condition.rs @@ -1,8 +1,9 @@ use crate::utils::*; use matches::matches; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; @@ -51,6 +52,8 @@ struct ExVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { if let ExprKind::Closure(_, _, eid, _, _) = expr.kind { let body = self.cx.tcx.hir().body(eid); @@ -62,14 +65,14 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { } walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition"; -const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks or closures with blocks; \ - instead, move the block or closure higher and bind it with a 'let'"; +const COMPLEX_BLOCK_MESSAGE: &str = "in an `if` condition, avoid complex blocks or closures with blocks; \ + instead, move the block or closure higher and bind it with a `let`"; impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 6d918b3cc4b4..dd0a021ea388 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -4,10 +4,11 @@ use crate::utils::{ }; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit; -use rustc::hir::intravisit::*; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; +use rustc_hir::intravisit; +use rustc_hir::intravisit::*; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; @@ -438,6 +439,8 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if in_macro(e.span) { return; @@ -456,7 +459,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { _ => walk_expr(self, e), } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -471,6 +474,8 @@ struct NotSimplificationVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let ExprKind::Unary(UnOp::UnNot, inner) = &expr.kind { if let Some(suggestion) = simplify_not(self.cx, inner) { @@ -488,7 +493,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index ae293c76c090..50a7f24cadc8 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -1,8 +1,9 @@ //! calculate cognitive complexity and warn about overly complex functions -use rustc::hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::impl_lint_pass; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; +use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; @@ -141,6 +142,8 @@ struct CCHelper { } impl<'tcx> Visitor<'tcx> for CCHelper { + type Map = Map<'tcx>; + fn visit_expr(&mut self, e: &'tcx Expr<'_>) { walk_expr(self, e); match e.kind { @@ -154,7 +157,7 @@ impl<'tcx> Visitor<'tcx> for CCHelper { _ => {}, } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index 0fd0abdc39d2..e34dfc9d9993 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -138,7 +138,7 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: & if expr.span.ctxt() != inner.span.ctxt() { return; } - span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| { + span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |db| { let lhs = Sugg::ast(cx, check, ".."); let rhs = Sugg::ast(cx, check_inner, ".."); db.span_suggestion( diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index c4778c6cf43a..5d04286575ad 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -38,7 +38,7 @@ declare_clippy_lint! { /// ``` pub IFS_SAME_COND, correctness, - "consecutive `ifs` with the same condition" + "consecutive `if`s with the same condition" } declare_clippy_lint! { @@ -85,7 +85,7 @@ declare_clippy_lint! { /// ``` pub SAME_FUNCTIONS_IN_IF_CONDITION, pedantic, - "consecutive `ifs` with the same function call" + "consecutive `if`s with the same function call" } declare_clippy_lint! { @@ -106,7 +106,7 @@ declare_clippy_lint! { /// ``` pub IF_SAME_THEN_ELSE, correctness, - "if with the same *then* and *else* blocks" + "`if` with the same `then` and `else` blocks" } declare_clippy_lint! { @@ -206,7 +206,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { cx, IFS_SAME_COND, j.span, - "this `if` has the same condition as a previous if", + "this `if` has the same condition as a previous `if`", i.span, "same as this", ); @@ -234,7 +234,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { cx, SAME_FUNCTIONS_IN_IF_CONDITION, j.span, - "this `if` has the same function call as a previous if", + "this `if` has the same function call as a previous `if`", i.span, "same as this", ); @@ -300,7 +300,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) { db.span_note( i.body.span, &format!( - "`{}` has the same arm body as the `_` wildcard, consider removing it`", + "`{}` has the same arm body as the `_` wildcard, consider removing it", lhs ), ); diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 62f80ef7652b..253d9b8d542f 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -26,7 +26,7 @@ declare_clippy_lint! { /// ``` pub DEFAULT_TRAIT_ACCESS, pedantic, - "checks for literal calls to Default::default()" + "checks for literal calls to `Default::default()`" } declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]); @@ -62,7 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { cx, DEFAULT_TRAIT_ACCESS, expr.span, - &format!("Calling {} is more clear than this expression", replacement), + &format!("Calling `{}` is more clear than this expression", replacement), "try", replacement, Applicability::Unspecified, // First resolve the TODO above diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 324c3f309a4f..d8ce2fcf661a 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -102,9 +102,9 @@ const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference inste Dropping a reference does nothing."; const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ Forgetting a reference does nothing."; -const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements Copy. \ +const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \ Dropping a copy leaves the original intact."; -const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements Copy. \ +const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ Forgetting a copy leaves the original intact."; declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]); @@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef { expr.span, &msg, arg.span, - &format!("argument has type {}", arg_ty)); + &format!("argument has type `{}`", arg_ty)); } else if is_copy(cx, arg_ty) { if match_def_path(cx, def_id, &paths::DROP) { lint = DROP_COPY; diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index 9e8ab0b2920b..8043a8c85555 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -43,7 +43,7 @@ declare_clippy_lint! { /// ``` pub ELSE_IF_WITHOUT_ELSE, restriction, - "if expression with an `else if`, but without a final `else` branch" + "`if` expression with an `else if`, but without a final `else` branch" } declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]); @@ -60,7 +60,7 @@ impl EarlyLintPass for ElseIfWithoutElse { cx, ELSE_IF_WITHOUT_ELSE, els.span, - "if expression with an `else if`, but without a final `else`", + "`if` expression with an `else if`, but without a final `else`", "add an `else` block here", ); } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 44211f37e644..7a91dd53c2f5 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -3,9 +3,10 @@ use crate::utils::{get_item_name, higher, match_type, paths, snippet, snippet_op use crate::utils::{snippet_with_applicability, span_lint_and_then, walk_ptrs_ty}; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; @@ -136,6 +137,8 @@ struct InsertVisitor<'a, 'tcx, 'b> { } impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref path, _, ref params) = expr.kind; @@ -179,7 +182,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { walk_expr(self, expr); } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 5500df3db027..899e288b6ef9 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,8 +1,8 @@ -use rustc::hir::intravisit as visit; use rustc::impl_lint_pass; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::layout::LayoutOf; use rustc::ty::{self, Ty}; +use rustc_hir::intravisit as visit; use rustc_hir::HirIdSet; use rustc_hir::{self, *}; use rustc_session::declare_tool_lint; diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 9c8b77992fe5..84545ed6967d 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -1,9 +1,10 @@ use crate::utils::{get_parent_expr, span_lint, span_note_and_lint}; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; @@ -124,6 +125,8 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, e: &'tcx Expr<'_>) { match e.kind { ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), @@ -156,7 +159,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { fn visit_block(&mut self, _: &'tcx Block<'_>) { // don't continue over blocks, LateLintPass already does that } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -288,6 +291,8 @@ struct ReadVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if expr.hir_id == self.last_expr.hir_id { return; @@ -337,7 +342,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 6b6165ce18d1..6aafb5e1ef15 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -2,6 +2,7 @@ use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESU use crate::utils::{is_expn_of, match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty}; use if_chain::if_chain; use rustc::declare_lint_pass; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::{self, Ty}; use rustc_hir as hir; @@ -47,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { } fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) { - use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; + use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::*; struct FindPanicUnwrap<'a, 'tcx> { @@ -57,6 +58,8 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it } impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // check for `begin_panic` if_chain! { @@ -83,7 +86,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it intravisit::walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 28b4760f0536..bd0e1ab29093 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -46,9 +46,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat { // Operate on the only argument of `alloc::fmt::format`. if let Some(sugg) = on_new_v1(cx, expr) { - span_useless_format(cx, span, "consider using .to_string()", sugg); + span_useless_format(cx, span, "consider using `.to_string()`", sugg); } else if let Some(sugg) = on_new_v1_fmt(cx, expr) { - span_useless_format(cx, span, "consider using .to_string()", sugg); + span_useless_format(cx, span, "consider using `.to_string()`", sugg); } } } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 98c6d901d186..65a5e7be830e 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -4,13 +4,14 @@ use crate::utils::{ type_is_unsafe_function, }; use matches::matches; -use rustc::hir::intravisit; +use rustc::hir::map::Map; use rustc::impl_lint_pass; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty::{self, Ty}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::intravisit; use rustc_hir::{def::Res, def_id::DefId}; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; @@ -538,6 +539,8 @@ struct DerefVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Call(ref f, args) => { @@ -566,7 +569,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { intravisit::walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } } @@ -594,6 +597,8 @@ struct StaticMutVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { use hir::ExprKind::*; @@ -627,7 +632,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { } } - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } } diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index 7019cfa8cc8f..a266d7c24344 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -61,7 +61,7 @@ impl EarlyLintPass for IfNotElse { IF_NOT_ELSE, item.span, "Unnecessary boolean `not` operation", - "remove the `!` and swap the blocks of the if/else", + "remove the `!` and swap the blocks of the `if`/`else`", ); }, ExprKind::Binary(ref kind, _, _) if kind.node == BinOpKind::Ne => { @@ -70,7 +70,7 @@ impl EarlyLintPass for IfNotElse { IF_NOT_ELSE, item.span, "Unnecessary `!=` operation", - "change to `==` and swap the blocks of the if/else", + "change to `==` and swap the blocks of the `if`/`else`", ); }, _ => (), diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index f5633d51aa4e..ef1e7ea96dcf 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -6,10 +6,10 @@ use crate::utils::{ use if_chain::if_chain; use rustc::{ declare_lint_pass, - hir::intravisit::FnKind, lint::{LateContext, LateLintPass, LintArray, LintPass}, }; use rustc_errors::Applicability; +use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, MatchSource, StmtKind}; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; @@ -51,7 +51,7 @@ fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str) let outer_span = outer_span.source_callsite(); let inner_span = inner_span.source_callsite(); - span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| { + span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing `return` statement", |db| { if let Some(snippet) = snippet_opt(cx, inner_span) { db.span_suggestion( outer_span, @@ -102,7 +102,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { expr_match(cx, &arm.body); } } else { - expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body); + expr_match(cx, &arms.first().expect("`if let` doesn't have a single arm").body); } }, // skip if it already has a return statement diff --git a/clippy_lints/src/infallible_destructuring_match.rs b/clippy_lints/src/infallible_destructuring_match.rs index c75aa8a30e49..d70b45eaecb8 100644 --- a/clippy_lints/src/infallible_destructuring_match.rs +++ b/clippy_lints/src/infallible_destructuring_match.rs @@ -38,7 +38,7 @@ declare_clippy_lint! { /// ``` pub INFALLIBLE_DESTRUCTURING_MATCH, style, - "a match statement with a single infallible arm instead of a `let`" + "a `match` statement with a single infallible arm instead of a `let`" } declare_lint_pass!(InfallibleDestructingMatch => [INFALLIBLE_DESTRUCTURING_MATCH]); @@ -61,7 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfallibleDestructingMatch { cx, INFALLIBLE_DESTRUCTURING_MATCH, local.span, - "you seem to be trying to use match to destructure a single infallible pattern. \ + "you seem to be trying to use `match` to destructure a single infallible pattern. \ Consider using `let`", "try this", format!( diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 01e81762b4c1..9d7c3b46fed5 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -88,7 +88,7 @@ declare_clippy_lint! { /// ``` pub INHERENT_TO_STRING_SHADOW_DISPLAY, correctness, - "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait " + "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait" } declare_lint_pass!(InherentToString => [INHERENT_TO_STRING, INHERENT_TO_STRING_SHADOW_DISPLAY]); diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 9a039929e67b..d9dd13923604 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -32,7 +32,7 @@ declare_clippy_lint! { /// ``` pub INT_PLUS_ONE, complexity, - "instead of using x >= y + 1, use x > y" + "instead of using `x >= y + 1`, use `x > y`" } declare_lint_pass!(IntPlusOne => [INT_PLUS_ONE]); diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 86abf72e06d0..eef583a6e625 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { self.maximum_allowed_size ), &format!( - "consider allocating on the heap with vec!{}.into_boxed_slice()", + "consider allocating on the heap with `vec!{}.into_boxed_slice()`", snippet(cx, expr.span, "[...]") ), ); diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index b966c68e7cd2..2b430f71f225 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -1,11 +1,12 @@ use crate::utils::{higher, qpath_res, snippet, span_lint_and_then}; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::Res; +use rustc_hir::intravisit; use rustc_hir::BindingAnnotation; use rustc_session::declare_tool_lint; @@ -144,6 +145,8 @@ struct UsedVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if_chain! { if let hir::ExprKind::Path(ref qpath) = expr.kind; @@ -156,7 +159,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> { } intravisit::walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } } diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index f75711a28c3f..7787a55a2bb6 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -27,7 +27,7 @@ declare_clippy_lint! { /// ``` pub LET_UNDERSCORE_MUST_USE, restriction, - "non-binding let on a #[must_use] expression" + "non-binding let on a `#[must_use]` expression" } declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE]); @@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { cx, LET_UNDERSCORE_MUST_USE, stmt.span, - "non-binding let on an expression with #[must_use] type", + "non-binding let on an expression with `#[must_use]` type", "consider explicitly using expression value" ) } else if is_must_use_func_call(cx, init) { @@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { cx, LET_UNDERSCORE_MUST_USE, stmt.span, - "non-binding let on a result of a #[must_use] function", + "non-binding let on a result of a `#[must_use]` function", "consider explicitly using function result" ) } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 5b68ecf562bc..1a112c0d3709 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -165,6 +165,7 @@ pub mod arithmetic; pub mod as_conversions; pub mod assertions_on_constants; pub mod assign_ops; +pub mod atomic_ordering; pub mod attrs; pub mod bit_mask; pub mod blacklisted_name; @@ -466,6 +467,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &assertions_on_constants::ASSERTIONS_ON_CONSTANTS, &assign_ops::ASSIGN_OP_PATTERN, &assign_ops::MISREFACTORED_ASSIGN_OP, + &atomic_ordering::INVALID_ATOMIC_ORDERING, &attrs::DEPRECATED_CFG_ATTR, &attrs::DEPRECATED_SEMVER, &attrs::EMPTY_LINE_AFTER_OUTER_ATTR, @@ -598,6 +600,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &matches::SINGLE_MATCH, &matches::SINGLE_MATCH_ELSE, &matches::WILDCARD_ENUM_MATCH_ARM, + &matches::WILDCARD_IN_OR_PATTERNS, &mem_discriminant::MEM_DISCRIMINANT_NON_ENUM, &mem_forget::MEM_FORGET, &mem_replace::MEM_REPLACE_OPTION_WITH_NONE, @@ -984,6 +987,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_early_pass(|| box as_conversions::AsConversions); store.register_early_pass(|| box utils::internal_lints::ProduceIce); store.register_late_pass(|| box let_underscore::LetUnderscore); + store.register_late_pass(|| box atomic_ordering::AtomicOrdering); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), @@ -1089,6 +1093,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&assertions_on_constants::ASSERTIONS_ON_CONSTANTS), LintId::of(&assign_ops::ASSIGN_OP_PATTERN), LintId::of(&assign_ops::MISREFACTORED_ASSIGN_OP), + LintId::of(&atomic_ordering::INVALID_ATOMIC_ORDERING), LintId::of(&attrs::DEPRECATED_CFG_ATTR), LintId::of(&attrs::DEPRECATED_SEMVER), LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS), @@ -1184,6 +1189,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&matches::MATCH_REF_PATS), LintId::of(&matches::MATCH_WILD_ERR_ARM), LintId::of(&matches::SINGLE_MATCH), + LintId::of(&matches::WILDCARD_IN_OR_PATTERNS), LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), @@ -1292,6 +1298,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&to_digit_is_some::TO_DIGIT_IS_SOME), LintId::of(&transmute::CROSSPOINTER_TRANSMUTE), LintId::of(&transmute::TRANSMUTE_BYTES_TO_STR), + LintId::of(&transmute::TRANSMUTE_FLOAT_TO_INT), LintId::of(&transmute::TRANSMUTE_INT_TO_BOOL), LintId::of(&transmute::TRANSMUTE_INT_TO_CHAR), LintId::of(&transmute::TRANSMUTE_INT_TO_FLOAT), @@ -1457,6 +1464,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN), LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN), LintId::of(&matches::MATCH_AS_REF), + LintId::of(&matches::WILDCARD_IN_OR_PATTERNS), LintId::of(&methods::CHARS_NEXT_CMP), LintId::of(&methods::CLONE_ON_COPY), LintId::of(&methods::FILTER_NEXT), @@ -1490,6 +1498,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&temporary_assignment::TEMPORARY_ASSIGNMENT), LintId::of(&transmute::CROSSPOINTER_TRANSMUTE), LintId::of(&transmute::TRANSMUTE_BYTES_TO_STR), + LintId::of(&transmute::TRANSMUTE_FLOAT_TO_INT), LintId::of(&transmute::TRANSMUTE_INT_TO_BOOL), LintId::of(&transmute::TRANSMUTE_INT_TO_CHAR), LintId::of(&transmute::TRANSMUTE_INT_TO_FLOAT), @@ -1509,6 +1518,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_group(true, "clippy::correctness", Some("clippy_correctness"), vec![ LintId::of(&approx_const::APPROX_CONSTANT), + LintId::of(&atomic_ordering::INVALID_ATOMIC_ORDERING), LintId::of(&attrs::DEPRECATED_SEMVER), LintId::of(&attrs::USELESS_ATTRIBUTE), LintId::of(&bit_mask::BAD_BIT_MASK), @@ -1607,7 +1617,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&mutex_atomic::MUTEX_INTEGER), LintId::of(&needless_borrow::NEEDLESS_BORROW), LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE), - LintId::of(&transmute::TRANSMUTE_FLOAT_TO_INT), LintId::of(&use_self::USE_SELF), ]); } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 0c72c9c6aa04..83f9cf9eac5f 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -1,9 +1,10 @@ use matches::matches; use rustc::declare_lint_pass; -use rustc::hir::intravisit::*; +use rustc::hir::map::Map; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::{DefKind, Res}; +use rustc_hir::intravisit::*; use rustc_hir::FunctionRetTy::Return; use rustc_hir::*; use rustc_session::declare_tool_lint; @@ -359,6 +360,8 @@ impl<'v, 't> RefVisitor<'v, 't> { } impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { self.record(&Some(*lifetime)); @@ -398,7 +401,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { } walk_ty(self, ty); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -453,6 +456,8 @@ struct LifetimeChecker { } impl<'tcx> Visitor<'tcx> for LifetimeChecker { + type Map = Map<'tcx>; + // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { self.map.remove(&lifetime.name.ident().name); @@ -468,7 +473,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker { walk_generic_param(self, param) } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -502,6 +507,8 @@ struct BodyLifetimeChecker { } impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { + type Map = Map<'tcx>; + // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { if lifetime.name.ident().name != kw::Invalid && lifetime.name.ident().name != kw::StaticLifetime { @@ -509,7 +516,7 @@ impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index acff3e2f7409..1c7407eebc68 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -2,17 +2,18 @@ use crate::reexport::*; use if_chain::if_chain; use itertools::Itertools; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::middle::region; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id; +use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; // use rustc::middle::region::CodeExtent; use crate::consts::{constant, Constant}; use crate::utils::usage::mutated_variables; use crate::utils::{is_type_diagnostic_item, qpath_res, same_tys, sext, sugg}; +use rustc::hir::map::Map; use rustc::ty::{self, Ty}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; @@ -1353,7 +1354,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e EXPLICIT_INTO_ITER_LOOP, arg.span, "it is more concise to loop over containers instead of using explicit \ - iteration methods`", + iteration methods", "to write this more concisely, try", object.to_string(), applicability, @@ -1706,6 +1707,8 @@ struct UsedVisitor { } impl<'tcx> Visitor<'tcx> for UsedVisitor { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if match_var(expr, self.var) { self.used = true; @@ -1714,7 +1717,7 @@ impl<'tcx> Visitor<'tcx> for UsedVisitor { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -1726,6 +1729,8 @@ struct LocalUsedVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for LocalUsedVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if same_var(self.cx, expr, self.local) { self.used = true; @@ -1734,7 +1739,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LocalUsedVisitor<'a, 'tcx> { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -1824,6 +1829,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { // a range index op @@ -1905,7 +1912,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } self.prefer_mutable = old; } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -1950,6 +1957,8 @@ struct VarUsedAfterLoopVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.past_while_let { if Some(self.def_id) == var_def_id(self.cx, expr) { @@ -1960,7 +1969,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { } walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -2058,6 +2067,8 @@ struct IncrementVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.done { return; @@ -2100,7 +2111,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { } walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -2117,6 +2128,8 @@ struct InitializeVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { // Look for declarations of the variable if let StmtKind::Local(ref local) = stmt.kind { @@ -2190,7 +2203,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir()) } } @@ -2285,6 +2298,8 @@ struct LoopNestVisitor { } impl<'tcx> Visitor<'tcx> for LoopNestVisitor { + type Map = Map<'tcx>; + fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { if stmt.hir_id == self.hir_id { self.nesting = LookFurther; @@ -2324,7 +2339,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { walk_pat(self, pat) } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -2392,6 +2407,8 @@ struct HasBreakOrReturnVisitor { } impl<'a, 'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.has_break_or_return { return; @@ -2408,7 +2425,7 @@ impl<'a, 'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -2447,6 +2464,8 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { match ex.kind { ExprKind::Path(_) => self.insert_def_id(ex), @@ -2457,7 +2476,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 0c66ce5dde55..ae2d08301285 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -112,7 +112,7 @@ fn lint_needless_cloning(cx: &LateContext<'_, '_>, root: Span, receiver: Span) { MAP_CLONE, root.trim_start(receiver).unwrap(), "You are needlessly cloning iterator elements", - "Remove the map call", + "Remove the `map` call", String::new(), Applicability::MachineApplicable, ) diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index d0164e5e2907..3855b5a21f99 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -48,7 +48,7 @@ declare_clippy_lint! { /// ``` pub OPTION_MAP_UNIT_FN, complexity, - "using `option.map(f)`, where f is a function or closure that returns ()" + "using `option.map(f)`, where `f` is a function or closure that returns `()`" } declare_clippy_lint! { @@ -89,7 +89,7 @@ declare_clippy_lint! { /// ``` pub RESULT_MAP_UNIT_FN, complexity, - "using `result.map(f)`, where f is a function or closure that returns ()" + "using `result.map(f)`, where `f` is a function or closure that returns `()`" } declare_lint_pass!(MapUnit => [OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN]); @@ -199,7 +199,7 @@ fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr<'_>) -> String #[must_use] fn suggestion_msg(function_type: &str, map_type: &str) -> String { format!( - "called `map(f)` on an {0} value where `f` is a unit {1}", + "called `map(f)` on an `{0}` value where `f` is a unit {1}", map_type, function_type ) } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 476051500f56..6b5b4e4c4f0b 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -3,7 +3,8 @@ use crate::utils::paths; use crate::utils::sugg::Sugg; use crate::utils::{ expr_block, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg, remove_blocks, snippet, - snippet_with_applicability, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, + snippet_with_applicability, span_help_and_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, + walk_ptrs_ty, }; use if_chain::if_chain; use rustc::declare_lint_pass; @@ -37,7 +38,7 @@ declare_clippy_lint! { /// ``` pub SINGLE_MATCH, style, - "a match statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`" + "a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`" } declare_clippy_lint! { @@ -76,7 +77,7 @@ declare_clippy_lint! { /// ``` pub SINGLE_MATCH_ELSE, pedantic, - "a match statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern" + "a `match` statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern" } declare_clippy_lint! { @@ -99,7 +100,7 @@ declare_clippy_lint! { /// ``` pub MATCH_REF_PATS, style, - "a match or `if let` with all arms prefixed with `&` instead of deref-ing the match expression" + "a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression" } declare_clippy_lint! { @@ -133,7 +134,7 @@ declare_clippy_lint! { /// ``` pub MATCH_BOOL, style, - "a match on a boolean expression instead of an `if..else` block" + "a `match` on a boolean expression instead of an `if..else` block" } declare_clippy_lint! { @@ -155,7 +156,7 @@ declare_clippy_lint! { /// ``` pub MATCH_OVERLAPPING_ARM, style, - "a match with overlapping arms" + "a `match` with overlapping arms" } declare_clippy_lint! { @@ -177,7 +178,7 @@ declare_clippy_lint! { /// ``` pub MATCH_WILD_ERR_ARM, style, - "a match with `Err(_)` arm and take drastic actions" + "a `match` with `Err(_)` arm and take drastic actions" } declare_clippy_lint! { @@ -198,7 +199,7 @@ declare_clippy_lint! { /// ``` pub MATCH_AS_REF, complexity, - "a match on an Option value instead of using `as_ref()` or `as_mut`" + "a `match` on an Option value instead of using `as_ref()` or `as_mut`" } declare_clippy_lint! { @@ -223,6 +224,26 @@ declare_clippy_lint! { "a wildcard enum match arm using `_`" } +declare_clippy_lint! { + /// **What it does:** Checks for wildcard pattern used with others patterns in same match arm. + /// + /// **Why is this bad?** Wildcard pattern already covers any other pattern as it will match anyway. + /// It makes the code less readable, especially to spot wildcard pattern use in match arm. + /// + /// **Known problems:** None. + /// + /// **Example:** + /// ```rust + /// match "foo" { + /// "a" => {}, + /// "bar" | _ => {}, + /// } + /// ``` + pub WILDCARD_IN_OR_PATTERNS, + complexity, + "a wildcard pattern used with others patterns in same match arm" +} + declare_lint_pass!(Matches => [ SINGLE_MATCH, MATCH_REF_PATS, @@ -231,7 +252,8 @@ declare_lint_pass!(Matches => [ MATCH_OVERLAPPING_ARM, MATCH_WILD_ERR_ARM, MATCH_AS_REF, - WILDCARD_ENUM_MATCH_ARM + WILDCARD_ENUM_MATCH_ARM, + WILDCARD_IN_OR_PATTERNS ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { @@ -246,6 +268,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { check_wild_err_arm(cx, ex, arms); check_wild_enum_match(cx, ex, arms); check_match_as_ref(cx, ex, arms, expr); + check_wild_in_or_pats(cx, arms); } if let ExprKind::Match(ref ex, ref arms, _) = expr.kind { check_match_ref_pats(cx, ex, arms, expr); @@ -407,7 +430,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], e if let Some(sugg) = sugg { db.span_suggestion( expr.span, - "consider using an if/else expression", + "consider using an `if`/`else` expression", sugg, Applicability::HasPlaceholders, ); @@ -461,10 +484,10 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) span_note_and_lint(cx, MATCH_WILD_ERR_ARM, arm.pat.span, - "Err(_) will match all errors, maybe not a good idea", + "`Err(_)` will match all errors, maybe not a good idea", arm.pat.span, "to remove this warning, match each error separately \ - or use unreachable macro"); + or use `unreachable!` macro"); } } } @@ -650,7 +673,7 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], cx, MATCH_AS_REF, expr.span, - &format!("use {}() instead", suggestion), + &format!("use `{}()` instead", suggestion), "try this", format!( "{}.{}(){}", @@ -664,6 +687,23 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], } } +fn check_wild_in_or_pats(cx: &LateContext<'_, '_>, arms: &[Arm<'_>]) { + for arm in arms { + if let PatKind::Or(ref fields) = arm.pat.kind { + // look for multiple fields in this arm that contains at least one Wild pattern + if fields.len() > 1 && fields.iter().any(is_wild) { + span_help_and_lint( + cx, + WILDCARD_IN_OR_PATTERNS, + arm.pat.span, + "wildcard pattern covers any other pattern as it will match anyway.", + "Consider handling `_` separately.", + ); + } + } + } +} + /// Gets all arms that are unbounded `PatRange`s. fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm<'_>]) -> Vec> { arms.iter() diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index 22797c3b754c..636c0f975789 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -25,7 +25,7 @@ declare_clippy_lint! { /// ``` pub MEM_DISCRIMINANT_NON_ENUM, correctness, - "calling mem::descriminant on non-enum type" + "calling `mem::descriminant` on non-enum type" } declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]); diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index 974f6419ee69..4172ea33950c 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget { let forgot_ty = cx.tables.expr_ty(&args[0]); if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { - span_lint(cx, MEM_FORGET, e.span, "usage of mem::forget on Drop type"); + span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type"); } } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index c33dae6c283d..3f621cb8b287 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -10,11 +10,12 @@ use std::iter; use if_chain::if_chain; use matches::matches; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{self, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass}; use rustc::ty::{self, Predicate, Ty}; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::intravisit::{self, Visitor}; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, Symbol, SymbolStr}; @@ -1412,6 +1413,8 @@ fn lint_or_fun_call<'a, 'tcx>( } impl<'a, 'tcx> intravisit::Visitor<'tcx> for FunCallFinder<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { let call_found = match &expr.kind { // ignore enum and struct constructors @@ -1429,7 +1432,7 @@ fn lint_or_fun_call<'a, 'tcx>( } } - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } } @@ -1828,7 +1831,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &h cx, CLONE_ON_REF_PTR, expr.span, - "using '.clone()' on a ref-counted pointer", + "using `.clone()` on a ref-counted pointer", "try this", format!( "{}::<{}>::clone(&{})", @@ -2220,8 +2223,8 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi lint, expr.span, &format!( - "used unwrap() on {} value. If you don't want to handle the {} case gracefully, consider \ - using expect() to provide a better panic \ + "used `unwrap()` on `{}` value. If you don't want to handle the `{}` case gracefully, consider \ + using `expect()` to provide a better panic \ message", kind, none_value ), @@ -2247,7 +2250,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi lint, expr.span, &format!( - "used expect() on {} value. If this value is an {} it will panic", + "used `expect()` on `{}` value. If this value is an `{}` it will panic", kind, none_value ), ); @@ -2268,7 +2271,7 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir cx, OK_EXPECT, expr.span, - "called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`", + "called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result`", ); } } @@ -2286,7 +2289,7 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr< span_lint_and_then(cx, MAP_FLATTEN, expr.span, msg, |db| { db.span_suggestion( expr.span, - "try using flat_map instead", + "try using `flat_map` instead", hint, Applicability::MachineApplicable, ); @@ -2320,10 +2323,10 @@ fn lint_map_unwrap_or_else<'a, 'tcx>( // lint message let msg = if is_option { - "called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling \ + "called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling \ `map_or_else(g, f)` instead" } else { - "called `map(f).unwrap_or_else(g)` on a Result value. This can be done more directly by calling \ + "called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling \ `.map_or_else(g, f)` instead" }; // get snippets for args to map() and unwrap_or_else() @@ -2380,7 +2383,7 @@ fn lint_map_or_none<'a, 'tcx>( if map_or_arg_is_none { // lint message - let msg = "called `map_or(None, f)` on an Option value. This can be done more directly by calling \ + let msg = "called `map_or(None, f)` on an `Option` value. This can be done more directly by calling \ `and_then(f)` instead"; let map_or_self_snippet = snippet(cx, map_or_args[0].span, ".."); let map_or_func_snippet = snippet(cx, map_or_args[2].span, ".."); @@ -2388,7 +2391,7 @@ fn lint_map_or_none<'a, 'tcx>( span_lint_and_then(cx, OPTION_MAP_OR_NONE, expr.span, msg, |db| { db.span_suggestion( expr.span, - "try using and_then instead", + "try using `and_then` instead", hint, Applicability::MachineApplicable, // snippet ); @@ -2860,7 +2863,7 @@ fn lint_single_char_pattern<'a, 'tcx>( SINGLE_CHAR_PATTERN, arg.span, "single-character string constant used as pattern", - "try using a char instead", + "try using a `char` instead", hint, applicability, ); @@ -2928,7 +2931,7 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, self_ref_ty: T INTO_ITER_ON_REF, method_span, &format!( - "this .into_iter() call is equivalent to .{}() and will not move the {}", + "this `.into_iter()` call is equivalent to `.{}()` and will not move the `{}`", method_name, kind, ), "call directly", @@ -3188,6 +3191,8 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool { } impl<'tcx> intravisit::Visitor<'tcx> for RetCallFinder { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if self.found { return; @@ -3199,7 +3204,7 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool { } } - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } } diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index c9cb17e965eb..6381c32d395d 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -1,9 +1,10 @@ use crate::utils::{differing_macro_contexts, paths, snippet_with_applicability, span_lint_and_then}; use crate::utils::{is_copy, match_type}; -use rustc::hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::LateContext; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; +use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; use rustc_hir::{self, *}; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; @@ -60,7 +61,7 @@ pub(super) fn lint<'a, 'tcx>( "map_or(a, f)" }; let msg = &format!( - "called `map(f).unwrap_or({})` on an Option value. \ + "called `map(f).unwrap_or({})` on an `Option` value. \ This can be done more directly by calling `{}` instead", arg, suggest ); @@ -91,12 +92,14 @@ struct UnwrapVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { self.identifiers.insert(ident(path)); walk_path(self, path); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.cx.tcx.hir()) } } @@ -108,6 +111,8 @@ struct MapExprVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { if self.identifiers.contains(&ident(path)) { self.found_identifier = true; @@ -116,7 +121,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> { walk_path(self, path); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.cx.tcx.hir()) } } diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index b77a40c6fc03..62b30baef18a 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -1,10 +1,11 @@ use crate::utils::paths; use crate::utils::usage::mutated_variables; use crate::utils::{match_qpath, match_trait_method, span_lint}; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::LateContext; use rustc_hir as hir; use rustc_hir::def::Res; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use if_chain::if_chain; @@ -123,6 +124,8 @@ impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if let hir::ExprKind::Ret(Some(expr)) = &expr.kind { let (found_mapping, found_filtering) = check_expression(self.cx, self.arg_id, expr); @@ -133,7 +136,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 4e2948620e2d..749f6b925151 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass { cx, MIN_MAX, expr.span, - "this min/max combination leads to constant result", + "this `min`/`max` combination leads to constant result", ); }, } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 202fb4cdcf7f..2195b486fd9c 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -1,10 +1,10 @@ use if_chain::if_chain; use matches::matches; use rustc::declare_lint_pass; -use rustc::hir::intravisit::FnKind; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; use rustc_errors::Applicability; +use rustc_hir::intravisit::FnKind; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::source_map::{ExpnKind, Span}; @@ -63,7 +63,7 @@ declare_clippy_lint! { /// ``` pub CMP_NAN, correctness, - "comparisons to NAN, which will always return false, probably not intended" + "comparisons to `NAN`, which will always return false, probably not intended" } declare_clippy_lint! { @@ -194,7 +194,7 @@ declare_clippy_lint! { /// ``` pub ZERO_PTR, style, - "using 0 as *{const, mut} T" + "using `0 as *{const, mut} T`" } declare_clippy_lint! { @@ -370,9 +370,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { } } let (lint, msg) = if is_named_constant(cx, left) || is_named_constant(cx, right) { - (FLOAT_CMP_CONST, "strict comparison of f32 or f64 constant") + (FLOAT_CMP_CONST, "strict comparison of `f32` or `f64` constant") } else { - (FLOAT_CMP, "strict comparison of f32 or f64") + (FLOAT_CMP, "strict comparison of `f32` or `f64`") }; span_lint_and_then(cx, lint, expr.span, msg, |db| { let lhs = Sugg::hir(cx, left, ".."); @@ -388,7 +388,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { ), Applicability::HasPlaceholders, // snippet ); - db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available."); + db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available."); }); } else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) { span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0"); @@ -456,7 +456,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { cx, CMP_NAN, cmp_expr.span, - "doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead", + "doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead", ); } } diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 980812c9e0ca..de734ccb6774 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -1,8 +1,8 @@ use crate::utils::{has_drop, is_entrypoint_fn, span_lint, trait_ref_of_method}; use rustc::declare_lint_pass; -use rustc::hir::intravisit::FnKind; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass}; use rustc_hir as hir; +use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Constness, FnDecl, HirId}; use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn; use rustc_session::declare_tool_lint; @@ -109,11 +109,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { let mir = cx.tcx.optimized_mir(def_id); if let Err((span, err)) = is_min_const_fn(cx.tcx, def_id, &mir) { - if cx.tcx.is_min_const_fn(def_id) { + if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id) { cx.tcx.sess.span_err(span, &err); } } else { - span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a const_fn"); + span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`"); } } } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 1ad3dff531dc..c25131c520cb 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -54,7 +54,7 @@ declare_clippy_lint! { /// ``` pub MISSING_INLINE_IN_PUBLIC_ITEMS, restriction, - "detects missing #[inline] attribute for public callables (functions, trait methods, methods...)" + "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)" } fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { diff --git a/clippy_lints/src/mul_add.rs b/clippy_lints/src/mul_add.rs index 1f4f0d53cccb..27f598c141e1 100644 --- a/clippy_lints/src/mul_add.rs +++ b/clippy_lints/src/mul_add.rs @@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MulAddCheck { cx, MANUAL_MUL_ADD, expr.span, - "consider using mul_add() for better numerical precision", + "consider using `mul_add()` for better numerical precision", "try", format!( "{}.mul_add({}, {})", @@ -94,7 +94,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MulAddCheck { cx, MANUAL_MUL_ADD, expr.span, - "consider using mul_add() for better numerical precision", + "consider using `mul_add()` for better numerical precision", "try", format!( "{}.mul_add({}, {})", diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 367f8638dc78..a64467ef6a24 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -47,7 +47,7 @@ declare_clippy_lint! { /// ``` pub MUTABLE_KEY_TYPE, correctness, - "Check for mutable Map/Set key type" + "Check for mutable `Map`/`Set` key type" } declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]); diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index c2e99c3559d8..5cc599368521 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -1,9 +1,10 @@ use crate::utils::{higher, span_lint}; use rustc::declare_lint_pass; -use rustc::hir::intravisit; +use rustc::hir::map::Map; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; use rustc_hir as hir; +use rustc_hir::intravisit; use rustc_session::declare_tool_lint; declare_clippy_lint! { @@ -33,7 +34,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut { } fn check_ty(&mut self, cx: &LateContext<'a, 'tcx>, ty: &'tcx hir::Ty<'_>) { - use rustc::hir::intravisit::Visitor; + use rustc_hir::intravisit::Visitor; MutVisitor { cx }.visit_ty(ty); } @@ -44,6 +45,8 @@ pub struct MutVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if in_external_macro(self.cx.sess(), expr.span) { return; @@ -105,7 +108,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { intravisit::walk_ty(self, ty); } - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } } diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index bbcfcd436135..0918886a9793 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -1,9 +1,10 @@ use crate::utils::{is_direct_expn_of, span_lint}; use if_chain::if_chain; use matches::matches; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_lint_pass, ty}; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, StmtKind, UnOp}; use rustc_session::declare_tool_lint; use rustc_span::Span; @@ -127,6 +128,8 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { match expr.kind { ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) => { @@ -150,7 +153,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { walk_expr(self, expr) } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir()) } } diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index fb3c767caca5..e04bd56e054f 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -63,8 +63,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex { let mutex_param = subst.type_at(0); if let Some(atomic_name) = get_atomic_name(mutex_param) { let msg = format!( - "Consider using an {} instead of a Mutex here. If you just want the locking \ - behaviour and not the internal type, consider using Mutex<()>.", + "Consider using an `{}` instead of a `Mutex` here. If you just want the locking \ + behavior and not the internal type, consider using `Mutex<()>`.", atomic_name ); match mutex_param.kind { diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index c11e6bf25f43..78c121b6dd8a 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { _ => (), } } else { - panic!("IfExpr 'then' node is not an ExprKind::Block"); + panic!("IfExpr `then` node is not an `ExprKind::Block`"); } } } diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index e5ba77d21f69..f35b84c449b2 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -274,15 +274,15 @@ struct LintData<'a> { block_stmts: &'a [ast::Stmt], } -const MSG_REDUNDANT_ELSE_BLOCK: &str = "This else block is redundant.\n"; +const MSG_REDUNDANT_ELSE_BLOCK: &str = "This `else` block is redundant.\n"; const MSG_ELSE_BLOCK_NOT_NEEDED: &str = "There is no need for an explicit `else` block for this `if` \ expression\n"; -const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "Consider dropping the else clause and merging the code that \ - follows (in the loop) with the if block, like so:\n"; +const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "Consider dropping the `else` clause and merging the code that \ + follows (in the loop) with the `if` block, like so:\n"; -const DROP_ELSE_BLOCK_MSG: &str = "Consider dropping the else clause, and moving out the code in the else \ +const DROP_ELSE_BLOCK_MSG: &str = "Consider dropping the `else` clause, and moving out the code in the `else` \ block, like so:\n"; fn emit_warning<'a>(ctx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str, typ: LintType) { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index c580715a1b21..12be861a9ff3 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -6,12 +6,13 @@ use crate::utils::{ use if_chain::if_chain; use matches::matches; use rustc::declare_lint_pass; -use rustc::hir::intravisit::FnKind; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::traits; +use rustc::traits::misc::can_type_implement_copy; use rustc::ty::{self, RegionKind, TypeFoldable}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; +use rustc_hir::intravisit::FnKind; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::{Span, Symbol}; @@ -205,8 +206,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let sugg = |db: &mut DiagnosticBuilder<'_>| { if let ty::Adt(def, ..) = ty.kind { if let Some(span) = cx.tcx.hir().span_if_local(def.did) { - if cx.param_env.can_type_implement_copy(cx.tcx, ty).is_ok() { - db.span_help(span, "consider marking this type as Copy"); + if can_type_implement_copy(cx.tcx, cx.param_env, ty).is_ok() { + db.span_help(span, "consider marking this type as `Copy`"); } } } diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 9757d1c01b95..6e77a7a77fa0 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -21,7 +21,7 @@ declare_clippy_lint! { /// ``` pub NEG_MULTIPLY, style, - "multiplying integers with -1" + "multiplying integers with `-1`" } declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]); @@ -48,7 +48,7 @@ fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_ if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit)); if cx.tables.expr_ty(exp).is_integral(); then { - span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with -1"); + span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with `-1`"); } } } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 039de766c086..6ffad405c2a2 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -49,7 +49,7 @@ declare_clippy_lint! { /// ``` pub DECLARE_INTERIOR_MUTABLE_CONST, correctness, - "declaring const with interior mutability" + "declaring `const` with interior mutability" } declare_clippy_lint! { @@ -81,7 +81,7 @@ declare_clippy_lint! { /// ``` pub BORROW_INTERIOR_MUTABLE_CONST, correctness, - "referencing const with interior mutability" + "referencing `const` with interior mutability" } #[allow(dead_code)] @@ -98,12 +98,12 @@ impl Source { match self { Self::Item { item } | Self::Assoc { item, .. } => ( DECLARE_INTERIOR_MUTABLE_CONST, - "a const item should never be interior mutable", + "a `const` item should never be interior mutable", *item, ), Self::Expr { expr } => ( BORROW_INTERIOR_MUTABLE_CONST, - "a const item with interior mutability should not be borrowed", + "a `const` item with interior mutability should not be borrowed", *expr, ), } diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 7ae73edc0164..f41ac30c4815 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -123,7 +123,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument cx, NONSENSICAL_OPEN_OPTIONS, span, - "the method \"create\" is called more than once", + "the method `create` is called more than once", ); } else { create = true @@ -136,7 +136,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument cx, NONSENSICAL_OPEN_OPTIONS, span, - "the method \"append\" is called more than once", + "the method `append` is called more than once", ); } else { append = true @@ -149,7 +149,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument cx, NONSENSICAL_OPEN_OPTIONS, span, - "the method \"truncate\" is called more than once", + "the method `truncate` is called more than once", ); } else { truncate = true @@ -162,7 +162,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument cx, NONSENSICAL_OPEN_OPTIONS, span, - "the method \"read\" is called more than once", + "the method `read` is called more than once", ); } else { read = true @@ -175,7 +175,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument cx, NONSENSICAL_OPEN_OPTIONS, span, - "the method \"write\" is called more than once", + "the method `write` is called more than once", ); } else { write = true @@ -190,7 +190,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument cx, NONSENSICAL_OPEN_OPTIONS, span, - "file opened with \"truncate\" and \"read\"", + "file opened with `truncate` and `read`", ); } if append && truncate && append_arg && truncate_arg { @@ -198,7 +198,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument cx, NONSENSICAL_OPEN_OPTIONS, span, - "file opened with \"append\" and \"truncate\"", + "file opened with `append` and `truncate`", ); } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 87a487c3b9eb..907a46846d07 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr { cx, CMP_NULL, expr.span, - "Comparing with null is better expressed by the .is_null() method", + "Comparing with null is better expressed by the `.is_null()` method", ); } } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 7787aa326613..a5e61da67401 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -112,7 +112,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges { span_lint(cx, RANGE_ZIP_WITH_LEN, expr.span, - &format!("It is more idiomatic to use {}.iter().enumerate()", + &format!("It is more idiomatic to use `{}.iter().enumerate()`", snippet(cx, iter_args[0].span, "_"))); } } diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 12c99bc8f9bb..c11dfb06a66a 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -5,7 +5,6 @@ use crate::utils::{ use if_chain::if_chain; use matches::matches; use rustc::declare_lint_pass; -use rustc::hir::intravisit::FnKind; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::mir::{ self, traversal, @@ -14,6 +13,7 @@ use rustc::mir::{ use rustc::ty::{self, fold::TypeVisitor, Ty}; use rustc_data_structures::{fx::FxHashMap, transitive_relation::TransitiveRelation}; use rustc_errors::Applicability; +use rustc_hir::intravisit::FnKind; use rustc_hir::{def_id, Body, FnDecl, HirId}; use rustc_index::bit_set::{BitSet, HybridBitSet}; use rustc_mir::dataflow::{ @@ -307,6 +307,13 @@ fn find_stmt_assigns_to<'tcx>( (true, mir::Rvalue::Ref(_, _, place)) | (false, mir::Rvalue::Use(mir::Operand::Copy(place))) => { base_local_and_movability(cx, mir, place) }, + (false, mir::Rvalue::Ref(_, _, place)) => { + if let [mir::ProjectionElem::Deref] = place.as_ref().projection { + base_local_and_movability(cx, mir, place) + } else { + None + } + }, _ => None, } } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 96e9fb2c409b..ced784ca4917 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -8,7 +8,7 @@ use rustc_span::BytePos; use syntax::ast; use syntax::visit::FnKind; -use crate::utils::{match_path_ast, snippet_opt, span_lint_and_then}; +use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then}; declare_clippy_lint! { /// **What it does:** Checks for return statements at the end of a block. @@ -154,7 +154,7 @@ impl Return { return; } - span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| { + span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| { if let Some(snippet) = snippet_opt(cx, inner_span) { db.span_suggestion(ret_span, "remove `return`", snippet, Applicability::MachineApplicable); } @@ -162,7 +162,7 @@ impl Return { }, None => match replacement { RetReplacement::Empty => { - span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| { + span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| { db.span_suggestion( ret_span, "remove `return`", @@ -172,7 +172,7 @@ impl Return { }); }, RetReplacement::Block => { - span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| { + span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| { db.span_suggestion( ret_span, "replace `return` with an empty block", @@ -205,14 +205,15 @@ impl Return { if !in_external_macro(cx.sess(), initexpr.span); if !in_external_macro(cx.sess(), retexpr.span); if !in_external_macro(cx.sess(), local.span); + if !in_macro(local.span); then { span_lint_and_then( cx, LET_AND_RETURN, retexpr.span, - "returning the result of a let binding from a block", + "returning the result of a `let` binding from a block", |err| { - err.span_label(local.span, "unnecessary let binding"); + err.span_label(local.span, "unnecessary `let` binding"); if let Some(snippet) = snippet_opt(cx, initexpr.span) { err.multipart_suggestion( diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 6efb2c272f15..825f9ee3a413 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -1,9 +1,9 @@ use crate::reexport::*; use crate::utils::{contains_name, higher, iter_input_pats, snippet, span_lint_and_then}; use rustc::declare_lint_pass; -use rustc::hir::intravisit::FnKind; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; +use rustc_hir::intravisit::FnKind; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 65b88f51ce27..512bf21a9f3c 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -2,9 +2,10 @@ use crate::utils::sugg::Sugg; use crate::utils::{get_enclosing_block, match_qpath, span_lint_and_then, SpanlessEq}; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_block, walk_expr, walk_stmt, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass}; use rustc_errors::Applicability; +use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::symbol::Symbol; @@ -279,6 +280,8 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { if self.initialization_found { match stmt.kind { @@ -316,7 +319,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 4756ca364d92..7092397619a5 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -1,9 +1,10 @@ use crate::utils::{get_trait_def_id, span_lint, trait_ref_of_method}; use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_hir as hir; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_session::declare_tool_lint; declare_clippy_lint! { @@ -185,6 +186,8 @@ struct BinaryExprVisitor { } impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Binary(..) @@ -195,7 +198,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index d6e0ab183c33..9d211b7b9351 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -36,7 +36,7 @@ declare_clippy_lint! { /// ``` /// /// Will be converted to: - /// ```rust + /// ```rust /// /// /// /// Struct to hold two strings: /// /// - first one diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 7e87a285eba9..30ea81125c52 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -210,7 +210,7 @@ declare_clippy_lint! { /// let _: u32 = 1f32.to_bits(); /// ``` pub TRANSMUTE_FLOAT_TO_INT, - nursery, + complexity, "transmutes from a float to an integer" } diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index f28527dc71fb..f8a6a2acd8a6 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -3,13 +3,13 @@ use std::cmp; use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg}; use if_chain::if_chain; use matches::matches; -use rustc::hir::intravisit::FnKind; use rustc::impl_lint_pass; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::session::config::Config as SessionConfig; use rustc::ty; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::intravisit::FnKind; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::Span; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 7d49b31d99f5..3edc220eda41 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -5,13 +5,14 @@ use std::cmp::Ordering; use std::collections::BTreeMap; use if_chain::if_chain; -use rustc::hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty::layout::LayoutOf; use rustc::ty::{self, InferTy, Ty, TyCtxt, TypeckTables}; use rustc::{declare_lint_pass, impl_lint_pass}; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -141,7 +142,7 @@ declare_clippy_lint! { /// ``` pub LINKEDLIST, pedantic, - "usage of LinkedList, usually a vector is faster, or a more specialized data structure like a VecDeque" + "usage of LinkedList, usually a vector is faster, or a more specialized data structure like a `VecDeque`" } declare_clippy_lint! { @@ -316,7 +317,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty<'_>, is_local: bool) { LINKEDLIST, hir_ty.span, "I see you're using a LinkedList! Perhaps you meant some other data structure?", - "a VecDeque might work", + "a `VecDeque` might work", ); return; // don't recurse into the type } @@ -464,7 +465,7 @@ declare_clippy_lint! { /// ``` pub LET_UNIT_VALUE, style, - "creating a let binding to a value of unit type, which usually can't be used afterwards" + "creating a `let` binding to a value of unit type, which usually can't be used afterwards" } declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); @@ -953,8 +954,8 @@ fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast_from CAST_PRECISION_LOSS, expr.span, &format!( - "casting {0} to {1} causes a loss of precision {2}({0} is {3} bits wide, but {1}'s mantissa \ - is only {4} bits wide)", + "casting `{0}` to `{1}` causes a loss of precision {2}(`{0}` is {3} bits wide, \ + but `{1}`'s mantissa is only {4} bits wide)", cast_from, if cast_to_f64 { "f64" } else { "f32" }, if arch_dependent { arch_dependent_str } else { "" }, @@ -998,7 +999,7 @@ fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, CAST_LOSSLESS, expr.span, &format!( - "casting {} to {} may become silently lossy if you later change the type", + "casting `{}` to `{}` may become silently lossy if you later change the type", cast_from, cast_to ), "try", @@ -1053,7 +1054,10 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cx, CAST_SIGN_LOSS, expr.span, - &format!("casting {} to {} may lose the sign of the value", cast_from, cast_to), + &format!( + "casting `{}` to `{}` may lose the sign of the value", + cast_from, cast_to + ), ); } @@ -1098,7 +1102,7 @@ fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast CAST_POSSIBLE_TRUNCATION, expr.span, &format!( - "casting {} to {} may truncate the value{}", + "casting `{}` to `{}` may truncate the value{}", cast_from, cast_to, match suffix_truncation { @@ -1115,7 +1119,7 @@ fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast CAST_POSSIBLE_WRAP, expr.span, &format!( - "casting {} to {} may wrap around the value{}", + "casting `{}` to `{}` may wrap around the value{}", cast_from, cast_to, match suffix_wrap { @@ -1194,7 +1198,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { cx, UNNECESSARY_CAST, expr.span, - &format!("casting integer literal to {} is unnecessary", cast_to), + &format!("casting integer literal to `{}` is unnecessary", cast_to), "try", format!("{}_{}", n, cast_to), Applicability::MachineApplicable, @@ -1256,14 +1260,17 @@ fn lint_numeric_casts<'tcx>( cx, CAST_POSSIBLE_TRUNCATION, expr.span, - &format!("casting {} to {} may truncate the value", cast_from, cast_to), + &format!("casting `{}` to `{}` may truncate the value", cast_from, cast_to), ); if !cast_to.is_signed() { span_lint( cx, CAST_SIGN_LOSS, expr.span, - &format!("casting {} to {} may lose the sign of the value", cast_from, cast_to), + &format!( + "casting `{}` to `{}` may lose the sign of the value", + cast_from, cast_to + ), ); } }, @@ -1278,7 +1285,7 @@ fn lint_numeric_casts<'tcx>( cx, CAST_POSSIBLE_TRUNCATION, expr.span, - "casting f64 to f32 may truncate the value", + "casting `f64` to `f32` may truncate the value", ); } if let (&ty::Float(FloatTy::F32), &ty::Float(FloatTy::F64)) = (&cast_from.kind, &cast_to.kind) { @@ -1487,6 +1494,8 @@ struct TypeComplexityVisitor { } impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { + type Map = Map<'tcx>; + fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) { let (add_score, sub_nest) = match ty.kind { // _, &x and *x have only small overhead; don't mess with nesting level @@ -1521,7 +1530,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { walk_ty(self, ty); self.nest -= sub_nest; } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -1550,7 +1559,7 @@ declare_clippy_lint! { /// ``` pub CHAR_LIT_AS_U8, complexity, - "casting a character literal to u8 truncates" + "casting a character literal to `u8` truncates" } declare_lint_pass!(CharLitAsU8 => [CHAR_LIT_AS_U8]); @@ -1742,7 +1751,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons { AlwaysFalse => "this comparison is always false".to_owned(), AlwaysTrue => "this comparison is always true".to_owned(), InequalityImpossible => format!( - "the case where the two sides are not equal never occurs, consider using {} == {} \ + "the case where the two sides are not equal never occurs, consider using `{} == {}` \ instead", snippet(cx, lhs.span, "lhs"), snippet(cx, rhs.span, "rhs") @@ -1750,7 +1759,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons { }; let help = format!( - "because {} is the {} value for this type, {}", + "because `{}` is the {} value for this type, {}", snippet(cx, culprit.expr.span, "x"), match culprit.which { Minimum => "minimum", @@ -1813,7 +1822,7 @@ impl FullInt { impl PartialEq for FullInt { #[must_use] fn eq(&self, other: &Self) -> bool { - self.partial_cmp(other).expect("partial_cmp only returns Some(_)") == Ordering::Equal + self.partial_cmp(other).expect("`partial_cmp` only returns `Some(_)`") == Ordering::Equal } } @@ -1832,7 +1841,7 @@ impl Ord for FullInt { #[must_use] fn cmp(&self, other: &Self) -> Ordering { self.partial_cmp(other) - .expect("partial_cmp for FullInt can never return None") + .expect("`partial_cmp` for FullInt can never return `None`") } } @@ -2266,6 +2275,8 @@ impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) { if let Some(target) = ImplicitHasherType::new(self.cx, t) { self.found.push(target); @@ -2274,7 +2285,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { walk_ty(self, t); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -2299,6 +2310,8 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { } impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { + type Map = Map<'tcx>; + fn visit_body(&mut self, body: &'tcx Body<'_>) { let prev_body = self.body; self.body = self.cx.tcx.body_tables(body.id()); @@ -2349,7 +2362,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't walk_expr(self, e); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir()) } } @@ -2404,7 +2417,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut { cx, CAST_REF_TO_MUT, expr.span, - "casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell", + "casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell`", ); } } diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index e4b0a3773969..008dc578bf90 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -66,7 +66,7 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>, UNSAFE_REMOVED_FROM_NAME, span, &format!( - "removed \"unsafe\" from the name of `{}` in use as `{}`", + "removed `unsafe` from the name of `{}` in use as `{}`", old_str, new_str ), ); diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index b698a4a22878..b145d354c894 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -1,8 +1,9 @@ use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_hir::def::Res; +use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; use rustc_hir::{AssocItemKind, HirId, ImplItemKind, ImplItemRef, Item, ItemKind, Path}; use rustc_session::declare_tool_lint; @@ -86,6 +87,8 @@ struct UnusedSelfVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UnusedSelfVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { if self.uses_self { // This function already uses `self` @@ -97,7 +100,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnusedSelfVisitor<'a, 'tcx> { walk_path(self, path); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir()) } } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index e9b4b1a5051a..7a4fe159d8be 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -1,11 +1,11 @@ +use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usage::is_potentially_mutated}; use if_chain::if_chain; use rustc::declare_lint_pass; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc_session::declare_tool_lint; - -use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usage::is_potentially_mutated}; -use rustc::hir::intravisit::*; +use rustc_hir::intravisit::*; use rustc_hir::*; +use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; declare_clippy_lint! { @@ -35,7 +35,7 @@ declare_clippy_lint! { /// ``` pub UNNECESSARY_UNWRAP, complexity, - "checks for calls of unwrap[_err]() that cannot fail" + "checks for calls of `unwrap[_err]()` that cannot fail" } declare_clippy_lint! { @@ -58,7 +58,7 @@ declare_clippy_lint! { /// This code will always panic. The if condition should probably be inverted. pub PANICKING_UNWRAP, correctness, - "checks for calls of unwrap[_err]() that will always fail" + "checks for calls of `unwrap[_err]()` that will always fail" } /// Visitor that keeps track of which variables are unwrappable. @@ -136,6 +136,8 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let Some((cond, then, els)) = if_block(&expr) { walk_expr(self, cond); @@ -179,7 +181,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir()) } } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index d4addec306a5..81e6e2e99cc5 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -1,12 +1,13 @@ use if_chain::if_chain; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{walk_item, walk_path, walk_ty, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; use rustc::ty::{DefIdTree, Ty}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; +use rustc_hir::intravisit::{walk_item, walk_path, walk_ty, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::symbol::kw; @@ -84,6 +85,8 @@ struct TraitImplTyVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) { let trait_ty = self.trait_type_walker.next(); let impl_ty = self.impl_type_walker.next(); @@ -107,7 +110,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> { walk_ty(self, t) } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -223,6 +226,8 @@ struct UseSelfVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { if !path.segments.iter().any(|p| p.ident.span.is_dummy()) { if path.segments.len() >= 2 { @@ -272,7 +277,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.cx.tcx.hir()) } } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 173f3b84eed5..902c3e2b7e72 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -3,11 +3,12 @@ use crate::utils::{get_attr, higher}; use rustc::declare_lint_pass; -use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::session::Session; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; +use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind}; use rustc_session::declare_tool_lint; use syntax::ast::{Attribute, LitFloatType, LitKind}; @@ -188,6 +189,8 @@ struct PrintVisitor { } impl<'tcx> Visitor<'tcx> for PrintVisitor { + type Map = Map<'tcx>; + #[allow(clippy::too_many_lines)] fn visit_expr(&mut self, expr: &Expr<'_>) { // handle if desugarings @@ -686,7 +689,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 58552d08b324..e63b29be9657 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -3,13 +3,14 @@ use crate::utils::{ walk_ptrs_ty, }; use if_chain::if_chain; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_lint_pass, impl_lint_pass}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_session::declare_tool_lint; use rustc_span::source_map::Span; @@ -239,6 +240,8 @@ struct LintCollector<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { walk_expr(self, expr); } @@ -248,7 +251,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { self.output.insert(path.segments[0].ident.name); } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.cx.tcx.hir()) } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3c806cc7ea58..803a962f221f 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -25,9 +25,10 @@ use std::mem; use if_chain::if_chain; use matches::matches; -use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::{LateContext, Level, Lint, LintContext}; use rustc::traits; +use rustc::traits::predicate_for_trait_def; use rustc::ty::{ self, layout::{self, IntegerExt}, @@ -38,11 +39,12 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::Node; use rustc_hir::*; use rustc_span::hygiene::ExpnKind; -use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::{kw, Symbol}; +use rustc_span::{BytePos, Pos, Span, DUMMY_SP}; use smallvec::SmallVec; use syntax::ast::{self, Attribute, LitKind}; use syntax::attr; @@ -312,7 +314,8 @@ pub fn implements_trait<'a, 'tcx>( ty_params: &[GenericArg<'tcx>], ) -> bool { let ty = cx.tcx.erase_regions(&ty); - let obligation = cx.tcx.predicate_for_trait_def( + let obligation = predicate_for_trait_def( + cx.tcx, cx.param_env, traits::ObligationCause::dummy(), trait_id, @@ -453,12 +456,14 @@ struct ContainsName { } impl<'tcx> Visitor<'tcx> for ContainsName { + type Map = Map<'tcx>; + fn visit_name(&mut self, _: Span, name: Name) { if self.name == name { self.result = true; } } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } @@ -552,7 +557,16 @@ pub fn last_line_of_span(cx: &T, span: Span) -> Span { let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap(); let line_no = source_map_and_line.line; let line_start = &source_map_and_line.sf.lines[line_no]; - Span::new(*line_start, span.hi(), span.ctxt()) + let span = Span::new(*line_start, span.hi(), span.ctxt()); + if_chain! { + if let Some(snip) = snippet_opt(cx, span); + if let Some(first_ch_pos) = snip.find(|c: char| !c.is_whitespace()); + then { + span.with_lo(span.lo() + BytePos::from_usize(first_ch_pos)) + } else { + span + } + } } /// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block`. @@ -873,12 +887,11 @@ pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool { /// /// Ie. `x`, `{ x }` and `{{{{ x }}}}` all give `x`. `{ x; y }` and `{}` return /// themselves. -pub fn remove_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { - if let ExprKind::Block(ref block, _) = expr.kind { - if block.stmts.is_empty() { - if let Some(ref expr) = block.expr { - return remove_blocks(expr); - } +pub fn remove_blocks<'tcx>(mut expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { + while let ExprKind::Block(ref block, ..) = expr.kind { + match (block.stmts.is_empty(), block.expr.as_ref()) { + (true, Some(e)) => expr = e, + _ => break, } } expr diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index e32d5e3a4ed0..03170fde4a65 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -1,6 +1,7 @@ use crate::utils::{get_pat_name, match_var, snippet}; -use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint::LateContext; +use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_span::source_map::Span; use std::borrow::Cow; @@ -52,6 +53,8 @@ struct PtrCloneVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.abort { return; @@ -75,7 +78,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } } diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index fc46da2c720b..11cc594fb5dc 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -20,7 +20,7 @@ declare_clippy_lint! { /// ``` pub ZERO_DIVIDED_BY_ZERO, complexity, - "usage of `0.0 / 0.0` to obtain NaN instead of std::f32::NaN or std::f64::NaN" + "usage of `0.0 / 0.0` to obtain NaN instead of `std::f32::NAN` or `std::f64::NAN`" } declare_lint_pass!(ZeroDiv => [ZERO_DIVIDED_BY_ZERO]); @@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { cx, ZERO_DIVIDED_BY_ZERO, expr.span, - "constant division of 0.0 with 0.0 will always result in NaN", + "constant division of `0.0` with `0.0` will always result in NaN", &format!( "Consider using `std::{}::NAN` if you would like a constant representing NaN", float_type, diff --git a/src/driver.rs b/src/driver.rs index 4a080c12e44b..27ff7fa9116e 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -259,7 +259,6 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { if !info.payload().is::() { let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic"); handler.emit_diagnostic(&d); - handler.abort_if_errors_and_should_abort(); } let version_info = rustc_tools_util::get_version_info!(); diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 5bc49f7b6002..f576bb152de9 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 344] = [ +pub const ALL_LINTS: [Lint; 346] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -87,7 +87,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "borrow_interior_mutable_const", group: "correctness", - desc: "referencing const with interior mutability", + desc: "referencing `const` with interior mutability", deprecation: None, module: "non_copy_const", }, @@ -178,7 +178,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "char_lit_as_u8", group: "complexity", - desc: "casting a character literal to u8 truncates", + desc: "casting a character literal to `u8` truncates", deprecation: None, module: "types", }, @@ -227,7 +227,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "cmp_nan", group: "correctness", - desc: "comparisons to NAN, which will always return false, probably not intended", + desc: "comparisons to `NAN`, which will always return false, probably not intended", deprecation: None, module: "misc", }, @@ -304,21 +304,21 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "declare_interior_mutable_const", group: "correctness", - desc: "declaring const with interior mutability", + desc: "declaring `const` with interior mutability", deprecation: None, module: "non_copy_const", }, Lint { name: "default_trait_access", group: "pedantic", - desc: "checks for literal calls to Default::default()", + desc: "checks for literal calls to `Default::default()`", deprecation: None, module: "default_trait_access", }, Lint { name: "deprecated_cfg_attr", group: "complexity", - desc: "usage of `cfg_attr(rustfmt)` instead of `tool_attributes`", + desc: "usage of `cfg_attr(rustfmt)` instead of tool attributes", deprecation: None, module: "attrs", }, @@ -423,7 +423,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "else_if_without_else", group: "restriction", - desc: "if expression with an `else if`, but without a final `else` branch", + desc: "`if` expression with an `else if`, but without a final `else` branch", deprecation: None, module: "else_if_without_else", }, @@ -710,14 +710,14 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "if_same_then_else", group: "correctness", - desc: "if with the same *then* and *else* blocks", + desc: "`if` with the same `then` and `else` blocks", deprecation: None, module: "copies", }, Lint { name: "ifs_same_cond", group: "correctness", - desc: "consecutive `ifs` with the same condition", + desc: "consecutive `if`s with the same condition", deprecation: None, module: "copies", }, @@ -766,7 +766,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "infallible_destructuring_match", group: "style", - desc: "a match statement with a single infallible arm instead of a `let`", + desc: "a `match` statement with a single infallible arm instead of a `let`", deprecation: None, module: "infallible_destructuring_match", }, @@ -787,7 +787,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "inherent_to_string_shadow_display", group: "correctness", - desc: "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait ", + desc: "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait", deprecation: None, module: "inherent_to_string", }, @@ -808,7 +808,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "int_plus_one", group: "complexity", - desc: "instead of using x >= y + 1, use x > y", + desc: "instead of using `x >= y + 1`, use `x > y`", deprecation: None, module: "int_plus_one", }, @@ -833,6 +833,13 @@ pub const ALL_LINTS: [Lint; 344] = [ deprecation: None, module: "methods", }, + Lint { + name: "invalid_atomic_ordering", + group: "correctness", + desc: "usage of invalid atomic ordering in atomic load/store calls", + deprecation: None, + module: "atomic_ordering", + }, Lint { name: "invalid_regex", group: "correctness", @@ -948,21 +955,21 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "let_underscore_must_use", group: "restriction", - desc: "non-binding let on a #[must_use] expression", + desc: "non-binding let on a `#[must_use]` expression", deprecation: None, module: "let_underscore", }, Lint { name: "let_unit_value", group: "style", - desc: "creating a let binding to a value of unit type, which usually can\'t be used afterwards", + desc: "creating a `let` binding to a value of unit type, which usually can\'t be used afterwards", deprecation: None, module: "types", }, Lint { name: "linkedlist", group: "pedantic", - desc: "usage of LinkedList, usually a vector is faster, or a more specialized data structure like a VecDeque", + desc: "usage of LinkedList, usually a vector is faster, or a more specialized data structure like a `VecDeque`", deprecation: None, module: "types", }, @@ -1039,28 +1046,28 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "match_as_ref", group: "complexity", - desc: "a match on an Option value instead of using `as_ref()` or `as_mut`", + desc: "a `match` on an Option value instead of using `as_ref()` or `as_mut`", deprecation: None, module: "matches", }, Lint { name: "match_bool", group: "style", - desc: "a match on a boolean expression instead of an `if..else` block", + desc: "a `match` on a boolean expression instead of an `if..else` block", deprecation: None, module: "matches", }, Lint { name: "match_overlapping_arm", group: "style", - desc: "a match with overlapping arms", + desc: "a `match` with overlapping arms", deprecation: None, module: "matches", }, Lint { name: "match_ref_pats", group: "style", - desc: "a match or `if let` with all arms prefixed with `&` instead of deref-ing the match expression", + desc: "a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression", deprecation: None, module: "matches", }, @@ -1074,7 +1081,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "match_wild_err_arm", group: "style", - desc: "a match with `Err(_)` arm and take drastic actions", + desc: "a `match` with `Err(_)` arm and take drastic actions", deprecation: None, module: "matches", }, @@ -1088,7 +1095,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "mem_discriminant_non_enum", group: "correctness", - desc: "calling mem::descriminant on non-enum type", + desc: "calling `mem::descriminant` on non-enum type", deprecation: None, module: "mem_discriminant", }, @@ -1158,7 +1165,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "missing_inline_in_public_items", group: "restriction", - desc: "detects missing #[inline] attribute for public callables (functions, trait methods, methods...)", + desc: "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)", deprecation: None, module: "missing_inline", }, @@ -1263,7 +1270,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "mutable_key_type", group: "correctness", - desc: "Check for mutable Map/Set key type", + desc: "Check for mutable `Map`/`Set` key type", deprecation: None, module: "mut_key", }, @@ -1375,7 +1382,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "neg_multiply", group: "style", - desc: "multiplying integers with -1", + desc: "multiplying integers with `-1`", deprecation: None, module: "neg_multiply", }, @@ -1473,7 +1480,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "option_map_unit_fn", group: "complexity", - desc: "using `option.map(f)`, where f is a function or closure that returns ()", + desc: "using `option.map(f)`, where `f` is a function or closure that returns `()`", deprecation: None, module: "map_unit_fn", }, @@ -1543,7 +1550,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "panicking_unwrap", group: "correctness", - desc: "checks for calls of unwrap[_err]() that will always fail", + desc: "checks for calls of `unwrap[_err]()` that will always fail", deprecation: None, module: "unwrap", }, @@ -1739,7 +1746,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "result_map_unit_fn", group: "complexity", - desc: "using `result.map(f)`, where f is a function or closure that returns ()", + desc: "using `result.map(f)`, where `f` is a function or closure that returns `()`", deprecation: None, module: "map_unit_fn", }, @@ -1767,7 +1774,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "same_functions_in_if_condition", group: "pedantic", - desc: "consecutive `ifs` with the same function call", + desc: "consecutive `if`s with the same function call", deprecation: None, module: "copies", }, @@ -1837,14 +1844,14 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "single_match", group: "style", - desc: "a match statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`", + desc: "a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`", deprecation: None, module: "matches", }, Lint { name: "single_match_else", group: "pedantic", - desc: "a match statement with two arms where the second arm\'s pattern is a placeholder instead of a specific match pattern", + desc: "a `match` statement with two arms where the second arm\'s pattern is a placeholder instead of a specific match pattern", deprecation: None, module: "matches", }, @@ -1990,7 +1997,7 @@ pub const ALL_LINTS: [Lint; 344] = [ }, Lint { name: "transmute_float_to_int", - group: "nursery", + group: "complexity", desc: "transmutes from a float to an integer", deprecation: None, module: "transmute", @@ -2152,7 +2159,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "unnecessary_unwrap", group: "complexity", - desc: "checks for calls of unwrap[_err]() that cannot fail", + desc: "checks for calls of `unwrap[_err]()` that cannot fail", deprecation: None, module: "unwrap", }, @@ -2338,6 +2345,13 @@ pub const ALL_LINTS: [Lint; 344] = [ deprecation: None, module: "matches", }, + Lint { + name: "wildcard_in_or_patterns", + group: "complexity", + desc: "a wildcard pattern used with others patterns in same match arm", + deprecation: None, + module: "matches", + }, Lint { name: "write_literal", group: "style", @@ -2383,7 +2397,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "zero_divided_by_zero", group: "complexity", - desc: "usage of `0.0 / 0.0` to obtain NaN instead of std::f32::NaN or std::f64::NaN", + desc: "usage of `0.0 / 0.0` to obtain NaN instead of `std::f32::NAN` or `std::f64::NAN`", deprecation: None, module: "zero_div_zero", }, @@ -2397,7 +2411,7 @@ pub const ALL_LINTS: [Lint; 344] = [ Lint { name: "zero_ptr", group: "style", - desc: "using 0 as *{const, mut} T", + desc: "using `0 as *{const, mut} T`", deprecation: None, module: "misc", }, diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index c22c7eb75b46..4ef364148cda 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -5,7 +5,7 @@ LL | u <= 0; | ^^^^^^ | = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings` - = help: because 0 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 0 instead + = help: because `0` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 0` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:15:5 @@ -13,7 +13,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | u <= Z; | ^^^^^^ | - = help: because Z is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == Z instead + = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == Z` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:16:5 @@ -21,7 +21,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | u < Z; | ^^^^^ | - = help: because Z is the minimum value for this type, this comparison is always false + = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:17:5 @@ -29,7 +29,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | Z >= u; | ^^^^^^ | - = help: because Z is the minimum value for this type, the case where the two sides are not equal never occurs, consider using Z == u instead + = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `Z == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:18:5 @@ -37,7 +37,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | Z > u; | ^^^^^ | - = help: because Z is the minimum value for this type, this comparison is always false + = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:19:5 @@ -45,7 +45,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | u > std::u32::MAX; | ^^^^^^^^^^^^^^^^^ | - = help: because std::u32::MAX is the maximum value for this type, this comparison is always false + = help: because `std::u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:20:5 @@ -53,7 +53,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | u >= std::u32::MAX; | ^^^^^^^^^^^^^^^^^^ | - = help: because std::u32::MAX is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == std::u32::MAX instead + = help: because `std::u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == std::u32::MAX` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:21:5 @@ -61,7 +61,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | std::u32::MAX < u; | ^^^^^^^^^^^^^^^^^ | - = help: because std::u32::MAX is the maximum value for this type, this comparison is always false + = help: because `std::u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:22:5 @@ -69,7 +69,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | std::u32::MAX <= u; | ^^^^^^^^^^^^^^^^^^ | - = help: because std::u32::MAX is the maximum value for this type, the case where the two sides are not equal never occurs, consider using std::u32::MAX == u instead + = help: because `std::u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `std::u32::MAX == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:23:5 @@ -77,7 +77,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | 1-1 > u; | ^^^^^^^ | - = help: because 1-1 is the minimum value for this type, this comparison is always false + = help: because `1-1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:24:5 @@ -85,7 +85,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | u >= !0; | ^^^^^^^ | - = help: because !0 is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == !0 instead + = help: because `!0` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == !0` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:25:5 @@ -93,7 +93,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | u <= 12 - 2*6; | ^^^^^^^^^^^^^ | - = help: because 12 - 2*6 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 12 - 2*6 instead + = help: because `12 - 2*6` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 12 - 2*6` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:27:5 @@ -101,7 +101,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | i < -127 - 1; | ^^^^^^^^^^^^ | - = help: because -127 - 1 is the minimum value for this type, this comparison is always false + = help: because `-127 - 1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:28:5 @@ -109,7 +109,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | std::i8::MAX >= i; | ^^^^^^^^^^^^^^^^^ | - = help: because std::i8::MAX is the maximum value for this type, this comparison is always true + = help: because `std::i8::MAX` is the maximum value for this type, this comparison is always true error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:29:5 @@ -117,7 +117,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | 3-7 < std::i32::MIN; | ^^^^^^^^^^^^^^^^^^^ | - = help: because std::i32::MIN is the minimum value for this type, this comparison is always false + = help: because `std::i32::MIN` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:31:5 @@ -125,7 +125,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | b >= true; | ^^^^^^^^^ | - = help: because true is the maximum value for this type, the case where the two sides are not equal never occurs, consider using b == true instead + = help: because `true` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `b == true` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:32:5 @@ -133,7 +133,7 @@ error: this comparison involving the minimum or maximum element for this type co LL | false > b; | ^^^^^^^^^ | - = help: because false is the minimum value for this type, this comparison is always false + = help: because `false` is the minimum value for this type, this comparison is always false error: <-comparison of unit values detected. This will always be false --> $DIR/absurd-extreme-comparisons.rs:35:5 diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index c746cfd9d56b..70b15d18a568 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -5,7 +5,7 @@ LL | a += a + 1; | ^^^^^^^^^^ | = note: `-D clippy::misrefactored-assign-op` implied by `-D warnings` -help: Did you mean a = a + 1 or a = a + a + 1? Consider replacing it with +help: Did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with | LL | a += 1; | ^^^^^^ @@ -20,7 +20,7 @@ error: variable appears on both sides of an assignment operation LL | a += 1 + a; | ^^^^^^^^^^ | -help: Did you mean a = a + 1 or a = a + 1 + a? Consider replacing it with +help: Did you mean `a = a + 1` or `a = a + 1 + a`? Consider replacing it with | LL | a += 1; | ^^^^^^ @@ -35,7 +35,7 @@ error: variable appears on both sides of an assignment operation LL | a -= a - 1; | ^^^^^^^^^^ | -help: Did you mean a = a - 1 or a = a - (a - 1)? Consider replacing it with +help: Did you mean `a = a - 1` or `a = a - (a - 1)`? Consider replacing it with | LL | a -= 1; | ^^^^^^ @@ -50,7 +50,7 @@ error: variable appears on both sides of an assignment operation LL | a *= a * 99; | ^^^^^^^^^^^ | -help: Did you mean a = a * 99 or a = a * a * 99? Consider replacing it with +help: Did you mean `a = a * 99` or `a = a * a * 99`? Consider replacing it with | LL | a *= 99; | ^^^^^^^ @@ -65,7 +65,7 @@ error: variable appears on both sides of an assignment operation LL | a *= 42 * a; | ^^^^^^^^^^^ | -help: Did you mean a = a * 42 or a = a * 42 * a? Consider replacing it with +help: Did you mean `a = a * 42` or `a = a * 42 * a`? Consider replacing it with | LL | a *= 42; | ^^^^^^^ @@ -80,7 +80,7 @@ error: variable appears on both sides of an assignment operation LL | a /= a / 2; | ^^^^^^^^^^ | -help: Did you mean a = a / 2 or a = a / (a / 2)? Consider replacing it with +help: Did you mean `a = a / 2` or `a = a / (a / 2)`? Consider replacing it with | LL | a /= 2; | ^^^^^^ @@ -95,7 +95,7 @@ error: variable appears on both sides of an assignment operation LL | a %= a % 5; | ^^^^^^^^^^ | -help: Did you mean a = a % 5 or a = a % (a % 5)? Consider replacing it with +help: Did you mean `a = a % 5` or `a = a % (a % 5)`? Consider replacing it with | LL | a %= 5; | ^^^^^^ @@ -110,7 +110,7 @@ error: variable appears on both sides of an assignment operation LL | a &= a & 1; | ^^^^^^^^^^ | -help: Did you mean a = a & 1 or a = a & a & 1? Consider replacing it with +help: Did you mean `a = a & 1` or `a = a & a & 1`? Consider replacing it with | LL | a &= 1; | ^^^^^^ @@ -125,7 +125,7 @@ error: variable appears on both sides of an assignment operation LL | a *= a * a; | ^^^^^^^^^^ | -help: Did you mean a = a * a or a = a * a * a? Consider replacing it with +help: Did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with | LL | a *= a; | ^^^^^^ diff --git a/tests/ui/atomic_ordering_bool.rs b/tests/ui/atomic_ordering_bool.rs new file mode 100644 index 000000000000..cdbde79b19eb --- /dev/null +++ b/tests/ui/atomic_ordering_bool.rs @@ -0,0 +1,25 @@ +#![warn(clippy::invalid_atomic_ordering)] + +use std::sync::atomic::{AtomicBool, Ordering}; + +fn main() { + let x = AtomicBool::new(true); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + // Allowed store ordering modes + x.store(false, Ordering::Release); + x.store(false, Ordering::SeqCst); + x.store(false, Ordering::Relaxed); + + // Disallowed store ordering modes + x.store(false, Ordering::Acquire); + x.store(false, Ordering::AcqRel); +} diff --git a/tests/ui/atomic_ordering_bool.stderr b/tests/ui/atomic_ordering_bool.stderr new file mode 100644 index 000000000000..397b893aed96 --- /dev/null +++ b/tests/ui/atomic_ordering_bool.stderr @@ -0,0 +1,35 @@ +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_bool.rs:14:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_bool.rs:15:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_bool.rs:23:20 + | +LL | x.store(false, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_bool.rs:24:20 + | +LL | x.store(false, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/atomic_ordering_int.rs b/tests/ui/atomic_ordering_int.rs new file mode 100644 index 000000000000..40a00ba3de35 --- /dev/null +++ b/tests/ui/atomic_ordering_int.rs @@ -0,0 +1,86 @@ +#![warn(clippy::invalid_atomic_ordering)] + +use std::sync::atomic::{AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, Ordering}; + +fn main() { + // `AtomicI8` test cases + let x = AtomicI8::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicI16` test cases + let x = AtomicI16::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicI32` test cases + let x = AtomicI32::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicI64` test cases + let x = AtomicI64::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicIsize` test cases + let x = AtomicIsize::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); +} diff --git a/tests/ui/atomic_ordering_int.stderr b/tests/ui/atomic_ordering_int.stderr new file mode 100644 index 000000000000..bbaf234d3c9f --- /dev/null +++ b/tests/ui/atomic_ordering_int.stderr @@ -0,0 +1,163 @@ +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:15:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:16:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:24:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:25:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:33:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:34:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:39:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:40:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:48:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:49:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:54:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:55:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:63:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:64:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:69:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:70:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:78:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:79:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:84:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_int.rs:85:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 20 previous errors + diff --git a/tests/ui/atomic_ordering_ptr.rs b/tests/ui/atomic_ordering_ptr.rs new file mode 100644 index 000000000000..ecbb05c7fbc3 --- /dev/null +++ b/tests/ui/atomic_ordering_ptr.rs @@ -0,0 +1,27 @@ +#![warn(clippy::invalid_atomic_ordering)] + +use std::sync::atomic::{AtomicPtr, Ordering}; + +fn main() { + let ptr = &mut 5; + let other_ptr = &mut 10; + let x = AtomicPtr::new(ptr); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + // Allowed store ordering modes + x.store(other_ptr, Ordering::Release); + x.store(other_ptr, Ordering::SeqCst); + x.store(other_ptr, Ordering::Relaxed); + + // Disallowed store ordering modes + x.store(other_ptr, Ordering::Acquire); + x.store(other_ptr, Ordering::AcqRel); +} diff --git a/tests/ui/atomic_ordering_ptr.stderr b/tests/ui/atomic_ordering_ptr.stderr new file mode 100644 index 000000000000..558ae55518d5 --- /dev/null +++ b/tests/ui/atomic_ordering_ptr.stderr @@ -0,0 +1,35 @@ +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_ptr.rs:16:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_ptr.rs:17:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_ptr.rs:25:24 + | +LL | x.store(other_ptr, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_ptr.rs:26:24 + | +LL | x.store(other_ptr, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/atomic_ordering_uint.rs b/tests/ui/atomic_ordering_uint.rs new file mode 100644 index 000000000000..a0d5d7c40103 --- /dev/null +++ b/tests/ui/atomic_ordering_uint.rs @@ -0,0 +1,86 @@ +#![warn(clippy::invalid_atomic_ordering)] + +use std::sync::atomic::{AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, Ordering}; + +fn main() { + // `AtomicU8` test cases + let x = AtomicU8::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicU16` test cases + let x = AtomicU16::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicU32` test cases + let x = AtomicU32::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicU64` test cases + let x = AtomicU64::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); + + // `AtomicUsize` test cases + let x = AtomicUsize::new(0); + + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + let _ = x.load(Ordering::Release); + let _ = x.load(Ordering::AcqRel); + + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + x.store(1, Ordering::Acquire); + x.store(1, Ordering::AcqRel); +} diff --git a/tests/ui/atomic_ordering_uint.stderr b/tests/ui/atomic_ordering_uint.stderr new file mode 100644 index 000000000000..5703135bcf1e --- /dev/null +++ b/tests/ui/atomic_ordering_uint.stderr @@ -0,0 +1,163 @@ +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:15:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:16:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:24:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:25:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:33:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:34:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:39:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:40:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:48:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:49:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:54:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:55:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:63:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:64:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:69:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:70:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:78:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:79:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:84:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` and `AcqRel` ordering + --> $DIR/atomic_ordering_uint.rs:85:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 20 previous errors + diff --git a/tests/ui/block_in_if_condition.stderr b/tests/ui/block_in_if_condition.stderr index 0876d5db6964..d75f3c02f197 100644 --- a/tests/ui/block_in_if_condition.stderr +++ b/tests/ui/block_in_if_condition.stderr @@ -1,4 +1,4 @@ -error: in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let' +error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` --> $DIR/block_in_if_condition.rs:26:8 | LL | if { @@ -30,7 +30,7 @@ LL | if { true } { 6 } ... -error: in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let' +error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` --> $DIR/block_in_if_condition.rs:58:17 | LL | |x| { @@ -40,7 +40,7 @@ LL | | x == target LL | | }, | |_____________^ -error: in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let' +error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` --> $DIR/block_in_if_condition.rs:67:13 | LL | |x| { diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 0ebd3a1f184d..4c66d7364948 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -1,4 +1,4 @@ -error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast.rs:11:5 | LL | x0 as f32; @@ -6,37 +6,37 @@ LL | x0 as f32; | = note: `-D clippy::cast-precision-loss` implied by `-D warnings` -error: casting i64 to f32 causes a loss of precision (i64 is 64 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast.rs:13:5 | LL | x1 as f32; | ^^^^^^^^^ -error: casting i64 to f64 causes a loss of precision (i64 is 64 bits wide, but f64's mantissa is only 52 bits wide) +error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast.rs:14:5 | LL | x1 as f64; | ^^^^^^^^^ -error: casting u32 to f32 causes a loss of precision (u32 is 32 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast.rs:16:5 | LL | x2 as f32; | ^^^^^^^^^ -error: casting u64 to f32 causes a loss of precision (u64 is 64 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast.rs:18:5 | LL | x3 as f32; | ^^^^^^^^^ -error: casting u64 to f64 causes a loss of precision (u64 is 64 bits wide, but f64's mantissa is only 52 bits wide) +error: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast.rs:19:5 | LL | x3 as f64; | ^^^^^^^^^ -error: casting f32 to i32 may truncate the value +error: casting `f32` to `i32` may truncate the value --> $DIR/cast.rs:21:5 | LL | 1f32 as i32; @@ -44,13 +44,13 @@ LL | 1f32 as i32; | = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` -error: casting f32 to u32 may truncate the value +error: casting `f32` to `u32` may truncate the value --> $DIR/cast.rs:22:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ -error: casting f32 to u32 may lose the sign of the value +error: casting `f32` to `u32` may lose the sign of the value --> $DIR/cast.rs:22:5 | LL | 1f32 as u32; @@ -58,43 +58,43 @@ LL | 1f32 as u32; | = note: `-D clippy::cast-sign-loss` implied by `-D warnings` -error: casting f64 to f32 may truncate the value +error: casting `f64` to `f32` may truncate the value --> $DIR/cast.rs:23:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ -error: casting i32 to i8 may truncate the value +error: casting `i32` to `i8` may truncate the value --> $DIR/cast.rs:24:5 | LL | 1i32 as i8; | ^^^^^^^^^^ -error: casting i32 to u8 may truncate the value +error: casting `i32` to `u8` may truncate the value --> $DIR/cast.rs:25:5 | LL | 1i32 as u8; | ^^^^^^^^^^ -error: casting f64 to isize may truncate the value +error: casting `f64` to `isize` may truncate the value --> $DIR/cast.rs:26:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ -error: casting f64 to usize may truncate the value +error: casting `f64` to `usize` may truncate the value --> $DIR/cast.rs:27:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ -error: casting f64 to usize may lose the sign of the value +error: casting `f64` to `usize` may lose the sign of the value --> $DIR/cast.rs:27:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ -error: casting u8 to i8 may wrap around the value +error: casting `u8` to `i8` may wrap around the value --> $DIR/cast.rs:29:5 | LL | 1u8 as i8; @@ -102,37 +102,37 @@ LL | 1u8 as i8; | = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` -error: casting u16 to i16 may wrap around the value +error: casting `u16` to `i16` may wrap around the value --> $DIR/cast.rs:30:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ -error: casting u32 to i32 may wrap around the value +error: casting `u32` to `i32` may wrap around the value --> $DIR/cast.rs:31:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ -error: casting u64 to i64 may wrap around the value +error: casting `u64` to `i64` may wrap around the value --> $DIR/cast.rs:32:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ -error: casting usize to isize may wrap around the value +error: casting `usize` to `isize` may wrap around the value --> $DIR/cast.rs:33:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ -error: casting i32 to u32 may lose the sign of the value +error: casting `i32` to `u32` may lose the sign of the value --> $DIR/cast.rs:36:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ -error: casting isize to usize may lose the sign of the value +error: casting `isize` to `usize` may lose the sign of the value --> $DIR/cast.rs:38:5 | LL | -1isize as usize; diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index 778a17344e53..0ed09f3083c2 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -1,4 +1,4 @@ -error: casting i8 to f32 may become silently lossy if you later change the type +error: casting `i8` to `f32` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:9:5 | LL | x0 as f32; @@ -6,61 +6,61 @@ LL | x0 as f32; | = note: `-D clippy::cast-lossless` implied by `-D warnings` -error: casting i8 to f64 may become silently lossy if you later change the type +error: casting `i8` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:10:5 | LL | x0 as f64; | ^^^^^^^^^ help: try: `f64::from(x0)` -error: casting u8 to f32 may become silently lossy if you later change the type +error: casting `u8` to `f32` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:12:5 | LL | x1 as f32; | ^^^^^^^^^ help: try: `f32::from(x1)` -error: casting u8 to f64 may become silently lossy if you later change the type +error: casting `u8` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:13:5 | LL | x1 as f64; | ^^^^^^^^^ help: try: `f64::from(x1)` -error: casting i16 to f32 may become silently lossy if you later change the type +error: casting `i16` to `f32` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:15:5 | LL | x2 as f32; | ^^^^^^^^^ help: try: `f32::from(x2)` -error: casting i16 to f64 may become silently lossy if you later change the type +error: casting `i16` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:16:5 | LL | x2 as f64; | ^^^^^^^^^ help: try: `f64::from(x2)` -error: casting u16 to f32 may become silently lossy if you later change the type +error: casting `u16` to `f32` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:18:5 | LL | x3 as f32; | ^^^^^^^^^ help: try: `f32::from(x3)` -error: casting u16 to f64 may become silently lossy if you later change the type +error: casting `u16` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:19:5 | LL | x3 as f64; | ^^^^^^^^^ help: try: `f64::from(x3)` -error: casting i32 to f64 may become silently lossy if you later change the type +error: casting `i32` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:21:5 | LL | x4 as f64; | ^^^^^^^^^ help: try: `f64::from(x4)` -error: casting u32 to f64 may become silently lossy if you later change the type +error: casting `u32` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:23:5 | LL | x5 as f64; | ^^^^^^^^^ help: try: `f64::from(x5)` -error: casting f32 to f64 may become silently lossy if you later change the type +error: casting `f32` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:26:5 | LL | 1.0f32 as f64; diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index c2f937942a3d..8e2890f9c28d 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -1,4 +1,4 @@ -error: casting i8 to i16 may become silently lossy if you later change the type +error: casting `i8` to `i16` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:8:5 | LL | 1i8 as i16; @@ -6,109 +6,109 @@ LL | 1i8 as i16; | = note: `-D clippy::cast-lossless` implied by `-D warnings` -error: casting i8 to i32 may become silently lossy if you later change the type +error: casting `i8` to `i32` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:9:5 | LL | 1i8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1i8)` -error: casting i8 to i64 may become silently lossy if you later change the type +error: casting `i8` to `i64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:10:5 | LL | 1i8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1i8)` -error: casting u8 to i16 may become silently lossy if you later change the type +error: casting `u8` to `i16` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:11:5 | LL | 1u8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1u8)` -error: casting u8 to i32 may become silently lossy if you later change the type +error: casting `u8` to `i32` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:12:5 | LL | 1u8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1u8)` -error: casting u8 to i64 may become silently lossy if you later change the type +error: casting `u8` to `i64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:13:5 | LL | 1u8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1u8)` -error: casting u8 to u16 may become silently lossy if you later change the type +error: casting `u8` to `u16` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:14:5 | LL | 1u8 as u16; | ^^^^^^^^^^ help: try: `u16::from(1u8)` -error: casting u8 to u32 may become silently lossy if you later change the type +error: casting `u8` to `u32` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:15:5 | LL | 1u8 as u32; | ^^^^^^^^^^ help: try: `u32::from(1u8)` -error: casting u8 to u64 may become silently lossy if you later change the type +error: casting `u8` to `u64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:16:5 | LL | 1u8 as u64; | ^^^^^^^^^^ help: try: `u64::from(1u8)` -error: casting i16 to i32 may become silently lossy if you later change the type +error: casting `i16` to `i32` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:17:5 | LL | 1i16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1i16)` -error: casting i16 to i64 may become silently lossy if you later change the type +error: casting `i16` to `i64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:18:5 | LL | 1i16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i16)` -error: casting u16 to i32 may become silently lossy if you later change the type +error: casting `u16` to `i32` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:19:5 | LL | 1u16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1u16)` -error: casting u16 to i64 may become silently lossy if you later change the type +error: casting `u16` to `i64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:20:5 | LL | 1u16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u16)` -error: casting u16 to u32 may become silently lossy if you later change the type +error: casting `u16` to `u32` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:21:5 | LL | 1u16 as u32; | ^^^^^^^^^^^ help: try: `u32::from(1u16)` -error: casting u16 to u64 may become silently lossy if you later change the type +error: casting `u16` to `u64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:22:5 | LL | 1u16 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u16)` -error: casting i32 to i64 may become silently lossy if you later change the type +error: casting `i32` to `i64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:23:5 | LL | 1i32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i32)` -error: casting u32 to i64 may become silently lossy if you later change the type +error: casting `u32` to `i64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:24:5 | LL | 1u32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u32)` -error: casting u32 to u64 may become silently lossy if you later change the type +error: casting `u32` to `u64` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:25:5 | LL | 1u32 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u32)` -error: casting u8 to u16 may become silently lossy if you later change the type +error: casting `u8` to `u16` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:28:5 | LL | (1u8 + 1u8) as u16; diff --git a/tests/ui/cast_ref_to_mut.stderr b/tests/ui/cast_ref_to_mut.stderr index 448a66cfcce0..aacd99437d9f 100644 --- a/tests/ui/cast_ref_to_mut.stderr +++ b/tests/ui/cast_ref_to_mut.stderr @@ -1,4 +1,4 @@ -error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell +error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell` --> $DIR/cast_ref_to_mut.rs:18:9 | LL | (*(a as *const _ as *mut String)).push_str(" world"); @@ -6,13 +6,13 @@ LL | (*(a as *const _ as *mut String)).push_str(" world"); | = note: `-D clippy::cast-ref-to-mut` implied by `-D warnings` -error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell +error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell` --> $DIR/cast_ref_to_mut.rs:19:9 | LL | *(a as *const _ as *mut _) = String::from("Replaced"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell +error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell` --> $DIR/cast_ref_to_mut.rs:20:9 | LL | *(a as *const _ as *mut String) += " world"; diff --git a/tests/ui/cast_size.stderr b/tests/ui/cast_size.stderr index ec7ed6aec94e..95552f2e2853 100644 --- a/tests/ui/cast_size.stderr +++ b/tests/ui/cast_size.stderr @@ -1,4 +1,4 @@ -error: casting isize to i8 may truncate the value +error: casting `isize` to `i8` may truncate the value --> $DIR/cast_size.rs:12:5 | LL | 1isize as i8; @@ -6,7 +6,7 @@ LL | 1isize as i8; | = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` -error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide) +error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast_size.rs:15:5 | LL | x0 as f64; @@ -14,49 +14,49 @@ LL | x0 as f64; | = note: `-D clippy::cast-precision-loss` implied by `-D warnings` -error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) +error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast_size.rs:16:5 | LL | x1 as f64; | ^^^^^^^^^ -error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast_size.rs:17:5 | LL | x0 as f32; | ^^^^^^^^^ -error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast_size.rs:18:5 | LL | x1 as f32; | ^^^^^^^^^ -error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers +error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size.rs:19:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ -error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers +error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size.rs:20:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ -error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers +error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size.rs:21:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ -error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers +error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size.rs:22:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ -error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers +error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> $DIR/cast_size.rs:22:5 | LL | 1usize as i32; @@ -64,49 +64,49 @@ LL | 1usize as i32; | = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` -error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers +error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size.rs:24:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ -error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers +error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size.rs:25:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ -error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers +error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size.rs:26:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ -error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers +error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> $DIR/cast_size.rs:26:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ -error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers +error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size.rs:27:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ -error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers +error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> $DIR/cast_size.rs:28:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ -error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast_size.rs:33:5 | LL | 999_999_999 as f32; | ^^^^^^^^^^^^^^^^^^ -error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) +error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast_size.rs:34:5 | LL | 9_999_999_999_999_999usize as f64; diff --git a/tests/ui/cast_size_32bit.stderr b/tests/ui/cast_size_32bit.stderr index cb89630718ae..2eec51895f59 100644 --- a/tests/ui/cast_size_32bit.stderr +++ b/tests/ui/cast_size_32bit.stderr @@ -1,4 +1,4 @@ -error: casting isize to i8 may truncate the value +error: casting `isize` to `i8` may truncate the value --> $DIR/cast_size_32bit.rs:12:5 | LL | 1isize as i8; @@ -6,7 +6,7 @@ LL | 1isize as i8; | = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` -error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide) +error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast_size_32bit.rs:15:5 | LL | x0 as f64; @@ -14,7 +14,7 @@ LL | x0 as f64; | = note: `-D clippy::cast-precision-loss` implied by `-D warnings` -error: casting isize to f64 may become silently lossy if you later change the type +error: casting `isize` to `f64` may become silently lossy if you later change the type --> $DIR/cast_size_32bit.rs:15:5 | LL | x0 as f64; @@ -22,55 +22,55 @@ LL | x0 as f64; | = note: `-D clippy::cast-lossless` implied by `-D warnings` -error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) +error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast_size_32bit.rs:16:5 | LL | x1 as f64; | ^^^^^^^^^ -error: casting usize to f64 may become silently lossy if you later change the type +error: casting `usize` to `f64` may become silently lossy if you later change the type --> $DIR/cast_size_32bit.rs:16:5 | LL | x1 as f64; | ^^^^^^^^^ help: try: `f64::from(x1)` -error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast_size_32bit.rs:17:5 | LL | x0 as f32; | ^^^^^^^^^ -error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast_size_32bit.rs:18:5 | LL | x1 as f32; | ^^^^^^^^^ -error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers +error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size_32bit.rs:19:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ -error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers +error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size_32bit.rs:20:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ -error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers +error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size_32bit.rs:21:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ -error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers +error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers --> $DIR/cast_size_32bit.rs:22:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ -error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers +error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> $DIR/cast_size_32bit.rs:22:5 | LL | 1usize as i32; @@ -78,49 +78,49 @@ LL | 1usize as i32; | = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` -error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers +error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size_32bit.rs:24:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ -error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers +error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size_32bit.rs:25:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ -error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers +error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size_32bit.rs:26:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ -error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers +error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> $DIR/cast_size_32bit.rs:26:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ -error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers +error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size_32bit.rs:27:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ -error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers +error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> $DIR/cast_size_32bit.rs:28:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ -error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide) +error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast_size_32bit.rs:33:5 | LL | 999_999_999 as f32; | ^^^^^^^^^^^^^^^^^^ -error: casting integer literal to f64 is unnecessary +error: casting integer literal to `f64` is unnecessary --> $DIR/cast_size_32bit.rs:34:5 | LL | 3_999_999_999usize as f64; diff --git a/tests/ui/cfg_attr_rustfmt.stderr b/tests/ui/cfg_attr_rustfmt.stderr index 09971caceea8..c1efd47db90b 100644 --- a/tests/ui/cfg_attr_rustfmt.stderr +++ b/tests/ui/cfg_attr_rustfmt.stderr @@ -1,4 +1,4 @@ -error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes +error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes --> $DIR/cfg_attr_rustfmt.rs:18:5 | LL | #[cfg_attr(rustfmt, rustfmt::skip)] @@ -6,7 +6,7 @@ LL | #[cfg_attr(rustfmt, rustfmt::skip)] | = note: `-D clippy::deprecated-cfg-attr` implied by `-D warnings` -error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes +error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes --> $DIR/cfg_attr_rustfmt.rs:22:1 | LL | #[cfg_attr(rustfmt, rustfmt_skip)] diff --git a/tests/ui/cmp_nan.stderr b/tests/ui/cmp_nan.stderr index 4ec92716a2b9..7aceeeaf78fc 100644 --- a/tests/ui/cmp_nan.stderr +++ b/tests/ui/cmp_nan.stderr @@ -1,4 +1,4 @@ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:8:5 | LL | x == std::f32::NAN; @@ -6,139 +6,139 @@ LL | x == std::f32::NAN; | = note: `-D clippy::cmp-nan` implied by `-D warnings` -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:9:5 | LL | x != std::f32::NAN; | ^^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:10:5 | LL | x < std::f32::NAN; | ^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:11:5 | LL | x > std::f32::NAN; | ^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:12:5 | LL | x <= std::f32::NAN; | ^^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:13:5 | LL | x >= std::f32::NAN; | ^^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:14:5 | LL | x == NAN_F32; | ^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:15:5 | LL | x != NAN_F32; | ^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:16:5 | LL | x < NAN_F32; | ^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:17:5 | LL | x > NAN_F32; | ^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:18:5 | LL | x <= NAN_F32; | ^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:19:5 | LL | x >= NAN_F32; | ^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:22:5 | LL | y == std::f64::NAN; | ^^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:23:5 | LL | y != std::f64::NAN; | ^^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:24:5 | LL | y < std::f64::NAN; | ^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:25:5 | LL | y > std::f64::NAN; | ^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:26:5 | LL | y <= std::f64::NAN; | ^^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:27:5 | LL | y >= std::f64::NAN; | ^^^^^^^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:28:5 | LL | y == NAN_F64; | ^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:29:5 | LL | y != NAN_F64; | ^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:30:5 | LL | y < NAN_F64; | ^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:31:5 | LL | y > NAN_F64; | ^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:32:5 | LL | y <= NAN_F64; | ^^^^^^^^^^^^ -error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead +error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead --> $DIR/cmp_nan.rs:33:5 | LL | y >= NAN_F64; diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index 063e716676ce..b563a2ebec2d 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -1,4 +1,4 @@ -error: Comparing with null is better expressed by the .is_null() method +error: Comparing with null is better expressed by the `.is_null()` method --> $DIR/cmp_null.rs:9:8 | LL | if p == ptr::null() { @@ -6,7 +6,7 @@ LL | if p == ptr::null() { | = note: `-D clippy::cmp-null` implied by `-D warnings` -error: Comparing with null is better expressed by the .is_null() method +error: Comparing with null is better expressed by the `.is_null()` method --> $DIR/cmp_null.rs:14:8 | LL | if m == ptr::null_mut() { diff --git a/tests/ui/collapsible_else_if.fixed b/tests/ui/collapsible_else_if.fixed new file mode 100644 index 000000000000..a31f748670ce --- /dev/null +++ b/tests/ui/collapsible_else_if.fixed @@ -0,0 +1,66 @@ +// run-rustfix +#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)] + +#[rustfmt::skip] +#[warn(clippy::collapsible_if)] +fn main() { + let x = "hello"; + let y = "world"; + // Collapse `else { if .. }` to `else if ..` + if x == "hello" { + print!("Hello "); + } else if y == "world" { + println!("world!") +} + + if x == "hello" { + print!("Hello "); + } else if let Some(42) = Some(42) { + println!("world!") +} + + if x == "hello" { + print!("Hello "); + } else if y == "world" { + println!("world") +} +else { + println!("!") +} + + if x == "hello" { + print!("Hello "); + } else if let Some(42) = Some(42) { + println!("world") +} +else { + println!("!") +} + + if let Some(42) = Some(42) { + print!("Hello "); + } else if let Some(42) = Some(42) { + println!("world") +} +else { + println!("!") +} + + if let Some(42) = Some(42) { + print!("Hello "); + } else if x == "hello" { + println!("world") +} +else { + println!("!") +} + + if let Some(42) = Some(42) { + print!("Hello "); + } else if let Some(42) = Some(42) { + println!("world") +} +else { + println!("!") +} +} diff --git a/tests/ui/collapsible_else_if.rs b/tests/ui/collapsible_else_if.rs new file mode 100644 index 000000000000..79a27aafc4d9 --- /dev/null +++ b/tests/ui/collapsible_else_if.rs @@ -0,0 +1,80 @@ +// run-rustfix +#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)] + +#[rustfmt::skip] +#[warn(clippy::collapsible_if)] +fn main() { + let x = "hello"; + let y = "world"; + // Collapse `else { if .. }` to `else if ..` + if x == "hello" { + print!("Hello "); + } else { + if y == "world" { + println!("world!") + } + } + + if x == "hello" { + print!("Hello "); + } else { + if let Some(42) = Some(42) { + println!("world!") + } + } + + if x == "hello" { + print!("Hello "); + } else { + if y == "world" { + println!("world") + } + else { + println!("!") + } + } + + if x == "hello" { + print!("Hello "); + } else { + if let Some(42) = Some(42) { + println!("world") + } + else { + println!("!") + } + } + + if let Some(42) = Some(42) { + print!("Hello "); + } else { + if let Some(42) = Some(42) { + println!("world") + } + else { + println!("!") + } + } + + if let Some(42) = Some(42) { + print!("Hello "); + } else { + if x == "hello" { + println!("world") + } + else { + println!("!") + } + } + + if let Some(42) = Some(42) { + print!("Hello "); + } else { + if let Some(42) = Some(42) { + println!("world") + } + else { + println!("!") + } + } +} diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr new file mode 100644 index 000000000000..26e3635c2d1c --- /dev/null +++ b/tests/ui/collapsible_else_if.stderr @@ -0,0 +1,154 @@ +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_else_if.rs:12:12 + | +LL | } else { + | ____________^ +LL | | if y == "world" { +LL | | println!("world!") +LL | | } +LL | | } + | |_____^ + | + = note: `-D clippy::collapsible-if` implied by `-D warnings` +help: try + | +LL | } else if y == "world" { +LL | println!("world!") +LL | } + | + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_else_if.rs:20:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world!") +LL | | } +LL | | } + | |_____^ + | +help: try + | +LL | } else if let Some(42) = Some(42) { +LL | println!("world!") +LL | } + | + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_else_if.rs:28:12 + | +LL | } else { + | ____________^ +LL | | if y == "world" { +LL | | println!("world") +LL | | } +... | +LL | | } +LL | | } + | |_____^ + | +help: try + | +LL | } else if y == "world" { +LL | println!("world") +LL | } +LL | else { +LL | println!("!") +LL | } + | + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_else_if.rs:39:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world") +LL | | } +... | +LL | | } +LL | | } + | |_____^ + | +help: try + | +LL | } else if let Some(42) = Some(42) { +LL | println!("world") +LL | } +LL | else { +LL | println!("!") +LL | } + | + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_else_if.rs:50:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world") +LL | | } +... | +LL | | } +LL | | } + | |_____^ + | +help: try + | +LL | } else if let Some(42) = Some(42) { +LL | println!("world") +LL | } +LL | else { +LL | println!("!") +LL | } + | + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_else_if.rs:61:12 + | +LL | } else { + | ____________^ +LL | | if x == "hello" { +LL | | println!("world") +LL | | } +... | +LL | | } +LL | | } + | |_____^ + | +help: try + | +LL | } else if x == "hello" { +LL | println!("world") +LL | } +LL | else { +LL | println!("!") +LL | } + | + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_else_if.rs:72:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world") +LL | | } +... | +LL | | } +LL | | } + | |_____^ + | +help: try + | +LL | } else if let Some(42) = Some(42) { +LL | println!("world") +LL | } +LL | else { +LL | println!("!") +LL | } + | + +error: aborting due to 7 previous errors + diff --git a/tests/ui/collapsible_if.fixed b/tests/ui/collapsible_if.fixed index 810fd2e69ea2..e8f90b3164a9 100644 --- a/tests/ui/collapsible_if.fixed +++ b/tests/ui/collapsible_if.fixed @@ -30,64 +30,6 @@ fn main() { println!("world!") } - // Collapse `else { if .. }` to `else if ..` - if x == "hello" { - print!("Hello "); - } else if y == "world" { - println!("world!") -} - - if x == "hello" { - print!("Hello "); - } else if let Some(42) = Some(42) { - println!("world!") -} - - if x == "hello" { - print!("Hello "); - } else if y == "world" { - println!("world") -} -else { - println!("!") -} - - if x == "hello" { - print!("Hello "); - } else if let Some(42) = Some(42) { - println!("world") -} -else { - println!("!") -} - - if let Some(42) = Some(42) { - print!("Hello "); - } else if let Some(42) = Some(42) { - println!("world") -} -else { - println!("!") -} - - if let Some(42) = Some(42) { - print!("Hello "); - } else if x == "hello" { - println!("world") -} -else { - println!("!") -} - - if let Some(42) = Some(42) { - print!("Hello "); - } else if let Some(42) = Some(42) { - println!("world") -} -else { - println!("!") -} - // Works because any if with an else statement cannot be collapsed. if x == "hello" { if y == "world" { diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs index 7b322acae263..503cb35f8588 100644 --- a/tests/ui/collapsible_if.rs +++ b/tests/ui/collapsible_if.rs @@ -42,78 +42,6 @@ fn main() { } } - // Collapse `else { if .. }` to `else if ..` - if x == "hello" { - print!("Hello "); - } else { - if y == "world" { - println!("world!") - } - } - - if x == "hello" { - print!("Hello "); - } else { - if let Some(42) = Some(42) { - println!("world!") - } - } - - if x == "hello" { - print!("Hello "); - } else { - if y == "world" { - println!("world") - } - else { - println!("!") - } - } - - if x == "hello" { - print!("Hello "); - } else { - if let Some(42) = Some(42) { - println!("world") - } - else { - println!("!") - } - } - - if let Some(42) = Some(42) { - print!("Hello "); - } else { - if let Some(42) = Some(42) { - println!("world") - } - else { - println!("!") - } - } - - if let Some(42) = Some(42) { - print!("Hello "); - } else { - if x == "hello" { - println!("world") - } - else { - println!("!") - } - } - - if let Some(42) = Some(42) { - print!("Hello "); - } else { - if let Some(42) = Some(42) { - println!("world") - } - else { - println!("!") - } - } - // Works because any if with an else statement cannot be collapsed. if x == "hello" { if y == "world" { diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr index 16bc5a1c1b02..b123bc1c7bd7 100644 --- a/tests/ui/collapsible_if.stderr +++ b/tests/ui/collapsible_if.stderr @@ -1,4 +1,4 @@ -error: this if statement can be collapsed +error: this `if` statement can be collapsed --> $DIR/collapsible_if.rs:9:5 | LL | / if x == "hello" { @@ -16,7 +16,7 @@ LL | println!("Hello world!"); LL | } | -error: this if statement can be collapsed +error: this `if` statement can be collapsed --> $DIR/collapsible_if.rs:15:5 | LL | / if x == "hello" || x == "world" { @@ -33,7 +33,7 @@ LL | println!("Hello world!"); LL | } | -error: this if statement can be collapsed +error: this `if` statement can be collapsed --> $DIR/collapsible_if.rs:21:5 | LL | / if x == "hello" && x == "world" { @@ -50,7 +50,7 @@ LL | println!("Hello world!"); LL | } | -error: this if statement can be collapsed +error: this `if` statement can be collapsed --> $DIR/collapsible_if.rs:27:5 | LL | / if x == "hello" || x == "world" { @@ -67,7 +67,7 @@ LL | println!("Hello world!"); LL | } | -error: this if statement can be collapsed +error: this `if` statement can be collapsed --> $DIR/collapsible_if.rs:33:5 | LL | / if x == "hello" && x == "world" { @@ -84,7 +84,7 @@ LL | println!("Hello world!"); LL | } | -error: this if statement can be collapsed +error: this `if` statement can be collapsed --> $DIR/collapsible_if.rs:39:5 | LL | / if 42 == 1337 { @@ -101,159 +101,8 @@ LL | println!("world!") LL | } | -error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_if.rs:48:12 - | -LL | } else { - | ____________^ -LL | | if y == "world" { -LL | | println!("world!") -LL | | } -LL | | } - | |_____^ - | -help: try - | -LL | } else if y == "world" { -LL | println!("world!") -LL | } - | - -error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_if.rs:56:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world!") -LL | | } -LL | | } - | |_____^ - | -help: try - | -LL | } else if let Some(42) = Some(42) { -LL | println!("world!") -LL | } - | - -error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_if.rs:64:12 - | -LL | } else { - | ____________^ -LL | | if y == "world" { -LL | | println!("world") -LL | | } -... | -LL | | } -LL | | } - | |_____^ - | -help: try - | -LL | } else if y == "world" { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } - | - -error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_if.rs:75:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world") -LL | | } -... | -LL | | } -LL | | } - | |_____^ - | -help: try - | -LL | } else if let Some(42) = Some(42) { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } - | - -error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_if.rs:86:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world") -LL | | } -... | -LL | | } -LL | | } - | |_____^ - | -help: try - | -LL | } else if let Some(42) = Some(42) { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } - | - -error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_if.rs:97:12 - | -LL | } else { - | ____________^ -LL | | if x == "hello" { -LL | | println!("world") -LL | | } -... | -LL | | } -LL | | } - | |_____^ - | -help: try - | -LL | } else if x == "hello" { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } - | - -error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_if.rs:108:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world") -LL | | } -... | -LL | | } -LL | | } - | |_____^ - | -help: try - | -LL | } else if let Some(42) = Some(42) { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } - | - -error: this if statement can be collapsed - --> $DIR/collapsible_if.rs:167:5 +error: this `if` statement can be collapsed + --> $DIR/collapsible_if.rs:95:5 | LL | / if x == "hello" { LL | | if y == "world" { // Collapsible @@ -269,5 +118,5 @@ LL | println!("Hello world!"); LL | } | -error: aborting due to 14 previous errors +error: aborting due to 7 previous errors diff --git a/tests/ui/default_trait_access.stderr b/tests/ui/default_trait_access.stderr index 1f115aecca1b..453760c6b921 100644 --- a/tests/ui/default_trait_access.stderr +++ b/tests/ui/default_trait_access.stderr @@ -1,4 +1,4 @@ -error: Calling std::string::String::default() is more clear than this expression +error: Calling `std::string::String::default()` is more clear than this expression --> $DIR/default_trait_access.rs:8:22 | LL | let s1: String = Default::default(); @@ -6,43 +6,43 @@ LL | let s1: String = Default::default(); | = note: `-D clippy::default-trait-access` implied by `-D warnings` -error: Calling std::string::String::default() is more clear than this expression +error: Calling `std::string::String::default()` is more clear than this expression --> $DIR/default_trait_access.rs:12:22 | LL | let s3: String = D2::default(); | ^^^^^^^^^^^^^ help: try: `std::string::String::default()` -error: Calling std::string::String::default() is more clear than this expression +error: Calling `std::string::String::default()` is more clear than this expression --> $DIR/default_trait_access.rs:14:22 | LL | let s4: String = std::default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()` -error: Calling std::string::String::default() is more clear than this expression +error: Calling `std::string::String::default()` is more clear than this expression --> $DIR/default_trait_access.rs:18:22 | LL | let s6: String = default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()` -error: Calling GenericDerivedDefault::default() is more clear than this expression +error: Calling `GenericDerivedDefault::default()` is more clear than this expression --> $DIR/default_trait_access.rs:28:46 | LL | let s11: GenericDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `GenericDerivedDefault::default()` -error: Calling TupleDerivedDefault::default() is more clear than this expression +error: Calling `TupleDerivedDefault::default()` is more clear than this expression --> $DIR/default_trait_access.rs:34:36 | LL | let s14: TupleDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleDerivedDefault::default()` -error: Calling ArrayDerivedDefault::default() is more clear than this expression +error: Calling `ArrayDerivedDefault::default()` is more clear than this expression --> $DIR/default_trait_access.rs:36:36 | LL | let s15: ArrayDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `ArrayDerivedDefault::default()` -error: Calling TupleStructDerivedDefault::default() is more clear than this expression +error: Calling `TupleStructDerivedDefault::default()` is more clear than this expression --> $DIR/default_trait_access.rs:40:42 | LL | let s17: TupleStructDerivedDefault = Default::default(); diff --git a/tests/ui/dlist.stderr b/tests/ui/dlist.stderr index 1f6646ec9ade..64fde33c64f5 100644 --- a/tests/ui/dlist.stderr +++ b/tests/ui/dlist.stderr @@ -5,7 +5,7 @@ LL | type Baz = LinkedList; | ^^^^^^^^^^^^^^ | = note: `-D clippy::linkedlist` implied by `-D warnings` - = help: a VecDeque might work + = help: a `VecDeque` might work error: I see you're using a LinkedList! Perhaps you meant some other data structure? --> $DIR/dlist.rs:10:15 @@ -13,7 +13,7 @@ error: I see you're using a LinkedList! Perhaps you meant some other data struct LL | fn foo(_: LinkedList); | ^^^^^^^^^^^^^^ | - = help: a VecDeque might work + = help: a `VecDeque` might work error: I see you're using a LinkedList! Perhaps you meant some other data structure? --> $DIR/dlist.rs:11:23 @@ -21,7 +21,7 @@ error: I see you're using a LinkedList! Perhaps you meant some other data struct LL | const BAR: Option>; | ^^^^^^^^^^^^^^ | - = help: a VecDeque might work + = help: a `VecDeque` might work error: I see you're using a LinkedList! Perhaps you meant some other data structure? --> $DIR/dlist.rs:22:15 @@ -29,7 +29,7 @@ error: I see you're using a LinkedList! Perhaps you meant some other data struct LL | fn foo(_: LinkedList) {} | ^^^^^^^^^^^^^^ | - = help: a VecDeque might work + = help: a `VecDeque` might work error: I see you're using a LinkedList! Perhaps you meant some other data structure? --> $DIR/dlist.rs:25:39 @@ -37,7 +37,7 @@ error: I see you're using a LinkedList! Perhaps you meant some other data struct LL | pub fn test(my_favourite_linked_list: LinkedList) { | ^^^^^^^^^^^^^^ | - = help: a VecDeque might work + = help: a `VecDeque` might work error: I see you're using a LinkedList! Perhaps you meant some other data structure? --> $DIR/dlist.rs:29:29 @@ -45,7 +45,7 @@ error: I see you're using a LinkedList! Perhaps you meant some other data struct LL | pub fn test_ret() -> Option> { | ^^^^^^^^^^^^^^ | - = help: a VecDeque might work + = help: a `VecDeque` might work error: aborting due to 6 previous errors diff --git a/tests/ui/drop_forget_copy.stderr b/tests/ui/drop_forget_copy.stderr index 55c840d34807..82a4f047ba85 100644 --- a/tests/ui/drop_forget_copy.stderr +++ b/tests/ui/drop_forget_copy.stderr @@ -1,4 +1,4 @@ -error: calls to `std::mem::drop` with a value that implements Copy. Dropping a copy leaves the original intact. +error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact. --> $DIR/drop_forget_copy.rs:33:5 | LL | drop(s1); @@ -11,7 +11,7 @@ note: argument has type SomeStruct LL | drop(s1); | ^^ -error: calls to `std::mem::drop` with a value that implements Copy. Dropping a copy leaves the original intact. +error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact. --> $DIR/drop_forget_copy.rs:34:5 | LL | drop(s2); @@ -23,7 +23,7 @@ note: argument has type SomeStruct LL | drop(s2); | ^^ -error: calls to `std::mem::drop` with a value that implements Copy. Dropping a copy leaves the original intact. +error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact. --> $DIR/drop_forget_copy.rs:36:5 | LL | drop(s4); @@ -35,7 +35,7 @@ note: argument has type SomeStruct LL | drop(s4); | ^^ -error: calls to `std::mem::forget` with a value that implements Copy. Forgetting a copy leaves the original intact. +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact. --> $DIR/drop_forget_copy.rs:39:5 | LL | forget(s1); @@ -48,7 +48,7 @@ note: argument has type SomeStruct LL | forget(s1); | ^^ -error: calls to `std::mem::forget` with a value that implements Copy. Forgetting a copy leaves the original intact. +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact. --> $DIR/drop_forget_copy.rs:40:5 | LL | forget(s2); @@ -60,7 +60,7 @@ note: argument has type SomeStruct LL | forget(s2); | ^^ -error: calls to `std::mem::forget` with a value that implements Copy. Forgetting a copy leaves the original intact. +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact. --> $DIR/drop_forget_copy.rs:42:5 | LL | forget(s4); diff --git a/tests/ui/drop_forget_ref.stderr b/tests/ui/drop_forget_ref.stderr index 8ffc369b8822..b51c45ea5ee2 100644 --- a/tests/ui/drop_forget_ref.stderr +++ b/tests/ui/drop_forget_ref.stderr @@ -5,7 +5,7 @@ LL | drop(&SomeStruct); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::drop-ref` implied by `-D warnings` -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:9:10 | LL | drop(&SomeStruct); @@ -18,7 +18,7 @@ LL | forget(&SomeStruct); | ^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::forget-ref` implied by `-D warnings` -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:10:12 | LL | forget(&SomeStruct); @@ -30,7 +30,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(&owned1); | ^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:13:10 | LL | drop(&owned1); @@ -42,7 +42,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(&&owned1); | ^^^^^^^^^^^^^^ | -note: argument has type &&SomeStruct +note: argument has type `&&SomeStruct` --> $DIR/drop_forget_ref.rs:14:10 | LL | drop(&&owned1); @@ -54,7 +54,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(&mut owned1); | ^^^^^^^^^^^^^^^^^ | -note: argument has type &mut SomeStruct +note: argument has type `&mut SomeStruct` --> $DIR/drop_forget_ref.rs:15:10 | LL | drop(&mut owned1); @@ -66,7 +66,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(&owned2); | ^^^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:18:12 | LL | forget(&owned2); @@ -78,7 +78,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(&&owned2); | ^^^^^^^^^^^^^^^^ | -note: argument has type &&SomeStruct +note: argument has type `&&SomeStruct` --> $DIR/drop_forget_ref.rs:19:12 | LL | forget(&&owned2); @@ -90,7 +90,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(&mut owned2); | ^^^^^^^^^^^^^^^^^^^ | -note: argument has type &mut SomeStruct +note: argument has type `&mut SomeStruct` --> $DIR/drop_forget_ref.rs:20:12 | LL | forget(&mut owned2); @@ -102,7 +102,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(reference1); | ^^^^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:24:10 | LL | drop(reference1); @@ -114,7 +114,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(&*reference1); | ^^^^^^^^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:25:12 | LL | forget(&*reference1); @@ -126,7 +126,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(reference2); | ^^^^^^^^^^^^^^^^ | -note: argument has type &mut SomeStruct +note: argument has type `&mut SomeStruct` --> $DIR/drop_forget_ref.rs:28:10 | LL | drop(reference2); @@ -138,7 +138,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(reference3); | ^^^^^^^^^^^^^^^^^^ | -note: argument has type &mut SomeStruct +note: argument has type `&mut SomeStruct` --> $DIR/drop_forget_ref.rs:30:12 | LL | forget(reference3); @@ -150,7 +150,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(reference4); | ^^^^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:33:10 | LL | drop(reference4); @@ -162,7 +162,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(reference4); | ^^^^^^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:34:12 | LL | forget(reference4); @@ -174,7 +174,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(&val); | ^^^^^^^^^^ | -note: argument has type &T +note: argument has type `&T` --> $DIR/drop_forget_ref.rs:39:10 | LL | drop(&val); @@ -186,7 +186,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(&val); | ^^^^^^^^^^^^ | -note: argument has type &T +note: argument has type `&T` --> $DIR/drop_forget_ref.rs:45:12 | LL | forget(&val); @@ -198,7 +198,7 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | std::mem::drop(&SomeStruct); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:53:20 | LL | std::mem::drop(&SomeStruct); @@ -210,7 +210,7 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | std::mem::forget(&SomeStruct); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: argument has type &SomeStruct +note: argument has type `&SomeStruct` --> $DIR/drop_forget_ref.rs:56:22 | LL | std::mem::forget(&SomeStruct); diff --git a/tests/ui/else_if_without_else.stderr b/tests/ui/else_if_without_else.stderr index 270009067546..6f47658cfb18 100644 --- a/tests/ui/else_if_without_else.stderr +++ b/tests/ui/else_if_without_else.stderr @@ -1,4 +1,4 @@ -error: if expression with an `else if`, but without a final `else` +error: `if` expression with an `else if`, but without a final `else` --> $DIR/else_if_without_else.rs:45:12 | LL | } else if bla2() { @@ -11,7 +11,7 @@ LL | | } = note: `-D clippy::else-if-without-else` implied by `-D warnings` = help: add an `else` block here -error: if expression with an `else if`, but without a final `else` +error: `if` expression with an `else if`, but without a final `else` --> $DIR/else_if_without_else.rs:54:12 | LL | } else if bla3() { diff --git a/tests/ui/empty_line_after_outer_attribute.stderr b/tests/ui/empty_line_after_outer_attribute.stderr index 72692310391b..d8c9786541f0 100644 --- a/tests/ui/empty_line_after_outer_attribute.stderr +++ b/tests/ui/empty_line_after_outer_attribute.stderr @@ -1,4 +1,4 @@ -error: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute? +error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? --> $DIR/empty_line_after_outer_attribute.rs:7:1 | LL | / #[crate_type = "lib"] @@ -9,7 +9,7 @@ LL | | fn with_one_newline_and_comment() { assert!(true) } | = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` -error: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute? +error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? --> $DIR/empty_line_after_outer_attribute.rs:19:1 | LL | / #[crate_type = "lib"] @@ -17,7 +17,7 @@ LL | | LL | | fn with_one_newline() { assert!(true) } | |_ -error: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute? +error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? --> $DIR/empty_line_after_outer_attribute.rs:24:1 | LL | / #[crate_type = "lib"] @@ -26,7 +26,7 @@ LL | | LL | | fn with_two_newlines() { assert!(true) } | |_ -error: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute? +error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? --> $DIR/empty_line_after_outer_attribute.rs:31:1 | LL | / #[crate_type = "lib"] @@ -34,7 +34,7 @@ LL | | LL | | enum Baz { | |_ -error: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute? +error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? --> $DIR/empty_line_after_outer_attribute.rs:39:1 | LL | / #[crate_type = "lib"] @@ -42,7 +42,7 @@ LL | | LL | | struct Foo { | |_ -error: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute? +error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? --> $DIR/empty_line_after_outer_attribute.rs:47:1 | LL | / #[crate_type = "lib"] diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index 4f954f611a69..444675259a90 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -1,4 +1,4 @@ -error: used expect() on an Option value. If this value is an None it will panic +error: used `expect()` on `an Option` value. If this value is an `None` it will panic --> $DIR/expect.rs:5:13 | LL | let _ = opt.expect(""); @@ -6,7 +6,7 @@ LL | let _ = opt.expect(""); | = note: `-D clippy::option-expect-used` implied by `-D warnings` -error: used expect() on a Result value. If this value is an Err it will panic +error: used `expect()` on `a Result` value. If this value is an `Err` it will panic --> $DIR/expect.rs:10:13 | LL | let _ = res.expect(""); diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index 116e3e90e637..68f5b23bdc73 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -1,35 +1,35 @@ -error: strict comparison of f32 or f64 +error: strict comparison of `f32` or `f64` --> $DIR/float_cmp.rs:59:5 | LL | ONE as f64 != 2.0; | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE as f64 - 2.0).abs() > error` | = note: `-D clippy::float-cmp` implied by `-D warnings` -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp.rs:59:5 | LL | ONE as f64 != 2.0; | ^^^^^^^^^^^^^^^^^ -error: strict comparison of f32 or f64 +error: strict comparison of `f32` or `f64` --> $DIR/float_cmp.rs:64:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp.rs:64:5 | LL | x == 1.0; | ^^^^^^^^ -error: strict comparison of f32 or f64 +error: strict comparison of `f32` or `f64` --> $DIR/float_cmp.rs:67:5 | LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() > error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp.rs:67:5 | LL | twice(x) != twice(ONE as f64); diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 3f2ac9eee9be..c13c555cd119 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -1,83 +1,83 @@ -error: strict comparison of f32 or f64 constant +error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:20:5 | LL | 1f32 == ONE; | ^^^^^^^^^^^ help: consider comparing them within some error: `(1f32 - ONE).abs() < error` | = note: `-D clippy::float-cmp-const` implied by `-D warnings` -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp_const.rs:20:5 | LL | 1f32 == ONE; | ^^^^^^^^^^^ -error: strict comparison of f32 or f64 constant +error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:21:5 | LL | TWO == ONE; | ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() < error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp_const.rs:21:5 | LL | TWO == ONE; | ^^^^^^^^^^ -error: strict comparison of f32 or f64 constant +error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:22:5 | LL | TWO != ONE; | ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() > error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp_const.rs:22:5 | LL | TWO != ONE; | ^^^^^^^^^^ -error: strict comparison of f32 or f64 constant +error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:23:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE + ONE - TWO).abs() < error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp_const.rs:23:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ -error: strict comparison of f32 or f64 constant +error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:25:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(x as f32 - ONE).abs() < error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp_const.rs:25:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ -error: strict comparison of f32 or f64 constant +error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:28:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() < error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp_const.rs:28:5 | LL | v == ONE; | ^^^^^^^^ -error: strict comparison of f32 or f64 constant +error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:29:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() > error` | -note: std::f32::EPSILON and std::f64::EPSILON are available. +note: `std::f32::EPSILON` and `std::f64::EPSILON` are available. --> $DIR/float_cmp_const.rs:29:5 | LL | v != ONE; diff --git a/tests/ui/for_loop_fixable.stderr b/tests/ui/for_loop_fixable.stderr index 71a2334170e8..f84b7a660ff4 100644 --- a/tests/ui/for_loop_fixable.stderr +++ b/tests/ui/for_loop_fixable.stderr @@ -68,7 +68,7 @@ error: it is more concise to loop over references to containers instead of using LL | for _v in vec.iter_mut() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec` -error: it is more concise to loop over containers instead of using explicit iteration methods` +error: it is more concise to loop over containers instead of using explicit iteration methods --> $DIR/for_loop_fixable.rs:103:15 | LL | for _v in out_vec.into_iter() {} @@ -130,7 +130,7 @@ error: it is more concise to loop over references to containers instead of using LL | for _v in bs.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bs` -error: it is more concise to loop over containers instead of using explicit iteration methods` +error: it is more concise to loop over containers instead of using explicit iteration methods --> $DIR/for_loop_fixable.rs:310:18 | LL | for i in iterator.into_iter() { @@ -142,7 +142,7 @@ error: it is more concise to loop over references to containers instead of using LL | for _ in t.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t` -error: it is more concise to loop over containers instead of using explicit iteration methods` +error: it is more concise to loop over containers instead of using explicit iteration methods --> $DIR/for_loop_fixable.rs:332:18 | LL | for _ in r.into_iter() {} diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 9736f34b03b4..9734492154e8 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -2,7 +2,7 @@ error: useless use of `format!` --> $DIR/format.rs:13:5 | LL | format!("foo"); - | ^^^^^^^^^^^^^^^ help: consider using .to_string(): `"foo".to_string();` + | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` | = note: `-D clippy::useless-format` implied by `-D warnings` @@ -10,13 +10,13 @@ error: useless use of `format!` --> $DIR/format.rs:14:5 | LL | format!("{{}}"); - | ^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"{}".to_string();` + | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string();` error: useless use of `format!` --> $DIR/format.rs:15:5 | LL | format!("{{}} abc {{}}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"{} abc {}".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string();` error: useless use of `format!` --> $DIR/format.rs:16:5 @@ -25,61 +25,61 @@ LL | / format!( LL | | r##"foo {{}} LL | | " bar"## LL | | ); - | |______^ help: consider using .to_string(): `"foo {}/n/" bar".to_string();` + | |______^ help: consider using `.to_string()`: `"foo {}/n/" bar".to_string();` error: useless use of `format!` --> $DIR/format.rs:21:5 | LL | format!("{}", "foo"); - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` error: useless use of `format!` --> $DIR/format.rs:25:5 | LL | format!("{:+}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` error: useless use of `format!` --> $DIR/format.rs:26:5 | LL | format!("{:<}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` error: useless use of `format!` --> $DIR/format.rs:31:5 | LL | format!("{}", arg); - | ^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` error: useless use of `format!` --> $DIR/format.rs:35:5 | LL | format!("{:+}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` error: useless use of `format!` --> $DIR/format.rs:36:5 | LL | format!("{:<}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` error: useless use of `format!` --> $DIR/format.rs:63:5 | LL | format!("{}", 42.to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `42.to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string();` error: useless use of `format!` --> $DIR/format.rs:65:5 | LL | format!("{}", x.display().to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `x.display().to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string();` error: useless use of `format!` --> $DIR/format.rs:69:18 | LL | let _ = Some(format!("{}", a + "bar")); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `a + "bar"` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` error: aborting due to 13 previous errors diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr index 3694f5aec536..78bc4d4bd20a 100644 --- a/tests/ui/if_not_else.stderr +++ b/tests/ui/if_not_else.stderr @@ -9,7 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::if-not-else` implied by `-D warnings` - = help: remove the `!` and swap the blocks of the if/else + = help: remove the `!` and swap the blocks of the `if`/`else` error: Unnecessary `!=` operation --> $DIR/if_not_else.rs:14:5 @@ -21,7 +21,7 @@ LL | | println!("Bunny"); LL | | } | |_____^ | - = help: change to `==` and swap the blocks of the if/else + = help: change to `==` and swap the blocks of the `if`/`else` error: aborting due to 2 previous errors diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index e1a7b6f7f8b8..0c2a1fdb78a4 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -230,7 +230,7 @@ LL | | return Ok(&foo[0..]); LL | | } else { | |_____^ -error: this `if` has the same condition as a previous if +error: this `if` has the same condition as a previous `if` --> $DIR/if_same_then_else.rs:241:15 | LL | } else if true { diff --git a/tests/ui/ifs_same_cond.stderr b/tests/ui/ifs_same_cond.stderr index 0b0dd24194ed..0c8f49b8687f 100644 --- a/tests/ui/ifs_same_cond.stderr +++ b/tests/ui/ifs_same_cond.stderr @@ -1,4 +1,4 @@ -error: this `if` has the same condition as a previous if +error: this `if` has the same condition as a previous `if` --> $DIR/ifs_same_cond.rs:9:15 | LL | } else if b { @@ -11,7 +11,7 @@ note: same as this LL | if b { | ^ -error: this `if` has the same condition as a previous if +error: this `if` has the same condition as a previous `if` --> $DIR/ifs_same_cond.rs:14:15 | LL | } else if a == 1 { @@ -23,7 +23,7 @@ note: same as this LL | if a == 1 { | ^^^^^^ -error: this `if` has the same condition as a previous if +error: this `if` has the same condition as a previous `if` --> $DIR/ifs_same_cond.rs:20:15 | LL | } else if 2 * a == 1 { diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 21822344437b..411b98067d0e 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -1,4 +1,4 @@ -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:12:5 | LL | true @@ -6,61 +6,61 @@ LL | true | = note: `-D clippy::implicit-return` implied by `-D warnings` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:18:9 | LL | true | ^^^^ help: add `return` as shown: `return true` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:20:9 | LL | false | ^^^^^ help: add `return` as shown: `return false` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:28:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:29:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:44:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:52:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:61:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:79:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:80:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` -error: missing return statement +error: missing `return` statement --> $DIR/implicit_return.rs:88:5 | LL | format!("test {}", "test") diff --git a/tests/ui/infallible_destructuring_match.stderr b/tests/ui/infallible_destructuring_match.stderr index e3693d44e9a1..2f6b81cf3b56 100644 --- a/tests/ui/infallible_destructuring_match.stderr +++ b/tests/ui/infallible_destructuring_match.stderr @@ -1,4 +1,4 @@ -error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let` +error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` --> $DIR/infallible_destructuring_match.rs:18:5 | LL | / let data = match wrapper { @@ -8,7 +8,7 @@ LL | | }; | = note: `-D clippy::infallible-destructuring-match` implied by `-D warnings` -error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let` +error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` --> $DIR/infallible_destructuring_match.rs:39:5 | LL | / let data = match wrapper { @@ -16,7 +16,7 @@ LL | | TupleStruct(i) => i, LL | | }; | |______^ help: try this: `let TupleStruct(data) = wrapper;` -error: you seem to be trying to use match to destructure a single infallible pattern. Consider using `let` +error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` --> $DIR/infallible_destructuring_match.rs:60:5 | LL | / let data = match wrapper { diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index a5be50f64052..80e2d104f824 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -1,4 +1,4 @@ -error: this .into_iter() call is equivalent to .iter() and will not move the Vec +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `Vec` --> $DIR/into_iter_on_ref.rs:14:30 | LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() @@ -6,151 +6,151 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() | = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` -error: this .into_iter() call is equivalent to .iter() and will not move the slice +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `slice` --> $DIR/into_iter_on_ref.rs:15:46 | LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the slice +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `slice` --> $DIR/into_iter_on_ref.rs:16:41 | LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the slice +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `slice` --> $DIR/into_iter_on_ref.rs:17:44 | LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the array +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `array` --> $DIR/into_iter_on_ref.rs:19:32 | LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the array +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `array` --> $DIR/into_iter_on_ref.rs:20:36 | LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the array +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `array` --> $DIR/into_iter_on_ref.rs:21:40 | LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the Option +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `Option` --> $DIR/into_iter_on_ref.rs:23:24 | LL | let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the Option +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `Option` --> $DIR/into_iter_on_ref.rs:24:28 | LL | let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the Result +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `Result` --> $DIR/into_iter_on_ref.rs:25:32 | LL | let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the Result +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `Result` --> $DIR/into_iter_on_ref.rs:26:37 | LL | let _ = (&mut Err::(7)).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the Vec +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `Vec` --> $DIR/into_iter_on_ref.rs:27:34 | LL | let _ = (&Vec::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the Vec +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `Vec` --> $DIR/into_iter_on_ref.rs:28:38 | LL | let _ = (&mut Vec::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the BTreeMap +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `BTreeMap` --> $DIR/into_iter_on_ref.rs:29:44 | LL | let _ = (&BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the BTreeMap +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `BTreeMap` --> $DIR/into_iter_on_ref.rs:30:48 | LL | let _ = (&mut BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the VecDeque +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `VecDeque` --> $DIR/into_iter_on_ref.rs:31:39 | LL | let _ = (&VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the VecDeque +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `VecDeque` --> $DIR/into_iter_on_ref.rs:32:43 | LL | let _ = (&mut VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the LinkedList +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `LinkedList` --> $DIR/into_iter_on_ref.rs:33:41 | LL | let _ = (&LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the LinkedList +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `LinkedList` --> $DIR/into_iter_on_ref.rs:34:45 | LL | let _ = (&mut LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the HashMap +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `HashMap` --> $DIR/into_iter_on_ref.rs:35:43 | LL | let _ = (&HashMap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter_mut() and will not move the HashMap +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not move the `HashMap` --> $DIR/into_iter_on_ref.rs:36:47 | LL | let _ = (&mut HashMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` -error: this .into_iter() call is equivalent to .iter() and will not move the BTreeSet +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `BTreeSet` --> $DIR/into_iter_on_ref.rs:38:39 | LL | let _ = (&BTreeSet::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the BinaryHeap +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `BinaryHeap` --> $DIR/into_iter_on_ref.rs:39:41 | LL | let _ = (&BinaryHeap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the HashSet +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `HashSet` --> $DIR/into_iter_on_ref.rs:40:38 | LL | let _ = (&HashSet::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the Path +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `Path` --> $DIR/into_iter_on_ref.rs:41:43 | LL | let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: this .into_iter() call is equivalent to .iter() and will not move the PathBuf +error: this `.into_iter()` call is equivalent to `.iter()` and will not move the `PathBuf` --> $DIR/into_iter_on_ref.rs:42:47 | LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter() diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index 98d8262372df..58c0a77c1c84 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -5,7 +5,7 @@ LL | [0u32; 20_000_000], | ^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::large-stack-arrays` implied by `-D warnings` - = help: consider allocating on the heap with vec![0u32; 20_000_000].into_boxed_slice() + = help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:18:9 @@ -13,7 +13,7 @@ error: allocating a local array larger than 512000 bytes LL | [S { data: [0; 32] }; 5000], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider allocating on the heap with vec![S { data: [0; 32] }; 5000].into_boxed_slice() + = help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:19:9 @@ -21,7 +21,7 @@ error: allocating a local array larger than 512000 bytes LL | [Some(""); 20_000_000], | ^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider allocating on the heap with vec![Some(""); 20_000_000].into_boxed_slice() + = help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:20:9 @@ -29,7 +29,7 @@ error: allocating a local array larger than 512000 bytes LL | [E::T(0); 5000], | ^^^^^^^^^^^^^^^ | - = help: consider allocating on the heap with vec![E::T(0); 5000].into_boxed_slice() + = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()` error: aborting due to 4 previous errors diff --git a/tests/ui/let_return.rs b/tests/ui/let_return.rs index 40052f86dd53..23645d48fe79 100644 --- a/tests/ui/let_return.rs +++ b/tests/ui/let_return.rs @@ -45,4 +45,26 @@ fn test_nowarn_5(x: i16) -> u16 { x } +// False positive example +trait Decode { + fn decode(d: D) -> Result + where + Self: Sized; +} + +macro_rules! tuple_encode { + ($($x:ident),*) => ( + impl<$($x: Decode),*> Decode for ($($x),*) { + #[inline] + #[allow(non_snake_case)] + fn decode(mut d: D) -> Result { + // Shouldn't trigger lint + Ok(($({let $x = Decode::decode(&mut d)?; $x }),*)) + } + } + ); +} + +tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); + fn main() {} diff --git a/tests/ui/let_return.stderr b/tests/ui/let_return.stderr index 11e9681f3ec0..128a22c86e36 100644 --- a/tests/ui/let_return.stderr +++ b/tests/ui/let_return.stderr @@ -1,8 +1,8 @@ -error: returning the result of a let binding from a block +error: returning the result of a `let` binding from a block --> $DIR/let_return.rs:7:5 | LL | let x = 5; - | ---------- unnecessary let binding + | ---------- unnecessary `let` binding LL | x | ^ | @@ -13,11 +13,11 @@ LL | LL | 5 | -error: returning the result of a let binding from a block +error: returning the result of a `let` binding from a block --> $DIR/let_return.rs:13:9 | LL | let x = 5; - | ---------- unnecessary let binding + | ---------- unnecessary `let` binding LL | x | ^ | diff --git a/tests/ui/let_underscore.stderr b/tests/ui/let_underscore.stderr index da007d3b0835..6fa587a4c0a7 100644 --- a/tests/ui/let_underscore.stderr +++ b/tests/ui/let_underscore.stderr @@ -1,4 +1,4 @@ -error: non-binding let on a result of a #[must_use] function +error: non-binding let on a result of a `#[must_use]` function --> $DIR/let_underscore.rs:59:5 | LL | let _ = f(); @@ -7,7 +7,7 @@ LL | let _ = f(); = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` = help: consider explicitly using function result -error: non-binding let on an expression with #[must_use] type +error: non-binding let on an expression with `#[must_use]` type --> $DIR/let_underscore.rs:60:5 | LL | let _ = g(); @@ -15,7 +15,7 @@ LL | let _ = g(); | = help: consider explicitly using expression value -error: non-binding let on a result of a #[must_use] function +error: non-binding let on a result of a `#[must_use]` function --> $DIR/let_underscore.rs:62:5 | LL | let _ = l(0_u32); @@ -23,7 +23,7 @@ LL | let _ = l(0_u32); | = help: consider explicitly using function result -error: non-binding let on a result of a #[must_use] function +error: non-binding let on a result of a `#[must_use]` function --> $DIR/let_underscore.rs:66:5 | LL | let _ = s.f(); @@ -31,7 +31,7 @@ LL | let _ = s.f(); | = help: consider explicitly using function result -error: non-binding let on an expression with #[must_use] type +error: non-binding let on an expression with `#[must_use]` type --> $DIR/let_underscore.rs:67:5 | LL | let _ = s.g(); @@ -39,7 +39,7 @@ LL | let _ = s.g(); | = help: consider explicitly using expression value -error: non-binding let on a result of a #[must_use] function +error: non-binding let on a result of a `#[must_use]` function --> $DIR/let_underscore.rs:70:5 | LL | let _ = S::h(); @@ -47,7 +47,7 @@ LL | let _ = S::h(); | = help: consider explicitly using function result -error: non-binding let on an expression with #[must_use] type +error: non-binding let on an expression with `#[must_use]` type --> $DIR/let_underscore.rs:71:5 | LL | let _ = S::p(); @@ -55,7 +55,7 @@ LL | let _ = S::p(); | = help: consider explicitly using expression value -error: non-binding let on a result of a #[must_use] function +error: non-binding let on a result of a `#[must_use]` function --> $DIR/let_underscore.rs:73:5 | LL | let _ = S::a(); @@ -63,7 +63,7 @@ LL | let _ = S::a(); | = help: consider explicitly using function result -error: non-binding let on an expression with #[must_use] type +error: non-binding let on an expression with `#[must_use]` type --> $DIR/let_underscore.rs:75:5 | LL | let _ = if true { Ok(()) } else { Err(()) }; @@ -71,7 +71,7 @@ LL | let _ = if true { Ok(()) } else { Err(()) }; | = help: consider explicitly using expression value -error: non-binding let on a result of a #[must_use] function +error: non-binding let on a result of a `#[must_use]` function --> $DIR/let_underscore.rs:79:5 | LL | let _ = a.is_ok(); @@ -79,7 +79,7 @@ LL | let _ = a.is_ok(); | = help: consider explicitly using function result -error: non-binding let on an expression with #[must_use] type +error: non-binding let on an expression with `#[must_use]` type --> $DIR/let_underscore.rs:81:5 | LL | let _ = a.map(|_| ()); @@ -87,7 +87,7 @@ LL | let _ = a.map(|_| ()); | = help: consider explicitly using expression value -error: non-binding let on an expression with #[must_use] type +error: non-binding let on an expression with `#[must_use]` type --> $DIR/let_underscore.rs:83:5 | LL | let _ = a; diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index 35e234a73296..f67679c7b967 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -34,7 +34,7 @@ error: You are needlessly cloning iterator elements --> $DIR/map_clone.rs:25:29 | LL | let _ = std::env::args().map(|v| v.clone()); - | ^^^^^^^^^^^^^^^^^^^ help: Remove the map call + | ^^^^^^^^^^^^^^^^^^^ help: Remove the `map` call error: aborting due to 6 previous errors diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr index 478c7e780d96..e2ebd89b4c46 100644 --- a/tests/ui/map_flatten.stderr +++ b/tests/ui/map_flatten.stderr @@ -2,7 +2,7 @@ error: called `map(..).flatten()` on an `Iterator`. This is more succinctly expr --> $DIR/map_flatten.rs:7:21 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using flat_map instead: `vec![5_i8; 6].into_iter().flat_map(|x| 0..x)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `vec![5_i8; 6].into_iter().flat_map(|x| 0..x)` | = note: `-D clippy::map-flatten` implied by `-D warnings` diff --git a/tests/ui/match_as_ref.stderr b/tests/ui/match_as_ref.stderr index dd4739d1ff21..c3b62849cb33 100644 --- a/tests/ui/match_as_ref.stderr +++ b/tests/ui/match_as_ref.stderr @@ -1,4 +1,4 @@ -error: use as_ref() instead +error: use `as_ref()` instead --> $DIR/match_as_ref.rs:8:33 | LL | let borrowed: Option<&()> = match owned { @@ -10,7 +10,7 @@ LL | | }; | = note: `-D clippy::match-as-ref` implied by `-D warnings` -error: use as_mut() instead +error: use `as_mut()` instead --> $DIR/match_as_ref.rs:14:39 | LL | let borrow_mut: Option<&mut ()> = match mut_owned { @@ -20,7 +20,7 @@ LL | | Some(ref mut v) => Some(v), LL | | }; | |_____^ help: try this: `mut_owned.as_mut()` -error: use as_ref() instead +error: use `as_ref()` instead --> $DIR/match_as_ref.rs:30:13 | LL | / match self.source { diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index 2751048f8726..42f20862939b 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -13,7 +13,7 @@ LL | / match test { LL | | true => 0, LL | | false => 42, LL | | }; - | |_____^ help: consider using an if/else expression: `if test { 0 } else { 42 }` + | |_____^ help: consider using an `if`/`else` expression: `if test { 0 } else { 42 }` | = note: `-D clippy::match-bool` implied by `-D warnings` @@ -24,7 +24,7 @@ LL | / match option == 1 { LL | | true => 1, LL | | false => 0, LL | | }; - | |_____^ help: consider using an if/else expression: `if option == 1 { 1 } else { 0 }` + | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: you seem to be trying to match on a boolean expression --> $DIR/match_bool.rs:15:5 @@ -37,7 +37,7 @@ LL | | }, LL | | }; | |_____^ | -help: consider using an if/else expression +help: consider using an `if`/`else` expression | LL | if !test { LL | println!("Noooo!"); @@ -55,7 +55,7 @@ LL | | _ => (), LL | | }; | |_____^ | -help: consider using an if/else expression +help: consider using an `if`/`else` expression | LL | if !test { LL | println!("Noooo!"); @@ -73,7 +73,7 @@ LL | | _ => (), LL | | }; | |_____^ | -help: consider using an if/else expression +help: consider using an `if`/`else` expression | LL | if !(test && test) { LL | println!("Noooo!"); @@ -100,7 +100,7 @@ LL | | }, LL | | }; | |_____^ | -help: consider using an if/else expression +help: consider using an `if`/`else` expression | LL | if test { LL | println!("Yes!"); diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index 38d51ebd4769..f2153cfb3ad3 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -24,7 +24,7 @@ LL | | if true { LL | | a LL | | }, | |_________^ -note: `42` has the same arm body as the `_` wildcard, consider removing it` +note: `42` has the same arm body as the `_` wildcard, consider removing it --> $DIR/match_same_arms.rs:28:15 | LL | 42 => { @@ -48,7 +48,7 @@ note: same as this | LL | Abc::A => 0, | ^ -note: `Abc::A` has the same arm body as the `_` wildcard, consider removing it` +note: `Abc::A` has the same arm body as the `_` wildcard, consider removing it --> $DIR/match_same_arms.rs:50:19 | LL | Abc::A => 0, diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index f47e976e8cc4..75d050f316b5 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -1,11 +1,11 @@ -error: Err(_) will match all errors, maybe not a good idea +error: `Err(_)` will match all errors, maybe not a good idea --> $DIR/matches.rs:14:9 | LL | Err(_) => panic!("err"), | ^^^^^^ | = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` - = note: to remove this warning, match each error separately or use unreachable macro + = note: to remove this warning, match each error separately or use `unreachable!` macro error: this `match` has identical arm bodies --> $DIR/matches.rs:13:18 @@ -26,13 +26,13 @@ LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) -error: Err(_) will match all errors, maybe not a good idea +error: `Err(_)` will match all errors, maybe not a good idea --> $DIR/matches.rs:20:9 | LL | Err(_) => panic!(), | ^^^^^^ | - = note: to remove this warning, match each error separately or use unreachable macro + = note: to remove this warning, match each error separately or use `unreachable!` macro error: this `match` has identical arm bodies --> $DIR/matches.rs:19:18 @@ -52,13 +52,13 @@ LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) -error: Err(_) will match all errors, maybe not a good idea +error: `Err(_)` will match all errors, maybe not a good idea --> $DIR/matches.rs:26:9 | LL | Err(_) => { | ^^^^^^ | - = note: to remove this warning, match each error separately or use unreachable macro + = note: to remove this warning, match each error separately or use `unreachable!` macro error: this `match` has identical arm bodies --> $DIR/matches.rs:25:18 diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index 16b95a1038a0..a90d8b1655dc 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -1,4 +1,4 @@ -error: usage of mem::forget on Drop type +error: usage of `mem::forget` on `Drop` type --> $DIR/mem_forget.rs:14:5 | LL | memstuff::forget(six); @@ -6,13 +6,13 @@ LL | memstuff::forget(six); | = note: `-D clippy::mem-forget` implied by `-D warnings` -error: usage of mem::forget on Drop type +error: usage of `mem::forget` on `Drop` type --> $DIR/mem_forget.rs:17:5 | LL | std::mem::forget(seven); | ^^^^^^^^^^^^^^^^^^^^^^^ -error: usage of mem::forget on Drop type +error: usage of `mem::forget` on `Drop` type --> $DIR/mem_forget.rs:20:5 | LL | forgetSomething(eight); diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr index 6d68d39e8d36..b552c137f7c7 100644 --- a/tests/ui/min_max.stderr +++ b/tests/ui/min_max.stderr @@ -1,4 +1,4 @@ -error: this min/max combination leads to constant result +error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:12:5 | LL | min(1, max(3, x)); @@ -6,37 +6,37 @@ LL | min(1, max(3, x)); | = note: `-D clippy::min-max` implied by `-D warnings` -error: this min/max combination leads to constant result +error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:13:5 | LL | min(max(3, x), 1); | ^^^^^^^^^^^^^^^^^ -error: this min/max combination leads to constant result +error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:14:5 | LL | max(min(x, 1), 3); | ^^^^^^^^^^^^^^^^^ -error: this min/max combination leads to constant result +error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:15:5 | LL | max(3, min(x, 1)); | ^^^^^^^^^^^^^^^^^ -error: this min/max combination leads to constant result +error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:17:5 | LL | my_max(3, my_min(x, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^ -error: this min/max combination leads to constant result +error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:29:5 | LL | min("Apple", max("Zoo", s)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: this min/max combination leads to constant result +error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:30:5 | LL | max(min(s, "Apple"), "Zoo"); diff --git a/tests/ui/missing-doc-impl.rs b/tests/ui/missing-doc-impl.rs new file mode 100644 index 000000000000..1317521f7366 --- /dev/null +++ b/tests/ui/missing-doc-impl.rs @@ -0,0 +1,87 @@ +#![warn(clippy::missing_docs_in_private_items)] +#![allow(dead_code)] +#![feature(associated_type_defaults)] + +//! Some garbage docs for the crate here +#![doc = "More garbage"] + +struct Foo { + a: isize, + b: isize, +} + +pub struct PubFoo { + pub a: isize, + b: isize, +} + +#[allow(clippy::missing_docs_in_private_items)] +pub struct PubFoo2 { + pub a: isize, + pub c: isize, +} + +/// dox +pub trait A { + /// dox + fn foo(&self); + /// dox + fn foo_with_impl(&self) {} +} + +#[allow(clippy::missing_docs_in_private_items)] +trait B { + fn foo(&self); + fn foo_with_impl(&self) {} +} + +pub trait C { + fn foo(&self); + fn foo_with_impl(&self) {} +} + +#[allow(clippy::missing_docs_in_private_items)] +pub trait D { + fn dummy(&self) {} +} + +/// dox +pub trait E { + type AssociatedType; + type AssociatedTypeDef = Self; + + /// dox + type DocumentedType; + /// dox + type DocumentedTypeDef = Self; + /// dox + fn dummy(&self) {} +} + +impl Foo { + pub fn foo() {} + fn bar() {} +} + +impl PubFoo { + pub fn foo() {} + /// dox + pub fn foo1() {} + fn foo2() {} + #[allow(clippy::missing_docs_in_private_items)] + pub fn foo3() {} +} + +#[allow(clippy::missing_docs_in_private_items)] +trait F { + fn a(); + fn b(&self); +} + +// should need to redefine documentation for implementations of traits +impl F for Foo { + fn a() {} + fn b(&self) {} +} + +fn main() {} diff --git a/tests/ui/missing-doc-impl.stderr b/tests/ui/missing-doc-impl.stderr new file mode 100644 index 000000000000..9656a39abceb --- /dev/null +++ b/tests/ui/missing-doc-impl.stderr @@ -0,0 +1,103 @@ +error: missing documentation for a struct + --> $DIR/missing-doc-impl.rs:8:1 + | +LL | / struct Foo { +LL | | a: isize, +LL | | b: isize, +LL | | } + | |_^ + | + = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + +error: missing documentation for a struct field + --> $DIR/missing-doc-impl.rs:9:5 + | +LL | a: isize, + | ^^^^^^^^ + +error: missing documentation for a struct field + --> $DIR/missing-doc-impl.rs:10:5 + | +LL | b: isize, + | ^^^^^^^^ + +error: missing documentation for a struct + --> $DIR/missing-doc-impl.rs:13:1 + | +LL | / pub struct PubFoo { +LL | | pub a: isize, +LL | | b: isize, +LL | | } + | |_^ + +error: missing documentation for a struct field + --> $DIR/missing-doc-impl.rs:14:5 + | +LL | pub a: isize, + | ^^^^^^^^^^^^ + +error: missing documentation for a struct field + --> $DIR/missing-doc-impl.rs:15:5 + | +LL | b: isize, + | ^^^^^^^^ + +error: missing documentation for a trait + --> $DIR/missing-doc-impl.rs:38:1 + | +LL | / pub trait C { +LL | | fn foo(&self); +LL | | fn foo_with_impl(&self) {} +LL | | } + | |_^ + +error: missing documentation for a trait method + --> $DIR/missing-doc-impl.rs:39:5 + | +LL | fn foo(&self); + | ^^^^^^^^^^^^^^ + +error: missing documentation for a trait method + --> $DIR/missing-doc-impl.rs:40:5 + | +LL | fn foo_with_impl(&self) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for an associated type + --> $DIR/missing-doc-impl.rs:50:5 + | +LL | type AssociatedType; + | ^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for an associated type + --> $DIR/missing-doc-impl.rs:51:5 + | +LL | type AssociatedTypeDef = Self; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc-impl.rs:62:5 + | +LL | pub fn foo() {} + | ^^^^^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc-impl.rs:63:5 + | +LL | fn bar() {} + | ^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc-impl.rs:67:5 + | +LL | pub fn foo() {} + | ^^^^^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc-impl.rs:70:5 + | +LL | fn foo2() {} + | ^^^^^^^^^^^^ + +error: aborting due to 15 previous errors + diff --git a/tests/ui/missing-doc.rs b/tests/ui/missing-doc.rs index e65bce8e783f..a9bf7140a1e5 100644 --- a/tests/ui/missing-doc.rs +++ b/tests/ui/missing-doc.rs @@ -2,7 +2,7 @@ // When denying at the crate level, be sure to not get random warnings from the // injected intrinsics by the compiler. #![allow(dead_code)] -#![feature(associated_type_defaults, global_asm)] +#![feature(global_asm)] //! Some garbage docs for the crate here #![doc = "More garbage"] @@ -10,22 +10,6 @@ type Typedef = String; pub type PubTypedef = String; -struct Foo { - a: isize, - b: isize, -} - -pub struct PubFoo { - pub a: isize, - b: isize, -} - -#[allow(clippy::missing_docs_in_private_items)] -pub struct PubFoo2 { - pub a: isize, - pub c: isize, -} - mod module_no_dox {} pub mod pub_module_no_dox {} @@ -36,69 +20,6 @@ fn foo3() {} #[allow(clippy::missing_docs_in_private_items)] pub fn foo4() {} -/// dox -pub trait A { - /// dox - fn foo(&self); - /// dox - fn foo_with_impl(&self) {} -} - -#[allow(clippy::missing_docs_in_private_items)] -trait B { - fn foo(&self); - fn foo_with_impl(&self) {} -} - -pub trait C { - fn foo(&self); - fn foo_with_impl(&self) {} -} - -#[allow(clippy::missing_docs_in_private_items)] -pub trait D { - fn dummy(&self) {} -} - -/// dox -pub trait E { - type AssociatedType; - type AssociatedTypeDef = Self; - - /// dox - type DocumentedType; - /// dox - type DocumentedTypeDef = Self; - /// dox - fn dummy(&self) {} -} - -impl Foo { - pub fn foo() {} - fn bar() {} -} - -impl PubFoo { - pub fn foo() {} - /// dox - pub fn foo1() {} - fn foo2() {} - #[allow(clippy::missing_docs_in_private_items)] - pub fn foo3() {} -} - -#[allow(clippy::missing_docs_in_private_items)] -trait F { - fn a(); - fn b(&self); -} - -// should need to redefine documentation for implementations of traits -impl F for Foo { - fn a() {} - fn b(&self) {} -} - // It sure is nice if doc(hidden) implies allow(missing_docs), and that it // applies recursively #[doc(hidden)] diff --git a/tests/ui/missing-doc.stderr b/tests/ui/missing-doc.stderr index a3ae62217a27..a876dc078ebf 100644 --- a/tests/ui/missing-doc.stderr +++ b/tests/ui/missing-doc.stderr @@ -12,131 +12,32 @@ error: missing documentation for a type alias LL | pub type PubTypedef = String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: missing documentation for a struct - --> $DIR/missing-doc.rs:13:1 - | -LL | / struct Foo { -LL | | a: isize, -LL | | b: isize, -LL | | } - | |_^ - -error: missing documentation for a struct field - --> $DIR/missing-doc.rs:14:5 - | -LL | a: isize, - | ^^^^^^^^ - -error: missing documentation for a struct field - --> $DIR/missing-doc.rs:15:5 - | -LL | b: isize, - | ^^^^^^^^ - -error: missing documentation for a struct - --> $DIR/missing-doc.rs:18:1 - | -LL | / pub struct PubFoo { -LL | | pub a: isize, -LL | | b: isize, -LL | | } - | |_^ - -error: missing documentation for a struct field - --> $DIR/missing-doc.rs:19:5 - | -LL | pub a: isize, - | ^^^^^^^^^^^^ - -error: missing documentation for a struct field - --> $DIR/missing-doc.rs:20:5 - | -LL | b: isize, - | ^^^^^^^^ - error: missing documentation for a module - --> $DIR/missing-doc.rs:29:1 + --> $DIR/missing-doc.rs:13:1 | LL | mod module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing-doc.rs:30:1 + --> $DIR/missing-doc.rs:14:1 | LL | pub mod pub_module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:34:1 + --> $DIR/missing-doc.rs:18:1 | LL | pub fn foo2() {} | ^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:35:1 + --> $DIR/missing-doc.rs:19:1 | LL | fn foo3() {} | ^^^^^^^^^^^^ -error: missing documentation for a trait - --> $DIR/missing-doc.rs:53:1 - | -LL | / pub trait C { -LL | | fn foo(&self); -LL | | fn foo_with_impl(&self) {} -LL | | } - | |_^ - -error: missing documentation for a trait method - --> $DIR/missing-doc.rs:54:5 - | -LL | fn foo(&self); - | ^^^^^^^^^^^^^^ - -error: missing documentation for a trait method - --> $DIR/missing-doc.rs:55:5 - | -LL | fn foo_with_impl(&self) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for an associated type - --> $DIR/missing-doc.rs:65:5 - | -LL | type AssociatedType; - | ^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for an associated type - --> $DIR/missing-doc.rs:66:5 - | -LL | type AssociatedTypeDef = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a method - --> $DIR/missing-doc.rs:77:5 - | -LL | pub fn foo() {} - | ^^^^^^^^^^^^^^^ - -error: missing documentation for a method - --> $DIR/missing-doc.rs:78:5 - | -LL | fn bar() {} - | ^^^^^^^^^^^ - -error: missing documentation for a method - --> $DIR/missing-doc.rs:82:5 - | -LL | pub fn foo() {} - | ^^^^^^^^^^^^^^^ - -error: missing documentation for a method - --> $DIR/missing-doc.rs:85:5 - | -LL | fn foo2() {} - | ^^^^^^^^^^^^ - error: missing documentation for an enum - --> $DIR/missing-doc.rs:112:1 + --> $DIR/missing-doc.rs:33:1 | LL | / enum Baz { LL | | BazA { a: isize, b: isize }, @@ -145,31 +46,31 @@ LL | | } | |_^ error: missing documentation for a variant - --> $DIR/missing-doc.rs:113:5 + --> $DIR/missing-doc.rs:34:5 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing-doc.rs:113:12 + --> $DIR/missing-doc.rs:34:12 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing-doc.rs:113:22 + --> $DIR/missing-doc.rs:34:22 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a variant - --> $DIR/missing-doc.rs:114:5 + --> $DIR/missing-doc.rs:35:5 | LL | BarB, | ^^^^ error: missing documentation for an enum - --> $DIR/missing-doc.rs:117:1 + --> $DIR/missing-doc.rs:38:1 | LL | / pub enum PubBaz { LL | | PubBazA { a: isize }, @@ -177,43 +78,43 @@ LL | | } | |_^ error: missing documentation for a variant - --> $DIR/missing-doc.rs:118:5 + --> $DIR/missing-doc.rs:39:5 | LL | PubBazA { a: isize }, | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing-doc.rs:118:15 + --> $DIR/missing-doc.rs:39:15 | LL | PubBazA { a: isize }, | ^^^^^^^^ error: missing documentation for a constant - --> $DIR/missing-doc.rs:138:1 + --> $DIR/missing-doc.rs:59:1 | LL | const FOO: u32 = 0; | ^^^^^^^^^^^^^^^^^^^ error: missing documentation for a constant - --> $DIR/missing-doc.rs:145:1 + --> $DIR/missing-doc.rs:66:1 | LL | pub const FOO4: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> $DIR/missing-doc.rs:147:1 + --> $DIR/missing-doc.rs:68:1 | LL | static BAR: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> $DIR/missing-doc.rs:154:1 + --> $DIR/missing-doc.rs:75:1 | LL | pub static BAR4: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing-doc.rs:156:1 + --> $DIR/missing-doc.rs:77:1 | LL | / mod internal_impl { LL | | /// dox @@ -225,34 +126,34 @@ LL | | } | |_^ error: missing documentation for a function - --> $DIR/missing-doc.rs:159:5 + --> $DIR/missing-doc.rs:80:5 | LL | pub fn undocumented1() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:160:5 + --> $DIR/missing-doc.rs:81:5 | LL | pub fn undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:161:5 + --> $DIR/missing-doc.rs:82:5 | LL | fn undocumented3() {} | ^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:166:9 + --> $DIR/missing-doc.rs:87:9 | LL | pub fn also_undocumented1() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:167:9 + --> $DIR/missing-doc.rs:88:9 | LL | fn also_undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 39 previous errors +error: aborting due to 24 previous errors diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index 708e7e467b9a..7d3dca1800b3 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -1,4 +1,4 @@ -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:12:5 | LL | / pub fn new() -> Self { @@ -8,7 +8,7 @@ LL | | } | = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:18:1 | LL | / fn one() -> i32 { @@ -16,7 +16,7 @@ LL | | 1 LL | | } | |_^ -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:23:1 | LL | / fn two() -> i32 { @@ -25,7 +25,7 @@ LL | | abc LL | | } | |_^ -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:30:1 | LL | / fn string() -> String { @@ -33,7 +33,7 @@ LL | | String::new() LL | | } | |_^ -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:35:1 | LL | / unsafe fn four() -> i32 { @@ -41,7 +41,7 @@ LL | | 4 LL | | } | |_^ -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:40:1 | LL | / fn generic(t: T) -> T { @@ -49,7 +49,7 @@ LL | | t LL | | } | |_^ -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:44:1 | LL | / fn sub(x: u32) -> usize { @@ -57,7 +57,7 @@ LL | | unsafe { transmute(&x) } LL | | } | |_^ -error: this could be a const_fn +error: this could be a `const fn` --> $DIR/could_be_const.rs:63:9 | LL | / pub fn b(self, a: &A) -> B { diff --git a/tests/ui/mul_add.stderr b/tests/ui/mul_add.stderr index 92c3b9e03c15..3b21646f7c30 100644 --- a/tests/ui/mul_add.stderr +++ b/tests/ui/mul_add.stderr @@ -1,4 +1,4 @@ -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add.rs:10:17 | LL | let test1 = (a * b + c) * (c + a * b) + (c + (a * b) + c); @@ -6,25 +6,25 @@ LL | let test1 = (a * b + c) * (c + a * b) + (c + (a * b) + c); | = note: `-D clippy::manual-mul-add` implied by `-D warnings` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add.rs:10:17 | LL | let test1 = (a * b + c) * (c + a * b) + (c + (a * b) + c); | ^^^^^^^^^^^ help: try: `a.mul_add(b, c)` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add.rs:10:31 | LL | let test1 = (a * b + c) * (c + a * b) + (c + (a * b) + c); | ^^^^^^^^^^^ help: try: `a.mul_add(b, c)` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add.rs:10:46 | LL | let test1 = (a * b + c) * (c + a * b) + (c + (a * b) + c); | ^^^^^^^^^^^ help: try: `a.mul_add(b, c)` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add.rs:11:17 | LL | let test2 = 1234.567 * 45.67834 + 0.0004; diff --git a/tests/ui/mul_add_fixable.stderr b/tests/ui/mul_add_fixable.stderr index 123ab2ff100a..235443f4b02b 100644 --- a/tests/ui/mul_add_fixable.stderr +++ b/tests/ui/mul_add_fixable.stderr @@ -1,4 +1,4 @@ -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add_fixable.rs:12:17 | LL | let test1 = a * b + c; @@ -6,31 +6,31 @@ LL | let test1 = a * b + c; | = note: `-D clippy::manual-mul-add` implied by `-D warnings` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add_fixable.rs:13:17 | LL | let test2 = c + a * b; | ^^^^^^^^^ help: try: `a.mul_add(b, c)` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add_fixable.rs:15:17 | LL | let test3 = (a * b) + c; | ^^^^^^^^^^^ help: try: `a.mul_add(b, c)` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add_fixable.rs:16:17 | LL | let test4 = c + (a * b); | ^^^^^^^^^^^ help: try: `a.mul_add(b, c)` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add_fixable.rs:18:17 | LL | let test5 = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))` -error: consider using mul_add() for better numerical precision +error: consider using `mul_add()` for better numerical precision --> $DIR/mul_add_fixable.rs:19:17 | LL | let test6 = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr index 1b0f5c1571b7..7dac08658554 100644 --- a/tests/ui/mutex_atomic.stderr +++ b/tests/ui/mutex_atomic.stderr @@ -1,4 +1,4 @@ -error: Consider using an AtomicBool instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. +error: Consider using an `AtomicBool` instead of a `Mutex` here. If you just want the locking behavior and not the internal type, consider using `Mutex<()>`. --> $DIR/mutex_atomic.rs:6:5 | LL | Mutex::new(true); @@ -6,31 +6,31 @@ LL | Mutex::new(true); | = note: `-D clippy::mutex-atomic` implied by `-D warnings` -error: Consider using an AtomicUsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. +error: Consider using an `AtomicUsize` instead of a `Mutex` here. If you just want the locking behavior and not the internal type, consider using `Mutex<()>`. --> $DIR/mutex_atomic.rs:7:5 | LL | Mutex::new(5usize); | ^^^^^^^^^^^^^^^^^^ -error: Consider using an AtomicIsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. +error: Consider using an `AtomicIsize` instead of a `Mutex` here. If you just want the locking behavior and not the internal type, consider using `Mutex<()>`. --> $DIR/mutex_atomic.rs:8:5 | LL | Mutex::new(9isize); | ^^^^^^^^^^^^^^^^^^ -error: Consider using an AtomicPtr instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. +error: Consider using an `AtomicPtr` instead of a `Mutex` here. If you just want the locking behavior and not the internal type, consider using `Mutex<()>`. --> $DIR/mutex_atomic.rs:10:5 | LL | Mutex::new(&x as *const u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Consider using an AtomicPtr instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. +error: Consider using an `AtomicPtr` instead of a `Mutex` here. If you just want the locking behavior and not the internal type, consider using `Mutex<()>`. --> $DIR/mutex_atomic.rs:11:5 | LL | Mutex::new(&mut x as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Consider using an AtomicUsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. +error: Consider using an `AtomicUsize` instead of a `Mutex` here. If you just want the locking behavior and not the internal type, consider using `Mutex<()>`. --> $DIR/mutex_atomic.rs:12:5 | LL | Mutex::new(0u32); @@ -38,7 +38,7 @@ LL | Mutex::new(0u32); | = note: `-D clippy::mutex-integer` implied by `-D warnings` -error: Consider using an AtomicIsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. +error: Consider using an `AtomicIsize` instead of a `Mutex` here. If you just want the locking behavior and not the internal type, consider using `Mutex<()>`. --> $DIR/mutex_atomic.rs:13:5 | LL | Mutex::new(0i32); diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 340ae66dae49..b9215885877d 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -1,4 +1,4 @@ -error: This else block is redundant. +error: This `else` block is redundant. --> $DIR/needless_continue.rs:28:16 | @@ -9,7 +9,7 @@ LL | | } | |_________^ | = note: `-D clippy::needless-continue` implied by `-D warnings` - = help: Consider dropping the else clause and merging the code that follows (in the loop) with the if block, like so: + = help: Consider dropping the `else` clause and merging the code that follows (in the loop) with the `if` block, like so: if i % 2 == 0 && i % 3 == 0 { println!("{}", i); println!("{}", i + 1); @@ -47,7 +47,7 @@ LL | | println!("Jabber"); LL | | } | |_________^ | - = help: Consider dropping the else clause, and moving out the code in the else block, like so: + = help: Consider dropping the `else` clause, and moving out the code in the `else` block, like so: if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { continue; } @@ -55,7 +55,7 @@ LL | | } println!("Jabber"); ... -error: This else block is redundant. +error: This `else` block is redundant. --> $DIR/needless_continue.rs:100:24 | @@ -65,7 +65,7 @@ LL | | continue 'inner; // should lint here LL | | } | |_________________^ | - = help: Consider dropping the else clause and merging the code that follows (in the loop) with the if block, like so: + = help: Consider dropping the `else` clause and merging the code that follows (in the loop) with the `if` block, like so: if condition() { println!("bar-3"); // Merged code follows...println!("bar-4"); @@ -90,7 +90,7 @@ LL | | println!("bar-5"); LL | | } | |_________________^ | - = help: Consider dropping the else clause, and moving out the code in the else block, like so: + = help: Consider dropping the `else` clause, and moving out the code in the `else` block, like so: if condition() { continue; } diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 37241dbb409e..9aa783bf904e 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -120,7 +120,7 @@ error: this argument is passed by value, but not consumed in the function body LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | -help: consider marking this type as Copy +help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); @@ -132,7 +132,7 @@ error: this argument is passed by value, but not consumed in the function body LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | -help: consider marking this type as Copy +help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); @@ -144,7 +144,7 @@ error: this argument is passed by value, but not consumed in the function body LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | -help: consider marking this type as Copy +help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); @@ -156,7 +156,7 @@ error: this argument is passed by value, but not consumed in the function body LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | -help: consider marking this type as Copy +help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index b29c47f7b7a7..c34eecbcbb63 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -1,4 +1,4 @@ -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:18:5 | LL | return true; @@ -6,67 +6,67 @@ LL | return true; | = note: `-D clippy::needless-return` implied by `-D warnings` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:22:5 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:27:9 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:29:9 | LL | return false; | ^^^^^^^^^^^^^ help: remove `return`: `false` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:35:17 | LL | true => return false, | ^^^^^^^^^^^^ help: remove `return`: `false` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:37:13 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:44:9 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:46:16 | LL | let _ = || return true; | ^^^^^^^^^^^ help: remove `return`: `true` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:54:5 | LL | return; | ^^^^^^^ help: remove `return` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:59:9 | LL | return; | ^^^^^^^ help: remove `return` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:61:9 | LL | return; | ^^^^^^^ help: remove `return` -error: unneeded return statement +error: unneeded `return` statement --> $DIR/needless_return.rs:68:14 | LL | _ => return, diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr index 055546554518..f08bbd6a12c5 100644 --- a/tests/ui/neg_multiply.stderr +++ b/tests/ui/neg_multiply.stderr @@ -1,4 +1,4 @@ -error: Negation by multiplying with -1 +error: Negation by multiplying with `-1` --> $DIR/neg_multiply.rs:27:5 | LL | x * -1; @@ -6,7 +6,7 @@ LL | x * -1; | = note: `-D clippy::neg-multiply` implied by `-D warnings` -error: Negation by multiplying with -1 +error: Negation by multiplying with `-1` --> $DIR/neg_multiply.rs:29:5 | LL | -1 * x; diff --git a/tests/ui/non_copy_const.stderr b/tests/ui/non_copy_const.stderr index 0568386f889b..c80bf3deb95b 100644 --- a/tests/ui/non_copy_const.stderr +++ b/tests/ui/non_copy_const.stderr @@ -1,4 +1,4 @@ -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:9:1 | LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable @@ -8,7 +8,7 @@ LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable | = note: `#[deny(clippy::declare_interior_mutable_const)]` on by default -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:10:1 | LL | const CELL: Cell = Cell::new(6); //~ ERROR interior mutable @@ -16,7 +16,7 @@ LL | const CELL: Cell = Cell::new(6); //~ ERROR interior mutable | | | make this a static item (maybe with lazy_static) -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:11:1 | LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], Vec::new(), 7); @@ -24,7 +24,7 @@ LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], V | | | make this a static item (maybe with lazy_static) -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:16:9 | LL | const $name: $ty = $e; @@ -33,13 +33,13 @@ LL | const $name: $ty = $e; LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable | ------------------------------------------ in this macro invocation -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:40:5 | LL | const ATOMIC: AtomicUsize; //~ ERROR interior mutable | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:44:5 | LL | const INPUT: T; @@ -47,7 +47,7 @@ LL | const INPUT: T; | | | consider requiring `T` to be `Copy` -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:47:5 | LL | const ASSOC: Self::NonCopyType; @@ -55,7 +55,7 @@ LL | const ASSOC: Self::NonCopyType; | | | consider requiring `>::NonCopyType` to be `Copy` -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:51:5 | LL | const AN_INPUT: T = Self::INPUT; @@ -63,7 +63,7 @@ LL | const AN_INPUT: T = Self::INPUT; | | | consider requiring `T` to be `Copy` -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:16:9 | LL | const $name: $ty = $e; @@ -72,7 +72,7 @@ LL | const $name: $ty = $e; LL | declare_const!(ANOTHER_INPUT: T = Self::INPUT); //~ ERROR interior mutable | ----------------------------------------------- in this macro invocation -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:60:5 | LL | const SELF_2: Self; @@ -80,13 +80,13 @@ LL | const SELF_2: Self; | | | consider requiring `Self` to be `Copy` -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:81:5 | LL | const ASSOC_3: AtomicUsize = AtomicUsize::new(14); //~ ERROR interior mutable | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:84:5 | LL | const U_SELF: U = U::SELF_2; @@ -94,7 +94,7 @@ LL | const U_SELF: U = U::SELF_2; | | | consider requiring `U` to be `Copy` -error: a const item should never be interior mutable +error: a `const` item should never be interior mutable --> $DIR/non_copy_const.rs:87:5 | LL | const T_ASSOC: T::NonCopyType = T::ASSOC; @@ -102,7 +102,7 @@ LL | const T_ASSOC: T::NonCopyType = T::ASSOC; | | | consider requiring `>::NonCopyType` to be `Copy` -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:94:5 | LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability @@ -111,7 +111,7 @@ LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability = note: `#[deny(clippy::borrow_interior_mutable_const)]` on by default = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:95:16 | LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability @@ -119,7 +119,7 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutabi | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:98:22 | LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability @@ -127,7 +127,7 @@ LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:99:25 | LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability @@ -135,7 +135,7 @@ LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:100:27 | LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability @@ -143,7 +143,7 @@ LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:101:26 | LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability @@ -151,7 +151,7 @@ LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:112:14 | LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability @@ -159,7 +159,7 @@ LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:113:14 | LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability @@ -167,7 +167,7 @@ LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:114:19 | LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability @@ -175,7 +175,7 @@ LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:115:14 | LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability @@ -183,7 +183,7 @@ LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:116:13 | LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability @@ -191,7 +191,7 @@ LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mu | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:122:13 | LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability @@ -199,7 +199,7 @@ LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:127:5 | LL | CELL.set(2); //~ ERROR interior mutability @@ -207,7 +207,7 @@ LL | CELL.set(2); //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:128:16 | LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability @@ -215,7 +215,7 @@ LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:141:5 | LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability @@ -223,7 +223,7 @@ LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability | = help: assign this const to a local or static variable, and use the variable here -error: a const item with interior mutability should not be borrowed +error: a `const` item with interior mutability should not be borrowed --> $DIR/non_copy_const.rs:142:16 | LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr index 99e623131833..f588c8bfed4c 100644 --- a/tests/ui/ok_expect.stderr +++ b/tests/ui/ok_expect.stderr @@ -1,4 +1,4 @@ -error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` +error: called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result` --> $DIR/ok_expect.rs:14:5 | LL | res.ok().expect("disaster!"); @@ -6,25 +6,25 @@ LL | res.ok().expect("disaster!"); | = note: `-D clippy::ok-expect` implied by `-D warnings` -error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` +error: called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result` --> $DIR/ok_expect.rs:20:5 | LL | res3.ok().expect("whoof"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` +error: called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result` --> $DIR/ok_expect.rs:22:5 | LL | res4.ok().expect("argh"); | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` +error: called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result` --> $DIR/ok_expect.rs:24:5 | LL | res5.ok().expect("oops"); | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` +error: called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result` --> $DIR/ok_expect.rs:26:5 | LL | res6.ok().expect("meh"); diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index addb0c4e1a56..26fe9f6fb206 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -1,4 +1,4 @@ -error: file opened with "truncate" and "read" +error: file opened with `truncate` and `read` --> $DIR/open_options.rs:6:5 | LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); @@ -6,37 +6,37 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); | = note: `-D clippy::nonsensical-open-options` implied by `-D warnings` -error: file opened with "append" and "truncate" +error: file opened with `append` and `truncate` --> $DIR/open_options.rs:7:5 | LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: the method "read" is called more than once +error: the method `read` is called more than once --> $DIR/open_options.rs:9:5 | LL | OpenOptions::new().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: the method "create" is called more than once +error: the method `create` is called more than once --> $DIR/open_options.rs:10:5 | LL | OpenOptions::new().create(true).create(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: the method "write" is called more than once +error: the method `write` is called more than once --> $DIR/open_options.rs:11:5 | LL | OpenOptions::new().write(true).write(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: the method "append" is called more than once +error: the method `append` is called more than once --> $DIR/open_options.rs:12:5 | LL | OpenOptions::new().append(true).append(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: the method "truncate" is called more than once +error: the method `truncate` is called more than once --> $DIR/open_options.rs:13:5 | LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr index 857b33a4291d..6f707987dbca 100644 --- a/tests/ui/option_map_or_none.stderr +++ b/tests/ui/option_map_or_none.stderr @@ -1,12 +1,12 @@ -error: called `map_or(None, f)` on an Option value. This can be done more directly by calling `and_then(f)` instead +error: called `map_or(None, f)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead --> $DIR/option_map_or_none.rs:10:13 | LL | let _ = opt.map_or(None, |x| Some(x + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using and_then instead: `opt.and_then(|x| Some(x + 1))` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(|x| Some(x + 1))` | = note: `-D clippy::option-map-or-none` implied by `-D warnings` -error: called `map_or(None, f)` on an Option value. This can be done more directly by calling `and_then(f)` instead +error: called `map_or(None, f)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead --> $DIR/option_map_or_none.rs:13:13 | LL | let _ = opt.map_or(None, |x| { @@ -15,7 +15,7 @@ LL | | Some(x + 1) LL | | }); | |_________________________^ | -help: try using and_then instead +help: try using `and_then` instead | LL | let _ = opt.and_then(|x| { LL | Some(x + 1) diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr index 6e87b070909e..f993e1931d59 100644 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ b/tests/ui/option_map_unit_fn_fixable.stderr @@ -1,4 +1,4 @@ -error: called `map(f)` on an Option value where `f` is a unit function +error: called `map(f)` on an `Option` value where `f` is a unit function --> $DIR/option_map_unit_fn_fixable.rs:34:5 | LL | x.field.map(do_nothing); @@ -8,7 +8,7 @@ LL | x.field.map(do_nothing); | = note: `-D clippy::option-map-unit-fn` implied by `-D warnings` -error: called `map(f)` on an Option value where `f` is a unit function +error: called `map(f)` on an `Option` value where `f` is a unit function --> $DIR/option_map_unit_fn_fixable.rs:36:5 | LL | x.field.map(do_nothing); @@ -16,7 +16,7 @@ LL | x.field.map(do_nothing); | | | help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }` -error: called `map(f)` on an Option value where `f` is a unit function +error: called `map(f)` on an `Option` value where `f` is a unit function --> $DIR/option_map_unit_fn_fixable.rs:38:5 | LL | x.field.map(diverge); @@ -24,7 +24,7 @@ LL | x.field.map(diverge); | | | help: try this: `if let Some(x_field) = x.field { diverge(x_field) }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:44:5 | LL | x.field.map(|value| x.do_option_nothing(value + captured)); @@ -32,7 +32,7 @@ LL | x.field.map(|value| x.do_option_nothing(value + captured)); | | | help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:46:5 | LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); @@ -40,7 +40,7 @@ LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); | | | help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:49:5 | LL | x.field.map(|value| do_nothing(value + captured)); @@ -48,7 +48,7 @@ LL | x.field.map(|value| do_nothing(value + captured)); | | | help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:51:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); @@ -56,7 +56,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) }); | | | help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:53:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); @@ -64,7 +64,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); }); | | | help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:55:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); @@ -72,7 +72,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } }); | | | help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:58:5 | LL | x.field.map(|value| diverge(value + captured)); @@ -80,7 +80,7 @@ LL | x.field.map(|value| diverge(value + captured)); | | | help: try this: `if let Some(value) = x.field { diverge(value + captured) }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:60:5 | LL | x.field.map(|value| { diverge(value + captured) }); @@ -88,7 +88,7 @@ LL | x.field.map(|value| { diverge(value + captured) }); | | | help: try this: `if let Some(value) = x.field { diverge(value + captured) }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:62:5 | LL | x.field.map(|value| { diverge(value + captured); }); @@ -96,7 +96,7 @@ LL | x.field.map(|value| { diverge(value + captured); }); | | | help: try this: `if let Some(value) = x.field { diverge(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:64:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); @@ -104,7 +104,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } }); | | | help: try this: `if let Some(value) = x.field { diverge(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:69:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); @@ -112,7 +112,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); }); | | | help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:71:5 | LL | x.field.map(|value| { plus_one(value + captured); }); @@ -120,7 +120,7 @@ LL | x.field.map(|value| { plus_one(value + captured); }); | | | help: try this: `if let Some(value) = x.field { plus_one(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:73:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); @@ -128,7 +128,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } }); | | | help: try this: `if let Some(value) = x.field { plus_one(value + captured); }` -error: called `map(f)` on an Option value where `f` is a unit closure +error: called `map(f)` on an `Option` value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) });} diff --git a/tests/ui/option_map_unwrap_or.stderr b/tests/ui/option_map_unwrap_or.stderr index c336c0f63d2e..f05f2893de23 100644 --- a/tests/ui/option_map_unwrap_or.stderr +++ b/tests/ui/option_map_unwrap_or.stderr @@ -1,4 +1,4 @@ -error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead +error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead --> $DIR/option_map_unwrap_or.rs:20:13 | LL | let _ = opt.map(|x| x + 1) @@ -13,7 +13,7 @@ help: use `map_or(a, f)` instead LL | let _ = opt.map_or(0, |x| x + 1); | ^^^^^^ ^^ -- -error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead +error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead --> $DIR/option_map_unwrap_or.rs:24:13 | LL | let _ = opt.map(|x| { @@ -31,7 +31,7 @@ LL | } LL | ); | -error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead +error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead --> $DIR/option_map_unwrap_or.rs:28:13 | LL | let _ = opt.map(|x| x + 1) @@ -48,7 +48,7 @@ LL | 0 LL | }, |x| x + 1); | -error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead +error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead --> $DIR/option_map_unwrap_or.rs:33:13 | LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); @@ -59,7 +59,7 @@ help: use `and_then(f)` instead LL | let _ = opt.and_then(|x| Some(x + 1)); | ^^^^^^^^ -- -error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead +error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead --> $DIR/option_map_unwrap_or.rs:35:13 | LL | let _ = opt.map(|x| { @@ -77,7 +77,7 @@ LL | } LL | ); | -error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead +error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead --> $DIR/option_map_unwrap_or.rs:39:13 | LL | let _ = opt @@ -91,7 +91,7 @@ help: use `and_then(f)` instead LL | .and_then(|x| Some(x + 1)); | ^^^^^^^^ -- -error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead +error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead --> $DIR/option_map_unwrap_or.rs:50:13 | LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); @@ -102,7 +102,7 @@ help: use `map_or(a, f)` instead LL | let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); | ^^^^^^ ^^^ -- -error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead +error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead --> $DIR/option_map_unwrap_or.rs:54:13 | LL | let _ = opt.map(|x| x + 1) @@ -114,7 +114,7 @@ LL | | .unwrap_or_else(|| 0); = note: `-D clippy::option-map-unwrap-or-else` implied by `-D warnings` = note: replace `map(|x| x + 1).unwrap_or_else(|| 0)` with `map_or_else(|| 0, |x| x + 1)` -error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead +error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead --> $DIR/option_map_unwrap_or.rs:58:13 | LL | let _ = opt.map(|x| { @@ -124,7 +124,7 @@ LL | | } LL | | ).unwrap_or_else(|| 0); | |__________________________^ -error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead +error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead --> $DIR/option_map_unwrap_or.rs:62:13 | LL | let _ = opt.map(|x| x + 1) diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr index c8d4e557d87f..d53c1edecac0 100644 --- a/tests/ui/range.stderr +++ b/tests/ui/range.stderr @@ -1,4 +1,4 @@ -error: It is more idiomatic to use v1.iter().enumerate() +error: It is more idiomatic to use `v1.iter().enumerate()` --> $DIR/range.rs:5:14 | LL | let _x = v1.iter().zip(0..v1.len()); diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index e5e706e8483e..84931f66fa8d 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -18,11 +18,11 @@ fn main() { let _s = Path::new("/a/b/").join("c"); - let _s = Path::new("/a/b/").join("c").to_path_buf(); + let _s = Path::new("/a/b/").join("c"); let _s = OsString::new(); - let _s = OsString::new().to_os_string(); + let _s = OsString::new(); // Check that lint level works #[allow(clippy::redundant_clone)] diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index 62f4ce7645ed..0f185cda0197 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -59,6 +59,18 @@ note: this value is dropped without further use LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: redundant clone + --> $DIR/redundant_clone.rs:21:42 + | +LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); + | ^^^^^^^^^^^^^^ help: remove this + | +note: this value is dropped without further use + --> $DIR/redundant_clone.rs:21:14 + | +LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: redundant clone --> $DIR/redundant_clone.rs:23:29 | @@ -71,6 +83,18 @@ note: this value is dropped without further use LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ +error: redundant clone + --> $DIR/redundant_clone.rs:25:29 + | +LL | let _s = OsString::new().to_os_string(); + | ^^^^^^^^^^^^^^^ help: remove this + | +note: this value is dropped without further use + --> $DIR/redundant_clone.rs:25:14 + | +LL | let _s = OsString::new().to_os_string(); + | ^^^^^^^^^^^^^^^ + error: redundant clone --> $DIR/redundant_clone.rs:32:19 | @@ -131,5 +155,5 @@ note: this value is dropped without further use LL | let _f = f.clone(); | ^ -error: aborting due to 11 previous errors +error: aborting due to 13 previous errors diff --git a/tests/ui/result_map_unit_fn_fixable.stderr b/tests/ui/result_map_unit_fn_fixable.stderr index 5f9bf2020b6e..33be39e34f15 100644 --- a/tests/ui/result_map_unit_fn_fixable.stderr +++ b/tests/ui/result_map_unit_fn_fixable.stderr @@ -1,4 +1,4 @@ -error: called `map(f)` on an Result value where `f` is a unit function +error: called `map(f)` on an `Result` value where `f` is a unit function --> $DIR/result_map_unit_fn_fixable.rs:35:5 | LL | x.field.map(do_nothing); @@ -8,7 +8,7 @@ LL | x.field.map(do_nothing); | = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` -error: called `map(f)` on an Result value where `f` is a unit function +error: called `map(f)` on an `Result` value where `f` is a unit function --> $DIR/result_map_unit_fn_fixable.rs:37:5 | LL | x.field.map(do_nothing); @@ -16,7 +16,7 @@ LL | x.field.map(do_nothing); | | | help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }` -error: called `map(f)` on an Result value where `f` is a unit function +error: called `map(f)` on an `Result` value where `f` is a unit function --> $DIR/result_map_unit_fn_fixable.rs:39:5 | LL | x.field.map(diverge); @@ -24,7 +24,7 @@ LL | x.field.map(diverge); | | | help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:45:5 | LL | x.field.map(|value| x.do_result_nothing(value + captured)); @@ -32,7 +32,7 @@ LL | x.field.map(|value| x.do_result_nothing(value + captured)); | | | help: try this: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:47:5 | LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); @@ -40,7 +40,7 @@ LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); | | | help: try this: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:50:5 | LL | x.field.map(|value| do_nothing(value + captured)); @@ -48,7 +48,7 @@ LL | x.field.map(|value| do_nothing(value + captured)); | | | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:52:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); @@ -56,7 +56,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) }); | | | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:54:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); @@ -64,7 +64,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); }); | | | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:56:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); @@ -72,7 +72,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } }); | | | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:59:5 | LL | x.field.map(|value| diverge(value + captured)); @@ -80,7 +80,7 @@ LL | x.field.map(|value| diverge(value + captured)); | | | help: try this: `if let Ok(value) = x.field { diverge(value + captured) }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:61:5 | LL | x.field.map(|value| { diverge(value + captured) }); @@ -88,7 +88,7 @@ LL | x.field.map(|value| { diverge(value + captured) }); | | | help: try this: `if let Ok(value) = x.field { diverge(value + captured) }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:63:5 | LL | x.field.map(|value| { diverge(value + captured); }); @@ -96,7 +96,7 @@ LL | x.field.map(|value| { diverge(value + captured); }); | | | help: try this: `if let Ok(value) = x.field { diverge(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:65:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); @@ -104,7 +104,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } }); | | | help: try this: `if let Ok(value) = x.field { diverge(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:70:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); @@ -112,7 +112,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); }); | | | help: try this: `if let Ok(value) = x.field { let y = plus_one(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:72:5 | LL | x.field.map(|value| { plus_one(value + captured); }); @@ -120,7 +120,7 @@ LL | x.field.map(|value| { plus_one(value + captured); }); | | | help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:74:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); @@ -128,7 +128,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } }); | | | help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }` -error: called `map(f)` on an Result value where `f` is a unit closure +error: called `map(f)` on an `Result` value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:77:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); diff --git a/tests/ui/result_map_unwrap_or_else.stderr b/tests/ui/result_map_unwrap_or_else.stderr index 2b014e9ebb1a..ec7bc8f12414 100644 --- a/tests/ui/result_map_unwrap_or_else.stderr +++ b/tests/ui/result_map_unwrap_or_else.stderr @@ -1,4 +1,4 @@ -error: called `map(f).unwrap_or_else(g)` on a Result value. This can be done more directly by calling `.map_or_else(g, f)` instead +error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead --> $DIR/result_map_unwrap_or_else.rs:15:13 | LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); // should lint even though this call is on a separate line @@ -7,7 +7,7 @@ LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); // should lint even t = note: `-D clippy::result-map-unwrap-or-else` implied by `-D warnings` = note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)` -error: called `map(f).unwrap_or_else(g)` on a Result value. This can be done more directly by calling `.map_or_else(g, f)` instead +error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead --> $DIR/result_map_unwrap_or_else.rs:17:13 | LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); @@ -15,7 +15,7 @@ LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); | = note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)` -error: called `map(f).unwrap_or_else(g)` on a Result value. This can be done more directly by calling `.map_or_else(g, f)` instead +error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead --> $DIR/result_map_unwrap_or_else.rs:18:13 | LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); diff --git a/tests/ui/same_functions_in_if_condition.stderr b/tests/ui/same_functions_in_if_condition.stderr index 214f1a9e7c8f..363a03846d23 100644 --- a/tests/ui/same_functions_in_if_condition.stderr +++ b/tests/ui/same_functions_in_if_condition.stderr @@ -1,4 +1,4 @@ -error: this `if` has the same function call as a previous if +error: this `if` has the same function call as a previous `if` --> $DIR/same_functions_in_if_condition.rs:29:15 | LL | } else if function() { @@ -11,7 +11,7 @@ note: same as this LL | if function() { | ^^^^^^^^^^ -error: this `if` has the same function call as a previous if +error: this `if` has the same function call as a previous `if` --> $DIR/same_functions_in_if_condition.rs:34:15 | LL | } else if fn_arg(a) { @@ -23,7 +23,7 @@ note: same as this LL | if fn_arg(a) { | ^^^^^^^^^ -error: this `if` has the same function call as a previous if +error: this `if` has the same function call as a previous `if` --> $DIR/same_functions_in_if_condition.rs:39:15 | LL | } else if obj.method() { @@ -35,7 +35,7 @@ note: same as this LL | if obj.method() { | ^^^^^^^^^^^^ -error: this `if` has the same function call as a previous if +error: this `if` has the same function call as a previous `if` --> $DIR/same_functions_in_if_condition.rs:44:15 | LL | } else if obj.method_arg(a) { @@ -47,7 +47,7 @@ note: same as this LL | if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ -error: this `if` has the same function call as a previous if +error: this `if` has the same function call as a previous `if` --> $DIR/same_functions_in_if_condition.rs:51:15 | LL | } else if v.pop() == None { @@ -59,7 +59,7 @@ note: same as this LL | if v.pop() == None { | ^^^^^^^^^^^^^^^ -error: this `if` has the same function call as a previous if +error: this `if` has the same function call as a previous `if` --> $DIR/same_functions_in_if_condition.rs:56:15 | LL | } else if v.len() == 42 { diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index 464ed375976f..fe7211c53f85 100644 --- a/tests/ui/single_char_pattern.stderr +++ b/tests/ui/single_char_pattern.stderr @@ -2,7 +2,7 @@ error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:9:13 | LL | x.split("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` | = note: `-D clippy::single-char-pattern` implied by `-D warnings` @@ -10,157 +10,157 @@ error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:26:16 | LL | x.contains("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:27:19 | LL | x.starts_with("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:28:17 | LL | x.ends_with("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:29:12 | LL | x.find("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:30:13 | LL | x.rfind("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:31:14 | LL | x.rsplit("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:32:24 | LL | x.split_terminator("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:33:25 | LL | x.rsplit_terminator("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:34:17 | LL | x.splitn(0, "x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:35:18 | LL | x.rsplitn(0, "x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:36:15 | LL | x.matches("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:37:16 | LL | x.rmatches("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:38:21 | LL | x.match_indices("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:39:22 | LL | x.rmatch_indices("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:40:26 | LL | x.trim_start_matches("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:41:24 | LL | x.trim_end_matches("x"); - | ^^^ help: try using a char instead: `'x'` + | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:43:13 | LL | x.split("/n"); - | ^^^^ help: try using a char instead: `'/n'` + | ^^^^ help: try using a `char` instead: `'/n'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:44:13 | LL | x.split("'"); - | ^^^ help: try using a char instead: `'/''` + | ^^^ help: try using a `char` instead: `'/''` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:45:13 | LL | x.split("/'"); - | ^^^^ help: try using a char instead: `'/''` + | ^^^^ help: try using a `char` instead: `'/''` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:50:31 | LL | x.replace(";", ",").split(","); // issue #2978 - | ^^^ help: try using a char instead: `','` + | ^^^ help: try using a `char` instead: `','` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:51:19 | LL | x.starts_with("/x03"); // issue #2996 - | ^^^^^^ help: try using a char instead: `'/x03'` + | ^^^^^^ help: try using a `char` instead: `'/x03'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:58:13 | LL | x.split(r"a"); - | ^^^^ help: try using a char instead: `'a'` + | ^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:59:13 | LL | x.split(r#"a"#); - | ^^^^^^ help: try using a char instead: `'a'` + | ^^^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:60:13 | LL | x.split(r###"a"###); - | ^^^^^^^^^^ help: try using a char instead: `'a'` + | ^^^^^^^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:61:13 | LL | x.split(r###"'"###); - | ^^^^^^^^^^ help: try using a char instead: `'/''` + | ^^^^^^^^^^ help: try using a `char` instead: `'/''` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:62:13 | LL | x.split(r###"#"###); - | ^^^^^^^^^^ help: try using a char instead: `'#'` + | ^^^^^^^^^^ help: try using a `char` instead: `'#'` error: aborting due to 27 previous errors diff --git a/tests/ui/types.stderr b/tests/ui/types.stderr index daba766856df..59c3e05a1aa3 100644 --- a/tests/ui/types.stderr +++ b/tests/ui/types.stderr @@ -1,4 +1,4 @@ -error: casting i32 to i64 may become silently lossy if you later change the type +error: casting `i32` to `i64` may become silently lossy if you later change the type --> $DIR/types.rs:14:22 | LL | let c_i64: i64 = c as i64; diff --git a/tests/ui/unnecessary_cast_fixable.stderr b/tests/ui/unnecessary_cast_fixable.stderr index 74616bb90822..8ff1e5dea600 100644 --- a/tests/ui/unnecessary_cast_fixable.stderr +++ b/tests/ui/unnecessary_cast_fixable.stderr @@ -1,4 +1,4 @@ -error: casting integer literal to f32 is unnecessary +error: casting integer literal to `f32` is unnecessary --> $DIR/unnecessary_cast_fixable.rs:8:5 | LL | 100 as f32; @@ -6,13 +6,13 @@ LL | 100 as f32; | = note: `-D clippy::unnecessary-cast` implied by `-D warnings` -error: casting integer literal to f64 is unnecessary +error: casting integer literal to `f64` is unnecessary --> $DIR/unnecessary_cast_fixable.rs:9:5 | LL | 100 as f64; | ^^^^^^^^^^ help: try: `100_f64` -error: casting integer literal to f64 is unnecessary +error: casting integer literal to `f64` is unnecessary --> $DIR/unnecessary_cast_fixable.rs:10:5 | LL | 100_i32 as f64; diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index 7ed1df8d703e..69447e6826c1 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -18,7 +18,7 @@ error: using `clone` on a `Copy` type LL | rc.borrow().clone(); | ^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*rc.borrow()` -error: using '.clone()' on a ref-counted pointer +error: using `.clone()` on a ref-counted pointer --> $DIR/unnecessary_clone.rs:39:5 | LL | rc.clone(); @@ -26,25 +26,25 @@ LL | rc.clone(); | = note: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` -error: using '.clone()' on a ref-counted pointer +error: using `.clone()` on a ref-counted pointer --> $DIR/unnecessary_clone.rs:42:5 | LL | arc.clone(); | ^^^^^^^^^^^ help: try this: `Arc::::clone(&arc)` -error: using '.clone()' on a ref-counted pointer +error: using `.clone()` on a ref-counted pointer --> $DIR/unnecessary_clone.rs:45:5 | LL | rcweak.clone(); | ^^^^^^^^^^^^^^ help: try this: `Weak::::clone(&rcweak)` -error: using '.clone()' on a ref-counted pointer +error: using `.clone()` on a ref-counted pointer --> $DIR/unnecessary_clone.rs:48:5 | LL | arc_weak.clone(); | ^^^^^^^^^^^^^^^^ help: try this: `Weak::::clone(&arc_weak)` -error: using '.clone()' on a ref-counted pointer +error: using `.clone()` on a ref-counted pointer --> $DIR/unnecessary_clone.rs:52:33 | LL | let _: Arc = x.clone(); diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr index 1b1c62430b25..4f871cbe41b0 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -1,4 +1,4 @@ -error: removed "unsafe" from the name of `UnsafeCell` in use as `TotallySafeCell` +error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCell` --> $DIR/unsafe_removed_from_name.rs:5:1 | LL | use std::cell::UnsafeCell as TotallySafeCell; @@ -6,13 +6,13 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; | = note: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` -error: removed "unsafe" from the name of `UnsafeCell` in use as `TotallySafeCellAgain` +error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` --> $DIR/unsafe_removed_from_name.rs:7:1 | LL | use std::cell::UnsafeCell as TotallySafeCellAgain; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: removed "unsafe" from the name of `Unsafe` in use as `LieAboutModSafety` +error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` --> $DIR/unsafe_removed_from_name.rs:21:1 | LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index cde3ceffd9d3..6609a3ff72d4 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -1,4 +1,4 @@ -error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message +error: used `unwrap()` on `an Option` value. If you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message --> $DIR/unwrap.rs:5:13 | LL | let _ = opt.unwrap(); @@ -6,7 +6,7 @@ LL | let _ = opt.unwrap(); | = note: `-D clippy::option-unwrap-used` implied by `-D warnings` -error: used unwrap() on a Result value. If you don't want to handle the Err case gracefully, consider using expect() to provide a better panic message +error: used `unwrap()` on `a Result` value. If you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message --> $DIR/unwrap.rs:10:13 | LL | let _ = res.unwrap(); diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed new file mode 100644 index 000000000000..56811a998728 --- /dev/null +++ b/tests/ui/useless_attribute.fixed @@ -0,0 +1,57 @@ +// run-rustfix +// aux-build:proc_macro_derive.rs + +#![warn(clippy::useless_attribute)] +#![warn(unreachable_pub)] +#![feature(rustc_private)] + +#![allow(dead_code)] +#![cfg_attr(feature = "cargo-clippy", allow(dead_code))] +#[rustfmt::skip] +#[allow(unused_imports)] +#[allow(unused_extern_crates)] +#[macro_use] +extern crate rustc; + +#[macro_use] +extern crate proc_macro_derive; + +// don't lint on unused_import for `use` items +#[allow(unused_imports)] +use std::collections; + +// don't lint on deprecated for `use` items +mod foo { + #[deprecated] + pub struct Bar; +} +#[allow(deprecated)] +pub use foo::Bar; + +// This should not trigger the lint. There's lint level definitions inside the external derive +// that would trigger the useless_attribute lint. +#[derive(DeriveSomething)] +struct Baz; + +// don't lint on unreachable_pub for `use` items +mod a { + mod b { + #[allow(dead_code)] + #[allow(unreachable_pub)] + pub struct C {} + } + + #[allow(unreachable_pub)] + pub use self::b::C; +} + +fn test_indented_attr() { + #![allow(clippy::almost_swapped)] + use std::collections::HashSet; + + let _ = HashSet::::default(); +} + +fn main() { + test_indented_attr(); +} diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 529680a7588a..bbf5e495db4a 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -1,3 +1,4 @@ +// run-rustfix // aux-build:proc_macro_derive.rs #![warn(clippy::useless_attribute)] @@ -44,4 +45,13 @@ mod a { pub use self::b::C; } -fn main() {} +fn test_indented_attr() { + #[allow(clippy::almost_swapped)] + use std::collections::HashSet; + + let _ = HashSet::::default(); +} + +fn main() { + test_indented_attr(); +} diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr index 87a1291543e1..08a211b41a91 100644 --- a/tests/ui/useless_attribute.stderr +++ b/tests/ui/useless_attribute.stderr @@ -1,5 +1,5 @@ error: useless lint attribute - --> $DIR/useless_attribute.rs:7:1 + --> $DIR/useless_attribute.rs:8:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]` @@ -7,10 +7,16 @@ LL | #[allow(dead_code)] = note: `-D clippy::useless-attribute` implied by `-D warnings` error: useless lint attribute - --> $DIR/useless_attribute.rs:8:1 + --> $DIR/useless_attribute.rs:9:1 | LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)` -error: aborting due to 2 previous errors +error: useless lint attribute + --> $DIR/useless_attribute.rs:49:5 + | +LL | #[allow(clippy::almost_swapped)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(clippy::almost_swapped)]` + +error: aborting due to 3 previous errors diff --git a/tests/ui/wild_in_or_pats.rs b/tests/ui/wild_in_or_pats.rs new file mode 100644 index 000000000000..ad600f125772 --- /dev/null +++ b/tests/ui/wild_in_or_pats.rs @@ -0,0 +1,36 @@ +#![warn(clippy::wildcard_in_or_patterns)] + +fn main() { + match "foo" { + "a" => { + dbg!("matched a"); + }, + "bar" | _ => { + dbg!("matched (bar or) wild"); + }, + }; + match "foo" { + "a" => { + dbg!("matched a"); + }, + "bar" | "bar2" | _ => { + dbg!("matched (bar or bar2 or) wild"); + }, + }; + match "foo" { + "a" => { + dbg!("matched a"); + }, + _ | "bar" | _ => { + dbg!("matched (bar or) wild"); + }, + }; + match "foo" { + "a" => { + dbg!("matched a"); + }, + _ | "bar" => { + dbg!("matched (bar or) wild"); + }, + }; +} diff --git a/tests/ui/wild_in_or_pats.stderr b/tests/ui/wild_in_or_pats.stderr new file mode 100644 index 000000000000..33c34cbbd408 --- /dev/null +++ b/tests/ui/wild_in_or_pats.stderr @@ -0,0 +1,35 @@ +error: wildcard pattern covers any other pattern as it will match anyway. + --> $DIR/wild_in_or_pats.rs:8:9 + | +LL | "bar" | _ => { + | ^^^^^^^^^ + | + = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` + = help: Consider handling `_` separately. + +error: wildcard pattern covers any other pattern as it will match anyway. + --> $DIR/wild_in_or_pats.rs:16:9 + | +LL | "bar" | "bar2" | _ => { + | ^^^^^^^^^^^^^^^^^^ + | + = help: Consider handling `_` separately. + +error: wildcard pattern covers any other pattern as it will match anyway. + --> $DIR/wild_in_or_pats.rs:24:9 + | +LL | _ | "bar" | _ => { + | ^^^^^^^^^^^^^ + | + = help: Consider handling `_` separately. + +error: wildcard pattern covers any other pattern as it will match anyway. + --> $DIR/wild_in_or_pats.rs:32:9 + | +LL | _ | "bar" => { + | ^^^^^^^^^ + | + = help: Consider handling `_` separately. + +error: aborting due to 4 previous errors + diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index 1da2833e2605..2aa24ea1156a 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -1,7 +1,13 @@ // run-rustfix #![deny(clippy::wildcard_enum_match_arm)] -#![allow(unreachable_code, unused_variables, dead_code, clippy::single_match)] +#![allow( + unreachable_code, + unused_variables, + dead_code, + clippy::single_match, + clippy::wildcard_in_or_patterns +)] use std::io::ErrorKind; diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index c2eb4b308024..07c93feaf284 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -1,7 +1,13 @@ // run-rustfix #![deny(clippy::wildcard_enum_match_arm)] -#![allow(unreachable_code, unused_variables, dead_code, clippy::single_match)] +#![allow( + unreachable_code, + unused_variables, + dead_code, + clippy::single_match, + clippy::wildcard_in_or_patterns +)] use std::io::ErrorKind; diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index 735f610b7e5d..e6f0411095ca 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -1,5 +1,5 @@ error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:31:9 + --> $DIR/wildcard_enum_match_arm.rs:37:9 | LL | _ => eprintln!("Not red"), | ^ help: try this: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` @@ -11,25 +11,25 @@ LL | #![deny(clippy::wildcard_enum_match_arm)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:35:9 + --> $DIR/wildcard_enum_match_arm.rs:41:9 | LL | _not_red => eprintln!("Not red"), | ^^^^^^^^ help: try this: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan` error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:39:9 + --> $DIR/wildcard_enum_match_arm.rs:45:9 | LL | not_red => format!("{:?}", not_red), | ^^^^^^^ help: try this: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan` error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:55:9 + --> $DIR/wildcard_enum_match_arm.rs:61:9 | LL | _ => "No red", | ^ help: try this: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` error: match on non-exhaustive enum doesn't explicitly match all known variants - --> $DIR/wildcard_enum_match_arm.rs:72:9 + --> $DIR/wildcard_enum_match_arm.rs:78:9 | LL | _ => {}, | ^ help: try this: `std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::ConnectionRefused | std::io::ErrorKind::ConnectionReset | std::io::ErrorKind::ConnectionAborted | std::io::ErrorKind::NotConnected | std::io::ErrorKind::AddrInUse | std::io::ErrorKind::AddrNotAvailable | std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::AlreadyExists | std::io::ErrorKind::WouldBlock | std::io::ErrorKind::InvalidInput | std::io::ErrorKind::InvalidData | std::io::ErrorKind::TimedOut | std::io::ErrorKind::WriteZero | std::io::ErrorKind::Interrupted | std::io::ErrorKind::Other | std::io::ErrorKind::UnexpectedEof | _` diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index c599da8baf9b..e4d6f168038b 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -6,7 +6,7 @@ LL | let nan = 0.0 / 0.0; | = note: `#[deny(clippy::eq_op)]` on by default -error: constant division of 0.0 with 0.0 will always result in NaN +error: constant division of `0.0` with `0.0` will always result in NaN --> $DIR/zero_div_zero.rs:4:15 | LL | let nan = 0.0 / 0.0; @@ -21,7 +21,7 @@ error: equal expressions as operands to `/` LL | let f64_nan = 0.0 / 0.0f64; | ^^^^^^^^^^^^ -error: constant division of 0.0 with 0.0 will always result in NaN +error: constant division of `0.0` with `0.0` will always result in NaN --> $DIR/zero_div_zero.rs:5:19 | LL | let f64_nan = 0.0 / 0.0f64; @@ -35,7 +35,7 @@ error: equal expressions as operands to `/` LL | let other_f64_nan = 0.0f64 / 0.0; | ^^^^^^^^^^^^ -error: constant division of 0.0 with 0.0 will always result in NaN +error: constant division of `0.0` with `0.0` will always result in NaN --> $DIR/zero_div_zero.rs:6:25 | LL | let other_f64_nan = 0.0f64 / 0.0; @@ -49,7 +49,7 @@ error: equal expressions as operands to `/` LL | let one_more_f64_nan = 0.0f64 / 0.0f64; | ^^^^^^^^^^^^^^^ -error: constant division of 0.0 with 0.0 will always result in NaN +error: constant division of `0.0` with `0.0` will always result in NaN --> $DIR/zero_div_zero.rs:7:28 | LL | let one_more_f64_nan = 0.0f64 / 0.0f64;