Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. If you cannot produce a minimal reproduction case (something that would work in isolation), please provide the steps or even link to a repository that causes the problematic output to occur. --Given the following code: The current output is: But with the suggestion applied the compiler displays an error with a different suggestion: <!-- The following is not always necessary. --Ideally the compiler should not output a warning and treat and as identical. <!-- If the problem is not self-explanatory, please provide a rationale for the change. --<!-- If dramatically different output is caused by small changes, consider also adding them here. If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. The output might also be different depending on the Edition. -- label D-incorrect A-suggestion-diagnostics <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
claim
I think it's relate with and
It would be great if it could give since parenthesizing the expression instead avoids the potential "is that a tuple?" confusion of .
Duplicate of .

Discussion:
}) => self.check_id(closure_id), _ => {} } <ins> lint_callback!(self, check_expr_post, e); </ins> } fn visit_generic_arg(&mut self, arg: &'a ast::GenericArg) {

fn check_pat(a: &ast::Pat); fn check_pat_post(a: &ast::Pat); fn check_expr(a: &ast::Expr); <ins> fn check_expr_post(a: &ast::Expr); </ins> fn check_ty(a: &ast::Ty); fn check_generic_arg(a: &ast::GenericArg); fn check_generic_param(a: &ast::GenericParam);

pub struct UnusedParens { with_self_ty_parens: bool, <ins> /// `1 as (i32) < 2` parses to ExprKind::Lt /// `1 as i32 < 2` parses to i32::<2[missing angle bracket] parens_in_cast_in_lt: Vec<ast::NodeId>, </ins> } impl UnusedParens { pub fn new() -> Self { <del> Self { with_self_ty_parens: false } </del> <ins> Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() } </ins> } }

impl EarlyLintPass for UnusedParens { #[inline] fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { <ins> if let ExprKind::Binary(op, lhs, _rhs) = &e.kind && (op.node == ast::BinOpKind::Lt || op.node == ast::BinOpKind::Shl) && let ExprKind::Cast(_expr, ty) = &lhs.kind && let ast::TyKind::Paren(_) = &ty.kind { self.parens_in_cast_in_lt.push(ty.id); } </ins> match e.kind { ExprKind::Let(ref pat, _, _) | ExprKind::ForLoop(ref pat, ..) => { self.check_unused_parens_pat(cx, pat, false, false, (true, true));

<Self as UnusedDelimLint>::check_expr(self, cx, e) } <ins> fn check_expr_post(&mut self, _cx: &EarlyContext<'_>, e: &ast::Expr) { if let ExprKind::Binary(op, lhs, _rhs) = &e.kind && (op.node == ast::BinOpKind::Lt || op.node == ast::BinOpKind::Shl) && let ExprKind::Cast(_expr, ty) = &lhs.kind && let ast::TyKind::Paren(_) = &ty.kind { let id = self.parens_in_cast_in_lt.pop().expect("check_expr and check_expr_post must balance"); assert_eq!(id, ty.id, "check_expr, check_ty, and check_expr_post are called, in that order, by the visitor"); } } </ins> fn check_pat(&mut self, cx: &EarlyContext<'_>, p: &ast::Pat) { use ast::{Mutability, PatKind::*}; let keep_space = (false, false);

} fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) { <ins> if let ast::TyKind::Paren(_) = ty.kind && Some(&ty.id) == self.parens_in_cast_in_lt.last() { return; } </ins> match &ty.kind { ast::TyKind::Array(_, len) => { self.check_unused_delims_expr(

<ins> // check-pass #![warn(unused_parens)] fn id<T>(t: T) -> T { t } fn main() { // This should not warn let _ = 1 as (i32) < 2; let _ = id(1 as (i32) < 2); let _ = id(1 as i32) as (i32) < 2; // These should warn let _ = 1 as ((i32)) < 2; //~WARN unnecessary parentheses let _ = 1 as (i32); //~WARN unnecessary parentheses let _ = 1 as (i32) > 2; //~WARN unnecessary parentheses let _ = id(1 as (i32)) //~WARN unnecessary parentheses as (i32) < 2; let _ = id(1 as (i32)) < 2; //~WARN unnecessary parentheses // This should not warn let _ = 1 as (i32) << 2; let _ = id(1 as (i32) << 2); let _ = id(1 as i32) as (i32) << 2; // These should warn let _ = 1 as ((i32)) << 2; //~WARN unnecessary parentheses let _ = 1 as (i32); //~WARN unnecessary parentheses let _ = 1 as (i32) >> 2; //~WARN unnecessary parentheses let _ = id(1 as (i32)) //~WARN unnecessary parentheses as (i32) << 2; let _ = id(1 as (i32)) << 2; //~WARN unnecessary parentheses } </ins>

<ins> warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:13:19 | LL |     let _ = 1 as ((i32)) < 2; |                   ^   ^ | note: the lint level is defined here --> $DIR/unused-parens-issue-106413.rs:2:9 | LL | #![warn(unused_parens)] |         ^^^^^^^^^^^^^ help: remove these parentheses | LL -     let _ = 1 as ((i32)) < 2; LL +     let _ = 1 as (i32) < 2; | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:14:18 | LL |     let _ = 1 as (i32); |                  ^   ^ | help: remove these parentheses | LL -     let _ = 1 as (i32); LL +     let _ = 1 as i32; | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:15:18 | LL |     let _ = 1 as (i32) > 2; |                  ^   ^ | help: remove these parentheses | LL -     let _ = 1 as (i32) > 2; LL +     let _ = 1 as i32 > 2; | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:16:21 | LL |     let _ = id(1 as (i32)) |                     ^   ^ | help: remove these parentheses | LL -     let _ = id(1 as (i32)) LL +     let _ = id(1 as i32) | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:18:21 | LL |     let _ = id(1 as (i32)) < 2; |                     ^   ^ | help: remove these parentheses | LL -     let _ = id(1 as (i32)) < 2; LL +     let _ = id(1 as i32) < 2; | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:26:19 | LL |     let _ = 1 as ((i32)) << 2; |                   ^   ^ | help: remove these parentheses | LL -     let _ = 1 as ((i32)) << 2; LL +     let _ = 1 as (i32) << 2; | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:27:18 | LL |     let _ = 1 as (i32); |                  ^   ^ | help: remove these parentheses | LL -     let _ = 1 as (i32); LL +     let _ = 1 as i32; | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:28:18 | LL |     let _ = 1 as (i32) >> 2; |                  ^   ^ | help: remove these parentheses | LL -     let _ = 1 as (i32) >> 2; LL +     let _ = 1 as i32 >> 2; | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:29:21 | LL |     let _ = id(1 as (i32)) |                     ^   ^ | help: remove these parentheses | LL -     let _ = id(1 as (i32)) LL +     let _ = id(1 as i32) | warning: unnecessary parentheses around type --> $DIR/unused-parens-issue-106413.rs:31:21 | LL |     let _ = id(1 as (i32)) << 2; |                     ^   ^ | help: remove these parentheses | LL -     let _ = id(1 as (i32)) << 2; LL +     let _ = id(1 as i32) << 2; | warning: 10 warnings emitted </ins>