Skip to content

Errormessage regarding curly braces in for statement #42982

Closed
@Bendrien

Description

@Bendrien

I got the following code:

struct StructWithCurlyBraces {
    _foo: usize
}

impl Iterator for StructWithCurlyBraces {
    type Item = ();
    
    fn next(&mut self) -> Option<Self::Item> {
        None
    }
}

pub fn main() {
    // with surrounding parentheses it works
    for _ in (StructWithCurlyBraces { _foo: 42 }) { }
    
    // without it doesn't
    for _ in StructWithCurlyBraces { _foo: 42 } { }
}

I don't know if the case without surrounding parentheses is intended to work but apart from that the error message is somewhat missleading.

error: expected type, found `42`
  --> <anon>:18:44
   |
18 |     for _ in StructWithCurlyBraces { _foo: 42 } { }
   |                                            ^^

error[E0423]: expected value, found struct `StructWithCurlyBraces`
  --> <anon>:18:14
   |
18 |     for _ in StructWithCurlyBraces { _foo: 42 } { }
   |              ^^^^^^^^^^^^^^^^^^^^^ did you mean `StructWithCurlyBraces { /* fields */ }`?

error: aborting due to 2 previous errors

It seems that the tokenizer doesn't get this right?

Edit: Include error message

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions