Skip to content

Commit f463e47

Browse files
authored
Rollup merge of #138782 - karolzwolak:where-test-91520, r=compiler-errors
test(ui): add tuple-struct-where-clause-suggestion ui test for #91520 Fixes #91520 I tried to also make it a .fixed test, but I failed to accomplish that. That's because of the 'consider annotating `Inner<T>` with `#[derive(Clone)]`' suggestion does not compile (conflicting Clone implementations), and I can't isolate them with `rustfix-only-machine-applicable` as both suggestions are not marked as `MachineApplicable`. Instead I just test that the where clause suggestion is applied to the correct line.
2 parents ca86dd5 + 2c77a07 commit f463e47

2 files changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Verify that the `where` clause suggestion is in the correct place
2+
// Previously, the suggestion to add `where` clause was placed inside the derive
3+
// like `#[derive(Clone where Inner<T>: Clone)]`
4+
// instead of `struct Outer<T>(Inner<T>) where Inner<T>: Clone`
5+
6+
#![crate_type = "lib"]
7+
8+
struct Inner<T>(T);
9+
//~^ HELP consider annotating `Inner<T>` with `#[derive(Clone)]`
10+
impl Clone for Inner<()> {
11+
fn clone(&self) -> Self { todo!() }
12+
}
13+
14+
#[derive(Clone)]
15+
struct Outer<T>(Inner<T>);
16+
//~^ ERROR the trait bound `Inner<T>: Clone` is not satisfied [E0277]
17+
//~| HELP consider introducing a `where` clause
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0277]: the trait bound `Inner<T>: Clone` is not satisfied
2+
--> $DIR/tuple-struct-where-clause-suggestion-91520.rs:15:17
3+
|
4+
LL | #[derive(Clone)]
5+
| ----- in this derive macro expansion
6+
LL | struct Outer<T>(Inner<T>);
7+
| ^^^^^^^^ the trait `Clone` is not implemented for `Inner<T>`
8+
|
9+
help: consider annotating `Inner<T>` with `#[derive(Clone)]`
10+
|
11+
LL + #[derive(Clone)]
12+
LL | struct Inner<T>(T);
13+
|
14+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
15+
|
16+
LL | struct Outer<T>(Inner<T>) where Inner<T>: Clone;
17+
| +++++++++++++++++++++
18+
19+
error: aborting due to 1 previous error
20+
21+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)