-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Clippy incorrectly complains about borrowed_box
when trait object is boxed
#3971
Comments
borrowed_box doesn't trigger on the code anymore. |
It is doing it again. I updated the example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f1d0ac1aa9020c047580ac51061f1af5 |
What prevents you from just using |
Whatever is a trait and at the point without a reference I have to box the trait. (not in the example, I could add it ) |
Can you do like trait Whatever {}
struct Something;
impl Whatever for Something {}
fn this_is_fine(_: &dyn Whatever) { }
fn this_is_also_fine_but_moves(_: Box<dyn Whatever>) { }
fn this_triggers_clippy(_: &Box<dyn Whatever>) { }
fn main() {
let wt: Box<dyn Whatever> = Box::new(Something);
this_triggers_clippy(&wt);
this_is_fine(&*wt);
this_is_also_fine_but_moves(wt);
} |
Alternatively |
Thanks, with the help of your example I got it working. I think it would be helpful for others to include this conversation in the message provided by clippy. |
Hard to include all of this in the message, but we should improve the documentation a bit. |
Ether that, I rather thought about a link to this conversation. |
The following code triggers
clippy::borrowed_box
:However, I don't think it should be complaining here since
Whatever
is notSized
(so I cannot overwrite it directly)I think, this issue (or similar) was raised before: #1884 (also mentioned in #3128)
The fix for #1884 was, however, just to check for
Any
trait as a special case.Playground
The text was updated successfully, but these errors were encountered: