-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Make cast suggestions verbose #142131
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
Make cast suggestions verbose #142131
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
``` error[E0604]: only `u8` can be cast as `char`, not `u32` --> $DIR/E0604.rs:2:5 | LL | 1u32 as char; | ^^^^^^^^^^^^ invalid cast | help: try `char::from_u32` instead | LL - 1u32 as char; LL + char::from_u32(1u32); | ``` ``` error[E0620]: cast to unsized type: `&[u8]` as `[char]` --> $DIR/cast-to-slice.rs:6:5 | LL | arr as [char]; | ^^^^^^^^^^^^^ | help: try casting to a reference instead | LL | arr as &[char]; | + ``` ``` error[E0620]: cast to unsized type: `Box<{integer}>` as `dyn Send` --> $DIR/cast-to-unsized-trait-object-suggestion.rs:3:5 | LL | Box::new(1) as dyn Send; | ^^^^^^^^^^^^^^^^^^^^^^^ | help: you can cast to a `Box` instead | LL | Box::new(1) as Box<dyn Send>; | ++++ + ```
Err(_) => err.span_help(self.span, "try `char::from_u32` instead"), | ||
}; | ||
err.multipart_suggestion( | ||
"try `char::from_u32` instead", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-existing (and no need to address it), but we should probably be consistent and use consider
instead of try
in those suggestions
r? Urgau r=me when CI is green |
@bors r=Urgau |
Make cast suggestions verbose ``` error[E0604]: only `u8` can be cast as `char`, not `u32` --> $DIR/E0604.rs:2:5 | LL | 1u32 as char; | ^^^^^^^^^^^^ invalid cast | help: try `char::from_u32` instead | LL - 1u32 as char; LL + char::from_u32(1u32); | ``` ``` error[E0620]: cast to unsized type: `&[u8]` as `[char]` --> $DIR/cast-to-slice.rs:6:5 | LL | arr as [char]; | ^^^^^^^^^^^^^ | help: try casting to a reference instead | LL | arr as &[char]; | + ``` ``` error[E0620]: cast to unsized type: `Box<{integer}>` as `dyn Send` --> $DIR/cast-to-unsized-trait-object-suggestion.rs:3:5 | LL | Box::new(1) as dyn Send; | ^^^^^^^^^^^^^^^^^^^^^^^ | help: you can cast to a `Box` instead | LL | Box::new(1) as Box<dyn Send>; | ++++ + ``` Part of rust-lang#141973.
Rollup of 8 pull requests Successful merges: - #137992 (Stabilise `os_string_pathbuf_leak`) - #141558 (Limit the size of cgu names when using the `-Zhuman-readable-cgu-name…) - #141797 (compiler: set Apple frame pointers by architecture) - #141857 (coretests: move float tests from num to floats module and use a more flexible macro to generate them) - #142045 (Make obligation cause code suggestions verbose) - #142076 (Check documentation of bootstrap in PR CI) - #142110 (Add solaris targets to build-manifest) - #142131 (Make cast suggestions verbose) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #142131 - estebank:cast-sugg, r=Urgau Make cast suggestions verbose ``` error[E0604]: only `u8` can be cast as `char`, not `u32` --> $DIR/E0604.rs:2:5 | LL | 1u32 as char; | ^^^^^^^^^^^^ invalid cast | help: try `char::from_u32` instead | LL - 1u32 as char; LL + char::from_u32(1u32); | ``` ``` error[E0620]: cast to unsized type: `&[u8]` as `[char]` --> $DIR/cast-to-slice.rs:6:5 | LL | arr as [char]; | ^^^^^^^^^^^^^ | help: try casting to a reference instead | LL | arr as &[char]; | + ``` ``` error[E0620]: cast to unsized type: `Box<{integer}>` as `dyn Send` --> $DIR/cast-to-unsized-trait-object-suggestion.rs:3:5 | LL | Box::new(1) as dyn Send; | ^^^^^^^^^^^^^^^^^^^^^^^ | help: you can cast to a `Box` instead | LL | Box::new(1) as Box<dyn Send>; | ++++ + ``` Part of #141973.
Part of #141973.