Skip to content

Commit

Permalink
Don't suggest changing ret ty for trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwang05 committed Dec 27, 2023
1 parent d8fb04e commit 942dde5
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 87 deletions.
6 changes: 1 addition & 5 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if let Some(local_did) = def_id.as_local()
&& let Some(node) = self.tcx.opt_hir_node(self.tcx.local_def_id_to_hir_id(local_did))
&& let hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(sig, ..),
..
})
| hir::Node::ImplItem(hir::ImplItem {
&& let hir::Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Fn(sig, ..), ..
})
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. }) = node
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
error[E0308]: mismatched types
--> $DIR/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.rs:24:37
|
LL | fn identify(&self) -> Self::Id;
| -------- help: consider changing identify's return type: `&I`
...
LL | let _low = self.lows.remove(low.identify()).unwrap();
| ------ ^^^^^^^^^^^^^^ expected `&I`, found associated type
| |
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/associated-types/associated-types-eq-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ help: consider constraining the associated type `<I as Foo>::A` to `Bar`
|
LL | fn foo2<I: Foo<A = Bar>>(x: I) {
| +++++++++
help: consider changing boo's return type
|
LL | fn boo(&self) -> Bar;
| ~~~

error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
--> $DIR/associated-types-eq-3.rs:38:10
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/impl-trait/equality2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ help: consider constraining the associated type `<impl Foo as Leak>::T` to `i32`
|
LL | fn hide<T: Foo>(x: T) -> impl Foo<T = i32> {
| +++++++++
help: consider changing Leak's return type
|
LL | fn leak(self) -> i32;
| ~~~

error[E0308]: mismatched types
--> $DIR/equality2.rs:38:10
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
error[E0308]: mismatched types
--> $DIR/opaque-in-impl-is-opaque.rs:14:19
|
LL | fn bar(&self) -> impl Display;
| ------------ help: consider changing bar's return type: `&str`
...
LL | fn bar(&self) -> impl Display {
| ------------ the found opaque type
...
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/issues/issue-22684.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
error[E0308]: mismatched types
--> $DIR/issue-22684.rs:17:17
|
LL | fn bar(&self) -> bool { true }
| ---- help: consider changing bar's return type: `()`
...
LL | let _: () = foo::Foo.bar();
| -- ^^^^^^^^^^^^^^ expected `()`, found `bool`
| |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ help: you can convert an `isize` to a `usize` and panic if the converted value d
|
LL | let y: usize = x.foo().try_into().unwrap();
| ++++++++++++++++++++
help: consider changing foo's return type
|
LL | fn foo(&self) -> usize;
| ~~~~~

error: aborting due to 3 previous errors

Expand Down
3 changes: 0 additions & 3 deletions tests/ui/specialization/specialization-default-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ LL | Box::new(self)
error[E0308]: mismatched types
--> $DIR/specialization-default-types.rs:25:5
|
LL | fn generate(self) -> Self::Output;
| ------------ help: consider changing Example's return type: `Box<T>`
...
LL | fn trouble<T>(t: T) -> Box<T> {
| ------ expected `Box<T>` because of return type
LL | Example::generate(t)
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/suggestions/box-future-wrong-output.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
error[E0308]: mismatched types
--> $DIR/box-future-wrong-output.rs:20:39
|
LL | fn boxed<'a>(self) -> BoxFuture<'a, Self::Output>
| --------------------------- help: consider changing boxed's return type: `Pin<Box<(dyn Future<Output = bool> + Send + 'static)>>`
...
LL | let _: BoxFuture<'static, bool> = async {}.boxed();
| ------------------------ ^^^^^^^^^^^^^^^^ expected `bool`, found `()`
| |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
trait Trait<T = Self> {
type A;

fn func(&self) -> usize;
fn func(&self) -> Self::A;
}

struct S<T>(T);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ help: consider constraining the associated type `<impl Trait as Trait>::A` to `u
|
LL | fn foo<'a, T: Trait + 'a>(&self, _: impl Trait, x: impl Trait<A = usize>, _: T) {
| +++++++++++
help: consider changing func's return type
|
LL | fn func(&self) -> usize;
| ~~~~~

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

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

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

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

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

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

error: aborting due to 7 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ help: consider constraining the associated type `<impl Trait as Trait>::A` to `u
|
LL | fn foo(_: impl Trait, x: impl Trait<A = usize>) {
| +++++++++++
help: consider changing func's return type
|
LL | fn func(&self) -> usize;
| ~~~~~

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

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

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

error[E0308]: mismatched types
--> $DIR/trait-with-missing-associated-type-restriction.rs:31:9
|
LL | fn func(&self) -> Self::A;
| ------- help: consider changing func's return type: `usize`
...
LL | fn baz<D: std::fmt::Debug, T: Trait<A = D>>(x: T) {
| - found this type parameter
LL | qux(x.func())
Expand All @@ -185,9 +166,6 @@ LL | fn qux(_: usize) {}
error[E0308]: mismatched types
--> $DIR/trait-with-missing-associated-type-restriction.rs:35:9
|
LL | fn func(&self) -> Self::A;
| ------- help: consider changing func's return type: `usize`
...
LL | qux(x.func())
| --- ^^^^^^^^ expected `usize`, found `()`
| |
Expand Down Expand Up @@ -228,10 +206,6 @@ help: consider constraining the associated type `<T as Trait>::A` to `usize`
|
LL | fn ban<T>(x: T) where T: Trait<A = usize> {
| +++++++++++
help: consider changing func's return type
|
LL | fn func(&self) -> usize;
| ~~~~~

error: aborting due to 9 previous errors

Expand Down

0 comments on commit 942dde5

Please sign in to comment.