Skip to content

Incorrect borrowing suggestion for range literals #54505

Closed
@varkor

Description

@varkor
use std::ops::RangeInclusive;

fn take_range(r: &RangeInclusive<i8>) {}

fn main() {
    take_range(0..=1);
}
error[E0308]: mismatched types
 --> src/main.rs:6:16
  |
6 |     take_range(0..=1);
  |                ^^^^^
  |                |
  |                expected reference, found struct `std::ops::RangeInclusive`
  |                help: consider borrowing here: `&0..=1`
  |
  = note: expected type `&std::ops::RangeInclusive<i8>`
             found type `std::ops::RangeInclusive<{integer}>`

&0..=1 is an incorrect suggestion because & has higher precedence than ..=. It should suggest &(0..=1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions