Skip to content

A few diagnostics-related fixes #17785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/librustc/middle/typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,30 +670,30 @@ 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;
}
};

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);
Expand Down
11 changes: 8 additions & 3 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5004,9 +5004,14 @@ pub fn check_enum_variants(ccx: &CrateCtxt,
};

// Check for duplicate discriminant values
if disr_vals.contains(&current_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 {
Expand Down
37 changes: 25 additions & 12 deletions src/libsyntax/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-13482.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 16 additions & 0 deletions src/test/compile-fail/issue-14772.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions src/test/compile-fail/issue-15524.rs
Original file line number Diff line number Diff line change
@@ -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() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/match-vec-mismatch-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

fn main() {
match () {
[()] => { } //~ ERROR mismatched types: expected `()`, found a vector pattern
[()] => { } //~ ERROR mismatched types: expected `()`, found an array pattern
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/tag-variant-disr-dup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...

Expand Down