-
Notifications
You must be signed in to change notification settings - Fork 32
/
mismatch-sugg-for-shorthand-field.rs
77 lines (61 loc) · 1.43 KB
/
mismatch-sugg-for-shorthand-field.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//@ run-rustfix
//@ edition:2021
#![allow(dead_code)]
#![allow(unused_variables)]
use std::future::Future;
use std::pin::Pin;
fn test1() {
let string = String::from("Hello, world");
struct Demo<'a> {
option: Option<&'a str>,
}
let option: Option<String> = Some(string.clone());
let s = Demo { option }; //~ ERROR mismatched types
}
fn test2() {
let string = String::from("Hello, world");
struct Demo<'a> {
option_ref: Option<&'a str>,
}
let option_ref = Some(&string);
let s = Demo { option_ref }; //~ ERROR mismatched types
}
fn test3() {
let string = String::from("Hello, world");
struct Demo<'a> {
option_ref_ref: Option<&'a str>,
}
let option_ref = Some(&string);
let option_ref_ref = option_ref.as_ref();
let s = Demo { option_ref_ref }; //~ ERROR mismatched types
}
fn test4() {
let a = 1;
struct Demo {
a: String,
}
let s = Demo { a }; //~ ERROR mismatched types
}
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
fn test5() {
let a = async { 42 };
struct Demo {
a: BoxFuture<'static, i32>,
}
let s = Demo { a }; //~ ERROR mismatched types
}
fn test6() {
struct A;
struct B;
impl From<B> for A {
fn from(_: B) -> Self {
A
}
}
struct Demo {
a: A,
}
let a = B;
let s = Demo { a }; //~ ERROR mismatched types
}
fn main() {}