Skip to content

Commit

Permalink
Unrolled build for rust-lang#127392
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#127392 - estebank:arg-type, r=jieyouxu

Use verbose suggestion for changing arg type
  • Loading branch information
rust-timer authored Jul 6, 2024
2 parents 51917e2 + 7569205 commit cb41705
Show file tree
Hide file tree
Showing 27 changed files with 206 additions and 163 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ fn report_trait_method_mismatch<'tcx>(
.next()
.unwrap_or(impl_err_span);

diag.span_suggestion(
diag.span_suggestion_verbose(
span,
"change the self-receiver type to match the trait",
sugg,
Expand All @@ -1005,12 +1005,12 @@ fn report_trait_method_mismatch<'tcx>(
}
hir::FnRetTy::Return(hir_ty) => {
let sugg = trait_sig.output();
diag.span_suggestion(hir_ty.span, msg, sugg, ap);
diag.span_suggestion_verbose(hir_ty.span, msg, sugg, ap);
}
};
};
} else if let Some(trait_ty) = trait_sig.inputs().get(*i) {
diag.span_suggestion(
diag.span_suggestion_verbose(
impl_err_span,
"change the parameter type to match the trait",
trait_ty,
Expand Down
18 changes: 10 additions & 8 deletions tests/ui/associated-types/defaults-specialization.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ error[E0053]: method `make` has an incompatible type for trait
--> $DIR/defaults-specialization.rs:19:18
|
LL | fn make() -> u8 { 0 }
| ^^
| |
| expected associated type, found `u8`
| help: change the output type to match the trait: `<A<T> as Tr>::Ty`
| ^^ expected associated type, found `u8`
|
note: type in trait
--> $DIR/defaults-specialization.rs:9:18
Expand All @@ -24,6 +21,10 @@ LL | fn make() -> Self::Ty {
| ^^^^^^^^
= note: expected signature `fn() -> <A<T> as Tr>::Ty`
found signature `fn() -> u8`
help: change the output type to match the trait
|
LL | fn make() -> <A<T> as Tr>::Ty { 0 }
| ~~~~~~~~~~~~~~~~

error[E0053]: method `make` has an incompatible type for trait
--> $DIR/defaults-specialization.rs:35:18
Expand All @@ -32,10 +33,7 @@ LL | default type Ty = bool;
| ----------------------- associated type is `default` and may be overridden
LL |
LL | fn make() -> bool { true }
| ^^^^
| |
| expected associated type, found `bool`
| help: change the output type to match the trait: `<B<T> as Tr>::Ty`
| ^^^^ expected associated type, found `bool`
|
note: type in trait
--> $DIR/defaults-specialization.rs:9:18
Expand All @@ -44,6 +42,10 @@ LL | fn make() -> Self::Ty {
| ^^^^^^^^
= note: expected signature `fn() -> <B<T> as Tr>::Ty`
found signature `fn() -> bool`
help: change the output type to match the trait
|
LL | fn make() -> <B<T> as Tr>::Ty { true }
| ~~~~~~~~~~~~~~~~

error[E0308]: mismatched types
--> $DIR/defaults-specialization.rs:10:9
Expand Down
18 changes: 10 additions & 8 deletions tests/ui/compare-method/bad-self-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ error[E0053]: method `poll` has an incompatible type for trait
--> $DIR/bad-self-type.rs:10:13
|
LL | fn poll(self, _: &mut Context<'_>) -> Poll<()> {
| ^^^^
| |
| expected `Pin<&mut MyFuture>`, found `MyFuture`
| help: change the self-receiver type to match the trait: `self: Pin<&mut MyFuture>`
| ^^^^ expected `Pin<&mut MyFuture>`, found `MyFuture`
|
= note: expected signature `fn(Pin<&mut MyFuture>, &mut Context<'_>) -> Poll<_>`
found signature `fn(MyFuture, &mut Context<'_>) -> Poll<_>`
help: change the self-receiver type to match the trait
|
LL | fn poll(self: Pin<&mut MyFuture>, _: &mut Context<'_>) -> Poll<()> {
| ~~~~~~~~~~~~~~~~~~~~~~~~

error[E0053]: method `foo` has an incompatible type for trait
--> $DIR/bad-self-type.rs:22:18
|
LL | fn foo(self: Box<Self>) {}
| ------^^^^^^^^^
| | |
| | expected `MyFuture`, found `Box<MyFuture>`
| help: change the self-receiver type to match the trait: `self`
| ^^^^^^^^^ expected `MyFuture`, found `Box<MyFuture>`
|
note: type in trait
--> $DIR/bad-self-type.rs:17:12
Expand All @@ -26,6 +24,10 @@ LL | fn foo(self);
| ^^^^
= note: expected signature `fn(MyFuture)`
found signature `fn(Box<MyFuture>)`
help: change the self-receiver type to match the trait
|
LL | fn foo(self) {}
| ~~~~

error[E0053]: method `bar` has an incompatible type for trait
--> $DIR/bad-self-type.rs:24:17
Expand Down
18 changes: 10 additions & 8 deletions tests/ui/compare-method/issue-90444.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ error[E0053]: method `from` has an incompatible type for trait
--> $DIR/issue-90444.rs:3:16
|
LL | fn from(_: fn((), (), &mut ())) -> Self {
| ^^^^^^^^^^^^^^^^^^^
| |
| types differ in mutability
| help: change the parameter type to match the trait: `for<'a> fn((), (), &'a ())`
| ^^^^^^^^^^^^^^^^^^^ types differ in mutability
|
= note: expected signature `fn(for<'a> fn((), (), &'a ())) -> A`
found signature `fn(for<'a> fn((), (), &'a mut ())) -> A`
help: change the parameter type to match the trait
|
LL | fn from(_: for<'a> fn((), (), &'a ())) -> Self {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0053]: method `from` has an incompatible type for trait
--> $DIR/issue-90444.rs:11:16
|
LL | fn from(_: fn((), (), u64)) -> Self {
| ^^^^^^^^^^^^^^^
| |
| expected `u32`, found `u64`
| help: change the parameter type to match the trait: `fn((), (), u32)`
| ^^^^^^^^^^^^^^^ expected `u32`, found `u64`
|
= note: expected signature `fn(fn((), (), u32)) -> B`
found signature `fn(fn((), (), u64)) -> B`
help: change the parameter type to match the trait
|
LL | fn from(_: fn((), (), u32)) -> Self {
| ~~~~~~~~~~~~~~~

error: aborting due to 2 previous errors

Expand Down
10 changes: 6 additions & 4 deletions tests/ui/compare-method/reordered-type-param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ error[E0053]: method `b` has an incompatible type for trait
--> $DIR/reordered-type-param.rs:16:30
|
LL | fn b<F:Clone,G>(&self, _x: G) -> G { panic!() }
| - - ^
| | | |
| | | expected type parameter `F`, found type parameter `G`
| | | help: change the parameter type to match the trait: `F`
| - - ^ expected type parameter `F`, found type parameter `G`
| | |
| | found type parameter
| expected type parameter
|
Expand All @@ -18,6 +16,10 @@ LL | fn b<C:Clone,D>(&self, x: C) -> C;
found signature `fn(&E, G) -> G`
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
help: change the parameter type to match the trait
|
LL | fn b<F:Clone,G>(&self, _x: F) -> G { panic!() }
| ~

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ error[E0053]: method `call` has an incompatible type for trait
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:13:32
|
LL | extern "rust-call" fn call(self, args: ()) -> () {}
| ^^^^
| |
| expected `&Foo`, found `Foo`
| help: change the self-receiver type to match the trait: `&self`
| ^^^^ expected `&Foo`, found `Foo`
|
= note: expected signature `extern "rust-call" fn(&Foo, ()) -> _`
found signature `extern "rust-call" fn(Foo, ())`
help: change the self-receiver type to match the trait
|
LL | extern "rust-call" fn call(&self, args: ()) -> () {}
| ~~~~~

error[E0183]: manual implementations of `FnOnce` are experimental
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:18:6
Expand Down Expand Up @@ -158,13 +159,14 @@ error[E0053]: method `call_mut` has an incompatible type for trait
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:30:36
|
LL | extern "rust-call" fn call_mut(&self, args: ()) -> () {}
| ^^^^^
| |
| types differ in mutability
| help: change the self-receiver type to match the trait: `&mut self`
| ^^^^^ types differ in mutability
|
= note: expected signature `extern "rust-call" fn(&mut Bar, ()) -> _`
found signature `extern "rust-call" fn(&Bar, ())`
help: change the self-receiver type to match the trait
|
LL | extern "rust-call" fn call_mut(&mut self, args: ()) -> () {}
| ~~~~~~~~~

error[E0046]: not all trait items implemented, missing: `Output`
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:35:1
Expand Down
10 changes: 6 additions & 4 deletions tests/ui/impl-trait/impl-generic-mismatch-ab.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ error[E0053]: method `foo` has an incompatible type for trait
--> $DIR/impl-generic-mismatch-ab.rs:8:32
|
LL | fn foo<B: Debug>(&self, a: &impl Debug, b: &B) { }
| - ^^^^^^^^^^^
| | |
| | expected type parameter `B`, found type parameter `impl Debug`
| | help: change the parameter type to match the trait: `&B`
| - ^^^^^^^^^^^ expected type parameter `B`, found type parameter `impl Debug`
| |
| expected type parameter
|
note: type in trait
Expand All @@ -17,6 +15,10 @@ LL | fn foo<A: Debug>(&self, a: &A, b: &impl Debug);
found signature `fn(&(), &impl Debug, &B)`
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
help: change the parameter type to match the trait
|
LL | fn foo<B: Debug>(&self, a: &B, b: &B) { }
| ~~

error: aborting due to 1 previous error

Expand Down
9 changes: 5 additions & 4 deletions tests/ui/impl-trait/in-assoc-type-unconstrained.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ LL | type Ty = impl Sized;
| ---------- the expected opaque type
LL |
LL | fn method() -> () {}
| ^^
| |
| expected opaque type, found `()`
| help: change the output type to match the trait: `<() as compare_method::Trait>::Ty`
| ^^ expected opaque type, found `()`
|
note: type in trait
--> $DIR/in-assoc-type-unconstrained.rs:17:24
Expand All @@ -44,6 +41,10 @@ note: this item must have the opaque type in its signature in order to be able t
|
LL | fn method() -> () {}
| ^^^^^^
help: change the output type to match the trait
|
LL | fn method() -> <() as compare_method::Trait>::Ty {}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: unconstrained opaque type
--> $DIR/in-assoc-type-unconstrained.rs:20:19
Expand Down
10 changes: 6 additions & 4 deletions tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ error[E0053]: method `early` has an incompatible type for trait
--> $DIR/method-signature-matches.rs:55:27
|
LL | fn early<'late, T>(_: &'late ()) {}
| - ^^^^^^^^^
| | |
| | expected type parameter `T`, found `()`
| | help: change the parameter type to match the trait: `&T`
| - ^^^^^^^^^ expected type parameter `T`, found `()`
| |
| expected this type parameter
|
note: type in trait
Expand All @@ -15,6 +13,10 @@ LL | fn early<'early, T>(x: &'early T) -> impl Sized;
| ^^^^^^^^^
= note: expected signature `fn(&T)`
found signature `fn(&'late ())`
help: change the parameter type to match the trait
|
LL | fn early<'late, T>(_: &T) {}
| ~~

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0053]: method `owo` has an incompatible type for trait
--> $DIR/method-signature-matches.rs:11:15
|
LL | fn owo(_: u8) {}
| ^^
| |
| expected `()`, found `u8`
| help: change the parameter type to match the trait: `()`
| ^^ expected `()`, found `u8`
|
note: type in trait
--> $DIR/method-signature-matches.rs:6:15
Expand All @@ -14,6 +11,10 @@ LL | fn owo(x: ()) -> impl Sized;
| ^^
= note: expected signature `fn(())`
found signature `fn(u8)`
help: change the parameter type to match the trait
|
LL | fn owo(_: ()) {}
| ~~

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0053]: method `owo` has an incompatible type for trait
--> $DIR/method-signature-matches.rs:22:21
|
LL | async fn owo(_: u8) {}
| ^^
| |
| expected `()`, found `u8`
| help: change the parameter type to match the trait: `()`
| ^^ expected `()`, found `u8`
|
note: type in trait
--> $DIR/method-signature-matches.rs:17:21
Expand All @@ -14,6 +11,10 @@ LL | async fn owo(x: ()) {}
| ^^
= note: expected signature `fn(()) -> _`
found signature `fn(u8) -> _`
help: change the parameter type to match the trait
|
LL | async fn owo(_: ()) {}
| ~~

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ error[E0053]: method `bar` has an incompatible type for trait
--> $DIR/opaque-and-lifetime-mismatch.rs:10:17
|
LL | fn bar() -> i32 {
| ^^^
| |
| expected `Wrapper<'static>`, found `i32`
| help: change the output type to match the trait: `Wrapper<'static>`
| ^^^ expected `Wrapper<'static>`, found `i32`
|
note: type in trait
--> $DIR/opaque-and-lifetime-mismatch.rs:4:17
Expand All @@ -87,6 +84,10 @@ LL | fn bar() -> Wrapper<impl Sized>;
| ^^^^^^^^^^^^^^^^^^^
= note: expected signature `fn() -> Wrapper<'static>`
found signature `fn() -> i32`
help: change the output type to match the trait
|
LL | fn bar() -> Wrapper<'static> {
| ~~~~~~~~~~~~~~~~

error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/opaque-and-lifetime-mismatch.rs:24:17
Expand Down
9 changes: 5 additions & 4 deletions tests/ui/impl-trait/in-trait/specialization-broken.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ LL | default impl<U> Foo for U
| - found this type parameter
...
LL | fn bar(&self) -> U {
| ^
| |
| expected associated type, found type parameter `U`
| help: change the output type to match the trait: `impl Sized`
| ^ expected associated type, found type parameter `U`
|
note: type in trait
--> $DIR/specialization-broken.rs:8:22
Expand All @@ -17,6 +14,10 @@ LL | fn bar(&self) -> impl Sized;
| ^^^^^^^^^^
= note: expected signature `fn(&_) -> impl Sized`
found signature `fn(&_) -> U`
help: change the output type to match the trait
|
LL | fn bar(&self) -> impl Sized {
| ~~~~~~~~~~

error: method with return-position `impl Trait` in trait cannot be specialized
--> $DIR/specialization-broken.rs:15:5
Expand Down
Loading

0 comments on commit cb41705

Please sign in to comment.