Skip to content

Commit

Permalink
address some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Mar 27, 2020
1 parent 2972bb3 commit 2ddc359
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 95 deletions.
6 changes: 3 additions & 3 deletions src/librustc_ast_lowering/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 8 additions & 6 deletions src/librustc_parse/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-32214.rs
Original file line number Diff line number Diff line change
@@ -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() { }
9 changes: 4 additions & 5 deletions src/test/ui/parser/issue-32214.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/parser/recover-assoc-const-constraint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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
|
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

2 changes: 1 addition & 1 deletion src/test/ui/parser/recover-assoc-eq-missing-term.rs
Original file line number Diff line number Diff line change
@@ -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() {}
12 changes: 6 additions & 6 deletions src/test/ui/parser/recover-assoc-eq-missing-term.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/suggestions/suggest-move-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ 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,
v: 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,
Expand All @@ -55,15 +55,15 @@ 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,
v: 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,
Expand All @@ -72,15 +72,15 @@ 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,
v: 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,
Expand Down
88 changes: 32 additions & 56 deletions src/test/ui/suggestions/suggest-move-types.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2ddc359

Please sign in to comment.