-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use resolutions(()).effective_visiblities
to avoid cycle errors in report_object_error
#119506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 1 commit into
rust-lang:master
from
compiler-errors:visibilities-for-object-safety-error
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-object-safety.rs
This file contains hidden or 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,28 @@ | ||
trait Marker {} | ||
impl Marker for u32 {} | ||
|
||
trait MyTrait { | ||
fn foo(&self) -> impl Marker; | ||
} | ||
|
||
struct Outer; | ||
|
||
impl MyTrait for Outer { | ||
fn foo(&self) -> impl Marker { | ||
42 | ||
} | ||
} | ||
|
||
impl dyn MyTrait { | ||
//~^ ERROR the trait `MyTrait` cannot be made into an object | ||
fn other(&self) -> impl Marker { | ||
//~^ ERROR the trait `MyTrait` cannot be made into an object | ||
MyTrait::foo(&self) | ||
//~^ ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied | ||
//~| ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied | ||
//~| ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied | ||
//~| ERROR the trait `MyTrait` cannot be made into an object | ||
} | ||
} | ||
|
||
fn main() {} |
78 changes: 78 additions & 0 deletions
78
tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-object-safety.stderr
This file contains hidden or 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,78 @@ | ||
error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied | ||
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:22 | ||
| | ||
LL | MyTrait::foo(&self) | ||
| ------------ ^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `MyTrait` is implemented for `Outer` | ||
|
||
error[E0038]: the trait `MyTrait` cannot be made into an object | ||
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:9 | ||
| | ||
LL | MyTrait::foo(&self) | ||
| ^^^^^^^^^^^^ `MyTrait` 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/cycle-effective-visibilities-during-object-safety.rs:5:22 | ||
| | ||
LL | trait MyTrait { | ||
| ------- this trait cannot be made into an object... | ||
LL | fn foo(&self) -> impl Marker; | ||
| ^^^^^^^^^^^ ...because method `foo` references an `impl Trait` type in its return type | ||
= help: consider moving `foo` to another trait | ||
= help: only type `Outer` implements the trait, consider using it directly instead | ||
|
||
error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied | ||
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:9 | ||
| | ||
LL | MyTrait::foo(&self) | ||
| ^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` | ||
| | ||
= help: the trait `MyTrait` is implemented for `Outer` | ||
|
||
error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied | ||
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:9 | ||
| | ||
LL | MyTrait::foo(&self) | ||
| ^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` | ||
| | ||
= help: the trait `MyTrait` is implemented for `Outer` | ||
|
||
error[E0038]: the trait `MyTrait` cannot be made into an object | ||
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:16:6 | ||
| | ||
LL | impl dyn MyTrait { | ||
| ^^^^^^^^^^^ `MyTrait` 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/cycle-effective-visibilities-during-object-safety.rs:5:22 | ||
| | ||
LL | trait MyTrait { | ||
| ------- this trait cannot be made into an object... | ||
LL | fn foo(&self) -> impl Marker; | ||
| ^^^^^^^^^^^ ...because method `foo` references an `impl Trait` type in its return type | ||
= help: consider moving `foo` to another trait | ||
= help: only type `Outer` implements the trait, consider using it directly instead | ||
|
||
error[E0038]: the trait `MyTrait` cannot be made into an object | ||
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:18:15 | ||
| | ||
LL | fn other(&self) -> impl Marker { | ||
| ^^^^ `MyTrait` 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/cycle-effective-visibilities-during-object-safety.rs:5:22 | ||
| | ||
LL | trait MyTrait { | ||
| ------- this trait cannot be made into an object... | ||
LL | fn foo(&self) -> impl Marker; | ||
| ^^^^^^^^^^^ ...because method `foo` references an `impl Trait` type in its return type | ||
= help: consider moving `foo` to another trait | ||
= help: only type `Outer` implements the trait, consider using it directly instead | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors have detailed explanations: E0038, E0277. | ||
For more information about an error, try `rustc --explain E0038`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.