diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2021-02-16 11:02:39 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2021-02-17 09:26:40 -0800 |
| commit | 32c97da0f466ceff1512d62729c246a8e3951afe (patch) | |
| tree | 17c475bfa7ceba642638643a3277f3ae1567aa5d /src/test | |
| parent | 8fe989dd768f5dfdb0fc90933f3f74fa4579fefd (diff) | |
| download | rust-32c97da0f466ceff1512d62729c246a8e3951afe.tar.gz rust-32c97da0f466ceff1512d62729c246a8e3951afe.zip | |
In some limited cases, suggest `where` bounds for non-type params
Partially address #81971.
Diffstat (limited to 'src/test')
5 files changed, 21 insertions, 1 deletions
diff --git a/src/test/ui/partialeq_help.stderr b/src/test/ui/partialeq_help.stderr index 6decbef1af4..e14e17c1622 100644 --- a/src/test/ui/partialeq_help.stderr +++ b/src/test/ui/partialeq_help.stderr @@ -5,6 +5,10 @@ LL | a == b; | ^^ no implementation for `&T == T` | = help: the trait `PartialEq<T>` is not implemented for `&T` +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | fn foo<T: PartialEq>(a: &T, b: T) where &T: PartialEq<T> { + | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/specialization/deafult-associated-type-bound-2.stderr b/src/test/ui/specialization/deafult-associated-type-bound-2.stderr index 2bc14dbe3b2..0e8a774bce3 100644 --- a/src/test/ui/specialization/deafult-associated-type-bound-2.stderr +++ b/src/test/ui/specialization/deafult-associated-type-bound-2.stderr @@ -18,6 +18,10 @@ LL | default type U = &'static B; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&'static B == B` | = help: the trait `PartialEq<B>` is not implemented for `&'static B` +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | impl<B: 'static, T> X<B> for T where &'static B: PartialEq<B> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/suggestions/suggest-change-mut.rs b/src/test/ui/suggestions/suggest-change-mut.rs index 8b465aae66b..a2bc6fd09b5 100644 --- a/src/test/ui/suggestions/suggest-change-mut.rs +++ b/src/test/ui/suggestions/suggest-change-mut.rs @@ -2,7 +2,7 @@ use std::io::{BufRead, BufReader, Read, Write}; -fn issue_81421<T: Read + Write>(mut stream: T) { +fn issue_81421<T: Read + Write>(mut stream: T) { //~ HELP consider introducing a `where` bound let initial_message = format!("Hello world"); let mut buffer: Vec<u8> = Vec::new(); let bytes_written = stream.write_all(initial_message.as_bytes()); diff --git a/src/test/ui/suggestions/suggest-change-mut.stderr b/src/test/ui/suggestions/suggest-change-mut.stderr index cb156f7c787..9b8181647a0 100644 --- a/src/test/ui/suggestions/suggest-change-mut.stderr +++ b/src/test/ui/suggestions/suggest-change-mut.stderr @@ -9,6 +9,10 @@ help: consider removing the leading `&`-reference | LL | let mut stream_reader = BufReader::new(stream); | -- +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | fn issue_81421<T: Read + Write>(mut stream: T) where &T: std::io::Read { + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing this borrow's mutability | LL | let mut stream_reader = BufReader::new(&mut stream); diff --git a/src/test/ui/traits/suggest-where-clause.stderr b/src/test/ui/traits/suggest-where-clause.stderr index b50017afa4d..86d589ffa9e 100644 --- a/src/test/ui/traits/suggest-where-clause.stderr +++ b/src/test/ui/traits/suggest-where-clause.stderr @@ -35,6 +35,10 @@ LL | <u64 as From<T>>::from; | ^^^^^^^^^^^^^^^^^^^^^^ the trait `From<T>` is not implemented for `u64` | = note: required by `from` +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | fn check<T: Iterator, U: ?Sized>() where u64: From<T> { + | ^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `u64: From<<T as Iterator>::Item>` is not satisfied --> $DIR/suggest-where-clause.rs:18:5 @@ -43,6 +47,10 @@ LL | <u64 as From<<T as Iterator>::Item>>::from; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<<T as Iterator>::Item>` is not implemented for `u64` | = note: required by `from` +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | fn check<T: Iterator, U: ?Sized>() where u64: From<<T as Iterator>::Item> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Misc<_>: From<T>` is not satisfied --> $DIR/suggest-where-clause.rs:23:5 |
