Skip to content

Commit f3211b1

Browse files
committed
Add a method to test span containment
1 parent 5180a7c commit f3211b1

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,10 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
281281
Ok(_) => {}
282282

283283
Err(err) => {
284-
let subspan = p.span.lo <= err.span.lo && err.span.hi <= p.span.hi;
285284
span_err!(cx.tcx.sess, err.span, E0471,
286285
"constant evaluation error: {}",
287286
err.description());
288-
if !subspan {
287+
if !p.span.contains(err.span) {
289288
cx.tcx.sess.span_note(p.span,
290289
"in pattern here")
291290
}

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,12 +1692,10 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
16921692
}
16931693
}
16941694
Err(ref r) => {
1695-
let subspan =
1696-
ast_ty.span.lo <= r.span.lo && r.span.hi <= ast_ty.span.hi;
16971695
span_err!(tcx.sess, r.span, E0250,
16981696
"array length constant evaluation error: {}",
16991697
r.description());
1700-
if !subspan {
1698+
if !ast_ty.span.contains(r.span) {
17011699
span_note!(tcx.sess, ast_ty.span, "for array length here")
17021700
}
17031701
this.tcx().types.err

src/libsyntax/codemap.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ impl Span {
142142
pub fn substitute_dummy(self, other: Span) -> Span {
143143
if self == DUMMY_SP { other } else { self }
144144
}
145+
146+
pub fn contains(self, other: Span) -> bool {
147+
self.lo <= other.lo && other.hi <= self.hi
148+
}
145149
}
146150

147151
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
@@ -1011,7 +1015,7 @@ impl CodeMap {
10111015

10121016
let span_comes_from_this_expansion =
10131017
info.callee.span.map_or(span == info.call_site, |mac_span| {
1014-
mac_span.lo <= span.lo && span.hi <= mac_span.hi
1018+
mac_span.contains(span)
10151019
});
10161020

10171021
debug!("span_allows_unstable: span: {:?} call_site: {:?} callee: {:?}",

0 commit comments

Comments
 (0)