Skip to content

Mutability issue while indexing static immutable array #46095

Closed
@vitvakatu

Description

Hello, today we've found some weird behaviour of array indexing.
Here is the example
Code snippet:

fn foo<'a>(a1: &'a mut Bar, a2: &'a mut Bar)
{
	let a = [a1, a2];
	for i in 0..42
	{
		let index = i % 2;
		//a[i % 2].bar(); //<= error
		a[index].bar(); //<= no error
	}
}

The question is, why is the indexing operator behaves depending on whether we evaluate index in place or not.

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions