-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Incorrect warning about trait object use when accessing trait method via subtrait #83395
Comments
The warning was added in #82868 To confirm if the warning and codegen matched, I emitted MIR, which included the following: _4 = move _5 as &dyn Pin (Pointer(Unsize)); // scope 1 at src/main.rs:16:22: 16:25
StorageDead(_5); // scope 1 at src/main.rs:16:24: 16:25
_3 = <dyn Pin as Configure>::make_output(move _4) -> bb1; // scope 1 at src/main.rs:16:5: 16:26 showing that If we try _3 = <MyPin as Configure>::make_output(move _4) -> bb1; // scope 1 at src/main.rs:16:5: 16:22 If we try It appears it is correctly warning, though understandably surprising. |
Thanks for looking at the MIR. I was worried it would be something like that. Is it a bug that using a supertrait leads to different MIR than using the subtrait? I find that behavior..really unintuitive, though I suppose that this warning does actually help nudge people in the direction of the more performant option. Should I update the title and issue description? Or just close this? |
Based on rust-lang/lang-team#65 (comment), it seems expected for |
I confirm that the change is intentional. |
Thanks for the explanation! I'll close this, though I do still feel that the observed behavior is pretty unintuitive to someone not intimately familiar with how supertraits work in Rust. |
I have found that constructing a struct which implements a Supertrait, and then calling one of the trait methods of that Supertrait via the subtrait leads to a warning about trait objects without an explicit
dyn
being deprecated. See the following minimal exampleI expected this to compile without warning
Instead, I get the following output:
It is very surprising to me that whether I get a warning is dependent on whether or not I call the method directly via the Supertrait rather than via the subtrait. I would have expected those to compile equivalent code.
(This minimal reproduction is based off of encountering this error in a number of places in Tock when upgrading to the latest nightly.)
Meta
This happens on current nightly (2021-03-21) but not on a 2 month old nightly (2021-01-07), or on current stable (1.50.0).
Playground link with the warning: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c4bb2774141c86d7af6971e1876a203c
The text was updated successfully, but these errors were encountered: