Skip to content

Commit 0cf87a7

Browse files
committed
Revert is_range_literal change
1 parent 7dce8b2 commit 0cf87a7

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use rustc_index::IndexVec;
2323
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
2424
use rustc_span::def_id::LocalDefId;
2525
use rustc_span::source_map::Spanned;
26-
use rustc_span::{
27-
BytePos, DUMMY_SP, DesugaringKind, ErrorGuaranteed, Ident, Span, Symbol, kw, sym,
28-
};
26+
use rustc_span::{BytePos, DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
2927
use rustc_target::asm::InlineAsmRegOrRegClass;
3028
use smallvec::SmallVec;
3129
use thin_vec::ThinVec;
@@ -2713,8 +2711,31 @@ impl Expr<'_> {
27132711
/// Checks if the specified expression is a built-in range literal.
27142712
/// (See: `LoweringContext::lower_expr()`).
27152713
pub fn is_range_literal(expr: &Expr<'_>) -> bool {
2716-
matches!(expr.kind, ExprKind::Call(..) | ExprKind::Struct(..))
2717-
&& expr.span.desugaring_kind() == Some(DesugaringKind::RangeExpr)
2714+
match expr.kind {
2715+
// All built-in range literals but `..=` and `..` desugar to `Struct`s.
2716+
ExprKind::Struct(ref qpath, _, _) => matches!(
2717+
**qpath,
2718+
QPath::LangItem(
2719+
LangItem::Range
2720+
| LangItem::RangeTo
2721+
| LangItem::RangeFrom
2722+
| LangItem::RangeFull
2723+
| LangItem::RangeToInclusive
2724+
| LangItem::RangeCopy
2725+
| LangItem::RangeFromCopy
2726+
| LangItem::RangeInclusiveCopy
2727+
| LangItem::RangeToInclusiveCopy,
2728+
..
2729+
)
2730+
),
2731+
2732+
// `..=` desugars into `::std::ops::RangeInclusive::new(...)`.
2733+
ExprKind::Call(ref func, _) => {
2734+
matches!(func.kind, ExprKind::Path(QPath::LangItem(LangItem::RangeInclusiveNew, ..)))
2735+
}
2736+
2737+
_ => false,
2738+
}
27182739
}
27192740

27202741
/// Checks if the specified expression needs parentheses for prefix

0 commit comments

Comments
 (0)