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

Incorrect loan error when local borrowed variable is updated to new loan #5550

Closed
lifthrasiir opened this issue Mar 26, 2013 · 2 comments
Closed

Comments

@lifthrasiir
Copy link
Contributor

The following code...

fn main() {
    let s: ~str = ~"foobar";
    let mut t: &str = s;
    t = t.slice(0, 3); // for master: str::view(t, 0, 3) maybe
}

...results in the following error:

t.rs:4:4: 4:5 error: assigning to mutable local variable prohibited due to outstanding loan
t.rs:4     t = t.slice(0, 3);
           ^
t.rs:4:8: 4:9 note: loan of mutable local variable granted here
t.rs:4     t = t.slice(0, 3);
               ^

Both t and t.slice(0, 3) are loans of s, so it should be safe to update t to new loan of s as updating t doesn't cause s to be freed.

@catamorphism
Copy link
Contributor

This works now; I'll check in the test case.

@ghost ghost assigned catamorphism May 24, 2013
catamorphism added a commit to catamorphism/rust that referenced this issue May 28, 2013
@catamorphism
Copy link
Contributor

Test case checked in in 9a06ff0. Closing

flip1995 pushed a commit to flip1995/rust that referenced this issue May 5, 2020
Implement the manual_non_exhaustive lint

Some implementation notes:
* Not providing automatic fixups because additional changes may be needed in other parts of the code, e.g. when constructing a struct.
* Even though the attribute is valid on enum variants, it's not possible to use the manual implementation of the pattern because the visibility is always public, so the lint ignores enum variants.
* Unit structs are also ignored, it's not possible to implement the pattern manually without fields.
* The attribute is not accepted in unions, so those are ignored too.
* Even though the original issue did not mention it, tuple structs are also linted because it's possible to apply the pattern manually.

changelog: Added the manual non-exhaustive implementation lint

Closes rust-lang#2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants