mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
94 lines
3.3 KiB
Text
94 lines
3.3 KiB
Text
error: consider implementing `TryFrom` instead
|
|
--> tests/ui/fallible_impl_from.rs:6:1
|
|
|
|
|
LL | / impl From<String> for Foo {
|
|
LL | |
|
|
LL | | fn from(s: String) -> Self {
|
|
LL | | Foo(s.parse().unwrap())
|
|
LL | | }
|
|
LL | | }
|
|
| |_^
|
|
|
|
|
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
|
note: potential failure(s)
|
|
--> tests/ui/fallible_impl_from.rs:9:13
|
|
|
|
|
LL | Foo(s.parse().unwrap())
|
|
| ^^^^^^^^^^^^^^^^^^
|
|
note: the lint level is defined here
|
|
--> tests/ui/fallible_impl_from.rs:1:9
|
|
|
|
|
LL | #![deny(clippy::fallible_impl_from)]
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: consider implementing `TryFrom` instead
|
|
--> tests/ui/fallible_impl_from.rs:28:1
|
|
|
|
|
LL | / impl From<usize> for Invalid {
|
|
LL | |
|
|
LL | | fn from(i: usize) -> Invalid {
|
|
LL | | if i != 42 {
|
|
... |
|
|
LL | | }
|
|
LL | | }
|
|
| |_^
|
|
|
|
|
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
|
note: potential failure(s)
|
|
--> tests/ui/fallible_impl_from.rs:32:13
|
|
|
|
|
LL | panic!();
|
|
| ^^^^^^^^
|
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
|
|
error: consider implementing `TryFrom` instead
|
|
--> tests/ui/fallible_impl_from.rs:38:1
|
|
|
|
|
LL | / impl From<Option<String>> for Invalid {
|
|
LL | |
|
|
LL | | fn from(s: Option<String>) -> Invalid {
|
|
LL | | let s = s.unwrap();
|
|
... |
|
|
LL | | }
|
|
LL | | }
|
|
| |_^
|
|
|
|
|
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
|
note: potential failure(s)
|
|
--> tests/ui/fallible_impl_from.rs:41:17
|
|
|
|
|
LL | let s = s.unwrap();
|
|
| ^^^^^^^^^^
|
|
LL | if !s.is_empty() {
|
|
LL | panic!("42");
|
|
| ^^^^^^^^^^^^
|
|
LL | } else if s.parse::<u32>().unwrap() != 42 {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
LL | panic!("{:?}", s);
|
|
| ^^^^^^^^^^^^^^^^^
|
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
|
|
error: consider implementing `TryFrom` instead
|
|
--> tests/ui/fallible_impl_from.rs:57:1
|
|
|
|
|
LL | / impl<'a> From<&'a mut <Box<u32> as ProjStrTrait>::ProjString> for Invalid {
|
|
LL | |
|
|
LL | | fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
|
|
LL | | if s.parse::<u32>().ok().unwrap() != 42 {
|
|
... |
|
|
LL | | }
|
|
LL | | }
|
|
| |_^
|
|
|
|
|
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
|
note: potential failure(s)
|
|
--> tests/ui/fallible_impl_from.rs:60:12
|
|
|
|
|
LL | if s.parse::<u32>().ok().unwrap() != 42 {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
LL | panic!("{:?}", s);
|
|
| ^^^^^^^^^^^^^^^^^
|
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
|
|
error: aborting due to 4 previous errors
|
|
|