Skip to content

Commit c586490

Browse files
committed
auto merge of #17785 : P1start/rust/diagnostics, r=alexcrichton
Closes #17765. Closes #15524. Closes #14772.
2 parents dfbe9eb + cc31d9c commit c586490

File tree

8 files changed

+81
-23
lines changed

8 files changed

+81
-23
lines changed

src/librustc/middle/typeck/check/_match.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,30 +670,30 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
670670
(ty, default_region_var, ast::MutImmutable, None)
671671
}
672672
_ => {
673-
check_err("a vector pattern".to_string());
673+
check_err("an array pattern".to_string());
674674
return;
675675
}
676676
},
677677
ty::ty_rptr(r, mt) => match ty::get(mt.ty).sty {
678678
ty::ty_vec(ty, None) => (ty, r, mt.mutbl, None),
679679
_ => {
680-
check_err("a vector pattern".to_string());
680+
check_err("an array pattern".to_string());
681681
return;
682682
}
683683
},
684684
_ => {
685-
check_err("a vector pattern".to_string());
685+
check_err("an array pattern".to_string());
686686
return;
687687
}
688688
};
689689

690690
let min_len = before.len() + after.len();
691691
fixed.and_then(|count| match *slice {
692692
Some(_) if count < min_len =>
693-
Some(format!("a fixed vector pattern of size at least {}", min_len)),
693+
Some(format!("a fixed array pattern of size at least {}", min_len)),
694694

695695
None if count != min_len =>
696-
Some(format!("a fixed vector pattern of size {}", min_len)),
696+
Some(format!("a fixed array pattern of size {}", min_len)),
697697

698698
_ => None
699699
}).map(check_err);

src/librustc/middle/typeck/check/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,9 +5004,14 @@ pub fn check_enum_variants(ccx: &CrateCtxt,
50045004
};
50055005

50065006
// Check for duplicate discriminant values
5007-
if disr_vals.contains(&current_disr_val) {
5008-
span_err!(ccx.tcx.sess, v.span, E0081,
5009-
"discriminant value already exists");
5007+
match disr_vals.iter().position(|&x| x == current_disr_val) {
5008+
Some(i) => {
5009+
span_err!(ccx.tcx.sess, v.span, E0081,
5010+
"discriminant value `{}` already exists", disr_vals[i]);
5011+
span_note!(ccx.tcx.sess, ccx.tcx().map.span(variants[i].id.node),
5012+
"conflicting discriminant here")
5013+
}
5014+
None => {}
50105015
}
50115016
// Check for unrepresentable discriminant values
50125017
match hint {

src/libsyntax/test.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,30 +274,43 @@ fn strip_test_functions(krate: ast::Crate) -> ast::Crate {
274274
fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
275275
let has_test_attr = attr::contains_name(i.attrs.as_slice(), "test");
276276

277-
fn has_test_signature(i: &ast::Item) -> bool {
277+
#[deriving(PartialEq)]
278+
enum HasTestSignature {
279+
Yes,
280+
No,
281+
NotEvenAFunction,
282+
}
283+
284+
fn has_test_signature(i: &ast::Item) -> HasTestSignature {
278285
match &i.node {
279286
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
280287
let no_output = match decl.output.node {
281288
ast::TyNil => true,
282-
_ => false
289+
_ => false,
283290
};
284-
decl.inputs.is_empty()
285-
&& no_output
286-
&& !generics.is_parameterized()
291+
if decl.inputs.is_empty()
292+
&& no_output
293+
&& !generics.is_parameterized() {
294+
Yes
295+
} else {
296+
No
297+
}
287298
}
288-
_ => false
299+
_ => NotEvenAFunction,
289300
}
290301
}
291302

292-
if has_test_attr && !has_test_signature(i) {
303+
if has_test_attr {
293304
let diag = cx.span_diagnostic;
294-
diag.span_err(
295-
i.span,
296-
"functions used as tests must have signature fn() -> ()."
297-
);
305+
match has_test_signature(i) {
306+
Yes => {},
307+
No => diag.span_err(i.span, "functions used as tests must have signature fn() -> ()"),
308+
NotEvenAFunction => diag.span_err(i.span,
309+
"only functions may be used as tests"),
310+
}
298311
}
299312

300-
return has_test_attr && has_test_signature(i);
313+
return has_test_attr && has_test_signature(i) == Yes;
301314
}
302315

303316
fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {

src/test/compile-fail/issue-13482.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let x = [1,2];
1313
let y = match x {
1414
[] => None,
15-
//~^ ERROR expected `[<generic integer #0>, ..2]`, found a fixed vector pattern of size 0
15+
//~^ ERROR expected `[<generic integer #0>, ..2]`, found a fixed array pattern of size 0
1616
[a,_] => Some(a)
1717
};
1818
}

src/test/compile-fail/issue-14772.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 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+
// compile-flags: --test
12+
13+
#[test]
14+
mod foo {} //~ ERROR only functions may be used as tests
15+
16+
fn main() {}

src/test/compile-fail/issue-15524.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 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+
static N: int = 1;
12+
13+
enum Foo {
14+
A = 1,
15+
B = 1, //~ ERROR discriminant value `1` already exists
16+
//~^^ NOTE conflicting
17+
C = 0,
18+
D, //~ ERROR discriminant value `1` already exists
19+
//~^^^^^ NOTE conflicting
20+
E = N, //~ ERROR discriminant value `1` already exists
21+
//~^^^^^^^ NOTE conflicting
22+
}
23+
24+
fn main() {}

src/test/compile-fail/match-vec-mismatch-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
fn main() {
1212
match () {
13-
[()] => { } //~ ERROR mismatched types: expected `()`, found a vector pattern
13+
[()] => { } //~ ERROR mismatched types: expected `()`, found an array pattern
1414
}
1515
}

src/test/compile-fail/tag-variant-disr-dup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//error-pattern:discriminant value already exists
11+
//error-pattern:discriminant value
1212

1313
// black and white have the same discriminator value ...
1414

0 commit comments

Comments
 (0)