- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
I was going trough the Learning Rust with entirely too many linked lists tutorial. I have my editor set to give me warnings from clippy. In section 3.1 the tutorial has you replacing a type with an Option, and then changing a couple of of mem::replace instances with the take() method on Option. I thought to myself "huh, that's always better, that should be a lint". So I googled, and turns out it is a lint, but for some reason the lint doesn't trigger on the code in the tutorial.
Lint Name
mem_replace_option_with_none
Reproducer
This is the code from the tutorial, but with the irrelevant parts cut out:
use std::mem; pub struct List { head: Option<Box<Node>>, } struct Node { #[allow(dead_code)] // to get rid of that warning since I cut the code that read from it next: Option<Box<Node>>, } impl List { pub fn push(&mut self) { let new_node = Box::new(Node { next: mem::replace(&mut self.head, None), }); self.head = Some(new_node); } }
To reproduce create a new with cargo library crate, paste into lib.rs, and run cargo clippy.
The lint is not triggered for the mem::replace on line 15.
Version
rustc 1.65.0 (897e37553 2022-11-02) binary: rustc commit-hash: 897e37553bba8b42751c67658967889d11ecd120 commit-date: 2022-11-02 host: x86_64-unknown-linux-gnu release: 1.65.0 LLVM version: 15.0.0
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't