Skip to content

Compiler "suggests" boxing type to access method that is not callable without bringing trait into scope #84812

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

Closed
BoxyUwU opened this issue May 2, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@BoxyUwU
Copy link
Member

BoxyUwU commented May 2, 2021

Given the following code: link

fn main() {
    let mut rng = rand::thread_rng();
    // uncomment me for Box<Box<ThreadRng>> error
    //let mut rng = Box::new(rng);
    rng.gen::<u32>();
}

The current output is:

error[E0599]: no method named `gen` found for struct `ThreadRng` in the current scope
  --> src/main.rs:5:9
   |
5  |     rng.gen::<u32>();
   |         ^^^ method not found in `ThreadRng`
   | 
  ::: /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.3/src/rng.rs:91:8
   |
91 |     fn gen<T>(&mut self) -> T
   |        --- the method is available for `Box<ThreadRng>` here
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
1  | use rand::Rng;
   |

uncommenting the let mut rng = Box::new(rng); line gives the following output:

error[E0599]: no method named `gen` found for struct `Box<ThreadRng>` in the current scope
  --> src/main.rs:5:9
   |
5  |     rng.gen::<u32>();
   |         ^^^ method not found in `Box<ThreadRng>`
   | 
  ::: /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.3/src/rng.rs:91:8
   |
91 |     fn gen<T>(&mut self) -> T
   |        --- the method is available for `Box<Box<ThreadRng>>` here
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
1  | use rand::Rng;
   |

and this just keeps adding more Box<Box<Box<Box<Box<...<ThreadRng>>>>>>>>> forever if you keep boxing in an attempt to access the "available method" 😆

@estebank

@BoxyUwU BoxyUwU added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 2, 2021
@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented May 2, 2021

This might be a duplicate of #84792

@BoxyUwU BoxyUwU closed this as completed Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants