Skip to content

False positive unused_lifetimes warning #77217

Closed
@Hawk777

Description

@Hawk777

I tried this code:

#![warn(unused_lifetimes)]

pub struct Thingy<'x, X> {
	x: &'x mut X,
	y: &'static str,
}

impl<'x, X> Thingy<'x, X> {
	pub fn new(x: &'x mut X) -> Self {
		Self{x, y: "hello"}
	}

	pub async fn foo(&mut self) -> &'static str {
		self.y
	}
}

I got a warning “lifetime parameter 'x never used”, on the impl line. But it clearly is used. The warning goes away if I delete the function foo, or make it a regular function instead of an asynchronous function.

Meta

rustc --version --verbose:

rustc 1.46.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.46.0
LLVM version: 10.0

I saw #61115 and rust-lang/rust-clippy#3988, but those were both closed at least a year ago and this is still happening in 1.46.0 which was just released recently, so I assume it’s not the same bug.

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions