Skip to content

Update E0107 message to new format #35373

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

Merged
merged 2 commits into from
Aug 6, 2016
Merged
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
22 changes: 19 additions & 3 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
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
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