forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle
impl Trait
where Trait
has an assoc type with missing bounds
Fix rust-lang#69638.
- Loading branch information
Showing
3 changed files
with
208 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// The double space in `impl Iterator` is load bearing! We want to make sure we don't regress by | ||
// accident if the internal string representation changes. | ||
#[rustfmt::skip] | ||
fn foo(constraints: impl Iterator) { | ||
for constraint in constraints { | ||
qux(constraint); | ||
//~^ ERROR `<impl Iterator as std::iter::Iterator>::Item` doesn't implement `std::fmt::Debug` | ||
} | ||
} | ||
|
||
fn bar<T>(t: T, constraints: impl Iterator) where T: std::fmt::Debug { | ||
for constraint in constraints { | ||
qux(t); | ||
qux(constraint); | ||
//~^ ERROR `<impl Iterator as std::iter::Iterator>::Item` doesn't implement `std::fmt::Debug` | ||
} | ||
} | ||
|
||
fn baz(t: impl std::fmt::Debug, constraints: impl Iterator) { | ||
for constraint in constraints { | ||
qux(t); | ||
qux(constraint); | ||
//~^ ERROR `<impl Iterator as std::iter::Iterator>::Item` doesn't implement `std::fmt::Debug` | ||
} | ||
} | ||
|
||
fn qux(_: impl std::fmt::Debug) {} | ||
|
||
fn main() {} |
48 changes: 48 additions & 0 deletions
48
src/test/ui/suggestions/impl-trait-with-missing-bounds.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
error[E0277]: `<impl Iterator as std::iter::Iterator>::Item` doesn't implement `std::fmt::Debug` | ||
--> $DIR/impl-trait-with-missing-bounds.rs:6:13 | ||
| | ||
LL | qux(constraint); | ||
| ^^^^^^^^^^ `<impl Iterator as std::iter::Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | ||
... | ||
LL | fn qux(_: impl std::fmt::Debug) {} | ||
| --- --------------- required by this bound in `qux` | ||
| | ||
= help: the trait `std::fmt::Debug` is not implemented for `<impl Iterator as std::iter::Iterator>::Item` | ||
help: introduce a type parameter with a trait bound instead of using `impl Trait` | ||
| | ||
LL | fn foo<T: Iterator>(constraints: T) where <T as std::iter::Iterator>::Item: std::fmt::Debug { | ||
| ^^^^^^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `<impl Iterator as std::iter::Iterator>::Item` doesn't implement `std::fmt::Debug` | ||
--> $DIR/impl-trait-with-missing-bounds.rs:14:13 | ||
| | ||
LL | qux(constraint); | ||
| ^^^^^^^^^^ `<impl Iterator as std::iter::Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | ||
... | ||
LL | fn qux(_: impl std::fmt::Debug) {} | ||
| --- --------------- required by this bound in `qux` | ||
| | ||
= help: the trait `std::fmt::Debug` is not implemented for `<impl Iterator as std::iter::Iterator>::Item` | ||
help: introduce a type parameter with a trait bound instead of using `impl Trait` | ||
| | ||
LL | fn bar<T, T: Iterator>(t: T, constraints: T) where T: std::fmt::Debug, <T as std::iter::Iterator>::Item: std::fmt::Debug { | ||
| ^^^^^^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `<impl Iterator as std::iter::Iterator>::Item` doesn't implement `std::fmt::Debug` | ||
--> $DIR/impl-trait-with-missing-bounds.rs:22:13 | ||
| | ||
LL | qux(constraint); | ||
| ^^^^^^^^^^ `<impl Iterator as std::iter::Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | ||
... | ||
LL | fn qux(_: impl std::fmt::Debug) {} | ||
| --- --------------- required by this bound in `qux` | ||
| | ||
= help: the trait `std::fmt::Debug` is not implemented for `<impl Iterator as std::iter::Iterator>::Item` | ||
help: introduce a type parameter with a trait bound instead of using `impl Trait` | ||
| | ||
LL | fn baz<T: Iterator>(t: impl std::fmt::Debug, constraints: T) where <T as std::iter::Iterator>::Item: std::fmt::Debug { | ||
| ^^^^^^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |