Skip to content

Commit 2ddc359

Browse files
committed
address some review comments
1 parent 2972bb3 commit 2ddc359

File tree

10 files changed

+68
-95
lines changed

10 files changed

+68
-95
lines changed

src/librustc_ast_lowering/path.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
367367
mut itctx: ImplTraitContext<'_, 'hir>,
368368
) -> (GenericArgsCtor<'hir>, bool) {
369369
let has_non_lt_args = data.args.iter().any(|arg| match arg {
370-
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_)) => false,
371-
AngleBracketedArg::Arg(ast::GenericArg::Type(_) | ast::GenericArg::Const(_))
372-
| AngleBracketedArg::Constraint(_) => true,
370+
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
371+
| AngleBracketedArg::Constraint(_) => false,
372+
AngleBracketedArg::Arg(ast::GenericArg::Type(_) | ast::GenericArg::Const(_)) => true,
373373
});
374374
let args = data
375375
.args

src/librustc_ast_passes/ast_validation.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,8 @@ impl<'a> AstValidator<'a> {
660660
// ...and then error:
661661
self.err_handler()
662662
.struct_span_err(
663-
data.span,
664-
"constraints in a path segment must come after generic arguments",
665-
)
666-
.span_labels(
667663
misplaced_args,
668-
"this generic argument must come before the first constraint",
664+
"generic arguments must come before the first constraint",
669665
)
670666
.span_label(first.unwrap(), "the first constraint is provided here")
671667
.emit();

src/librustc_parse/parser/path.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ impl<'a> Parser<'a> {
439439
Some(GenericArg::Type(ty)) => return Ok(ty),
440440
Some(GenericArg::Const(expr)) => {
441441
self.struct_span_err(span, "cannot constrain an associated constant to a value")
442-
.span_label(ident.span, "the value constrains this associated constant")
443-
.span_label(expr.value.span, "the value is given in this expression")
442+
.span_label(ident.span, "this associated constant...")
443+
.span_label(expr.value.span, "...cannot be constrained to this value")
444444
.emit();
445445
}
446446
Some(GenericArg::Lifetime(lt)) => {
@@ -450,15 +450,17 @@ impl<'a> Parser<'a> {
450450
.emit();
451451
}
452452
None => {
453-
self.struct_span_err(span, "missing type to the right of `=`")
453+
let after_eq = eq.shrink_to_hi();
454+
let before_next = self.token.span.shrink_to_lo();
455+
self.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`")
454456
.span_suggestion(
455-
span,
457+
self.sess.source_map().next_point(eq).to(before_next),
456458
"to constrain the associated type, add a type after `=`",
457-
format!("{} = TheType", ident),
459+
" TheType".to_string(),
458460
Applicability::HasPlaceholders,
459461
)
460462
.span_suggestion(
461-
eq,
463+
eq.to(before_next),
462464
&format!("remove the `=` if `{}` is a type", ident),
463465
String::new(),
464466
Applicability::MaybeIncorrect,

src/test/ui/parser/issue-32214.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
trait Trait<T> { type Item; }
22

33
pub fn test<W, I: Trait<Item=(), W> >() {}
4-
//~^ ERROR constraints in a path segment must come after generic arguments
4+
//~^ ERROR generic arguments must come before the first constraint
55

66
fn main() { }

src/test/ui/parser/issue-32214.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
error: constraints in a path segment must come after generic arguments
2-
--> $DIR/issue-32214.rs:3:24
1+
error: generic arguments must come before the first constraint
2+
--> $DIR/issue-32214.rs:3:34
33
|
44
LL | pub fn test<W, I: Trait<Item=(), W> >() {}
5-
| ^-------^^-^
6-
| | |
7-
| | this generic argument must come before the first constraint
5+
| ------- ^
6+
| |
87
| the first constraint is provided here
98

109
error: aborting due to previous error

src/test/ui/parser/recover-assoc-const-constraint.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ error: cannot constrain an associated constant to a value
44
LL | bar::<Item = 42>();
55
| ----^^^--
66
| | |
7-
| | the value is given in this expression
8-
| the value constrains this associated constant
7+
| | ...cannot be constrained to this value
8+
| this associated constant...
99

1010
error: cannot constrain an associated constant to a value
1111
--> $DIR/recover-assoc-const-constraint.rs:4:11
1212
|
1313
LL | bar::<Item = { 42 }>();
1414
| ----^^^------
1515
| | |
16-
| | the value is given in this expression
17-
| the value constrains this associated constant
16+
| | ...cannot be constrained to this value
17+
| this associated constant...
1818

1919
error: aborting due to 2 previous errors
2020

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(FALSE)]
22
fn syntax() {
3-
bar::<Item = >(); //~ ERROR missing type to the right of `=`
3+
bar::<Item = >(); //~ ERROR missing type to the right of `=`
44
}
55

66
fn main() {}

src/test/ui/parser/recover-assoc-eq-missing-term.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error: missing type to the right of `=`
2-
--> $DIR/recover-assoc-eq-missing-term.rs:3:11
2+
--> $DIR/recover-assoc-eq-missing-term.rs:3:17
33
|
4-
LL | bar::<Item = >();
5-
| ^^^^^^
4+
LL | bar::<Item = >();
5+
| ^^^
66
|
77
help: to constrain the associated type, add a type after `=`
88
|
9-
LL | bar::<Item = TheType >();
10-
| ^^^^^^^^^^^^^^
9+
LL | bar::<Item = TheType>();
10+
| ^^^^^^^
1111
help: remove the `=` if `Item` is a type
1212
|
13-
LL | bar::<Item >();
13+
LL | bar::<Item >();
1414
| --
1515

1616
error: aborting due to previous error

src/test/ui/suggestions/suggest-move-types.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ trait ThreeWithLifetime<'a, 'b, 'c, T, U, V> {
2424
}
2525

2626
struct A<T, M: One<A=(), T>> {
27-
//~^ ERROR constraints in a path segment must come after generic arguments
27+
//~^ ERROR generic arguments must come before the first constraint
2828
m: M,
2929
t: T,
3030
}
3131

3232

3333
struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
34-
//~^ ERROR constraints in a path segment must come after generic arguments
34+
//~^ ERROR generic arguments must come before the first constraint
3535
//~^^ ERROR type provided when a lifetime was expected
3636
m: M,
3737
t: &'a T,
3838
}
3939

4040
struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
41-
//~^ ERROR constraints in a path segment must come after generic arguments
41+
//~^ ERROR generic arguments must come before the first constraint
4242
m: M,
4343
t: T,
4444
u: U,
4545
v: V,
4646
}
4747

4848
struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
49-
//~^ ERROR constraints in a path segment must come after generic arguments
49+
//~^ ERROR generic arguments must come before the first constraint
5050
//~^^ ERROR type provided when a lifetime was expected
5151
m: M,
5252
t: &'a T,
@@ -55,15 +55,15 @@ struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, '
5555
}
5656

5757
struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
58-
//~^ ERROR constraints in a path segment must come after generic arguments
58+
//~^ ERROR generic arguments must come before the first constraint
5959
m: M,
6060
t: T,
6161
u: U,
6262
v: V,
6363
}
6464

6565
struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
66-
//~^ ERROR constraints in a path segment must come after generic arguments
66+
//~^ ERROR generic arguments must come before the first constraint
6767
//~^^ ERROR lifetime provided when a type was expected
6868
m: M,
6969
t: &'a T,
@@ -72,15 +72,15 @@ struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U,
7272
}
7373

7474
struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
75-
//~^ ERROR constraints in a path segment must come after generic arguments
75+
//~^ ERROR generic arguments must come before the first constraint
7676
m: M,
7777
t: T,
7878
u: U,
7979
v: V,
8080
}
8181

8282
struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
83-
//~^ ERROR constraints in a path segment must come after generic arguments
83+
//~^ ERROR generic arguments must come before the first constraint
8484
//~^^ ERROR lifetime provided when a type was expected
8585
m: M,
8686
t: &'a T,

src/test/ui/suggestions/suggest-move-types.stderr

+32-56
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,65 @@
1-
error: constraints in a path segment must come after generic arguments
2-
--> $DIR/suggest-move-types.rs:26:19
1+
error: generic arguments must come before the first constraint
2+
--> $DIR/suggest-move-types.rs:26:26
33
|
44
LL | struct A<T, M: One<A=(), T>> {
5-
| ^----^^-^
6-
| | |
7-
| | this generic argument must come before the first constraint
5+
| ---- ^
6+
| |
87
| the first constraint is provided here
98

10-
error: constraints in a path segment must come after generic arguments
11-
--> $DIR/suggest-move-types.rs:33:36
9+
error: generic arguments must come before the first constraint
10+
--> $DIR/suggest-move-types.rs:33:43
1211
|
1312
LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
14-
| ^----^^-^^--^
15-
| | | |
16-
| | | this generic argument must come before the first constraint
17-
| | this generic argument must come before the first constraint
13+
| ---- ^ ^^
14+
| |
1815
| the first constraint is provided here
1916

20-
error: constraints in a path segment must come after generic arguments
21-
--> $DIR/suggest-move-types.rs:40:27
17+
error: generic arguments must come before the first constraint
18+
--> $DIR/suggest-move-types.rs:40:46
2219
|
2320
LL | struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
24-
| ^----^^^^^^^^^^^^^^-^^-^^-^
25-
| | | | |
26-
| | | | this generic argument must come before the first constraint
27-
| | | this generic argument must come before the first constraint
28-
| | this generic argument must come before the first constraint
21+
| ---- ^ ^ ^
22+
| |
2923
| the first constraint is provided here
3024

31-
error: constraints in a path segment must come after generic arguments
32-
--> $DIR/suggest-move-types.rs:48:52
25+
error: generic arguments must come before the first constraint
26+
--> $DIR/suggest-move-types.rs:48:71
3327
|
3428
LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
35-
| ^----^^^^^^^^^^^^^^-^^-^^-^^--^^--^^--^
36-
| | | | | | | |
37-
| | | | | | | this generic argument must come before the first constraint
38-
| | | | | | this generic argument must come before the first constraint
39-
| | | | | this generic argument must come before the first constraint
40-
| | | | this generic argument must come before the first constraint
41-
| | | this generic argument must come before the first constraint
42-
| | this generic argument must come before the first constraint
29+
| ---- ^ ^ ^ ^^ ^^ ^^
30+
| |
4331
| the first constraint is provided here
4432

45-
error: constraints in a path segment must come after generic arguments
46-
--> $DIR/suggest-move-types.rs:57:27
33+
error: generic arguments must come before the first constraint
34+
--> $DIR/suggest-move-types.rs:57:49
4735
|
4836
LL | struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
49-
| ^^^^----^^^^^^^^^^^^^^-^^-^
50-
| | | |
51-
| | | this generic argument must come before the first constraint
52-
| | this generic argument must come before the first constraint
37+
| ---- ^ ^
38+
| |
5339
| the first constraint is provided here
5440

55-
error: constraints in a path segment must come after generic arguments
56-
--> $DIR/suggest-move-types.rs:65:52
41+
error: generic arguments must come before the first constraint
42+
--> $DIR/suggest-move-types.rs:65:78
5743
|
5844
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
59-
| ^^^^^^^^----^^^^^^^^^^^^^^-^^--^^-^^--^
60-
| | | | | |
61-
| | | | | this generic argument must come before the first constraint
62-
| | | | this generic argument must come before the first constraint
63-
| | | this generic argument must come before the first constraint
64-
| | this generic argument must come before the first constraint
45+
| ---- ^ ^^ ^ ^^
46+
| |
6547
| the first constraint is provided here
6648

67-
error: constraints in a path segment must come after generic arguments
68-
--> $DIR/suggest-move-types.rs:74:27
49+
error: generic arguments must come before the first constraint
50+
--> $DIR/suggest-move-types.rs:74:43
6951
|
7052
LL | struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
71-
| ^^^^----^^^^^^^^-^^^^^^^^-^
72-
| | | |
73-
| | | this generic argument must come before the first constraint
74-
| | this generic argument must come before the first constraint
53+
| ---- ^ ^
54+
| |
7555
| the first constraint is provided here
7656

77-
error: constraints in a path segment must come after generic arguments
78-
--> $DIR/suggest-move-types.rs:82:52
57+
error: generic arguments must come before the first constraint
58+
--> $DIR/suggest-move-types.rs:82:72
7959
|
8060
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
81-
| ^^^^^^^^----^^^^^^^^-^^--^^^^^^^^-^^--^
82-
| | | | | |
83-
| | | | | this generic argument must come before the first constraint
84-
| | | | this generic argument must come before the first constraint
85-
| | | this generic argument must come before the first constraint
86-
| | this generic argument must come before the first constraint
61+
| ---- ^ ^^ ^ ^^
62+
| |
8763
| the first constraint is provided here
8864

8965
error[E0747]: type provided when a lifetime was expected

0 commit comments

Comments
 (0)