Skip to content
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 suggestion about borrowed_box when trait object is boxed is incomplete #11940

Open
droogmic opened this issue Dec 9, 2023 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@droogmic
Copy link

droogmic commented Dec 9, 2023

Summary

This follows from #3971
and #8161.

I think the message should suggest the .as_ref() method at the call site.

Reproducer

Clippy reported this:

warning: you seem to be trying to use `&Box<T>`. Consider using just `&T`
  --> advent2023-bin/src/main.rs:46:54
   |
46 |     let get_result_pair = move |day_num: usize, day: &Box<dyn DayTrait>| -> (String, String) {
   |                                                      ^^^^^^^^^^^^^^^^^^ help: try: `&dyn DayTrait`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
   = note: `#[warn(clippy::borrowed_box)]` on by default

When fixed as indicated:

error[E0277]: the trait bound `Box<dyn DayTrait>: DayTrait` is not satisfied
  --> advent2023-bin/src/main.rs:63:76
   |
63 |             print_day(day_num, day.get_display(), get_result_pair(day_num, &day));
   |                                                                            ^^^^ the trait `DayTrait` is not implemented for `Box<dyn DayTrait>`
   |
   = help: the trait `DayTrait` is implemented for `Day<D, O, C, F, S>`
   = note: required for the cast from `&Box<dyn DayTrait>` to `&dyn DayTrait`

See minimum reproduction:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=88aa6d38369c9c8f48eabf5899ed65b0

Version

rustc 1.76.0-nightly (87e1447aa 2023-11-30)
binary: rustc
commit-hash: 87e1447aadaa2899ff6ccabe1fa669eb50fb60a1
commit-date: 2023-11-30
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

Additional Labels

No response

@droogmic droogmic added the C-bug Category: Clippy is not doing the correct thing label Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

1 participant