about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-10-03 00:36:50 +0000
committerbors <bors@rust-lang.org>2015-10-03 00:36:50 +0000
commit98df45830a04498c9207c4251a16ef6c80629146 (patch)
treeb77e86d28652807496d6eb6424b029d446a9ec67
parentbfb26033af68949646081429040db606a044db22 (diff)
parent4fb789b86eb4d9f50c1ae6477126cd84025ff566 (diff)
downloadrust-98df45830a04498c9207c4251a16ef6c80629146.tar.gz
rust-98df45830a04498c9207c4251a16ef6c80629146.zip
Auto merge of #28672 - sanxiyn:const-eval-span, r=alexcrichton
Fix #28402.
-rw-r--r--src/librustc/middle/check_match.rs3
-rw-r--r--src/librustc_typeck/astconv.rs4
-rw-r--r--src/librustc_typeck/collect.rs9
-rw-r--r--src/libsyntax/codemap.rs6
-rw-r--r--src/test/compile-fail/const-eval-span.rs24
5 files changed, 37 insertions, 9 deletions
diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs
index 283c6264717..a8f20815a9a 100644
--- a/src/librustc/middle/check_match.rs
+++ b/src/librustc/middle/check_match.rs
@@ -281,11 +281,10 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
                 Ok(_) => {}
 
                 Err(err) => {
-                    let subspan = p.span.lo <= err.span.lo && err.span.hi <= p.span.hi;
                     span_err!(cx.tcx.sess, err.span, E0471,
                               "constant evaluation error: {}",
                               err.description());
-                    if !subspan {
+                    if !p.span.contains(err.span) {
                         cx.tcx.sess.span_note(p.span,
                                               "in pattern here")
                     }
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index dd15c132560..a05d9b19d23 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -1692,12 +1692,10 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
                     }
                 }
                 Err(ref r) => {
-                    let subspan  =
-                        ast_ty.span.lo <= r.span.lo && r.span.hi <= ast_ty.span.hi;
                     span_err!(tcx.sess, r.span, E0250,
                               "array length constant evaluation error: {}",
                               r.description());
-                    if !subspan {
+                    if !ast_ty.span.contains(r.span) {
                         span_note!(tcx.sess, ast_ty.span, "for array length here")
                     }
                     this.tcx().types.err
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 39805bfc8a3..7a70bc73b73 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -1173,9 +1173,12 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>,
                 None
             },
             Err(err) => {
-              span_err!(tcx.sess, err.span, E0080,
-                        "constant evaluation error: {}",
-                        err.description());
+                span_err!(tcx.sess, err.span, E0080,
+                          "constant evaluation error: {}",
+                          err.description());
+                if !e.span.contains(err.span) {
+                    tcx.sess.span_note(e.span, "for enum discriminant here");
+                }
                 None
             }
         }
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 1f8c726bf68..aa4dd1d53c5 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -142,6 +142,10 @@ impl Span {
     pub fn substitute_dummy(self, other: Span) -> Span {
         if self == DUMMY_SP { other } else { self }
     }
+
+    pub fn contains(self, other: Span) -> bool {
+        self.lo <= other.lo && other.hi <= self.hi
+    }
 }
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
@@ -1011,7 +1015,7 @@ impl CodeMap {
 
                     let span_comes_from_this_expansion =
                         info.callee.span.map_or(span == info.call_site, |mac_span| {
-                            mac_span.lo <= span.lo && span.hi <= mac_span.hi
+                            mac_span.contains(span)
                         });
 
                     debug!("span_allows_unstable: span: {:?} call_site: {:?} callee: {:?}",
diff --git a/src/test/compile-fail/const-eval-span.rs b/src/test/compile-fail/const-eval-span.rs
new file mode 100644
index 00000000000..8e9209916f3
--- /dev/null
+++ b/src/test/compile-fail/const-eval-span.rs
@@ -0,0 +1,24 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Check that error in constant evaluation of enum discriminant
+// provides the context for what caused the evaluation.
+
+struct S(i32);
+
+const CONSTANT: S = S(0);
+//~^ ERROR: constant evaluation error: unsupported constant expr
+
+enum E {
+    V = CONSTANT,
+    //~^ NOTE: for enum discriminant here
+}
+
+fn main() {}