Match default modes failure -- bug? (no)


#1

https://play.rust-lang.org/?gist=43a5b1dd39f48f5cb452dca9f8c8fea5&version=stable&mode=debug

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?


#2

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

https://play.rust-lang.org/?gist=a9a2e64fe2acaf6786ce31d5744559ba&version=stable&mode=debug

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`

#3

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


#4

match on Struct?