-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Running this code on the latest stable (1.38.0) as well as nightly (2019-10-20)
fn foo<F, I>(i: &mut I)
where
F: FnMut(),
I: std::ops::IndexMut<(), Output = F>,
{
i[()](); // fails
(&mut i[()])(); // works
}gives the error
error[E0596]: cannot borrow data in an index of `I` as mutable
--> src/lib.rs:6:5
|
6 | i[()](); // fails
| ^^^^^ cannot borrow as mutable
|
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `I`
which is clearly wrong.
Notably, the same error does not occur if we switch everything to Fn:
fn foo<F, I>(i: &I)
where
F: Fn(),
I: std::ops::Index<(), Output = F>,
{
i[()](); // works
}Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.