Merge remote-tracking branch 'upstream/master' into rustup
This commit is contained in:
commit
0bb1b5bd3b
263 changed files with 5325 additions and 4470 deletions
|
|
@ -1,8 +1,6 @@
|
|||
if let StmtKind::Let(local) = stmt.kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Cast(expr, cast_ty) = init.kind
|
||||
&& let TyKind::Path(ref qpath) = cast_ty.kind
|
||||
&& match_qpath(qpath, &["char"])
|
||||
&& let ExprKind::Lit(ref lit) = expr.kind
|
||||
&& let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ if let ExprKind::Block(block, None) = expr.kind
|
|||
&& name1.as_str() == "_t"
|
||||
&& let StmtKind::Semi(e) = block.stmts[2].kind
|
||||
&& let ExprKind::Unary(UnOp::Neg, inner) = e.kind
|
||||
&& let ExprKind::Path(ref qpath) = inner.kind
|
||||
&& match_qpath(qpath, &["x"])
|
||||
&& block.expr.is_none()
|
||||
{
|
||||
// report your lint here
|
||||
|
|
@ -25,18 +23,14 @@ if let ExprKind::Block(block, None) = expr.kind
|
|||
&& let StmtKind::Let(local) = block.stmts[0].kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Call(func, args) = init.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["String", "new"])
|
||||
&& is_path_diagnostic_item(cx, func, sym::string_new)
|
||||
&& args.is_empty()
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
|
||||
&& name.as_str() == "expr"
|
||||
&& let Some(trailing_expr) = block.expr
|
||||
&& let ExprKind::Call(func1, args1) = trailing_expr.kind
|
||||
&& let ExprKind::Path(ref qpath1) = func1.kind
|
||||
&& match_qpath(qpath1, &["drop"])
|
||||
&& is_path_diagnostic_item(cx, func1, sym::mem_drop)
|
||||
&& args1.len() == 1
|
||||
&& let ExprKind::Path(ref qpath2) = args1[0].kind
|
||||
&& match_qpath(qpath2, &["expr"])
|
||||
{
|
||||
// report your lint here
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
if let StmtKind::Let(local) = stmt.kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Call(func, args) = init.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["{{root}}", "std", "cmp", "min"])
|
||||
&& is_path_diagnostic_item(cx, func, sym::cmp_min)
|
||||
&& args.len() == 2
|
||||
&& let ExprKind::Lit(ref lit) = args[0].kind
|
||||
&& let LitKind::Int(3, LitIntType::Unsuffixed) = lit.node
|
||||
|
|
|
|||
|
|
@ -31,10 +31,8 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind
|
||||
&& let ExprKind::Let(let_expr) = cond.kind
|
||||
&& let PatKind::Expr(lit_expr) = let_expr.pat.kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Bool(true) = lit.node
|
||||
&& let ExprKind::Path(ref qpath) = let_expr.init.kind
|
||||
&& match_qpath(qpath, &["a"])
|
||||
&& let ExprKind::Block(block, None) = then.kind
|
||||
&& block.stmts.is_empty()
|
||||
&& block.expr.is_none()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
if let StmtKind::Let(local) = stmt.kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Call(func, args) = init.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["std", "mem", "transmute"])
|
||||
&& is_path_diagnostic_item(cx, func, sym::transmute)
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Path(ref qpath1) = args[0].kind
|
||||
&& match_qpath(qpath1, &["ZPTR"])
|
||||
&& let PatKind::Wild = local.pat.kind
|
||||
{
|
||||
// report your lint here
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Let(local) = block.stmts[0].kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Path(ref qpath1) = init.kind
|
||||
&& match_qpath(qpath1, &["y"])
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name1, None) = local.pat.kind
|
||||
&& name1.as_str() == "z"
|
||||
&& block.expr.is_none()
|
||||
|
|
@ -64,8 +62,6 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
// report your lint here
|
||||
}
|
||||
if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr)
|
||||
&& let ExprKind::Path(ref qpath) = condition.kind
|
||||
&& match_qpath(qpath, &["a"])
|
||||
&& let ExprKind::Block(block, None) = body.kind
|
||||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
|
|
@ -77,10 +73,8 @@ if let Some(higher::While { condition: condition, body: body }) = higher::While:
|
|||
}
|
||||
if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr)
|
||||
&& let PatKind::Expr(lit_expr) = let_pat.kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Bool(true) = lit.node
|
||||
&& let ExprKind::Path(ref qpath) = let_expr.kind
|
||||
&& match_qpath(qpath, &["a"])
|
||||
&& let ExprKind::Block(block, None) = if_then.kind
|
||||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
|
|
|
|||
|
|
@ -7,12 +7,10 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
&& let ExprKind::Call(func, args) = e.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["$crate", "io", "_print"])
|
||||
&& paths::STD_IO_STDIO__PRINT.matches_path(cx, func) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Call(func1, args1) = args[0].kind
|
||||
&& let ExprKind::Path(ref qpath1) = func1.kind
|
||||
&& match_qpath(qpath1, &["format_arguments", "new_v1"])
|
||||
&& paths::CORE_FMT_RT_NEW_V1.matches_path(cx, func1) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args1.len() == 2
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
|
||||
&& let ExprKind::Array(elements) = inner.kind
|
||||
|
|
@ -27,12 +25,9 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& let ExprKind::Array(elements1) = inner1.kind
|
||||
&& elements1.len() == 1
|
||||
&& let ExprKind::Call(func2, args2) = elements1[0].kind
|
||||
&& let ExprKind::Path(ref qpath2) = func2.kind
|
||||
&& match_qpath(qpath2, &["format_argument", "new_display"])
|
||||
&& paths::CORE_FMT_RT_ARGUMENT_NEW_DISPLAY.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args2.len() == 1
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
|
||||
&& let ExprKind::Path(ref qpath3) = inner2.kind
|
||||
&& match_qpath(qpath3, &["x"])
|
||||
&& block.expr.is_none()
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
|
||||
&& name.as_str() == "print_text"
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
&& block1.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e1) = block1.stmts[0].kind
|
||||
&& let ExprKind::Call(func, args) = e1.kind
|
||||
&& let ExprKind::Path(ref qpath1) = func.kind
|
||||
&& match_qpath(qpath1, &["$crate", "io", "_print"])
|
||||
&& paths::STD_IO_STDIO__PRINT.matches_path(cx, func) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Call(func1, args1) = args[0].kind
|
||||
&& let ExprKind::Path(ref qpath2) = func1.kind
|
||||
&& match_qpath(qpath2, &["format_arguments", "new_v1"])
|
||||
&& paths::CORE_FMT_RT_NEW_V1.matches_path(cx, func1) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args1.len() == 2
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
|
||||
&& let ExprKind::Array(elements) = inner.kind
|
||||
|
|
@ -37,12 +35,9 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
&& let ExprKind::Array(elements1) = inner1.kind
|
||||
&& elements1.len() == 1
|
||||
&& let ExprKind::Call(func2, args2) = elements1[0].kind
|
||||
&& let ExprKind::Path(ref qpath3) = func2.kind
|
||||
&& match_qpath(qpath3, &["format_argument", "new_display"])
|
||||
&& paths::CORE_FMT_RT_ARGUMENT_NEW_DISPLAY.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args2.len() == 1
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
|
||||
&& let ExprKind::Path(ref qpath4) = inner2.kind
|
||||
&& match_qpath(qpath4, &["i"])
|
||||
&& block1.expr.is_none()
|
||||
&& block.expr.is_none()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node
|
||||
&& arms.len() == 3
|
||||
&& let PatKind::Expr(lit_expr) = arms[0].pat.kind
|
||||
&& let PatExprKind::Lit{ref lit1, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit1, negated } = lit_expr.kind
|
||||
&& let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node
|
||||
&& arms[0].guard.is_none()
|
||||
&& let ExprKind::Lit(ref lit2) = arms[0].body.kind
|
||||
&& let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node
|
||||
&& let PatKind::Expr(lit_expr1) = arms[1].pat.kind
|
||||
&& let PatExprKind::Lit{ref lit3, negated1 } = lit_expr1.kind
|
||||
&& let PatExprKind::Lit { ref lit3, negated1 } = lit_expr1.kind
|
||||
&& let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node
|
||||
&& arms[1].guard.is_none()
|
||||
&& let ExprKind::Block(block, None) = arms[1].body.kind
|
||||
|
|
@ -23,8 +23,6 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local1.pat.kind
|
||||
&& name.as_str() == "x"
|
||||
&& let Some(trailing_expr) = block.expr
|
||||
&& let ExprKind::Path(ref qpath) = trailing_expr.kind
|
||||
&& match_qpath(qpath, &["x"])
|
||||
&& let PatKind::Wild = arms[2].pat.kind
|
||||
&& arms[2].guard.is_none()
|
||||
&& let ExprKind::Lit(ref lit5) = arms[2].body.kind
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
if let ExprKind::Struct(qpath, fields, None) = expr.kind
|
||||
&& match_qpath(qpath, &["Test"])
|
||||
&& fields.len() == 1
|
||||
&& fields[0].ident.as_str() == "field"
|
||||
&& let ExprKind::If(cond, then, Some(else_expr)) = fields[0].expr.kind
|
||||
|
|
@ -20,11 +19,10 @@ if let ExprKind::Struct(qpath, fields, None) = expr.kind
|
|||
// report your lint here
|
||||
}
|
||||
if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
|
||||
&& match_qpath(qpath, &["Test"])
|
||||
&& fields.len() == 1
|
||||
&& fields[0].ident.as_str() == "field"
|
||||
&& let PatKind::Expr(lit_expr) = fields[0].pat.kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
|
||||
&& arm.guard.is_none()
|
||||
&& let ExprKind::Block(block, None) = arm.body.kind
|
||||
|
|
@ -34,10 +32,9 @@ if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
|
|||
// report your lint here
|
||||
}
|
||||
if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
|
||||
&& match_qpath(qpath, &["TestTuple"])
|
||||
&& fields.len() == 1
|
||||
&& let PatKind::Expr(lit_expr) = fields[0].kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
|
||||
&& arm.guard.is_none()
|
||||
&& let ExprKind::Block(block, None) = arm.body.kind
|
||||
|
|
@ -48,8 +45,6 @@ if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
|
|||
}
|
||||
if let ExprKind::MethodCall(method_name, receiver, args, _) = expr.kind
|
||||
&& method_name.ident.as_str() == "test"
|
||||
&& let ExprKind::Path(ref qpath) = receiver.kind
|
||||
&& match_qpath(qpath, &["test_method_call"])
|
||||
&& args.is_empty()
|
||||
{
|
||||
// report your lint here
|
||||
|
|
|
|||
|
|
@ -51,14 +51,14 @@ pub fn rename_my_lifetimes(_args: TokenStream, input: TokenStream) -> TokenStrea
|
|||
|
||||
fn mut_receiver_of(sig: &mut Signature) -> Option<&mut FnArg> {
|
||||
let arg = sig.inputs.first_mut()?;
|
||||
if let FnArg::Typed(PatType { pat, .. }) = arg {
|
||||
if let Pat::Ident(PatIdent { ident, .. }) = &**pat {
|
||||
if ident == "self" {
|
||||
return Some(arg);
|
||||
}
|
||||
}
|
||||
if let FnArg::Typed(PatType { pat, .. }) = arg
|
||||
&& let Pat::Ident(PatIdent { ident, .. }) = &**pat
|
||||
&& ident == "self"
|
||||
{
|
||||
Some(arg)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
let mut elided = 0;
|
||||
|
|
@ -66,30 +66,29 @@ pub fn rename_my_lifetimes(_args: TokenStream, input: TokenStream) -> TokenStrea
|
|||
|
||||
// Look for methods having arbitrary self type taken by &mut ref
|
||||
for inner in &mut item.items {
|
||||
if let ImplItem::Fn(method) = inner {
|
||||
if let Some(FnArg::Typed(pat_type)) = mut_receiver_of(&mut method.sig) {
|
||||
if let box Type::Reference(reference) = &mut pat_type.ty {
|
||||
// Target only unnamed lifetimes
|
||||
let name = match &reference.lifetime {
|
||||
Some(lt) if lt.ident == "_" => make_name(elided),
|
||||
None => make_name(elided),
|
||||
_ => continue,
|
||||
};
|
||||
elided += 1;
|
||||
if let ImplItem::Fn(method) = inner
|
||||
&& let Some(FnArg::Typed(pat_type)) = mut_receiver_of(&mut method.sig)
|
||||
&& let box Type::Reference(reference) = &mut pat_type.ty
|
||||
{
|
||||
// Target only unnamed lifetimes
|
||||
let name = match &reference.lifetime {
|
||||
Some(lt) if lt.ident == "_" => make_name(elided),
|
||||
None => make_name(elided),
|
||||
_ => continue,
|
||||
};
|
||||
elided += 1;
|
||||
|
||||
// HACK: Syn uses `Span` from the proc_macro2 crate, and does not seem to reexport it.
|
||||
// In order to avoid adding the dependency, get a default span from a nonexistent token.
|
||||
// A default span is needed to mark the code as coming from expansion.
|
||||
let span = Star::default().span();
|
||||
// HACK: Syn uses `Span` from the proc_macro2 crate, and does not seem to reexport it.
|
||||
// In order to avoid adding the dependency, get a default span from a nonexistent token.
|
||||
// A default span is needed to mark the code as coming from expansion.
|
||||
let span = Star::default().span();
|
||||
|
||||
// Replace old lifetime with the named one
|
||||
let lifetime = Lifetime::new(&name, span);
|
||||
reference.lifetime = Some(parse_quote!(#lifetime));
|
||||
// Replace old lifetime with the named one
|
||||
let lifetime = Lifetime::new(&name, span);
|
||||
reference.lifetime = Some(parse_quote!(#lifetime));
|
||||
|
||||
// Add lifetime to the generics of the method
|
||||
method.sig.generics.params.push(parse_quote!(#lifetime));
|
||||
}
|
||||
}
|
||||
// Add lifetime to the generics of the method
|
||||
method.sig.generics.params.push(parse_quote!(#lifetime));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -129,15 +128,15 @@ pub fn fake_desugar_await(_args: TokenStream, input: TokenStream) -> TokenStream
|
|||
let mut async_fn = parse_macro_input!(input as syn::ItemFn);
|
||||
|
||||
for stmt in &mut async_fn.block.stmts {
|
||||
if let syn::Stmt::Expr(syn::Expr::Match(syn::ExprMatch { expr: scrutinee, .. }), _) = stmt {
|
||||
if let syn::Expr::Await(syn::ExprAwait { base, await_token, .. }) = scrutinee.as_mut() {
|
||||
let blc = quote_spanned!( await_token.span => {
|
||||
#[allow(clippy::let_and_return)]
|
||||
let __pinned = #base;
|
||||
__pinned
|
||||
});
|
||||
*scrutinee = parse_quote!(#blc);
|
||||
}
|
||||
if let syn::Stmt::Expr(syn::Expr::Match(syn::ExprMatch { expr: scrutinee, .. }), _) = stmt
|
||||
&& let syn::Expr::Await(syn::ExprAwait { base, await_token, .. }) = scrutinee.as_mut()
|
||||
{
|
||||
let blc = quote_spanned!( await_token.span => {
|
||||
#[allow(clippy::let_and_return)]
|
||||
let __pinned = #base;
|
||||
__pinned
|
||||
});
|
||||
*scrutinee = parse_quote!(#blc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(let_chains)]
|
||||
#![feature(proc_macro_span)]
|
||||
#![allow(clippy::needless_if, dead_code)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(let_chains)]
|
||||
#![warn(clippy::bool_to_int_with_if)]
|
||||
#![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(let_chains)]
|
||||
#![warn(clippy::bool_to_int_with_if)]
|
||||
#![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:14:5
|
||||
--> tests/ui/bool_to_int_with_if.rs:13:5
|
||||
|
|
||||
LL | / if a {
|
||||
LL | |
|
||||
|
|
@ -14,7 +14,7 @@ LL | | };
|
|||
= help: to override `-D warnings` add `#[allow(clippy::bool_to_int_with_if)]`
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:20:5
|
||||
--> tests/ui/bool_to_int_with_if.rs:19:5
|
||||
|
|
||||
LL | / if a {
|
||||
LL | |
|
||||
|
|
@ -27,7 +27,7 @@ LL | | };
|
|||
= note: `!a as i32` or `(!a).into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:26:5
|
||||
--> tests/ui/bool_to_int_with_if.rs:25:5
|
||||
|
|
||||
LL | / if !a {
|
||||
LL | |
|
||||
|
|
@ -40,7 +40,7 @@ LL | | };
|
|||
= note: `!a as i32` or `(!a).into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:32:5
|
||||
--> tests/ui/bool_to_int_with_if.rs:31:5
|
||||
|
|
||||
LL | / if a || b {
|
||||
LL | |
|
||||
|
|
@ -53,7 +53,7 @@ LL | | };
|
|||
= note: `(a || b) as i32` or `(a || b).into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:38:5
|
||||
--> tests/ui/bool_to_int_with_if.rs:37:5
|
||||
|
|
||||
LL | / if cond(a, b) {
|
||||
LL | |
|
||||
|
|
@ -66,7 +66,7 @@ LL | | };
|
|||
= note: `cond(a, b) as i32` or `cond(a, b).into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:44:5
|
||||
--> tests/ui/bool_to_int_with_if.rs:43:5
|
||||
|
|
||||
LL | / if x + y < 4 {
|
||||
LL | |
|
||||
|
|
@ -79,7 +79,7 @@ LL | | };
|
|||
= note: `(x + y < 4) as i32` or `(x + y < 4).into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:54:12
|
||||
--> tests/ui/bool_to_int_with_if.rs:53:12
|
||||
|
|
||||
LL | } else if b {
|
||||
| ____________^
|
||||
|
|
@ -93,7 +93,7 @@ LL | | };
|
|||
= note: `b as i32` or `b.into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:64:12
|
||||
--> tests/ui/bool_to_int_with_if.rs:63:12
|
||||
|
|
||||
LL | } else if b {
|
||||
| ____________^
|
||||
|
|
@ -107,7 +107,7 @@ LL | | };
|
|||
= note: `!b as i32` or `(!b).into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:130:5
|
||||
--> tests/ui/bool_to_int_with_if.rs:129:5
|
||||
|
|
||||
LL | if a { 1 } else { 0 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)`
|
||||
|
|
@ -115,7 +115,7 @@ LL | if a { 1 } else { 0 }
|
|||
= note: `a as u8` or `a.into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:174:13
|
||||
--> tests/ui/bool_to_int_with_if.rs:173:13
|
||||
|
|
||||
LL | let _ = if dbg!(4 > 0) { 1 } else { 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `i32::from(dbg!(4 > 0))`
|
||||
|
|
@ -123,7 +123,7 @@ LL | let _ = if dbg!(4 > 0) { 1 } else { 0 };
|
|||
= note: `dbg!(4 > 0) as i32` or `dbg!(4 > 0).into()` can also be valid options
|
||||
|
||||
error: boolean to int conversion using if
|
||||
--> tests/ui/bool_to_int_with_if.rs:177:18
|
||||
--> tests/ui/bool_to_int_with_if.rs:176:18
|
||||
|
|
||||
LL | let _ = dbg!(if 4 > 0 { 1 } else { 0 });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `i32::from(4 > 0)`
|
||||
|
|
|
|||
|
|
@ -188,6 +188,91 @@ fn issue11371() {
|
|||
}
|
||||
}
|
||||
|
||||
fn gen_option() -> Option<()> {
|
||||
Some(())
|
||||
// Or None
|
||||
}
|
||||
|
||||
fn gen_result() -> Result<(), ()> {
|
||||
Ok(())
|
||||
// Or Err(())
|
||||
}
|
||||
|
||||
fn issue14725() {
|
||||
let option = Some(());
|
||||
|
||||
if option.is_some() {
|
||||
let _ = option.as_ref().unwrap();
|
||||
//~^ unnecessary_unwrap
|
||||
} else {
|
||||
let _ = option.as_ref().unwrap();
|
||||
//~^ panicking_unwrap
|
||||
}
|
||||
|
||||
let result = Ok::<(), ()>(());
|
||||
|
||||
if result.is_ok() {
|
||||
let _y = 1;
|
||||
result.as_ref().unwrap();
|
||||
//~^ unnecessary_unwrap
|
||||
} else {
|
||||
let _y = 1;
|
||||
result.as_ref().unwrap();
|
||||
//~^ panicking_unwrap
|
||||
}
|
||||
|
||||
let mut option = Some(());
|
||||
if option.is_some() {
|
||||
option = gen_option();
|
||||
option.as_mut().unwrap();
|
||||
} else {
|
||||
option = gen_option();
|
||||
option.as_mut().unwrap();
|
||||
}
|
||||
|
||||
let mut result = Ok::<(), ()>(());
|
||||
if result.is_ok() {
|
||||
result = gen_result();
|
||||
result.as_mut().unwrap();
|
||||
} else {
|
||||
result = gen_result();
|
||||
result.as_mut().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn issue14763(x: Option<String>, r: Result<(), ()>) {
|
||||
_ = || {
|
||||
if x.is_some() {
|
||||
_ = x.unwrap();
|
||||
//~^ unnecessary_unwrap
|
||||
} else {
|
||||
_ = x.unwrap();
|
||||
//~^ panicking_unwrap
|
||||
}
|
||||
};
|
||||
_ = || {
|
||||
if r.is_ok() {
|
||||
_ = r.as_ref().unwrap();
|
||||
//~^ unnecessary_unwrap
|
||||
} else {
|
||||
_ = r.as_ref().unwrap();
|
||||
//~^ panicking_unwrap
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const ISSUE14763: fn(Option<String>) = |x| {
|
||||
_ = || {
|
||||
if x.is_some() {
|
||||
_ = x.unwrap();
|
||||
//~^ unnecessary_unwrap
|
||||
} else {
|
||||
_ = x.unwrap();
|
||||
//~^ panicking_unwrap
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn check_expect() {
|
||||
let x = Some(());
|
||||
if x.is_some() {
|
||||
|
|
|
|||
|
|
@ -236,6 +236,92 @@ LL | if result.is_ok() {
|
|||
LL | result.as_mut().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `option` after checking its variant with `is_some`
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:205:17
|
||||
|
|
||||
LL | if option.is_some() {
|
||||
| ------------------- help: try: `if let Some(<item>) = &option`
|
||||
LL | let _ = option.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:208:17
|
||||
|
|
||||
LL | if option.is_some() {
|
||||
| ---------------- because of this check
|
||||
...
|
||||
LL | let _ = option.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `result` after checking its variant with `is_ok`
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:216:9
|
||||
|
|
||||
LL | if result.is_ok() {
|
||||
| ----------------- help: try: `if let Ok(<item>) = &result`
|
||||
LL | let _y = 1;
|
||||
LL | result.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:220:9
|
||||
|
|
||||
LL | if result.is_ok() {
|
||||
| -------------- because of this check
|
||||
...
|
||||
LL | result.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `x` after checking its variant with `is_some`
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:246:17
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| -------------- help: try: `if let Some(<item>) = x`
|
||||
LL | _ = x.unwrap();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:249:17
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| ----------- because of this check
|
||||
...
|
||||
LL | _ = x.unwrap();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `r` after checking its variant with `is_ok`
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:255:17
|
||||
|
|
||||
LL | if r.is_ok() {
|
||||
| ------------ help: try: `if let Ok(<item>) = &r`
|
||||
LL | _ = r.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:258:17
|
||||
|
|
||||
LL | if r.is_ok() {
|
||||
| --------- because of this check
|
||||
...
|
||||
LL | _ = r.as_ref().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `x` after checking its variant with `is_some`
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:267:17
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| -------------- help: try: `if let Some(<item>) = x`
|
||||
LL | _ = x.unwrap();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:270:17
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| ----------- because of this check
|
||||
...
|
||||
LL | _ = x.unwrap();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: creating a shared reference to mutable static
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:183:12
|
||||
|
|
||||
|
|
@ -246,5 +332,5 @@ LL | if X.is_some() {
|
|||
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
|
||||
= note: `#[deny(static_mut_refs)]` on by default
|
||||
|
||||
error: aborting due to 26 previous errors
|
||||
error: aborting due to 36 previous errors
|
||||
|
||||
|
|
|
|||
64
tests/ui/cloned_ref_to_slice_refs.fixed
Normal file
64
tests/ui/cloned_ref_to_slice_refs.fixed
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#![warn(clippy::cloned_ref_to_slice_refs)]
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Data;
|
||||
|
||||
fn main() {
|
||||
{
|
||||
let data = Data;
|
||||
let data_ref = &data;
|
||||
let _ = std::slice::from_ref(data_ref); //~ ERROR: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
}
|
||||
|
||||
{
|
||||
let _ = std::slice::from_ref(&Data); //~ ERROR: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
}
|
||||
|
||||
{
|
||||
#[derive(Clone)]
|
||||
struct Point(i32, i32);
|
||||
|
||||
let _ = std::slice::from_ref(&Point(0, 0)); //~ ERROR: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
}
|
||||
|
||||
// the string was cloned with the intention to not mutate
|
||||
{
|
||||
struct BetterString(String);
|
||||
|
||||
let mut message = String::from("good");
|
||||
let sender = BetterString(message.clone());
|
||||
|
||||
message.push_str("bye!");
|
||||
|
||||
println!("{} {}", message, sender.0)
|
||||
}
|
||||
|
||||
// the string was cloned with the intention to not mutate
|
||||
{
|
||||
let mut x = String::from("Hello");
|
||||
let r = &[x.clone()];
|
||||
x.push('!');
|
||||
println!("r = `{}', x = `{x}'", r[0]);
|
||||
}
|
||||
|
||||
// mutable borrows may have the intention to clone
|
||||
{
|
||||
let data = Data;
|
||||
let data_ref = &data;
|
||||
let _ = &mut [data_ref.clone()];
|
||||
}
|
||||
|
||||
// `T::clone` is used to denote a clone with side effects
|
||||
{
|
||||
use std::sync::Arc;
|
||||
let data = Arc::new(Data);
|
||||
let _ = &[Arc::clone(&data)];
|
||||
}
|
||||
|
||||
// slices with multiple members can only be made from a singular reference
|
||||
{
|
||||
let data_1 = Data;
|
||||
let data_2 = Data;
|
||||
let _ = &[data_1.clone(), data_2.clone()];
|
||||
}
|
||||
}
|
||||
64
tests/ui/cloned_ref_to_slice_refs.rs
Normal file
64
tests/ui/cloned_ref_to_slice_refs.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#![warn(clippy::cloned_ref_to_slice_refs)]
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Data;
|
||||
|
||||
fn main() {
|
||||
{
|
||||
let data = Data;
|
||||
let data_ref = &data;
|
||||
let _ = &[data_ref.clone()]; //~ ERROR: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
}
|
||||
|
||||
{
|
||||
let _ = &[Data.clone()]; //~ ERROR: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
}
|
||||
|
||||
{
|
||||
#[derive(Clone)]
|
||||
struct Point(i32, i32);
|
||||
|
||||
let _ = &[Point(0, 0).clone()]; //~ ERROR: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
}
|
||||
|
||||
// the string was cloned with the intention to not mutate
|
||||
{
|
||||
struct BetterString(String);
|
||||
|
||||
let mut message = String::from("good");
|
||||
let sender = BetterString(message.clone());
|
||||
|
||||
message.push_str("bye!");
|
||||
|
||||
println!("{} {}", message, sender.0)
|
||||
}
|
||||
|
||||
// the string was cloned with the intention to not mutate
|
||||
{
|
||||
let mut x = String::from("Hello");
|
||||
let r = &[x.clone()];
|
||||
x.push('!');
|
||||
println!("r = `{}', x = `{x}'", r[0]);
|
||||
}
|
||||
|
||||
// mutable borrows may have the intention to clone
|
||||
{
|
||||
let data = Data;
|
||||
let data_ref = &data;
|
||||
let _ = &mut [data_ref.clone()];
|
||||
}
|
||||
|
||||
// `T::clone` is used to denote a clone with side effects
|
||||
{
|
||||
use std::sync::Arc;
|
||||
let data = Arc::new(Data);
|
||||
let _ = &[Arc::clone(&data)];
|
||||
}
|
||||
|
||||
// slices with multiple members can only be made from a singular reference
|
||||
{
|
||||
let data_1 = Data;
|
||||
let data_2 = Data;
|
||||
let _ = &[data_1.clone(), data_2.clone()];
|
||||
}
|
||||
}
|
||||
23
tests/ui/cloned_ref_to_slice_refs.stderr
Normal file
23
tests/ui/cloned_ref_to_slice_refs.stderr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
error: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
--> tests/ui/cloned_ref_to_slice_refs.rs:10:17
|
||||
|
|
||||
LL | let _ = &[data_ref.clone()];
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::slice::from_ref(data_ref)`
|
||||
|
|
||||
= note: `-D clippy::cloned-ref-to-slice-refs` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::cloned_ref_to_slice_refs)]`
|
||||
|
||||
error: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
--> tests/ui/cloned_ref_to_slice_refs.rs:14:17
|
||||
|
|
||||
LL | let _ = &[Data.clone()];
|
||||
| ^^^^^^^^^^^^^^^ help: try: `std::slice::from_ref(&Data)`
|
||||
|
||||
error: this call to `clone` can be replaced with `std::slice::from_ref`
|
||||
--> tests/ui/cloned_ref_to_slice_refs.rs:21:17
|
||||
|
|
||||
LL | let _ = &[Point(0, 0).clone()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::slice::from_ref(&Point(0, 0))`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -101,27 +101,8 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
// Test behavior wrt. `let_chains`.
|
||||
// None of the cases below should be collapsed.
|
||||
fn truth() -> bool { true }
|
||||
|
||||
// Prefix:
|
||||
if let 0 = 1 {
|
||||
if truth() {}
|
||||
}
|
||||
|
||||
// Suffix:
|
||||
if truth() {
|
||||
if let 0 = 1 {}
|
||||
}
|
||||
|
||||
// Midfix:
|
||||
if truth() {
|
||||
if let 0 = 1 {
|
||||
if truth() {}
|
||||
}
|
||||
}
|
||||
|
||||
// Fix #5962
|
||||
if matches!(true, true)
|
||||
&& matches!(true, true) {}
|
||||
|
|
@ -162,3 +143,14 @@ fn layout_check() -> u32 {
|
|||
; 3
|
||||
//~^^^^^ collapsible_if
|
||||
}
|
||||
|
||||
fn issue14722() {
|
||||
let x = if true {
|
||||
Some(1)
|
||||
} else {
|
||||
if true {
|
||||
println!("Some debug information");
|
||||
};
|
||||
None
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,27 +108,8 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
// Test behavior wrt. `let_chains`.
|
||||
// None of the cases below should be collapsed.
|
||||
fn truth() -> bool { true }
|
||||
|
||||
// Prefix:
|
||||
if let 0 = 1 {
|
||||
if truth() {}
|
||||
}
|
||||
|
||||
// Suffix:
|
||||
if truth() {
|
||||
if let 0 = 1 {}
|
||||
}
|
||||
|
||||
// Midfix:
|
||||
if truth() {
|
||||
if let 0 = 1 {
|
||||
if truth() {}
|
||||
}
|
||||
}
|
||||
|
||||
// Fix #5962
|
||||
if matches!(true, true) {
|
||||
if matches!(true, true) {}
|
||||
|
|
@ -172,3 +153,14 @@ fn layout_check() -> u32 {
|
|||
}; 3
|
||||
//~^^^^^ collapsible_if
|
||||
}
|
||||
|
||||
fn issue14722() {
|
||||
let x = if true {
|
||||
Some(1)
|
||||
} else {
|
||||
if true {
|
||||
println!("Some debug information");
|
||||
};
|
||||
None
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ LL ~ }
|
|||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if.rs:133:5
|
||||
--> tests/ui/collapsible_if.rs:114:5
|
||||
|
|
||||
LL | / if matches!(true, true) {
|
||||
LL | | if matches!(true, true) {}
|
||||
|
|
@ -141,7 +141,7 @@ LL ~ && matches!(true, true) {}
|
|||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if.rs:139:5
|
||||
--> tests/ui/collapsible_if.rs:120:5
|
||||
|
|
||||
LL | / if matches!(true, true) && truth() {
|
||||
LL | | if matches!(true, true) {}
|
||||
|
|
@ -155,7 +155,7 @@ LL ~ && matches!(true, true) {}
|
|||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if.rs:151:5
|
||||
--> tests/ui/collapsible_if.rs:132:5
|
||||
|
|
||||
LL | / if true {
|
||||
LL | | if true {
|
||||
|
|
@ -173,7 +173,7 @@ LL ~ }
|
|||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if.rs:168:5
|
||||
--> tests/ui/collapsible_if.rs:149:5
|
||||
|
|
||||
LL | / if true {
|
||||
LL | | if true {
|
||||
|
|
|
|||
68
tests/ui/collapsible_if_let_chains.edition2024.fixed
Normal file
68
tests/ui/collapsible_if_let_chains.edition2024.fixed
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
//@revisions: edition2021 edition2024
|
||||
//@[edition2021] edition:2021
|
||||
//@[edition2024] edition:2024
|
||||
//@[edition2021] check-pass
|
||||
|
||||
#![warn(clippy::collapsible_if)]
|
||||
|
||||
fn main() {
|
||||
if let Some(a) = Some(3) {
|
||||
// with comment, so do not lint
|
||||
if let Some(b) = Some(4) {
|
||||
let _ = a + b;
|
||||
}
|
||||
}
|
||||
|
||||
//~[edition2024]v collapsible_if
|
||||
if let Some(a) = Some(3)
|
||||
&& let Some(b) = Some(4) {
|
||||
let _ = a + b;
|
||||
}
|
||||
|
||||
//~[edition2024]v collapsible_if
|
||||
if let Some(a) = Some(3)
|
||||
&& a + 1 == 4 {
|
||||
let _ = a;
|
||||
}
|
||||
|
||||
//~[edition2024]v collapsible_if
|
||||
if Some(3) == Some(4).map(|x| x - 1)
|
||||
&& let Some(b) = Some(4) {
|
||||
let _ = b;
|
||||
}
|
||||
|
||||
fn truth() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// Prefix:
|
||||
//~[edition2024]v collapsible_if
|
||||
if let 0 = 1
|
||||
&& truth() {}
|
||||
|
||||
// Suffix:
|
||||
//~[edition2024]v collapsible_if
|
||||
if truth()
|
||||
&& let 0 = 1 {}
|
||||
|
||||
// Midfix:
|
||||
//~[edition2024]vvv collapsible_if
|
||||
//~[edition2024]v collapsible_if
|
||||
if truth()
|
||||
&& let 0 = 1
|
||||
&& truth() {}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.87.0"]
|
||||
fn msrv_1_87() {
|
||||
if let 0 = 1 {
|
||||
if true {}
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.88.0"]
|
||||
fn msrv_1_88() {
|
||||
//~[edition2024]v collapsible_if
|
||||
if let 0 = 1
|
||||
&& true {}
|
||||
}
|
||||
132
tests/ui/collapsible_if_let_chains.edition2024.stderr
Normal file
132
tests/ui/collapsible_if_let_chains.edition2024.stderr
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:17:5
|
||||
|
|
||||
LL | / if let Some(a) = Some(3) {
|
||||
LL | | if let Some(b) = Some(4) {
|
||||
LL | | let _ = a + b;
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::collapsible-if` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]`
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if let Some(a) = Some(3)
|
||||
LL ~ && let Some(b) = Some(4) {
|
||||
LL | let _ = a + b;
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:24:5
|
||||
|
|
||||
LL | / if let Some(a) = Some(3) {
|
||||
LL | | if a + 1 == 4 {
|
||||
LL | | let _ = a;
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if let Some(a) = Some(3)
|
||||
LL ~ && a + 1 == 4 {
|
||||
LL | let _ = a;
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:31:5
|
||||
|
|
||||
LL | / if Some(3) == Some(4).map(|x| x - 1) {
|
||||
LL | | if let Some(b) = Some(4) {
|
||||
LL | | let _ = b;
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if Some(3) == Some(4).map(|x| x - 1)
|
||||
LL ~ && let Some(b) = Some(4) {
|
||||
LL | let _ = b;
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:43:5
|
||||
|
|
||||
LL | / if let 0 = 1 {
|
||||
LL | | if truth() {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if let 0 = 1
|
||||
LL ~ && truth() {}
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:49:5
|
||||
|
|
||||
LL | / if truth() {
|
||||
LL | | if let 0 = 1 {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if truth()
|
||||
LL ~ && let 0 = 1 {}
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:56:5
|
||||
|
|
||||
LL | / if truth() {
|
||||
LL | | if let 0 = 1 {
|
||||
LL | | if truth() {}
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if truth()
|
||||
LL ~ && let 0 = 1 {
|
||||
LL | if truth() {}
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:57:9
|
||||
|
|
||||
LL | / if let 0 = 1 {
|
||||
LL | | if truth() {}
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if let 0 = 1
|
||||
LL ~ && truth() {}
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:73:5
|
||||
|
|
||||
LL | / if let 0 = 1 {
|
||||
LL | | if true {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if let 0 = 1
|
||||
LL ~ && true {}
|
||||
|
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#![feature(let_chains)]
|
||||
#![warn(clippy::collapsible_if)]
|
||||
|
||||
fn main() {
|
||||
if let Some(a) = Some(3) {
|
||||
// with comment, so do not lint
|
||||
if let Some(b) = Some(4) {
|
||||
let _ = a + b;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(a) = Some(3)
|
||||
&& let Some(b) = Some(4) {
|
||||
let _ = a + b;
|
||||
}
|
||||
//~^^^^^ collapsible_if
|
||||
|
||||
if let Some(a) = Some(3)
|
||||
&& a + 1 == 4 {
|
||||
let _ = a;
|
||||
}
|
||||
//~^^^^^ collapsible_if
|
||||
|
||||
if Some(3) == Some(4).map(|x| x - 1)
|
||||
&& let Some(b) = Some(4) {
|
||||
let _ = b;
|
||||
}
|
||||
//~^^^^^ collapsible_if
|
||||
}
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
#![feature(let_chains)]
|
||||
//@revisions: edition2021 edition2024
|
||||
//@[edition2021] edition:2021
|
||||
//@[edition2024] edition:2024
|
||||
//@[edition2021] check-pass
|
||||
|
||||
#![warn(clippy::collapsible_if)]
|
||||
|
||||
fn main() {
|
||||
|
|
@ -9,24 +13,64 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
//~[edition2024]v collapsible_if
|
||||
if let Some(a) = Some(3) {
|
||||
if let Some(b) = Some(4) {
|
||||
let _ = a + b;
|
||||
}
|
||||
}
|
||||
//~^^^^^ collapsible_if
|
||||
|
||||
//~[edition2024]v collapsible_if
|
||||
if let Some(a) = Some(3) {
|
||||
if a + 1 == 4 {
|
||||
let _ = a;
|
||||
}
|
||||
}
|
||||
//~^^^^^ collapsible_if
|
||||
|
||||
//~[edition2024]v collapsible_if
|
||||
if Some(3) == Some(4).map(|x| x - 1) {
|
||||
if let Some(b) = Some(4) {
|
||||
let _ = b;
|
||||
}
|
||||
}
|
||||
//~^^^^^ collapsible_if
|
||||
|
||||
fn truth() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// Prefix:
|
||||
//~[edition2024]v collapsible_if
|
||||
if let 0 = 1 {
|
||||
if truth() {}
|
||||
}
|
||||
|
||||
// Suffix:
|
||||
//~[edition2024]v collapsible_if
|
||||
if truth() {
|
||||
if let 0 = 1 {}
|
||||
}
|
||||
|
||||
// Midfix:
|
||||
//~[edition2024]vvv collapsible_if
|
||||
//~[edition2024]v collapsible_if
|
||||
if truth() {
|
||||
if let 0 = 1 {
|
||||
if truth() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.87.0"]
|
||||
fn msrv_1_87() {
|
||||
if let 0 = 1 {
|
||||
if true {}
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.88.0"]
|
||||
fn msrv_1_88() {
|
||||
//~[edition2024]v collapsible_if
|
||||
if let 0 = 1 {
|
||||
if true {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:12:5
|
||||
|
|
||||
LL | / if let Some(a) = Some(3) {
|
||||
LL | | if let Some(b) = Some(4) {
|
||||
LL | | let _ = a + b;
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::collapsible-if` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]`
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if let Some(a) = Some(3)
|
||||
LL ~ && let Some(b) = Some(4) {
|
||||
LL | let _ = a + b;
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:19:5
|
||||
|
|
||||
LL | / if let Some(a) = Some(3) {
|
||||
LL | | if a + 1 == 4 {
|
||||
LL | | let _ = a;
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if let Some(a) = Some(3)
|
||||
LL ~ && a + 1 == 4 {
|
||||
LL | let _ = a;
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: this `if` statement can be collapsed
|
||||
--> tests/ui/collapsible_if_let_chains.rs:26:5
|
||||
|
|
||||
LL | / if Some(3) == Some(4).map(|x| x - 1) {
|
||||
LL | | if let Some(b) = Some(4) {
|
||||
LL | | let _ = b;
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: collapse nested if block
|
||||
|
|
||||
LL ~ if Some(3) == Some(4).map(|x| x - 1)
|
||||
LL ~ && let Some(b) = Some(4) {
|
||||
LL | let _ = b;
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#![warn(clippy::collapsible_match)]
|
||||
#![allow(
|
||||
clippy::collapsible_if,
|
||||
clippy::equatable_if_let,
|
||||
clippy::needless_return,
|
||||
clippy::no_effect,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this `match` can be collapsed into the outer `match`
|
||||
--> tests/ui/collapsible_match.rs:14:20
|
||||
--> tests/ui/collapsible_match.rs:15:20
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ____________________^
|
||||
|
|
@ -10,7 +10,7 @@ LL | | },
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:14:12
|
||||
--> tests/ui/collapsible_match.rs:15:12
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -21,7 +21,7 @@ LL | Some(n) => foo(n),
|
|||
= help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]`
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> tests/ui/collapsible_match.rs:24:20
|
||||
--> tests/ui/collapsible_match.rs:25:20
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ____________________^
|
||||
|
|
@ -32,7 +32,7 @@ LL | | },
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:24:12
|
||||
--> tests/ui/collapsible_match.rs:25:12
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -41,7 +41,7 @@ LL | Some(n) => foo(n),
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> tests/ui/collapsible_match.rs:34:9
|
||||
--> tests/ui/collapsible_match.rs:35:9
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
|
|
@ -51,7 +51,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:33:15
|
||||
--> tests/ui/collapsible_match.rs:34:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -59,7 +59,7 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> tests/ui/collapsible_match.rs:43:9
|
||||
--> tests/ui/collapsible_match.rs:44:9
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
|
|
@ -71,7 +71,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:42:15
|
||||
--> tests/ui/collapsible_match.rs:43:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -79,7 +79,7 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `if let`
|
||||
--> tests/ui/collapsible_match.rs:56:9
|
||||
--> tests/ui/collapsible_match.rs:57:9
|
||||
|
|
||||
LL | / match val {
|
||||
LL | |
|
||||
|
|
@ -89,7 +89,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:55:15
|
||||
--> tests/ui/collapsible_match.rs:56:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -98,7 +98,7 @@ LL | Some(n) => foo(n),
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `match`
|
||||
--> tests/ui/collapsible_match.rs:66:13
|
||||
--> tests/ui/collapsible_match.rs:67:13
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
|
|
@ -108,7 +108,7 @@ LL | | }
|
|||
| |_____________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:65:12
|
||||
--> tests/ui/collapsible_match.rs:66:12
|
||||
|
|
||||
LL | Ok(val) => {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -116,7 +116,7 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `if let`
|
||||
--> tests/ui/collapsible_match.rs:77:9
|
||||
--> tests/ui/collapsible_match.rs:78:9
|
||||
|
|
||||
LL | / match val {
|
||||
LL | |
|
||||
|
|
@ -126,7 +126,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:76:15
|
||||
--> tests/ui/collapsible_match.rs:77:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -135,7 +135,7 @@ LL | Some(n) => foo(n),
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `match`
|
||||
--> tests/ui/collapsible_match.rs:89:13
|
||||
--> tests/ui/collapsible_match.rs:90:13
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
|
|
@ -147,7 +147,7 @@ LL | | }
|
|||
| |_____________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:88:12
|
||||
--> tests/ui/collapsible_match.rs:89:12
|
||||
|
|
||||
LL | Ok(val) => {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -155,7 +155,7 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> tests/ui/collapsible_match.rs:102:20
|
||||
--> tests/ui/collapsible_match.rs:103:20
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ____________________^
|
||||
|
|
@ -166,7 +166,7 @@ LL | | },
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:102:12
|
||||
--> tests/ui/collapsible_match.rs:103:12
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -175,7 +175,7 @@ LL | Some(n) => foo(n),
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> tests/ui/collapsible_match.rs:112:22
|
||||
--> tests/ui/collapsible_match.rs:113:22
|
||||
|
|
||||
LL | Some(val) => match val {
|
||||
| ______________________^
|
||||
|
|
@ -186,7 +186,7 @@ LL | | },
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:112:14
|
||||
--> tests/ui/collapsible_match.rs:113:14
|
||||
|
|
||||
LL | Some(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -195,7 +195,7 @@ LL | Some(n) => foo(n),
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> tests/ui/collapsible_match.rs:256:22
|
||||
--> tests/ui/collapsible_match.rs:257:22
|
||||
|
|
||||
LL | Some(val) => match val {
|
||||
| ______________________^
|
||||
|
|
@ -206,7 +206,7 @@ LL | | },
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:256:14
|
||||
--> tests/ui/collapsible_match.rs:257:14
|
||||
|
|
||||
LL | Some(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
|
|
@ -215,7 +215,7 @@ LL | E::A(val) | E::B(val) => foo(val),
|
|||
| ^^^^^^^^^^^^^^^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> tests/ui/collapsible_match.rs:288:9
|
||||
--> tests/ui/collapsible_match.rs:289:9
|
||||
|
|
||||
LL | / if let Some(u) = a {
|
||||
LL | |
|
||||
|
|
@ -225,7 +225,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:287:27
|
||||
--> tests/ui/collapsible_match.rs:288:27
|
||||
|
|
||||
LL | if let Issue9647::A { a, .. } = x {
|
||||
| ^ replace this binding
|
||||
|
|
@ -233,7 +233,7 @@ LL | if let Some(u) = a {
|
|||
| ^^^^^^^ with this pattern, prefixed by `a`:
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> tests/ui/collapsible_match.rs:298:9
|
||||
--> tests/ui/collapsible_match.rs:299:9
|
||||
|
|
||||
LL | / if let Some(u) = a {
|
||||
LL | |
|
||||
|
|
@ -243,7 +243,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> tests/ui/collapsible_match.rs:297:35
|
||||
--> tests/ui/collapsible_match.rs:298:35
|
||||
|
|
||||
LL | if let Issue9647::A { a: Some(a), .. } = x {
|
||||
| ^ replace this binding
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#![warn(clippy::comparison_to_empty)]
|
||||
#![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
fn main() {
|
||||
// Disallow comparisons to empty
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#![warn(clippy::comparison_to_empty)]
|
||||
#![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
fn main() {
|
||||
// Disallow comparisons to empty
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:8:13
|
||||
--> tests/ui/comparison_to_empty.rs:7:13
|
||||
|
|
||||
LL | let _ = s == "";
|
||||
| ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
|
@ -8,73 +8,73 @@ LL | let _ = s == "";
|
|||
= help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:10:13
|
||||
--> tests/ui/comparison_to_empty.rs:9:13
|
||||
|
|
||||
LL | let _ = s != "";
|
||||
| ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:14:13
|
||||
--> tests/ui/comparison_to_empty.rs:13:13
|
||||
|
|
||||
LL | let _ = v == [];
|
||||
| ^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:16:13
|
||||
--> tests/ui/comparison_to_empty.rs:15:13
|
||||
|
|
||||
LL | let _ = v != [];
|
||||
| ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()`
|
||||
|
||||
error: comparison to empty slice using `if let`
|
||||
--> tests/ui/comparison_to_empty.rs:18:8
|
||||
--> tests/ui/comparison_to_empty.rs:17:8
|
||||
|
|
||||
LL | if let [] = &*v {}
|
||||
| ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(*v).is_empty()`
|
||||
|
||||
error: comparison to empty slice using `if let`
|
||||
--> tests/ui/comparison_to_empty.rs:21:8
|
||||
--> tests/ui/comparison_to_empty.rs:20:8
|
||||
|
|
||||
LL | if let [] = s {}
|
||||
| ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
||||
error: comparison to empty slice using `if let`
|
||||
--> tests/ui/comparison_to_empty.rs:23:8
|
||||
--> tests/ui/comparison_to_empty.rs:22:8
|
||||
|
|
||||
LL | if let [] = &*s {}
|
||||
| ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
||||
error: comparison to empty slice using `if let`
|
||||
--> tests/ui/comparison_to_empty.rs:25:8
|
||||
--> tests/ui/comparison_to_empty.rs:24:8
|
||||
|
|
||||
LL | if let [] = &*s
|
||||
| ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:27:12
|
||||
--> tests/ui/comparison_to_empty.rs:26:12
|
||||
|
|
||||
LL | && s == []
|
||||
| ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:48:13
|
||||
--> tests/ui/comparison_to_empty.rs:47:13
|
||||
|
|
||||
LL | let _ = s.eq("");
|
||||
| ^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:50:13
|
||||
--> tests/ui/comparison_to_empty.rs:49:13
|
||||
|
|
||||
LL | let _ = s.ne("");
|
||||
| ^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:53:13
|
||||
--> tests/ui/comparison_to_empty.rs:52:13
|
||||
|
|
||||
LL | let _ = v.eq(&[]);
|
||||
| ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:55:13
|
||||
--> tests/ui/comparison_to_empty.rs:54:13
|
||||
|
|
||||
LL | let _ = v.ne(&[]);
|
||||
| ^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()`
|
||||
|
|
|
|||
14
tests/ui/confusing_method_to_numeric_cast.fixed
Normal file
14
tests/ui/confusing_method_to_numeric_cast.fixed
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#![feature(float_minimum_maximum)]
|
||||
#![warn(clippy::confusing_method_to_numeric_cast)]
|
||||
|
||||
fn main() {
|
||||
let _ = u16::MAX as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = u16::MIN as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = u16::MAX as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = u16::MIN as usize; //~ confusing_method_to_numeric_cast
|
||||
|
||||
let _ = f32::MAX as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = f32::MAX as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = f32::MIN as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = f32::MIN as usize; //~ confusing_method_to_numeric_cast
|
||||
}
|
||||
14
tests/ui/confusing_method_to_numeric_cast.rs
Normal file
14
tests/ui/confusing_method_to_numeric_cast.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#![feature(float_minimum_maximum)]
|
||||
#![warn(clippy::confusing_method_to_numeric_cast)]
|
||||
|
||||
fn main() {
|
||||
let _ = u16::max as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = u16::min as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = u16::max_value as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = u16::min_value as usize; //~ confusing_method_to_numeric_cast
|
||||
|
||||
let _ = f32::maximum as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = f32::max as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = f32::minimum as usize; //~ confusing_method_to_numeric_cast
|
||||
let _ = f32::min as usize; //~ confusing_method_to_numeric_cast
|
||||
}
|
||||
100
tests/ui/confusing_method_to_numeric_cast.stderr
Normal file
100
tests/ui/confusing_method_to_numeric_cast.stderr
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
error: casting function pointer `u16::max` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:5:13
|
||||
|
|
||||
LL | let _ = u16::max as usize;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::confusing-method-to-numeric-cast` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::confusing_method_to_numeric_cast)]`
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = u16::max as usize;
|
||||
LL + let _ = u16::MAX as usize;
|
||||
|
|
||||
|
||||
error: casting function pointer `u16::min` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:6:13
|
||||
|
|
||||
LL | let _ = u16::min as usize;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = u16::min as usize;
|
||||
LL + let _ = u16::MIN as usize;
|
||||
|
|
||||
|
||||
error: casting function pointer `u16::max_value` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:7:13
|
||||
|
|
||||
LL | let _ = u16::max_value as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = u16::max_value as usize;
|
||||
LL + let _ = u16::MAX as usize;
|
||||
|
|
||||
|
||||
error: casting function pointer `u16::min_value` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:8:13
|
||||
|
|
||||
LL | let _ = u16::min_value as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = u16::min_value as usize;
|
||||
LL + let _ = u16::MIN as usize;
|
||||
|
|
||||
|
||||
error: casting function pointer `f32::maximum` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:10:13
|
||||
|
|
||||
LL | let _ = f32::maximum as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = f32::maximum as usize;
|
||||
LL + let _ = f32::MAX as usize;
|
||||
|
|
||||
|
||||
error: casting function pointer `f32::max` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:11:13
|
||||
|
|
||||
LL | let _ = f32::max as usize;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = f32::max as usize;
|
||||
LL + let _ = f32::MAX as usize;
|
||||
|
|
||||
|
||||
error: casting function pointer `f32::minimum` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:12:13
|
||||
|
|
||||
LL | let _ = f32::minimum as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = f32::minimum as usize;
|
||||
LL + let _ = f32::MIN as usize;
|
||||
|
|
||||
|
||||
error: casting function pointer `f32::min` to `usize`
|
||||
--> tests/ui/confusing_method_to_numeric_cast.rs:13:13
|
||||
|
|
||||
LL | let _ = f32::min as usize;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: did you mean to use the associated constant?
|
||||
|
|
||||
LL - let _ = f32::min as usize;
|
||||
LL + let _ = f32::MIN as usize;
|
||||
|
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
13
tests/ui/crashes/missing_const_for_fn_14774.fixed
Normal file
13
tests/ui/crashes/missing_const_for_fn_14774.fixed
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//@compile-flags: -Z validate-mir
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
|
||||
static BLOCK_FN_DEF: fn(usize) -> usize = {
|
||||
//~v missing_const_for_fn
|
||||
const fn foo(a: usize) -> usize {
|
||||
a + 10
|
||||
}
|
||||
foo
|
||||
};
|
||||
struct X;
|
||||
|
||||
fn main() {}
|
||||
13
tests/ui/crashes/missing_const_for_fn_14774.rs
Normal file
13
tests/ui/crashes/missing_const_for_fn_14774.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//@compile-flags: -Z validate-mir
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
|
||||
static BLOCK_FN_DEF: fn(usize) -> usize = {
|
||||
//~v missing_const_for_fn
|
||||
fn foo(a: usize) -> usize {
|
||||
a + 10
|
||||
}
|
||||
foo
|
||||
};
|
||||
struct X;
|
||||
|
||||
fn main() {}
|
||||
17
tests/ui/crashes/missing_const_for_fn_14774.stderr
Normal file
17
tests/ui/crashes/missing_const_for_fn_14774.stderr
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
error: this could be a `const fn`
|
||||
--> tests/ui/crashes/missing_const_for_fn_14774.rs:6:5
|
||||
|
|
||||
LL | / fn foo(a: usize) -> usize {
|
||||
LL | | a + 10
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::missing-const-for-fn` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::missing_const_for_fn)]`
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | const fn foo(a: usize) -> usize {
|
||||
| +++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
#![expect(incomplete_features)] // `unsafe_fields` is incomplete for the time being
|
||||
#![feature(unsafe_fields)] // `clone()` cannot be derived automatically on unsafe fields
|
||||
|
||||
|
||||
#[derive(Copy)]
|
||||
struct Qux;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> tests/ui/derive.rs:16:1
|
||||
--> tests/ui/derive.rs:15:1
|
||||
|
|
||||
LL | / impl Clone for Qux {
|
||||
LL | |
|
||||
|
|
@ -10,7 +10,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> tests/ui/derive.rs:16:1
|
||||
--> tests/ui/derive.rs:15:1
|
||||
|
|
||||
LL | / impl Clone for Qux {
|
||||
LL | |
|
||||
|
|
@ -23,7 +23,7 @@ LL | | }
|
|||
= help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]`
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> tests/ui/derive.rs:42:1
|
||||
--> tests/ui/derive.rs:41:1
|
||||
|
|
||||
LL | / impl<'a> Clone for Lt<'a> {
|
||||
LL | |
|
||||
|
|
@ -34,7 +34,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> tests/ui/derive.rs:42:1
|
||||
--> tests/ui/derive.rs:41:1
|
||||
|
|
||||
LL | / impl<'a> Clone for Lt<'a> {
|
||||
LL | |
|
||||
|
|
@ -45,7 +45,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> tests/ui/derive.rs:55:1
|
||||
--> tests/ui/derive.rs:54:1
|
||||
|
|
||||
LL | / impl Clone for BigArray {
|
||||
LL | |
|
||||
|
|
@ -56,7 +56,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> tests/ui/derive.rs:55:1
|
||||
--> tests/ui/derive.rs:54:1
|
||||
|
|
||||
LL | / impl Clone for BigArray {
|
||||
LL | |
|
||||
|
|
@ -67,7 +67,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> tests/ui/derive.rs:68:1
|
||||
--> tests/ui/derive.rs:67:1
|
||||
|
|
||||
LL | / impl Clone for FnPtr {
|
||||
LL | |
|
||||
|
|
@ -78,7 +78,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> tests/ui/derive.rs:68:1
|
||||
--> tests/ui/derive.rs:67:1
|
||||
|
|
||||
LL | / impl Clone for FnPtr {
|
||||
LL | |
|
||||
|
|
@ -89,7 +89,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> tests/ui/derive.rs:90:1
|
||||
--> tests/ui/derive.rs:89:1
|
||||
|
|
||||
LL | / impl<T: Clone> Clone for Generic2<T> {
|
||||
LL | |
|
||||
|
|
@ -100,7 +100,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> tests/ui/derive.rs:90:1
|
||||
--> tests/ui/derive.rs:89:1
|
||||
|
|
||||
LL | / impl<T: Clone> Clone for Generic2<T> {
|
||||
LL | |
|
||||
|
|
|
|||
|
|
@ -220,4 +220,19 @@ mod issue11494 {
|
|||
}
|
||||
}
|
||||
|
||||
mod encapsulated {
|
||||
mod types {
|
||||
pub struct FooError;
|
||||
pub struct BarError;
|
||||
pub struct BazError;
|
||||
}
|
||||
|
||||
enum Error {
|
||||
FooError(types::FooError),
|
||||
BarError(types::BarError),
|
||||
BazError(types::BazError),
|
||||
Other,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#![deny(clippy::index_refutable_slice)]
|
||||
#![allow(clippy::uninlined_format_args, clippy::needless_lifetimes)]
|
||||
#![allow(clippy::uninlined_format_args, clippy::needless_lifetimes, clippy::collapsible_if)]
|
||||
|
||||
enum SomeEnum<T> {
|
||||
One(T),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#![deny(clippy::index_refutable_slice)]
|
||||
#![allow(clippy::uninlined_format_args, clippy::needless_lifetimes)]
|
||||
#![allow(clippy::uninlined_format_args, clippy::needless_lifetimes, clippy::collapsible_if)]
|
||||
|
||||
enum SomeEnum<T> {
|
||||
One(T),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#![warn(clippy::integer_division)]
|
||||
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
const TWO: NonZeroU32 = NonZeroU32::new(2).unwrap();
|
||||
|
||||
fn main() {
|
||||
let two = 2;
|
||||
let n = 1 / 2;
|
||||
|
|
@ -12,4 +16,8 @@ fn main() {
|
|||
//~^ integer_division
|
||||
|
||||
let x = 1. / 2.0;
|
||||
|
||||
let a = 1;
|
||||
let s = a / TWO;
|
||||
//~^ integer_division
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: integer division
|
||||
--> tests/ui/integer_division.rs:5:13
|
||||
--> tests/ui/integer_division.rs:9:13
|
||||
|
|
||||
LL | let n = 1 / 2;
|
||||
| ^^^^^
|
||||
|
|
@ -9,7 +9,7 @@ LL | let n = 1 / 2;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::integer_division)]`
|
||||
|
||||
error: integer division
|
||||
--> tests/ui/integer_division.rs:8:13
|
||||
--> tests/ui/integer_division.rs:12:13
|
||||
|
|
||||
LL | let o = 1 / two;
|
||||
| ^^^^^^^
|
||||
|
|
@ -17,12 +17,20 @@ LL | let o = 1 / two;
|
|||
= help: division of integers may cause loss of precision. consider using floats
|
||||
|
||||
error: integer division
|
||||
--> tests/ui/integer_division.rs:11:13
|
||||
--> tests/ui/integer_division.rs:15:13
|
||||
|
|
||||
LL | let p = two / 4;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: division of integers may cause loss of precision. consider using floats
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: integer division
|
||||
--> tests/ui/integer_division.rs:21:13
|
||||
|
|
||||
LL | let s = a / TWO;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: division of integers may cause loss of precision. consider using floats
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
extern crate proc_macros;
|
||||
use proc_macros::with_span;
|
||||
|
||||
use clippy_utils::is_from_proc_macro;
|
||||
use std::boxed::Box;
|
||||
use std::fmt::Display;
|
||||
use std::future::Future;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error: non-binding `let` without a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:51:5
|
||||
--> tests/ui/let_underscore_untyped.rs:50:5
|
||||
|
|
||||
LL | let _ = a();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:51:10
|
||||
--> tests/ui/let_underscore_untyped.rs:50:10
|
||||
|
|
||||
LL | let _ = a();
|
||||
| ^
|
||||
|
|
@ -13,49 +13,49 @@ LL | let _ = a();
|
|||
= help: to override `-D warnings` add `#[allow(clippy::let_underscore_untyped)]`
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:53:5
|
||||
--> tests/ui/let_underscore_untyped.rs:52:5
|
||||
|
|
||||
LL | let _ = b(1);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:53:10
|
||||
--> tests/ui/let_underscore_untyped.rs:52:10
|
||||
|
|
||||
LL | let _ = b(1);
|
||||
| ^
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:56:5
|
||||
--> tests/ui/let_underscore_untyped.rs:55:5
|
||||
|
|
||||
LL | let _ = d(&1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:56:10
|
||||
--> tests/ui/let_underscore_untyped.rs:55:10
|
||||
|
|
||||
LL | let _ = d(&1);
|
||||
| ^
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:58:5
|
||||
--> tests/ui/let_underscore_untyped.rs:57:5
|
||||
|
|
||||
LL | let _ = e();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:58:10
|
||||
--> tests/ui/let_underscore_untyped.rs:57:10
|
||||
|
|
||||
LL | let _ = e();
|
||||
| ^
|
||||
|
||||
error: non-binding `let` without a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:60:5
|
||||
--> tests/ui/let_underscore_untyped.rs:59:5
|
||||
|
|
||||
LL | let _ = f();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: consider adding a type annotation
|
||||
--> tests/ui/let_underscore_untyped.rs:60:10
|
||||
--> tests/ui/let_underscore_untyped.rs:59:10
|
||||
|
|
||||
LL | let _ = f();
|
||||
| ^
|
||||
|
|
|
|||
47
tests/ui/let_with_type_underscore.fixed
Normal file
47
tests/ui/let_with_type_underscore.fixed
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//@aux-build: proc_macros.rs
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::let_with_type_underscore)]
|
||||
#![allow(clippy::let_unit_value, clippy::needless_late_init)]
|
||||
|
||||
extern crate proc_macros;
|
||||
|
||||
fn func() -> &'static str {
|
||||
""
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
// Will lint
|
||||
let x = 1;
|
||||
//~^ let_with_type_underscore
|
||||
let _ = 2;
|
||||
//~^ let_with_type_underscore
|
||||
let x = func();
|
||||
//~^ let_with_type_underscore
|
||||
let x;
|
||||
//~^ let_with_type_underscore
|
||||
x = ();
|
||||
|
||||
let x = 1; // Will not lint, Rust infers this to an integer before Clippy
|
||||
let x = func();
|
||||
let x: Vec<_> = Vec::<u32>::new();
|
||||
let x: [_; 1] = [1];
|
||||
let x = 1;
|
||||
//~^ let_with_type_underscore
|
||||
|
||||
// Do not lint from procedural macros
|
||||
proc_macros::with_span! {
|
||||
span
|
||||
let x: _ = ();
|
||||
// Late initialization
|
||||
let x: _;
|
||||
x = ();
|
||||
// Ensure weird formatting will not break it (hopefully)
|
||||
let x : _ = 1;
|
||||
let x
|
||||
: _ = 1;
|
||||
let x :
|
||||
_;
|
||||
x = ();
|
||||
};
|
||||
}
|
||||
|
|
@ -4,13 +4,13 @@ error: variable declared with type underscore
|
|||
LL | let x: _ = 1;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the explicit type `_` declaration
|
||||
--> tests/ui/let_with_type_underscore.rs:15:10
|
||||
|
|
||||
LL | let x: _ = 1;
|
||||
| ^^^
|
||||
= note: `-D clippy::let-with-type-underscore` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::let_with_type_underscore)]`
|
||||
help: remove the explicit type `_` declaration
|
||||
|
|
||||
LL - let x: _ = 1;
|
||||
LL + let x = 1;
|
||||
|
|
||||
|
||||
error: variable declared with type underscore
|
||||
--> tests/ui/let_with_type_underscore.rs:17:5
|
||||
|
|
@ -19,10 +19,10 @@ LL | let _: _ = 2;
|
|||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the explicit type `_` declaration
|
||||
--> tests/ui/let_with_type_underscore.rs:17:10
|
||||
|
|
||||
LL | let _: _ = 2;
|
||||
| ^^^
|
||||
LL - let _: _ = 2;
|
||||
LL + let _ = 2;
|
||||
|
|
||||
|
||||
error: variable declared with type underscore
|
||||
--> tests/ui/let_with_type_underscore.rs:19:5
|
||||
|
|
@ -31,10 +31,10 @@ LL | let x: _ = func();
|
|||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the explicit type `_` declaration
|
||||
--> tests/ui/let_with_type_underscore.rs:19:10
|
||||
|
|
||||
LL | let x: _ = func();
|
||||
| ^^^
|
||||
LL - let x: _ = func();
|
||||
LL + let x = func();
|
||||
|
|
||||
|
||||
error: variable declared with type underscore
|
||||
--> tests/ui/let_with_type_underscore.rs:21:5
|
||||
|
|
@ -43,10 +43,10 @@ LL | let x: _;
|
|||
| ^^^^^^^^^
|
||||
|
|
||||
help: remove the explicit type `_` declaration
|
||||
--> tests/ui/let_with_type_underscore.rs:21:10
|
||||
|
|
||||
LL | let x: _;
|
||||
| ^^^
|
||||
LL - let x: _;
|
||||
LL + let x;
|
||||
|
|
||||
|
||||
error: variable declared with type underscore
|
||||
--> tests/ui/let_with_type_underscore.rs:29:5
|
||||
|
|
@ -55,10 +55,10 @@ LL | let x : _ = 1;
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the explicit type `_` declaration
|
||||
--> tests/ui/let_with_type_underscore.rs:29:10
|
||||
|
|
||||
LL | let x : _ = 1;
|
||||
| ^^^^
|
||||
LL - let x : _ = 1;
|
||||
LL + let x = 1;
|
||||
|
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -514,3 +514,35 @@ mod issue13768 {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
mod issue14598 {
|
||||
fn bar() -> Result<bool, &'static str> {
|
||||
let value = match foo() {
|
||||
//~^ manual_let_else
|
||||
Err(_) => return Err("abc"),
|
||||
Ok(value) => value,
|
||||
};
|
||||
|
||||
let w = Some(0);
|
||||
let v = match w {
|
||||
//~^ manual_let_else
|
||||
None => return Err("abc"),
|
||||
Some(x) => x,
|
||||
};
|
||||
|
||||
enum Foo<T> {
|
||||
Foo(T),
|
||||
}
|
||||
|
||||
let v = match Foo::Foo(Some(())) {
|
||||
Foo::Foo(Some(_)) => return Err("abc"),
|
||||
Foo::Foo(v) => v,
|
||||
};
|
||||
|
||||
Ok(value == 42)
|
||||
}
|
||||
|
||||
fn foo() -> Result<u32, &'static str> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -529,5 +529,25 @@ LL + return;
|
|||
LL + };
|
||||
|
|
||||
|
||||
error: aborting due to 33 previous errors
|
||||
error: this could be rewritten as `let...else`
|
||||
--> tests/ui/manual_let_else.rs:520:9
|
||||
|
|
||||
LL | / let value = match foo() {
|
||||
LL | |
|
||||
LL | | Err(_) => return Err("abc"),
|
||||
LL | | Ok(value) => value,
|
||||
LL | | };
|
||||
| |__________^ help: consider writing: `let Ok(value) = foo() else { return Err("abc") };`
|
||||
|
||||
error: this could be rewritten as `let...else`
|
||||
--> tests/ui/manual_let_else.rs:527:9
|
||||
|
|
||||
LL | / let v = match w {
|
||||
LL | |
|
||||
LL | | None => return Err("abc"),
|
||||
LL | | Some(x) => x,
|
||||
LL | | };
|
||||
| |__________^ help: consider writing: `let Some(v) = w else { return Err("abc") };`
|
||||
|
||||
error: aborting due to 35 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#![allow(clippy::legacy_numeric_constants, unused_imports)]
|
||||
|
||||
use std::{i32, i128, u32, u128};
|
||||
|
||||
fn main() {
|
||||
let _ = 1u32.saturating_add(1);
|
||||
//~^ manual_saturating_arithmetic
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#![allow(clippy::legacy_numeric_constants, unused_imports)]
|
||||
|
||||
use std::{i32, i128, u32, u128};
|
||||
|
||||
fn main() {
|
||||
let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
|
||||
//~^ manual_saturating_arithmetic
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:6:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:4:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)`
|
||||
|
|
@ -8,19 +8,19 @@ LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
|
|||
= help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:8:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:6:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:10:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:8:13
|
||||
|
|
||||
LL | let _ = 1u8.checked_add(1).unwrap_or(255);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u8.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:12:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:10:13
|
||||
|
|
||||
LL | let _ = 1u128
|
||||
| _____________^
|
||||
|
|
@ -30,49 +30,49 @@ LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455);
|
|||
| |_______________________________________________________________________^ help: consider using `saturating_add`: `1u128.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:18:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:16:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_mul`: `1u32.saturating_mul(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:21:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:19:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:23:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:21:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:25:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:23:13
|
||||
|
|
||||
LL | let _ = 1u8.checked_sub(1).unwrap_or(0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u8.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:30:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:28:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:32:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:30:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:34:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:32:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_add(1).unwrap_or(127);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:36:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:34:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
@ -82,25 +82,25 @@ LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727);
|
|||
| |_______________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:40:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:38:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:42:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:40:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:44:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:42:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_add(-1).unwrap_or(-128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:46:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:44:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
@ -110,25 +110,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
|
|||
| |________________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:54:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:52:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:56:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:54:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:58:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:56:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_sub(1).unwrap_or(-128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:60:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:58:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
@ -138,25 +138,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
|
|||
| |________________________________________________________________________^ help: consider using `saturating_sub`: `1i128.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:64:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:62:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:66:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:64:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:68:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:66:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_sub(-1).unwrap_or(127);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:70:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:68:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
|
|||
|
|
@ -123,3 +123,40 @@ fn issue14189() {
|
|||
*b = !*b;
|
||||
}
|
||||
}
|
||||
|
||||
mod issue14685 {
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ZipList<T>(T);
|
||||
|
||||
impl<T> ZipList<T> {
|
||||
fn len(&self) -> usize {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Index<usize> for ZipList<T> {
|
||||
type Output = T;
|
||||
|
||||
fn index(&self, _: usize) -> &Self::Output {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IndexMut<usize> for ZipList<T> {
|
||||
fn index_mut(&mut self, _: usize) -> &mut Self::Output {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn index_mut(mut zl: ZipList<usize>) {
|
||||
for i in 0..zl.len() {
|
||||
zl[i] = 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,3 +136,40 @@ fn issue14189() {
|
|||
*b = !*b;
|
||||
}
|
||||
}
|
||||
|
||||
mod issue14685 {
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ZipList<T>(T);
|
||||
|
||||
impl<T> ZipList<T> {
|
||||
fn len(&self) -> usize {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Index<usize> for ZipList<T> {
|
||||
type Output = T;
|
||||
|
||||
fn index(&self, _: usize) -> &Self::Output {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IndexMut<usize> for ZipList<T> {
|
||||
fn index_mut(&mut self, _: usize) -> &mut Self::Output {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn index_mut(mut zl: ZipList<usize>) {
|
||||
for i in 0..zl.len() {
|
||||
zl[i] = 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,3 +106,16 @@ fn issue_12928() {
|
|||
fn allowed_manual_unwrap_or_zero() -> u32 {
|
||||
Some(42).unwrap_or_default()
|
||||
}
|
||||
|
||||
mod issue14716 {
|
||||
struct Foo {
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
fn bar(project: &Foo) {
|
||||
let _name = match project.name {
|
||||
Some(ref x) => x,
|
||||
None => "",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,3 +147,16 @@ fn allowed_manual_unwrap_or_zero() -> u32 {
|
|||
0
|
||||
}
|
||||
}
|
||||
|
||||
mod issue14716 {
|
||||
struct Foo {
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
fn bar(project: &Foo) {
|
||||
let _name = match project.name {
|
||||
Some(ref x) => x,
|
||||
None => "",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
/// unimplemented!();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// With an explicit return type it should lint too
|
||||
/// ```edition2015
|
||||
/// fn main() -> () {
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
/// unimplemented!();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// This should, too.
|
||||
/// ```rust
|
||||
/// fn main() {
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
/// unimplemented!();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// This one too.
|
||||
/// ```no_run
|
||||
/// // the fn is not always the first line
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![feature(let_chains)]
|
||||
#![allow(
|
||||
clippy::blocks_in_conditions,
|
||||
clippy::if_same_then_else,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![feature(let_chains)]
|
||||
#![allow(
|
||||
clippy::blocks_in_conditions,
|
||||
clippy::if_same_then_else,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this `if` branch is empty
|
||||
--> tests/ui/needless_if.rs:27:5
|
||||
--> tests/ui/needless_if.rs:26:5
|
||||
|
|
||||
LL | if (true) {}
|
||||
| ^^^^^^^^^^^^ help: you can remove it
|
||||
|
|
@ -8,13 +8,13 @@ LL | if (true) {}
|
|||
= help: to override `-D warnings` add `#[allow(clippy::needless_if)]`
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> tests/ui/needless_if.rs:30:5
|
||||
--> tests/ui/needless_if.rs:29:5
|
||||
|
|
||||
LL | if maybe_side_effect() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `maybe_side_effect();`
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> tests/ui/needless_if.rs:36:5
|
||||
--> tests/ui/needless_if.rs:35:5
|
||||
|
|
||||
LL | / if {
|
||||
LL | |
|
||||
|
|
@ -31,7 +31,7 @@ LL + });
|
|||
|
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> tests/ui/needless_if.rs:51:5
|
||||
--> tests/ui/needless_if.rs:50:5
|
||||
|
|
||||
LL | / if {
|
||||
LL | |
|
||||
|
|
@ -57,19 +57,19 @@ LL + } && true);
|
|||
|
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> tests/ui/needless_if.rs:96:5
|
||||
--> tests/ui/needless_if.rs:95:5
|
||||
|
|
||||
LL | if { maybe_side_effect() } {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() });`
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> tests/ui/needless_if.rs:99:5
|
||||
--> tests/ui/needless_if.rs:98:5
|
||||
|
|
||||
LL | if { maybe_side_effect() } && true {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() } && true);`
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> tests/ui/needless_if.rs:104:5
|
||||
--> tests/ui/needless_if.rs:103:5
|
||||
|
|
||||
LL | if true {}
|
||||
| ^^^^^^^^^^ help: you can remove it: `true;`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![feature(let_chains)]
|
||||
#![allow(unused)]
|
||||
#![allow(
|
||||
clippy::assign_op_pattern,
|
||||
clippy::blocks_in_conditions,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![feature(let_chains)]
|
||||
#![allow(unused)]
|
||||
#![allow(
|
||||
clippy::assign_op_pattern,
|
||||
clippy::blocks_in_conditions,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:27:5
|
||||
--> tests/ui/needless_late_init.rs:25:5
|
||||
|
|
||||
LL | let a;
|
||||
| ^^^^^^ created here
|
||||
|
|
@ -17,7 +17,7 @@ LL ~ let a = "zero";
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:31:5
|
||||
--> tests/ui/needless_late_init.rs:29:5
|
||||
|
|
||||
LL | let b;
|
||||
| ^^^^^^ created here
|
||||
|
|
@ -35,7 +35,7 @@ LL ~ let b = 1;
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:33:5
|
||||
--> tests/ui/needless_late_init.rs:31:5
|
||||
|
|
||||
LL | let c;
|
||||
| ^^^^^^ created here
|
||||
|
|
@ -52,7 +52,7 @@ LL ~ let c = 2;
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:38:5
|
||||
--> tests/ui/needless_late_init.rs:36:5
|
||||
|
|
||||
LL | let d: usize;
|
||||
| ^^^^^^^^^^^^^ created here
|
||||
|
|
@ -68,7 +68,7 @@ LL ~ let d: usize = 1;
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:42:5
|
||||
--> tests/ui/needless_late_init.rs:40:5
|
||||
|
|
||||
LL | let e;
|
||||
| ^^^^^^ created here
|
||||
|
|
@ -84,7 +84,7 @@ LL ~ let e = format!("{}", d);
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:48:5
|
||||
--> tests/ui/needless_late_init.rs:46:5
|
||||
|
|
||||
LL | let a;
|
||||
| ^^^^^^
|
||||
|
|
@ -103,7 +103,7 @@ LL ~ };
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:58:5
|
||||
--> tests/ui/needless_late_init.rs:56:5
|
||||
|
|
||||
LL | let b;
|
||||
| ^^^^^^
|
||||
|
|
@ -120,7 +120,7 @@ LL ~ };
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:66:5
|
||||
--> tests/ui/needless_late_init.rs:64:5
|
||||
|
|
||||
LL | let d;
|
||||
| ^^^^^^
|
||||
|
|
@ -138,7 +138,7 @@ LL ~ };
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:75:5
|
||||
--> tests/ui/needless_late_init.rs:73:5
|
||||
|
|
||||
LL | let e;
|
||||
| ^^^^^^
|
||||
|
|
@ -155,7 +155,7 @@ LL ~ };
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:83:5
|
||||
--> tests/ui/needless_late_init.rs:81:5
|
||||
|
|
||||
LL | let f;
|
||||
| ^^^^^^
|
||||
|
|
@ -169,7 +169,7 @@ LL ~ 1 => "three",
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:90:5
|
||||
--> tests/ui/needless_late_init.rs:88:5
|
||||
|
|
||||
LL | let g: usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
@ -186,7 +186,7 @@ LL ~ };
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:99:5
|
||||
--> tests/ui/needless_late_init.rs:97:5
|
||||
|
|
||||
LL | let x;
|
||||
| ^^^^^^ created here
|
||||
|
|
@ -203,7 +203,7 @@ LL ~ let x = 1;
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:104:5
|
||||
--> tests/ui/needless_late_init.rs:102:5
|
||||
|
|
||||
LL | let x;
|
||||
| ^^^^^^ created here
|
||||
|
|
@ -220,7 +220,7 @@ LL ~ let x = SignificantDrop;
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:109:5
|
||||
--> tests/ui/needless_late_init.rs:107:5
|
||||
|
|
||||
LL | let x;
|
||||
| ^^^^^^ created here
|
||||
|
|
@ -238,7 +238,7 @@ LL ~ let x = SignificantDrop;
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:129:5
|
||||
--> tests/ui/needless_late_init.rs:127:5
|
||||
|
|
||||
LL | let a;
|
||||
| ^^^^^^
|
||||
|
|
@ -257,7 +257,7 @@ LL ~ };
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:147:5
|
||||
--> tests/ui/needless_late_init.rs:145:5
|
||||
|
|
||||
LL | let a;
|
||||
| ^^^^^^
|
||||
|
|
@ -276,7 +276,7 @@ LL ~ };
|
|||
|
|
||||
|
||||
error: unneeded late initialization
|
||||
--> tests/ui/needless_late_init.rs:300:5
|
||||
--> tests/ui/needless_late_init.rs:298:5
|
||||
|
|
||||
LL | let r;
|
||||
| ^^^^^^ created here
|
||||
|
|
|
|||
|
|
@ -70,3 +70,10 @@ mod external_macros {
|
|||
once_cell::external!();
|
||||
lazy_static::external!();
|
||||
}
|
||||
|
||||
mod issue14729 {
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
#[expect(clippy::non_std_lazy_statics)]
|
||||
static LAZY_FOO: Lazy<String> = Lazy::new(|| "foo".to_uppercase());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,3 +70,10 @@ mod external_macros {
|
|||
once_cell::external!();
|
||||
lazy_static::external!();
|
||||
}
|
||||
|
||||
mod issue14729 {
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
#[expect(clippy::non_std_lazy_statics)]
|
||||
static LAZY_FOO: Lazy<String> = Lazy::new(|| "foo".to_uppercase());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(let_chains, if_let_guard)]
|
||||
#![feature(if_let_guard)]
|
||||
#![warn(clippy::redundant_pattern_matching)]
|
||||
#![allow(
|
||||
clippy::needless_bool,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(let_chains, if_let_guard)]
|
||||
#![feature(if_let_guard)]
|
||||
#![warn(clippy::redundant_pattern_matching)]
|
||||
#![allow(
|
||||
clippy::needless_bool,
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@
|
|||
#![allow(unused_labels)]
|
||||
#![allow(ambiguous_wide_pointer_comparisons)]
|
||||
#![allow(clippy::reversed_empty_ranges)]
|
||||
#![allow(unnecessary_transmutes)]
|
||||
#![warn(clippy::almost_complete_range)] //~ ERROR: lint `clippy::almost_complete_letter_range`
|
||||
#![warn(clippy::disallowed_names)] //~ ERROR: lint `clippy::blacklisted_name`
|
||||
#![warn(clippy::blocks_in_conditions)] //~ ERROR: lint `clippy::block_in_if_condition_expr`
|
||||
|
|
@ -132,5 +133,9 @@
|
|||
#![warn(unused_labels)] //~ ERROR: lint `clippy::unused_label`
|
||||
#![warn(ambiguous_wide_pointer_comparisons)] //~ ERROR: lint `clippy::vtable_address_comparisons`
|
||||
#![warn(clippy::reversed_empty_ranges)] //~ ERROR: lint `clippy::reverse_range_loop`
|
||||
#![warn(unnecessary_transmutes)] //~ ERROR: lint `clippy::transmute_int_to_float`
|
||||
#![warn(unnecessary_transmutes)] //~ ERROR: lint `clippy::transmute_int_to_char`
|
||||
#![warn(unnecessary_transmutes)] //~ ERROR: lint `clippy::transmute_float_to_int`
|
||||
#![warn(unnecessary_transmutes)] //~ ERROR: lint `clippy::transmute_num_to_bytes`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@
|
|||
#![allow(unused_labels)]
|
||||
#![allow(ambiguous_wide_pointer_comparisons)]
|
||||
#![allow(clippy::reversed_empty_ranges)]
|
||||
#![allow(unnecessary_transmutes)]
|
||||
#![warn(clippy::almost_complete_letter_range)] //~ ERROR: lint `clippy::almost_complete_letter_range`
|
||||
#![warn(clippy::blacklisted_name)] //~ ERROR: lint `clippy::blacklisted_name`
|
||||
#![warn(clippy::block_in_if_condition_expr)] //~ ERROR: lint `clippy::block_in_if_condition_expr`
|
||||
|
|
@ -132,5 +133,9 @@
|
|||
#![warn(clippy::unused_label)] //~ ERROR: lint `clippy::unused_label`
|
||||
#![warn(clippy::vtable_address_comparisons)] //~ ERROR: lint `clippy::vtable_address_comparisons`
|
||||
#![warn(clippy::reverse_range_loop)] //~ ERROR: lint `clippy::reverse_range_loop`
|
||||
#![warn(clippy::transmute_int_to_float)] //~ ERROR: lint `clippy::transmute_int_to_float`
|
||||
#![warn(clippy::transmute_int_to_char)] //~ ERROR: lint `clippy::transmute_int_to_char`
|
||||
#![warn(clippy::transmute_float_to_int)] //~ ERROR: lint `clippy::transmute_float_to_int`
|
||||
#![warn(clippy::transmute_num_to_bytes)] //~ ERROR: lint `clippy::transmute_num_to_bytes`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range`
|
||||
--> tests/ui/rename.rs:66:9
|
||||
--> tests/ui/rename.rs:67:9
|
||||
|
|
||||
LL | #![warn(clippy::almost_complete_letter_range)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range`
|
||||
|
|
@ -8,412 +8,436 @@ LL | #![warn(clippy::almost_complete_letter_range)]
|
|||
= help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]`
|
||||
|
||||
error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names`
|
||||
--> tests/ui/rename.rs:67:9
|
||||
--> tests/ui/rename.rs:68:9
|
||||
|
|
||||
LL | #![warn(clippy::blacklisted_name)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names`
|
||||
|
||||
error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_conditions`
|
||||
--> tests/ui/rename.rs:68:9
|
||||
--> tests/ui/rename.rs:69:9
|
||||
|
|
||||
LL | #![warn(clippy::block_in_if_condition_expr)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions`
|
||||
|
||||
error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_conditions`
|
||||
--> tests/ui/rename.rs:69:9
|
||||
--> tests/ui/rename.rs:70:9
|
||||
|
|
||||
LL | #![warn(clippy::block_in_if_condition_stmt)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions`
|
||||
|
||||
error: lint `clippy::blocks_in_if_conditions` has been renamed to `clippy::blocks_in_conditions`
|
||||
--> tests/ui/rename.rs:70:9
|
||||
--> tests/ui/rename.rs:71:9
|
||||
|
|
||||
LL | #![warn(clippy::blocks_in_if_conditions)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions`
|
||||
|
||||
error: lint `clippy::box_vec` has been renamed to `clippy::box_collection`
|
||||
--> tests/ui/rename.rs:71:9
|
||||
--> tests/ui/rename.rs:72:9
|
||||
|
|
||||
LL | #![warn(clippy::box_vec)]
|
||||
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection`
|
||||
|
||||
error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes`
|
||||
--> tests/ui/rename.rs:72:9
|
||||
--> tests/ui/rename.rs:73:9
|
||||
|
|
||||
LL | #![warn(clippy::const_static_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes`
|
||||
|
||||
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
|
||||
--> tests/ui/rename.rs:73:9
|
||||
--> tests/ui/rename.rs:74:9
|
||||
|
|
||||
LL | #![warn(clippy::cyclomatic_complexity)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
|
||||
|
||||
error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq`
|
||||
--> tests/ui/rename.rs:74:9
|
||||
--> tests/ui/rename.rs:75:9
|
||||
|
|
||||
LL | #![warn(clippy::derive_hash_xor_eq)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq`
|
||||
|
||||
error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods`
|
||||
--> tests/ui/rename.rs:75:9
|
||||
--> tests/ui/rename.rs:76:9
|
||||
|
|
||||
LL | #![warn(clippy::disallowed_method)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods`
|
||||
|
||||
error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types`
|
||||
--> tests/ui/rename.rs:76:9
|
||||
--> tests/ui/rename.rs:77:9
|
||||
|
|
||||
LL | #![warn(clippy::disallowed_type)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types`
|
||||
|
||||
error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression`
|
||||
--> tests/ui/rename.rs:77:9
|
||||
--> tests/ui/rename.rs:78:9
|
||||
|
|
||||
LL | #![warn(clippy::eval_order_dependence)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression`
|
||||
|
||||
error: lint `clippy::find_map` has been renamed to `clippy::manual_find_map`
|
||||
--> tests/ui/rename.rs:78:9
|
||||
--> tests/ui/rename.rs:79:9
|
||||
|
|
||||
LL | #![warn(clippy::find_map)]
|
||||
| ^^^^^^^^^^^^^^^^ help: use the new name: `clippy::manual_find_map`
|
||||
|
||||
error: lint `clippy::filter_map` has been renamed to `clippy::manual_filter_map`
|
||||
--> tests/ui/rename.rs:79:9
|
||||
--> tests/ui/rename.rs:80:9
|
||||
|
|
||||
LL | #![warn(clippy::filter_map)]
|
||||
| ^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::manual_filter_map`
|
||||
|
||||
error: lint `clippy::fn_address_comparisons` has been renamed to `unpredictable_function_pointer_comparisons`
|
||||
--> tests/ui/rename.rs:80:9
|
||||
--> tests/ui/rename.rs:81:9
|
||||
|
|
||||
LL | #![warn(clippy::fn_address_comparisons)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unpredictable_function_pointer_comparisons`
|
||||
|
||||
error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion`
|
||||
--> tests/ui/rename.rs:81:9
|
||||
--> tests/ui/rename.rs:82:9
|
||||
|
|
||||
LL | #![warn(clippy::identity_conversion)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion`
|
||||
|
||||
error: lint `clippy::if_let_redundant_pattern_matching` has been renamed to `clippy::redundant_pattern_matching`
|
||||
--> tests/ui/rename.rs:82:9
|
||||
--> tests/ui/rename.rs:83:9
|
||||
|
|
||||
LL | #![warn(clippy::if_let_redundant_pattern_matching)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_pattern_matching`
|
||||
|
||||
error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok`
|
||||
--> tests/ui/rename.rs:83:9
|
||||
--> tests/ui/rename.rs:84:9
|
||||
|
|
||||
LL | #![warn(clippy::if_let_some_result)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok`
|
||||
|
||||
error: lint `clippy::incorrect_clone_impl_on_copy_type` has been renamed to `clippy::non_canonical_clone_impl`
|
||||
--> tests/ui/rename.rs:84:9
|
||||
--> tests/ui/rename.rs:85:9
|
||||
|
|
||||
LL | #![warn(clippy::incorrect_clone_impl_on_copy_type)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_clone_impl`
|
||||
|
||||
error: lint `clippy::incorrect_partial_ord_impl_on_ord_type` has been renamed to `clippy::non_canonical_partial_ord_impl`
|
||||
--> tests/ui/rename.rs:85:9
|
||||
--> tests/ui/rename.rs:86:9
|
||||
|
|
||||
LL | #![warn(clippy::incorrect_partial_ord_impl_on_ord_type)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_partial_ord_impl`
|
||||
|
||||
error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects`
|
||||
--> tests/ui/rename.rs:86:9
|
||||
--> tests/ui/rename.rs:87:9
|
||||
|
|
||||
LL | #![warn(clippy::integer_arithmetic)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects`
|
||||
|
||||
error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr`
|
||||
--> tests/ui/rename.rs:87:9
|
||||
--> tests/ui/rename.rs:88:9
|
||||
|
|
||||
LL | #![warn(clippy::logic_bug)]
|
||||
| ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr`
|
||||
|
||||
error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default`
|
||||
--> tests/ui/rename.rs:88:9
|
||||
--> tests/ui/rename.rs:89:9
|
||||
|
|
||||
LL | #![warn(clippy::new_without_default_derive)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default`
|
||||
|
||||
error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map`
|
||||
--> tests/ui/rename.rs:89:9
|
||||
--> tests/ui/rename.rs:90:9
|
||||
|
|
||||
LL | #![warn(clippy::option_and_then_some)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map`
|
||||
|
||||
error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used`
|
||||
--> tests/ui/rename.rs:90:9
|
||||
--> tests/ui/rename.rs:91:9
|
||||
|
|
||||
LL | #![warn(clippy::option_expect_used)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used`
|
||||
|
||||
error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or`
|
||||
--> tests/ui/rename.rs:91:9
|
||||
--> tests/ui/rename.rs:92:9
|
||||
|
|
||||
LL | #![warn(clippy::option_map_unwrap_or)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
|
||||
|
||||
error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or`
|
||||
--> tests/ui/rename.rs:92:9
|
||||
--> tests/ui/rename.rs:93:9
|
||||
|
|
||||
LL | #![warn(clippy::option_map_unwrap_or_else)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
|
||||
|
||||
error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used`
|
||||
--> tests/ui/rename.rs:93:9
|
||||
--> tests/ui/rename.rs:94:9
|
||||
|
|
||||
LL | #![warn(clippy::option_unwrap_used)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used`
|
||||
|
||||
error: lint `clippy::overflow_check_conditional` has been renamed to `clippy::panicking_overflow_checks`
|
||||
--> tests/ui/rename.rs:94:9
|
||||
--> tests/ui/rename.rs:95:9
|
||||
|
|
||||
LL | #![warn(clippy::overflow_check_conditional)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::panicking_overflow_checks`
|
||||
|
||||
error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow`
|
||||
--> tests/ui/rename.rs:95:9
|
||||
--> tests/ui/rename.rs:96:9
|
||||
|
|
||||
LL | #![warn(clippy::ref_in_deref)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow`
|
||||
|
||||
error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used`
|
||||
--> tests/ui/rename.rs:96:9
|
||||
--> tests/ui/rename.rs:97:9
|
||||
|
|
||||
LL | #![warn(clippy::result_expect_used)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used`
|
||||
|
||||
error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or`
|
||||
--> tests/ui/rename.rs:97:9
|
||||
--> tests/ui/rename.rs:98:9
|
||||
|
|
||||
LL | #![warn(clippy::result_map_unwrap_or_else)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
|
||||
|
||||
error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used`
|
||||
--> tests/ui/rename.rs:98:9
|
||||
--> tests/ui/rename.rs:99:9
|
||||
|
|
||||
LL | #![warn(clippy::result_unwrap_used)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used`
|
||||
|
||||
error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str`
|
||||
--> tests/ui/rename.rs:99:9
|
||||
--> tests/ui/rename.rs:100:9
|
||||
|
|
||||
LL | #![warn(clippy::single_char_push_str)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str`
|
||||
|
||||
error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
|
||||
--> tests/ui/rename.rs:100:9
|
||||
--> tests/ui/rename.rs:101:9
|
||||
|
|
||||
LL | #![warn(clippy::stutter)]
|
||||
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
|
||||
|
||||
error: lint `clippy::thread_local_initializer_can_be_made_const` has been renamed to `clippy::missing_const_for_thread_local`
|
||||
--> tests/ui/rename.rs:101:9
|
||||
--> tests/ui/rename.rs:102:9
|
||||
|
|
||||
LL | #![warn(clippy::thread_local_initializer_can_be_made_const)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::missing_const_for_thread_local`
|
||||
|
||||
error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl`
|
||||
--> tests/ui/rename.rs:102:9
|
||||
--> tests/ui/rename.rs:103:9
|
||||
|
|
||||
LL | #![warn(clippy::to_string_in_display)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl`
|
||||
|
||||
error: lint `clippy::unwrap_or_else_default` has been renamed to `clippy::unwrap_or_default`
|
||||
--> tests/ui/rename.rs:103:9
|
||||
--> tests/ui/rename.rs:104:9
|
||||
|
|
||||
LL | #![warn(clippy::unwrap_or_else_default)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_or_default`
|
||||
|
||||
error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters`
|
||||
--> tests/ui/rename.rs:104:9
|
||||
--> tests/ui/rename.rs:105:9
|
||||
|
|
||||
LL | #![warn(clippy::zero_width_space)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
|
||||
|
||||
error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting`
|
||||
--> tests/ui/rename.rs:105:9
|
||||
--> tests/ui/rename.rs:106:9
|
||||
|
|
||||
LL | #![warn(clippy::cast_ref_to_mut)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting`
|
||||
|
||||
error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op`
|
||||
--> tests/ui/rename.rs:106:9
|
||||
--> tests/ui/rename.rs:107:9
|
||||
|
|
||||
LL | #![warn(clippy::clone_double_ref)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op`
|
||||
|
||||
error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons`
|
||||
--> tests/ui/rename.rs:107:9
|
||||
--> tests/ui/rename.rs:108:9
|
||||
|
|
||||
LL | #![warn(clippy::cmp_nan)]
|
||||
| ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons`
|
||||
|
||||
error: lint `clippy::invalid_null_ptr_usage` has been renamed to `invalid_null_arguments`
|
||||
--> tests/ui/rename.rs:108:9
|
||||
--> tests/ui/rename.rs:109:9
|
||||
|
|
||||
LL | #![warn(clippy::invalid_null_ptr_usage)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_null_arguments`
|
||||
|
||||
error: lint `clippy::double_neg` has been renamed to `double_negations`
|
||||
--> tests/ui/rename.rs:109:9
|
||||
--> tests/ui/rename.rs:110:9
|
||||
|
|
||||
LL | #![warn(clippy::double_neg)]
|
||||
| ^^^^^^^^^^^^^^^^^^ help: use the new name: `double_negations`
|
||||
|
||||
error: lint `clippy::drop_bounds` has been renamed to `drop_bounds`
|
||||
--> tests/ui/rename.rs:110:9
|
||||
--> tests/ui/rename.rs:111:9
|
||||
|
|
||||
LL | #![warn(clippy::drop_bounds)]
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds`
|
||||
|
||||
error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types`
|
||||
--> tests/ui/rename.rs:111:9
|
||||
--> tests/ui/rename.rs:112:9
|
||||
|
|
||||
LL | #![warn(clippy::drop_copy)]
|
||||
| ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types`
|
||||
|
||||
error: lint `clippy::drop_ref` has been renamed to `dropping_references`
|
||||
--> tests/ui/rename.rs:112:9
|
||||
--> tests/ui/rename.rs:113:9
|
||||
|
|
||||
LL | #![warn(clippy::drop_ref)]
|
||||
| ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references`
|
||||
|
||||
error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks`
|
||||
--> tests/ui/rename.rs:113:9
|
||||
--> tests/ui/rename.rs:114:9
|
||||
|
|
||||
LL | #![warn(clippy::fn_null_check)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks`
|
||||
|
||||
error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles`
|
||||
--> tests/ui/rename.rs:114:9
|
||||
--> tests/ui/rename.rs:115:9
|
||||
|
|
||||
LL | #![warn(clippy::for_loop_over_option)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
|
||||
|
||||
error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles`
|
||||
--> tests/ui/rename.rs:115:9
|
||||
--> tests/ui/rename.rs:116:9
|
||||
|
|
||||
LL | #![warn(clippy::for_loop_over_result)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
|
||||
|
||||
error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles`
|
||||
--> tests/ui/rename.rs:116:9
|
||||
--> tests/ui/rename.rs:117:9
|
||||
|
|
||||
LL | #![warn(clippy::for_loops_over_fallibles)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
|
||||
|
||||
error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types`
|
||||
--> tests/ui/rename.rs:117:9
|
||||
--> tests/ui/rename.rs:118:9
|
||||
|
|
||||
LL | #![warn(clippy::forget_copy)]
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types`
|
||||
|
||||
error: lint `clippy::forget_ref` has been renamed to `forgetting_references`
|
||||
--> tests/ui/rename.rs:118:9
|
||||
--> tests/ui/rename.rs:119:9
|
||||
|
|
||||
LL | #![warn(clippy::forget_ref)]
|
||||
| ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references`
|
||||
|
||||
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
|
||||
--> tests/ui/rename.rs:119:9
|
||||
--> tests/ui/rename.rs:120:9
|
||||
|
|
||||
LL | #![warn(clippy::into_iter_on_array)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter`
|
||||
|
||||
error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering`
|
||||
--> tests/ui/rename.rs:120:9
|
||||
--> tests/ui/rename.rs:121:9
|
||||
|
|
||||
LL | #![warn(clippy::invalid_atomic_ordering)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering`
|
||||
|
||||
error: lint `clippy::invalid_ref` has been renamed to `invalid_value`
|
||||
--> tests/ui/rename.rs:121:9
|
||||
--> tests/ui/rename.rs:122:9
|
||||
|
|
||||
LL | #![warn(clippy::invalid_ref)]
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value`
|
||||
|
||||
error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked`
|
||||
--> tests/ui/rename.rs:122:9
|
||||
--> tests/ui/rename.rs:123:9
|
||||
|
|
||||
LL | #![warn(clippy::invalid_utf8_in_unchecked)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked`
|
||||
|
||||
error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop`
|
||||
--> tests/ui/rename.rs:123:9
|
||||
--> tests/ui/rename.rs:124:9
|
||||
|
|
||||
LL | #![warn(clippy::let_underscore_drop)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop`
|
||||
|
||||
error: lint `clippy::maybe_misused_cfg` has been renamed to `unexpected_cfgs`
|
||||
--> tests/ui/rename.rs:124:9
|
||||
--> tests/ui/rename.rs:125:9
|
||||
|
|
||||
LL | #![warn(clippy::maybe_misused_cfg)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unexpected_cfgs`
|
||||
|
||||
error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums`
|
||||
--> tests/ui/rename.rs:125:9
|
||||
--> tests/ui/rename.rs:126:9
|
||||
|
|
||||
LL | #![warn(clippy::mem_discriminant_non_enum)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums`
|
||||
|
||||
error: lint `clippy::mismatched_target_os` has been renamed to `unexpected_cfgs`
|
||||
--> tests/ui/rename.rs:126:9
|
||||
--> tests/ui/rename.rs:127:9
|
||||
|
|
||||
LL | #![warn(clippy::mismatched_target_os)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unexpected_cfgs`
|
||||
|
||||
error: lint `clippy::panic_params` has been renamed to `non_fmt_panics`
|
||||
--> tests/ui/rename.rs:127:9
|
||||
--> tests/ui/rename.rs:128:9
|
||||
|
|
||||
LL | #![warn(clippy::panic_params)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics`
|
||||
|
||||
error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally`
|
||||
--> tests/ui/rename.rs:128:9
|
||||
--> tests/ui/rename.rs:129:9
|
||||
|
|
||||
LL | #![warn(clippy::positional_named_format_parameters)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally`
|
||||
|
||||
error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `dangling_pointers_from_temporaries`
|
||||
--> tests/ui/rename.rs:129:9
|
||||
--> tests/ui/rename.rs:130:9
|
||||
|
|
||||
LL | #![warn(clippy::temporary_cstring_as_ptr)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `dangling_pointers_from_temporaries`
|
||||
|
||||
error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops`
|
||||
--> tests/ui/rename.rs:130:9
|
||||
--> tests/ui/rename.rs:131:9
|
||||
|
|
||||
LL | #![warn(clippy::undropped_manually_drops)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops`
|
||||
|
||||
error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints`
|
||||
--> tests/ui/rename.rs:131:9
|
||||
--> tests/ui/rename.rs:132:9
|
||||
|
|
||||
LL | #![warn(clippy::unknown_clippy_lints)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints`
|
||||
|
||||
error: lint `clippy::unused_label` has been renamed to `unused_labels`
|
||||
--> tests/ui/rename.rs:132:9
|
||||
--> tests/ui/rename.rs:133:9
|
||||
|
|
||||
LL | #![warn(clippy::unused_label)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
|
||||
|
||||
error: lint `clippy::vtable_address_comparisons` has been renamed to `ambiguous_wide_pointer_comparisons`
|
||||
--> tests/ui/rename.rs:133:9
|
||||
--> tests/ui/rename.rs:134:9
|
||||
|
|
||||
LL | #![warn(clippy::vtable_address_comparisons)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `ambiguous_wide_pointer_comparisons`
|
||||
|
||||
error: lint `clippy::reverse_range_loop` has been renamed to `clippy::reversed_empty_ranges`
|
||||
--> tests/ui/rename.rs:134:9
|
||||
--> tests/ui/rename.rs:135:9
|
||||
|
|
||||
LL | #![warn(clippy::reverse_range_loop)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::reversed_empty_ranges`
|
||||
|
||||
error: aborting due to 69 previous errors
|
||||
error: lint `clippy::transmute_int_to_float` has been renamed to `unnecessary_transmutes`
|
||||
--> tests/ui/rename.rs:136:9
|
||||
|
|
||||
LL | #![warn(clippy::transmute_int_to_float)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unnecessary_transmutes`
|
||||
|
||||
error: lint `clippy::transmute_int_to_char` has been renamed to `unnecessary_transmutes`
|
||||
--> tests/ui/rename.rs:137:9
|
||||
|
|
||||
LL | #![warn(clippy::transmute_int_to_char)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unnecessary_transmutes`
|
||||
|
||||
error: lint `clippy::transmute_float_to_int` has been renamed to `unnecessary_transmutes`
|
||||
--> tests/ui/rename.rs:138:9
|
||||
|
|
||||
LL | #![warn(clippy::transmute_float_to_int)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unnecessary_transmutes`
|
||||
|
||||
error: lint `clippy::transmute_num_to_bytes` has been renamed to `unnecessary_transmutes`
|
||||
--> tests/ui/rename.rs:139:9
|
||||
|
|
||||
LL | #![warn(clippy::transmute_num_to_bytes)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unnecessary_transmutes`
|
||||
|
||||
error: aborting due to 73 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -67,8 +67,60 @@ fn main() {
|
|||
.first() // creates temporary reference
|
||||
.and_then(|x| test_opt_block(Some(*x)))
|
||||
}
|
||||
|
||||
fn in_closure() -> bool {
|
||||
let _ = || {
|
||||
let x = Some("")?;
|
||||
if x.len() > 2 { Some(3) } else { None }
|
||||
//~^ return_and_then
|
||||
};
|
||||
true
|
||||
}
|
||||
|
||||
fn with_return(shortcut: bool) -> Option<i32> {
|
||||
if shortcut {
|
||||
return {
|
||||
let x = Some("")?;
|
||||
if x.len() > 2 { Some(3) } else { None }
|
||||
};
|
||||
//~^ return_and_then
|
||||
};
|
||||
None
|
||||
}
|
||||
|
||||
fn with_return_multiline(shortcut: bool) -> Option<i32> {
|
||||
if shortcut {
|
||||
return {
|
||||
let mut x = Some("")?;
|
||||
let x = format!("{x}.");
|
||||
if x.len() > 2 { Some(3) } else { None }
|
||||
};
|
||||
//~^^^^ return_and_then
|
||||
};
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_option(n: i32) -> Option<i32> {
|
||||
Some(n)
|
||||
}
|
||||
|
||||
mod issue14781 {
|
||||
fn foo(_: &str, _: (u32, u32)) -> Result<(u32, u32), ()> {
|
||||
Ok((1, 1))
|
||||
}
|
||||
|
||||
fn bug(_: Option<&str>) -> Result<(), ()> {
|
||||
let year: Option<&str> = None;
|
||||
let month: Option<&str> = None;
|
||||
let day: Option<&str> = None;
|
||||
|
||||
let _day = if let (Some(year), Some(month)) = (year, month) {
|
||||
day.and_then(|day| foo(day, (1, 31)).ok())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,55 @@ fn main() {
|
|||
.first() // creates temporary reference
|
||||
.and_then(|x| test_opt_block(Some(*x)))
|
||||
}
|
||||
|
||||
fn in_closure() -> bool {
|
||||
let _ = || {
|
||||
Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None })
|
||||
//~^ return_and_then
|
||||
};
|
||||
true
|
||||
}
|
||||
|
||||
fn with_return(shortcut: bool) -> Option<i32> {
|
||||
if shortcut {
|
||||
return Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None });
|
||||
//~^ return_and_then
|
||||
};
|
||||
None
|
||||
}
|
||||
|
||||
fn with_return_multiline(shortcut: bool) -> Option<i32> {
|
||||
if shortcut {
|
||||
return Some("").and_then(|mut x| {
|
||||
let x = format!("{x}.");
|
||||
if x.len() > 2 { Some(3) } else { None }
|
||||
});
|
||||
//~^^^^ return_and_then
|
||||
};
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_option(n: i32) -> Option<i32> {
|
||||
Some(n)
|
||||
}
|
||||
|
||||
mod issue14781 {
|
||||
fn foo(_: &str, _: (u32, u32)) -> Result<(u32, u32), ()> {
|
||||
Ok((1, 1))
|
||||
}
|
||||
|
||||
fn bug(_: Option<&str>) -> Result<(), ()> {
|
||||
let year: Option<&str> = None;
|
||||
let month: Option<&str> = None;
|
||||
let day: Option<&str> = None;
|
||||
|
||||
let _day = if let (Some(year), Some(month)) = (year, month) {
|
||||
day.and_then(|day| foo(day, (1, 31)).ok())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,5 +101,50 @@ LL + })?;
|
|||
LL + if x.len() > 2 { Some(3) } else { None }
|
||||
|
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: use the `?` operator instead of an `and_then` call
|
||||
--> tests/ui/return_and_then.rs:69:13
|
||||
|
|
||||
LL | Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None })
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: try
|
||||
|
|
||||
LL ~ let x = Some("")?;
|
||||
LL + if x.len() > 2 { Some(3) } else { None }
|
||||
|
|
||||
|
||||
error: use the `?` operator instead of an `and_then` call
|
||||
--> tests/ui/return_and_then.rs:77:20
|
||||
|
|
||||
LL | return Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: try
|
||||
|
|
||||
LL ~ return {
|
||||
LL + let x = Some("")?;
|
||||
LL + if x.len() > 2 { Some(3) } else { None }
|
||||
LL ~ };
|
||||
|
|
||||
|
||||
error: use the `?` operator instead of an `and_then` call
|
||||
--> tests/ui/return_and_then.rs:85:20
|
||||
|
|
||||
LL | return Some("").and_then(|mut x| {
|
||||
| ____________________^
|
||||
LL | | let x = format!("{x}.");
|
||||
LL | | if x.len() > 2 { Some(3) } else { None }
|
||||
LL | | });
|
||||
| |______________^
|
||||
|
|
||||
help: try
|
||||
|
|
||||
LL ~ return {
|
||||
LL + let mut x = Some("")?;
|
||||
LL + let x = format!("{x}.");
|
||||
LL + if x.len() > 2 { Some(3) } else { None }
|
||||
LL ~ };
|
||||
|
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -9,3 +9,20 @@ fn main() {
|
|||
let _ = char::is_digit(c, 8);
|
||||
//~^ to_digit_is_some
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.86"]
|
||||
mod cannot_lint_in_const_context {
|
||||
fn without_const(c: char) -> bool {
|
||||
c.is_digit(8)
|
||||
//~^ to_digit_is_some
|
||||
}
|
||||
const fn with_const(c: char) -> bool {
|
||||
c.to_digit(8).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.87"]
|
||||
const fn with_const(c: char) -> bool {
|
||||
c.is_digit(8)
|
||||
//~^ to_digit_is_some
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,3 +9,20 @@ fn main() {
|
|||
let _ = char::to_digit(c, 8).is_some();
|
||||
//~^ to_digit_is_some
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.86"]
|
||||
mod cannot_lint_in_const_context {
|
||||
fn without_const(c: char) -> bool {
|
||||
c.to_digit(8).is_some()
|
||||
//~^ to_digit_is_some
|
||||
}
|
||||
const fn with_const(c: char) -> bool {
|
||||
c.to_digit(8).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.87"]
|
||||
const fn with_const(c: char) -> bool {
|
||||
c.to_digit(8).is_some()
|
||||
//~^ to_digit_is_some
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,5 +13,17 @@ error: use of `.to_digit(..).is_some()`
|
|||
LL | let _ = char::to_digit(c, 8).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `char::is_digit(c, 8)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: use of `.to_digit(..).is_some()`
|
||||
--> tests/ui/to_digit_is_some.rs:16:9
|
||||
|
|
||||
LL | c.to_digit(8).is_some()
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `c.is_digit(8)`
|
||||
|
||||
error: use of `.to_digit(..).is_some()`
|
||||
--> tests/ui/to_digit_is_some.rs:26:5
|
||||
|
|
||||
LL | c.to_digit(8).is_some()
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `c.is_digit(8)`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
11
tests/ui/to_string_in_format_args_incremental.fixed
Normal file
11
tests/ui/to_string_in_format_args_incremental.fixed
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
//@compile-flags: -C incremental=target/debug/test/incr
|
||||
|
||||
#![allow(clippy::uninlined_format_args)]
|
||||
|
||||
// see https://github.com/rust-lang/rust-clippy/issues/10969
|
||||
|
||||
fn main() {
|
||||
let s = "Hello, world!";
|
||||
println!("{}", s);
|
||||
//~^ to_string_in_format_args
|
||||
}
|
||||
11
tests/ui/to_string_in_format_args_incremental.rs
Normal file
11
tests/ui/to_string_in_format_args_incremental.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
//@compile-flags: -C incremental=target/debug/test/incr
|
||||
|
||||
#![allow(clippy::uninlined_format_args)]
|
||||
|
||||
// see https://github.com/rust-lang/rust-clippy/issues/10969
|
||||
|
||||
fn main() {
|
||||
let s = "Hello, world!";
|
||||
println!("{}", s.to_string());
|
||||
//~^ to_string_in_format_args
|
||||
}
|
||||
11
tests/ui/to_string_in_format_args_incremental.stderr
Normal file
11
tests/ui/to_string_in_format_args_incremental.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: `to_string` applied to a type that implements `Display` in `println!` args
|
||||
--> tests/ui/to_string_in_format_args_incremental.rs:9:21
|
||||
|
|
||||
LL | println!("{}", s.to_string());
|
||||
| ^^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::to_string_in_format_args)]`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
@ -116,138 +116,6 @@ fn int_to_bool() {
|
|||
//~^ transmute_int_to_bool
|
||||
}
|
||||
|
||||
#[warn(clippy::transmute_int_to_float)]
|
||||
mod int_to_float {
|
||||
fn test() {
|
||||
let _: f16 = unsafe { std::mem::transmute(0_u16) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
let _: f16 = unsafe { std::mem::transmute(0_i16) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
let _: f32 = unsafe { std::mem::transmute(0_u32) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
let _: f32 = unsafe { std::mem::transmute(0_i32) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
let _: f64 = unsafe { std::mem::transmute(0_u64) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
let _: f64 = unsafe { std::mem::transmute(0_i64) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
let _: f128 = unsafe { std::mem::transmute(0_u128) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
let _: f128 = unsafe { std::mem::transmute(0_i128) };
|
||||
//~^ transmute_int_to_float
|
||||
}
|
||||
|
||||
mod issue_5747 {
|
||||
const VALUE16: f16 = unsafe { std::mem::transmute(0_u16) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
const VALUE32: f32 = unsafe { std::mem::transmute(0_u32) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
const VALUE64: f64 = unsafe { std::mem::transmute(0_i64) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
const VALUE128: f128 = unsafe { std::mem::transmute(0_i128) };
|
||||
//~^ transmute_int_to_float
|
||||
|
||||
const fn from_bits_16(v: i16) -> f16 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_int_to_float
|
||||
}
|
||||
|
||||
const fn from_bits_32(v: i32) -> f32 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_int_to_float
|
||||
}
|
||||
|
||||
const fn from_bits_64(v: u64) -> f64 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_int_to_float
|
||||
}
|
||||
|
||||
const fn from_bits_128(v: u128) -> f128 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_int_to_float
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod num_to_bytes {
|
||||
fn test() {
|
||||
unsafe {
|
||||
let _: [u8; 1] = std::mem::transmute(0u8);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 4] = std::mem::transmute(0u32);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 16] = std::mem::transmute(0u128);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 1] = std::mem::transmute(0i8);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 4] = std::mem::transmute(0i32);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 16] = std::mem::transmute(0i128);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 2] = std::mem::transmute(0.0f16);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 4] = std::mem::transmute(0.0f32);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 8] = std::mem::transmute(0.0f64);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 16] = std::mem::transmute(0.0f128);
|
||||
//~^ transmute_num_to_bytes
|
||||
}
|
||||
}
|
||||
const fn test_const() {
|
||||
unsafe {
|
||||
let _: [u8; 1] = std::mem::transmute(0u8);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 4] = std::mem::transmute(0u32);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 16] = std::mem::transmute(0u128);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 1] = std::mem::transmute(0i8);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 4] = std::mem::transmute(0i32);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 16] = std::mem::transmute(0i128);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 2] = std::mem::transmute(0.0f16);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 4] = std::mem::transmute(0.0f32);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 8] = std::mem::transmute(0.0f64);
|
||||
//~^ transmute_num_to_bytes
|
||||
|
||||
let _: [u8; 16] = std::mem::transmute(0.0f128);
|
||||
//~^ transmute_num_to_bytes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn bytes_to_str(mb: &mut [u8]) {
|
||||
const B: &[u8] = b"";
|
||||
|
||||
|
|
|
|||
|
|
@ -97,230 +97,8 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) };
|
|||
= note: `-D clippy::transmute-int-to-bool` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_bool)]`
|
||||
|
||||
error: transmute from a `u16` to a `f16`
|
||||
--> tests/ui/transmute.rs:122:31
|
||||
|
|
||||
LL | let _: f16 = unsafe { std::mem::transmute(0_u16) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_u16)`
|
||||
|
|
||||
= note: `-D clippy::transmute-int-to-float` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_float)]`
|
||||
|
||||
error: transmute from a `i16` to a `f16`
|
||||
--> tests/ui/transmute.rs:125:31
|
||||
|
|
||||
LL | let _: f16 = unsafe { std::mem::transmute(0_i16) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_i16 as u16)`
|
||||
|
||||
error: transmute from a `u32` to a `f32`
|
||||
--> tests/ui/transmute.rs:128:31
|
||||
|
|
||||
LL | let _: f32 = unsafe { std::mem::transmute(0_u32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)`
|
||||
|
||||
error: transmute from a `i32` to a `f32`
|
||||
--> tests/ui/transmute.rs:131:31
|
||||
|
|
||||
LL | let _: f32 = unsafe { std::mem::transmute(0_i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)`
|
||||
|
||||
error: transmute from a `u64` to a `f64`
|
||||
--> tests/ui/transmute.rs:134:31
|
||||
|
|
||||
LL | let _: f64 = unsafe { std::mem::transmute(0_u64) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)`
|
||||
|
||||
error: transmute from a `i64` to a `f64`
|
||||
--> tests/ui/transmute.rs:137:31
|
||||
|
|
||||
LL | let _: f64 = unsafe { std::mem::transmute(0_i64) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)`
|
||||
|
||||
error: transmute from a `u128` to a `f128`
|
||||
--> tests/ui/transmute.rs:140:32
|
||||
|
|
||||
LL | let _: f128 = unsafe { std::mem::transmute(0_u128) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_u128)`
|
||||
|
||||
error: transmute from a `i128` to a `f128`
|
||||
--> tests/ui/transmute.rs:143:32
|
||||
|
|
||||
LL | let _: f128 = unsafe { std::mem::transmute(0_i128) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_i128 as u128)`
|
||||
|
||||
error: transmute from a `u16` to a `f16`
|
||||
--> tests/ui/transmute.rs:148:39
|
||||
|
|
||||
LL | const VALUE16: f16 = unsafe { std::mem::transmute(0_u16) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_u16)`
|
||||
|
||||
error: transmute from a `u32` to a `f32`
|
||||
--> tests/ui/transmute.rs:151:39
|
||||
|
|
||||
LL | const VALUE32: f32 = unsafe { std::mem::transmute(0_u32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)`
|
||||
|
||||
error: transmute from a `i64` to a `f64`
|
||||
--> tests/ui/transmute.rs:154:39
|
||||
|
|
||||
LL | const VALUE64: f64 = unsafe { std::mem::transmute(0_i64) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)`
|
||||
|
||||
error: transmute from a `i128` to a `f128`
|
||||
--> tests/ui/transmute.rs:157:41
|
||||
|
|
||||
LL | const VALUE128: f128 = unsafe { std::mem::transmute(0_i128) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_i128 as u128)`
|
||||
|
||||
error: transmute from a `i16` to a `f16`
|
||||
--> tests/ui/transmute.rs:161:22
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(v as u16)`
|
||||
|
||||
error: transmute from a `i32` to a `f32`
|
||||
--> tests/ui/transmute.rs:166:22
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(v as u32)`
|
||||
|
||||
error: transmute from a `u64` to a `f64`
|
||||
--> tests/ui/transmute.rs:171:22
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(v)`
|
||||
|
||||
error: transmute from a `u128` to a `f128`
|
||||
--> tests/ui/transmute.rs:176:22
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(v)`
|
||||
|
||||
error: transmute from a `u8` to a `[u8; 1]`
|
||||
--> tests/ui/transmute.rs:185:30
|
||||
|
|
||||
LL | let _: [u8; 1] = std::mem::transmute(0u8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()`
|
||||
|
|
||||
= note: `-D clippy::transmute-num-to-bytes` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::transmute_num_to_bytes)]`
|
||||
|
||||
error: transmute from a `u32` to a `[u8; 4]`
|
||||
--> tests/ui/transmute.rs:188:30
|
||||
|
|
||||
LL | let _: [u8; 4] = std::mem::transmute(0u32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `u128` to a `[u8; 16]`
|
||||
--> tests/ui/transmute.rs:191:31
|
||||
|
|
||||
LL | let _: [u8; 16] = std::mem::transmute(0u128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `i8` to a `[u8; 1]`
|
||||
--> tests/ui/transmute.rs:194:30
|
||||
|
|
||||
LL | let _: [u8; 1] = std::mem::transmute(0i8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `i32` to a `[u8; 4]`
|
||||
--> tests/ui/transmute.rs:197:30
|
||||
|
|
||||
LL | let _: [u8; 4] = std::mem::transmute(0i32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `i128` to a `[u8; 16]`
|
||||
--> tests/ui/transmute.rs:200:31
|
||||
|
|
||||
LL | let _: [u8; 16] = std::mem::transmute(0i128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f16` to a `[u8; 2]`
|
||||
--> tests/ui/transmute.rs:203:30
|
||||
|
|
||||
LL | let _: [u8; 2] = std::mem::transmute(0.0f16);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f16.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f32` to a `[u8; 4]`
|
||||
--> tests/ui/transmute.rs:206:30
|
||||
|
|
||||
LL | let _: [u8; 4] = std::mem::transmute(0.0f32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f32.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f64` to a `[u8; 8]`
|
||||
--> tests/ui/transmute.rs:209:30
|
||||
|
|
||||
LL | let _: [u8; 8] = std::mem::transmute(0.0f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f64.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f128` to a `[u8; 16]`
|
||||
--> tests/ui/transmute.rs:212:31
|
||||
|
|
||||
LL | let _: [u8; 16] = std::mem::transmute(0.0f128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f128.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `u8` to a `[u8; 1]`
|
||||
--> tests/ui/transmute.rs:218:30
|
||||
|
|
||||
LL | let _: [u8; 1] = std::mem::transmute(0u8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `u32` to a `[u8; 4]`
|
||||
--> tests/ui/transmute.rs:221:30
|
||||
|
|
||||
LL | let _: [u8; 4] = std::mem::transmute(0u32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `u128` to a `[u8; 16]`
|
||||
--> tests/ui/transmute.rs:224:31
|
||||
|
|
||||
LL | let _: [u8; 16] = std::mem::transmute(0u128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `i8` to a `[u8; 1]`
|
||||
--> tests/ui/transmute.rs:227:30
|
||||
|
|
||||
LL | let _: [u8; 1] = std::mem::transmute(0i8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `i32` to a `[u8; 4]`
|
||||
--> tests/ui/transmute.rs:230:30
|
||||
|
|
||||
LL | let _: [u8; 4] = std::mem::transmute(0i32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `i128` to a `[u8; 16]`
|
||||
--> tests/ui/transmute.rs:233:31
|
||||
|
|
||||
LL | let _: [u8; 16] = std::mem::transmute(0i128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f16` to a `[u8; 2]`
|
||||
--> tests/ui/transmute.rs:236:30
|
||||
|
|
||||
LL | let _: [u8; 2] = std::mem::transmute(0.0f16);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f16.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f32` to a `[u8; 4]`
|
||||
--> tests/ui/transmute.rs:239:30
|
||||
|
|
||||
LL | let _: [u8; 4] = std::mem::transmute(0.0f32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f32.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f64` to a `[u8; 8]`
|
||||
--> tests/ui/transmute.rs:242:30
|
||||
|
|
||||
LL | let _: [u8; 8] = std::mem::transmute(0.0f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f64.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `f128` to a `[u8; 16]`
|
||||
--> tests/ui/transmute.rs:245:31
|
||||
|
|
||||
LL | let _: [u8; 16] = std::mem::transmute(0.0f128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f128.to_ne_bytes()`
|
||||
|
||||
error: transmute from a `&[u8]` to a `&str`
|
||||
--> tests/ui/transmute.rs:254:28
|
||||
--> tests/ui/transmute.rs:122:28
|
||||
|
|
||||
LL | let _: &str = unsafe { std::mem::transmute(B) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()`
|
||||
|
|
@ -329,16 +107,16 @@ LL | let _: &str = unsafe { std::mem::transmute(B) };
|
|||
= help: to override `-D warnings` add `#[allow(clippy::transmute_bytes_to_str)]`
|
||||
|
||||
error: transmute from a `&mut [u8]` to a `&mut str`
|
||||
--> tests/ui/transmute.rs:257:32
|
||||
--> tests/ui/transmute.rs:125:32
|
||||
|
|
||||
LL | let _: &mut str = unsafe { std::mem::transmute(mb) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()`
|
||||
|
||||
error: transmute from a `&[u8]` to a `&str`
|
||||
--> tests/ui/transmute.rs:260:30
|
||||
--> tests/ui/transmute.rs:128:30
|
||||
|
|
||||
LL | const _: &str = unsafe { std::mem::transmute(B) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)`
|
||||
|
||||
error: aborting due to 54 previous errors
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
#![warn(clippy::transmute_float_to_int)]
|
||||
#![allow(clippy::missing_transmute_annotations, unnecessary_transmutes)]
|
||||
#![feature(f128)]
|
||||
#![feature(f16)]
|
||||
|
||||
fn float_to_int() {
|
||||
let _: u32 = unsafe { 1f32.to_bits() };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: i32 = unsafe { 1f32.to_bits() as i32 };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: u64 = unsafe { 1f64.to_bits() };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: i64 = unsafe { 1f64.to_bits() as i64 };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: u64 = unsafe { 1.0f64.to_bits() };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: u64 = unsafe { (-1.0f64).to_bits() };
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
mod issue_5747 {
|
||||
const VALUE16: i16 = unsafe { 1f16.to_bits() as i16 };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const VALUE32: i32 = unsafe { 1f32.to_bits() as i32 };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const VALUE64: u64 = unsafe { 1f64.to_bits() };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const VALUE128: u128 = unsafe { 1f128.to_bits() };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const fn to_bits_16(v: f16) -> u16 {
|
||||
unsafe { v.to_bits() }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
const fn to_bits_32(v: f32) -> u32 {
|
||||
unsafe { v.to_bits() }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
const fn to_bits_64(v: f64) -> i64 {
|
||||
unsafe { v.to_bits() as i64 }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
const fn to_bits_128(v: f128) -> i128 {
|
||||
unsafe { v.to_bits() as i128 }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#![warn(clippy::transmute_float_to_int)]
|
||||
#![allow(clippy::missing_transmute_annotations, unnecessary_transmutes)]
|
||||
#![feature(f128)]
|
||||
#![feature(f16)]
|
||||
|
||||
fn float_to_int() {
|
||||
let _: u32 = unsafe { std::mem::transmute(1f32) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: i32 = unsafe { std::mem::transmute(1f32) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: u64 = unsafe { std::mem::transmute(1f64) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: i64 = unsafe { std::mem::transmute(1f64) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: u64 = unsafe { std::mem::transmute(1.0) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
let _: u64 = unsafe { std::mem::transmute(-1.0) };
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
mod issue_5747 {
|
||||
const VALUE16: i16 = unsafe { std::mem::transmute(1f16) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const VALUE32: i32 = unsafe { std::mem::transmute(1f32) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const VALUE64: u64 = unsafe { std::mem::transmute(1f64) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const VALUE128: u128 = unsafe { std::mem::transmute(1f128) };
|
||||
//~^ transmute_float_to_int
|
||||
|
||||
const fn to_bits_16(v: f16) -> u16 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
const fn to_bits_32(v: f32) -> u32 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
const fn to_bits_64(v: f64) -> i64 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
|
||||
const fn to_bits_128(v: f128) -> i128 {
|
||||
unsafe { std::mem::transmute(v) }
|
||||
//~^ transmute_float_to_int
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
error: transmute from a `f32` to a `u32`
|
||||
--> tests/ui/transmute_float_to_int.rs:7:27
|
||||
|
|
||||
LL | let _: u32 = unsafe { std::mem::transmute(1f32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()`
|
||||
|
|
||||
= note: `-D clippy::transmute-float-to-int` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::transmute_float_to_int)]`
|
||||
|
||||
error: transmute from a `f32` to a `i32`
|
||||
--> tests/ui/transmute_float_to_int.rs:10:27
|
||||
|
|
||||
LL | let _: i32 = unsafe { std::mem::transmute(1f32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32`
|
||||
|
||||
error: transmute from a `f64` to a `u64`
|
||||
--> tests/ui/transmute_float_to_int.rs:13:27
|
||||
|
|
||||
LL | let _: u64 = unsafe { std::mem::transmute(1f64) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()`
|
||||
|
||||
error: transmute from a `f64` to a `i64`
|
||||
--> tests/ui/transmute_float_to_int.rs:16:27
|
||||
|
|
||||
LL | let _: i64 = unsafe { std::mem::transmute(1f64) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64`
|
||||
|
||||
error: transmute from a `f64` to a `u64`
|
||||
--> tests/ui/transmute_float_to_int.rs:19:27
|
||||
|
|
||||
LL | let _: u64 = unsafe { std::mem::transmute(1.0) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()`
|
||||
|
||||
error: transmute from a `f64` to a `u64`
|
||||
--> tests/ui/transmute_float_to_int.rs:22:27
|
||||
|
|
||||
LL | let _: u64 = unsafe { std::mem::transmute(-1.0) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()`
|
||||
|
||||
error: transmute from a `f16` to a `i16`
|
||||
--> tests/ui/transmute_float_to_int.rs:27:35
|
||||
|
|
||||
LL | const VALUE16: i16 = unsafe { std::mem::transmute(1f16) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f16.to_bits() as i16`
|
||||
|
||||
error: transmute from a `f32` to a `i32`
|
||||
--> tests/ui/transmute_float_to_int.rs:30:35
|
||||
|
|
||||
LL | const VALUE32: i32 = unsafe { std::mem::transmute(1f32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32`
|
||||
|
||||
error: transmute from a `f64` to a `u64`
|
||||
--> tests/ui/transmute_float_to_int.rs:33:35
|
||||
|
|
||||
LL | const VALUE64: u64 = unsafe { std::mem::transmute(1f64) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()`
|
||||
|
||||
error: transmute from a `f128` to a `u128`
|
||||
--> tests/ui/transmute_float_to_int.rs:36:37
|
||||
|
|
||||
LL | const VALUE128: u128 = unsafe { std::mem::transmute(1f128) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f128.to_bits()`
|
||||
|
||||
error: transmute from a `f16` to a `u16`
|
||||
--> tests/ui/transmute_float_to_int.rs:40:18
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits()`
|
||||
|
||||
error: transmute from a `f32` to a `u32`
|
||||
--> tests/ui/transmute_float_to_int.rs:45:18
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits()`
|
||||
|
||||
error: transmute from a `f64` to a `i64`
|
||||
--> tests/ui/transmute_float_to_int.rs:50:18
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits() as i64`
|
||||
|
||||
error: transmute from a `f128` to a `i128`
|
||||
--> tests/ui/transmute_float_to_int.rs:55:18
|
||||
|
|
||||
LL | unsafe { std::mem::transmute(v) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits() as i128`
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#![warn(clippy::transmute_int_to_char)]
|
||||
#![allow(clippy::missing_transmute_annotations, unnecessary_transmutes)]
|
||||
|
||||
fn int_to_char() {
|
||||
let _: char = unsafe { std::char::from_u32(0_u32).unwrap() };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
let _: char = unsafe { std::char::from_u32(0_i32 as u32).unwrap() };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
// These shouldn't warn
|
||||
const _: char = unsafe { std::mem::transmute(0_u32) };
|
||||
const _: char = unsafe { std::mem::transmute(0_i32) };
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#![warn(clippy::transmute_int_to_char)]
|
||||
#![allow(clippy::missing_transmute_annotations, unnecessary_transmutes)]
|
||||
|
||||
fn int_to_char() {
|
||||
let _: char = unsafe { std::mem::transmute(0_u32) };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
let _: char = unsafe { std::mem::transmute(0_i32) };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
// These shouldn't warn
|
||||
const _: char = unsafe { std::mem::transmute(0_u32) };
|
||||
const _: char = unsafe { std::mem::transmute(0_i32) };
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
error: transmute from a `u32` to a `char`
|
||||
--> tests/ui/transmute_int_to_char.rs:5:28
|
||||
|
|
||||
LL | let _: char = unsafe { std::mem::transmute(0_u32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()`
|
||||
|
|
||||
= note: `-D clippy::transmute-int-to-char` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]`
|
||||
|
||||
error: transmute from a `i32` to a `char`
|
||||
--> tests/ui/transmute_int_to_char.rs:8:28
|
||||
|
|
||||
LL | let _: char = unsafe { std::mem::transmute(0_i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#![no_std]
|
||||
#![feature(lang_items)]
|
||||
#![warn(clippy::transmute_int_to_char)]
|
||||
#![allow(clippy::missing_transmute_annotations, unnecessary_transmutes)]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
extern "C" fn eh_personality() {}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn int_to_char() {
|
||||
let _: char = unsafe { core::char::from_u32(0_u32).unwrap() };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
let _: char = unsafe { core::char::from_u32(0_i32 as u32).unwrap() };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
// These shouldn't warn
|
||||
const _: char = unsafe { core::mem::transmute(0_u32) };
|
||||
const _: char = unsafe { core::mem::transmute(0_i32) };
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#![no_std]
|
||||
#![feature(lang_items)]
|
||||
#![warn(clippy::transmute_int_to_char)]
|
||||
#![allow(clippy::missing_transmute_annotations, unnecessary_transmutes)]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
extern "C" fn eh_personality() {}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn int_to_char() {
|
||||
let _: char = unsafe { core::mem::transmute(0_u32) };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
let _: char = unsafe { core::mem::transmute(0_i32) };
|
||||
//~^ transmute_int_to_char
|
||||
|
||||
// These shouldn't warn
|
||||
const _: char = unsafe { core::mem::transmute(0_u32) };
|
||||
const _: char = unsafe { core::mem::transmute(0_i32) };
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
error: transmute from a `u32` to a `char`
|
||||
--> tests/ui/transmute_int_to_char_no_std.rs:17:28
|
||||
|
|
||||
LL | let _: char = unsafe { core::mem::transmute(0_u32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::char::from_u32(0_u32).unwrap()`
|
||||
|
|
||||
= note: `-D clippy::transmute-int-to-char` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]`
|
||||
|
||||
error: transmute from a `i32` to a `char`
|
||||
--> tests/ui/transmute_int_to_char_no_std.rs:20:28
|
||||
|
|
||||
LL | let _: char = unsafe { core::mem::transmute(0_i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::char::from_u32(0_i32 as u32).unwrap()`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ pub fn foo<T>(_t: T)
|
|||
where
|
||||
T: Copy,
|
||||
T: Clone,
|
||||
//~^ ERROR: this type has already been used as a bound predicate
|
||||
//~^ type_repetition_in_bounds
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ trait LintBounds
|
|||
where
|
||||
Self: Clone,
|
||||
Self: Copy + Default + Ord,
|
||||
//~^ ERROR: this type has already been used as a bound predicate
|
||||
//~^ type_repetition_in_bounds
|
||||
Self: Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign,
|
||||
Self: Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign,
|
||||
{
|
||||
|
|
@ -105,13 +105,13 @@ where
|
|||
pub fn f<T: ?Sized>()
|
||||
where
|
||||
T: Clone,
|
||||
//~^ ERROR: this type has already been used as a bound predicate
|
||||
//~^ type_repetition_in_bounds
|
||||
{
|
||||
}
|
||||
pub fn g<T: Clone>()
|
||||
where
|
||||
T: ?Sized,
|
||||
//~^ ERROR: this type has already been used as a bound predicate
|
||||
//~^ type_repetition_in_bounds
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -137,10 +137,27 @@ mod issue8772_pass {
|
|||
pub fn f<T: ?Sized, U>(arg: usize)
|
||||
where
|
||||
T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
|
||||
//~^ ERROR: this type has already been used as a bound predicate
|
||||
//~^ type_repetition_in_bounds
|
||||
U: Clone + Sync + 'static,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
struct Issue14744<'a, K: 'a>
|
||||
where
|
||||
K: Clone,
|
||||
{
|
||||
phantom: std::marker::PhantomData<&'a K>,
|
||||
}
|
||||
//~^^^^ type_repetition_in_bounds
|
||||
|
||||
struct ComplexType<T>
|
||||
where
|
||||
Vec<T>: Clone,
|
||||
Vec<T>: Clone,
|
||||
{
|
||||
t: T,
|
||||
}
|
||||
//~^^^^ type_repetition_in_bounds
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: this type has already been used as a bound predicate
|
||||
error: type `T` has already been used as a bound predicate
|
||||
--> tests/ui/type_repetition_in_bounds.rs:14:5
|
||||
|
|
||||
LL | T: Clone,
|
||||
|
|
@ -11,7 +11,7 @@ note: the lint level is defined here
|
|||
LL | #![deny(clippy::type_repetition_in_bounds)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this type has already been used as a bound predicate
|
||||
error: type `Self` has already been used as a bound predicate
|
||||
--> tests/ui/type_repetition_in_bounds.rs:32:5
|
||||
|
|
||||
LL | Self: Copy + Default + Ord,
|
||||
|
|
@ -19,7 +19,7 @@ LL | Self: Copy + Default + Ord,
|
|||
|
|
||||
= help: consider combining the bounds: `Self: Clone + Copy + Default + Ord`
|
||||
|
||||
error: this type has already been used as a bound predicate
|
||||
error: type `T` has already been used as a bound predicate
|
||||
--> tests/ui/type_repetition_in_bounds.rs:107:5
|
||||
|
|
||||
LL | T: Clone,
|
||||
|
|
@ -27,7 +27,7 @@ LL | T: Clone,
|
|||
|
|
||||
= help: consider combining the bounds: `T: ?Sized + Clone`
|
||||
|
||||
error: this type has already been used as a bound predicate
|
||||
error: type `T` has already been used as a bound predicate
|
||||
--> tests/ui/type_repetition_in_bounds.rs:113:5
|
||||
|
|
||||
LL | T: ?Sized,
|
||||
|
|
@ -35,13 +35,29 @@ LL | T: ?Sized,
|
|||
|
|
||||
= help: consider combining the bounds: `T: Clone + ?Sized`
|
||||
|
||||
error: this type has already been used as a bound predicate
|
||||
error: type `T` has already been used as a bound predicate
|
||||
--> tests/ui/type_repetition_in_bounds.rs:139:9
|
||||
|
|
||||
LL | T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider combining the bounds: `T: ?Sized + Trait<Option<usize>, Box<[String]>, bool>`
|
||||
= help: consider combining the bounds: `T: ?Sized + Trait<Option<usize>, Box<[String]>, bool> + 'static`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: type `K` has already been used as a bound predicate
|
||||
--> tests/ui/type_repetition_in_bounds.rs:148:5
|
||||
|
|
||||
LL | K: Clone,
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: consider combining the bounds: `K: 'a + Clone`
|
||||
|
||||
error: type `Vec<T>` has already been used as a bound predicate
|
||||
--> tests/ui/type_repetition_in_bounds.rs:157:5
|
||||
|
|
||||
LL | Vec<T>: Clone,
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider combining the bounds: `Vec<T>: Clone + Clone`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -119,3 +119,11 @@ fn main() {
|
|||
foo();
|
||||
bar();
|
||||
}
|
||||
|
||||
mod issue14704 {
|
||||
use std::sync::Arc;
|
||||
|
||||
trait Action {
|
||||
async fn cancel(self: Arc<Self>) {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,3 +66,20 @@ fn main() {
|
|||
SOME.expect("Still not three?");
|
||||
}
|
||||
}
|
||||
|
||||
mod with_expansion {
|
||||
macro_rules! open {
|
||||
($file:expr) => {
|
||||
std::fs::File::open($file)
|
||||
};
|
||||
}
|
||||
|
||||
fn test(file: &str) {
|
||||
use std::io::Read;
|
||||
let mut s = String::new();
|
||||
let _ = open!(file).unwrap(); //~ unwrap_used
|
||||
let _ = open!(file).expect("can open"); //~ expect_used
|
||||
let _ = open!(file).unwrap_err(); //~ unwrap_used
|
||||
let _ = open!(file).expect_err("can open"); //~ expect_used
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,5 +50,37 @@ LL | a.expect_err("Hello error!");
|
|||
|
|
||||
= note: if this value is an `Ok`, it will panic
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: used `unwrap()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:80:17
|
||||
|
|
||||
LL | let _ = open!(file).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Err`, it will panic
|
||||
|
||||
error: used `expect()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:81:17
|
||||
|
|
||||
LL | let _ = open!(file).expect("can open");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Err`, it will panic
|
||||
|
||||
error: used `unwrap_err()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:82:17
|
||||
|
|
||||
LL | let _ = open!(file).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Ok`, it will panic
|
||||
|
||||
error: used `expect_err()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:83:17
|
||||
|
|
||||
LL | let _ = open!(file).expect_err("can open");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Ok`, it will panic
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue