-
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
Trivial cast warning for cast that can't be removed #23742
Comments
Note: I've got another instance of this where I'm not doing it in a pair, but for a single |
"Trivial" doesn't mean "can be omitted", the warning triggers because type ascription is supposed to be used here and not |
As far as I can tell, this isn't really something that we can fix; it's working as intended. Replacing the single-line casts with something like the following resolves both the lint and doesn't introduce any errors. I wasn't quite able to get it working with type ascription, though, but I feel like that's likely my fault. Should this be closed? let ar: *mut _ = slc.get_unchecked_mut(a);
let ar = &mut *(ar); |
Closing, please reopen if this is still an issue. |
Trivial cast warnings are no longer enabled by default, so the issue is fixed that way. |
…_lint_doc, r=steveklabnik Reword `trivial_casts` lint in rustc book to better explain what it does. The current description of the trivial casts lint under the "allowed by default" listing in the rustc book indicates the lint is for casts which may be removed, which is less clear than saying it's for casts which may be replaced by coercion (which is the wording used by the error message included in the doc). This commit changes the wording slightly to better describe what the lint does. This issue bit me in some recent code where I was attempting to convert a `Vec<SomeType>` to a `Vec<SomeTraitObject>`, and hit my project-wide `#![deny(trivial_casts)]` with `map(|o| Box::new(o) as TraitObject)`. I'd read the book docs for `trivial_casts` and was surprised by the error, as I took it to mean the cast ought to be removed (rather than replaced by ascription in this case). Removing the cast meant other code didn't compile, and I then found issues like rust-lang#23742 and realized my misunderstanding.
The following code yields warnings:
Warning spots are marked
// WARN
belowThe casts are non-trivial because without them the code does not pass the borrow check. Under the circumstances above we do so soundly by using an unsafe block.
Warning introduced in #23630
The text was updated successfully, but these errors were encountered: