forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#110590 - oli-obk:object_safe_assoc_types, r…
…=jackh726 Add some tests around (lack of) object safety of associated types and consts See https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/.60where.20Self.3ASized.60.20on.20assoc.20types/near/351260928 for some discussion around why this isn't allowed. We didn't have any tests for these, so I decided to add them now, even if we don't end up doing anything about it.
- Loading branch information
Showing
10 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
trait Foo<T> { | ||
const BAR: bool | ||
where //~ ERROR: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where` | ||
Self: Sized; | ||
} | ||
|
||
trait Cake {} | ||
impl Cake for () {} | ||
|
||
fn foo(_: &dyn Foo<()>) {} | ||
fn bar(_: &dyn Foo<i32>) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where` | ||
--> $DIR/assoc_const_bounds.rs:3:9 | ||
| | ||
LL | trait Foo<T> { | ||
| - while parsing this item list starting here | ||
LL | const BAR: bool | ||
| - expected one of 7 possible tokens | ||
LL | where | ||
| ^^^^^ unexpected token | ||
LL | Self: Sized; | ||
LL | } | ||
| - the item list ends here | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
trait Foo { | ||
const BAR: bool | ||
where //~ ERROR: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where` | ||
Self: Sized; | ||
} | ||
|
||
fn foo(_: &dyn Foo) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where` | ||
--> $DIR/assoc_const_bounds_sized.rs:3:9 | ||
| | ||
LL | trait Foo { | ||
| - while parsing this item list starting here | ||
LL | const BAR: bool | ||
| - expected one of 7 possible tokens | ||
LL | where | ||
| ^^^^^ unexpected token | ||
LL | Self: Sized; | ||
LL | } | ||
| - the item list ends here | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
trait Foo<T> { | ||
type Bar | ||
where | ||
T: Cake; | ||
} | ||
|
||
trait Cake {} | ||
impl Cake for () {} | ||
|
||
fn foo(_: &dyn Foo<()>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
fn bar(_: &dyn Foo<i32>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
--> $DIR/assoc_type_bounds.rs:10:16 | ||
| | ||
LL | type Bar | ||
| -------- `Bar` defined here | ||
... | ||
LL | fn foo(_: &dyn Foo<()>) {} | ||
| ^^^^^^^ help: specify the associated type: `Foo<(), Bar = Type>` | ||
|
||
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
--> $DIR/assoc_type_bounds.rs:11:16 | ||
| | ||
LL | type Bar | ||
| -------- `Bar` defined here | ||
... | ||
LL | fn bar(_: &dyn Foo<i32>) {} | ||
| ^^^^^^^^ help: specify the associated type: `Foo<i32, Bar = Type>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0191`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
trait Foo<T> { | ||
type Bar | ||
where | ||
Self: Foo<()>; | ||
} | ||
|
||
trait Cake {} | ||
impl Cake for () {} | ||
|
||
fn foo(_: &dyn Foo<()>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
fn bar(_: &dyn Foo<i32>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
--> $DIR/assoc_type_bounds2.rs:10:16 | ||
| | ||
LL | type Bar | ||
| -------- `Bar` defined here | ||
... | ||
LL | fn foo(_: &dyn Foo<()>) {} | ||
| ^^^^^^^ help: specify the associated type: `Foo<(), Bar = Type>` | ||
|
||
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
--> $DIR/assoc_type_bounds2.rs:11:16 | ||
| | ||
LL | type Bar | ||
| -------- `Bar` defined here | ||
... | ||
LL | fn bar(_: &dyn Foo<i32>) {} | ||
| ^^^^^^^^ help: specify the associated type: `Foo<i32, Bar = Type>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0191`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
trait Foo { | ||
type Bar | ||
where | ||
Self: Sized; | ||
} | ||
|
||
fn foo(_: &dyn Foo) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified | ||
--> $DIR/assoc_type_bounds_sized.rs:7:16 | ||
| | ||
LL | type Bar | ||
| -------- `Bar` defined here | ||
... | ||
LL | fn foo(_: &dyn Foo) {} | ||
| ^^^ help: specify the associated type: `Foo<Bar = Type>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0191`. |