address some review comments

This commit is contained in:
Mazdak Farrokhzad 2020-03-27 07:39:10 +01:00
parent 2972bb37b8
commit 2ddc35997c
10 changed files with 68 additions and 95 deletions

View file

@ -367,9 +367,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
mut itctx: ImplTraitContext<'_, 'hir>,
) -> (GenericArgsCtor<'hir>, bool) {
let has_non_lt_args = data.args.iter().any(|arg| match arg {
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_)) => false,
AngleBracketedArg::Arg(ast::GenericArg::Type(_) | ast::GenericArg::Const(_))
| AngleBracketedArg::Constraint(_) => true,
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
| AngleBracketedArg::Constraint(_) => false,
AngleBracketedArg::Arg(ast::GenericArg::Type(_) | ast::GenericArg::Const(_)) => true,
});
let args = data
.args

View file

@ -660,12 +660,8 @@ impl<'a> AstValidator<'a> {
// ...and then error:
self.err_handler()
.struct_span_err(
data.span,
"constraints in a path segment must come after generic arguments",
)
.span_labels(
misplaced_args,
"this generic argument must come before the first constraint",
"generic arguments must come before the first constraint",
)
.span_label(first.unwrap(), "the first constraint is provided here")
.emit();

View file

@ -439,8 +439,8 @@ impl<'a> Parser<'a> {
Some(GenericArg::Type(ty)) => return Ok(ty),
Some(GenericArg::Const(expr)) => {
self.struct_span_err(span, "cannot constrain an associated constant to a value")
.span_label(ident.span, "the value constrains this associated constant")
.span_label(expr.value.span, "the value is given in this expression")
.span_label(ident.span, "this associated constant...")
.span_label(expr.value.span, "...cannot be constrained to this value")
.emit();
}
Some(GenericArg::Lifetime(lt)) => {
@ -450,15 +450,17 @@ impl<'a> Parser<'a> {
.emit();
}
None => {
self.struct_span_err(span, "missing type to the right of `=`")
let after_eq = eq.shrink_to_hi();
let before_next = self.token.span.shrink_to_lo();
self.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`")
.span_suggestion(
span,
self.sess.source_map().next_point(eq).to(before_next),
"to constrain the associated type, add a type after `=`",
format!("{} = TheType", ident),
" TheType".to_string(),
Applicability::HasPlaceholders,
)
.span_suggestion(
eq,
eq.to(before_next),
&format!("remove the `=` if `{}` is a type", ident),
String::new(),
Applicability::MaybeIncorrect,

View file

@ -1,6 +1,6 @@
trait Trait<T> { type Item; }
pub fn test<W, I: Trait<Item=(), W> >() {}
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
fn main() { }

View file

@ -1,10 +1,9 @@
error: constraints in a path segment must come after generic arguments
--> $DIR/issue-32214.rs:3:24
error: generic arguments must come before the first constraint
--> $DIR/issue-32214.rs:3:34
|
LL | pub fn test<W, I: Trait<Item=(), W> >() {}
| ^-------^^-^
| | |
| | this generic argument must come before the first constraint
| ------- ^
| |
| the first constraint is provided here
error: aborting due to previous error

View file

@ -4,8 +4,8 @@ error: cannot constrain an associated constant to a value
LL | bar::<Item = 42>();
| ----^^^--
| | |
| | the value is given in this expression
| the value constrains this associated constant
| | ...cannot be constrained to this value
| this associated constant...
error: cannot constrain an associated constant to a value
--> $DIR/recover-assoc-const-constraint.rs:4:11
@ -13,8 +13,8 @@ error: cannot constrain an associated constant to a value
LL | bar::<Item = { 42 }>();
| ----^^^------
| | |
| | the value is given in this expression
| the value constrains this associated constant
| | ...cannot be constrained to this value
| this associated constant...
error: aborting due to 2 previous errors

View file

@ -1,6 +1,6 @@
#[cfg(FALSE)]
fn syntax() {
bar::<Item = >(); //~ ERROR missing type to the right of `=`
bar::<Item = >(); //~ ERROR missing type to the right of `=`
}
fn main() {}

View file

@ -1,16 +1,16 @@
error: missing type to the right of `=`
--> $DIR/recover-assoc-eq-missing-term.rs:3:11
--> $DIR/recover-assoc-eq-missing-term.rs:3:17
|
LL | bar::<Item = >();
| ^^^^^^
LL | bar::<Item = >();
| ^^^
|
help: to constrain the associated type, add a type after `=`
|
LL | bar::<Item = TheType >();
| ^^^^^^^^^^^^^^
LL | bar::<Item = TheType>();
| ^^^^^^^
help: remove the `=` if `Item` is a type
|
LL | bar::<Item >();
LL | bar::<Item >();
| --
error: aborting due to previous error

View file

@ -24,21 +24,21 @@ trait ThreeWithLifetime<'a, 'b, 'c, T, U, V> {
}
struct A<T, M: One<A=(), T>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
m: M,
t: T,
}
struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
//~^^ ERROR type provided when a lifetime was expected
m: M,
t: &'a T,
}
struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
m: M,
t: T,
u: U,
@ -46,7 +46,7 @@ struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
}
struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
//~^^ ERROR type provided when a lifetime was expected
m: M,
t: &'a T,
@ -55,7 +55,7 @@ struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, '
}
struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
m: M,
t: T,
u: U,
@ -63,7 +63,7 @@ struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
}
struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
//~^^ ERROR lifetime provided when a type was expected
m: M,
t: &'a T,
@ -72,7 +72,7 @@ struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U,
}
struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
m: M,
t: T,
u: U,
@ -80,7 +80,7 @@ struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
}
struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
//~^ ERROR constraints in a path segment must come after generic arguments
//~^ ERROR generic arguments must come before the first constraint
//~^^ ERROR lifetime provided when a type was expected
m: M,
t: &'a T,

View file

@ -1,89 +1,65 @@
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:26:19
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:26:26
|
LL | struct A<T, M: One<A=(), T>> {
| ^----^^-^
| | |
| | this generic argument must come before the first constraint
| ---- ^
| |
| the first constraint is provided here
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:33:36
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:33:43
|
LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
| ^----^^-^^--^
| | | |
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| ---- ^ ^^
| |
| the first constraint is provided here
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:40:27
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:40:46
|
LL | struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
| ^----^^^^^^^^^^^^^^-^^-^^-^
| | | | |
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| ---- ^ ^ ^
| |
| the first constraint is provided here
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:48:52
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:48:71
|
LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
| ^----^^^^^^^^^^^^^^-^^-^^-^^--^^--^^--^
| | | | | | | |
| | | | | | | this generic argument must come before the first constraint
| | | | | | this generic argument must come before the first constraint
| | | | | this generic argument must come before the first constraint
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| ---- ^ ^ ^ ^^ ^^ ^^
| |
| the first constraint is provided here
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:57:27
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:57:49
|
LL | struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
| ^^^^----^^^^^^^^^^^^^^-^^-^
| | | |
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| ---- ^ ^
| |
| the first constraint is provided here
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:65:52
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:65:78
|
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
| ^^^^^^^^----^^^^^^^^^^^^^^-^^--^^-^^--^
| | | | | |
| | | | | this generic argument must come before the first constraint
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| ---- ^ ^^ ^ ^^
| |
| the first constraint is provided here
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:74:27
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:74:43
|
LL | struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
| ^^^^----^^^^^^^^-^^^^^^^^-^
| | | |
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| ---- ^ ^
| |
| the first constraint is provided here
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:82:52
error: generic arguments must come before the first constraint
--> $DIR/suggest-move-types.rs:82:72
|
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
| ^^^^^^^^----^^^^^^^^-^^--^^^^^^^^-^^--^
| | | | | |
| | | | | this generic argument must come before the first constraint
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| ---- ^ ^^ ^ ^^
| |
| the first constraint is provided here
error[E0747]: type provided when a lifetime was expected