Skip to content
Myr

Merge pull request #2769 from dtolnay/onunimpl

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add ui test of unsatisfied serde trait bound

authored by David Tolnay · committed by GitHub · parents 595019e, 1179158 · Browse files · 2 files+78 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+78 added−0 removed

  • tests:+78 added−0 removed

2 files+78 added−0 removed

added:test_suite/tests/ui/on_unimplemented.rs+23 added
1use serde::de::Deserialize;2use serde::ser::Serialize;34fn to_string<T>(_: &T) -> String5where6 T: Serialize,7{8 unimplemented!()9}1011fn from_str<'de, T>(_: &'de str) -> T12where13 T: Deserialize<'de>,14{15 unimplemented!()16}1718struct MyStruct;1920fn main() {21 to_string(&MyStruct);22 let _: MyStruct = from_str("");23}
added:test_suite/tests/ui/on_unimplemented.stderr+55 added
1error[E0277]: the trait bound `MyStruct: Serialize` is not satisfied2 --> tests/ui/on_unimplemented.rs:21:153 |421 | to_string(&MyStruct);5 | --------- ^^^^^^^^^ the trait `Serialize` is not implemented for `MyStruct`6 | |7 | required by a bound introduced by this call8 |9 = note: for local types consider adding `#[derive(serde::Serialize)]` to your `MyStruct` type10 = note: for types from other crates check whether the crate offers a `serde` feature flag11 = help: the following other types implement trait `Serialize`:12 &'a T13 &'a mut T14 ()15 (T,)16 (T0, T1)17 (T0, T1, T2)18 (T0, T1, T2, T3)19 (T0, T1, T2, T3, T4)20 and $N others21note: required by a bound in `to_string`22 --> tests/ui/on_unimplemented.rs:6:823 |244 | fn to_string<T>(_: &T) -> String25 | --------- required by a bound in this function265 | where276 | T: Serialize,28 | ^^^^^^^^^ required by this bound in `to_string`2930error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied31 --> tests/ui/on_unimplemented.rs:22:2332 |3322 | let _: MyStruct = from_str("");34 | ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct`35 |36 = note: for local types consider adding `#[derive(serde::Deserialize)]` to your `MyStruct` type37 = note: for types from other crates check whether the crate offers a `serde` feature flag38 = help: the following other types implement trait `Deserialize<'de>`:39 &'a Path40 &'a [u8]41 &'a str42 ()43 (T,)44 (T0, T1)45 (T0, T1, T2)46 (T0, T1, T2, T3)47 and $N others48note: required by a bound in `from_str`49 --> tests/ui/on_unimplemented.rs:13:850 |5111 | fn from_str<'de, T>(_: &'de str) -> T52 | -------- required by a bound in this function5312 | where5413 | T: Deserialize<'de>,55 | ^^^^^^^^^^^^^^^^ required by this bound in `from_str`