Point at every unexpected lifetime and type argument in E0107

This commit is contained in:
Esteban Küber 2018-11-08 17:51:13 -08:00
parent 910ec6d97f
commit abdcb868ff
5 changed files with 69 additions and 29 deletions

View file

@ -338,33 +338,31 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
(required, "")
};
let mut span = span;
let label = if required == permitted && provided > permitted {
let diff = provided - permitted;
if diff == 1 {
// In the case when the user has provided too many arguments,
// we want to point to the first unexpected argument.
let first_superfluous_arg: &GenericArg = &args.args[offset + permitted];
span = first_superfluous_arg.span();
}
format!(
"{}unexpected {} argument{}",
if diff != 1 { format!("{} ", diff) } else { String::new() },
kind,
if diff != 1 { "s" } else { "" },
let (spans, label) = if required == permitted && provided > permitted {
// In the case when the user has provided too many arguments,
// we want to point to the unexpected arguments.
(
args.args[offset+permitted .. offset+provided]
.iter()
.map(|arg| arg.span())
.collect(),
format!(
"unexpected {} argument",
kind,
),
)
} else {
format!(
(vec![span], format!(
"expected {}{} {} argument{}",
quantifier,
bound,
kind,
if bound != 1 { "s" } else { "" },
)
))
};
tcx.sess.struct_span_err_with_code(
span,
let mut err = tcx.sess.struct_span_err_with_code(
spans.clone(),
&format!(
"wrong number of {} arguments: expected {}{}, found {}",
kind,
@ -373,7 +371,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
provided,
),
DiagnosticId::Error("E0107".into())
).span_label(span, label).emit();
);
for span in spans {
err.span_label(span, label.as_str());
}
err.emit();
provided > required // `suppress_error`
};
@ -1030,13 +1032,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
for item_def_id in associated_types {
let assoc_item = tcx.associated_item(item_def_id);
let trait_def_id = assoc_item.container.id();
struct_span_err!(tcx.sess, span, E0191, "the value of the associated type `{}` \
(from the trait `{}`) must be specified",
assoc_item.ident,
tcx.item_path_str(trait_def_id))
.span_label(span, format!("missing associated type `{}` value",
assoc_item.ident))
.emit();
let mut err = struct_span_err!(
tcx.sess,
span,
E0191,
"the value of the associated type `{}` (from the trait `{}`) must be specified",
assoc_item.ident,
tcx.item_path_str(trait_def_id),
);
err.span_label(span, format!("missing associated type `{}` value", assoc_item.ident));
err.emit();
}
// Erase the `dummy_self` (`TRAIT_OBJECT_DUMMY_SELF`) used above.

View file

@ -0,0 +1,8 @@
pub trait T<X, Y> {
type A;
type B;
type C;
}
pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
fn main() {}

View file

@ -0,0 +1,24 @@
error[E0107]: wrong number of type arguments: expected 2, found 4
--> $DIR/E0107-b.rs:6:42
|
LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
| ^^^^^ ^^^^^ unexpected type argument
| |
| unexpected type argument
error[E0191]: the value of the associated type `A` (from the trait `T`) must be specified
--> $DIR/E0107-b.rs:6:26
|
LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing associated type `A` value
error[E0191]: the value of the associated type `C` (from the trait `T`) must be specified
--> $DIR/E0107-b.rs:6:26
|
LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing associated type `C` value
error: aborting due to 3 previous errors
Some errors occurred: E0107, E0191.
For more information about an error, try `rustc --explain E0107`.

View file

@ -26,7 +26,8 @@ struct Baz<'a, 'b, 'c> {
//~| unexpected lifetime argument
foo2: Foo<'a, 'b, 'c>,
//~^ ERROR E0107
//~| 2 unexpected lifetime arguments
//~| unexpected lifetime argument
//~| unexpected lifetime argument
}
fn main() {}

View file

@ -11,10 +11,12 @@ LL | bar: Bar<'a>,
| ^^ unexpected lifetime argument
error[E0107]: wrong number of lifetime arguments: expected 1, found 3
--> $DIR/E0107.rs:27:11
--> $DIR/E0107.rs:27:19
|
LL | foo2: Foo<'a, 'b, 'c>,
| ^^^^^^^^^^^^^^^ 2 unexpected lifetime arguments
| ^^ ^^ unexpected lifetime argument
| |
| unexpected lifetime argument
error: aborting due to 3 previous errors