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

Regression of #53738: spurious single_use_lifetimes warning #69952

Closed
stouset opened this issue Mar 12, 2020 · 8 comments · Fixed by #96833 or #103089
Closed

Regression of #53738: spurious single_use_lifetimes warning #69952

stouset opened this issue Mar 12, 2020 · 8 comments · Fixed by #96833 or #103089
Assignees
Labels
A-edition-2018-lints Area: Lints supporting the 2018 edition A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-lint-single_use_lifetimes `single_use_lifetimes` lint ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@stouset
Copy link

stouset commented Mar 12, 2020

Issue #53738 seems to have regressed.

I tried this code:

#[deny(single_use_lifetimes)]

#[derive(Eq)]
struct Foo<'a, T> {
    /// a reference to the underlying secret data that will be derefed
    pub data: &'a mut T,
}

I expected to see this happen: No warning should be produced.

Instead, this happened:

error: lifetime parameter `'a` only used once
 --> src/lib.rs:4:12
  |
3 | #[derive(Eq)]
  |          -- ...is used only here
4 | struct Foo<'a, T> {
  |            ^^ this lifetime...
  |
note: lint level defined here
 --> src/lib.rs:1:8
  |
1 | #[deny(single_use_lifetimes)]
  |        ^^^^^^^^^^^^^^^^^^^^

Meta

rustc --version --verbose:

rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-apple-darwin
release: 1.42.0
LLVM version: 9.0
@stouset stouset added the C-bug Category: This is a bug. label Mar 12, 2020
@jonas-schievink jonas-schievink added I-nominated regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-edition-2018-lints Area: Lints supporting the 2018 edition labels Mar 12, 2020
@jonas-schievink
Copy link
Contributor

From what I can tell, the Eq case might have never worked, since Debug still doesn't warn (so the linked issue specifically maybe didn't regress, only a closely related example incorrectly warns). This needs confirmation though.

@jonas-schievink jonas-schievink added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Mar 12, 2020
@cuviper
Copy link
Member

cuviper commented Mar 12, 2020

It also fails in 1.40 and 1.41.

It gets a different error in 1.39, with Eq complaining that PartialEq is not implemented, but if you add that then it does compile successfully.

@RalfJung RalfJung changed the title Regression of #53738 Regression of #53738: spurious single_use_lifetimes warning Mar 13, 2020
@spastorino
Copy link
Member

@rustbot ping cleanup

@Centril Centril added the P-medium Medium priority label Mar 18, 2020
@rustbot rustbot added ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections and removed P-medium Medium priority labels Mar 18, 2020
@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2020

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke

@Centril Centril added P-medium Medium priority and removed I-nominated labels Mar 18, 2020
@chrissimpkins
Copy link
Member

chrissimpkins commented Mar 18, 2020

bisect-rustc:

searched nightlies: from nightly-2019-09-01 to nightly-2020-03-10
regressed nightly: nightly-2019-10-28
searched commits: from fae75cd to 95f437b
regressed commit: b7176b4
source code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4bd9c10c79f908d449f607e5ce69bfa7

#[deny(single_use_lifetimes)]
#[derive(Eq)]
struct Foo<'a, T> {
    _y: &'a mut T,
}
impl<T> PartialEq for Foo<'_, T> {
    fn eq(&self, _x: &Self) -> bool {
        true
    }
}

Builds without errors as of rustc 1.39.0 and earlier (tested on godbolt)

Error

COLLAPSIBLE ERROR STACKTRACE

error: lifetime parameter `'a` only used once
 --> src/main.rs:4:12
  |
3 | #[derive(Eq)]
  |          -- ...is used only here
4 | struct Foo<'a, T> {
  |            ^^ this lifetime...
  |
note: the lint level is defined here
 --> src/main.rs:1:8
  |
1 | #[deny(single_use_lifetimes)]
  |        ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile `bisectit`.

To learn more, run the command again with --verbose.

@spastorino
Copy link
Member

spastorino commented Mar 20, 2020

cc @pnkfelix , is it a good idea to assign this one to you Felix? regressed here #65519

@LeSeulArtichaut
Copy link
Contributor

@rustbot modify labels: -E-needs-bisection

@rustbot rustbot removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Mar 20, 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
@jyn514
Copy link
Member

jyn514 commented Jun 15, 2022

@dylni points out this is not actually fixed: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=3dcd3a8a7f8b85cc732d738bf6e57dc2
cc @cjgillot

@bors bors closed this as completed in 2c0bfbe Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018-lints Area: Lints supporting the 2018 edition A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-lint-single_use_lifetimes `single_use_lifetimes` lint ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet