Skip to content

Commit 4fb789b

Browse files
committed
Provide the context for error in constant evaluation of enum discriminant
1 parent f3211b1 commit 4fb789b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/librustc_typeck/collect.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,9 +1173,12 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>,
11731173
None
11741174
},
11751175
Err(err) => {
1176-
span_err!(tcx.sess, err.span, E0080,
1177-
"constant evaluation error: {}",
1178-
err.description());
1176+
span_err!(tcx.sess, err.span, E0080,
1177+
"constant evaluation error: {}",
1178+
err.description());
1179+
if !e.span.contains(err.span) {
1180+
tcx.sess.span_note(e.span, "for enum discriminant here");
1181+
}
11791182
None
11801183
}
11811184
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that error in constant evaluation of enum discriminant
12+
// provides the context for what caused the evaluation.
13+
14+
struct S(i32);
15+
16+
const CONSTANT: S = S(0);
17+
//~^ ERROR: constant evaluation error: unsupported constant expr
18+
19+
enum E {
20+
V = CONSTANT,
21+
//~^ NOTE: for enum discriminant here
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)