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;
fn main() {}

src/a.rs

#[warn(single_use_lifetimes)]
#[derive(Debug)]
pub(crate) struct pathThing {
    pub(crate) path: std::path::Path,
}
#[derive(Debug, Clone)]
pub(crate) struct DirSizes<'a> {
    pub(crate) b: &'a pathThing,
}
impl<'a> DirSizes<'a> {
    pub(crate) fn new(a: &'a pathThing) -> Self {
        let b = &a;
        Self { b }
    }
}
impl<'a> std::fmt::Display for DirSizes<'a> {
    fn fmt(&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)

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    on Sep 9, 2018
  2. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 11, 2020
  3. self-assigned this
    on May 8, 2022
  4. added a commit that references this issue on May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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