-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make WHERE_CLAUSES_OBJECT_SAFETY a regular object safety violation
- Loading branch information
1 parent
8768db9
commit de6b219
Showing
13 changed files
with
74 additions
and
191 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
5 changes: 2 additions & 3 deletions
5
tests/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs
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 |
---|---|---|
@@ -1,22 +1,21 @@ | ||
#![feature(generic_const_exprs)] | ||
#![allow(incomplete_features)] | ||
#![deny(where_clauses_object_safety)] | ||
|
||
|
||
const fn bar<T: ?Sized>() -> usize { 7 } | ||
|
||
trait Foo { | ||
fn test(&self) where [u8; bar::<Self>()]: Sized; | ||
//~^ ERROR the trait `Foo` cannot be made into an object | ||
//~| WARN this was previously accepted by the compiler but is being phased out | ||
} | ||
|
||
impl Foo for () { | ||
fn test(&self) where [u8; bar::<Self>()]: Sized {} | ||
} | ||
|
||
fn use_dyn(v: &dyn Foo) { | ||
//~^ ERROR the trait `Foo` cannot be made into an object | ||
v.test(); | ||
//~^ ERROR the trait `Foo` cannot be made into an object | ||
} | ||
|
||
fn main() {} |
35 changes: 23 additions & 12 deletions
35
tests/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr
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 |
---|---|---|
@@ -1,24 +1,35 @@ | ||
error: the trait `Foo` cannot be made into an object | ||
--> $DIR/object-safety-err-where-bounds.rs:9:8 | ||
error[E0038]: the trait `Foo` cannot be made into an object | ||
--> $DIR/object-safety-err-where-bounds.rs:15:16 | ||
| | ||
LL | fn test(&self) where [u8; bar::<Self>()]: Sized; | ||
| ^^^^ | ||
LL | fn use_dyn(v: &dyn Foo) { | ||
| ^^^^^^^ `Foo` cannot be made into an object | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443> | ||
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> | ||
--> $DIR/object-safety-err-where-bounds.rs:9:8 | ||
--> $DIR/object-safety-err-where-bounds.rs:8:8 | ||
| | ||
LL | trait Foo { | ||
| --- this trait cannot be made into an object... | ||
LL | fn test(&self) where [u8; bar::<Self>()]: Sized; | ||
| ^^^^ ...because method `test` references the `Self` type in its `where` clause | ||
= help: consider moving `test` to another trait | ||
note: the lint level is defined here | ||
--> $DIR/object-safety-err-where-bounds.rs:3:9 | ||
= help: only type `()` implements the trait, consider using it directly instead | ||
|
||
error[E0038]: the trait `Foo` cannot be made into an object | ||
--> $DIR/object-safety-err-where-bounds.rs:17:5 | ||
| | ||
LL | v.test(); | ||
| ^^^^^^^^ `Foo` cannot be made into an object | ||
| | ||
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> | ||
--> $DIR/object-safety-err-where-bounds.rs:8:8 | ||
| | ||
LL | #![deny(where_clauses_object_safety)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | trait Foo { | ||
| --- this trait cannot be made into an object... | ||
LL | fn test(&self) where [u8; bar::<Self>()]: Sized; | ||
| ^^^^ ...because method `test` references the `Self` type in its `where` clause | ||
= help: consider moving `test` to another trait | ||
= help: only type `()` implements the trait, consider using it directly instead | ||
|
||
error: aborting due to 1 previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0038`. |
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
#![deny(where_clauses_object_safety)] | ||
|
||
trait Trait {} | ||
|
||
trait X { | ||
fn foo(&self) where Self: Trait; //~ ERROR the trait `X` cannot be made into an object | ||
//~^ WARN this was previously accepted by the compiler but is being phased out | ||
fn foo(&self) where Self: Trait; | ||
} | ||
|
||
impl X for () { | ||
fn foo(&self) {} | ||
} | ||
|
||
impl Trait for dyn X {} | ||
//~^ ERROR the trait `X` cannot be made into an object | ||
|
||
pub fn main() { | ||
// Check that this does not segfault. | ||
<dyn X as X>::foo(&()); | ||
//~^ ERROR the trait `X` cannot be made into an object | ||
//~| ERROR the trait `X` cannot be made into an object | ||
} |
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 |
---|---|---|
@@ -1,24 +1,52 @@ | ||
error: the trait `X` cannot be made into an object | ||
--> $DIR/issue-50781.rs:6:8 | ||
error[E0038]: the trait `X` cannot be made into an object | ||
--> $DIR/issue-50781.rs:11:16 | ||
| | ||
LL | impl Trait for dyn X {} | ||
| ^^^^^ `X` cannot be made into an object | ||
| | ||
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> | ||
--> $DIR/issue-50781.rs:4:8 | ||
| | ||
LL | trait X { | ||
| - this trait cannot be made into an object... | ||
LL | fn foo(&self) where Self: Trait; | ||
| ^^^ | ||
| ^^^ ...because method `foo` references the `Self` type in its `where` clause | ||
= help: consider moving `foo` to another trait | ||
= help: only type `()` implements the trait, consider using it directly instead | ||
|
||
error[E0038]: the trait `X` cannot be made into an object | ||
--> $DIR/issue-50781.rs:16:23 | ||
| | ||
LL | <dyn X as X>::foo(&()); | ||
| ^^^ `X` cannot be made into an object | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443> | ||
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> | ||
--> $DIR/issue-50781.rs:6:8 | ||
--> $DIR/issue-50781.rs:4:8 | ||
| | ||
LL | trait X { | ||
| - this trait cannot be made into an object... | ||
LL | fn foo(&self) where Self: Trait; | ||
| ^^^ ...because method `foo` references the `Self` type in its `where` clause | ||
= help: consider moving `foo` to another trait | ||
note: the lint level is defined here | ||
--> $DIR/issue-50781.rs:1:9 | ||
= help: only type `()` implements the trait, consider using it directly instead | ||
= note: required for the cast from `&()` to `&dyn X` | ||
|
||
error[E0038]: the trait `X` cannot be made into an object | ||
--> $DIR/issue-50781.rs:16:6 | ||
| | ||
LL | <dyn X as X>::foo(&()); | ||
| ^^^^^ `X` cannot be made into an object | ||
| | ||
LL | #![deny(where_clauses_object_safety)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> | ||
--> $DIR/issue-50781.rs:4:8 | ||
| | ||
LL | trait X { | ||
| - this trait cannot be made into an object... | ||
LL | fn foo(&self) where Self: Trait; | ||
| ^^^ ...because method `foo` references the `Self` type in its `where` clause | ||
= help: consider moving `foo` to another trait | ||
= help: only type `()` implements the trait, consider using it directly instead | ||
|
||
error: aborting due to 1 previous error | ||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0038`. |
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
//@ check-pass | ||
|
||
#![deny(where_clauses_object_safety)] | ||
|
||
pub trait Trait { | ||
fn method(&self) where Self: Sync; | ||
} | ||
|
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
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
Oops, something went wrong.