Repository navigation
Conversation
…ure lifetime mismatch
Suggest type annotation for closure params on HRTB FnOnce mismatch in next trait solver.
```
help: consider adding an explicit type annotation to the closure's argument
|
LL | let outer_closure = |buf: &mut [u8]| {
| +++++++++++
```
in
```
error[E0277]: expected `FnOnce(&mut [u8])` signature, found `{closure@$DIR/hrtb-closure-suggest-type-annotation.rs:22:25: 22:30}`
--> $DIR/hrtb-closure-suggest-type-annotation.rs:35:16
|
LL | inner(buf, outer_closure)
| ----- ^^^^^^^^^^^^^ expected `FnOnce(&mut [u8])` signature, found `{closure@$DIR/hrtb-closure-suggest-type-annotation.rs:22:25: 22:30}`
| |
| required by a bound introduced by this call
|
help: the trait `for<'a> FnOnce(&'a mut [u8])` is not implemented for closure `{closure@$DIR/hrtb-closure-suggest-type-annotation.rs:22:25: 22:30}`
--> $DIR/hrtb-closure-suggest-type-annotation.rs:22:25
|
LL | let outer_closure = |buf| {
| ^^^^^
= note: expected type with signature `for<'a> fn(&'a mut _)`
found closure with signature `fn(&mut _)`
note: required by a bound in `inner`
--> $DIR/hrtb-closure-suggest-type-annotation.rs:10:8
|
LL | fn inner<F>(buf: &mut [u8], func: F) -> usize
LL | where
LL | F: FnOnce(&mut [u8]) -> Result<usize, isize>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `inner`
help: consider adding an explicit type annotation to the closure's argument
|
LL | let outer_closure = |buf: &mut [u8]| {
| +++++++++++
```
Collaborator
|
r? @tmiasko rustbot has assigned @tmiasko. Use Why was this reviewer chosen?The reviewer was selected based on:
|
estebank
commented
Nov 9, 2026
Contributor
Author
There was a problem hiding this comment.
Making this one run-rustfix causes additional lifetime errors that don't have suggestions when they likely should.
error[E0271]: type mismatch resolving `<{closure@main.rs:8:14} as FnOnce<(&i32,)>>::Output == &i32`
--> src/main.rs:8:24
|
8 | take_foo(|a: &i32| a);
| -------- --------- ^ types differ
| | |
| | this closure
| required by a bound introduced by this call
|
note: required for `{closure@src/main.rs:8:14: 8:23}` to implement `Foo`
--> src/main.rs:3:9
|
3 | impl<F> Foo for F where F: Fn(&i32) -> &i32 {}
| ^^^ ^ ---- unsatisfied trait bound introduced here
note: required by a bound in `take_foo`
--> src/main.rs:5:21
|
5 | fn take_foo(_: impl Foo) {}
| ^^^ required by this bound in `take_foo`
error[E0271]: type mismatch resolving `<{closure@main.rs:9:14} as FnOnce<(&i32,)>>::Output == &i32`
--> src/main.rs:9:34
|
9 | take_foo(|a: &i32| -> &i32 { a });
| -------- ----------------- ^ types differ
| | |
| | this closure
| required by a bound introduced by this call
|
note: required for `{closure@src/main.rs:9:14: 9:31}` to implement `Foo`
--> src/main.rs:3:9
|
3 | impl<F> Foo for F where F: Fn(&i32) -> &i32 {}
| ^^^ ^ ---- unsatisfied trait bound introduced here
note: required by a bound in `take_foo`
--> src/main.rs:5:21
|
5 | fn take_foo(_: impl Foo) {}
| ^^^ required by this bound in `take_foo`
and on old trait solver
error[E0308]: mismatched types
--> src/main.rs:8:5
|
8 | take_foo(|a: &i32| a);
| ^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected reference `&_`
found reference `&_`
note: the lifetime requirement is introduced here
--> src/main.rs:5:21
|
5 | fn take_foo(_: impl Foo) {}
| ^^^
error: lifetime may not live long enough
--> src/main.rs:8:24
|
8 | take_foo(|a: &i32| a);
| - - ^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure is &'2 i32
| let's call the lifetime of this reference `'1`
error[E0308]: mismatched types
--> src/main.rs:9:5
|
9 | take_foo(|a: &i32| -> &i32 { a });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected reference `&_`
found reference `&_`
note: the lifetime requirement is introduced here
--> src/main.rs:5:21
|
5 | fn take_foo(_: impl Foo) {}
| ^^^
error: lifetime may not live long enough
--> src/main.rs:9:34
|
9 | take_foo(|a: &i32| -> &i32 { a });
| - - ^ returning this value requires that `'1` must outlive `'2`
| | |
| | let's call the lifetime of this reference `'2`
| let's call the lifetime of this reference `'1`
Contributor
|
@rustbot reroll |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Suggest type annotation for closure params on HRTB FnOnce mismatch in next trait solver. Follow up to #158701 (which provided the suggestion in the old trait solver).
in
Fix #158393.