mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Avoid misleading closure return type note
This commit is contained in:
@@ -2009,6 +2009,9 @@ fn report_return_mismatched_types<'infcx>(
|
||||
// note in this case, since it would be incorrect.
|
||||
&& let Some(fn_sig) = fcx.body_fn_sig()
|
||||
&& fn_sig.output().is_ty_var()
|
||||
&& fcx.ret_coercion.as_ref().is_some_and(|ret_coercion| {
|
||||
fcx.resolve_vars_if_possible(ret_coercion.borrow().expected_ty()) == expected
|
||||
})
|
||||
{
|
||||
err.span_note(sp, format!("return type inferred to be `{expected}` here"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
struct SmolStr;
|
||||
|
||||
const _: fn() = || {
|
||||
match Some(()) {
|
||||
Some(()) => (),
|
||||
None => return,
|
||||
};
|
||||
let _: String = {
|
||||
SmolStr
|
||||
//~^ ERROR mismatched types
|
||||
};
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/closure-return-block-note-issue-155670.rs:9:9
|
||||
|
|
||||
LL | SmolStr
|
||||
| ^^^^^^^ expected `String`, found `SmolStr`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
Reference in New Issue
Block a user