Change:
} } <del> let sugg = mutability.ref_prefix_str(); let (sugg, verbose) = if needs_parens { ( vec![ (sp.shrink_to_lo(), format!("{prefix}{sugg}(")), (sp.shrink_to_hi(), ")".to_string()), ], false, ) } else { (vec![(sp.shrink_to_lo(), format!("{prefix}{sugg}"))], true) </del> <ins> let make_sugg = |expr: &Expr<'_>, span: Span, sugg: &str| { let needs_parens = match expr.kind { // parenthesize if needed (Issue #46756) hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true, // parenthesize borrows of range literals (Issue #54505) _ if is_range_literal(expr) => true, _ => false, }; if needs_parens { ( vec![ (span.shrink_to_lo(), format!("{prefix}{sugg}(")), (span.shrink_to_hi(), ")".to_string()), ], false, ) } else { (vec![(span.shrink_to_lo(), format!("{prefix}{sugg}"))], true) } </ins> }; <ins> // Suggest dereferencing the lhs for expressions such as `&T == T` if let Some(hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(_, lhs, ..), .. })) = self.tcx.hir().find_parent(expr.hir_id) && let &ty::Ref(..) = self.check_expr(lhs).kind() { let (sugg, verbose) = make_sugg(lhs, lhs.span, "*"); return Some(( sugg, "consider dereferencing the borrow".to_string(), Applicability::MachineApplicable, verbose, false, )); } let sugg = mutability.ref_prefix_str(); let (sugg, verbose) = make_sugg(expr, sp, sugg); </ins> return Some(( sugg, format!("consider {}borrowing here", mutability.mutably_str()),

Discussion:
What I actually wanted was . <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
The problem is by the time this error is emittedwe don't have the information about the root cause anymore. In this case that would be the type of being checked for and figuring out the the rhs needs to be of the same type. Clippy has a lint that will tell you to clean it up afterwards, but we should probably issue a better diagnostic to begin with.
can you please create a ?
Please excuse my naïvety, but why is this (according to csmoes MCVE) a problem? You can actually write if i < &0 {} and everything works just fine. Can you please explain this part (to me)?
The comparison operator already takes references to both sides. so it seems simpler to dereference the lhs and save the monomorphizer and the optimizer some effort
Resurrecting this. what're the benefits of dereferencing the lhs instead of referencing the rhs? Also, if I were to go about fixing this, where would I start?
The benefit is that expands to , so if you start out with you get , seems better to just do instead (since is a no-op that gets easily removed). I'm not sure how to solve this or whether we should try at all.
claim
I want to get started with this, but would appreciate some mentoring from someone before I do, to point me in the right direction please
There's a reason I marked this as . I have no idea how to do this reasonably. I'm sorry, but I have no hints for you, and I don't even know if it's possible to do in a reasonable way.
cue terminator background music Leaving this here for future generations to see. I'm gonna try attempting to solve this and see if I can do something about it. I don't know if I can, or if I'll even survive this, but there's only one way to find out. Lol in all seriousness, if someone wants to claim this up, feel free to. Until then, I'll try and fix this.
Hi, are you still working on this issue
Hey I've been meaning to fix this up.

I've reached a point where I know exactly how to fix this as well. I just haven't found the time to fix this. Feel free to take it up, considering I wouldn't be having the time to work on this in the forseeable future.
release-assignment If do you find the time in the future, please claim this issue again. Until then I'll free it up in case anybody else wants it
Is anyone currently working on this? If not, I'd be happy to give it a go. claim