Skip to content

diagnostics: fp single_use_lifetimes: only used in #[derive(Trait)] #54079

Description

@matthiaskrgr

cargo.toml

cargo-features = ["edition"]
[package]
name = "warn"version = "0.1.0"authors = ["me"]
edition = "2018"
[dependencies]

src/main.rs

#![warn(single_use_lifetimes)]mod a;fnmain(){}

src/a.rs

#[warn(single_use_lifetimes)]#[derive(Debug)]pub(crate)structpathThing{pub(crate)path: std::path::Path,}#[derive(Debug,Clone)]pub(crate)structDirSizes<'a>{pub(crate)b:&'apathThing,}impl<'a>DirSizes<'a>{pub(crate)fnnew(a:&'apathThing) -> Self{let b = &a;Self{ b }}}impl<'a> std::fmt::DisplayforDirSizes<'a>{fnfmt(&self,f:&'_mut std::fmt::Formatter<'_>) -> std::fmt::Result{write!(f,"{}","hello")?;Ok(())}}

when building, I get

warning: lifetime parameter `'a` only used once
--> src/a.rs:19:6
|
19 | impl<'a> std::fmt::Display for DirSizes<'a> {
| ^^ this lifetime... -- ...is used only here
|
note: lint level defined here
--> src/main.rs:1:9
|
1 | #![warn(single_use_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^
warning: lifetime parameter `'a` only used once
--> src/a.rs:8:28
|
7 | #[derive(Debug, Clone)]
| ----- ...is used only here
8 | pub(crate) struct DirSizes<'a> {
| ^^ this lifetime...
warning: method is never used: `new`
--> src/a.rs:13:5
|
13 | pub(crate) fn new(a: &'a pathThing) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default
warning: type `pathThing` should have a camel case name such as `Paththing`
--> src/a.rs:3:1
|
3 | / pub(crate) struct pathThing {
4 | | pub(crate) path: std::path::Path,
5 | | }
| |_^
|
= note: #[warn(non_camel_case_types)] on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.41

the

warning: lifetime parameter `'a` only used once
--> src/a.rs:8:28
|
7 | #[derive(Debug, Clone)]
| ----- ...is used only here
8 | pub(crate) struct DirSizes<'a> {
| ^^ this lifetime...

is what looks sorta wrong.
rustc 1.30.0-nightly (0198a1ea4 2018-09-08)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.L-single_use_lifetimesLint: single_use_lifetimesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions