auto merge of #17785 : P1start/rust/diagnostics, r=alexcrichton
Closes #17765. Closes #15524. Closes #14772.
This commit is contained in:
commit
c586490715
8 changed files with 81 additions and 23 deletions
|
@ -670,19 +670,19 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|
|||
(ty, default_region_var, ast::MutImmutable, None)
|
||||
}
|
||||
_ => {
|
||||
check_err("a vector pattern".to_string());
|
||||
check_err("an array pattern".to_string());
|
||||
return;
|
||||
}
|
||||
},
|
||||
ty::ty_rptr(r, mt) => match ty::get(mt.ty).sty {
|
||||
ty::ty_vec(ty, None) => (ty, r, mt.mutbl, None),
|
||||
_ => {
|
||||
check_err("a vector pattern".to_string());
|
||||
check_err("an array pattern".to_string());
|
||||
return;
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
check_err("a vector pattern".to_string());
|
||||
check_err("an array pattern".to_string());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -690,10 +690,10 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|
|||
let min_len = before.len() + after.len();
|
||||
fixed.and_then(|count| match *slice {
|
||||
Some(_) if count < min_len =>
|
||||
Some(format!("a fixed vector pattern of size at least {}", min_len)),
|
||||
Some(format!("a fixed array pattern of size at least {}", min_len)),
|
||||
|
||||
None if count != min_len =>
|
||||
Some(format!("a fixed vector pattern of size {}", min_len)),
|
||||
Some(format!("a fixed array pattern of size {}", min_len)),
|
||||
|
||||
_ => None
|
||||
}).map(check_err);
|
||||
|
|
|
@ -5004,9 +5004,14 @@ pub fn check_enum_variants(ccx: &CrateCtxt,
|
|||
};
|
||||
|
||||
// Check for duplicate discriminant values
|
||||
if disr_vals.contains(¤t_disr_val) {
|
||||
span_err!(ccx.tcx.sess, v.span, E0081,
|
||||
"discriminant value already exists");
|
||||
match disr_vals.iter().position(|&x| x == current_disr_val) {
|
||||
Some(i) => {
|
||||
span_err!(ccx.tcx.sess, v.span, E0081,
|
||||
"discriminant value `{}` already exists", disr_vals[i]);
|
||||
span_note!(ccx.tcx.sess, ccx.tcx().map.span(variants[i].id.node),
|
||||
"conflicting discriminant here")
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
// Check for unrepresentable discriminant values
|
||||
match hint {
|
||||
|
|
|
@ -274,30 +274,43 @@ fn strip_test_functions(krate: ast::Crate) -> ast::Crate {
|
|||
fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
|
||||
let has_test_attr = attr::contains_name(i.attrs.as_slice(), "test");
|
||||
|
||||
fn has_test_signature(i: &ast::Item) -> bool {
|
||||
#[deriving(PartialEq)]
|
||||
enum HasTestSignature {
|
||||
Yes,
|
||||
No,
|
||||
NotEvenAFunction,
|
||||
}
|
||||
|
||||
fn has_test_signature(i: &ast::Item) -> HasTestSignature {
|
||||
match &i.node {
|
||||
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
|
||||
let no_output = match decl.output.node {
|
||||
ast::TyNil => true,
|
||||
_ => false
|
||||
_ => false,
|
||||
};
|
||||
decl.inputs.is_empty()
|
||||
&& no_output
|
||||
&& !generics.is_parameterized()
|
||||
if decl.inputs.is_empty()
|
||||
&& no_output
|
||||
&& !generics.is_parameterized() {
|
||||
Yes
|
||||
} else {
|
||||
No
|
||||
}
|
||||
}
|
||||
_ => false
|
||||
_ => NotEvenAFunction,
|
||||
}
|
||||
}
|
||||
|
||||
if has_test_attr && !has_test_signature(i) {
|
||||
if has_test_attr {
|
||||
let diag = cx.span_diagnostic;
|
||||
diag.span_err(
|
||||
i.span,
|
||||
"functions used as tests must have signature fn() -> ()."
|
||||
);
|
||||
match has_test_signature(i) {
|
||||
Yes => {},
|
||||
No => diag.span_err(i.span, "functions used as tests must have signature fn() -> ()"),
|
||||
NotEvenAFunction => diag.span_err(i.span,
|
||||
"only functions may be used as tests"),
|
||||
}
|
||||
}
|
||||
|
||||
return has_test_attr && has_test_signature(i);
|
||||
return has_test_attr && has_test_signature(i) == Yes;
|
||||
}
|
||||
|
||||
fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
|
||||
|
|
|
@ -12,7 +12,7 @@ fn main() {
|
|||
let x = [1,2];
|
||||
let y = match x {
|
||||
[] => None,
|
||||
//~^ ERROR expected `[<generic integer #0>, ..2]`, found a fixed vector pattern of size 0
|
||||
//~^ ERROR expected `[<generic integer #0>, ..2]`, found a fixed array pattern of size 0
|
||||
[a,_] => Some(a)
|
||||
};
|
||||
}
|
||||
|
|
16
src/test/compile-fail/issue-14772.rs
Normal file
16
src/test/compile-fail/issue-14772.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
// compile-flags: --test
|
||||
|
||||
#[test]
|
||||
mod foo {} //~ ERROR only functions may be used as tests
|
||||
|
||||
fn main() {}
|
24
src/test/compile-fail/issue-15524.rs
Normal file
24
src/test/compile-fail/issue-15524.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
static N: int = 1;
|
||||
|
||||
enum Foo {
|
||||
A = 1,
|
||||
B = 1, //~ ERROR discriminant value `1` already exists
|
||||
//~^^ NOTE conflicting
|
||||
C = 0,
|
||||
D, //~ ERROR discriminant value `1` already exists
|
||||
//~^^^^^ NOTE conflicting
|
||||
E = N, //~ ERROR discriminant value `1` already exists
|
||||
//~^^^^^^^ NOTE conflicting
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -10,6 +10,6 @@
|
|||
|
||||
fn main() {
|
||||
match () {
|
||||
[()] => { } //~ ERROR mismatched types: expected `()`, found a vector pattern
|
||||
[()] => { } //~ ERROR mismatched types: expected `()`, found an array pattern
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//error-pattern:discriminant value already exists
|
||||
//error-pattern:discriminant value
|
||||
|
||||
// black and white have the same discriminator value ...
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue