Skip to content

Commit b85b3c9

Browse files
committed
Fix span typo in the arithmetic overflow for array length reporting.
Added pair of regression tests that I should have made when I thought of doing this in the first place.
1 parent 8491c82 commit b85b3c9

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
13991399
Err(ref r) => {
14001400
let subspan =
14011401
ast_ty.span.lo <= r.span.lo && r.span.hi <= ast_ty.span.hi;
1402-
span_err!(tcx.sess, ast_ty.span, E0250,
1402+
span_err!(tcx.sess, r.span, E0250,
14031403
"array length constant evaluation error: {}",
14041404
r.description().as_slice());
14051405
if !subspan {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2012-2013 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 an constant-evaluation underflow highlights the correct
12+
// spot (where the underflow occurred), while also providing the
13+
// overall context for what caused the evaluation.
14+
15+
const ONE: usize = 1;
16+
const TWO: usize = 2;
17+
const LEN: usize = ONE - TWO;
18+
//~^ ERROR array length constant evaluation error: attempted to sub with overflow [E0250]
19+
20+
fn main() {
21+
let a: [i8; LEN] = unimplemented!();
22+
//~^ NOTE for array length here
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2012-2013 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 an constant-evaluation underflow highlights the correct
12+
// spot (where the underflow occurred).
13+
14+
const ONE: usize = 1;
15+
const TWO: usize = 2;
16+
17+
fn main() {
18+
let a: [i8; ONE - TWO] = unimplemented!();
19+
//~^ ERROR array length constant evaluation error: attempted to sub with overflow [E0250]
20+
}

0 commit comments

Comments
 (0)