]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/fallible_impl_from.rs
1 #![deny(clippy::fallible_impl_from)]
2 #![allow(clippy::uninlined_format_args)]
6 impl From
<String
> for Foo
{
7 //~^ ERROR: consider implementing `TryFrom` instead
8 fn from(s
: String
) -> Self {
9 Foo(s
.parse().unwrap())
13 struct Valid(Vec
<u8>);
15 impl<'a
> From
<&'a
str> for Valid
{
16 fn from(s
: &'a
str) -> Valid
{
17 Valid(s
.to_owned().into_bytes())
20 impl From
<usize> for Valid
{
21 fn from(i
: usize) -> Valid
{
22 Valid(Vec
::with_capacity(i
))
28 impl From
<usize> for Invalid
{
29 //~^ ERROR: consider implementing `TryFrom` instead
30 fn from(i
: usize) -> Invalid
{
38 impl From
<Option
<String
>> for Invalid
{
39 //~^ ERROR: consider implementing `TryFrom` instead
40 fn from(s
: Option
<String
>) -> Invalid
{
44 } else if s
.parse
::<u32>().unwrap() != 42 {
54 impl<T
> ProjStrTrait
for Box
<T
> {
55 type ProjString
= String
;
57 impl<'a
> From
<&'a
mut <Box
<u32> as ProjStrTrait
>::ProjString
> for Invalid
{
58 //~^ ERROR: consider implementing `TryFrom` instead
59 fn from(s
: &'a
mut <Box
<u32> as ProjStrTrait
>::ProjString
) -> Invalid
{
60 if s
.parse
::<u32>().ok().unwrap() != 42 {
69 impl From
<String
> for Unreachable
{
70 fn from(s
: String
) -> Unreachable
{
74 match s
.chars().next() {
75 Some(_
) => Unreachable
,
76 None
=> unreachable
!(), // do not lint the unreachable macro