Match default modes failure -- bug? (no)

struct Rule;
struct Position;

enum Token {
    Start {
        rule: Rule,
        pos: Position,
    }
}

struct FmtToken(Token);

impl FmtToken {
    fn foo(&self) {
        match self.0 {
            Token::Start { rule, pos } => unimplemented!(),
        }
    }
}
error[E0507]: cannot move out of borrowed content
  --> src/main.rs:15:15
   |
15 |         match self.0 {
   |               ^^^^ cannot move out of borrowed content
16 |             Token::Start { rule, pos } => unimplemented!(),
   |                            ----  --- ...and here (use `ref pos` or `ref mut pos`)
   |                            |
   |                            hint: to prevent move, use `ref rule` or `ref mut rule`

I just ran into this. Shouldn't match-default-modes be inserting ref-mode here?

Reduced it by one nesting level, still gives an error:

struct Token {
    rule: Rule,
    pos: Position,
}

struct FmtToken(Token);

impl FmtToken {
    fn foo(&self) {
        match self.0 {
            Token { rule, pos } => unimplemented!(),
        }
    }
}
error[E0507]: cannot move out of borrowed content
  --> src/main.rs:13:15
   |
13 |         match self.0 {
   |               ^^^^ cannot move out of borrowed content
14 |             Token { rule, pos } => unimplemented!(),
   |                     ----  --- ...and here (use `ref pos` or `ref mut pos`)
   |                     |
   |                     hint: to prevent move, use `ref rule` or `ref mut rule`

The expression self.0 has type Token by value. If you change to match &self.0 then the compiler gives you implied refs.

1 Like

match on Struct?