-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priorityMedium priorityT-langRelevant to the language teamRelevant to the language teamfixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
Description
UPDATE: This was fixed by #47167 but still needs a regression test to be added.
fn main() {
let mut i = [1,2,3];
i[i[0]] = 0; // Works
i[i[0] - 1] = 0; // Is rejected
}
I had expect the - 1
not to make any difference, but the borrow checker complains with the following error:
<anon>:4:7: 4:11 error: cannot use `i[..]` because it was mutably borrowed
<anon>:4 i[i[0] - 1] = 0;
^~~~
<anon>:4:5: 4:6 note: borrow of `i` occurs here
<anon>:4 i[i[0] - 1] = 0;
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priorityMedium priorityT-langRelevant to the language teamRelevant to the language teamfixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.