Merge commit '1e5237f4a5' into clippy-subtree-update

This commit is contained in:
Philipp Krones 2025-03-20 22:34:29 +01:00
commit ae31f7a024
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
216 changed files with 4613 additions and 1146 deletions

View file

@ -16,7 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
use ui_test::custom_flags::Flag;
use ui_test::custom_flags::rustfix::RustfixMode;
use ui_test::spanned::Spanned;
use ui_test::{Args, CommandBuilder, Config, Match, OutputConflictHandling, status_emitter};
use ui_test::{Args, CommandBuilder, Config, Match, error_on_output_conflict, status_emitter};
use std::collections::{BTreeMap, HashMap};
use std::env::{self, set_var, var_os};
@ -142,7 +142,7 @@ impl TestContext {
fn base_config(&self, test_dir: &str, mandatory_annotations: bool) -> Config {
let target_dir = PathBuf::from(var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into()));
let mut config = Config {
output_conflict_handling: OutputConflictHandling::Error,
output_conflict_handling: error_on_output_conflict,
filter_files: env::var("TESTNAME")
.map(|filters| filters.split(',').map(str::to_string).collect())
.unwrap_or_default(),
@ -220,7 +220,7 @@ fn run_internal_tests(cx: &TestContext) {
if !RUN_INTERNAL_TESTS {
return;
}
let mut config = cx.base_config("ui-internal", false);
let mut config = cx.base_config("ui-internal", true);
config.bless_command = Some("cargo uitest --features internal -- -- --bless".into());
ui_test::run_tests_generic(

View file

@ -44,6 +44,7 @@ impl Message {
".*AT&T x86 assembly syntax used",
"note: Clippy version: .*",
"the compiler unexpectedly panicked. this is a bug.",
"internal compiler error:",
])
.unwrap()
});

View file

@ -38,6 +38,7 @@ declare_tool_lint! {
// Invalid attributes
///////////////////////
declare_tool_lint! {
//~^ invalid_clippy_version_attribute
#[clippy::version = "1.2.3.4.5.6"]
pub clippy::INVALID_ONE,
Warn,
@ -46,6 +47,7 @@ declare_tool_lint! {
}
declare_tool_lint! {
//~^ invalid_clippy_version_attribute
#[clippy::version = "I'm a string"]
pub clippy::INVALID_TWO,
Warn,
@ -57,6 +59,7 @@ declare_tool_lint! {
// Missing attribute test
///////////////////////
declare_tool_lint! {
//~^ missing_clippy_version_attribute
#[clippy::version]
pub clippy::MISSING_ATTRIBUTE_ONE,
Warn,
@ -65,6 +68,7 @@ declare_tool_lint! {
}
declare_tool_lint! {
//~^ missing_clippy_version_attribute
pub clippy::MISSING_ATTRIBUTE_TWO,
Warn,
"Two",

View file

@ -2,10 +2,10 @@ error: this item has an invalid `clippy::version` attribute
--> tests/ui-internal/check_clippy_version_attribute.rs:40:1
|
LL | / declare_tool_lint! {
LL | |
LL | | #[clippy::version = "1.2.3.4.5.6"]
LL | | pub clippy::INVALID_ONE,
LL | | Warn,
LL | | "One",
... |
LL | | report_in_external_macro: true
LL | | }
| |_^
@ -20,13 +20,13 @@ LL | #![deny(clippy::internal)]
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this item has an invalid `clippy::version` attribute
--> tests/ui-internal/check_clippy_version_attribute.rs:48:1
--> tests/ui-internal/check_clippy_version_attribute.rs:49:1
|
LL | / declare_tool_lint! {
LL | |
LL | | #[clippy::version = "I'm a string"]
LL | | pub clippy::INVALID_TWO,
LL | | Warn,
LL | | "Two",
... |
LL | | report_in_external_macro: true
LL | | }
| |_^
@ -35,13 +35,13 @@ LL | | }
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this lint is missing the `clippy::version` attribute or version value
--> tests/ui-internal/check_clippy_version_attribute.rs:59:1
--> tests/ui-internal/check_clippy_version_attribute.rs:61:1
|
LL | / declare_tool_lint! {
LL | |
LL | | #[clippy::version]
LL | | pub clippy::MISSING_ATTRIBUTE_ONE,
LL | | Warn,
LL | | "Two",
... |
LL | | report_in_external_macro: true
LL | | }
| |_^
@ -51,9 +51,10 @@ LL | | }
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this lint is missing the `clippy::version` attribute or version value
--> tests/ui-internal/check_clippy_version_attribute.rs:67:1
--> tests/ui-internal/check_clippy_version_attribute.rs:70:1
|
LL | / declare_tool_lint! {
LL | |
LL | | pub clippy::MISSING_ATTRIBUTE_TWO,
LL | | Warn,
LL | | "Two",

View file

@ -21,6 +21,7 @@ declare_tool_lint! {
declare_tool_lint! {
/// # What it does
/// Check for lint formulations that are correct
//~^ almost_standard_lint_formulation
#[clippy::version = "pre 1.29.0"]
pub clippy::INVALID1,
Warn,
@ -31,6 +32,7 @@ declare_tool_lint! {
declare_tool_lint! {
/// # What it does
/// Detects uses of incorrect formulations
//~^ almost_standard_lint_formulation
#[clippy::version = "pre 1.29.0"]
pub clippy::INVALID2,
Warn,

View file

@ -9,7 +9,7 @@ LL | /// Check for lint formulations that are correct
= help: to override `-D warnings` add `#[allow(clippy::almost_standard_lint_formulation)]`
error: non-standard lint formulation
--> tests/ui-internal/check_formulation.rs:33:5
--> tests/ui-internal/check_formulation.rs:34:5
|
LL | /// Detects uses of incorrect formulations
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -33,18 +33,23 @@ impl EarlyLintPass for Pass {
let predicate = true;
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
//~^ collapsible_span_lint_calls
db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
});
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
//~^ collapsible_span_lint_calls
db.span_help(expr.span, help_msg);
});
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
//~^ collapsible_span_lint_calls
db.help(help_msg);
});
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
//~^ collapsible_span_lint_calls
db.span_note(expr.span, note_msg);
});
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
//~^ collapsible_span_lint_calls
db.note(note_msg);
});

View file

@ -2,6 +2,7 @@ error: this call is collapsible
--> tests/ui-internal/collapsible_span_lint_calls.rs:35:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | |
LL | | db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
LL | | });
| |__________^ help: collapse into: `span_lint_and_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable)`
@ -14,33 +15,37 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::collapsible_span_lint_calls)]` implied by `#[deny(clippy::internal)]`
error: this call is collapsible
--> tests/ui-internal/collapsible_span_lint_calls.rs:38:9
--> tests/ui-internal/collapsible_span_lint_calls.rs:39:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | |
LL | | db.span_help(expr.span, help_msg);
LL | | });
| |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg)`
error: this call is collapsible
--> tests/ui-internal/collapsible_span_lint_calls.rs:41:9
--> tests/ui-internal/collapsible_span_lint_calls.rs:43:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | |
LL | | db.help(help_msg);
LL | | });
| |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg)`
error: this call is collapsible
--> tests/ui-internal/collapsible_span_lint_calls.rs:44:9
--> tests/ui-internal/collapsible_span_lint_calls.rs:47:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | |
LL | | db.span_note(expr.span, note_msg);
LL | | });
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg)`
error: this call is collapsible
--> tests/ui-internal/collapsible_span_lint_calls.rs:47:9
--> tests/ui-internal/collapsible_span_lint_calls.rs:51:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | |
LL | | db.note(note_msg);
LL | | });
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg)`

View file

@ -10,5 +10,6 @@
#![allow(clippy::missing_clippy_version_attribute)]
fn it_looks_like_you_are_trying_to_kill_clippy() {}
//~^ ice: Would you like some help with that?
fn main() {}

View file

@ -1,9 +1,18 @@
note: no errors encountered even though delayed bugs were created
thread '<unnamed>' panicked at clippy_lints/src/utils/internal_lints/produce_ice.rs:
Would you like some help with that?
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: those delayed bugs will now be shown as internal compiler errors
error: the compiler unexpectedly panicked. this is a bug.
error: internal compiler error: Would you like some help with that?
--> tests/ui-internal/custom_ice_message.rs:12:1
|
LL | fn it_looks_like_you_are_trying_to_kill_clippy() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: delayed at clippy_lints/src/utils/internal_lints/produce_ice.rs - disabled backtrace
--> tests/ui-internal/custom_ice_message.rs:12:1
|
LL | fn it_looks_like_you_are_trying_to_kill_clippy() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml
@ -13,9 +22,5 @@ note: rustc <version> running on <target>
note: compiler flags: -Z ui-testing -Z deduplicate-diagnostics=no
query stack during panic:
#0 [early_lint_checks] perform lints prior to AST lowering
#1 [hir_crate] getting the crate HIR
... and 3 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
note: Clippy version: foo

View file

@ -16,6 +16,7 @@ declare_tool_lint! {
}
declare_tool_lint! {
//~^ default_lint
pub clippy::TEST_LINT_DEFAULT,
Warn,
"default lint description",

View file

@ -2,6 +2,7 @@ error: the lint `TEST_LINT_DEFAULT` has the default lint description
--> tests/ui-internal/default_lint.rs:18:1
|
LL | / declare_tool_lint! {
LL | |
LL | | pub clippy::TEST_LINT_DEFAULT,
LL | | Warn,
LL | | "default lint description",

View file

@ -12,12 +12,14 @@ use rustc_middle::ty::TyCtxt;
pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) {
cx.span_lint(lint, span, |lint| {
//~^ disallowed_methods
lint.primary_message(msg);
});
}
pub fn b(tcx: TyCtxt<'_>, lint: &'static Lint, hir_id: HirId, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) {
tcx.node_span_lint(lint, hir_id, span, |lint| {
//~^ disallowed_methods
lint.primary_message(msg);
});
}

View file

@ -9,7 +9,7 @@ LL | cx.span_lint(lint, span, |lint| {
= help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]`
error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::node_span_lint`
--> tests/ui-internal/disallow_span_lint.rs:20:9
--> tests/ui-internal/disallow_span_lint.rs:21:9
|
LL | tcx.node_span_lint(lint, hir_id, span, |lint| {
| ^^^^^^^^^^^^^^

View file

@ -15,15 +15,19 @@ macro_rules! sym {
fn main() {
// Direct use of Symbol::intern
let _ = rustc_span::sym::f32;
//~^ interning_defined_symbol
// Using a sym macro
let _ = rustc_span::sym::f32;
//~^ interning_defined_symbol
// Correct suggestion when symbol isn't stringified constant name
let _ = rustc_span::sym::proc_dash_macro;
//~^ interning_defined_symbol
// interning a keyword
let _ = rustc_span::kw::SelfLower;
//~^ interning_defined_symbol
// Interning a symbol that is not defined
let _ = Symbol::intern("xyz123");

View file

@ -15,15 +15,19 @@ macro_rules! sym {
fn main() {
// Direct use of Symbol::intern
let _ = Symbol::intern("f32");
//~^ interning_defined_symbol
// Using a sym macro
let _ = sym!(f32);
//~^ interning_defined_symbol
// Correct suggestion when symbol isn't stringified constant name
let _ = Symbol::intern("proc-macro");
//~^ interning_defined_symbol
// interning a keyword
let _ = Symbol::intern("self");
//~^ interning_defined_symbol
// Interning a symbol that is not defined
let _ = Symbol::intern("xyz123");

View file

@ -12,19 +12,19 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::interning_defined_symbol)]` implied by `#[deny(clippy::internal)]`
error: interning a defined symbol
--> tests/ui-internal/interning_defined_symbol.rs:20:13
--> tests/ui-internal/interning_defined_symbol.rs:21:13
|
LL | let _ = sym!(f32);
| ^^^^^^^^^ help: try: `rustc_span::sym::f32`
error: interning a defined symbol
--> tests/ui-internal/interning_defined_symbol.rs:23:13
--> tests/ui-internal/interning_defined_symbol.rs:25:13
|
LL | let _ = Symbol::intern("proc-macro");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::proc_dash_macro`
error: interning a defined symbol
--> tests/ui-internal/interning_defined_symbol.rs:26:13
--> tests/ui-internal/interning_defined_symbol.rs:29:13
|
LL | let _ = Symbol::intern("self");
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::kw::SelfLower`

View file

@ -27,6 +27,7 @@ impl_lint_pass!(Pass => [TEST_LINT]);
impl EarlyLintPass for Pass {
extract_msrv_attr!();
//~^ missing_msrv_attr_impl
fn check_expr(&mut self, _: &EarlyContext<'_>, _: &rustc_ast::Expr) {}
}

View file

@ -26,6 +26,7 @@ struct Pass {
impl_lint_pass!(Pass => [TEST_LINT]);
impl EarlyLintPass for Pass {
//~^ missing_msrv_attr_impl
fn check_expr(&mut self, _: &EarlyContext<'_>, _: &rustc_ast::Expr) {}
}

View file

@ -13,12 +13,15 @@ mod paths {
// Path with empty segment
pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute"];
//~^ invalid_paths
// Path with bad crate
pub const BAD_CRATE_PATH: [&str; 2] = ["bad", "path"];
//~^ invalid_paths
// Path with bad module
pub const BAD_MOD_PATH: [&str; 2] = ["std", "xxx"];
//~^ invalid_paths
// Path to method on an enum inherent impl
pub const OPTION_IS_SOME: [&str; 4] = ["core", "option", "Option", "is_some"];

View file

@ -8,13 +8,13 @@ LL | pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute"
= help: to override `-D warnings` add `#[allow(clippy::invalid_paths)]`
error: invalid path
--> tests/ui-internal/invalid_paths.rs:18:5
--> tests/ui-internal/invalid_paths.rs:19:5
|
LL | pub const BAD_CRATE_PATH: [&str; 2] = ["bad", "path"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: invalid path
--> tests/ui-internal/invalid_paths.rs:21:5
--> tests/ui-internal/invalid_paths.rs:23:5
|
LL | pub const BAD_MOD_PATH: [&str; 2] = ["std", "xxx"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -10,6 +10,7 @@ extern crate rustc_lint;
use rustc_lint::{LintPass, LintVec};
declare_tool_lint! {
//~^ lint_without_lint_pass
pub clippy::TEST_LINT,
Warn,
"",

View file

@ -2,6 +2,7 @@ error: the lint `TEST_LINT` is not added to any `LintPass`
--> tests/ui-internal/lint_without_lint_pass.rs:12:1
|
LL | / declare_tool_lint! {
LL | |
LL | | pub clippy::TEST_LINT,
LL | | Warn,
LL | | "",

View file

@ -21,6 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT]);
impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_expr(&mut self, _cx: &LateContext<'tcx>, expr: &'tcx Expr) {
let _ = expr.span.ctxt().outer_expn_data();
//~^ outer_expn_expn_data
}
}

View file

@ -21,6 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT]);
impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_expr(&mut self, _cx: &LateContext<'tcx>, expr: &'tcx Expr) {
let _ = expr.span.ctxt().outer_expn().expn_data();
//~^ outer_expn_expn_data
}
}

View file

@ -35,28 +35,43 @@ const RESULT: &[&str] = &["core", "result", "Result"];
fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
let _ = is_type_diagnostic_item(cx, ty, sym::Option);
//~^ unnecessary_def_path
let _ = is_type_diagnostic_item(cx, ty, sym::Result);
//~^ unnecessary_def_path
let _ = is_type_diagnostic_item(cx, ty, sym::Result);
//~^ unnecessary_def_path
#[allow(unused, clippy::unnecessary_def_path)]
let rc_path = &["alloc", "rc", "Rc"];
let _ = is_type_diagnostic_item(cx, ty, sym::Rc);
//~^ unnecessary_def_path
let _ = is_type_diagnostic_item(cx, ty, sym::Option);
//~^ unnecessary_def_path
let _ = is_type_diagnostic_item(cx, ty, sym::Result);
//~^ unnecessary_def_path
let _ = is_type_lang_item(cx, ty, LangItem::OwnedBox);
//~^ unnecessary_def_path
let _ = is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit);
//~^ unnecessary_def_path
let _ = cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did);
//~^ unnecessary_def_path
let _ = cx.tcx.is_diagnostic_item(sym::Option, did);
//~^ unnecessary_def_path
let _ = cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did);
//~^ unnecessary_def_path
let _ = is_trait_method(cx, expr, sym::AsRef);
//~^ unnecessary_def_path
let _ = is_path_diagnostic_item(cx, expr, sym::Option);
//~^ unnecessary_def_path
let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id));
//~^ unnecessary_def_path
let _ = is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome);
//~^ unnecessary_def_path
}
fn main() {}

View file

@ -35,28 +35,43 @@ const RESULT: &[&str] = &["core", "result", "Result"];
fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
let _ = match_type(cx, ty, &OPTION);
//~^ unnecessary_def_path
let _ = match_type(cx, ty, RESULT);
//~^ unnecessary_def_path
let _ = match_type(cx, ty, &["core", "result", "Result"]);
//~^ unnecessary_def_path
#[allow(unused, clippy::unnecessary_def_path)]
let rc_path = &["alloc", "rc", "Rc"];
let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
//~^ unnecessary_def_path
let _ = match_type(cx, ty, &paths::OPTION);
//~^ unnecessary_def_path
let _ = match_type(cx, ty, paths::RESULT);
//~^ unnecessary_def_path
let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]);
//~^ unnecessary_def_path
let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]);
//~^ unnecessary_def_path
let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
//~^ unnecessary_def_path
let _ = match_def_path(cx, did, &["core", "option", "Option"]);
//~^ unnecessary_def_path
let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
//~^ unnecessary_def_path
let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]);
//~^ unnecessary_def_path
let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]);
//~^ unnecessary_def_path
let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
//~^ unnecessary_def_path
let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]);
//~^ unnecessary_def_path
}
fn main() {}

View file

@ -12,61 +12,61 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::unnecessary_def_path)]` implied by `#[deny(clippy::internal)]`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:38:13
--> tests/ui-internal/unnecessary_def_path.rs:39:13
|
LL | let _ = match_type(cx, ty, RESULT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:39:13
--> tests/ui-internal/unnecessary_def_path.rs:41:13
|
LL | let _ = match_type(cx, ty, &["core", "result", "Result"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:43:13
--> tests/ui-internal/unnecessary_def_path.rs:46:13
|
LL | let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Rc)`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:45:13
--> tests/ui-internal/unnecessary_def_path.rs:49:13
|
LL | let _ = match_type(cx, ty, &paths::OPTION);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:46:13
--> tests/ui-internal/unnecessary_def_path.rs:51:13
|
LL | let _ = match_type(cx, ty, paths::RESULT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
error: use of a def path to a `LangItem`
--> tests/ui-internal/unnecessary_def_path.rs:48:13
--> tests/ui-internal/unnecessary_def_path.rs:54:13
|
LL | let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_lang_item(cx, ty, LangItem::OwnedBox)`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:49:13
--> tests/ui-internal/unnecessary_def_path.rs:56:13
|
LL | let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit)`
error: use of a def path to a `LangItem`
--> tests/ui-internal/unnecessary_def_path.rs:51:13
--> tests/ui-internal/unnecessary_def_path.rs:59:13
|
LL | let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did)`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:52:13
--> tests/ui-internal/unnecessary_def_path.rs:61:13
|
LL | let _ = match_def_path(cx, did, &["core", "option", "Option"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.is_diagnostic_item(sym::Option, did)`
error: use of a def path to a `LangItem`
--> tests/ui-internal/unnecessary_def_path.rs:53:13
--> tests/ui-internal/unnecessary_def_path.rs:63:13
|
LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did)`
@ -74,25 +74,25 @@ LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
= help: if this `DefId` came from a constructor expression or pattern then the parent `DefId` should be used instead
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:55:13
--> tests/ui-internal/unnecessary_def_path.rs:66:13
|
LL | let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_trait_method(cx, expr, sym::AsRef)`
error: use of a def path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path.rs:57:13
--> tests/ui-internal/unnecessary_def_path.rs:69:13
|
LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_path_diagnostic_item(cx, expr, sym::Option)`
error: use of a def path to a `LangItem`
--> tests/ui-internal/unnecessary_def_path.rs:58:13
--> tests/ui-internal/unnecessary_def_path.rs:71:13
|
LL | let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id))`
error: use of a def path to a `LangItem`
--> tests/ui-internal/unnecessary_def_path.rs:59:13
--> tests/ui-internal/unnecessary_def_path.rs:73:13
|
LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome)`

View file

@ -8,8 +8,11 @@ use rustc_hir::LangItem;
fn main() {
const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
//~^ unnecessary_def_path
const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
//~^ unnecessary_def_path
const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
//~^ unnecessary_def_path
// Don't lint, not a diagnostic or language item
const OPS_MOD: [&str; 2] = ["core", "ops"];

View file

@ -9,7 +9,7 @@ LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_def_path)]`
error: hardcoded path to a language item
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:11:40
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:12:40
|
LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -17,7 +17,7 @@ LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"]
= help: convert all references to use `LangItem::DerefMut`
error: hardcoded path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:12:43
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:14:43
|
LL | const OPS_MOD: [&str; 5] = ["core", "ops"];
| ^^^^^^^^^^^^^^^

View file

@ -14,8 +14,13 @@ use rustc_span::symbol::{Ident, Symbol};
fn main() {
Symbol::intern("foo") == rustc_span::sym::clippy;
//~^ unnecessary_symbol_str
Symbol::intern("foo") == rustc_span::kw::SelfLower;
//~^ unnecessary_symbol_str
Symbol::intern("foo") != rustc_span::kw::SelfUpper;
//~^ unnecessary_symbol_str
Ident::empty().name == rustc_span::sym::clippy;
//~^ unnecessary_symbol_str
rustc_span::sym::clippy == Ident::empty().name;
//~^ unnecessary_symbol_str
}

View file

@ -14,8 +14,13 @@ use rustc_span::symbol::{Ident, Symbol};
fn main() {
Symbol::intern("foo").as_str() == "clippy";
//~^ unnecessary_symbol_str
Symbol::intern("foo").to_string() == "self";
//~^ unnecessary_symbol_str
Symbol::intern("foo").to_ident_string() != "Self";
//~^ unnecessary_symbol_str
&*Ident::empty().as_str() == "clippy";
//~^ unnecessary_symbol_str
"clippy" == Ident::empty().to_string();
//~^ unnecessary_symbol_str
}

View file

@ -12,25 +12,25 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::unnecessary_symbol_str)]` implied by `#[deny(clippy::internal)]`
error: unnecessary `Symbol` to string conversion
--> tests/ui-internal/unnecessary_symbol_str.rs:17:5
--> tests/ui-internal/unnecessary_symbol_str.rs:18:5
|
LL | Symbol::intern("foo").to_string() == "self";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::kw::SelfLower`
error: unnecessary `Symbol` to string conversion
--> tests/ui-internal/unnecessary_symbol_str.rs:18:5
--> tests/ui-internal/unnecessary_symbol_str.rs:20:5
|
LL | Symbol::intern("foo").to_ident_string() != "Self";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") != rustc_span::kw::SelfUpper`
error: unnecessary `Symbol` to string conversion
--> tests/ui-internal/unnecessary_symbol_str.rs:19:5
--> tests/ui-internal/unnecessary_symbol_str.rs:22:5
|
LL | &*Ident::empty().as_str() == "clippy";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy`
error: unnecessary `Symbol` to string conversion
--> tests/ui-internal/unnecessary_symbol_str.rs:20:5
--> tests/ui-internal/unnecessary_symbol_str.rs:24:5
|
LL | "clippy" == Ident::empty().to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name`

View file

@ -0,0 +1 @@
module-items-ordered-within-groupings = true

View file

@ -0,0 +1 @@
module-items-ordered-within-groupings = ["madules"]

View file

@ -0,0 +1 @@
module-items-ordered-within-groupings = ["entirely garbled"]

View file

@ -9,4 +9,4 @@ module-item-order-groupings = [
["PascalCase", ["ty_alias", "enum", "struct", "union", "trait", "trait_alias", "impl"]],
["lower_snake_case", ["fn"]]
]
module-items-ordered-within-groupings = "none"

View file

@ -0,0 +1 @@
module-items-ordered-within-groupings = ["PascalCase"]

View file

@ -0,0 +1,2 @@
source-item-ordering = ["module"]
module-items-ordered-within-groupings = ["PascalCase"]

View file

@ -0,0 +1 @@
module-items-ordered-within-groupings = "all"

View file

@ -0,0 +1,8 @@
error: error reading Clippy's configuration file: data did not match any variant of untagged enum StringOrVecOfString The available options for configuring an ordering within module item groups are: "all", "none", or a list of module item group names (as configured with the `module-item-order-groupings` configuration option).
--> $DIR/tests/ui-toml/arbitrary_source_item_ordering/bad_conf_4/clippy.toml:1:41
|
LL | module-items-ordered-within-groupings = true
| ^^^^
error: aborting due to 1 previous error

View file

@ -0,0 +1,4 @@
error: error reading Clippy's configuration file: unknown ordering group: `madules` was not specified in `module-items-ordered-within-groupings`, perhaps you meant `modules`? expected one of: `modules`, `use`, `macros`, `global_asm`, `UPPER_SNAKE_CASE`, `PascalCase`, `lower_snake_case`
error: aborting due to 1 previous error

View file

@ -0,0 +1,4 @@
error: error reading Clippy's configuration file: unknown ordering group: `entirely garbled` was not specified in `module-items-ordered-within-groupings`, expected one of: `modules`, `use`, `macros`, `global_asm`, `UPPER_SNAKE_CASE`, `PascalCase`, `lower_snake_case`
error: aborting due to 1 previous error

View file

@ -1,15 +1,21 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
//@revisions: default default_exp bad_conf_1 bad_conf_2 bad_conf_3
//@revisions: default default_exp bad_conf_1 bad_conf_2 bad_conf_3 bad_conf_4 bad_conf_5 bad_conf_6
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/default
//@[default_exp] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/default_exp
//@[bad_conf_1] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_1
//@[bad_conf_2] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_2
//@[bad_conf_3] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_3
//@[bad_conf_4] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_4
//@[bad_conf_5] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_5
//@[bad_conf_6] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_6
//@[default] check-pass
//@[default_exp] check-pass
//@[bad_conf_1] error-in-other-file:
//@[bad_conf_2] error-in-other-file:
//@[bad_conf_3] error-in-other-file:
//@[bad_conf_4] error-in-other-file:
//@[bad_conf_5] error-in-other-file:
//@[bad_conf_6] error-in-other-file:
#![allow(dead_code)]
#![warn(clippy::arbitrary_source_item_ordering)]

View file

@ -1,223 +1,160 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:22:14
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:26:14
|
LL | use std::rc::Weak;
| ^^^^
|
note: should be placed before `SNAKE_CASE`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:20:7
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:23:7
|
LL | const SNAKE_CASE: &str = "zzzzzzzz";
| ^^^^^^^^^^
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:67:1
|
LL | / impl CloneSelf for StructOrdered {
LL | |
LL | | fn clone_self(&self) -> Self {
LL | | Self {
... |
LL | | }
| |_^
|
note: should be placed before the following item
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:57:1
|
LL | / impl Default for StructOrdered {
LL | | fn default() -> Self {
LL | | Self {
LL | | a: true,
... |
LL | | }
| |_^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:145:7
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:149:7
|
LL | const ZIS_SHOULD_BE_REALLY_EARLY: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `TraitUnorderedItemKinds`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:132:7
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:136:7
|
LL | trait TraitUnorderedItemKinds {
| ^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:163:1
|
LL | impl BasicEmptyTrait for StructOrdered {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before the following item
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:148:1
|
LL | / impl TraitUnordered for StructUnordered {
LL | | const A: bool = false;
LL | | const C: bool = false;
LL | | const B: bool = false;
... |
LL | | }
| |_^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:184:5
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:188:5
|
LL | mod this_is_in_the_wrong_position {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `main`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:179:4
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:183:4
|
LL | fn main() {
| ^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:194:7
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:198:7
|
LL | const ZIS_SHOULD_BE_EVEN_EARLIER: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `ZisShouldBeBeforeZeMainFn`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:192:8
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:196:8
|
LL | struct ZisShouldBeBeforeZeMainFn;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:12:11
|
LL | const AFTER: i8 = 0;
| ^^^^^
|
note: should be placed before `BEFORE`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:10:11
|
LL | const BEFORE: i8 = 0;
| ^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:40:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:44:5
|
LL | B,
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:39:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:43:5
|
LL | C,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:92:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:96:5
|
LL | b: bool,
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:91:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:95:5
|
LL | c: bool,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:101:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:105:5
|
LL | b: bool,
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:100:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:104:5
|
LL | c: bool,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:121:11
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:125:11
|
LL | const B: bool;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:120:11
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:124:11
|
LL | const C: bool;
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:128:8
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:132:8
|
LL | fn b();
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:127:8
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:131:8
|
LL | fn c();
| ^
error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:135:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:139:5
|
LL | const A: bool;
| ^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:133:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:137:5
|
LL | type SomeType;
| ^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:151:11
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:155:11
|
LL | const B: bool = false;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:150:11
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:154:11
|
LL | const C: bool = false;
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:158:8
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:162:8
|
LL | fn b() {}
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:157:8
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:161:8
|
LL | fn c() {}
| ^
error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:169:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:173:5
|
LL | const A: bool = false;
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:167:5
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:171:5
|
LL | type SomeType = ();
| ^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:187:11
|
LL | const A: i8 = 1;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:186:11
|
LL | const C: i8 = 0;
| ^
error: aborting due to 17 previous errors
error: aborting due to 13 previous errors

View file

@ -0,0 +1,160 @@
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:26:14
|
LL | use std::rc::Weak;
| ^^^^
|
note: should be placed before `SNAKE_CASE`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:23:7
|
LL | const SNAKE_CASE: &str = "zzzzzzzz";
| ^^^^^^^^^^
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:149:7
|
LL | const ZIS_SHOULD_BE_REALLY_EARLY: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `TraitUnorderedItemKinds`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:136:7
|
LL | trait TraitUnorderedItemKinds {
| ^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:188:5
|
LL | mod this_is_in_the_wrong_position {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `main`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:183:4
|
LL | fn main() {
| ^^^^
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:198:7
|
LL | const ZIS_SHOULD_BE_EVEN_EARLIER: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `ZisShouldBeBeforeZeMainFn`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:196:8
|
LL | struct ZisShouldBeBeforeZeMainFn;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:44:5
|
LL | B,
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:43:5
|
LL | C,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:96:5
|
LL | b: bool,
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:95:5
|
LL | c: bool,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:105:5
|
LL | b: bool,
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:104:5
|
LL | c: bool,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:125:11
|
LL | const B: bool;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:124:11
|
LL | const C: bool;
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:132:8
|
LL | fn b();
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:131:8
|
LL | fn c();
| ^
error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:139:5
|
LL | const A: bool;
| ^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:137:5
|
LL | type SomeType;
| ^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:155:11
|
LL | const B: bool = false;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:154:11
|
LL | const C: bool = false;
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:162:8
|
LL | fn b() {}
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:161:8
|
LL | fn c() {}
| ^
error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:173:5
|
LL | const A: bool = false;
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:171:5
|
LL | type SomeType = ();
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 13 previous errors

View file

@ -0,0 +1,235 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:23:7
|
LL | const SNAKE_CASE: &str = "zzzzzzzz";
| ^^^^^^^^^^
|
note: should be placed before `ZNAKE_CASE`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:22:7
|
LL | const ZNAKE_CASE: &str = "123";
| ^^^^^^^^^^
= note: `-D clippy::arbitrary-source-item-ordering` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]`
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:26:14
|
LL | use std::rc::Weak;
| ^^^^
|
note: should be placed before `SNAKE_CASE`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:23:7
|
LL | const SNAKE_CASE: &str = "zzzzzzzz";
| ^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:71:1
|
LL | / impl CloneSelf for StructOrdered {
LL | |
LL | | fn clone_self(&self) -> Self {
LL | | Self {
... |
LL | | }
| |_^
|
note: should be placed before the following item
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:61:1
|
LL | / impl Default for StructOrdered {
LL | | fn default() -> Self {
LL | | Self {
LL | | a: true,
... |
LL | | }
| |_^
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:149:7
|
LL | const ZIS_SHOULD_BE_REALLY_EARLY: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `TraitUnorderedItemKinds`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:136:7
|
LL | trait TraitUnorderedItemKinds {
| ^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:167:1
|
LL | impl BasicEmptyTrait for StructOrdered {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before the following item
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:152:1
|
LL | / impl TraitUnordered for StructUnordered {
LL | | const A: bool = false;
LL | | const C: bool = false;
LL | | const B: bool = false;
... |
LL | | }
| |_^
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:188:5
|
LL | mod this_is_in_the_wrong_position {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `main`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:183:4
|
LL | fn main() {
| ^^^^
error: incorrect ordering of items (module item groupings specify another order)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:198:7
|
LL | const ZIS_SHOULD_BE_EVEN_EARLIER: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `ZisShouldBeBeforeZeMainFn`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:196:8
|
LL | struct ZisShouldBeBeforeZeMainFn;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:14:11
|
LL | const AFTER: i8 = 0;
| ^^^^^
|
note: should be placed before `BEFORE`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:12:11
|
LL | const BEFORE: i8 = 0;
| ^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:44:5
|
LL | B,
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:43:5
|
LL | C,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:96:5
|
LL | b: bool,
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:95:5
|
LL | c: bool,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:105:5
|
LL | b: bool,
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:104:5
|
LL | c: bool,
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:125:11
|
LL | const B: bool;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:124:11
|
LL | const C: bool;
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:132:8
|
LL | fn b();
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:131:8
|
LL | fn c();
| ^
error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:139:5
|
LL | const A: bool;
| ^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:137:5
|
LL | type SomeType;
| ^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:155:11
|
LL | const B: bool = false;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:154:11
|
LL | const C: bool = false;
| ^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:162:8
|
LL | fn b() {}
| ^
|
note: should be placed before `c`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:161:8
|
LL | fn c() {}
| ^
error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:173:5
|
LL | const A: bool = false;
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: should be placed before `SomeType`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:171:5
|
LL | type SomeType = ();
| ^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:191:11
|
LL | const A: i8 = 1;
| ^
|
note: should be placed before `C`
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:190:11
|
LL | const C: i8 = 0;
| ^
error: aborting due to 18 previous errors

View file

@ -1,6 +1,8 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
//@revisions: default
//@revisions: default default_exp ord_within
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/default
//@[default_exp] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/default_exp
//@[ord_within] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_within
#![allow(dead_code)]
#![warn(clippy::arbitrary_source_item_ordering)]
@ -10,14 +12,16 @@ mod i_am_just_right {
const BEFORE: i8 = 0;
const AFTER: i8 = 0;
//~^ arbitrary_source_item_ordering
//~[ord_within]^ arbitrary_source_item_ordering
}
// Use statements should not be linted internally - this is normally auto-sorted using rustfmt.
use std::rc::Rc;
use std::sync::{Arc, Barrier, RwLock};
const ZNAKE_CASE: &str = "123";
const SNAKE_CASE: &str = "zzzzzzzz";
//~[ord_within]^ arbitrary_source_item_ordering
use std::rc::Weak;
//~^ arbitrary_source_item_ordering
@ -65,7 +69,7 @@ impl Default for StructOrdered {
}
impl CloneSelf for StructOrdered {
//~^ arbitrary_source_item_ordering
//~[ord_within]^ arbitrary_source_item_ordering
fn clone_self(&self) -> Self {
Self {
a: true,
@ -161,7 +165,7 @@ impl TraitUnordered for StructUnordered {
// Trait impls should be located just after the type they implement it for.
impl BasicEmptyTrait for StructOrdered {}
//~^ arbitrary_source_item_ordering
//~[ord_within]^ arbitrary_source_item_ordering
impl TraitUnorderedItemKinds for StructUnordered {
type SomeType = ();
@ -185,7 +189,7 @@ mod this_is_in_the_wrong_position {
//~^ arbitrary_source_item_ordering
const C: i8 = 0;
const A: i8 = 1;
//~^ arbitrary_source_item_ordering
//~[ord_within]^ arbitrary_source_item_ordering
}
#[derive(Default, std::clone::Clone)]

View file

@ -0,0 +1,19 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
|
LL | a: bool,
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
|
LL | b: bool,
| ^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
|
LL | #[deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View file

@ -0,0 +1,36 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
|
LL | struct OrderedChecked {
| ^^^^^^^^^^^^^^
|
note: should be placed before `Unordered`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
|
LL | struct Unordered {
| ^^^^^^^^^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
|
LL | #![deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
|
LL | a: bool,
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
|
LL | b: bool,
| ^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
|
LL | #[deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -0,0 +1,19 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
|
LL | struct OrderedChecked {
| ^^^^^^^^^^^^^^
|
note: should be placed before `Unordered`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
|
LL | struct Unordered {
| ^^^^^^^^^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
|
LL | #![deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View file

@ -0,0 +1,48 @@
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:24:8
|
LL | struct OrderedChecked {
| ^^^^^^^^^^^^^^
|
note: should be placed before `Unordered`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:18:8
|
LL | struct Unordered {
| ^^^^^^^^^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:9:9
|
LL | #![deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:45:4
|
LL | fn before_main() {}
| ^^^^^^^^^^^
|
note: should be placed before `main`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:41:4
|
LL | fn main() {
| ^^^^
error: incorrect ordering of items (must be alphabetically ordered)
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:35:5
|
LL | a: bool,
| ^
|
note: should be placed before `b`
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:34:5
|
LL | b: bool,
| ^
note: the lint level is defined here
--> tests/ui-toml/arbitrary_source_item_ordering/selective_ordering.rs:32:8
|
LL | #[deny(clippy::arbitrary_source_item_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View file

@ -0,0 +1,46 @@
//@aux-build:../../ui/auxiliary/proc_macros.rs
//@revisions: default ord_within ord_in_2 ord_in_3
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/default
//@[ord_within] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_within
//@[ord_in_2] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_in_2
//@[ord_in_3] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_in_3
#![allow(dead_code)]
#![deny(clippy::arbitrary_source_item_ordering)]
#[allow(clippy::arbitrary_source_item_ordering)]
struct Ordered {
a: bool,
b: bool,
}
#[allow(clippy::arbitrary_source_item_ordering)]
struct Unordered {
b: bool,
a: bool,
}
#[deny(clippy::arbitrary_source_item_ordering)]
struct OrderedChecked {
//~[ord_within]^ arbitrary_source_item_ordering
//~[ord_in_2]| arbitrary_source_item_ordering
//~[ord_in_3]| arbitrary_source_item_ordering
a: bool,
b: bool,
}
#[deny(clippy::arbitrary_source_item_ordering)]
struct UnorderedChecked {
b: bool,
a: bool,
//~[ord_within]^ arbitrary_source_item_ordering
//~[default]| arbitrary_source_item_ordering
//~[ord_in_2]| arbitrary_source_item_ordering
}
fn main() {
// test code goes here
}
fn before_main() {}
//~[ord_within]^ arbitrary_source_item_ordering

View file

@ -60,6 +60,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
min-ident-chars-threshold
missing-docs-in-crate-items
module-item-order-groupings
module-items-ordered-within-groupings
msrv
pass-by-value-size-limit
pub-underscore-fields-behavior
@ -152,6 +153,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
min-ident-chars-threshold
missing-docs-in-crate-items
module-item-order-groupings
module-items-ordered-within-groupings
msrv
pass-by-value-size-limit
pub-underscore-fields-behavior
@ -244,6 +246,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
min-ident-chars-threshold
missing-docs-in-crate-items
module-item-order-groupings
module-items-ordered-within-groupings
msrv
pass-by-value-size-limit
pub-underscore-fields-behavior

View file

@ -310,5 +310,49 @@ LL | let bar = unsafe {};
|
= help: consider adding a safety comment on the preceding line
error: aborting due to 35 previous errors
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:638:52
|
LL | const NO_SAFETY_IN_TRAIT_BUT_IN_IMPL: u8 = unsafe { 0 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:647:41
|
LL | const NO_SAFETY_IN_TRAIT: i32 = unsafe { 1 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:657:42
|
LL | const HAS_SAFETY_IN_TRAIT: i32 = unsafe { 3 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:662:40
|
LL | const NO_SAFETY_IN_IMPL: i32 = unsafe { 1 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: statement has unnecessary safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:719:5
|
LL | _ = bar();
| ^^^^^^^^^^
|
help: consider removing the safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:718:5
|
LL | // SAFETY: unnecessary_safety_comment triggers here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 40 previous errors

View file

@ -390,5 +390,65 @@ LL | unsafe {}
|
= help: consider adding a safety comment on the preceding line
error: aborting due to 45 previous errors
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:638:52
|
LL | const NO_SAFETY_IN_TRAIT_BUT_IN_IMPL: u8 = unsafe { 0 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:647:41
|
LL | const NO_SAFETY_IN_TRAIT: i32 = unsafe { 1 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:657:42
|
LL | const HAS_SAFETY_IN_TRAIT: i32 = unsafe { 3 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:662:40
|
LL | const NO_SAFETY_IN_IMPL: i32 = unsafe { 1 };
| ^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:673:9
|
LL | unsafe { here_is_another_variable_with_long_name };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:702:9
|
LL | unsafe { Date::__from_ordinal_date_unchecked(1970, 1) }.into_julian_day_just_make_this_line_longer();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: statement has unnecessary safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:719:5
|
LL | _ = bar();
| ^^^^^^^^^^
|
help: consider removing the safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:718:5
|
LL | // SAFETY: unnecessary_safety_comment triggers here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 52 previous errors

View file

@ -632,4 +632,95 @@ mod issue_11246 {
// Safety: Another safety comment
const FOO: () = unsafe {};
// trait items and impl items
mod issue_11709 {
trait MyTrait {
const NO_SAFETY_IN_TRAIT_BUT_IN_IMPL: u8 = unsafe { 0 };
//~^ ERROR: unsafe block missing a safety comment
// SAFETY: safe
const HAS_SAFETY_IN_TRAIT: i32 = unsafe { 1 };
// SAFETY: unrelated
unsafe fn unsafe_fn() {}
const NO_SAFETY_IN_TRAIT: i32 = unsafe { 1 };
//~^ ERROR: unsafe block missing a safety comment
}
struct UnsafeStruct;
impl MyTrait for UnsafeStruct {
// SAFETY: safe in this impl
const NO_SAFETY_IN_TRAIT_BUT_IN_IMPL: u8 = unsafe { 2 };
const HAS_SAFETY_IN_TRAIT: i32 = unsafe { 3 };
//~^ ERROR: unsafe block missing a safety comment
}
impl UnsafeStruct {
const NO_SAFETY_IN_IMPL: i32 = unsafe { 1 };
//~^ ERROR: unsafe block missing a safety comment
}
}
fn issue_13024() {
let mut just_a_simple_variable_with_a_very_long_name_that_has_seventy_eight_characters = 0;
let here_is_another_variable_with_long_name = 100;
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
just_a_simple_variable_with_a_very_long_name_that_has_seventy_eight_characters =
unsafe { here_is_another_variable_with_long_name };
//~[disabled]^ undocumented_unsafe_blocks
}
// https://docs.rs/time/0.3.36/src/time/offset_date_time.rs.html#35
mod issue_11709_regression {
use std::num::NonZeroI32;
struct Date {
value: NonZeroI32,
}
impl Date {
const unsafe fn __from_ordinal_date_unchecked(year: i32, ordinal: u16) -> Self {
Self {
// Safety: The caller must guarantee that `ordinal` is not zero.
value: unsafe { NonZeroI32::new_unchecked((year << 9) | ordinal as i32) },
}
}
const fn into_julian_day_just_make_this_line_longer(self) -> i32 {
42
}
}
/// The Julian day of the Unix epoch.
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
#[allow(unsafe_code)]
const UNIX_EPOCH_JULIAN_DAY: i32 =
unsafe { Date::__from_ordinal_date_unchecked(1970, 1) }.into_julian_day_just_make_this_line_longer();
//~[disabled]^ undocumented_unsafe_blocks
}
fn issue_13039() {
unsafe fn foo() -> usize {
1234
}
fn bar() -> usize {
1234
}
// SAFETY: unnecessary_safety_comment should not trigger here
_ = unsafe { foo() };
// SAFETY: unnecessary_safety_comment triggers here
_ = bar();
//~^ unnecessary_safety_comment
// SAFETY: unnecessary_safety_comment should not trigger here
_ = unsafe { foo() }
}
fn main() {}

View file

@ -118,6 +118,13 @@ mod issue_12016 {
}
}
fn issue_9911() {
if { return } {}
let a = 1;
if { if a == 1 { return } else { true } } {}
}
fn in_closure() {
let v = vec![1, 2, 3];
if v.into_iter()

View file

@ -118,6 +118,13 @@ mod issue_12016 {
}
}
fn issue_9911() {
if { return } {}
let a = 1;
if { if a == 1 { return } else { true } } {}
}
fn in_closure() {
let v = vec![1, 2, 3];
if v.into_iter()

View file

@ -1,6 +1,5 @@
//@ check-pass
#![allow(clippy::comparison_chain)]
#![deny(clippy::if_same_then_else)]
// Test for https://github.com/rust-lang/rust-clippy/issues/2426

View file

@ -2,7 +2,7 @@ error: this argument is passed by value, but not consumed in the function body
--> tests/ui/crashes/needless_pass_by_value-w-late-bound.rs:7:12
|
LL | fn test(x: Foo<'_>) {}
| ^^^^^^^ help: consider taking a reference instead: `&Foo<'_>`
| ^^^^^^^
|
help: or consider marking this type as `Copy`
--> tests/ui/crashes/needless_pass_by_value-w-late-bound.rs:5:1
@ -11,6 +11,10 @@ LL | struct Foo<'a>(&'a [(); 100]);
| ^^^^^^^^^^^^^^
= note: `-D clippy::needless-pass-by-value` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_value)]`
help: consider taking a reference instead
|
LL | fn test(x: &Foo<'_>) {}
| +
error: aborting due to 1 previous error

View file

@ -0,0 +1,98 @@
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
#![warn(clippy::doc_comment_double_space_linebreaks)]
#![allow(unused, clippy::empty_docs)]
//~v doc_comment_double_space_linebreaks
//! Should warn on double space linebreaks\
//! in file/module doc comment
/// Should not warn on single-line doc comments
fn single_line() {}
/// Should not warn on single-line doc comments
/// split across multiple lines
fn single_line_split() {}
// Should not warn on normal comments
// note: cargo fmt can remove double spaces from normal and block comments
// Should not warn on normal comments
// with double spaces at the end of a line
#[doc = "This is a doc attribute, which should not be linted"]
fn normal_comment() {
/*
Should not warn on block comments
*/
/*
Should not warn on block comments
with double space at the end of a line
*/
}
//~v doc_comment_double_space_linebreaks
/// Should warn when doc comment uses double space\
/// as a line-break, even when there are multiple\
/// in a row
fn double_space_doc_comment() {}
/// Should not warn when back-slash is used \
/// as a line-break
fn back_slash_doc_comment() {}
//~v doc_comment_double_space_linebreaks
/// 🌹 are 🟥\
/// 🌷 are 🟦\
/// 📎 is 😎\
/// and so are 🫵\
/// (hopefully no formatting weirdness linting this)
fn multi_byte_chars_tada() {}
macro_rules! macro_that_makes_function {
() => {
/// Shouldn't lint on this!
/// (hopefully)
fn my_macro_created_function() {}
}
}
macro_that_makes_function!();
// dont lint when its alone on a line
///
fn alone() {}
/// | First column | Second column |
/// | ------------ | ------------- |
/// | Not a line | break when |
/// | after a line | in a table |
fn table() {}
/// ```text
/// It's also not a hard line break if
/// there's two spaces at the end of a
/// line in a block code.
/// ```
fn codeblock() {}
/// It's also not a hard line break `if
/// there's` two spaces in the middle of inline code.
fn inline() {}
/// It's also not a hard line break [when](
/// https://example.com) in a URL.
fn url() {}
//~v doc_comment_double_space_linebreaks
/// here we mix\
/// double spaces\
/// and also\
/// adding backslash\
/// to some of them\
/// to see how that looks
fn mixed() {}
fn main() {}

View file

@ -0,0 +1,98 @@
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
#![warn(clippy::doc_comment_double_space_linebreaks)]
#![allow(unused, clippy::empty_docs)]
//~v doc_comment_double_space_linebreaks
//! Should warn on double space linebreaks
//! in file/module doc comment
/// Should not warn on single-line doc comments
fn single_line() {}
/// Should not warn on single-line doc comments
/// split across multiple lines
fn single_line_split() {}
// Should not warn on normal comments
// note: cargo fmt can remove double spaces from normal and block comments
// Should not warn on normal comments
// with double spaces at the end of a line
#[doc = "This is a doc attribute, which should not be linted"]
fn normal_comment() {
/*
Should not warn on block comments
*/
/*
Should not warn on block comments
with double space at the end of a line
*/
}
//~v doc_comment_double_space_linebreaks
/// Should warn when doc comment uses double space
/// as a line-break, even when there are multiple
/// in a row
fn double_space_doc_comment() {}
/// Should not warn when back-slash is used \
/// as a line-break
fn back_slash_doc_comment() {}
//~v doc_comment_double_space_linebreaks
/// 🌹 are 🟥
/// 🌷 are 🟦
/// 📎 is 😎
/// and so are 🫵
/// (hopefully no formatting weirdness linting this)
fn multi_byte_chars_tada() {}
macro_rules! macro_that_makes_function {
() => {
/// Shouldn't lint on this!
/// (hopefully)
fn my_macro_created_function() {}
}
}
macro_that_makes_function!();
// dont lint when its alone on a line
///
fn alone() {}
/// | First column | Second column |
/// | ------------ | ------------- |
/// | Not a line | break when |
/// | after a line | in a table |
fn table() {}
/// ```text
/// It's also not a hard line break if
/// there's two spaces at the end of a
/// line in a block code.
/// ```
fn codeblock() {}
/// It's also not a hard line break `if
/// there's` two spaces in the middle of inline code.
fn inline() {}
/// It's also not a hard line break [when](
/// https://example.com) in a URL.
fn url() {}
//~v doc_comment_double_space_linebreaks
/// here we mix
/// double spaces\
/// and also
/// adding backslash\
/// to some of them
/// to see how that looks
fn mixed() {}
fn main() {}

View file

@ -0,0 +1,50 @@
error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreaks.rs:8:43
|
LL | //! Should warn on double space linebreaks
| ^^
|
= help: replace this double space with a backslash: `\`
= note: `-D clippy::doc-comment-double-space-linebreaks` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::doc_comment_double_space_linebreaks)]`
error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreaks.rs:37:51
|
LL | /// Should warn when doc comment uses double space
| ^^
LL | /// as a line-break, even when there are multiple
| ^^
|
= help: replace this double space with a backslash: `\`
error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreaks.rs:47:12
|
LL | /// 🌹 are 🟥
| ^^
LL | /// 🌷 are 🟦
| ^^
LL | /// 📎 is 😎
| ^^
LL | /// and so are 🫵
| ^^
|
= help: replace this double space with a backslash: `\`
error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreaks.rs:90:16
|
LL | /// here we mix
| ^^
LL | /// double spaces\
LL | /// and also
| ^^
LL | /// adding backslash\
LL | /// to some of them
| ^^
|
= help: replace this double space with a backslash: `\`
error: aborting due to 4 previous errors

View file

@ -0,0 +1,94 @@
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
#![warn(clippy::map_entry)]
//@no-rustfix
use std::collections::HashMap;
use std::hash::Hash;
macro_rules! m {
($e:expr) => {{ $e }};
}
macro_rules! insert {
($map:expr, $key:expr, $val:expr) => {
$map.insert($key, $val)
};
}
mod issue13306 {
use std::collections::HashMap;
struct Env {
enclosing: Option<Box<Env>>,
values: HashMap<String, usize>,
}
impl Env {
fn assign(&mut self, name: String, value: usize) -> bool {
if !self.values.contains_key(&name) {
//~^ map_entry
self.values.insert(name, value);
true
} else if let Some(enclosing) = &mut self.enclosing {
enclosing.assign(name, value)
} else {
false
}
}
}
}
fn issue9925(mut hm: HashMap<String, bool>) {
let key = "hello".to_string();
if hm.contains_key(&key) {
//~^ map_entry
let bval = hm.get_mut(&key).unwrap();
*bval = false;
} else {
hm.insert(key, true);
}
}
mod issue9470 {
use std::collections::HashMap;
use std::sync::Mutex;
struct Interner(i32);
impl Interner {
const fn new() -> Self {
Interner(0)
}
fn resolve(&self, name: String) -> Option<String> {
todo!()
}
}
static INTERNER: Mutex<Interner> = Mutex::new(Interner::new());
struct VM {
stack: Vec<i32>,
globals: HashMap<String, i32>,
}
impl VM {
fn stack_top(&self) -> &i32 {
self.stack.last().unwrap()
}
fn resolve(&mut self, name: String, value: i32) -> Result<(), String> {
if self.globals.contains_key(&name) {
//~^ map_entry
self.globals.insert(name, value);
} else {
let interner = INTERNER.lock().unwrap();
return Err(interner.resolve(name).unwrap().to_owned());
}
Ok(())
}
}
}
fn main() {}

View file

@ -0,0 +1,41 @@
error: usage of `contains_key` followed by `insert` on a `HashMap`
--> tests/ui/entry_unfixable.rs:28:13
|
LL | / if !self.values.contains_key(&name) {
LL | |
LL | | self.values.insert(name, value);
LL | | true
... |
LL | | false
LL | | }
| |_____________^
|
= note: `-D clippy::map-entry` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::map_entry)]`
error: usage of `contains_key` followed by `insert` on a `HashMap`
--> tests/ui/entry_unfixable.rs:43:5
|
LL | / if hm.contains_key(&key) {
LL | |
LL | | let bval = hm.get_mut(&key).unwrap();
LL | | *bval = false;
LL | | } else {
LL | | hm.insert(key, true);
LL | | }
| |_____^
error: usage of `contains_key` followed by `insert` on a `HashMap`
--> tests/ui/entry_unfixable.rs:81:13
|
LL | / if self.globals.contains_key(&name) {
LL | |
LL | | self.globals.insert(name, value);
LL | | } else {
LL | | let interner = INTERNER.lock().unwrap();
LL | | return Err(interner.resolve(name).unwrap().to_owned());
LL | | }
| |_____________^
error: aborting due to 3 previous errors

View file

@ -105,4 +105,15 @@ fn issue_12138() {
}
}
fn issue_112502() {
struct MyInt(i64);
impl From<MyInt> for i64 {
//~^ from_over_into
fn from(val: MyInt) -> Self {
val.0
}
}
}
fn main() {}

View file

@ -105,4 +105,15 @@ fn issue_12138() {
}
}
fn issue_112502() {
struct MyInt(i64);
impl Into<i64> for MyInt {
//~^ from_over_into
fn into(self: MyInt) -> i64 {
self.0
}
}
}
fn main() {}

View file

@ -107,5 +107,21 @@ LL |
LL ~ fn from(val: Hello) {}
|
error: aborting due to 7 previous errors
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
--> tests/ui/from_over_into.rs:111:5
|
LL | impl Into<i64> for MyInt {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
help: replace the `Into` implementation with `From<issue_112502::MyInt>`
|
LL ~ impl From<MyInt> for i64 {
LL |
LL ~ fn from(val: MyInt) -> Self {
LL ~ val.0
|
error: aborting due to 8 previous errors

View file

@ -1,10 +1,5 @@
#![warn(clippy::ifs_same_cond)]
#![allow(
clippy::if_same_then_else,
clippy::comparison_chain,
clippy::needless_if,
clippy::needless_else
)] // all empty blocks
#![allow(clippy::if_same_then_else, clippy::needless_if, clippy::needless_else)] // all empty blocks
fn ifs_same_cond() {
let a = 0;

View file

@ -1,11 +1,11 @@
error: this `if` has the same condition as a previous `if`
--> tests/ui/ifs_same_cond.rs:14:15
--> tests/ui/ifs_same_cond.rs:9:15
|
LL | } else if b {
| ^
|
note: same as this
--> tests/ui/ifs_same_cond.rs:13:8
--> tests/ui/ifs_same_cond.rs:8:8
|
LL | if b {
| ^
@ -13,37 +13,37 @@ LL | if b {
= help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]`
error: this `if` has the same condition as a previous `if`
--> tests/ui/ifs_same_cond.rs:19:15
--> tests/ui/ifs_same_cond.rs:14:15
|
LL | } else if a == 1 {
| ^^^^^^
|
note: same as this
--> tests/ui/ifs_same_cond.rs:18:8
--> tests/ui/ifs_same_cond.rs:13:8
|
LL | if a == 1 {
| ^^^^^^
error: this `if` has the same condition as a previous `if`
--> tests/ui/ifs_same_cond.rs:25:15
--> tests/ui/ifs_same_cond.rs:20:15
|
LL | } else if 2 * a == 1 {
| ^^^^^^^^^^
|
note: same as this
--> tests/ui/ifs_same_cond.rs:23:8
--> tests/ui/ifs_same_cond.rs:18:8
|
LL | if 2 * a == 1 {
| ^^^^^^^^^^
error: this `if` has the same condition as a previous `if`
--> tests/ui/ifs_same_cond.rs:58:15
--> tests/ui/ifs_same_cond.rs:53:15
|
LL | } else if a.contains("ah") {
| ^^^^^^^^^^^^^^^^
|
note: same as this
--> tests/ui/ifs_same_cond.rs:57:8
--> tests/ui/ifs_same_cond.rs:52:8
|
LL | if a.contains("ah") {
| ^^^^^^^^^^^^^^^^

View file

@ -228,3 +228,27 @@ fn regression_13524(a: usize, b: usize, c: bool) -> usize {
123
} else { b.saturating_sub(a) }
}
fn with_side_effect(a: u64) -> u64 {
println!("a = {a}");
a
}
fn arbitrary_expression() {
let (a, b) = (15u64, 20u64);
let _ = (a * 2).saturating_sub(b);
//~^ implicit_saturating_sub
let _ = a.saturating_sub(b * 2);
//~^ implicit_saturating_sub
let _ = a.saturating_sub(b * 2);
//~^ implicit_saturating_sub
let _ = if with_side_effect(a) > a {
with_side_effect(a) - a
} else {
0
};
}

View file

@ -302,3 +302,27 @@ fn regression_13524(a: usize, b: usize, c: bool) -> usize {
b - a
}
}
fn with_side_effect(a: u64) -> u64 {
println!("a = {a}");
a
}
fn arbitrary_expression() {
let (a, b) = (15u64, 20u64);
let _ = if a * 2 > b { a * 2 - b } else { 0 };
//~^ implicit_saturating_sub
let _ = if a > b * 2 { a - b * 2 } else { 0 };
//~^ implicit_saturating_sub
let _ = if a < b * 2 { 0 } else { a - b * 2 };
//~^ implicit_saturating_sub
let _ = if with_side_effect(a) > a {
with_side_effect(a) - a
} else {
0
};
}

View file

@ -220,5 +220,23 @@ LL | | b - a
LL | | }
| |_____^ help: replace it with: `{ b.saturating_sub(a) }`
error: aborting due to 24 previous errors
error: manual arithmetic check found
--> tests/ui/implicit_saturating_sub.rs:314:13
|
LL | let _ = if a * 2 > b { a * 2 - b } else { 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `(a * 2).saturating_sub(b)`
error: manual arithmetic check found
--> tests/ui/implicit_saturating_sub.rs:317:13
|
LL | let _ = if a > b * 2 { a - b * 2 } else { 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b * 2)`
error: manual arithmetic check found
--> tests/ui/implicit_saturating_sub.rs:320:13
|
LL | let _ = if a < b * 2 { 0 } else { a - b * 2 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b * 2)`
error: aborting due to 27 previous errors

View file

@ -1,5 +1,6 @@
#![warn(clippy::incompatible_msrv)]
#![feature(custom_inner_attributes)]
#![feature(panic_internals)]
#![clippy::msrv = "1.3.0"]
use std::collections::HashMap;
@ -34,4 +35,42 @@ async fn issue12273(v: impl Future<Output = ()>) {
v.await;
}
fn core_special_treatment(p: bool) {
// Do not lint code coming from `core` macros expanding into `core` function calls
if p {
panic!("foo"); // Do not lint
}
// But still lint code calling `core` functions directly
if p {
core::panicking::panic("foo");
//~^ ERROR: is `1.3.0` but this item is stable since `1.6.0`
}
// Lint code calling `core` from non-`core` macros
macro_rules! my_panic {
($msg:expr) => {
core::panicking::panic($msg)
}; //~^ ERROR: is `1.3.0` but this item is stable since `1.6.0`
}
my_panic!("foo");
// Lint even when the macro comes from `core` and calls `core` functions
assert!(core::panicking::panic("out of luck"));
//~^ ERROR: is `1.3.0` but this item is stable since `1.6.0`
}
#[clippy::msrv = "1.26.0"]
fn lang_items() {
// Do not lint lang items. `..=` will expand into `RangeInclusive::new()`, which was introduced
// in Rust 1.27.0.
let _ = 1..=3;
}
#[clippy::msrv = "1.80.0"]
fn issue14212() {
let _ = std::iter::repeat_n((), 5);
//~^ ERROR: is `1.80.0` but this item is stable since `1.82.0`
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.10.0`
--> tests/ui/incompatible_msrv.rs:13:39
--> tests/ui/incompatible_msrv.rs:14:39
|
LL | assert_eq!(map.entry("poneyland").key(), &"poneyland");
| ^^^^^
@ -8,16 +8,45 @@ LL | assert_eq!(map.entry("poneyland").key(), &"poneyland");
= help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]`
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.12.0`
--> tests/ui/incompatible_msrv.rs:17:11
--> tests/ui/incompatible_msrv.rs:18:11
|
LL | v.into_key();
| ^^^^^^^^^^
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0`
--> tests/ui/incompatible_msrv.rs:21:5
--> tests/ui/incompatible_msrv.rs:22:5
|
LL | sleep(Duration::new(1, 0));
| ^^^^^
error: aborting due to 3 previous errors
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.6.0`
--> tests/ui/incompatible_msrv.rs:46:9
|
LL | core::panicking::panic("foo");
| ^^^^^^^^^^^^^^^^^^^^^^
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.6.0`
--> tests/ui/incompatible_msrv.rs:53:13
|
LL | core::panicking::panic($msg)
| ^^^^^^^^^^^^^^^^^^^^^^
...
LL | my_panic!("foo");
| ---------------- in this macro invocation
|
= note: this error originates in the macro `my_panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.6.0`
--> tests/ui/incompatible_msrv.rs:59:13
|
LL | assert!(core::panicking::panic("out of luck"));
| ^^^^^^^^^^^^^^^^^^^^^^
error: current MSRV (Minimum Supported Rust Version) is `1.80.0` but this item is stable since `1.82.0`
--> tests/ui/incompatible_msrv.rs:72:13
|
LL | let _ = std::iter::repeat_n((), 5);
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors

View file

@ -53,3 +53,8 @@ mod paths {
fn under_msrv() {
let _err = std::io::Error::new(std::io::ErrorKind::Other, E);
}
pub fn issue14346(x: i32) -> std::io::Error {
std::io::Error::other(format!("{x}"))
//~^ ERROR: this can be `std::io::Error::other(_)`
}

View file

@ -53,3 +53,8 @@ mod paths {
fn under_msrv() {
let _err = std::io::Error::new(std::io::ErrorKind::Other, E);
}
pub fn issue14346(x: i32) -> std::io::Error {
std::io::Error::new(std::io::ErrorKind::Other, format!("{x}"))
//~^ ERROR: this can be `std::io::Error::other(_)`
}

View file

@ -48,5 +48,17 @@ LL - let _err = io::Error::new(io::ErrorKind::Other, super::E);
LL + let _err = io::Error::other(super::E);
|
error: aborting due to 4 previous errors
error: this can be `std::io::Error::other(_)`
--> tests/ui/io_other_error.rs:58:5
|
LL | std::io::Error::new(std::io::ErrorKind::Other, format!("{x}"))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `std::io::Error::other`
|
LL - std::io::Error::new(std::io::ErrorKind::Other, format!("{x}"))
LL + std::io::Error::other(format!("{x}"))
|
error: aborting due to 5 previous errors

View file

@ -30,6 +30,10 @@ fn main() {
//~^ separated_literal_suffix
//~| mixed_case_hex_literals
let fail2 = 0xab_CD_isize;
//~^ separated_literal_suffix
//~| mixed_case_hex_literals
let fail_multi_zero = 000_123usize;
//~^ unseparated_literal_suffix
//~| zero_prefixed_literal

View file

@ -25,6 +25,7 @@ error: inconsistent casing in hexadecimal literal
LL | let fail1 = 0xabCD;
| ^^^^^^
|
= help: consider using `0xabcd` or `0xABCD`
= note: `-D clippy::mixed-case-hex-literals` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::mixed_case_hex_literals)]`
@ -39,6 +40,8 @@ error: inconsistent casing in hexadecimal literal
|
LL | let fail2 = 0xabCD_u32;
| ^^^^^^^^^^
|
= help: consider using `0xabcd_u32` or `0xABCD_u32`
error: integer type suffix should not be separated by an underscore
--> tests/ui/literals.rs:29:17
@ -51,9 +54,25 @@ error: inconsistent casing in hexadecimal literal
|
LL | let fail2 = 0xabCD_isize;
| ^^^^^^^^^^^^
|
= help: consider using `0xabcd_isize` or `0xABCD_isize`
error: integer type suffix should not be separated by an underscore
--> tests/ui/literals.rs:33:17
|
LL | let fail2 = 0xab_CD_isize;
| ^^^^^^^^^^^^^ help: remove the underscore: `0xab_CDisize`
error: inconsistent casing in hexadecimal literal
--> tests/ui/literals.rs:33:17
|
LL | let fail2 = 0xab_CD_isize;
| ^^^^^^^^^^^^^
|
= help: consider using `0xab_cd_isize` or `0xAB_CD_isize`
error: integer type suffix should be separated by an underscore
--> tests/ui/literals.rs:33:27
--> tests/ui/literals.rs:37:27
|
LL | let fail_multi_zero = 000_123usize;
| ^^^^^^^^^^^^ help: add an underscore: `000_123_usize`
@ -62,7 +81,7 @@ LL | let fail_multi_zero = 000_123usize;
= help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]`
error: this is a decimal constant
--> tests/ui/literals.rs:33:27
--> tests/ui/literals.rs:37:27
|
LL | let fail_multi_zero = 000_123usize;
| ^^^^^^^^^^^^
@ -81,13 +100,13 @@ LL + let fail_multi_zero = 0o123usize;
|
error: integer type suffix should not be separated by an underscore
--> tests/ui/literals.rs:38:16
--> tests/ui/literals.rs:42:16
|
LL | let ok10 = 0_i64;
| ^^^^^ help: remove the underscore: `0i64`
error: this is a decimal constant
--> tests/ui/literals.rs:41:17
--> tests/ui/literals.rs:45:17
|
LL | let fail8 = 0123;
| ^^^^
@ -103,13 +122,13 @@ LL | let fail8 = 0o123;
| +
error: integer type suffix should not be separated by an underscore
--> tests/ui/literals.rs:51:16
--> tests/ui/literals.rs:55:16
|
LL | let ok17 = 0x123_4567_8901_usize;
| ^^^^^^^^^^^^^^^^^^^^^ help: remove the underscore: `0x123_4567_8901usize`
error: digits grouped inconsistently by underscores
--> tests/ui/literals.rs:56:18
--> tests/ui/literals.rs:60:18
|
LL | let fail19 = 12_3456_21;
| ^^^^^^^^^^ help: consider: `12_345_621`
@ -118,19 +137,19 @@ LL | let fail19 = 12_3456_21;
= help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]`
error: digits grouped inconsistently by underscores
--> tests/ui/literals.rs:59:18
--> tests/ui/literals.rs:63:18
|
LL | let fail22 = 3__4___23;
| ^^^^^^^^^ help: consider: `3_423`
error: digits grouped inconsistently by underscores
--> tests/ui/literals.rs:62:18
--> tests/ui/literals.rs:66:18
|
LL | let fail23 = 3__16___23;
| ^^^^^^^^^^ help: consider: `31_623`
error: digits of hex, binary or octal literal not in groups of equal size
--> tests/ui/literals.rs:65:18
--> tests/ui/literals.rs:69:18
|
LL | let fail24 = 0xAB_ABC_AB;
| ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB`
@ -139,7 +158,7 @@ LL | let fail24 = 0xAB_ABC_AB;
= help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]`
error: this is a decimal constant
--> tests/ui/literals.rs:75:13
--> tests/ui/literals.rs:79:13
|
LL | let _ = 08;
| ^^
@ -151,7 +170,7 @@ LL + let _ = 8;
|
error: this is a decimal constant
--> tests/ui/literals.rs:78:13
--> tests/ui/literals.rs:82:13
|
LL | let _ = 09;
| ^^
@ -163,7 +182,7 @@ LL + let _ = 9;
|
error: this is a decimal constant
--> tests/ui/literals.rs:81:13
--> tests/ui/literals.rs:85:13
|
LL | let _ = 089;
| ^^^
@ -174,5 +193,5 @@ LL - let _ = 089;
LL + let _ = 89;
|
error: aborting due to 20 previous errors
error: aborting due to 22 previous errors

View file

@ -24,6 +24,15 @@ fn main() {
let result = if b <= a { 0 } else { a - b };
//~^ inverted_saturating_sub
let result = if b * 2 <= a { 0 } else { a - b * 2 };
//~^ inverted_saturating_sub
let result = if b <= a * 2 { 0 } else { a * 2 - b };
//~^ inverted_saturating_sub
let result = if b + 3 <= a + 2 { 0 } else { (a + 2) - (b + 3) };
//~^ inverted_saturating_sub
let af = 12f32;
let bf = 13f32;
// Should not lint!

View file

@ -71,5 +71,41 @@ note: this subtraction underflows when `a < b`
LL | let result = if b <= a { 0 } else { a - b };
| ^^^^^
error: aborting due to 6 previous errors
error: inverted arithmetic check before subtraction
--> tests/ui/manual_arithmetic_check-2.rs:27:27
|
LL | let result = if b * 2 <= a { 0 } else { a - b * 2 };
| ^^ --------- help: try replacing it with: `b * 2 - a`
|
note: this subtraction underflows when `a < b * 2`
--> tests/ui/manual_arithmetic_check-2.rs:27:45
|
LL | let result = if b * 2 <= a { 0 } else { a - b * 2 };
| ^^^^^^^^^
error: inverted arithmetic check before subtraction
--> tests/ui/manual_arithmetic_check-2.rs:30:23
|
LL | let result = if b <= a * 2 { 0 } else { a * 2 - b };
| ^^ --------- help: try replacing it with: `b - a * 2`
|
note: this subtraction underflows when `a * 2 < b`
--> tests/ui/manual_arithmetic_check-2.rs:30:45
|
LL | let result = if b <= a * 2 { 0 } else { a * 2 - b };
| ^^^^^^^^^
error: inverted arithmetic check before subtraction
--> tests/ui/manual_arithmetic_check-2.rs:33:27
|
LL | let result = if b + 3 <= a + 2 { 0 } else { (a + 2) - (b + 3) };
| ^^ ----------------- help: try replacing it with: `b + 3 - (a + 2)`
|
note: this subtraction underflows when `a + 2 < b + 3`
--> tests/ui/manual_arithmetic_check-2.rs:33:49
|
LL | let result = if b + 3 <= a + 2 { 0 } else { (a + 2) - (b + 3) };
| ^^^^^^^^^^^^^^^^^
error: aborting due to 9 previous errors

View file

@ -1,4 +1,4 @@
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:14:5
|
LL | size_of::<i8>() * 8;
@ -7,169 +7,169 @@ LL | size_of::<i8>() * 8;
= note: `-D clippy::manual-bits` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::manual_bits)]`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:16:5
|
LL | size_of::<i16>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:18:5
|
LL | size_of::<i32>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:20:5
|
LL | size_of::<i64>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:22:5
|
LL | size_of::<i128>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:24:5
|
LL | size_of::<isize>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:27:5
|
LL | size_of::<u8>() * 8;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:29:5
|
LL | size_of::<u16>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:31:5
|
LL | size_of::<u32>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:33:5
|
LL | size_of::<u64>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:35:5
|
LL | size_of::<u128>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:37:5
|
LL | size_of::<usize>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:40:5
|
LL | 8 * size_of::<i8>();
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:42:5
|
LL | 8 * size_of::<i16>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:44:5
|
LL | 8 * size_of::<i32>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:46:5
|
LL | 8 * size_of::<i64>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:48:5
|
LL | 8 * size_of::<i128>();
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:50:5
|
LL | 8 * size_of::<isize>();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:53:5
|
LL | 8 * size_of::<u8>();
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:55:5
|
LL | 8 * size_of::<u16>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:57:5
|
LL | 8 * size_of::<u32>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:59:5
|
LL | 8 * size_of::<u64>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:61:5
|
LL | 8 * size_of::<u128>();
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:63:5
|
LL | 8 * size_of::<usize>();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:74:5
|
LL | size_of::<Word>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `Word::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:79:18
|
LL | let _: u32 = (size_of::<u128>() * 8) as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:81:18
|
LL | let _: u32 = (size_of::<u128>() * 8).try_into().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:83:13
|
LL | let _ = (size_of::<u128>() * 8).pow(5);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
error: usage of `size_of::<T>()` to obtain the size of `T` in bits
--> tests/ui/manual_bits.rs:85:14
|
LL | let _ = &(size_of::<u128>() * 8);

View file

@ -480,3 +480,37 @@ fn issue12337() {
//~^ manual_let_else
};
}
mod issue13768 {
enum Foo {
Str(String),
None,
}
fn foo(value: Foo) {
let signature = match value {
//~^ manual_let_else
Foo::Str(ref val) => val,
_ => {
println!("No signature found");
return;
},
};
}
enum Bar {
Str { inner: String },
None,
}
fn bar(mut value: Bar) {
let signature = match value {
//~^ manual_let_else
Bar::Str { ref mut inner } => inner,
_ => {
println!("No signature found");
return;
},
};
}
}

View file

@ -489,5 +489,45 @@ error: this could be rewritten as `let...else`
LL | let v = if let Some(v_some) = g() { v_some } else { return };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };`
error: aborting due to 31 previous errors
error: this could be rewritten as `let...else`
--> tests/ui/manual_let_else.rs:491:9
|
LL | / let signature = match value {
LL | |
LL | | Foo::Str(ref val) => val,
LL | | _ => {
... |
LL | | },
LL | | };
| |__________^
|
help: consider writing
|
LL ~ let Foo::Str(ref signature) = value else {
LL + println!("No signature found");
LL + return;
LL + };
|
error: this could be rewritten as `let...else`
--> tests/ui/manual_let_else.rs:507:9
|
LL | / let signature = match value {
LL | |
LL | | Bar::Str { ref mut inner } => inner,
LL | | _ => {
... |
LL | | },
LL | | };
| |__________^
|
help: consider writing
|
LL ~ let Bar::Str { inner: ref mut signature } = value else {
LL + println!("No signature found");
LL + return;
LL + };
|
error: aborting due to 33 previous errors

View file

@ -218,3 +218,91 @@ mod with_ty_alias {
fn mut_add(x: &mut i32) {
*x += 1;
}
#[clippy::msrv = "1.87"]
mod issue14020 {
use std::ops::Add;
fn f<T: Add>(a: T, b: T) -> <T as Add>::Output {
a + b
}
}
#[clippy::msrv = "1.87"]
mod issue14290 {
use std::ops::{Deref, DerefMut};
struct Wrapper<T> {
t: T,
}
impl<T> Deref for Wrapper<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.t
}
}
impl<T> DerefMut for Wrapper<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.t
}
}
struct Example(bool);
fn do_something(mut a: Wrapper<Example>) {
a.0 = !a.0;
}
pub struct Stream(Vec<u8>);
impl Stream {
pub fn bytes(&self) -> &[u8] {
&self.0
}
}
}
#[clippy::msrv = "1.87"]
mod issue14091 {
use std::mem::ManuallyDrop;
struct BucketSlotGuard<'a> {
id: u32,
free_list: &'a mut Vec<u32>,
}
impl BucketSlotGuard<'_> {
fn into_inner(self) -> u32 {
let this = ManuallyDrop::new(self);
this.id
}
}
use std::ops::{Deref, DerefMut};
struct Wrap<T>(T);
impl<T> Deref for Wrap<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
impl<T> DerefMut for Wrap<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}
fn smart_two_field(v: &mut Wrap<(i32, i32)>) {
let _a = &mut v.0;
let _b = &mut v.1;
}
fn smart_destructure(v: &mut Wrap<(i32, i32)>) {
let (ref mut _head, ref mut _tail) = **v;
}
}

View file

@ -98,6 +98,29 @@ fn main() {
let mut out = vec![];
values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
let _y = values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
// Don't write a warning if we call `clone()` on the iterator
// https://github.com/rust-lang/rust-clippy/issues/13430
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let _cloned = my_collection.into_iter().clone();
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let my_iter = my_collection.into_iter();
let _cloned = my_iter.clone();
// Same for `as_slice()`, for same reason.
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let _sliced = my_collection.into_iter().as_slice();
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let my_iter = my_collection.into_iter();
let _sliced = my_iter.as_slice();
// Assignment outside of main scope
{
let x;
{
let xxx: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
x = xxx.into_iter();
for i in x.as_slice() {}
}
}
}
fn foo(_: impl IntoIterator<Item = usize>) {}

View file

@ -98,6 +98,29 @@ fn main() {
let mut out = vec![];
values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
let _y = values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
// Don't write a warning if we call `clone()` on the iterator
// https://github.com/rust-lang/rust-clippy/issues/13430
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let _cloned = my_collection.into_iter().clone();
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let my_iter = my_collection.into_iter();
let _cloned = my_iter.clone();
// Same for `as_slice()`, for same reason.
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let _sliced = my_collection.into_iter().as_slice();
let my_collection: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
let my_iter = my_collection.into_iter();
let _sliced = my_iter.as_slice();
// Assignment outside of main scope
{
let x;
{
let xxx: Vec<()> = vec![()].into_iter().map(|()| {}).collect();
x = xxx.into_iter();
for i in x.as_slice() {}
}
}
}
fn foo(_: impl IntoIterator<Item = usize>) {}

View file

@ -297,3 +297,9 @@ fn issue13776() {
let x;
issue13776_mac!(x, 10); // should not lint
}
fn issue9895() {
//~^ needless_late_init
let r = 5;
}

View file

@ -297,3 +297,9 @@ fn issue13776() {
let x;
issue13776_mac!(x, 10); // should not lint
}
fn issue9895() {
let r;
//~^ needless_late_init
(r = 5);
}

View file

@ -275,5 +275,21 @@ LL | },
LL ~ };
|
error: aborting due to 16 previous errors
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:302:5
|
LL | let r;
| ^^^^^^ created here
LL |
LL | (r = 5);
| ^^^^^^^ initialised here
|
help: move the declaration `r` here
|
LL ~
LL |
LL ~ let r = 5;
|
error: aborting due to 17 previous errors

View file

@ -189,6 +189,42 @@ struct Obj(String);
fn prefix_test(_unused_with_prefix: Obj) {}
// Regression test for <https://github.com/rust-lang/rust-clippy/issues/13744>.
// It's more idiomatic to write `Option<&T>` rather than `&Option<T>`.
fn option_inner_ref(x: Option<String>) {
//~^ ERROR: this argument is passed by value, but not consumed in the function body
assert!(x.is_some());
}
mod non_standard {
#[derive(Debug)]
pub struct Option<T>(T);
}
fn non_standard_option(x: non_standard::Option<String>) {
//~^ needless_pass_by_value
dbg!(&x);
}
fn option_by_name(x: Option<std::option::Option<core::option::Option<non_standard::Option<String>>>>) {
//~^ needless_pass_by_value
dbg!(&x);
}
type OptStr = Option<String>;
fn non_option(x: OptStr) {
//~^ needless_pass_by_value
dbg!(&x);
}
type Opt<T> = Option<T>;
fn non_option_either(x: Opt<String>) {
//~^ needless_pass_by_value
dbg!(&x);
}
fn main() {
// This should not cause an ICE either
// https://github.com/rust-lang/rust-clippy/issues/3144

View file

@ -17,43 +17,78 @@ error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:35:22
|
LL | fn bar(x: String, y: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
| ^^^^^^^
|
help: consider taking a reference instead
|
LL | fn bar(x: String, y: &Wrapper) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:44:71
|
LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: V) {
| ^ help: consider taking a reference instead: `&V`
| ^
|
help: consider taking a reference instead
|
LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: &V) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:58:18
|
LL | fn test_match(x: Option<Option<String>>, y: Option<Option<String>>) {
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option<Option<String>>`
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: consider taking a reference instead
|
LL | fn test_match(x: Option<Option<&String>>, y: Option<Option<String>>) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:73:24
|
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
| ^^^^^^^
|
help: consider taking a reference instead
|
LL | fn test_destructure(x: &Wrapper, y: Wrapper, z: Wrapper) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:73:36
|
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
| ^^^^^^^
|
help: consider taking a reference instead
|
LL | fn test_destructure(x: Wrapper, y: &Wrapper, z: Wrapper) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:92:49
|
LL | fn test_blanket_ref<T: Foo, S: Serialize>(vals: T, serializable: S) {}
| ^ help: consider taking a reference instead: `&T`
| ^
|
help: consider taking a reference instead
|
LL | fn test_blanket_ref<T: Foo, S: Serialize>(vals: &T, serializable: S) {}
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:95:18
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^ help: consider taking a reference instead: `&String`
| ^^^^^^
|
help: consider taking a reference instead
|
LL | fn issue_2114(s: &String, t: String, u: Vec<i32>, v: Vec<i32>) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:95:29
@ -76,7 +111,12 @@ error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:95:40
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^^^ help: consider taking a reference instead: `&Vec<i32>`
| ^^^^^^^^
|
help: consider taking a reference instead
|
LL | fn issue_2114(s: String, t: String, u: &Vec<i32>, v: Vec<i32>) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:95:53
@ -105,79 +145,175 @@ error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:115:12
|
LL | t: String,
| ^^^^^^ help: consider taking a reference instead: `&String`
| ^^^^^^
|
help: consider taking a reference instead
|
LL | t: &String,
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:125:23
|
LL | fn baz(&self, uu: U, ss: Self) {}
| ^ help: consider taking a reference instead: `&U`
| ^
|
help: consider taking a reference instead
|
LL | fn baz(&self, uu: &U, ss: Self) {}
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:125:30
|
LL | fn baz(&self, uu: U, ss: Self) {}
| ^^^^ help: consider taking a reference instead: `&Self`
| ^^^^
|
help: consider taking a reference instead
|
LL | fn baz(&self, uu: U, ss: &Self) {}
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:149:24
|
LL | fn bar_copy(x: u32, y: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
| ^^^^^^^^^^^
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:147:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
help: consider taking a reference instead
|
LL | fn bar_copy(x: u32, y: &CopyWrapper) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:157:29
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
| ^^^^^^^^^^^
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:147:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
help: consider taking a reference instead
|
LL | fn test_destructure_copy(x: &CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:157:45
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
| ^^^^^^^^^^^
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:147:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
help: consider taking a reference instead
|
LL | fn test_destructure_copy(x: CopyWrapper, y: &CopyWrapper, z: CopyWrapper) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:157:61
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
| ^^^^^^^^^^^
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:147:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
help: consider taking a reference instead
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: &CopyWrapper) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:173:40
|
LL | fn some_fun<'b, S: Bar<'b, ()>>(items: S) {}
| ^ help: consider taking a reference instead: `&S`
| ^
|
help: consider taking a reference instead
|
LL | fn some_fun<'b, S: Bar<'b, ()>>(items: &S) {}
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:179:20
|
LL | fn more_fun(items: impl Club<'static, i32>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>`
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider taking a reference instead
|
LL | fn more_fun(items: &impl Club<'static, i32>) {}
| +
error: aborting due to 22 previous errors
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:194:24
|
LL | fn option_inner_ref(x: Option<String>) {
| ^^^^^^^^^^^^^^
|
help: consider taking a reference instead
|
LL | fn option_inner_ref(x: Option<&String>) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:204:27
|
LL | fn non_standard_option(x: non_standard::Option<String>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider taking a reference instead
|
LL | fn non_standard_option(x: &non_standard::Option<String>) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:209:22
|
LL | fn option_by_name(x: Option<std::option::Option<core::option::Option<non_standard::Option<String>>>>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider taking a reference instead
|
LL | fn option_by_name(x: Option<std::option::Option<core::option::Option<&non_standard::Option<String>>>>) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:216:18
|
LL | fn non_option(x: OptStr) {
| ^^^^^^
|
help: consider taking a reference instead
|
LL | fn non_option(x: &OptStr) {
| +
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:223:25
|
LL | fn non_option_either(x: Opt<String>) {
| ^^^^^^^^^^^
|
help: consider taking a reference instead
|
LL | fn non_option_either(x: &Opt<String>) {
| +
error: aborting due to 27 previous errors

View file

@ -6,7 +6,8 @@
clippy::single_match,
clippy::needless_bool,
clippy::equatable_if_let,
clippy::needless_else
clippy::needless_else,
clippy::missing_safety_doc
)]
#![warn(clippy::needless_return)]
@ -442,3 +443,12 @@ fn b(x: Option<u8>) -> Option<u8> {
},
}
}
unsafe fn todo() -> *const u8 {
todo!()
}
pub unsafe fn issue_12157() -> *const i32 {
(unsafe { todo() } as *const i32)
//~^ needless_return
}

View file

@ -6,7 +6,8 @@
clippy::single_match,
clippy::needless_bool,
clippy::equatable_if_let,
clippy::needless_else
clippy::needless_else,
clippy::missing_safety_doc
)]
#![warn(clippy::needless_return)]
@ -451,3 +452,12 @@ fn b(x: Option<u8>) -> Option<u8> {
},
}
}
unsafe fn todo() -> *const u8 {
todo!()
}
pub unsafe fn issue_12157() -> *const i32 {
return unsafe { todo() } as *const i32;
//~^ needless_return
}

View file

@ -1,5 +1,5 @@
error: unneeded `return` statement
--> tests/ui/needless_return.rs:29:5
--> tests/ui/needless_return.rs:30:5
|
LL | return true;
| ^^^^^^^^^^^
@ -13,7 +13,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:34:5
--> tests/ui/needless_return.rs:35:5
|
LL | return true;
| ^^^^^^^^^^^
@ -25,7 +25,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:40:5
--> tests/ui/needless_return.rs:41:5
|
LL | return true;;;
| ^^^^^^^^^^^
@ -37,7 +37,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:46:5
--> tests/ui/needless_return.rs:47:5
|
LL | return true;; ; ;
| ^^^^^^^^^^^
@ -49,7 +49,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:52:9
--> tests/ui/needless_return.rs:53:9
|
LL | return true;
| ^^^^^^^^^^^
@ -61,7 +61,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:55:9
--> tests/ui/needless_return.rs:56:9
|
LL | return false;
| ^^^^^^^^^^^^
@ -73,7 +73,7 @@ LL + false
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:62:17
--> tests/ui/needless_return.rs:63:17
|
LL | true => return false,
| ^^^^^^^^^^^^
@ -85,7 +85,7 @@ LL + true => false,
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:65:13
--> tests/ui/needless_return.rs:66:13
|
LL | return true;
| ^^^^^^^^^^^
@ -97,7 +97,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:73:9
--> tests/ui/needless_return.rs:74:9
|
LL | return true;
| ^^^^^^^^^^^
@ -109,7 +109,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:76:16
--> tests/ui/needless_return.rs:77:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^
@ -121,7 +121,7 @@ LL + let _ = || true;
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:81:5
--> tests/ui/needless_return.rs:82:5
|
LL | return the_answer!();
| ^^^^^^^^^^^^^^^^^^^^
@ -133,7 +133,7 @@ LL + the_answer!()
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:85:21
--> tests/ui/needless_return.rs:86:21
|
LL | fn test_void_fun() {
| _____________________^
@ -148,7 +148,7 @@ LL + fn test_void_fun() {
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:91:11
--> tests/ui/needless_return.rs:92:11
|
LL | if b {
| ___________^
@ -163,7 +163,7 @@ LL + if b {
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:94:13
--> tests/ui/needless_return.rs:95:13
|
LL | } else {
| _____________^
@ -178,7 +178,7 @@ LL + } else {
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:103:14
--> tests/ui/needless_return.rs:104:14
|
LL | _ => return,
| ^^^^^^
@ -190,7 +190,7 @@ LL + _ => (),
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:112:24
--> tests/ui/needless_return.rs:113:24
|
LL | let _ = 42;
| ________________________^
@ -205,7 +205,7 @@ LL + let _ = 42;
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:116:14
--> tests/ui/needless_return.rs:117:14
|
LL | _ => return,
| ^^^^^^
@ -217,7 +217,7 @@ LL + _ => (),
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:130:9
--> tests/ui/needless_return.rs:131:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -229,7 +229,7 @@ LL + String::from("test")
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:133:9
--> tests/ui/needless_return.rs:134:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^
@ -241,7 +241,7 @@ LL + String::new()
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:156:32
--> tests/ui/needless_return.rs:157:32
|
LL | bar.unwrap_or_else(|_| return)
| ^^^^^^
@ -253,7 +253,7 @@ LL + bar.unwrap_or_else(|_| {})
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:161:21
--> tests/ui/needless_return.rs:162:21
|
LL | let _ = || {
| _____________________^
@ -268,7 +268,7 @@ LL + let _ = || {
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:165:20
--> tests/ui/needless_return.rs:166:20
|
LL | let _ = || return;
| ^^^^^^
@ -280,7 +280,7 @@ LL + let _ = || {};
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:172:32
--> tests/ui/needless_return.rs:173:32
|
LL | res.unwrap_or_else(|_| return Foo)
| ^^^^^^^^^^
@ -292,7 +292,7 @@ LL + res.unwrap_or_else(|_| Foo)
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:182:5
--> tests/ui/needless_return.rs:183:5
|
LL | return true;
| ^^^^^^^^^^^
@ -304,7 +304,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:187:5
--> tests/ui/needless_return.rs:188:5
|
LL | return true;
| ^^^^^^^^^^^
@ -316,7 +316,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:193:9
--> tests/ui/needless_return.rs:194:9
|
LL | return true;
| ^^^^^^^^^^^
@ -328,7 +328,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:196:9
--> tests/ui/needless_return.rs:197:9
|
LL | return false;
| ^^^^^^^^^^^^
@ -340,7 +340,7 @@ LL + false
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:203:17
--> tests/ui/needless_return.rs:204:17
|
LL | true => return false,
| ^^^^^^^^^^^^
@ -352,7 +352,7 @@ LL + true => false,
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:206:13
--> tests/ui/needless_return.rs:207:13
|
LL | return true;
| ^^^^^^^^^^^
@ -364,7 +364,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:214:9
--> tests/ui/needless_return.rs:215:9
|
LL | return true;
| ^^^^^^^^^^^
@ -376,7 +376,7 @@ LL + true
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:217:16
--> tests/ui/needless_return.rs:218:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^
@ -388,7 +388,7 @@ LL + let _ = || true;
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:222:5
--> tests/ui/needless_return.rs:223:5
|
LL | return the_answer!();
| ^^^^^^^^^^^^^^^^^^^^
@ -400,7 +400,7 @@ LL + the_answer!()
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:226:33
--> tests/ui/needless_return.rs:227:33
|
LL | async fn async_test_void_fun() {
| _________________________________^
@ -415,7 +415,7 @@ LL + async fn async_test_void_fun() {
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:232:11
--> tests/ui/needless_return.rs:233:11
|
LL | if b {
| ___________^
@ -430,7 +430,7 @@ LL + if b {
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:235:13
--> tests/ui/needless_return.rs:236:13
|
LL | } else {
| _____________^
@ -445,7 +445,7 @@ LL + } else {
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:244:14
--> tests/ui/needless_return.rs:245:14
|
LL | _ => return,
| ^^^^^^
@ -457,7 +457,7 @@ LL + _ => (),
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:258:9
--> tests/ui/needless_return.rs:259:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -469,7 +469,7 @@ LL + String::from("test")
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:261:9
--> tests/ui/needless_return.rs:262:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^
@ -481,7 +481,7 @@ LL + String::new()
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:278:5
--> tests/ui/needless_return.rs:279:5
|
LL | return format!("Hello {}", "world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -493,7 +493,7 @@ LL + format!("Hello {}", "world!")
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:320:9
--> tests/ui/needless_return.rs:321:9
|
LL | return true;
| ^^^^^^^^^^^
@ -508,7 +508,7 @@ LL ~ }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:323:9
--> tests/ui/needless_return.rs:324:9
|
LL | return false;
| ^^^^^^^^^^^^
@ -521,7 +521,7 @@ LL ~ }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:331:13
--> tests/ui/needless_return.rs:332:13
|
LL | return 10;
| ^^^^^^^^^
@ -536,7 +536,7 @@ LL ~ }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:335:13
--> tests/ui/needless_return.rs:336:13
|
LL | return 100;
| ^^^^^^^^^^
@ -550,7 +550,7 @@ LL ~ }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:344:9
--> tests/ui/needless_return.rs:345:9
|
LL | return 0;
| ^^^^^^^^
@ -563,7 +563,7 @@ LL ~ }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:352:13
--> tests/ui/needless_return.rs:353:13
|
LL | return *(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -579,7 +579,7 @@ LL ~ }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:355:13
--> tests/ui/needless_return.rs:356:13
|
LL | return !*(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -593,7 +593,7 @@ LL ~ }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:363:20
--> tests/ui/needless_return.rs:364:20
|
LL | let _ = 42;
| ____________________^
@ -608,7 +608,7 @@ LL + let _ = 42;
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:370:20
--> tests/ui/needless_return.rs:371:20
|
LL | let _ = 42; return;
| ^^^^^^^
@ -620,7 +620,7 @@ LL + let _ = 42;
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:383:9
--> tests/ui/needless_return.rs:384:9
|
LL | return Ok(format!("ok!"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@ -632,7 +632,7 @@ LL + Ok(format!("ok!"))
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:386:9
--> tests/ui/needless_return.rs:387:9
|
LL | return Err(format!("err!"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -644,7 +644,7 @@ LL + Err(format!("err!"))
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:393:9
--> tests/ui/needless_return.rs:394:9
|
LL | return if true { 1 } else { 2 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -656,7 +656,7 @@ LL + if true { 1 } else { 2 }
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:398:9
--> tests/ui/needless_return.rs:399:9
|
LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -668,7 +668,7 @@ LL + (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:420:5
--> tests/ui/needless_return.rs:421:5
|
LL | return { "a".to_string() } + "b" + { "c" };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -680,7 +680,7 @@ LL + ({ "a".to_string() } + "b" + { "c" })
|
error: unneeded `return` statement
--> tests/ui/needless_return.rs:425:5
--> tests/ui/needless_return.rs:426:5
|
LL | return "".split("").next().unwrap().to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -691,5 +691,17 @@ LL - return "".split("").next().unwrap().to_string();
LL + "".split("").next().unwrap().to_string()
|
error: aborting due to 54 previous errors
error: unneeded `return` statement
--> tests/ui/needless_return.rs:461:5
|
LL | return unsafe { todo() } as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove `return` and wrap the sequence with parentheses
|
LL - return unsafe { todo() } as *const i32;
LL + (unsafe { todo() } as *const i32)
|
error: aborting due to 55 previous errors

View file

@ -422,6 +422,34 @@ pub fn issue12205() -> Option<()> {
}
}
fn stmt_after_return() {
for v in 0..10 {
//~^ never_loop
break;
println!("{v}");
}
}
fn loop_label() {
'outer: for v in 0..10 {
//~^ never_loop
loop {
//~^ never_loop
break 'outer;
}
return;
}
for v in 0..10 {
//~^ never_loop
'inner: loop {
//~^ never_loop
break 'inner;
}
return;
}
}
fn main() {
test1();
test2();

View file

@ -164,5 +164,73 @@ LL | | unimplemented!("not yet");
LL | | }
| |_____^
error: aborting due to 16 previous errors
error: this loop never actually loops
--> tests/ui/never_loop.rs:426:5
|
LL | / for v in 0..10 {
LL | |
LL | | break;
LL | | println!("{v}");
LL | | }
| |_____^
|
help: if you need the first element of the iterator, try writing
|
LL - for v in 0..10 {
LL + if let Some(v) = (0..10).next() {
|
error: this loop never actually loops
--> tests/ui/never_loop.rs:434:5
|
LL | / 'outer: for v in 0..10 {
LL | |
LL | | loop {
... |
LL | | return;
LL | | }
| |_____^
|
help: if you need the first element of the iterator, try writing
|
LL - 'outer: for v in 0..10 {
LL + if let Some(v) = (0..10).next() {
|
error: this loop never actually loops
--> tests/ui/never_loop.rs:436:9
|
LL | / loop {
LL | |
LL | | break 'outer;
LL | | }
| |_________^
error: this loop never actually loops
--> tests/ui/never_loop.rs:443:5
|
LL | / for v in 0..10 {
LL | |
LL | | 'inner: loop {
... |
LL | | return;
LL | | }
| |_____^
|
help: if you need the first element of the iterator, try writing
|
LL - for v in 0..10 {
LL + if let Some(v) = (0..10).next() {
|
error: this loop never actually loops
--> tests/ui/never_loop.rs:445:9
|
LL | / 'inner: loop {
LL | |
LL | | break 'inner;
LL | | }
| |_________^
error: aborting due to 21 previous errors

View file

@ -0,0 +1,20 @@
#![allow(clippy::iter_next_slice, clippy::needless_return)]
fn no_break_or_continue_loop() {
if let Some(i) = [1, 2, 3].iter().next() {
//~^ never_loop
return;
}
}
fn no_break_or_continue_loop_outer() {
if let Some(i) = [1, 2, 3].iter().next() {
//~^ never_loop
return;
loop {
if true {
continue;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show more