Skip to content

Commit a335827

Browse files
authored
Merge pull request #2680 from BoxyUwU/binders_example_error
make more clear code snippet is supposed to error
2 parents 7a1898a + ff59c1a commit a335827

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/ty_module/instantiating_binders.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instantiating `Binder`s
22

3-
Much like [`EarlyBinder`], when accessing the inside of a [`Binder`] we must first discharge it by replacing the bound vars with some other value. This is for much the same reason as with `EarlyBinder`, types referencing parameters introduced by the `Binder` do not make any sense outside of that binder, for example:
3+
Much like [`EarlyBinder`], when accessing the inside of a [`Binder`] we must first discharge it by replacing the bound vars with some other value. This is for much the same reason as with `EarlyBinder`, types referencing parameters introduced by the `Binder` do not make any sense outside of that binder. See the following erroring example:
44
```rust,ignore
55
fn foo<'a>(a: &'a u32) -> &'a u32 {
66
a
@@ -11,10 +11,11 @@ fn bar<T>(a: fn(&u32) -> T) -> T {
1111
1212
fn main() {
1313
let higher_ranked_fn_ptr = foo as for<'a> fn(&'a u32) -> &'a u32;
14+
// Attempt to infer `T=for<'a> &'a u32` which is not satsifiable
1415
let references_bound_vars = bar(higher_ranked_fn_ptr);
1516
}
1617
```
17-
In this example we are providing an argument of type `for<'a> fn(&'^0 u32) -> &'^0 u32` to `bar`, we do not want to allow `T` to be inferred to the type `&'^0 u32` as it would be rather nonsensical (and likely unsound if we did not happen to ICE, `main` has no idea what `'a` is so how would the borrow checker handle a borrow with lifetime `'a`).
18+
In this example we are providing an argument of type `for<'a> fn(&'^0 u32) -> &'^0 u32` to `bar`, we do not want to allow `T` to be inferred to the type `&'^0 u32` as it would be rather nonsensical (and likely unsound if we did not happen to ICE). `main` doesn't know about `'a` so the borrow checker would not be able to handle a borrow with lifetime `'a`.
1819

1920
Unlike `EarlyBinder` we typically do not instantiate `Binder` with some concrete set of arguments from the user, i.e. `['b, 'static]` as arguments to a `for<'a1, 'a2> fn(&'a1 u32, &'a2 u32)`. Instead we usually instantiate the binder with inference variables or placeholders.
2021

0 commit comments

Comments
 (0)