Skip to content

Commit

Permalink
Rollup merge of rust-lang#35373 - oijazsh:E0107, r=jonathandturner
Browse files Browse the repository at this point in the history
Update E0107 message to new format

Fixes rust-lang#35246 as part of rust-lang#35233.

r? @jonathandturner
  • Loading branch information
Jonathan Turner authored Aug 5, 2016
2 parents 8d881d6 + 2061d65 commit 7f5d263
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2273,9 +2273,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
17 changes: 14 additions & 3 deletions src/test/compile-fail/E0107.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@
// except according to those terms.

struct Foo<'a>(&'a str);
struct Buzz<'a, 'b>(&'a str, &'b str);

enum Bar {
A,
B,
C,
}

struct Baz<'a> {
foo: Foo, //~ ERROR E0107
bar: Bar<'a>, //~ ERROR E0107
struct Baz<'a, 'b, 'c> {
foo: Foo,
//~^ ERROR E0107
//~| expected 1 lifetime parameter
buzz: Buzz<'a>,
//~^ ERROR E0107
//~| expected 2 lifetime parameters
bar: Bar<'a>,
//~^ ERROR E0107
//~| unexpected lifetime parameter
foo2: Foo<'a, 'b, 'c>,
//~^ ERROR E0107
//~| 2 unexpected lifetime parameters
}

fn main() {
Expand Down

0 comments on commit 7f5d263

Please sign in to comment.