Skip to content

Commit a759e56

Browse files
committed
WIP
1 parent b32e6e6 commit a759e56

File tree

9 files changed

+43
-77
lines changed

9 files changed

+43
-77
lines changed

compiler/rustc_parse/src/parser/path.rs

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,10 @@ impl<'a> Parser<'a> {
418418
match arg {
419419
Some(arg) => {
420420
if self.check(&token::Colon) | self.check(&token::Eq) {
421-
let (ident, gen_args) = self.get_ident_from_generic_arg(arg, lo)?;
421+
let (ident, gen_args) = match self.get_ident_from_generic_arg(arg) {
422+
Ok(ident_gen_args) => ident_gen_args,
423+
Err(arg) => return Ok(Some(AngleBracketedArg::Arg(arg))),
424+
};
422425
let kind = if self.eat(&token::Colon) {
423426
// Parse associated type constraint bound.
424427

@@ -553,50 +556,15 @@ impl<'a> Parser<'a> {
553556
fn get_ident_from_generic_arg(
554557
&self,
555558
gen_arg: GenericArg,
556-
lo: Span,
557-
) -> PResult<'a, (Ident, Option<GenericArgs>)> {
558-
let gen_arg_span = gen_arg.span();
559-
match gen_arg {
560-
GenericArg::Type(t) => match t.into_inner().kind {
561-
ast::TyKind::Path(qself, mut path) => {
562-
if let Some(qself) = qself {
563-
let mut err = self.struct_span_err(
564-
gen_arg_span,
565-
"qualified paths cannot be used in associated type constraints",
566-
);
567-
err.span_label(
568-
qself.path_span,
569-
"not allowed in associated type constraints",
570-
);
571-
return Err(err);
572-
}
573-
if path.segments.len() == 1 {
574-
let path_seg = path.segments.remove(0);
575-
let ident = path_seg.ident;
576-
let gen_args = path_seg.args.map(|args| args.into_inner());
577-
return Ok((ident, gen_args));
578-
}
579-
let err = self.struct_span_err(
580-
path.span,
581-
"paths with multiple segments cannot be used in associated type constraints",
582-
);
583-
return Err(err);
559+
) -> Result<(Ident, Option<GenericArgs>), GenericArg> {
560+
if let GenericArg::Type(ty) = &gen_arg {
561+
if let ast::TyKind::Path(qself, path) = &ty.kind {
562+
if qself.is_none() && path.segments.len() == 1 {
563+
let seg = &path.segments[0];
564+
return Ok((seg.ident, seg.args.as_deref().cloned()));
584565
}
585-
_ => {
586-
let span = lo.to(self.prev_token.span);
587-
let err = self.struct_span_err(
588-
span,
589-
"only path types can be used in associated type constraints",
590-
);
591-
return Err(err);
592-
}
593-
},
594-
_ => {
595-
let span = lo.to(self.prev_token.span);
596-
let err = self
597-
.struct_span_err(span, "only types can be used in associated type constraints");
598-
return Err(err);
599566
}
600567
}
568+
Err(gen_arg)
601569
}
602570
}

src/test/ui/generic-associated-types/parse/trait-path-expressions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod error2 {
1717
}
1818

1919
fn f2<'a>(arg : Box<dyn X< { 1 } = 32 >>) {}
20-
//~^ ERROR: only types can be used in associated type constraints
20+
//~^ ERROR: expected one of
2121
}
2222

2323
fn main() {}

src/test/ui/generic-associated-types/parse/trait-path-expressions.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | fn f1<'a>(arg : Box<dyn X< 1 = 32 >>) {}
66
| |
77
| while parsing a const generic argument starting here
88

9-
error: only types can be used in associated type constraints
10-
--> $DIR/trait-path-expressions.rs:19:30
9+
error: expected one of `,`, `:`, or `>`, found `=`
10+
--> $DIR/trait-path-expressions.rs:19:36
1111
|
1212
LL | fn f2<'a>(arg : Box<dyn X< { 1 } = 32 >>) {}
13-
| ^^^^^
13+
| ^ expected one of `,`, `:`, or `>`
1414

1515
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
1616
--> $DIR/trait-path-expressions.rs:1:12

src/test/ui/generic-associated-types/parse/trait-path-segments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const _: () = {
77
}
88

99
fn f1<'a>(arg : Box<dyn X<X::Y = u32>>) {}
10-
//~^ ERROR: paths with multiple segments cannot be used in associated type constraints
10+
//~^ ERROR: expected one of
1111
};
1212

1313
const _: () = {
@@ -18,7 +18,7 @@ const _: () = {
1818
trait Z {}
1919

2020
impl<T : X<<Self as X>::Y<'a> = &'a u32>> Z for T {}
21-
//~^ ERROR: qualified paths cannot be used in associated type constraints
21+
//~^ ERROR: expected one of
2222
};
2323

2424
const _: () = {
@@ -29,7 +29,7 @@ const _: () = {
2929
trait Z {}
3030

3131
impl<T : X<X::Y<'a> = &'a u32>> Z for T {}
32-
//~^ ERROR: paths with multiple segments cannot be used in associated type constraints
32+
//~^ ERROR: expected one of
3333
};
3434

3535
fn main() {}

src/test/ui/generic-associated-types/parse/trait-path-segments.stderr

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
error: paths with multiple segments cannot be used in associated type constraints
2-
--> $DIR/trait-path-segments.rs:9:31
1+
error: expected one of `!`, `(`, `+`, `,`, `::`, `:`, `<`, or `>`, found `=`
2+
--> $DIR/trait-path-segments.rs:9:36
33
|
44
LL | fn f1<'a>(arg : Box<dyn X<X::Y = u32>>) {}
5-
| ^^^^
5+
| ^ expected one of 8 possible tokens
66

7-
error: qualified paths cannot be used in associated type constraints
8-
--> $DIR/trait-path-segments.rs:20:16
7+
error: expected one of `,`, `::`, `:`, or `>`, found `=`
8+
--> $DIR/trait-path-segments.rs:20:35
99
|
1010
LL | impl<T : X<<Self as X>::Y<'a> = &'a u32>> Z for T {}
11-
| ^^^^^^^^^-^^^^^^^^
12-
| |
13-
| not allowed in associated type constraints
11+
| ^ expected one of `,`, `::`, `:`, or `>`
1412

15-
error: paths with multiple segments cannot be used in associated type constraints
16-
--> $DIR/trait-path-segments.rs:31:16
13+
error: expected one of `!`, `+`, `,`, `::`, `:`, or `>`, found `=`
14+
--> $DIR/trait-path-segments.rs:31:25
1715
|
1816
LL | impl<T : X<X::Y<'a> = &'a u32>> Z for T {}
19-
| ^^^^^^^^
17+
| ^ expected one of `!`, `+`, `,`, `::`, `:`, or `>`
2018

2119
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
2220
--> $DIR/trait-path-segments.rs:1:12

src/test/ui/generic-associated-types/parse/trait-path-types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ trait X {
77

88
const _: () = {
99
fn f<'a>(arg : Box<dyn X< [u8; 1] = u32>>) {}
10-
//~^ ERROR: only path types can be used in associated type constraints
10+
//~^ ERROR: expected one of
1111
};
1212

1313
const _: () = {
1414
fn f1<'a>(arg : Box<dyn X<(Y<'a>) = &'a ()>>) {}
15-
//~^ ERROR: only path types can be used in associated type constraints
15+
//~^ ERROR: expected one of
1616
};
1717

1818
const _: () = {
1919
fn f1<'a>(arg : Box<dyn X< 'a = u32 >>) {}
20-
//~^ ERROR: only types can be used in associated type constraints
20+
//~^ ERROR: expected one of
2121
};
2222

2323
fn main() {}

src/test/ui/generic-associated-types/parse/trait-path-types.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error: only path types can be used in associated type constraints
2-
--> $DIR/trait-path-types.rs:9:29
1+
error: expected one of `,`, `:`, or `>`, found `=`
2+
--> $DIR/trait-path-types.rs:9:37
33
|
44
LL | fn f<'a>(arg : Box<dyn X< [u8; 1] = u32>>) {}
5-
| ^^^^^^^
5+
| ^ expected one of `,`, `:`, or `>`
66

7-
error: only path types can be used in associated type constraints
8-
--> $DIR/trait-path-types.rs:14:29
7+
error: expected one of `,`, `:`, or `>`, found `=`
8+
--> $DIR/trait-path-types.rs:14:37
99
|
1010
LL | fn f1<'a>(arg : Box<dyn X<(Y<'a>) = &'a ()>>) {}
11-
| ^^^^^^^
11+
| ^ expected one of `,`, `:`, or `>`
1212

13-
error: only types can be used in associated type constraints
14-
--> $DIR/trait-path-types.rs:19:30
13+
error: expected one of `,`, `:`, or `>`, found `=`
14+
--> $DIR/trait-path-types.rs:19:33
1515
|
1616
LL | fn f1<'a>(arg : Box<dyn X< 'a = u32 >>) {}
17-
| ^^
17+
| ^ expected one of `,`, `:`, or `>`
1818

1919
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
2020
--> $DIR/trait-path-types.rs:1:12

src/test/ui/issues/issue-34334.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main () {
22
let sr: Vec<(u32, _, _) = vec![];
3-
//~^ ERROR only path types can be used in associated type constraints
3+
//~^ ERROR expected one of
44
let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect();
55
//~^ ERROR a value of type `Vec<(u32, _, _)>` cannot be built
66
}

src/test/ui/issues/issue-34334.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: only path types can be used in associated type constraints
2-
--> $DIR/issue-34334.rs:2:17
1+
error: expected one of `,`, `:`, or `>`, found `=`
2+
--> $DIR/issue-34334.rs:2:29
33
|
44
LL | let sr: Vec<(u32, _, _) = vec![];
5-
| -- ^^^^^^^^^^^
5+
| -- ^ expected one of `,`, `:`, or `>`
66
| |
77
| while parsing the type for `sr`
88

0 commit comments

Comments
 (0)