Skip to content

Commit 80a83ea

Browse files
committed
is_rnge_literal: fix fallout
1 parent a2cc3d6 commit 80a83ea

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

src/librustc/hir/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ use syntax::ast::{AttrVec, Attribute, Label, LitKind, StrStyle, FloatTy, IntTy,
2424
pub use syntax::ast::{Mutability, Constness, Unsafety, Movability, CaptureBy};
2525
pub use syntax::ast::{IsAuto, ImplPolarity, BorrowKind};
2626
use syntax::attr::{InlineAttr, OptimizeAttr};
27-
use syntax::symbol::{Symbol, kw};
2827
use syntax::tokenstream::TokenStream;
2928
use syntax::util::parser::ExprPrecedence;
29+
use syntax_pos::symbol::{Symbol, kw, sym};
30+
use syntax_pos::source_map::SourceMap;
3031
use rustc_target::spec::abi::Abi;
3132
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
3233
use rustc_macros::HashStable;
@@ -1597,9 +1598,7 @@ impl fmt::Debug for Expr {
15971598

15981599
/// Checks if the specified expression is a built-in range literal.
15991600
/// (See: `LoweringContext::lower_expr()`).
1600-
pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
1601-
use hir::{Path, QPath, ExprKind, TyKind};
1602-
1601+
pub fn is_range_literal(sm: &SourceMap, expr: &Expr) -> bool {
16031602
// Returns whether the given path represents a (desugared) range,
16041603
// either in std or core, i.e. has either a `::std::ops::Range` or
16051604
// `::core::ops::Range` prefix.
@@ -1617,11 +1616,10 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
16171616

16181617
// Check whether a span corresponding to a range expression is a
16191618
// range literal, rather than an explicit struct or `new()` call.
1620-
fn is_lit(sess: &Session, span: &Span) -> bool {
1621-
let source_map = sess.source_map();
1622-
let end_point = source_map.end_point(*span);
1619+
fn is_lit(sm: &SourceMap, span: &Span) -> bool {
1620+
let end_point = sm.end_point(*span);
16231621

1624-
if let Ok(end_string) = source_map.span_to_snippet(end_point) {
1622+
if let Ok(end_string) = sm.span_to_snippet(end_point) {
16251623
!(end_string.ends_with("}") || end_string.ends_with(")"))
16261624
} else {
16271625
false
@@ -1632,21 +1630,21 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
16321630
// All built-in range literals but `..=` and `..` desugar to `Struct`s.
16331631
ExprKind::Struct(ref qpath, _, _) => {
16341632
if let QPath::Resolved(None, ref path) = **qpath {
1635-
return is_range_path(&path) && is_lit(sess, &expr.span);
1633+
return is_range_path(&path) && is_lit(sm, &expr.span);
16361634
}
16371635
}
16381636

16391637
// `..` desugars to its struct path.
16401638
ExprKind::Path(QPath::Resolved(None, ref path)) => {
1641-
return is_range_path(&path) && is_lit(sess, &expr.span);
1639+
return is_range_path(&path) && is_lit(sm, &expr.span);
16421640
}
16431641

16441642
// `..=` desugars into `::std::ops::RangeInclusive::new(...)`.
16451643
ExprKind::Call(ref func, _) => {
16461644
if let ExprKind::Path(QPath::TypeRelative(ref ty, ref segment)) = func.kind {
16471645
if let TyKind::Path(QPath::Resolved(None, ref path)) = ty.kind {
16481646
let new_call = segment.ident.name == sym::new;
1649-
return is_range_path(&path) && is_lit(sess, &expr.span) && new_call;
1647+
return is_range_path(&path) && is_lit(sm, &expr.span) && new_call;
16501648
}
16511649
}
16521650
}

src/librustc_lint/types.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![allow(non_snake_case)]
22

3-
use rustc::hir::{ExprKind, Node};
4-
use crate::hir::def_id::DefId;
5-
use rustc::hir::lowering::is_range_literal;
3+
use rustc::hir::{ExprKind, Node, is_range_literal, def_id::DefId};
64
use rustc::ty::subst::SubstsRef;
75
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
86
use rustc::ty::layout::{self, IntegerExt, LayoutOf, VariantIdx, SizeSkeleton};
@@ -275,7 +273,7 @@ fn lint_int_literal<'a, 'tcx>(
275273
let par_id = cx.tcx.hir().get_parent_node(e.hir_id);
276274
if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) {
277275
if let hir::ExprKind::Struct(..) = par_e.kind {
278-
if is_range_literal(cx.sess(), par_e)
276+
if is_range_literal(cx.sess().source_map(), par_e)
279277
&& lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t.name_str())
280278
{
281279
// The overflowing literal lint was overridden.
@@ -328,7 +326,7 @@ fn lint_uint_literal<'a, 'tcx>(
328326
}
329327
}
330328
hir::ExprKind::Struct(..)
331-
if is_range_literal(cx.sess(), par_e) => {
329+
if is_range_literal(cx.sess().source_map(), par_e) => {
332330
let t = t.name_str();
333331
if lint_overflowing_range_endpoint(cx, lit, lit_val, max, e, par_e, t) {
334332
// The overflowing literal lint was overridden.

src/librustc_typeck/check/demand.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ use crate::check::FnCtxt;
22
use rustc::infer::InferOk;
33
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
44

5-
use syntax::symbol::sym;
65
use syntax::util::parser::PREC_POSTFIX;
6+
use syntax_pos::symbol::sym;
77
use syntax_pos::Span;
8-
use rustc::hir;
9-
use rustc::hir::Node;
10-
use rustc::hir::{print, lowering::is_range_literal};
8+
use rustc::hir::{self, Node, print, is_range_literal};
119
use rustc::ty::{self, Ty, AssocItem};
1210
use rustc::ty::adjustment::AllowTwoPhase;
1311
use errors::{Applicability, DiagnosticBuilder};
@@ -466,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
466464
hir::ExprKind::Cast(_, _) |
467465
hir::ExprKind::Binary(_, _, _) => true,
468466
// parenthesize borrows of range literals (Issue #54505)
469-
_ if is_range_literal(self.tcx.sess, expr) => true,
467+
_ if is_range_literal(self.tcx.sess.source_map(), expr) => true,
470468
_ => false,
471469
};
472470
let sugg_expr = if needs_parens {

0 commit comments

Comments
 (0)