Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add tests for parser
  • Loading branch information
b-naber committed Nov 11, 2020
commit 98e53ac25137f88010b0195257da49d55c75d341
16 changes: 16 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Several parsing errors for associated type constraints that are supposed
// to trigger all errors in ´get_assoc_type_with_generics´ and
// ´get_generic_args_from_path_segment´

#![feature(generic_associated_types)]

trait X {
type Y<'a>;
}

trait Z {}

impl<T : X<X::Y<'a> = &'a u32>> Z for T {}
//~^ ERROR: associated types cannot contain multiple path segments

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: found a Path with multiple segments, expected a Path with a single segment
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-1.rs:13:12
|
13 | impl<T : X<X::Y<'a> = &'a u32>> Z for T {}
| ^^^^^^^^
| |
| expected the name of an associated type
| help: try to use only the last segment:: `Y`

error: aborting due to previous error
12 changes: 12 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Only accept generic arguments of typeTyKind::Path as associated types in
// trait paths
#![feature(generic_associated_types)]

trait X {
type Y<'a>;
}

fn f1<'a>(arg : Box<dyn X<(Y<'a>) = &'a ()>>) {}
//~^ ERROR: Expected the name of an associated type

fn main() {}
18 changes: 18 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: Incorrect type of generic argument, expected a Path with a single path segment
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-2.rs:9:27
|
9 | fn f1<'a>(arg : Box<dyn X<(Y<'a>) = &'a ()>>) {}
| ^^^^^^^^-
| |
| Expected the name of an associated type

warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-2.rs:3:12
|
3 | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error: aborting due to previous error; 1 warning emitted
12 changes: 12 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Test to ensure that only GenericArg::Type is accepted in associated type
// constraints
#![feature(generic_associated_types)]

trait X {
type Y<'a>;
}

fn f1<'a>(arg : Box<dyn X<'a = &'a ()>>) {}
//~^ ERROR: Expected the name of an associated type

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: Incorrect type of generic argument, expected a path with a single segment
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-3.rs:9:27
|
9 | fn f1<'a>(arg : Box<dyn X<'a = &'a ()>>) {}
| ^^^^ expected the name of an associated type

warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-3.rs:3:12
|
3 | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error: aborting due to previous error; 1 warning emitted
14 changes: 14 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Only accept lifetimes or types as generic arguments for associated types
// in trait paths

#![feature(generic_associated_types)]

trait X {
type Y<'a>;
}

fn f1<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
//~^ ERROR: generic arguments of associated types must be lifetimes or types
//~^^ ERROR: wrong number of lifetime arguments: expected 1, found 0

fn main() {}
24 changes: 24 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-4.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error: generic arguments of associated types must be lifetimes or types
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-4.rs:10:27
|
10 | fn f1<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
| ^

warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-4.rs:4:12
|
4 | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0107]: wrong number of lifetime arguments: expected 1, found 0
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-4.rs:10:27
|
10 | fn f1<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
| ^^^^^^^^^^^^^ expected 1 lifetime argument

error: aborting due to 2 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0107`.
12 changes: 12 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-5.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Test to ensure that the Constraint branch of the pattern match on AngleBracketedArg
// in `get_assoc_type_with_generic_args` is unreachable
#![feature(generic_associated_types)]

trait X {
type Y<'a>;
}

fn f1<'a>(arg : Box<dyn X<Y = B = &'a ()>>) {}
//~^ ERROR: Expected the name of an associated type

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-5.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-5.rs:9:33
|
9 | fn f1<'a>(arg : Box<dyn X<Y = B = &'a ()>>) {}
| ^ expected one of 7 possible tokens

warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-5.rs:3:12
|
3 | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error: aborting due to previous error; 1 warning emitted
16 changes: 16 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-6.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Parser shouldn't accept parenthesized generic arguments for associated types in
// trait paths
#![feature(generic_associated_types)]

trait X {
type Y<'a>;
}

fn f1<'a>(arg : Box<dyn X<Y('a) = &'a ()>>) {}
//~^ ERROR: lifetime in trait object type must be followed by `+`
//~^^ ERROR: invalid use of parenthesized generic arguments, expected angle
// bracketed (`<...>`) generic arguments
//~^^^^ ERROR: wrong number of lifetime arguments: expected 1, found 0


fn main() {}
30 changes: 30 additions & 0 deletions src/test/ui/generic-associated-types/parse/issue-67510-6.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error: lifetime in trait object type must be followed by `+`
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-6.rs:9:29
|
9 | fn f1<'a>(arg : Box<dyn X<Y('a) = &'a ()>>) {}
| ^^

error: invalid use of parenthesized generic arguments, expected angle bracketed (`<...>`) generic arguments
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-6.rs:9:27
|
9 | fn f1<'a>(arg : Box<dyn X<Y('a) = &'a ()>>) {}
| ^^^^^

warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-6.rs:3:12
|
3 | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0107]: wrong number of lifetime arguments: expected 1, found 0
--> /Users/bn/Documents/rust_fork/rust/src/test/ui/generic-associated-types/parse/issue-67510-6.rs:9:27
|
9 | fn f1<'a>(arg : Box<dyn X<Y('a) = &'a ()>>) {}
| ^^^^^^^^^^^^^^ expected 1 lifetime argument

error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0107`.