Skip to content

Commit 800f1f3

Browse files
Liberate late-bound regions correctly
1 parent 95b61d1 commit 800f1f3

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3758,13 +3758,13 @@ fn hint_missing_borrow<'tcx>(
37583758
err: &mut Diagnostic,
37593759
) {
37603760
let found_args = match found.kind() {
3761-
ty::FnPtr(f) => f.inputs().skip_binder().iter(),
3761+
ty::FnPtr(f) => infcx.replace_bound_vars_with_placeholders(*f).inputs().iter(),
37623762
kind => {
37633763
span_bug!(span, "found was converted to a FnPtr above but is now {:?}", kind)
37643764
}
37653765
};
37663766
let expected_args = match expected.kind() {
3767-
ty::FnPtr(f) => f.inputs().skip_binder().iter(),
3767+
ty::FnPtr(f) => infcx.replace_bound_vars_with_placeholders(*f).inputs().iter(),
37683768
kind => {
37693769
span_bug!(span, "expected was converted to a FnPtr above but is now {:?}", kind)
37703770
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use std::cell::RefCell;
2+
use std::collections::HashMap;
3+
use std::rc::Rc;
4+
5+
pub struct Trader<'a> {
6+
closure: Box<dyn Fn(&mut Trader) + 'a>,
7+
}
8+
9+
impl<'a> Trader<'a> {
10+
pub fn new() -> Self {
11+
Trader {
12+
closure: Box::new(|_| {}),
13+
}
14+
}
15+
pub fn set_closure(&mut self, function: impl Fn(&mut Trader) + 'a) {
16+
//foo
17+
}
18+
}
19+
20+
fn main() {
21+
let closure = |trader : Trader| {
22+
println!("Woooosh!");
23+
};
24+
25+
let mut trader = Trader::new();
26+
trader.set_closure(closure);
27+
//~^ ERROR type mismatch in closure arguments
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0631]: type mismatch in closure arguments
2+
--> $DIR/late-bound-in-borrow-closure-sugg.rs:26:24
3+
|
4+
LL | let closure = |trader : Trader| {
5+
| ----------------- found signature defined here
6+
...
7+
LL | trader.set_closure(closure);
8+
| ----------- ^^^^^^^ expected due to this
9+
| |
10+
| required by a bound introduced by this call
11+
|
12+
= note: expected closure signature `for<'a, 'b> fn(&'a mut Trader<'b>) -> _`
13+
found closure signature `for<'a> fn(Trader<'a>) -> _`
14+
note: required by a bound in `Trader::<'a>::set_closure`
15+
--> $DIR/late-bound-in-borrow-closure-sugg.rs:15:50
16+
|
17+
LL | pub fn set_closure(&mut self, function: impl Fn(&mut Trader) + 'a) {
18+
| ^^^^^^^^^^^^^^^ required by this bound in `Trader::<'a>::set_closure`
19+
help: consider borrowing the argument
20+
|
21+
LL | let closure = |trader : &Trader| {
22+
| +
23+
24+
error: aborting due to previous error
25+
26+
For more information about this error, try `rustc --explain E0631`.

0 commit comments

Comments
 (0)