Skip to content

Commit

Permalink
Update E0107 message to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
ojsheikh committed Aug 5, 2016
1 parent 4c02363 commit 3575812
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -2266,9 +2266,25 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
}

fn report_lifetime_number_error(tcx: TyCtxt, span: Span, number: usize, expected: usize) {
span_err!(tcx.sess, span, E0107,
"wrong number of lifetime parameters: expected {}, found {}",
expected, number);
let label = if number < expected {
if expected == 1 {
format!("expected {} lifetime parameter", expected)
} else {
format!("expected {} lifetime parameters", expected)
}
} else {
let additional = number - expected;
if additional == 1 {
"unexpected lifetime parameter".to_string()
} else {
format!("{} unexpected lifetime parameters", additional)
}
};
struct_span_err!(tcx.sess, span, E0107,
"wrong number of lifetime parameters: expected {}, found {}",
expected, number)
.span_label(span, &label)
.emit();
}

// A helper struct for conveniently grouping a set of bounds which we pass to
Expand Down
8 changes: 6 additions & 2 deletions src/test/compile-fail/E0107.rs
Expand Up @@ -17,8 +17,12 @@ enum Bar {
}

struct Baz<'a> {
foo: Foo, //~ ERROR E0107
bar: Bar<'a>, //~ ERROR E0107
foo: Foo,
//~^ ERROR E0107
//~| expected 1 lifetime parameter
bar: Bar<'a>,
//~^ ERROR E0107
//~| unexpected lifetime parameter
}

fn main() {
Expand Down

0 comments on commit 3575812

Please sign in to comment.