Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borrow check error with "unknown scope" region for callee's self parameter #4464

Closed
jld opened this issue Jan 13, 2013 · 8 comments
Closed
Labels
A-lifetimes Area: Lifetimes / regions E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@jld
Copy link
Contributor

jld commented Jan 13, 2013

A reduced test case, which seems as if it should be valid:

fn broken(v: &r/[u8], i: uint, j: uint) -> &r/[u8] { v.view(i, j) }

The error:

src/test.rs:1:53: 1:54 error: illegal borrow: borrowed value does not live long enough
src/test.rs:1 fn broken(v: &r/[u8], i: uint, j: uint) -> &r/[u8] { v.view(i, j) }
                                                                   ^
src/test.rs:1:51: 1:67 note: borrowed pointer must be valid for the lifetime &r as defined on the block at 1:51...
src/test.rs:1 fn broken(v: &r/[u8], i: uint, j: uint) -> &r/[u8] { v.view(i, j) }
                                                                 ^~~~~~~~~~~~~~~~
note: ...but borrowed value is only valid for unknown scope: 34.  Please report a bug.
error: aborting due to previous error
@ghost ghost assigned nikomatsakis Jan 13, 2013
@nikomatsakis
Copy link
Contributor

Looks broken all right.

@graydon
Copy link
Contributor

graydon commented Mar 22, 2013

no longer ICE; it now responds to updated input:

fn broken(v: &'r [u8], i: uint, j: uint) -> &'r [u8] { v.slice(i, j) }

with:

4464.rs:1:55: 1:56 error: illegal borrow: borrowed value does not live long enough
4464.rs:1 fn broken(v: &'r [u8], i: uint, j: uint) -> &'r [u8] { v.slice(i, j) }
                                                                 ^
4464.rs:1:53: 1:70 note: borrowed pointer must be valid for the lifetime &'r  as defined on the block at 1:53...
4464.rs:1 fn broken(v: &'r [u8], i: uint, j: uint) -> &'r [u8] { v.slice(i, j) }
                                                               ^~~~~~~~~~~~~~~~~
4464.rs:1:0: 1:70 note: ...but borrowed value is only valid for the function body at 1:0
4464.rs:1 fn broken(v: &'r [u8], i: uint, j: uint) -> &'r [u8] { v.slice(i, j) }
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

This looks like a reasonable error to mem except, hm, I think probably the signature of slice isn't right? Or something. Leaving open but moving off the priority list for 0.6 (and removed ICE label)

@jld
Copy link
Contributor Author

jld commented Mar 26, 2013

fn slice(&self, start: uint, end: uint) -> &'self [T];, inside impl<T> ImmutableVector<T> for &'self [T].

I think the problem is the last part: the lifetime of the pointer/length pair itself shouldn't be constrained to be equal to the lifetime of the pointed-to data like that. So impl<T, 'r> ImmutableVector<T> for &'r [T], maybe?

@nikomatsakis
Copy link
Contributor

This is rather related to #5656. I'll take a look as I work.

@nikomatsakis
Copy link
Contributor

I think I have the fix for this problem (inadvertently, actually).

@nikomatsakis
Copy link
Contributor

Never mind, I was wrong. It seemed related to another problem that I found, but the fix for that issue doesn't seem to have fixed this test case. I'll look at this more specifically shortly.

@catamorphism
Copy link
Contributor

@graydon 's code compiles now (modified to take the lifetime parameter explicitly). I'll add a test case.

@ghost ghost assigned catamorphism May 24, 2013
@emberian
Copy link
Member

Still needs test, updated syntax: fn broken<'r>(v: &'r [u8], i: uint, j: uint) -> &'r [u8] { v.slice(i, j) }

bors added a commit that referenced this issue Aug 15, 2013
Closes #3907
Closes #5493
Closes #4464
Closes #4759
Closes #5666
Closes #5884
Closes #5926
Closes #6318
Closes #6557
Closes #6898
Closes #6919
Closes #7222
calebcartwright pushed a commit to calebcartwright/rust that referenced this issue Nov 8, 2021
* Document RUSTFMT env var

* Move documentation up

* Apply suggestions from code review

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

* Fix accedental removal

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
# Conflicts:
#	README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants