Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
matthiaskrgr opened this issue Sep 9, 2018 · 0 comments · Fixed by #96833
Closed

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

matthiaskrgr opened this issue Sep 9, 2018 · 0 comments · Fixed by #96833
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. F-lint-single_use_lifetimes `single_use_lifetimes` lint T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Sep 9, 2018

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)

@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 9, 2018
@crlf0710 crlf0710 added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2020
@jackh726 jackh726 added the F-lint-single_use_lifetimes `single_use_lifetimes` lint label Mar 18, 2022
@cjgillot cjgillot self-assigned this May 8, 2022
@bors bors closed this as completed in b5caa5a May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. F-lint-single_use_lifetimes `single_use_lifetimes` lint T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants