Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Provide the context for error in constant evaluation of enum discrimi…
…nant
  • Loading branch information
sanxiyn committed Oct 2, 2015
1 parent f3211b1 commit 4fb789b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/librustc_typeck/collect.rs
Expand Up @@ -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
}
}
Expand Down
24 changes: 24 additions & 0 deletions 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() {}

0 comments on commit 4fb789b

Please sign in to comment.