From ec037a4b39aef24a02020a7361fb3f5187a4c504 Mon Sep 17 00:00:00 2001 From: sjwang05 <63834813+sjwang05@users.noreply.github.com> Date: Mon, 25 Dec 2023 23:33:00 -0800 Subject: [PATCH 1/3] Point at fn definition on type mismatch involving call --- compiler/rustc_hir_typeck/src/demand.rs | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 6e5bd740b2ee4..f6ef97e9583cd 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -94,6 +94,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.suggest_method_call_on_range_literal(err, expr, expr_ty, expected); self.suggest_return_binding_for_missing_tail_expr(err, expr, expr_ty, expected); self.note_wrong_return_ty_due_to_generic_arg(err, expr, expr_ty); + self.note_fn_method_def_due_to_call(err, expr, expected); } /// Really hacky heuristic to remap an `assert_eq!` error to the user @@ -1170,6 +1171,56 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => return, } } + + fn note_fn_method_def_due_to_call( + &self, + err: &mut Diagnostic, + expr: &hir::Expr<'_>, + expected: Ty<'_>, + ) { + let (def_id, ident, callee_str) = if let hir::ExprKind::Call(fun, _) = expr.kind + && let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = fun.kind + && let hir::def::Res::Def(def_kind, def_id) = path.res + && !matches!(def_kind, hir::def::DefKind::Ctor(..)) + { + (def_id, path.segments[0].ident, "function") + } else if let hir::ExprKind::MethodCall(method, ..) = expr.kind + && let Some(def_id) = self.typeck_results.borrow().type_dependent_def_id(expr.hir_id) + && !matches!(self.tcx.def_kind(def_id), hir::def::DefKind::Ctor(..)) + { + (def_id, method.ident, "method") + } else { + return; + }; + err.span_note( + self.tcx.def_span(def_id), + format!("the {callee_str} {ident} is defined here"), + ); + + 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 { + kind: hir::ImplItemKind::Fn(sig, ..), .. + }) + | hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. }) = node + && let ret_span = sig.decl.output.span() + && !ret_span.from_expansion() + && expected.has_concrete_skeleton() + { + let sugg = + if ret_span.is_empty() { format!("-> {expected}") } else { format!("{expected}") }; + err.span_suggestion( + ret_span, + format!("consider changing {ident}'s return type"), + sugg, + Applicability::MaybeIncorrect, + ); + } + } } pub enum TypeMismatchSource<'tcx> { From d8fb04e194c4d783dc84bf124b9055699fb13626 Mon Sep 17 00:00:00 2001 From: sjwang05 <63834813+sjwang05@users.noreply.github.com> Date: Tue, 26 Dec 2023 14:42:14 -0800 Subject: [PATCH 2/3] Bless test output --- tests/incremental/circular-dependencies.rs | 5 +- ...alloc-error-handler-bad-signature-1.stderr | 12 +++- ...alloc-error-handler-bad-signature-2.stderr | 11 +++- ...or-type-param-of-current-assoc-item.stderr | 8 +++ .../ui/associated-type-bounds/elision.stderr | 2 + .../associated-types-eq-3.stderr | 9 +++ .../associated-types-path-2.stderr | 9 +++ tests/ui/async-await/coroutine-desc.stderr | 5 ++ .../ui/async-await/issues/issue-102206.stderr | 5 ++ .../async-await/suggest-missing-await.stderr | 5 ++ .../unexpected-return-on-unit.stderr | 9 +++ .../add_semicolon_non_block_closure.rs | 2 +- .../add_semicolon_non_block_closure.stderr | 9 +++ tests/ui/coercion/retslot-cast.stderr | 9 +++ .../occurs-check/unify-n-nplusone.stderr | 9 +++ .../occurs-check/unused-substs-4.stderr | 9 +++ .../occurs-check/unused-substs-5.stderr | 6 ++ tests/ui/did_you_mean/compatible-variants.rs | 1 + .../did_you_mean/compatible-variants.stderr | 35 +++++++---- tests/ui/diverging-fn-tail-35849.stderr | 2 + tests/ui/impl-trait/equality2.stderr | 19 +++++- .../in-trait/opaque-in-impl-is-opaque.stderr | 8 +++ tests/ui/impl-trait/issue-102605.stderr | 5 ++ tests/ui/impl-trait/issue-99914.stderr | 5 ++ tests/ui/impl-trait/printing-binder.stderr | 20 +++++- .../suggest-calling-rpit-closure.stderr | 9 +++ tests/ui/inference/array-len-mismatch.rs | 2 +- tests/ui/inference/array-len-mismatch.stderr | 17 ++++- tests/ui/issues/issue-22684.stderr | 9 +++ tests/ui/issues/issue-47486.stderr | 3 + tests/ui/issues/issue-61106.stderr | 2 + tests/ui/lifetimes/issue-26638.stderr | 2 + ...od-ambig-one-trait-unknown-int-type.stderr | 9 +++ tests/ui/mismatched_types/issue-84976.stderr | 36 +++++++++++ .../mismatch-ty-unwrap-expect.fixed | 31 --------- .../mismatch-ty-unwrap-expect.rs | 1 - .../mismatch-ty-unwrap-expect.stderr | 21 +++++-- ...ne-call-on-ref-due-to-missing-bound.stderr | 2 + tests/ui/noexporttypeexe.stderr | 5 ++ tests/ui/numeric/len.stderr | 2 + tests/ui/numeric/numeric-cast-2.stderr | 9 +++ tests/ui/parser/expr-as-stmt.stderr | 18 +++++- ...ssue-82612-return-mutable-reference.stderr | 2 + tests/ui/return/return-type.stderr | 9 +++ .../specialization-default-projection.stderr | 17 ++++- .../specialization-default-types.stderr | 8 +++ .../box-future-wrong-output.stderr | 10 +++ ...chain-method-call-mutation-in-place.stderr | 4 ++ ...n-unconstrained-borrowed-type-param.stderr | 4 ++ tests/ui/suggestions/copied-and-cloned.stderr | 2 + tests/ui/suggestions/issue-105494.stderr | 9 +++ tests/ui/suggestions/issue-117669.stderr | 3 + tests/ui/suggestions/issue-52820.stderr | 3 + tests/ui/suggestions/issue-53692.stderr | 5 ++ tests/ui/suggestions/issue-81839.stderr | 5 ++ .../issue-86100-tuple-paren-comma.stderr | 2 + .../ui/suggestions/match-needing-semi.stderr | 9 +++ .../match-prev-arm-needing-semi.rs | 5 ++ .../match-prev-arm-needing-semi.stderr | 47 +++++++++++--- ...-associated-type-restriction-fixable.fixed | 2 +- ...associated-type-restriction-fixable.stderr | 63 +++++++++++++++++++ ...missing-associated-type-restriction.stderr | 61 ++++++++++++++++++ .../try-operator-dont-suggest-semicolon.rs | 2 + ...try-operator-dont-suggest-semicolon.stderr | 18 +++++- tests/ui/tail-typeck.stderr | 9 +++ ...estrict-assoc-type-of-generic-bound.stderr | 5 ++ tests/ui/traits/issue-68295.stderr | 10 +++ ...o_revealing_outside_defining_module.stderr | 8 +++ .../normalize-hidden-types.current.stderr | 8 +++ tests/ui/typeck/deref-multi.stderr | 2 + tests/ui/typeck/explain_clone_autoref.rs | 2 + tests/ui/typeck/explain_clone_autoref.stderr | 48 +++++++------- ...2007-leaked-writeln-macro-internals.stderr | 4 ++ tests/ui/typeck/issue-13853.stderr | 2 + .../typeck/issue-50687-ice-on-borrow.stderr | 2 + tests/ui/typeck/issue-81943.stderr | 23 +++++++ tests/ui/typeck/issue-89275.stderr | 8 +++ ...ue-90027-async-fn-return-suggestion.stderr | 5 ++ tests/ui/typeck/output-type-mismatch.stderr | 9 +++ .../ptr-null-mutability-suggestions.stderr | 2 + .../typeck/return_type_containing_closure.rs | 1 + .../return_type_containing_closure.stderr | 2 + .../tag-that-dare-not-speak-its-name.stderr | 9 +++ 83 files changed, 742 insertions(+), 104 deletions(-) delete mode 100644 tests/ui/mismatched_types/mismatch-ty-unwrap-expect.fixed diff --git a/tests/incremental/circular-dependencies.rs b/tests/incremental/circular-dependencies.rs index 10673066a9df0..dc118bf870692 100644 --- a/tests/incremental/circular-dependencies.rs +++ b/tests/incremental/circular-dependencies.rs @@ -14,7 +14,7 @@ pub struct Foo; pub fn consume_foo(_: Foo) {} //[cfail2]~^ NOTE function defined here -pub fn produce_foo() -> Foo { +pub fn produce_foo() -> Foo { //[cfail2]~ NOTE the function produce_foo is defined here Foo } @@ -28,10 +28,11 @@ fn test() { //[cfail2]~| NOTE the crate `circular_dependencies` is compiled multiple times, possibly with different configurations //[cfail2]~| NOTE function defined here - consume_foo(aux::produce_foo()); + consume_foo(aux::produce_foo()); // //[cfail2]~^ ERROR mismatched types [E0308] //[cfail2]~| NOTE expected `Foo`, found `circular_dependencies::Foo` //[cfail2]~| NOTE arguments to this function are incorrect //[cfail2]~| NOTE `circular_dependencies::Foo` and `Foo` have similar names, but are actually distinct types //[cfail2]~| NOTE the crate `circular_dependencies` is compiled multiple times, possibly with different configurations + //[cfail2]~| NOTE the function aux is defined here } diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr b/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr index de92841d7f18e..fa00f4abbe9bc 100644 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr +++ b/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr @@ -29,7 +29,10 @@ LL | #[alloc_error_handler] LL | // fn oom( LL | || info: &Layout, LL | || ) -> () - | ||_______^ expected `!`, found `()` + | || -^ + | ||______|| + | | |expected `!`, found `()` + | | help: consider changing oom's return type: `!` LL | | { LL | | loop {} LL | | } @@ -37,6 +40,13 @@ LL | | } | = note: expected type `!` found unit type `()` +note: the function oom is defined here + --> $DIR/alloc-error-handler-bad-signature-1.rs:10:1 + | +LL | / fn oom( +LL | | info: &Layout, +LL | | ) -> () + | |_______^ = note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr b/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr index 7a495380f2ba1..178ac9dee200c 100644 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr +++ b/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr @@ -36,13 +36,22 @@ LL | #[alloc_error_handler] LL | // fn oom( LL | || info: Layout, LL | || ) { - | ||_^ expected `!`, found `()` + | || ^- help: consider changing oom's return type: `-> !` + | ||_| + | | expected `!`, found `()` LL | | loop {} LL | | } | |__- expected `!` because of return type | = note: expected type `!` found unit type `()` +note: the function oom is defined here + --> $DIR/alloc-error-handler-bad-signature-2.rs:10:1 + | +LL | / fn oom( +LL | | info: Layout, +LL | | ) { + | |_^ = note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr b/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr index 1f99d7db0b024..96bca643ae28b 100644 --- a/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr +++ b/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr @@ -1,6 +1,9 @@ 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 | | @@ -10,6 +13,11 @@ LL | let _low = self.lows.remove(low.identify()).unwrap(); found associated type `::Id` = help: consider constraining the associated type `::Id` to `&I` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: the method identify is defined here + --> $DIR/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.rs:8:5 + | +LL | fn identify(&self) -> Self::Id; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: method defined here --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL diff --git a/tests/ui/associated-type-bounds/elision.stderr b/tests/ui/associated-type-bounds/elision.stderr index a29e32a784fe4..8152415e492f0 100644 --- a/tests/ui/associated-type-bounds/elision.stderr +++ b/tests/ui/associated-type-bounds/elision.stderr @@ -21,6 +21,8 @@ LL | fn f(x: &mut dyn Iterator>) -> Option<&'_ ()> | = note: expected enum `Option<&()>` found enum `Option>` +note: the method next is defined here + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL error: aborting due to 2 previous errors diff --git a/tests/ui/associated-types/associated-types-eq-3.stderr b/tests/ui/associated-types/associated-types-eq-3.stderr index c3377eed20a52..78a9662187a1d 100644 --- a/tests/ui/associated-types/associated-types-eq-3.stderr +++ b/tests/ui/associated-types/associated-types-eq-3.stderr @@ -8,10 +8,19 @@ LL | let _: Bar = x.boo(); | = note: expected struct `Bar` found associated type `::A` +note: the method boo is defined here + --> $DIR/associated-types-eq-3.rs:6:5 + | +LL | fn boo(&self) -> ::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider constraining the associated type `::A` to `Bar` | LL | fn foo2>(x: I) { | +++++++++ +help: consider changing boo's return type + | +LL | fn boo(&self) -> Bar; + | ~~~ error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:38:10 diff --git a/tests/ui/associated-types/associated-types-path-2.stderr b/tests/ui/associated-types/associated-types-path-2.stderr index 206f490241026..5b7871c1bb9aa 100644 --- a/tests/ui/associated-types/associated-types-path-2.stderr +++ b/tests/ui/associated-types/associated-types-path-2.stderr @@ -86,10 +86,19 @@ LL | let _: i32 = f2(2i32); | | | expected due to this | +note: the function f2 is defined here + --> $DIR/associated-types-path-2.rs:14:1 + | +LL | pub fn f2(a: T) -> T::A { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit | LL | let _: i32 = f2(2i32).try_into().unwrap(); | ++++++++++++++++++++ +help: consider changing f2's return type + | +LL | pub fn f2(a: T) -> i32 { + | ~~~ error: aborting due to 8 previous errors diff --git a/tests/ui/async-await/coroutine-desc.stderr b/tests/ui/async-await/coroutine-desc.stderr index e4cb0915a1090..15d49c202b778 100644 --- a/tests/ui/async-await/coroutine-desc.stderr +++ b/tests/ui/async-await/coroutine-desc.stderr @@ -25,6 +25,11 @@ LL | fun(one(), two()); | = help: consider `await`ing on both `Future`s = note: distinct uses of `impl Trait` result in different opaque types +note: the function two is defined here + --> $DIR/coroutine-desc.rs:6:1 + | +LL | async fn two() {} + | ^^^^^^^^^^^^^^ note: function defined here --> $DIR/coroutine-desc.rs:8:4 | diff --git a/tests/ui/async-await/issues/issue-102206.stderr b/tests/ui/async-await/issues/issue-102206.stderr index 19c70e8743a17..1bdb2abd686c8 100644 --- a/tests/ui/async-await/issues/issue-102206.stderr +++ b/tests/ui/async-await/issues/issue-102206.stderr @@ -6,6 +6,11 @@ LL | std::mem::size_of_val(foo()); | | | arguments to this function are incorrect | +note: the function foo is defined here + --> $DIR/issue-102206.rs:3:1 + | +LL | async fn foo() {} + | ^^^^^^^^^^^^^^ note: function defined here --> $SRC_DIR/core/src/mem/mod.rs:LL:COL help: consider borrowing here diff --git a/tests/ui/async-await/suggest-missing-await.stderr b/tests/ui/async-await/suggest-missing-await.stderr index f0ec34a6a5557..57916c76f2e77 100644 --- a/tests/ui/async-await/suggest-missing-await.stderr +++ b/tests/ui/async-await/suggest-missing-await.stderr @@ -32,6 +32,11 @@ note: calling an async function returns a future | LL | dummy() | ^^^^^^^ +note: the function dummy is defined here + --> $DIR/suggest-missing-await.rs:18:1 + | +LL | async fn dummy() {} + | ^^^^^^^^^^^^^^^^ help: consider `await`ing on the `Future` | LL | dummy().await diff --git a/tests/ui/block-result/unexpected-return-on-unit.stderr b/tests/ui/block-result/unexpected-return-on-unit.stderr index 0b79cf0da2a69..0c8e73e6c7304 100644 --- a/tests/ui/block-result/unexpected-return-on-unit.stderr +++ b/tests/ui/block-result/unexpected-return-on-unit.stderr @@ -4,6 +4,11 @@ error[E0308]: mismatched types LL | foo() | ^^^^^ expected `()`, found `usize` | +note: the function foo is defined here + --> $DIR/unexpected-return-on-unit.rs:4:1 + | +LL | fn foo() -> usize { + | ^^^^^^^^^^^^^^^^^ help: consider using a semicolon here | LL | foo(); @@ -12,6 +17,10 @@ help: try adding a return type | LL | fn bar() -> usize { | ++++++++ +help: consider changing foo's return type + | +LL | fn foo() -> () { + | ~~ error: aborting due to 1 previous error diff --git a/tests/ui/closures/add_semicolon_non_block_closure.rs b/tests/ui/closures/add_semicolon_non_block_closure.rs index 3ae91be60c5a0..9071c0fc6b9ea 100644 --- a/tests/ui/closures/add_semicolon_non_block_closure.rs +++ b/tests/ui/closures/add_semicolon_non_block_closure.rs @@ -1,6 +1,6 @@ fn foo(_f: impl Fn()) {} -fn bar() -> i32 { +fn bar() -> i32 { //~ HELP consider changing bar's return type 1 } diff --git a/tests/ui/closures/add_semicolon_non_block_closure.stderr b/tests/ui/closures/add_semicolon_non_block_closure.stderr index d095e59c7ebb0..47ca56b5c254d 100644 --- a/tests/ui/closures/add_semicolon_non_block_closure.stderr +++ b/tests/ui/closures/add_semicolon_non_block_closure.stderr @@ -6,10 +6,19 @@ LL | fn main() { LL | foo(|| bar()) | ^^^^^ expected `()`, found `i32` | +note: the function bar is defined here + --> $DIR/add_semicolon_non_block_closure.rs:3:1 + | +LL | fn bar() -> i32 { + | ^^^^^^^^^^^^^^^ help: consider using a semicolon here | LL | foo(|| { bar(); }) | + +++ +help: consider changing bar's return type + | +LL | fn bar() -> () { + | ~~ error: aborting due to 1 previous error diff --git a/tests/ui/coercion/retslot-cast.stderr b/tests/ui/coercion/retslot-cast.stderr index dac21a7f25b2b..5e57d95e5ad7b 100644 --- a/tests/ui/coercion/retslot-cast.stderr +++ b/tests/ui/coercion/retslot-cast.stderr @@ -6,9 +6,18 @@ LL | -> Option<&Iterator> { ... LL | inner(x) | ^^^^^^^^ expected trait `Iterator`, found trait `Iterator + Send` +... +LL | -> Option<&(Iterator+Send)> { + | --------------------------------- help: consider changing inner's return type: `Option<&dyn Iterator>` | = note: expected enum `Option<&dyn Iterator>` found enum `Option<&dyn Iterator + Send>` +note: the function inner is defined here + --> $DIR/retslot-cast.rs:16:1 + | +LL | / pub fn inner(x: Option<&(Iterator+Send)>) +LL | | -> Option<&(Iterator+Send)> { + | |_________________________________________________^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/occurs-check/unify-n-nplusone.stderr b/tests/ui/const-generics/occurs-check/unify-n-nplusone.stderr index 1a251044ec07e..cf5f79530a844 100644 --- a/tests/ui/const-generics/occurs-check/unify-n-nplusone.stderr +++ b/tests/ui/const-generics/occurs-check/unify-n-nplusone.stderr @@ -1,8 +1,17 @@ error[E0308]: mismatched types --> $DIR/unify-n-nplusone.rs:14:11 | +LL | fn bind(value: [u8; N]) -> [u8; N + 1] { + | ----------- help: consider changing bind's return type: `[u8; _]` +... LL | arr = bind(arr); | ^^^^^^^^^ encountered a self-referencing constant + | +note: the function bind is defined here + --> $DIR/unify-n-nplusone.rs:6:1 + | +LL | fn bind(value: [u8; N]) -> [u8; N + 1] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/occurs-check/unused-substs-4.stderr b/tests/ui/const-generics/occurs-check/unused-substs-4.stderr index 1e33439f6d731..ab4aa82977bed 100644 --- a/tests/ui/const-generics/occurs-check/unused-substs-4.stderr +++ b/tests/ui/const-generics/occurs-check/unused-substs-4.stderr @@ -1,8 +1,17 @@ error[E0308]: mismatched types --> $DIR/unused-substs-4.rs:10:11 | +LL | fn bind(value: [u8; N]) -> [u8; 3 + 4] { + | ----------- help: consider changing bind's return type: `[u8; _]` +... LL | arr = bind(arr); | ^^^^^^^^^ encountered a self-referencing constant + | +note: the function bind is defined here + --> $DIR/unused-substs-4.rs:4:1 + | +LL | fn bind(value: [u8; N]) -> [u8; 3 + 4] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/occurs-check/unused-substs-5.stderr b/tests/ui/const-generics/occurs-check/unused-substs-5.stderr index 1b3a54923284c..74e57079b8aed 100644 --- a/tests/ui/const-generics/occurs-check/unused-substs-5.stderr +++ b/tests/ui/const-generics/occurs-check/unused-substs-5.stderr @@ -5,6 +5,12 @@ LL | x = q::<_, N>(x); | ^^^^^^^^^^^^- help: try using a conversion method: `.to_vec()` | | | cyclic type of infinite size + | +note: the function q is defined here + --> $DIR/unused-substs-5.rs:5:1 + | +LL | fn q(_: T) -> [u8; N + 1] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/did_you_mean/compatible-variants.rs b/tests/ui/did_you_mean/compatible-variants.rs index b1c7dc2a7f672..b176c7ffb869e 100644 --- a/tests/ui/did_you_mean/compatible-variants.rs +++ b/tests/ui/did_you_mean/compatible-variants.rs @@ -8,6 +8,7 @@ struct Foo { } fn f() {} +//~^ HELP consider changing f's return type fn a() -> Option<()> { while false { diff --git a/tests/ui/did_you_mean/compatible-variants.stderr b/tests/ui/did_you_mean/compatible-variants.stderr index f2bbd8ced8f24..a5ce684b98ce6 100644 --- a/tests/ui/did_you_mean/compatible-variants.stderr +++ b/tests/ui/did_you_mean/compatible-variants.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:13:5 + --> $DIR/compatible-variants.rs:14:5 | LL | fn a() -> Option<()> { | ---------- expected `Option<()>` because of return type @@ -21,7 +21,7 @@ LL + Some(()) | error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:21:5 + --> $DIR/compatible-variants.rs:22:5 | LL | fn b() -> Result<(), ()> { | -------------- expected `Result<(), ()>` because of return type @@ -30,14 +30,23 @@ LL | f() | = note: expected enum `Result<(), ()>` found unit type `()` +note: the function f is defined here + --> $DIR/compatible-variants.rs:10:1 + | +LL | fn f() {} + | ^^^^^^ help: try adding an expression at the end of the block | LL ~ f(); LL + Ok(()) | +help: consider changing f's return type + | +LL | fn f()-> Result<(), ()> {} + | +++++++++++++++++ error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:27:5 + --> $DIR/compatible-variants.rs:28:5 | LL | fn c() -> Option<()> { | ---------- expected `Option<()>` because of return type @@ -59,7 +68,7 @@ LL + Some(()) | error[E0308]: `?` operator has incompatible types - --> $DIR/compatible-variants.rs:35:5 + --> $DIR/compatible-variants.rs:36:5 | LL | fn d() -> Option<()> { | ---------- expected `Option<()>` because of return type @@ -84,7 +93,7 @@ LL + Some(()) | error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:42:25 + --> $DIR/compatible-variants.rs:43:25 | LL | let _: Option<()> = while false {}; | ---------- ^^^^^^^^^^^^^^ expected `Option<()>`, found `()` @@ -99,7 +108,7 @@ LL | let _: Option<()> = Some(while false {}); | +++++ + error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:46:9 + --> $DIR/compatible-variants.rs:47:9 | LL | while false {} | ^^^^^^^^^^^^^^ expected `Option<()>`, found `()` @@ -116,7 +125,7 @@ LL + Some(()) | error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:50:31 + --> $DIR/compatible-variants.rs:51:31 | LL | let _: Result = 1; | ---------------- ^ expected `Result`, found integer @@ -133,7 +142,7 @@ LL | let _: Result = Err(1); | ++++ + error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:53:26 + --> $DIR/compatible-variants.rs:54:26 | LL | let _: Option = 1; | ----------- ^ expected `Option`, found integer @@ -148,7 +157,7 @@ LL | let _: Option = Some(1); | +++++ + error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:56:28 + --> $DIR/compatible-variants.rs:57:28 | LL | let _: Hey = 1; | ------------- ^ expected `Hey`, found integer @@ -165,7 +174,7 @@ LL | let _: Hey = Hey::B(1); | +++++++ + error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:59:29 + --> $DIR/compatible-variants.rs:60:29 | LL | let _: Hey = false; | -------------- ^^^^^ expected `Hey`, found `bool` @@ -180,7 +189,7 @@ LL | let _: Hey = Hey::B(false); | +++++++ + error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:63:19 + --> $DIR/compatible-variants.rs:64:19 | LL | let _ = Foo { bar }; | ^^^ expected `Option`, found `i32` @@ -193,7 +202,7 @@ LL | let _ = Foo { bar: Some(bar) }; | ++++++++++ + error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:80:16 + --> $DIR/compatible-variants.rs:81:16 | LL | let a: A = B::Fst; | - ^^^^^^ expected `A`, found `B` @@ -206,7 +215,7 @@ LL | let a: A = A::B { b: B::Fst }; | +++++++++ + error[E0308]: mismatched types - --> $DIR/compatible-variants.rs:86:17 + --> $DIR/compatible-variants.rs:87:17 | LL | let a: A2 = B::Fst; | -- ^^^^^^ expected `A2`, found `B` diff --git a/tests/ui/diverging-fn-tail-35849.stderr b/tests/ui/diverging-fn-tail-35849.stderr index 614f9b9cb5d20..326e8da7da6de 100644 --- a/tests/ui/diverging-fn-tail-35849.stderr +++ b/tests/ui/diverging-fn-tail-35849.stderr @@ -9,6 +9,8 @@ LL | ::std::mem::transmute::(panic!()) | = note: expected type `!` found array `[u8; 8]` +note: the function {{root}} is defined here + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/equality2.stderr b/tests/ui/impl-trait/equality2.stderr index 52f25d2458c91..dc6be133a95a4 100644 --- a/tests/ui/impl-trait/equality2.stderr +++ b/tests/ui/impl-trait/equality2.stderr @@ -12,7 +12,10 @@ error[E0308]: mismatched types --> $DIR/equality2.rs:25:18 | LL | fn hide(x: T) -> impl Foo { - | -------- the found opaque type + | -------- + | | + | the found opaque type + | help: consider changing hide's return type: `u32` ... LL | let _: u32 = hide(0_u32); | --- ^^^^^^^^^^^ expected `u32`, found opaque type @@ -21,6 +24,11 @@ LL | let _: u32 = hide(0_u32); | = note: expected type `u32` found opaque type `impl Foo` +note: the function hide is defined here + --> $DIR/equality2.rs:7:1 + | +LL | fn hide(x: T) -> impl Foo { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/equality2.rs:31:18 @@ -35,10 +43,19 @@ LL | let _: i32 = Leak::leak(hide(0_i32)); | = note: expected type `i32` found associated type `::T` +note: the function Leak is defined here + --> $DIR/equality2.rs:13:5 + | +LL | fn leak(self) -> Self::T; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider constraining the associated type `::T` to `i32` | LL | fn hide(x: T) -> impl Foo { | +++++++++ +help: consider changing Leak's return type + | +LL | fn leak(self) -> i32; + | ~~~ error[E0308]: mismatched types --> $DIR/equality2.rs:38:10 diff --git a/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr index 4996e6839e967..05a78c7a66f29 100644 --- a/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr +++ b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr @@ -1,6 +1,9 @@ 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 ... @@ -11,6 +14,11 @@ LL | let x: &str = ().bar(); | = note: expected reference `&str` found opaque type `impl std::fmt::Display` +note: the method bar is defined here + --> $DIR/opaque-in-impl-is-opaque.rs:4:5 + | +LL | fn bar(&self) -> impl Display; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/issue-102605.stderr b/tests/ui/impl-trait/issue-102605.stderr index dcb22797173cb..f647295701c20 100644 --- a/tests/ui/impl-trait/issue-102605.stderr +++ b/tests/ui/impl-trait/issue-102605.stderr @@ -19,6 +19,11 @@ note: calling an async function returns a future | LL | convert_result(foo()) | ^^^^^ +note: the function foo is defined here + --> $DIR/issue-102605.rs:3:1 + | +LL | async fn foo() -> Result<(), String> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/issue-102605.rs:7:4 | diff --git a/tests/ui/impl-trait/issue-99914.stderr b/tests/ui/impl-trait/issue-99914.stderr index 06e85e521d226..489db30e2adf5 100644 --- a/tests/ui/impl-trait/issue-99914.stderr +++ b/tests/ui/impl-trait/issue-99914.stderr @@ -4,6 +4,11 @@ error[E0308]: mismatched types LL | t.and_then(|t| -> _ { bar(t) }); | ^^^^^^ expected `Result<_, Error>`, found future | +note: the function bar is defined here + --> $DIR/issue-99914.rs:13:1 + | +LL | async fn bar(t: Okay) {} + | ^^^^^^^^^^^^^^^^^^^^^ help: try wrapping the expression in `Ok` | LL | t.and_then(|t| -> _ { Ok(bar(t)) }); diff --git a/tests/ui/impl-trait/printing-binder.stderr b/tests/ui/impl-trait/printing-binder.stderr index 5ffec8af10289..75dfd815fe56b 100644 --- a/tests/ui/impl-trait/printing-binder.stderr +++ b/tests/ui/impl-trait/printing-binder.stderr @@ -2,7 +2,10 @@ error[E0308]: mismatched types --> $DIR/printing-binder.rs:10:18 | LL | fn whatever() -> impl for<'a> Trait<'a> + for<'b> Trait<'b> {} - | ------------------------------------------ the found opaque type + | ------------------------------------------ + | | + | the found opaque type + | help: consider changing whatever's return type: `u32` ... LL | let x: u32 = whatever(); | --- ^^^^^^^^^^ expected `u32`, found opaque type @@ -11,12 +14,20 @@ LL | let x: u32 = whatever(); | = note: expected type `u32` found opaque type `impl for<'a> Trait<'a> + for<'b> Trait<'b>` +note: the function whatever is defined here + --> $DIR/printing-binder.rs:3:1 + | +LL | fn whatever() -> impl for<'a> Trait<'a> + for<'b> Trait<'b> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/printing-binder.rs:12:19 | LL | fn whatever2() -> impl for<'c> Fn(&'c ()) { - | ----------------------- the found opaque type + | ----------------------- + | | + | the found opaque type + | help: consider changing whatever2's return type: `u32` ... LL | let x2: u32 = whatever2(); | --- ^^^^^^^^^^^ expected `u32`, found opaque type @@ -25,6 +36,11 @@ LL | let x2: u32 = whatever2(); | = note: expected type `u32` found opaque type `impl for<'c> Fn(&'c ())` +note: the function whatever2 is defined here + --> $DIR/printing-binder.rs:5:1 + | +LL | fn whatever2() -> impl for<'c> Fn(&'c ()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/impl-trait/suggest-calling-rpit-closure.stderr b/tests/ui/impl-trait/suggest-calling-rpit-closure.stderr index b0ae10b8d8629..6e31796cb68e6 100644 --- a/tests/ui/impl-trait/suggest-calling-rpit-closure.stderr +++ b/tests/ui/impl-trait/suggest-calling-rpit-closure.stderr @@ -11,10 +11,19 @@ LL | fn opaque() -> impl Fn() -> i32 { | = note: expected type `i32` found opaque type `impl Fn() -> i32` +note: the function opaque is defined here + --> $DIR/suggest-calling-rpit-closure.rs:6:1 + | +LL | fn opaque() -> impl Fn() -> i32 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use parentheses to call this opaque type | LL | opaque()() | ++ +help: consider changing opaque's return type + | +LL | fn opaque() -> i32 { + | ~~~ error: aborting due to 1 previous error diff --git a/tests/ui/inference/array-len-mismatch.rs b/tests/ui/inference/array-len-mismatch.rs index 149d061029bc3..944a18812e0e9 100644 --- a/tests/ui/inference/array-len-mismatch.rs +++ b/tests/ui/inference/array-len-mismatch.rs @@ -1,4 +1,4 @@ -fn returns_arr() -> [u8; 2] { +fn returns_arr() -> [u8; 2] { //~ HELP consider changing returns_arr's return type [1, 2] } diff --git a/tests/ui/inference/array-len-mismatch.stderr b/tests/ui/inference/array-len-mismatch.stderr index 7358e47839725..6b2cc39c4f347 100644 --- a/tests/ui/inference/array-len-mismatch.stderr +++ b/tests/ui/inference/array-len-mismatch.stderr @@ -12,9 +12,22 @@ error[E0308]: mismatched types | LL | let wrong: [u8; 3] = returns_arr(); | ------- ^^^^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements - | | | - | | help: consider specifying the actual array length: `2` + | | | expected due to this + | +note: the function returns_arr is defined here + --> $DIR/array-len-mismatch.rs:1:1 + | +LL | fn returns_arr() -> [u8; 2] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider specifying the actual array length + | +LL | let wrong: [u8; 2] = returns_arr(); + | ~ +help: consider changing returns_arr's return type + | +LL | fn returns_arr() -> [u8; 3] { + | ~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-22684.stderr b/tests/ui/issues/issue-22684.stderr index e2ca54caeac05..e0d5db773afb3 100644 --- a/tests/ui/issues/issue-22684.stderr +++ b/tests/ui/issues/issue-22684.stderr @@ -1,10 +1,19 @@ 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` | | | expected due to this + | +note: the method bar is defined here + --> $DIR/issue-22684.rs:8:9 + | +LL | fn bar(&self) -> bool { true } + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-47486.stderr b/tests/ui/issues/issue-47486.stderr index c7e9af70e64a7..a766952f28956 100644 --- a/tests/ui/issues/issue-47486.stderr +++ b/tests/ui/issues/issue-47486.stderr @@ -5,6 +5,9 @@ LL | () < std::mem::size_of::<_>(); | -- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize` | | | expected because this is `()` + | +note: the function std is defined here + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL error[E0282]: type annotations needed --> $DIR/issue-47486.rs:3:11 diff --git a/tests/ui/issues/issue-61106.stderr b/tests/ui/issues/issue-61106.stderr index f825141fa062a..4fbbc848fc2db 100644 --- a/tests/ui/issues/issue-61106.stderr +++ b/tests/ui/issues/issue-61106.stderr @@ -6,6 +6,8 @@ LL | foo(x.clone()); | | | arguments to this function are incorrect | +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL note: function defined here --> $DIR/issue-61106.rs:6:4 | diff --git a/tests/ui/lifetimes/issue-26638.stderr b/tests/ui/lifetimes/issue-26638.stderr index ee958686259aa..d7ff8d59132a9 100644 --- a/tests/ui/lifetimes/issue-26638.stderr +++ b/tests/ui/lifetimes/issue-26638.stderr @@ -56,6 +56,8 @@ LL | fn parse_type(iter: Box+'static>) -> &str { iter.ne | = note: expected reference `&str` found enum `Option<&str>` +note: the method next is defined here + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider using `Option::expect` to unwrap the `Option<&str>` value, panicking if the value is an `Option::None` | LL | fn parse_type(iter: Box+'static>) -> &str { iter.next().expect("REASON") } diff --git a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr index 0a022dc3984f5..c938be03ca836 100644 --- a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr +++ b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr @@ -36,10 +36,19 @@ LL | let y: usize = x.foo(); | | | expected due to this | +note: the method foo is defined here + --> $DIR/method-ambig-one-trait-unknown-int-type.rs:6:5 + | +LL | fn foo(&self) -> isize; + | ^^^^^^^^^^^^^^^^^^^^^^^ help: you can convert an `isize` to a `usize` and panic if the converted value doesn't fit | 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 diff --git a/tests/ui/mismatched_types/issue-84976.stderr b/tests/ui/mismatched_types/issue-84976.stderr index 9157566e3a79b..bc98648fc8ad8 100644 --- a/tests/ui/mismatched_types/issue-84976.stderr +++ b/tests/ui/mismatched_types/issue-84976.stderr @@ -4,34 +4,70 @@ error[E0308]: mismatched types LL | length = { foo(&length) }; | ^^^^^^^^^^^^ expected `u32`, found `i32` | +note: the function foo is defined here + --> $DIR/issue-84976.rs:5:1 + | +LL | fn foo(length: &u32) -> i32 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can convert an `i32` to a `u32` and panic if the converted value doesn't fit | LL | length = { foo(&length).try_into().unwrap() }; | ++++++++++++++++++++ +help: consider changing foo's return type + | +LL | fn foo(length: &u32) -> u32 { + | ~~~ error[E0308]: mismatched types --> $DIR/issue-84976.rs:17:14 | +LL | fn foo(length: &u32) -> i32 { + | --- help: consider changing foo's return type: `u32` +... LL | let mut length = 0; | - expected due to this value ... LL | length = foo(&length); | ^^^^^^^^^^^^ expected `u32`, found `i32` + | +note: the function foo is defined here + --> $DIR/issue-84976.rs:5:1 + | +LL | fn foo(length: &u32) -> i32 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/issue-84976.rs:21:22 | +LL | fn bar(length: &f32) -> f64 { + | --- help: consider changing bar's return type: `f32` +... LL | float_length = { bar(&float_length) }; | ^^^^^^^^^^^^^^^^^^ expected `f32`, found `f64` + | +note: the function bar is defined here + --> $DIR/issue-84976.rs:9:1 + | +LL | fn bar(length: &f32) -> f64 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/issue-84976.rs:23:20 | +LL | fn bar(length: &f32) -> f64 { + | --- help: consider changing bar's return type: `f32` +... LL | let mut float_length = 0.0; | --- expected due to this value ... LL | float_length = bar(&float_length); | ^^^^^^^^^^^^^^^^^^ expected `f32`, found `f64` + | +note: the function bar is defined here + --> $DIR/issue-84976.rs:9:1 + | +LL | fn bar(length: &f32) -> f64 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.fixed b/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.fixed deleted file mode 100644 index f3f560fe530ab..0000000000000 --- a/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.fixed +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix -#![allow(unused, dead_code)] - -fn func() -> Option { - Some(1) -} - -fn test_unwrap() -> Result { - let b: Result = Ok(1); - let v: i32 = b?; //~ ERROR mismatched types - Ok(v) -} - -fn test_unwrap_option() -> Option { - let b = Some(1); - let v: i32 = b?; //~ ERROR mismatched types - Some(v) -} - -fn main() { - let a = Some(1); - let v: i32 = a.expect("REASON"); //~ ERROR mismatched types - - let b: Result = Ok(1); - let v: i32 = b.expect("REASON"); //~ ERROR mismatched types - - let v: i32 = func().expect("REASON"); //~ ERROR mismatched types - - let a = None; - let v: i32 = a.expect("REASON"); //~ ERROR mismatched types -} diff --git a/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.rs b/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.rs index 14020e872ff02..9d6ec739e8646 100644 --- a/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.rs +++ b/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.rs @@ -1,4 +1,3 @@ -// run-rustfix #![allow(unused, dead_code)] fn func() -> Option { diff --git a/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.stderr b/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.stderr index 9de23447fed53..d1f003b2a9566 100644 --- a/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.stderr +++ b/tests/ui/mismatched_types/mismatch-ty-unwrap-expect.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/mismatch-ty-unwrap-expect.rs:10:18 + --> $DIR/mismatch-ty-unwrap-expect.rs:9:18 | LL | let v: i32 = b; | --- ^ expected `i32`, found `Result` @@ -14,7 +14,7 @@ LL | let v: i32 = b?; | + error[E0308]: mismatched types - --> $DIR/mismatch-ty-unwrap-expect.rs:16:18 + --> $DIR/mismatch-ty-unwrap-expect.rs:15:18 | LL | let v: i32 = b; | --- ^ expected `i32`, found `Option<{integer}>` @@ -29,7 +29,7 @@ LL | let v: i32 = b?; | + error[E0308]: mismatched types - --> $DIR/mismatch-ty-unwrap-expect.rs:22:18 + --> $DIR/mismatch-ty-unwrap-expect.rs:21:18 | LL | let v: i32 = a; | --- ^ expected `i32`, found `Option<{integer}>` @@ -44,7 +44,7 @@ LL | let v: i32 = a.expect("REASON"); | +++++++++++++++++ error[E0308]: mismatched types - --> $DIR/mismatch-ty-unwrap-expect.rs:25:18 + --> $DIR/mismatch-ty-unwrap-expect.rs:24:18 | LL | let v: i32 = b; | --- ^ expected `i32`, found `Result` @@ -59,7 +59,7 @@ LL | let v: i32 = b.expect("REASON"); | +++++++++++++++++ error[E0308]: mismatched types - --> $DIR/mismatch-ty-unwrap-expect.rs:27:18 + --> $DIR/mismatch-ty-unwrap-expect.rs:26:18 | LL | let v: i32 = func(); | --- ^^^^^^ expected `i32`, found `Option` @@ -68,13 +68,22 @@ LL | let v: i32 = func(); | = note: expected type `i32` found enum `Option` +note: the function func is defined here + --> $DIR/mismatch-ty-unwrap-expect.rs:3:1 + | +LL | fn func() -> Option { + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `Option::expect` to unwrap the `Option` value, panicking if the value is an `Option::None` | LL | let v: i32 = func().expect("REASON"); | +++++++++++++++++ +help: consider changing func's return type + | +LL | fn func() -> i32 { + | ~~~ error[E0308]: mismatched types - --> $DIR/mismatch-ty-unwrap-expect.rs:30:18 + --> $DIR/mismatch-ty-unwrap-expect.rs:29:18 | LL | let v: i32 = a; | --- ^ expected `i32`, found `Option<_>` diff --git a/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.stderr b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.stderr index 6a9d76f7998c9..fd25b44267fb9 100644 --- a/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.stderr +++ b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.stderr @@ -14,6 +14,8 @@ note: `HashSet` does not implement `Clone`, so `&HashSet` was cloned i LL | let mut x: HashSet = v.clone(); | ^ = help: `Clone` is not implemented because the trait bound `Day: Clone` is not satisfied +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL help: consider annotating `Day` with `#[derive(Clone)]` | LL + #[derive(Clone)] diff --git a/tests/ui/noexporttypeexe.stderr b/tests/ui/noexporttypeexe.stderr index 59759b696c7a2..0fdb33f27721c 100644 --- a/tests/ui/noexporttypeexe.stderr +++ b/tests/ui/noexporttypeexe.stderr @@ -8,6 +8,11 @@ LL | let x: isize = noexporttypelib::foo(); | = note: expected type `isize` found enum `Option` +note: the function noexporttypelib is defined here + --> $DIR/auxiliary/noexporttypelib.rs:2:1 + | +LL | pub fn foo() -> oint { Some(3) } + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `Option::expect` to unwrap the `Option` value, panicking if the value is an `Option::None` | LL | let x: isize = noexporttypelib::foo().expect("REASON"); diff --git a/tests/ui/numeric/len.stderr b/tests/ui/numeric/len.stderr index 7b20d35c876d2..f23b792f5ac62 100644 --- a/tests/ui/numeric/len.stderr +++ b/tests/ui/numeric/len.stderr @@ -6,6 +6,8 @@ LL | test(array.len()); | | | arguments to this function are incorrect | +note: the method len is defined here + --> $SRC_DIR/core/src/slice/mod.rs:LL:COL note: function defined here --> $DIR/len.rs:6:4 | diff --git a/tests/ui/numeric/numeric-cast-2.stderr b/tests/ui/numeric/numeric-cast-2.stderr index a7b342739aa1b..c86736d2b5a7c 100644 --- a/tests/ui/numeric/numeric-cast-2.stderr +++ b/tests/ui/numeric/numeric-cast-2.stderr @@ -6,10 +6,19 @@ LL | let x: u16 = foo(); | | | expected due to this | +note: the function foo is defined here + --> $DIR/numeric-cast-2.rs:1:1 + | +LL | fn foo() -> i32 { + | ^^^^^^^^^^^^^^^ help: you can convert an `i32` to a `u16` and panic if the converted value doesn't fit | LL | let x: u16 = foo().try_into().unwrap(); | ++++++++++++++++++++ +help: consider changing foo's return type + | +LL | fn foo() -> u16 { + | ~~~ error[E0308]: mismatched types --> $DIR/numeric-cast-2.rs:7:18 diff --git a/tests/ui/parser/expr-as-stmt.stderr b/tests/ui/parser/expr-as-stmt.stderr index 76a83aa0161bb..18334f3f9faaf 100644 --- a/tests/ui/parser/expr-as-stmt.stderr +++ b/tests/ui/parser/expr-as-stmt.stderr @@ -81,9 +81,21 @@ error[E0308]: mismatched types --> $DIR/expr-as-stmt.rs:64:7 | LL | { foo() } || { true } - | ^^^^^- help: consider using a semicolon here: `;` - | | - | expected `()`, found `i32` + | ^^^^^ expected `()`, found `i32` + | +note: the function foo is defined here + --> $DIR/expr-as-stmt.rs:7:1 + | +LL | fn foo() -> i32 { + | ^^^^^^^^^^^^^^^ +help: consider using a semicolon here + | +LL | { foo(); } || { true } + | + +help: consider changing foo's return type + | +LL | fn foo() -> () { + | ~~ error[E0308]: mismatched types --> $DIR/expr-as-stmt.rs:8:6 diff --git a/tests/ui/return/issue-82612-return-mutable-reference.stderr b/tests/ui/return/issue-82612-return-mutable-reference.stderr index 59a6bb85d0fd3..195e0e7ac3034 100644 --- a/tests/ui/return/issue-82612-return-mutable-reference.stderr +++ b/tests/ui/return/issue-82612-return-mutable-reference.stderr @@ -10,6 +10,8 @@ LL | | } | = note: expected unit type `()` found mutable reference `&mut V` +note: the method get_or_insert_with is defined here + --> $SRC_DIR/core/src/option.rs:LL:COL help: consider using a semicolon here | LL | value.get_or_insert_with(func); diff --git a/tests/ui/return/return-type.stderr b/tests/ui/return/return-type.stderr index 1757fcac6e258..9111e93e5b580 100644 --- a/tests/ui/return/return-type.stderr +++ b/tests/ui/return/return-type.stderr @@ -6,6 +6,11 @@ LL | foo(4 as usize) | = note: expected unit type `()` found struct `S` +note: the function foo is defined here + --> $DIR/return-type.rs:5:1 + | +LL | fn foo(x: T) -> S { + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a semicolon here | LL | foo(4 as usize); @@ -14,6 +19,10 @@ help: try adding a return type | LL | fn bar() -> S { | +++++++++++ +help: consider changing foo's return type + | +LL | fn foo(x: T) -> () { + | ~~ error: aborting due to 1 previous error diff --git a/tests/ui/specialization/specialization-default-projection.stderr b/tests/ui/specialization/specialization-default-projection.stderr index b8b81876d8131..f3d380f165f1d 100644 --- a/tests/ui/specialization/specialization-default-projection.stderr +++ b/tests/ui/specialization/specialization-default-projection.stderr @@ -29,14 +29,25 @@ LL | fn monomorphic() -> () { | -- expected `()` because of return type ... LL | generic::<()>() - | ^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;` - | | - | expected `()`, found associated type + | ^^^^^^^^^^^^^^^ expected `()`, found associated type | = note: expected unit type `()` found associated type `<() as Foo>::Assoc` = help: consider constraining the associated type `<() as Foo>::Assoc` to `()` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: the function generic is defined here + --> $DIR/specialization-default-projection.rs:17:1 + | +LL | fn generic() -> ::Assoc { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider using a semicolon here + | +LL | generic::<()>(); + | + +help: consider changing generic's return type + | +LL | fn generic() -> () { + | ~~ error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/specialization/specialization-default-types.stderr b/tests/ui/specialization/specialization-default-types.stderr index 774ac9536175d..be4c3b7395d33 100644 --- a/tests/ui/specialization/specialization-default-types.stderr +++ b/tests/ui/specialization/specialization-default-types.stderr @@ -24,6 +24,9 @@ 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` +... LL | fn trouble(t: T) -> Box { | ------ expected `Box` because of return type LL | Example::generate(t) @@ -33,6 +36,11 @@ LL | Example::generate(t) found associated type `::Output` = help: consider constraining the associated type `::Output` to `Box` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: the function Example is defined here + --> $DIR/specialization-default-types.rs:9:5 + | +LL | fn generate(self) -> Self::Output; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/suggestions/box-future-wrong-output.stderr b/tests/ui/suggestions/box-future-wrong-output.stderr index 6a232c3444d93..a27ae60336a20 100644 --- a/tests/ui/suggestions/box-future-wrong-output.stderr +++ b/tests/ui/suggestions/box-future-wrong-output.stderr @@ -1,6 +1,9 @@ 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 + Send + 'static)>>` +... LL | let _: BoxFuture<'static, bool> = async {}.boxed(); | ------------------------ ^^^^^^^^^^^^^^^^ expected `bool`, found `()` | | @@ -8,6 +11,13 @@ LL | let _: BoxFuture<'static, bool> = async {}.boxed(); | = note: expected struct `Pin + Send + 'static)>>` found struct `Pin + Send>>` +note: the method boxed is defined here + --> $DIR/box-future-wrong-output.rs:11:5 + | +LL | / fn boxed<'a>(self) -> BoxFuture<'a, Self::Output> +LL | | where +LL | | Self: Sized + Send + 'a, + | |________________________________^ error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/chain-method-call-mutation-in-place.stderr b/tests/ui/suggestions/chain-method-call-mutation-in-place.stderr index 2dd6fb6a3bf6d..7e337e6822cd5 100644 --- a/tests/ui/suggestions/chain-method-call-mutation-in-place.stderr +++ b/tests/ui/suggestions/chain-method-call-mutation-in-place.stderr @@ -13,6 +13,8 @@ note: method `sort_by_key` modifies its receiver in-place, it is not meant to be | LL | let x: Vec = vec![1, 2, 3].into_iter().collect::>().sort_by_key(|i| i); | ^^^^^^^^^^^ this call modifies its receiver in-place +note: the method sort_by_key is defined here + --> $SRC_DIR/alloc/src/slice.rs:LL:COL error[E0599]: no method named `sort` found for unit type `()` in the current scope --> $DIR/chain-method-call-mutation-in-place.rs:3:72 @@ -45,6 +47,8 @@ LL | s.push_str("asdf") | | | you probably want to use this value after calling the method... = note: ...instead of the `()` output of method `push_str` +note: the method push_str is defined here + --> $SRC_DIR/alloc/src/string.rs:LL:COL error: aborting due to 3 previous errors diff --git a/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr b/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr index afbb9c32d516e..a5e91ad23d1c8 100644 --- a/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr +++ b/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr @@ -15,6 +15,8 @@ note: `T` does not implement `Clone`, so `&T` was cloned instead | LL | t.clone() | ^ +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL help: consider restricting type parameter `T` | LL | fn wat(t: &T) -> T { @@ -33,6 +35,8 @@ note: `Foo` does not implement `Clone`, so `&Foo` was cloned instead | LL | t.clone() | ^ +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL help: consider annotating `Foo` with `#[derive(Clone)]` | LL + #[derive(Clone)] diff --git a/tests/ui/suggestions/copied-and-cloned.stderr b/tests/ui/suggestions/copied-and-cloned.stderr index 87b0624d48be1..ace59e34e6ea9 100644 --- a/tests/ui/suggestions/copied-and-cloned.stderr +++ b/tests/ui/suggestions/copied-and-cloned.stderr @@ -8,6 +8,8 @@ LL | lol.x = x.clone(); | = note: expected enum `Option` found enum `Option<&String>` +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL help: use `Option::cloned` to clone the value inside the `Option` | LL | lol.x = x.clone().cloned(); diff --git a/tests/ui/suggestions/issue-105494.stderr b/tests/ui/suggestions/issue-105494.stderr index 4cb4a399a7245..1234d8ff4cafa 100644 --- a/tests/ui/suggestions/issue-105494.stderr +++ b/tests/ui/suggestions/issue-105494.stderr @@ -6,6 +6,8 @@ LL | let _v: i32 = (1 as i32).to_string(); | | | expected due to this | +note: the method to_string is defined here + --> $SRC_DIR/alloc/src/string.rs:LL:COL help: try removing the method call | LL - let _v: i32 = (1 as i32).to_string(); @@ -19,6 +21,9 @@ LL | let _v: i32 = (1 as i128).to_string(); | --- ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `String` | | | expected due to this + | +note: the method to_string is defined here + --> $SRC_DIR/alloc/src/string.rs:LL:COL error[E0308]: mismatched types --> $DIR/issue-105494.rs:7:20 @@ -28,6 +33,8 @@ LL | let _v: &str = "foo".to_string(); | | | expected due to this | +note: the method to_string is defined here + --> $SRC_DIR/alloc/src/string.rs:LL:COL help: try removing the method call | LL - let _v: &str = "foo".to_string(); @@ -43,6 +50,8 @@ LL | let mut path: String = "/usr".to_string(); LL | path = format!("{}/{}", path, folder).as_str(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `&str` | +note: the method as_str is defined here + --> $SRC_DIR/alloc/src/string.rs:LL:COL help: try removing the method call | LL - path = format!("{}/{}", path, folder).as_str(); diff --git a/tests/ui/suggestions/issue-117669.stderr b/tests/ui/suggestions/issue-117669.stderr index 01783ea4ef629..1e08b575e0fef 100644 --- a/tests/ui/suggestions/issue-117669.stderr +++ b/tests/ui/suggestions/issue-117669.stderr @@ -8,6 +8,9 @@ LL | let abs: i32 = 3i32.checked_abs(); | = note: expected type `i32` found enum `Option` +note: the method checked_abs is defined here + --> $SRC_DIR/core/src/num/mod.rs:LL:COL + = note: this error originates in the macro `int_impl` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider using `Option::expect` to unwrap the `Option` value, panicking if the value is an `Option::None` | LL | let abs: i32 = 3i32.checked_abs().expect("REASON"); diff --git a/tests/ui/suggestions/issue-52820.stderr b/tests/ui/suggestions/issue-52820.stderr index a67d75014171f..f029d38468313 100644 --- a/tests/ui/suggestions/issue-52820.stderr +++ b/tests/ui/suggestions/issue-52820.stderr @@ -17,6 +17,9 @@ LL | brains: guts.clone(), | | | | | help: try using a conversion method: `to_string` | expected `String`, found `&str` + | +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL error: aborting due to 2 previous errors diff --git a/tests/ui/suggestions/issue-53692.stderr b/tests/ui/suggestions/issue-53692.stderr index 469a538411fb1..7d3bfc3d09b34 100644 --- a/tests/ui/suggestions/issue-53692.stderr +++ b/tests/ui/suggestions/issue-53692.stderr @@ -10,6 +10,8 @@ LL | let items_clone: Vec = ref_items.clone(); | = note: expected struct `Vec` found reference `&[i32]` +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL error[E0308]: mismatched types --> $DIR/issue-53692.rs:14:26 @@ -20,6 +22,9 @@ LL | let string: String = s.clone(); | | | help: try using a conversion method: `to_string` | | expected `String`, found `&str` | expected due to this + | +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL error: aborting due to 2 previous errors diff --git a/tests/ui/suggestions/issue-81839.stderr b/tests/ui/suggestions/issue-81839.stderr index de1ea98554bee..6e6625ce0abec 100644 --- a/tests/ui/suggestions/issue-81839.stderr +++ b/tests/ui/suggestions/issue-81839.stderr @@ -11,6 +11,11 @@ LL | | _ => cx.answer_str("hi"), LL | | } | |_____- `match` arms have incompatible types | +note: the method answer_str is defined here + --> $DIR/auxiliary/issue-81839.rs:6:5 + | +LL | pub async fn answer_str(&self, _s: &str) -> Test { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing this semicolon | LL - cx.answer_str("hi"); diff --git a/tests/ui/suggestions/issue-86100-tuple-paren-comma.stderr b/tests/ui/suggestions/issue-86100-tuple-paren-comma.stderr index da6f7641be53b..c665f7c9b3197 100644 --- a/tests/ui/suggestions/issue-86100-tuple-paren-comma.stderr +++ b/tests/ui/suggestions/issue-86100-tuple-paren-comma.stderr @@ -41,6 +41,8 @@ LL | let _s = S { _s: ("abc".to_string()) }; | = note: expected tuple `(String,)` found struct `String` +note: the method to_string is defined here + --> $SRC_DIR/alloc/src/string.rs:LL:COL help: use a trailing comma to create a tuple with one element | LL | let _s = S { _s: ("abc".to_string(),) }; diff --git a/tests/ui/suggestions/match-needing-semi.stderr b/tests/ui/suggestions/match-needing-semi.stderr index b5f01d7038c0d..1ddbd4de08037 100644 --- a/tests/ui/suggestions/match-needing-semi.stderr +++ b/tests/ui/suggestions/match-needing-semi.stderr @@ -11,6 +11,11 @@ LL | | _ => 2 LL | | } | |_____- expected this to be `()` | +note: the function foo is defined here + --> $DIR/match-needing-semi.rs:19:1 + | +LL | fn foo() -> i32 { + | ^^^^^^^^^^^^^^^ help: consider using a semicolon here | LL | foo(); @@ -19,6 +24,10 @@ help: consider using a semicolon here | LL | }; | + +help: consider changing foo's return type + | +LL | fn foo() -> () { + | ~~ error[E0308]: mismatched types --> $DIR/match-needing-semi.rs:11:5 diff --git a/tests/ui/suggestions/match-prev-arm-needing-semi.rs b/tests/ui/suggestions/match-prev-arm-needing-semi.rs index 11463c453d407..d0128793787c3 100644 --- a/tests/ui/suggestions/match-prev-arm-needing-semi.rs +++ b/tests/ui/suggestions/match-prev-arm-needing-semi.rs @@ -1,6 +1,8 @@ // edition:2018 fn dummy() -> i32 { 42 } +//~^ NOTE the function dummy is defined here +//~| HELP consider changing dummy's return type fn extra_semicolon() { let _ = match true { //~ NOTE `match` arms have incompatible types @@ -14,8 +16,11 @@ fn extra_semicolon() { } async fn async_dummy() {} +//~^ NOTE the function async_dummy is defined here async fn async_dummy2() {} +//~^ NOTE the function async_dummy2 is defined here +//~| NOTE the function async_dummy2 is defined here async fn async_extra_semicolon_same() { let _ = match true { //~ NOTE `match` arms have incompatible types diff --git a/tests/ui/suggestions/match-prev-arm-needing-semi.stderr b/tests/ui/suggestions/match-prev-arm-needing-semi.stderr index cf3cf45ef402a..e7c126fe3e654 100644 --- a/tests/ui/suggestions/match-prev-arm-needing-semi.stderr +++ b/tests/ui/suggestions/match-prev-arm-needing-semi.stderr @@ -1,5 +1,5 @@ error[E0308]: `match` arms have incompatible types - --> $DIR/match-prev-arm-needing-semi.rs:26:18 + --> $DIR/match-prev-arm-needing-semi.rs:31:18 | LL | let _ = match true { | _____________- @@ -16,10 +16,15 @@ LL | | }; | |_____- `match` arms have incompatible types | note: calling an async function returns a future - --> $DIR/match-prev-arm-needing-semi.rs:26:18 + --> $DIR/match-prev-arm-needing-semi.rs:31:18 | LL | false => async_dummy(), | ^^^^^^^^^^^^^ +note: the function async_dummy is defined here + --> $DIR/match-prev-arm-needing-semi.rs:18:1 + | +LL | async fn async_dummy() {} + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider `await`ing on the `Future` | LL | false => async_dummy().await, @@ -31,7 +36,7 @@ LL + async_dummy() | error[E0308]: `match` arms have incompatible types - --> $DIR/match-prev-arm-needing-semi.rs:39:18 + --> $DIR/match-prev-arm-needing-semi.rs:44:18 | LL | let _ = match true { | _____________- @@ -48,10 +53,15 @@ LL | | }; | |_____- `match` arms have incompatible types | note: calling an async function returns a future - --> $DIR/match-prev-arm-needing-semi.rs:39:18 + --> $DIR/match-prev-arm-needing-semi.rs:44:18 | LL | false => async_dummy2(), | ^^^^^^^^^^^^^^ +note: the function async_dummy2 is defined here + --> $DIR/match-prev-arm-needing-semi.rs:21:1 + | +LL | async fn async_dummy2() {} + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider `await`ing on the `Future` | LL | false => async_dummy2().await, @@ -65,7 +75,7 @@ LL ~ false => Box::new(async_dummy2()), | error[E0308]: `match` arms have incompatible types - --> $DIR/match-prev-arm-needing-semi.rs:50:18 + --> $DIR/match-prev-arm-needing-semi.rs:55:18 | LL | let _ = match true { | _____________- @@ -80,6 +90,11 @@ LL | | }; | |_____- `match` arms have incompatible types | = note: distinct uses of `impl Trait` result in different opaque types +note: the function async_dummy2 is defined here + --> $DIR/match-prev-arm-needing-semi.rs:21:1 + | +LL | async fn async_dummy2() {} + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider `await`ing on both `Future`s | LL ~ true => async_dummy().await, @@ -88,16 +103,13 @@ LL ~ false => async_dummy2().await, | error[E0308]: `match` arms have incompatible types - --> $DIR/match-prev-arm-needing-semi.rs:11:18 + --> $DIR/match-prev-arm-needing-semi.rs:13:18 | LL | let _ = match true { | _____________- LL | | true => { LL | | dummy(); - | | -------- - | | | | - | | | help: consider removing this semicolon - | | this is found to be of type `()` + | | -------- this is found to be of type `()` LL | | LL | | } LL | | false => dummy(), @@ -105,6 +117,21 @@ LL | | false => dummy(), LL | | LL | | }; | |_____- `match` arms have incompatible types + | +note: the function dummy is defined here + --> $DIR/match-prev-arm-needing-semi.rs:3:1 + | +LL | fn dummy() -> i32 { 42 } + | ^^^^^^^^^^^^^^^^^ +help: consider removing this semicolon + | +LL - dummy(); +LL + dummy() + | +help: consider changing dummy's return type + | +LL | fn dummy() -> () { 42 } + | ~~ error: aborting due to 4 previous errors diff --git a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed index 8ef7e34ab3050..f4c68b3fbefc0 100644 --- a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed +++ b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed @@ -4,7 +4,7 @@ trait Trait { type A; - fn func(&self) -> Self::A; + fn func(&self) -> usize; } struct S(T); diff --git a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr index ac839ff7eb966..c768b415677a9 100644 --- a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr +++ b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr @@ -8,6 +8,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:7:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:41:4 | @@ -17,6 +22,10 @@ help: consider constraining the associated type `::A` to `u | LL | fn foo<'a, T: Trait + 'a>(&self, _: impl Trait, x: impl Trait, _: 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 @@ -28,6 +37,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:7:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:41:4 | @@ -37,6 +51,10 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn ban(x: T) where T: Trait { | +++++++++++ +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 @@ -48,6 +66,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:7:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:41:4 | @@ -57,6 +80,10 @@ help: consider constraining the associated type `::A` to `u | LL | fn foo<'a, T: Trait + 'a>(_: impl Trait, x: impl Trait, _: 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 @@ -68,6 +95,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:7:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:41:4 | @@ -77,6 +109,10 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn bar>(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 @@ -88,6 +124,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type ` as Trait>::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:7:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:41:4 | @@ -97,6 +138,10 @@ help: consider constraining the associated type ` as Trait> | LL | fn foo2(x: impl Trait) { | +++++++++++ +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 @@ -108,6 +153,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `>::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:7:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:41:4 | @@ -117,6 +167,10 @@ help: consider constraining the associated type `>::A` to `usize | LL | fn bar2>(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 @@ -128,6 +182,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:7:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction-fixable.rs:41:4 | @@ -137,6 +196,10 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn ban(x: T) where T: Trait { | +++++++++++ +help: consider changing func's return type + | +LL | fn func(&self) -> usize; + | ~~~~~ error: aborting due to 7 previous errors diff --git a/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr b/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr index 980c2455c8e41..8453d7903563f 100644 --- a/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr +++ b/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr @@ -22,6 +22,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction.rs:42:4 | @@ -31,6 +36,10 @@ help: consider constraining the associated type `::A` to `u | LL | fn foo(_: impl Trait, x: impl Trait) { | +++++++++++ +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 @@ -42,6 +51,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction.rs:42:4 | @@ -51,6 +65,10 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn bar>(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 @@ -62,6 +80,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type ` as Trait>::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction.rs:42:4 | @@ -71,6 +94,10 @@ help: consider constraining the associated type ` as Trait> | LL | fn foo2(x: impl Trait) { | +++++++++++ +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 @@ -110,6 +137,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `>::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction.rs:42:4 | @@ -119,10 +151,17 @@ help: consider constraining the associated type `>::A` to `usize | LL | fn bar2>(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>(x: T) { | - found this type parameter LL | qux(x.func()) @@ -132,6 +171,11 @@ LL | qux(x.func()) | = note: expected type `usize` found type parameter `D` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction.rs:42:4 | @@ -141,11 +185,19 @@ 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 `()` | | | arguments to this function are incorrect | +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction.rs:42:4 | @@ -162,6 +214,11 @@ LL | qux(x.func()) | = note: expected type `usize` found associated type `::A` +note: the method func is defined here + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: function defined here --> $DIR/trait-with-missing-associated-type-restriction.rs:42:4 | @@ -171,6 +228,10 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn ban(x: T) where T: Trait { | +++++++++++ +help: consider changing func's return type + | +LL | fn func(&self) -> usize; + | ~~~~~ error: aborting due to 9 previous errors diff --git a/tests/ui/suggestions/try-operator-dont-suggest-semicolon.rs b/tests/ui/suggestions/try-operator-dont-suggest-semicolon.rs index f882a159f9834..4237a56003f2c 100644 --- a/tests/ui/suggestions/try-operator-dont-suggest-semicolon.rs +++ b/tests/ui/suggestions/try-operator-dont-suggest-semicolon.rs @@ -25,3 +25,5 @@ fn main() -> Result<(), ()> { fn a(f: F) -> Result<(), ()> where F: FnMut() { Ok(()) } fn b() -> i32 { 42 } +//~^ NOTE: the function b is defined here +//~| HELP: consider changing b's return type diff --git a/tests/ui/suggestions/try-operator-dont-suggest-semicolon.stderr b/tests/ui/suggestions/try-operator-dont-suggest-semicolon.stderr index 939285498fb69..1567347b1d8a3 100644 --- a/tests/ui/suggestions/try-operator-dont-suggest-semicolon.stderr +++ b/tests/ui/suggestions/try-operator-dont-suggest-semicolon.stderr @@ -2,9 +2,21 @@ error[E0308]: mismatched types --> $DIR/try-operator-dont-suggest-semicolon.rs:6:9 | LL | b() - | ^^^- help: consider using a semicolon here: `;` - | | - | expected `()`, found `i32` + | ^^^ expected `()`, found `i32` + | +note: the function b is defined here + --> $DIR/try-operator-dont-suggest-semicolon.rs:27:1 + | +LL | fn b() -> i32 { 42 } + | ^^^^^^^^^^^^^ +help: consider using a semicolon here + | +LL | b(); + | + +help: consider changing b's return type + | +LL | fn b() -> () { 42 } + | ~~ error[E0308]: mismatched types --> $DIR/try-operator-dont-suggest-semicolon.rs:16:9 diff --git a/tests/ui/tail-typeck.stderr b/tests/ui/tail-typeck.stderr index 0e470a7b4057f..fd2d290f0d6f6 100644 --- a/tests/ui/tail-typeck.stderr +++ b/tests/ui/tail-typeck.stderr @@ -6,10 +6,19 @@ LL | fn f() -> isize { return g(); } | | | expected `isize` because of return type | +note: the function g is defined here + --> $DIR/tail-typeck.rs:5:1 + | +LL | fn g() -> usize { return 0; } + | ^^^^^^^^^^^^^^^ help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | LL | fn f() -> isize { return g().try_into().unwrap(); } | ++++++++++++++++++++ +help: consider changing g's return type + | +LL | fn g() -> isize { return 0; } + | ~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/trait-bounds/restrict-assoc-type-of-generic-bound.stderr b/tests/ui/trait-bounds/restrict-assoc-type-of-generic-bound.stderr index 5024ad21892a6..23b1c02b0c1b4 100644 --- a/tests/ui/trait-bounds/restrict-assoc-type-of-generic-bound.stderr +++ b/tests/ui/trait-bounds/restrict-assoc-type-of-generic-bound.stderr @@ -10,6 +10,11 @@ LL | return a.bar(); | = note: expected type parameter `B` found associated type `::T` +note: the method bar is defined here + --> $DIR/restrict-assoc-type-of-generic-bound.rs:5:5 + | +LL | fn bar(self) -> Self::T; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider further restricting this bound | LL | pub fn foo, B>(a: A) -> B { diff --git a/tests/ui/traits/issue-68295.stderr b/tests/ui/traits/issue-68295.stderr index 8bc315302417b..c1a1755589251 100644 --- a/tests/ui/traits/issue-68295.stderr +++ b/tests/ui/traits/issue-68295.stderr @@ -1,6 +1,9 @@ error[E0308]: mismatched types --> $DIR/issue-68295.rs:43:5 | +LL | fn into_owned(self) -> Matrix> + | ----------------------------- help: consider changing into_owned's return type: `Matrix` +... LL | fn crash(input: Matrix) -> Matrix | ----------------- expected `Matrix` because of return type ... @@ -11,6 +14,13 @@ LL | input.into_owned() found struct `Matrix<_, _, <() as Allocator>::Buffer>` = help: consider constraining the associated type `<() as Allocator>::Buffer` to `u32` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: the method into_owned is defined here + --> $DIR/issue-68295.rs:8:5 + | +LL | / fn into_owned(self) -> Matrix> +LL | | where +LL | | (): Allocator, + | |____________________________^ error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr index 863282a0ff94d..28d0b26c9aaac 100644 --- a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr +++ b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr @@ -8,6 +8,9 @@ LL | let _: &str = bomp(); | ---- ^^^^^^ expected `&str`, found opaque type | | | expected due to this +... +LL | fn bomp() -> boo::Boo { + | -------- help: consider changing bomp's return type: `&str` | = note: expected reference `&str` found opaque type `Boo` @@ -16,6 +19,11 @@ note: this item must have the opaque type in its signature in order to be able t | LL | fn bomp2() { | ^^^^^ +note: the function bomp is defined here + --> $DIR/no_revealing_outside_defining_module.rs:18:1 + | +LL | fn bomp() -> boo::Boo { + | ^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/no_revealing_outside_defining_module.rs:19:5 diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr index dd2737c706d6b..8b63bc2970e3e 100644 --- a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr +++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr @@ -25,6 +25,9 @@ LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) } error[E0308]: mismatched types --> $DIR/normalize-hidden-types.rs:44:25 | +LL | fn dyn_hoops(_: T) -> *const dyn FnOnce(T::Gat<'_>) { + | ----------------------------- help: consider changing dyn_hoops's return type: `typeck::Opaque` +... LL | type Opaque = impl Sized; | ---------- the expected opaque type ... @@ -37,6 +40,11 @@ LL | let _: Opaque = dyn_hoops::(0); found raw pointer `*const (dyn FnOnce(()) + 'static)` = help: consider constraining the associated type `::Gat<'_>` to `()` or calling a method that returns `::Gat<'_>` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: the function dyn_hoops is defined here + --> $DIR/normalize-hidden-types.rs:18:1 + | +LL | fn dyn_hoops(_: T) -> *const dyn FnOnce(T::Gat<'_>) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: concrete type differs from previous defining opaque type use --> $DIR/normalize-hidden-types.rs:54:25 diff --git a/tests/ui/typeck/deref-multi.stderr b/tests/ui/typeck/deref-multi.stderr index 4346e273d0d66..ac08160ca2a22 100644 --- a/tests/ui/typeck/deref-multi.stderr +++ b/tests/ui/typeck/deref-multi.stderr @@ -62,6 +62,8 @@ LL | x.lock().unwrap() | = note: expected type `i32` found struct `MutexGuard<'_, &i32>` +note: the method unwrap is defined here + --> $SRC_DIR/core/src/result.rs:LL:COL help: consider dereferencing the type | LL | **x.lock().unwrap() diff --git a/tests/ui/typeck/explain_clone_autoref.rs b/tests/ui/typeck/explain_clone_autoref.rs index 88aaac469b21d..16ee311b4391c 100644 --- a/tests/ui/typeck/explain_clone_autoref.rs +++ b/tests/ui/typeck/explain_clone_autoref.rs @@ -10,6 +10,7 @@ fn clone_thing(nc: &NotClone) -> NotClone { //~^ ERROR mismatched type //~| NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead //~| NOTE expected `NotClone`, found `&NotClone` + //~| NOTE the method clone is defined here } fn clone_thing2(nc: &NotClone) -> NotClone { @@ -18,6 +19,7 @@ fn clone_thing2(nc: &NotClone) -> NotClone { //~| NOTE expected due to this //~| NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead //~| NOTE expected `NotClone`, found `&NotClone` + //~| NOTE the method clone is defined here nc } diff --git a/tests/ui/typeck/explain_clone_autoref.stderr b/tests/ui/typeck/explain_clone_autoref.stderr index 40d3df3011901..3f6f6567cc814 100644 --- a/tests/ui/typeck/explain_clone_autoref.stderr +++ b/tests/ui/typeck/explain_clone_autoref.stderr @@ -12,6 +12,8 @@ note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead | LL | nc.clone() | ^^ +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL help: consider annotating `NotClone` with `#[derive(Clone)]` | LL + #[derive(Clone)] @@ -19,7 +21,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:16:24 + --> $DIR/explain_clone_autoref.rs:17:24 | LL | let nc: NotClone = nc.clone(); | -------- ^^^^^^^^^^ expected `NotClone`, found `&NotClone` @@ -27,10 +29,12 @@ LL | let nc: NotClone = nc.clone(); | expected due to this | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:16:24 + --> $DIR/explain_clone_autoref.rs:17:24 | LL | let nc: NotClone = nc.clone(); | ^^ +note: the method clone is defined here + --> $SRC_DIR/core/src/clone.rs:LL:COL help: consider annotating `NotClone` with `#[derive(Clone)]` | LL + #[derive(Clone)] @@ -38,7 +42,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:28:5 + --> $DIR/explain_clone_autoref.rs:30:5 | LL | fn clone_thing3(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type @@ -47,7 +51,7 @@ LL | nc | ^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:26:14 + --> $DIR/explain_clone_autoref.rs:28:14 | LL | let nc = nc.clone(); | ^^ @@ -58,7 +62,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:38:5 + --> $DIR/explain_clone_autoref.rs:40:5 | LL | fn clone_thing4(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type @@ -67,7 +71,7 @@ LL | nc2 | ^^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:35:14 + --> $DIR/explain_clone_autoref.rs:37:14 | LL | let nc = nc.clone(); | ^^ @@ -78,7 +82,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:57:5 + --> $DIR/explain_clone_autoref.rs:59:5 | LL | fn clone_thing5(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type @@ -87,7 +91,7 @@ LL | nc3 | ^^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:52:14 + --> $DIR/explain_clone_autoref.rs:54:14 | LL | let nc = nc.clone(); | ^^ @@ -98,7 +102,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:67:5 + --> $DIR/explain_clone_autoref.rs:69:5 | LL | fn clone_thing6(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type @@ -107,7 +111,7 @@ LL | ret | ^^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:64:21 + --> $DIR/explain_clone_autoref.rs:66:21 | LL | let (ret, _) = (nc.clone(), 1); | ^^ @@ -118,7 +122,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:76:5 + --> $DIR/explain_clone_autoref.rs:78:5 | LL | fn clone_thing7(nc: Vec<&NotClone>) -> NotClone { | -------- expected `NotClone` because of return type @@ -127,7 +131,7 @@ LL | ret | ^^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:74:15 + --> $DIR/explain_clone_autoref.rs:76:15 | LL | let ret = nc[0].clone(); | ^^^^^ @@ -138,7 +142,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:88:5 + --> $DIR/explain_clone_autoref.rs:90:5 | LL | fn clone_thing8(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type @@ -147,7 +151,7 @@ LL | ret | ^^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:84:17 + --> $DIR/explain_clone_autoref.rs:86:17 | LL | let a = nc.clone(); | ^^ @@ -158,7 +162,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:98:5 + --> $DIR/explain_clone_autoref.rs:100:5 | LL | fn clone_thing9(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type @@ -167,7 +171,7 @@ LL | ret | ^^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:95:17 + --> $DIR/explain_clone_autoref.rs:97:17 | LL | let cl = || nc.clone(); | ^^ @@ -178,13 +182,13 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:110:6 + --> $DIR/explain_clone_autoref.rs:112:6 | LL | (a, b) | ^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:105:17 + --> $DIR/explain_clone_autoref.rs:107:17 | LL | let a = nc.clone(); | ^^ @@ -195,13 +199,13 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:110:9 + --> $DIR/explain_clone_autoref.rs:112:9 | LL | (a, b) | ^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:107:13 + --> $DIR/explain_clone_autoref.rs:109:13 | LL | (a, nc.clone()) | ^^ @@ -212,7 +216,7 @@ LL | struct NotClone; | error[E0308]: mismatched types - --> $DIR/explain_clone_autoref.rs:126:5 + --> $DIR/explain_clone_autoref.rs:128:5 | LL | fn clone_thing11(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type @@ -221,7 +225,7 @@ LL | a | ^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead - --> $DIR/explain_clone_autoref.rs:121:17 + --> $DIR/explain_clone_autoref.rs:123:17 | LL | let a = nc.clone(); | ^^ diff --git a/tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.stderr b/tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.stderr index df2e06e8f3b76..cdf6212354e7c 100644 --- a/tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.stderr +++ b/tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.stderr @@ -12,6 +12,8 @@ LL | | } | = note: expected unit type `()` found enum `Result<(), std::fmt::Error>` +note: the method write_fmt is defined here + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL = note: this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider using a semicolon here | @@ -35,6 +37,8 @@ LL | | } | = note: expected unit type `()` found enum `Result<(), std::fmt::Error>` +note: the method write_fmt is defined here + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL = note: this error originates in the macro `writeln` which comes from the expansion of the macro `baz` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider using a semicolon here | diff --git a/tests/ui/typeck/issue-13853.stderr b/tests/ui/typeck/issue-13853.stderr index 0683c782933af..0b52e83da7cc0 100644 --- a/tests/ui/typeck/issue-13853.stderr +++ b/tests/ui/typeck/issue-13853.stderr @@ -9,6 +9,8 @@ LL | self.iter() | = note: expected type parameter `I` found struct `std::slice::Iter<'_, N>` +note: the method iter is defined here + --> $SRC_DIR/core/src/slice/mod.rs:LL:COL error[E0599]: no method named `iter` found for reference `&G` in the current scope --> $DIR/issue-13853.rs:27:23 diff --git a/tests/ui/typeck/issue-50687-ice-on-borrow.stderr b/tests/ui/typeck/issue-50687-ice-on-borrow.stderr index 24dce4697929d..74ae172222808 100644 --- a/tests/ui/typeck/issue-50687-ice-on-borrow.stderr +++ b/tests/ui/typeck/issue-50687-ice-on-borrow.stderr @@ -8,6 +8,8 @@ LL | let _: () = Borrow::borrow(&owned); | = note: expected unit type `()` found reference `&_` +note: the function Borrow is defined here + --> $SRC_DIR/core/src/borrow.rs:LL:COL help: consider dereferencing the borrow | LL | let _: () = *Borrow::borrow(&owned); diff --git a/tests/ui/typeck/issue-81943.stderr b/tests/ui/typeck/issue-81943.stderr index 041ff10752cf0..f1c07e64b6d7a 100644 --- a/tests/ui/typeck/issue-81943.stderr +++ b/tests/ui/typeck/issue-81943.stderr @@ -4,6 +4,11 @@ error[E0308]: mismatched types LL | f(|x| lib::d!(x)); | ^^^^^^^^^^ expected `()`, found `i32` | +note: the function $crate is defined here + --> $DIR/auxiliary/issue-81943-lib.rs:1:1 + | +LL | pub fn g(t: i32) -> i32 { t } + | ^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `lib::d` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types @@ -15,6 +20,11 @@ LL | f(|x| match x { tmp => { g(tmp) } }); | | expected `()`, found `i32` | expected this to be `()` | +note: the function g is defined here + --> $DIR/issue-81943.rs:5:1 + | +LL | fn g(t: i32) -> i32 { t } + | ^^^^^^^^^^^^^^^^^^^ help: consider using a semicolon here | LL | f(|x| match x { tmp => { g(tmp); } }); @@ -23,6 +33,10 @@ help: consider using a semicolon here | LL | f(|x| match x { tmp => { g(tmp) } };); | + +help: consider changing g's return type + | +LL | fn g(t: i32) -> () { t } + | ~~ error[E0308]: mismatched types --> $DIR/issue-81943.rs:10:38 @@ -36,6 +50,11 @@ LL | } LL | f(|x| d!(x)); | ----- in this macro invocation | +note: the function g is defined here + --> $DIR/issue-81943.rs:5:1 + | +LL | fn g(t: i32) -> i32 { t } + | ^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `d` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider using a semicolon here | @@ -45,6 +64,10 @@ help: consider using a semicolon here | LL | ($e:expr) => { match $e { x => { g(x) } }; } | + +help: consider changing g's return type + | +LL | fn g(t: i32) -> () { t } + | ~~ error: aborting due to 3 previous errors diff --git a/tests/ui/typeck/issue-89275.stderr b/tests/ui/typeck/issue-89275.stderr index 6686d5f977e6b..fb634fbedf55b 100644 --- a/tests/ui/typeck/issue-89275.stderr +++ b/tests/ui/typeck/issue-89275.stderr @@ -1,6 +1,9 @@ error[E0308]: mismatched types --> $DIR/issue-89275.rs:28:29 | +LL | fn downcast<'a, W: ?Sized>() -> &'a W { + | ----- help: consider changing downcast's return type: `&mut Other` +... LL | let other: &mut Other = downcast(); | ---------- ^^^^^^^^^^ types differ in mutability | | @@ -8,6 +11,11 @@ LL | let other: &mut Other = downcast(); | = note: expected mutable reference `&mut Other` found reference `&_` +note: the function downcast is defined here + --> $DIR/issue-89275.rs:21:1 + | +LL | fn downcast<'a, W: ?Sized>() -> &'a W { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr b/tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr index c46f4ec1ec301..81fd32ce37419 100644 --- a/tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr +++ b/tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr @@ -25,6 +25,11 @@ note: calling an async function returns a future | LL | hello() | ^^^^^^^ +note: the function hello is defined here + --> $DIR/issue-90027-async-fn-return-suggestion.rs:3:1 + | +LL | async fn hello() { + | ^^^^^^^^^^^^^^^^ help: consider `await`ing on the `Future` | LL | hello().await diff --git a/tests/ui/typeck/output-type-mismatch.stderr b/tests/ui/typeck/output-type-mismatch.stderr index c6df6650654a6..03d9dfbb41a5e 100644 --- a/tests/ui/typeck/output-type-mismatch.stderr +++ b/tests/ui/typeck/output-type-mismatch.stderr @@ -1,10 +1,19 @@ error[E0308]: mismatched types --> $DIR/output-type-mismatch.rs:5:31 | +LL | fn f() { } + | - help: consider changing f's return type: `-> isize` +LL | LL | fn main() { let i: isize; i = f(); } | ----- ^^^ expected `isize`, found `()` | | | expected due to this type + | +note: the function f is defined here + --> $DIR/output-type-mismatch.rs:3:1 + | +LL | fn f() { } + | ^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/typeck/ptr-null-mutability-suggestions.stderr b/tests/ui/typeck/ptr-null-mutability-suggestions.stderr index b615d9fb45cbe..0de23532785d5 100644 --- a/tests/ui/typeck/ptr-null-mutability-suggestions.stderr +++ b/tests/ui/typeck/ptr-null-mutability-suggestions.stderr @@ -10,6 +10,8 @@ LL | expecting_null_mut(ptr::null()); | = note: expected raw pointer `*mut u8` found raw pointer `*const _` +note: the function ptr is defined here + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: function defined here --> $DIR/ptr-null-mutability-suggestions.rs:6:4 | diff --git a/tests/ui/typeck/return_type_containing_closure.rs b/tests/ui/typeck/return_type_containing_closure.rs index 8b826daeede48..a315953d58e98 100644 --- a/tests/ui/typeck/return_type_containing_closure.rs +++ b/tests/ui/typeck/return_type_containing_closure.rs @@ -4,6 +4,7 @@ fn foo() { //~ HELP a return type might be missing here //~^ ERROR mismatched types [E0308] //~| NOTE expected `()`, found `Map, ...>` //~| NOTE expected unit type `()` + //~| NOTE the method map is defined here //~| HELP consider using a semicolon here } diff --git a/tests/ui/typeck/return_type_containing_closure.stderr b/tests/ui/typeck/return_type_containing_closure.stderr index ea9c74be36238..f42ec90c432d3 100644 --- a/tests/ui/typeck/return_type_containing_closure.stderr +++ b/tests/ui/typeck/return_type_containing_closure.stderr @@ -6,6 +6,8 @@ LL | vec!['a'].iter().map(|c| c) | = note: expected unit type `()` found struct `Map, {closure@$DIR/return_type_containing_closure.rs:3:26: 3:29}>` +note: the method map is defined here + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider using a semicolon here | LL | vec!['a'].iter().map(|c| c); diff --git a/tests/ui/typeck/tag-that-dare-not-speak-its-name.stderr b/tests/ui/typeck/tag-that-dare-not-speak-its-name.stderr index 3a7e2068ca63f..ef7634c9ac1cc 100644 --- a/tests/ui/typeck/tag-that-dare-not-speak-its-name.stderr +++ b/tests/ui/typeck/tag-that-dare-not-speak-its-name.stderr @@ -8,10 +8,19 @@ LL | let x : char = last(y); | = note: expected type `char` found enum `Option<_>` +note: the function last is defined here + --> $DIR/tag-that-dare-not-speak-its-name.rs:5:1 + | +LL | fn last(v: Vec<&T> ) -> std::option::Option { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `Option::expect` to unwrap the `Option<_>` value, panicking if the value is an `Option::None` | LL | let x : char = last(y).expect("REASON"); | +++++++++++++++++ +help: consider changing last's return type + | +LL | fn last(v: Vec<&T> ) -> char { + | ~~~~ error: aborting due to 1 previous error From da2a8bebc8de10d24aac802ffba44182b35440e9 Mon Sep 17 00:00:00 2001 From: sjwang05 <63834813+sjwang05@users.noreply.github.com> Date: Wed, 27 Dec 2023 12:16:42 -0800 Subject: [PATCH 3/3] Don't suggest changing ret ty for trait methods --- compiler/rustc_hir_typeck/src/demand.rs | 32 +++++++++---------- ...or-type-param-of-current-assoc-item.stderr | 3 -- .../associated-types-eq-3.stderr | 4 --- tests/ui/impl-trait/equality2.stderr | 6 +--- .../in-trait/opaque-in-impl-is-opaque.stderr | 3 -- tests/ui/issues/issue-22684.stderr | 3 -- ...od-ambig-one-trait-unknown-int-type.stderr | 4 --- .../specialization-default-types.stderr | 5 +-- .../box-future-wrong-output.stderr | 3 -- ...-associated-type-restriction-fixable.fixed | 2 +- ...associated-type-restriction-fixable.stderr | 28 ---------------- ...missing-associated-type-restriction.stderr | 26 --------------- .../typeck/issue-50687-ice-on-borrow.stderr | 2 +- 13 files changed, 19 insertions(+), 102 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index f6ef97e9583cd..8c203f5cf1ae8 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1178,41 +1178,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr: &hir::Expr<'_>, expected: Ty<'_>, ) { - let (def_id, ident, callee_str) = if let hir::ExprKind::Call(fun, _) = expr.kind + let (def_id, ident) = if let hir::ExprKind::Call(fun, _) = expr.kind && let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = fun.kind - && let hir::def::Res::Def(def_kind, def_id) = path.res - && !matches!(def_kind, hir::def::DefKind::Ctor(..)) + && let hir::def::Res::Def(_, def_id) = path.res { - (def_id, path.segments[0].ident, "function") + (def_id, path.segments[0].ident) } else if let hir::ExprKind::MethodCall(method, ..) = expr.kind && let Some(def_id) = self.typeck_results.borrow().type_dependent_def_id(expr.hir_id) - && !matches!(self.tcx.def_kind(def_id), hir::def::DefKind::Ctor(..)) { - (def_id, method.ident, "method") + (def_id, method.ident) } else { return; }; + if !matches!(self.tcx.def_kind(def_id), hir::def::DefKind::AssocFn | hir::def::DefKind::Fn) + { + return; + } err.span_note( self.tcx.def_span(def_id), - format!("the {callee_str} {ident} is defined here"), + format!("the {} {ident} is defined here", self.tcx.def_descr(def_id)), ); 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 { - kind: hir::ImplItemKind::Fn(sig, ..), .. - }) - | hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. }) = node + && !matches!(node, hir::Node::TraitItem(..)) + && let Some(sig) = node.fn_sig() && let ret_span = sig.decl.output.span() && !ret_span.from_expansion() && expected.has_concrete_skeleton() { - let sugg = - if ret_span.is_empty() { format!("-> {expected}") } else { format!("{expected}") }; + let sugg = match sig.decl.output { + hir::FnRetTy::DefaultReturn(..) => format!("-> {expected}"), + hir::FnRetTy::Return(..) => format!("{expected}"), + }; err.span_suggestion( ret_span, format!("consider changing {ident}'s return type"), diff --git a/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr b/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr index 96bca643ae28b..4d893a758a950 100644 --- a/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr +++ b/tests/ui/associated-type-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.stderr @@ -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 | | diff --git a/tests/ui/associated-types/associated-types-eq-3.stderr b/tests/ui/associated-types/associated-types-eq-3.stderr index 78a9662187a1d..07cdf272ba970 100644 --- a/tests/ui/associated-types/associated-types-eq-3.stderr +++ b/tests/ui/associated-types/associated-types-eq-3.stderr @@ -17,10 +17,6 @@ help: consider constraining the associated type `::A` to `Bar` | LL | fn foo2>(x: I) { | +++++++++ -help: consider changing boo's return type - | -LL | fn boo(&self) -> Bar; - | ~~~ error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:38:10 diff --git a/tests/ui/impl-trait/equality2.stderr b/tests/ui/impl-trait/equality2.stderr index dc6be133a95a4..c6187b3a30473 100644 --- a/tests/ui/impl-trait/equality2.stderr +++ b/tests/ui/impl-trait/equality2.stderr @@ -43,7 +43,7 @@ LL | let _: i32 = Leak::leak(hide(0_i32)); | = note: expected type `i32` found associated type `::T` -note: the function Leak is defined here +note: the method Leak is defined here --> $DIR/equality2.rs:13:5 | LL | fn leak(self) -> Self::T; @@ -52,10 +52,6 @@ help: consider constraining the associated type `::T` to `i32` | LL | fn hide(x: T) -> impl Foo { | +++++++++ -help: consider changing Leak's return type - | -LL | fn leak(self) -> i32; - | ~~~ error[E0308]: mismatched types --> $DIR/equality2.rs:38:10 diff --git a/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr index 05a78c7a66f29..9faf40e975cef 100644 --- a/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr +++ b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr @@ -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 ... diff --git a/tests/ui/issues/issue-22684.stderr b/tests/ui/issues/issue-22684.stderr index e0d5db773afb3..ecb9517772f4b 100644 --- a/tests/ui/issues/issue-22684.stderr +++ b/tests/ui/issues/issue-22684.stderr @@ -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` | | diff --git a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr index c938be03ca836..d0cae444dafdb 100644 --- a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr +++ b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr @@ -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 diff --git a/tests/ui/specialization/specialization-default-types.stderr b/tests/ui/specialization/specialization-default-types.stderr index be4c3b7395d33..f28f3c595f801 100644 --- a/tests/ui/specialization/specialization-default-types.stderr +++ b/tests/ui/specialization/specialization-default-types.stderr @@ -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` -... LL | fn trouble(t: T) -> Box { | ------ expected `Box` because of return type LL | Example::generate(t) @@ -36,7 +33,7 @@ LL | Example::generate(t) found associated type `::Output` = help: consider constraining the associated type `::Output` to `Box` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html -note: the function Example is defined here +note: the method Example is defined here --> $DIR/specialization-default-types.rs:9:5 | LL | fn generate(self) -> Self::Output; diff --git a/tests/ui/suggestions/box-future-wrong-output.stderr b/tests/ui/suggestions/box-future-wrong-output.stderr index a27ae60336a20..685bd7273d215 100644 --- a/tests/ui/suggestions/box-future-wrong-output.stderr +++ b/tests/ui/suggestions/box-future-wrong-output.stderr @@ -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 + Send + 'static)>>` -... LL | let _: BoxFuture<'static, bool> = async {}.boxed(); | ------------------------ ^^^^^^^^^^^^^^^^ expected `bool`, found `()` | | diff --git a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed index f4c68b3fbefc0..8ef7e34ab3050 100644 --- a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed +++ b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.fixed @@ -4,7 +4,7 @@ trait Trait { type A; - fn func(&self) -> usize; + fn func(&self) -> Self::A; } struct S(T); diff --git a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr index c768b415677a9..e590d264f26a8 100644 --- a/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr +++ b/tests/ui/suggestions/trait-with-missing-associated-type-restriction-fixable.stderr @@ -22,10 +22,6 @@ help: consider constraining the associated type `::A` to `u | LL | fn foo<'a, T: Trait + 'a>(&self, _: impl Trait, x: impl Trait, _: 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 @@ -51,10 +47,6 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn ban(x: T) where T: Trait { | +++++++++++ -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 @@ -80,10 +72,6 @@ help: consider constraining the associated type `::A` to `u | LL | fn foo<'a, T: Trait + 'a>(_: impl Trait, x: impl Trait, _: 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 @@ -109,10 +97,6 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn bar>(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 @@ -138,10 +122,6 @@ help: consider constraining the associated type ` as Trait> | LL | fn foo2(x: impl Trait) { | +++++++++++ -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 @@ -167,10 +147,6 @@ help: consider constraining the associated type `>::A` to `usize | LL | fn bar2>(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 @@ -196,10 +172,6 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn ban(x: T) where T: Trait { | +++++++++++ -help: consider changing func's return type - | -LL | fn func(&self) -> usize; - | ~~~~~ error: aborting due to 7 previous errors diff --git a/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr b/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr index 8453d7903563f..5d36a533b35f1 100644 --- a/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr +++ b/tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr @@ -36,10 +36,6 @@ help: consider constraining the associated type `::A` to `u | LL | fn foo(_: impl Trait, x: impl Trait) { | +++++++++++ -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 @@ -65,10 +61,6 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn bar>(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 @@ -94,10 +86,6 @@ help: consider constraining the associated type ` as Trait> | LL | fn foo2(x: impl Trait) { | +++++++++++ -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 @@ -151,17 +139,10 @@ help: consider constraining the associated type `>::A` to `usize | LL | fn bar2>(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>(x: T) { | - found this type parameter LL | qux(x.func()) @@ -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 `()` | | @@ -228,10 +206,6 @@ help: consider constraining the associated type `::A` to `usize` | LL | fn ban(x: T) where T: Trait { | +++++++++++ -help: consider changing func's return type - | -LL | fn func(&self) -> usize; - | ~~~~~ error: aborting due to 9 previous errors diff --git a/tests/ui/typeck/issue-50687-ice-on-borrow.stderr b/tests/ui/typeck/issue-50687-ice-on-borrow.stderr index 74ae172222808..95c7efc4757dd 100644 --- a/tests/ui/typeck/issue-50687-ice-on-borrow.stderr +++ b/tests/ui/typeck/issue-50687-ice-on-borrow.stderr @@ -8,7 +8,7 @@ LL | let _: () = Borrow::borrow(&owned); | = note: expected unit type `()` found reference `&_` -note: the function Borrow is defined here +note: the method Borrow is defined here --> $SRC_DIR/core/src/borrow.rs:LL:COL help: consider dereferencing the borrow |