Skip to content

Commit dd7f493

Browse files
committed
is_range_literal: fix fallout
1 parent 45acee3 commit dd7f493

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

src/librustc/hir/mod.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ use syntax::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle,
2929
pub use syntax::ast::{BorrowKind, ImplPolarity, IsAuto};
3030
pub use syntax::ast::{CaptureBy, Constness, Movability, Mutability, Unsafety};
3131
use syntax::attr::{InlineAttr, OptimizeAttr};
32-
use syntax::source_map::Spanned;
33-
use syntax::symbol::{kw, Symbol};
3432
use syntax::tokenstream::TokenStream;
3533
use syntax::util::parser::ExprPrecedence;
34+
use syntax_pos::source_map::{SourceMap, Spanned};
35+
use syntax_pos::symbol::{kw, sym, Symbol};
3636
use syntax_pos::{MultiSpan, Span, DUMMY_SP};
3737

3838
/// HIR doesn't commit to a concrete storage type and has its own alias for a vector.
@@ -1566,9 +1566,7 @@ impl fmt::Debug for Expr {
15661566

15671567
/// Checks if the specified expression is a built-in range literal.
15681568
/// (See: `LoweringContext::lower_expr()`).
1569-
pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
1570-
use hir::{Path, QPath, ExprKind, TyKind};
1571-
1569+
pub fn is_range_literal(sm: &SourceMap, expr: &Expr) -> bool {
15721570
// Returns whether the given path represents a (desugared) range,
15731571
// either in std or core, i.e. has either a `::std::ops::Range` or
15741572
// `::core::ops::Range` prefix.
@@ -1586,11 +1584,10 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
15861584

15871585
// Check whether a span corresponding to a range expression is a
15881586
// range literal, rather than an explicit struct or `new()` call.
1589-
fn is_lit(sess: &Session, span: &Span) -> bool {
1590-
let source_map = sess.source_map();
1591-
let end_point = source_map.end_point(*span);
1587+
fn is_lit(sm: &SourceMap, span: &Span) -> bool {
1588+
let end_point = sm.end_point(*span);
15921589

1593-
if let Ok(end_string) = source_map.span_to_snippet(end_point) {
1590+
if let Ok(end_string) = sm.span_to_snippet(end_point) {
15941591
!(end_string.ends_with("}") || end_string.ends_with(")"))
15951592
} else {
15961593
false
@@ -1601,21 +1598,21 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
16011598
// All built-in range literals but `..=` and `..` desugar to `Struct`s.
16021599
ExprKind::Struct(ref qpath, _, _) => {
16031600
if let QPath::Resolved(None, ref path) = **qpath {
1604-
return is_range_path(&path) && is_lit(sess, &expr.span);
1601+
return is_range_path(&path) && is_lit(sm, &expr.span);
16051602
}
16061603
}
16071604

16081605
// `..` desugars to its struct path.
16091606
ExprKind::Path(QPath::Resolved(None, ref path)) => {
1610-
return is_range_path(&path) && is_lit(sess, &expr.span);
1607+
return is_range_path(&path) && is_lit(sm, &expr.span);
16111608
}
16121609

16131610
// `..=` desugars into `::std::ops::RangeInclusive::new(...)`.
16141611
ExprKind::Call(ref func, _) => {
16151612
if let ExprKind::Path(QPath::TypeRelative(ref ty, ref segment)) = func.kind {
16161613
if let TyKind::Path(QPath::Resolved(None, ref path)) = ty.kind {
16171614
let new_call = segment.ident.name == sym::new;
1618-
return is_range_path(&path) && is_lit(sess, &expr.span) && new_call;
1615+
return is_range_path(&path) && is_lit(sm, &expr.span) && new_call;
16191616
}
16201617
}
16211618
}

src/librustc_lint/types.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use crate::hir::def_id::DefId;
44
use lint::{LateContext, LintArray, LintContext};
55
use lint::{LateLintPass, LintPass};
6-
use rustc::hir::lowering::is_range_literal;
7-
use rustc::hir::{ExprKind, Node};
6+
use rustc::hir::{is_range_literal, ExprKind, Node};
87
use rustc::ty::layout::{self, IntegerExt, LayoutOf, SizeSkeleton, VariantIdx};
98
use rustc::ty::subst::SubstsRef;
109
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
@@ -266,7 +265,7 @@ fn lint_int_literal<'a, 'tcx>(
266265
let par_id = cx.tcx.hir().get_parent_node(e.hir_id);
267266
if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) {
268267
if let hir::ExprKind::Struct(..) = par_e.kind {
269-
if is_range_literal(cx.sess(), par_e)
268+
if is_range_literal(cx.sess().source_map(), par_e)
270269
&& lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t.name_str())
271270
{
272271
// The overflowing literal lint was overridden.
@@ -318,7 +317,7 @@ fn lint_uint_literal<'a, 'tcx>(
318317
return;
319318
}
320319
}
321-
hir::ExprKind::Struct(..) if is_range_literal(cx.sess(), par_e) => {
320+
hir::ExprKind::Struct(..) if is_range_literal(cx.sess().source_map(), par_e) => {
322321
let t = t.name_str();
323322
if lint_overflowing_range_endpoint(cx, lit, lit_val, max, e, par_e, t) {
324323
// The overflowing literal lint was overridden.

src/librustc_typeck/check/demand.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use rustc::infer::InferOk;
33
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
44

55
use errors::{Applicability, DiagnosticBuilder};
6-
use rustc::hir;
7-
use rustc::hir::Node;
8-
use rustc::hir::{lowering::is_range_literal, print};
6+
use rustc::hir::{self, is_range_literal, print, Node};
97
use rustc::ty::adjustment::AllowTwoPhase;
108
use rustc::ty::{self, AssocItem, Ty};
119
use syntax::symbol::sym;
@@ -478,7 +476,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
478476
// parenthesize if needed (Issue #46756)
479477
hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true,
480478
// parenthesize borrows of range literals (Issue #54505)
481-
_ if is_range_literal(self.tcx.sess, expr) => true,
479+
_ if is_range_literal(self.tcx.sess.source_map(), expr) => true,
482480
_ => false,
483481
};
484482
let sugg_expr = if needs_parens { format!("({})", src) } else { src };

0 commit comments

Comments
 (0)