Provide the context for error in constant evaluation of enum discriminant

This commit is contained in:
Seo Sanghyeon 2015-09-26 11:52:34 +09:00
parent f3211b1578
commit 4fb789b86e
2 changed files with 30 additions and 3 deletions

View file

@ -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
}
}

View file

@ -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() {}