question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spurious "Use of moved value" on a u32

See original GitHub issue

Environment

  • Plugin 0.2.114.2151-193
  • Rust 1.40.0
  • CLion 2019.3
  • Windows

Problem description

I have code that imports std::u32 to get at the u32::MAX const, but it seems to generate a spurious “use of moved value” when I use the same u32 twice in a function:

Steps to reproduce

In my code base, the word first on the line under “next: first,” is underlined and marked with error “use of moved value”. I assume the plugin sees that I used it on the line previous, thinking it was a move, but as it is a u32 so the compiler would done a copy not a move.

use std::u32;

#[derive(Debug, Clone)]
pub struct Handle {
    next: u32,
    first: u32,
}

impl Handle {
    /// Creates a new handle factory, that starts with the supplied number
    pub fn new(first: u32) -> Handle {
        Handle {
            next: first,
            first, // <-- ERROR HERE
        }
    }

    /// Returns the next handle to be issued, internally incrementing each time so the handle
    /// is always different until it wraps back to the start.
    pub fn next(&mut self) -> u32 {
        let next = self.next;
        // Increment next
        if self.next == u32::MAX {
            self.next = self.first;
        } else {
            self.next += 1;
        }
        next
    }

    pub fn set_next(&mut self, next: u32) {
        self.next = next;
    }

    /// Resets the handle to its initial state
    pub fn reset(&mut self) {
        self.set_next(self.first);
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
locka99commented, Jan 31, 2020

No I don’t. It’s a stable rust set through “rustup default stable-gnu”. I’ll get back to you tonight because one machine can’t fetch from crates.io at the moment and I want to reproduce the behaviour from a machine that is building normally.

0reactions
locka99commented, Jan 31, 2020

I’m going to close the issue because it works on the other computer. I think it is because the external crates could not be fetched there was nothing in External Libraries, even a reference to Rust’s own stdlib.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What do I have to do to solve a "use of moved value" error?
When a function requires a parameter by value, the compiler will check if the value can be copied by checking if it implements...
Read more >
A hammer you can only hold by the handle
Note that use_name takes name 's ownership (and it's not pass-by-reference) so name is moved on line 5, and it cannot be used...
Read more >
Rust for Embedded C Programmers | OpenTitan Documentation
Reference lifetimes start when the reference is taken, and end either when the lifetime goes out of scope or when the value referenced...
Read more >
A hammer you can only hold by the handle - Andrea Lattuada
Note that use_name takes name 's ownership (and it's not pass-by-reference) so name is moved on line 5, and it cannot be used...
Read more >
How to solve this "used of moved value" issue - help
Hi, I am new to Rust. Currently I'm confused about this kind of problem. My code may look like this: pub fn test(mut...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found