Skip to content

Commit

Permalink
Add ui test of unsatisfied serde trait bound
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 6, 2024
1 parent 8e6637a commit b2683ef
Show file tree
Hide file tree
Showing 2 changed files with 347 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test_suite/tests/ui/on_unimplemented.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use serde::de::Deserialize;
use serde::ser::Serialize;

fn to_string<T>(_: &T) -> String
where
T: Serialize,
{
unimplemented!()
}

fn from_str<'de, T>(_: &'de str) -> T
where
T: Deserialize<'de>,
{
unimplemented!()
}

struct MyStruct;

fn main() {
to_string(&MyStruct);
let _: MyStruct = from_str("");
}
324 changes: 324 additions & 0 deletions test_suite/tests/ui/on_unimplemented.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
error[E0277]: the trait bound `MyStruct: Serialize` is not satisfied
--> tests/ui/on_unimplemented.rs:21:15
|
21 | to_string(&MyStruct);
| --------- ^^^^^^^^^ the trait `Serialize` is not implemented for `MyStruct`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Serialize`:
&'a T
&'a mut T
()
(T,)
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
(T0, T1, T2, T3, T4, T5)
(T0, T1, T2, T3, T4, T5, T6)
(T0, T1, T2, T3, T4, T5, T6, T7)
(T0, T1, T2, T3, T4, T5, T6, T7, T8)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
AdjacentlyTaggedEnumVariant
Arc<T>
Arguments<'a>
AtomicBool
AtomicI16
AtomicI32
AtomicI64
AtomicI8
AtomicIsize
AtomicU16
AtomicU32
AtomicU64
AtomicU8
AtomicUsize
BTreeMap<K, V>
BTreeSet<T>
BinaryHeap<T>
Bound<T>
Box<T>
CStr
CString
Cell<T>
Cow<'a, T>
Duration
HashMap<K, V, H>
HashSet<T, H>
IpAddr
Ipv4Addr
Ipv6Addr
LinkedList<T>
Mutex<T>
NonZero<i128>
NonZero<i16>
NonZero<i32>
NonZero<i64>
NonZero<i8>
NonZero<isize>
NonZero<u128>
NonZero<u16>
NonZero<u32>
NonZero<u64>
NonZero<u8>
NonZero<usize>
OsStr
OsString
Path
PathBuf
PhantomData<T>
RangeFrom<Idx>
RangeInclusive<Idx>
RangeTo<Idx>
Rc<T>
RefCell<T>
Result<T, E>
Reverse<T>
RwLock<T>
Saturating<T>
SocketAddrV4
SocketAddrV6
SystemTime
Vec<T>
VecDeque<T>
Wrapping<T>
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
[T; 16]
[T; 17]
[T; 18]
[T; 19]
[T; 1]
[T; 20]
[T; 21]
[T; 22]
[T; 23]
[T; 24]
[T; 25]
[T; 26]
[T; 27]
[T; 28]
[T; 29]
[T; 2]
[T; 30]
[T; 31]
[T; 32]
[T; 3]
[T; 4]
[T; 5]
[T; 6]
[T; 7]
[T; 8]
[T; 9]
[T]
bool
char
f32
f64
i128
i16
i32
i64
i8
isize
serde::__private::ser::content::Content
std::net::SocketAddr
std::ops::Range<Idx>
std::option::Option<T>
std::rc::Weak<T>
std::string::String
std::sync::Weak<T>
str
u128
u16
u32
u64
u8
usize
note: required by a bound in `to_string`
--> tests/ui/on_unimplemented.rs:6:8
|
4 | fn to_string<T>(_: &T) -> String
| --------- required by a bound in this function
5 | where
6 | T: Serialize,
| ^^^^^^^^^ required by this bound in `to_string`

error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied
--> tests/ui/on_unimplemented.rs:22:23
|
22 | let _: MyStruct = from_str("");
| ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a Path
&'a [u8]
&'a str
()
(T,)
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
(T0, T1, T2, T3, T4, T5)
(T0, T1, T2, T3, T4, T5, T6)
(T0, T1, T2, T3, T4, T5, T6, T7)
(T0, T1, T2, T3, T4, T5, T6, T7, T8)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
Arc<T>
AtomicBool
AtomicI16
AtomicI32
AtomicI64
AtomicI8
AtomicIsize
AtomicU16
AtomicU32
AtomicU64
AtomicU8
AtomicUsize
BTreeMap<K, V>
BTreeSet<T>
BinaryHeap<T>
Bound<T>
Box<CStr>
Box<OsStr>
Box<Path>
Box<T>
Box<[T]>
Box<str>
CString
Cell<T>
Cow<'a, T>
Duration
HashMap<K, V, S>
HashSet<T, S>
IgnoredAny
IpAddr
Ipv4Addr
Ipv6Addr
LinkedList<T>
Mutex<T>
NonZero<i128>
NonZero<i16>
NonZero<i32>
NonZero<i64>
NonZero<i8>
NonZero<isize>
NonZero<u128>
NonZero<u16>
NonZero<u32>
NonZero<u64>
NonZero<u8>
NonZero<usize>
OsString
PathBuf
PhantomData<T>
RangeFrom<Idx>
RangeInclusive<Idx>
RangeTo<Idx>
Rc<T>
RefCell<T>
Result<T, E>
Reverse<T>
RwLock<T>
Saturating<i128>
Saturating<i16>
Saturating<i32>
Saturating<i64>
Saturating<i8>
Saturating<isize>
Saturating<u128>
Saturating<u16>
Saturating<u32>
Saturating<u64>
Saturating<u8>
Saturating<usize>
SocketAddrV4
SocketAddrV6
SystemTime
Vec<T>
VecDeque<T>
Wrapping<T>
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
[T; 16]
[T; 17]
[T; 18]
[T; 19]
[T; 1]
[T; 20]
[T; 21]
[T; 22]
[T; 23]
[T; 24]
[T; 25]
[T; 26]
[T; 27]
[T; 28]
[T; 29]
[T; 2]
[T; 30]
[T; 31]
[T; 32]
[T; 3]
[T; 4]
[T; 5]
[T; 6]
[T; 7]
[T; 8]
[T; 9]
bool
char
f32
f64
i128
i16
i32
i64
i8
isize
serde::__private::de::content::Content<'de>
std::net::SocketAddr
std::ops::Range<Idx>
std::option::Option<T>
std::rc::Weak<T>
std::string::String
std::sync::Weak<T>
u128
u16
u32
u64
u8
usize
note: required by a bound in `from_str`
--> tests/ui/on_unimplemented.rs:13:8
|
11 | fn from_str<'de, T>(_: &'de str) -> T
| -------- required by a bound in this function
12 | where
13 | T: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `from_str`

0 comments on commit b2683ef

Please sign in to comment.