From 4fb789b86eb4d9f50c1ae6477126cd84025ff566 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Sat, 26 Sep 2015 11:52:34 +0900 Subject: [PATCH] Provide the context for error in constant evaluation of enum discriminant --- src/librustc_typeck/collect.rs | 9 ++++++--- src/test/compile-fail/const-eval-span.rs | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/const-eval-span.rs diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 39805bfc8a3e2..7a70bc73b7338 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/test/compile-fail/const-eval-span.rs b/src/test/compile-fail/const-eval-span.rs new file mode 100644 index 0000000000000..8e9209916f35b --- /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 or the MIT license +// , 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() {}