Skip to content

Commit 942dde5

Browse files
committed
Don't suggest changing ret ty for trait methods
1 parent d8fb04e commit 942dde5

12 files changed

+2
-87
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1199,11 +1199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11991199

12001200
if let Some(local_did) = def_id.as_local()
12011201
&& let Some(node) = self.tcx.opt_hir_node(self.tcx.local_def_id_to_hir_id(local_did))
1202-
&& let hir::Node::TraitItem(hir::TraitItem {
1203-
kind: hir::TraitItemKind::Fn(sig, ..),
1204-
..
1205-
})
1206-
| hir::Node::ImplItem(hir::ImplItem {
1202+
&& let hir::Node::ImplItem(hir::ImplItem {
12071203
kind: hir::ImplItemKind::Fn(sig, ..), ..
12081204
})
12091205
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. }) = node

tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.rs:24:37
33
|
4-
LL | fn identify(&self) -> Self::Id;
5-
| -------- help: consider changing identify's return type: `&I`
6-
...
74
LL | let _low = self.lows.remove(low.identify()).unwrap();
85
| ------ ^^^^^^^^^^^^^^ expected `&I`, found associated type
96
| |

tests/ui/associated-types/associated-types-eq-3.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ help: consider constraining the associated type `<I as Foo>::A` to `Bar`
1717
|
1818
LL | fn foo2<I: Foo<A = Bar>>(x: I) {
1919
| +++++++++
20-
help: consider changing boo's return type
21-
|
22-
LL | fn boo(&self) -> Bar;
23-
| ~~~
2420

2521
error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
2622
--> $DIR/associated-types-eq-3.rs:38:10

tests/ui/impl-trait/equality2.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ help: consider constraining the associated type `<impl Foo as Leak>::T` to `i32`
5252
|
5353
LL | fn hide<T: Foo>(x: T) -> impl Foo<T = i32> {
5454
| +++++++++
55-
help: consider changing Leak's return type
56-
|
57-
LL | fn leak(self) -> i32;
58-
| ~~~
5955

6056
error[E0308]: mismatched types
6157
--> $DIR/equality2.rs:38:10

tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/opaque-in-impl-is-opaque.rs:14:19
33
|
4-
LL | fn bar(&self) -> impl Display;
5-
| ------------ help: consider changing bar's return type: `&str`
6-
...
74
LL | fn bar(&self) -> impl Display {
85
| ------------ the found opaque type
96
...

tests/ui/issues/issue-22684.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-22684.rs:17:17
33
|
4-
LL | fn bar(&self) -> bool { true }
5-
| ---- help: consider changing bar's return type: `()`
6-
...
74
LL | let _: () = foo::Foo.bar();
85
| -- ^^^^^^^^^^^^^^ expected `()`, found `bool`
96
| |

tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ help: you can convert an `isize` to a `usize` and panic if the converted value d
4545
|
4646
LL | let y: usize = x.foo().try_into().unwrap();
4747
| ++++++++++++++++++++
48-
help: consider changing foo's return type
49-
|
50-
LL | fn foo(&self) -> usize;
51-
| ~~~~~
5248

5349
error: aborting due to 3 previous errors
5450

tests/ui/specialization/specialization-default-types.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ LL | Box::new(self)
2424
error[E0308]: mismatched types
2525
--> $DIR/specialization-default-types.rs:25:5
2626
|
27-
LL | fn generate(self) -> Self::Output;
28-
| ------------ help: consider changing Example's return type: `Box<T>`
29-
...
3027
LL | fn trouble<T>(t: T) -> Box<T> {
3128
| ------ expected `Box<T>` because of return type
3229
LL | Example::generate(t)

tests/ui/suggestions/box-future-wrong-output.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/box-future-wrong-output.rs:20:39
33
|
4-
LL | fn boxed<'a>(self) -> BoxFuture<'a, Self::Output>
5-
| --------------------------- help: consider changing boxed's return type: `Pin<Box<(dyn Future<Output = bool> + Send + 'static)>>`
6-
...
74
LL | let _: BoxFuture<'static, bool> = async {}.boxed();
85
| ------------------------ ^^^^^^^^^^^^^^^^ expected `bool`, found `()`
96
| |

tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
trait Trait<T = Self> {
55
type A;
66

7-
fn func(&self) -> usize;
7+
fn func(&self) -> Self::A;
88
}
99

1010
struct S<T>(T);

tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr

-28
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ help: consider constraining the associated type `<impl Trait as Trait>::A` to `u
2222
|
2323
LL | fn foo<'a, T: Trait + 'a>(&self, _: impl Trait, x: impl Trait<A = usize>, _: T) {
2424
| +++++++++++
25-
help: consider changing func's return type
26-
|
27-
LL | fn func(&self) -> usize;
28-
| ~~~~~
2925

3026
error[E0308]: mismatched types
3127
--> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:17:13
@@ -51,10 +47,6 @@ help: consider constraining the associated type `<T as Trait>::A` to `usize`
5147
|
5248
LL | fn ban<T>(x: T) where T: Trait<A = usize> {
5349
| +++++++++++
54-
help: consider changing func's return type
55-
|
56-
LL | fn func(&self) -> usize;
57-
| ~~~~~
5850

5951
error[E0308]: mismatched types
6052
--> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:22:9
@@ -80,10 +72,6 @@ help: consider constraining the associated type `<impl Trait as Trait>::A` to `u
8072
|
8173
LL | fn foo<'a, T: Trait + 'a>(_: impl Trait, x: impl Trait<A = usize>, _: T) {
8274
| +++++++++++
83-
help: consider changing func's return type
84-
|
85-
LL | fn func(&self) -> usize;
86-
| ~~~~~
8775

8876
error[E0308]: mismatched types
8977
--> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:26:9
@@ -109,10 +97,6 @@ help: consider constraining the associated type `<T as Trait>::A` to `usize`
10997
|
11098
LL | fn bar<T: Trait<A = usize>>(x: T) {
11199
| +++++++++++
112-
help: consider changing func's return type
113-
|
114-
LL | fn func(&self) -> usize;
115-
| ~~~~~
116100

117101
error[E0308]: mismatched types
118102
--> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:30:9
@@ -138,10 +122,6 @@ help: consider constraining the associated type `<impl Trait<i32> as Trait<i32>>
138122
|
139123
LL | fn foo2(x: impl Trait<i32, A = usize>) {
140124
| +++++++++++
141-
help: consider changing func's return type
142-
|
143-
LL | fn func(&self) -> usize;
144-
| ~~~~~
145125

146126
error[E0308]: mismatched types
147127
--> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:34:9
@@ -167,10 +147,6 @@ help: consider constraining the associated type `<T as Trait<i32>>::A` to `usize
167147
|
168148
LL | fn bar2<T: Trait<i32, A = usize>>(x: T) {
169149
| +++++++++++
170-
help: consider changing func's return type
171-
|
172-
LL | fn func(&self) -> usize;
173-
| ~~~~~
174150

175151
error[E0308]: mismatched types
176152
--> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:38:9
@@ -196,10 +172,6 @@ help: consider constraining the associated type `<T as Trait>::A` to `usize`
196172
|
197173
LL | fn ban<T>(x: T) where T: Trait<A = usize> {
198174
| +++++++++++
199-
help: consider changing func's return type
200-
|
201-
LL | fn func(&self) -> usize;
202-
| ~~~~~
203175

204176
error: aborting due to 7 previous errors
205177

tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr

-26
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ help: consider constraining the associated type `<impl Trait as Trait>::A` to `u
3636
|
3737
LL | fn foo(_: impl Trait, x: impl Trait<A = usize>) {
3838
| +++++++++++
39-
help: consider changing func's return type
40-
|
41-
LL | fn func(&self) -> usize;
42-
| ~~~~~
4339

4440
error[E0308]: mismatched types
4541
--> $DIR/trait-with-missing-associated-type-restriction.rs:18:9
@@ -65,10 +61,6 @@ help: consider constraining the associated type `<T as Trait>::A` to `usize`
6561
|
6662
LL | fn bar<T: Trait<A = usize>>(x: T) {
6763
| +++++++++++
68-
help: consider changing func's return type
69-
|
70-
LL | fn func(&self) -> usize;
71-
| ~~~~~
7264

7365
error[E0308]: mismatched types
7466
--> $DIR/trait-with-missing-associated-type-restriction.rs:22:9
@@ -94,10 +86,6 @@ help: consider constraining the associated type `<impl Trait<i32> as Trait<i32>>
9486
|
9587
LL | fn foo2(x: impl Trait<i32, A = usize>) {
9688
| +++++++++++
97-
help: consider changing func's return type
98-
|
99-
LL | fn func(&self) -> usize;
100-
| ~~~~~
10189

10290
error[E0308]: mismatched types
10391
--> $DIR/trait-with-missing-associated-type-restriction.rs:26:12
@@ -151,17 +139,10 @@ help: consider constraining the associated type `<T as Trait<i32>>::A` to `usize
151139
|
152140
LL | fn bar2<T: Trait<i32, A = usize>>(x: T) {
153141
| +++++++++++
154-
help: consider changing func's return type
155-
|
156-
LL | fn func(&self) -> usize;
157-
| ~~~~~
158142

159143
error[E0308]: mismatched types
160144
--> $DIR/trait-with-missing-associated-type-restriction.rs:31:9
161145
|
162-
LL | fn func(&self) -> Self::A;
163-
| ------- help: consider changing func's return type: `usize`
164-
...
165146
LL | fn baz<D: std::fmt::Debug, T: Trait<A = D>>(x: T) {
166147
| - found this type parameter
167148
LL | qux(x.func())
@@ -185,9 +166,6 @@ LL | fn qux(_: usize) {}
185166
error[E0308]: mismatched types
186167
--> $DIR/trait-with-missing-associated-type-restriction.rs:35:9
187168
|
188-
LL | fn func(&self) -> Self::A;
189-
| ------- help: consider changing func's return type: `usize`
190-
...
191169
LL | qux(x.func())
192170
| --- ^^^^^^^^ expected `usize`, found `()`
193171
| |
@@ -228,10 +206,6 @@ help: consider constraining the associated type `<T as Trait>::A` to `usize`
228206
|
229207
LL | fn ban<T>(x: T) where T: Trait<A = usize> {
230208
| +++++++++++
231-
help: consider changing func's return type
232-
|
233-
LL | fn func(&self) -> usize;
234-
| ~~~~~
235209

236210
error: aborting due to 9 previous errors
237211

0 commit comments

Comments
 (0)