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

Cast error doesn't suggest boxed traits but maybe it should. #44602

Open
quadrupleslap opened this issue Sep 15, 2017 · 0 comments
Open

Cast error doesn't suggest boxed traits but maybe it should. #44602

quadrupleslap opened this issue Sep 15, 2017 · 0 comments
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@quadrupleslap
Copy link

I have a function call that's something like:

test(&[&"nani?" as &_, &"=_=".to_owned() as &_]);

The first &_ is interpreted as a no-op cast, and the second is interpreted as a &String -> &&str. I did this to try and get a list of boxed traits, but the error message is pretty misleading unless you notice what the compiler's actually inferring, and almost makes it sound like as can't be used in this situation at all:

error[E0605]: non-primitive cast: `&std::string::String` as `&&str`
...
  = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait

I don't know how, but it would be nice if it could automagically recommend boxed traits in similar situations.

Playground

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 18, 2017
@crlf0710 crlf0710 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2020
@fmease fmease added the D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. label May 14, 2024
@fmease fmease added A-coercions Area: implicit and explicit `expr as Type` coercions S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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

4 participants