Skip to content

Erroneous error note for using field after move with NLL enabled #51512

Closed
@carado

Description

@carado

Hi, I noticed that the error for the following code:

#![feature(nll)]
fn main() {
    let range = 0 .. 1;
    let r = range;
    let x = range.start;
}

is this:

error[E0382]: use of moved value: `range.start`
 --> src/main.rs:5:13
  |
4 |     let r = range;
  |             ----- value moved here
5 |     let x = range.start;
  |             ^^^^^^^^^^^ value used here after move
  |
  = note: move occurs because `range.start` has type `i32`, which does not implement the `Copy` 

Notice the weird error note.

Without NLL enabled, the error becomes the more expected:

error[E0382]: use of moved value: `range.start`
 --> src/main.rs:4:9
  |
3 |     let r = range;
  |         - value moved here
4 |     let x = range.start;
  |         ^ value used here after move
  |
  = note: move occurs because `range` has type `std::ops::Range<i32>`, which does not implement the `Copy` trait

I'm running the latest nightly (as of this writing), which I got from rustup.

rustc 1.28.0-nightly (a805a2a5e 2018-06-10)
binary: rustc
commit-hash: a805a2a5ebba2802f432d79874e59c24e398f82a
commit-date: 2018-06-10
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0

Thanks for your time.

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)C-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.NLL-diagnosticsWorking towards the "diagnostic parity" goal

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions