@@ -23,9 +23,7 @@ use rustc_index::IndexVec;
2323use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
2424use rustc_span:: def_id:: LocalDefId ;
2525use 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} ;
2927use rustc_target:: asm:: InlineAsmRegOrRegClass ;
3028use smallvec:: SmallVec ;
3129use 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()`).
27152713pub 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