Skip to content

diagnostics: suggest type annotation for closure params on HRTB FnOnce mismatch#158701

Open
Rohan-Singla wants to merge 3 commits into
rust-lang:mainfrom
Rohan-Singla:fix/#158393
Open

diagnostics: suggest type annotation for closure params on HRTB FnOnce mismatch#158701
Rohan-Singla wants to merge 3 commits into
rust-lang:mainfrom
Rohan-Singla:fix/#158393

Conversation

@Rohan-Singla

@Rohan-Singla Rohan-Singla commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #158393

Problem

When a closure passed to a function requiring for<'a> FnOnce(&'a mut [u8]) has
unannotated parameters (e.g. |buf|), the compiler emits the confusing error:

implementation of `FnOnce` is not general enough

without explaining how to fix it.

In many cases, simply adding an explicit type annotation to the closure
parameter (e.g. |buf: &mut [u8]|) resolves the lifetime ambiguity, but the
compiler does not currently provide any guidance.

What

This PR adds a diagnostic suggestion in placeholder_error.rs that detects
when:

  • the mismatched trait is an Fn-trait (FnOnce, FnMut, or Fn)
  • the self type is a local closure
  • one or more closure parameters do not have explicit type annotations

When these conditions are met, the compiler now emits the following help
message:

help: consider adding an explicit type annotation to the closure parameter
      to resolve the lifetime ambiguity
  |
  |     let outer_closure = |buf: &mut [u8]| {
  |                             +++++++++++

Testing

A UI test has been added covering the exact reproduction case from the
reported issue.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 2, 2026
@rustbot

rustbot commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/ice-106874/ice-106874.stderr`
diff of stderr:

6    |
7    = note: closure with signature `fn(&'0 mut V)` must implement `FnOnce<(&mut V,)>`, for some specific lifetime `'0`...
8    = note: ...but it actually implements `FnOnce<(&'1 mut V,)>`, for some specific lifetime `'1`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
9 
10 error: implementation of `FnOnce` is not general enough
11   --> $DIR/ice-106874.rs:8:5

16    = note: closure with signature `fn(&'0 mut V)` must implement `FnOnce<(&mut V,)>`, for some specific lifetime `'0`...
17    = note: ...but it actually implements `FnOnce<(&'1 mut V,)>`, for some specific lifetime `'1`
18    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
19 
20 error: higher-ranked subtype error
21   --> $DIR/ice-106874.rs:8:5

39    |
40    = note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
41    = note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
42 
43 error: implementation of `Fn` is not general enough
44   --> $DIR/ice-106874.rs:8:7

48    |
49    = note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
50    = note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
51 
52 error: implementation of `FnOnce` is not general enough
53   --> $DIR/ice-106874.rs:8:7

58    = note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
59    = note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
60    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
61 
62 error: implementation of `Fn` is not general enough
63   --> $DIR/ice-106874.rs:8:7

68    = note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
69    = note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
70    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
71 
72 error: implementation of `FnOnce` is not general enough
73   --> $DIR/ice-106874.rs:8:7

78    = note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
79    = note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
80    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
81 
82 error: implementation of `Fn` is not general enough
83   --> $DIR/ice-106874.rs:8:7

88    = note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
89    = note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
90    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
+    |                               ++++++++
91 
92 error: aborting due to 10 previous errors
93 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args nll/ice-106874.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/ice-106874.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/ice-106874" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:5
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'0 mut V)` must implement `FnOnce<(&mut V,)>`, for some specific lifetime `'0`...
   = note: ...but it actually implements `FnOnce<(&'1 mut V,)>`, for some specific lifetime `'1`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:5
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'0 mut V)` must implement `FnOnce<(&mut V,)>`, for some specific lifetime `'0`...
   = note: ...but it actually implements `FnOnce<(&'1 mut V,)>`, for some specific lifetime `'1`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: higher-ranked subtype error
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:5
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: higher-ranked subtype error
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:5
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:7
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: implementation of `Fn` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:7
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Fn` is not general enough
   |
   = note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:7
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: implementation of `Fn` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:7
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Fn` is not general enough
   |
   = note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:7
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: implementation of `Fn` is not general enough
##[error]  --> /checkout/tests/ui/nll/ice-106874.rs:8:7
   |
LL |     A(B(C::new(D::new(move |st| f(st)))))
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Fn` is not general enough
   |
   = note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     A(B(C::new(D::new(move |st: &mut V| f(st)))))
   |                               ++++++++

error: aborting due to 10 previous errors
------------------------------------------

---- [ui] tests/ui/nll/ice-106874.rs stdout end ----
---- [ui] tests/ui/nll/issue-57843.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/issue-57843/issue-57843.stderr`
diff of stderr:

6    |
7    = note: closure with signature `fn(&'2 bool)` must implement `FnOnce<(&'1 bool,)>`, for any lifetime `'1`...
8    = note: ...but it actually implements `FnOnce<(&'2 bool,)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     Foo(Box::new(|_: &'a bool| ()));
+    |                    ++++++++++
9 
10 error: aborting due to 1 previous error
11 

Note: some mismatched output was normalized before being compared
- LL |     Foo(Box::new(|_: &'a bool| ())); //~ ERROR implementation of `FnOnce` is not general enough
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     Foo(Box::new(|_: &'a bool| ()));
+    |                    ++++++++++


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args nll/issue-57843.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/issue-57843.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/issue-57843" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/issue-57843.rs:25:9
   |
LL |     Foo(Box::new(|_| ())); //~ ERROR implementation of `FnOnce` is not general enough
   |         ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 bool)` must implement `FnOnce<(&'1 bool,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 bool,)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     Foo(Box::new(|_: &'a bool| ())); //~ ERROR implementation of `FnOnce` is not general enough
   |                    ++++++++++

error: aborting due to 1 previous error
------------------------------------------

---- [ui] tests/ui/nll/issue-57843.rs stdout end ----
---- [ui] tests/ui/nll/missing-universe-cause-issue-114907.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/missing-universe-cause-issue-114907/missing-universe-cause-issue-114907.stderr`
diff of stderr:

6    |
7    = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
8    = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let callback = |_: &()| {};
+    |                      +++++
9 
10 error: implementation of `FnOnce` is not general enough
11   --> $DIR/missing-universe-cause-issue-114907.rs:33:5

16    = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
17    = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
18    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let callback = |_: &()| {};
+    |                      +++++
19 
20 error: implementation of `FnOnce` is not general enough
21   --> $DIR/missing-universe-cause-issue-114907.rs:33:5

26    = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
27    = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
28    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let callback = |_: &()| {};
+    |                      +++++
29 
30 error: implementation of `FnOnce` is not general enough
31   --> $DIR/missing-universe-cause-issue-114907.rs:33:5

36    = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
37    = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
38    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let callback = |_: &()| {};
+    |                      +++++
39 
40 error: higher-ranked subtype error
41   --> $DIR/missing-universe-cause-issue-114907.rs:33:5


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args nll/missing-universe-cause-issue-114907.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/missing-universe-cause-issue-114907.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/missing-universe-cause-issue-114907" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/missing-universe-cause-issue-114907.rs:33:5
   |
LL |     accept(callback);
   |     ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let callback = |_: &()| {};
   |                      +++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/missing-universe-cause-issue-114907.rs:33:5
   |
LL |     accept(callback);
   |     ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let callback = |_: &()| {};
   |                      +++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/missing-universe-cause-issue-114907.rs:33:5
   |
LL |     accept(callback);
   |     ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let callback = |_: &()| {};
   |                      +++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/missing-universe-cause-issue-114907.rs:33:5
   |
LL |     accept(callback);
   |     ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let callback = |_: &()| {};
   |                      +++++

error: higher-ranked subtype error
##[error]  --> /checkout/tests/ui/nll/missing-universe-cause-issue-114907.rs:33:5
   |
---
------------------------------------------

---- [ui] tests/ui/nll/missing-universe-cause-issue-114907.rs stdout end ----
---- [ui] tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs#nll stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/polonius/location-insensitive-scopes-issue-117146.nll/location-insensitive-scopes-issue-117146.nll.stderr`
diff of stderr:

32    |
33    = note: closure with signature `fn(&'2 ()) -> &()` must implement `Fn<(&'1 (),)>`, for any lifetime `'1`...
34    = note: ...but it actually implements `Fn<(&'2 (),)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let b = |_: &()| &a;
+    |               +++++
35 
36 error: implementation of `FnOnce` is not general enough
37   --> $DIR/location-insensitive-scopes-issue-117146.rs:13:5

41    |
42    = note: closure with signature `fn(&'2 ()) -> &()` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
43    = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let b = |_: &()| &a;
+    |               +++++
44 
45 error: aborting due to 3 previous errors
46 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args nll/polonius/location-insensitive-scopes-issue-117146.rs`

error in revision `nll`: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "nll" "--check-cfg" "cfg(test,FALSE,nll,polonius)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/polonius/location-insensitive-scopes-issue-117146.nll" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0597]: `a` does not live long enough
##[error]  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:10:18
   |
LL |     let a = ();
   |         - binding `a` declared here
LL |     let b = |_| &a;
   |             --- -^
   |             |   ||
   |             |   |borrowed value does not live long enough
   |             |   returning this value requires that `a` is borrowed for `'static`
   |             value captured here
...
LL | }
   | - `a` dropped here while still borrowed
   |
note: due to a current limitation of the type system, this implies a `'static` lifetime
  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:20:11
   |
LL | fn bad<F: Fn(&()) -> &()>(_: F) {}
   |           ^^^^^^^^^^^^^^
note: requirement that the value outlives `'static` introduced here
  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:20:22
   |
LL | fn bad<F: Fn(&()) -> &()>(_: F) {}
   |                      ^^^

error: implementation of `Fn` is not general enough
##[error]  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:13:5
   |
LL |     bad(&b);
   |     ^^^^^^^ implementation of `Fn` is not general enough
   |
   = note: closure with signature `fn(&'2 ()) -> &()` must implement `Fn<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `Fn<(&'2 (),)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let b = |_: &()| &a;
   |               +++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:13:5
   |
LL |     bad(&b);
   |     ^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 ()) -> &()` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let b = |_: &()| &a;
   |               +++++

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0597`.
------------------------------------------

---- [ui] tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs#nll stdout end ----
---- [ui] tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs#polonius stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/polonius/location-insensitive-scopes-issue-117146.polonius/location-insensitive-scopes-issue-117146.polonius.stderr`
diff of stderr:

32    |
33    = note: closure with signature `fn(&'2 ()) -> &()` must implement `Fn<(&'1 (),)>`, for any lifetime `'1`...
34    = note: ...but it actually implements `Fn<(&'2 (),)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let b = |_: &()| &a;
+    |               +++++
35 
36 error: implementation of `FnOnce` is not general enough
37   --> $DIR/location-insensitive-scopes-issue-117146.rs:13:5

41    |
42    = note: closure with signature `fn(&'2 ()) -> &()` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
43    = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
+ help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
+    |
+ LL |     let b = |_: &()| &a;
+    |               +++++
44 
45 error: aborting due to 3 previous errors
46 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args nll/polonius/location-insensitive-scopes-issue-117146.rs`

error in revision `polonius`: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "polonius" "--check-cfg" "cfg(test,FALSE,nll,polonius)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/polonius/location-insensitive-scopes-issue-117146.polonius" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Zpolonius=next"
stdout: none
--- stderr -------------------------------
error[E0597]: `a` does not live long enough
##[error]  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:10:18
   |
LL |     let a = ();
   |         - binding `a` declared here
LL |     let b = |_| &a;
   |             --- -^
   |             |   ||
   |             |   |borrowed value does not live long enough
   |             |   returning this value requires that `a` is borrowed for `'static`
   |             value captured here
...
LL | }
   | - `a` dropped here while still borrowed
   |
note: due to a current limitation of the type system, this implies a `'static` lifetime
  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:20:11
   |
LL | fn bad<F: Fn(&()) -> &()>(_: F) {}
   |           ^^^^^^^^^^^^^^
note: requirement that the value outlives `'static` introduced here
  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:20:22
   |
LL | fn bad<F: Fn(&()) -> &()>(_: F) {}
   |                      ^^^

error: implementation of `Fn` is not general enough
##[error]  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:13:5
   |
LL |     bad(&b);
   |     ^^^^^^^ implementation of `Fn` is not general enough
   |
   = note: closure with signature `fn(&'2 ()) -> &()` must implement `Fn<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `Fn<(&'2 (),)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let b = |_: &()| &a;
   |               +++++

error: implementation of `FnOnce` is not general enough
##[error]  --> /checkout/tests/ui/nll/polonius/location-insensitive-scopes-issue-117146.rs:13:5
   |
LL |     bad(&b);
   |     ^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'2 ()) -> &()` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
help: consider adding an explicit type annotation to the closure parameter to resolve the lifetime ambiguity
   |
LL |     let b = |_: &()| &a;
   |               +++++

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0597`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler suggests HRTB for closure when only type annotation needed

4 participants