Auto merge of #146069 - camsteffen:range-desugar-span, r=SparrowLii

Mark desugared range expression spans with DesugaringKind::RangeExpr

This is a prerequisite to removing `QPath::LangItem` (rust-lang/rust#115178) because otherwise there would be no way to detect a range expression in the HIR.

There are some non-obvious Clippy changes so a Clippy team review would be good.
This commit is contained in:
bors
2025-10-27 02:50:35 +00:00
30 changed files with 136 additions and 75 deletions

View File

@@ -20,7 +20,7 @@ use rustc_hir::intravisit::{Visitor, VisitorExt};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{
self as hir, AmbigArg, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, HirId, Node,
expr_needs_parens, is_range_literal,
expr_needs_parens,
};
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferCtxt, InferOk};
use rustc_middle::middle::privacy::Level;
@@ -668,12 +668,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
);
}
let derefs = "*".repeat(steps);
let needs_parens = steps > 0
&& match expr.kind {
hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true,
_ if is_range_literal(expr) => true,
_ => false,
};
let needs_parens = steps > 0 && expr_needs_parens(expr);
let mut suggestion = if needs_parens {
vec![
(