Rust: Regression of #53738: spurious single_use_lifetimes warning

Created on 12 Mar 2020  路  7Comments  路  Source: rust-lang/rust

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

A-edition-2018-lints A-lifetimes A-lint C-bug ICEBreaker-Cleanup-Crew P-medium T-compiler regression-from-stable-to-stable

Most helpful comment

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.

All 7 comments

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.

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.

@rustbot ping cleanup

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

bisect-rustc:

searched nightlies: from nightly-2019-09-01 to nightly-2020-03-10
regressed nightly: nightly-2019-10-28
searched commits: from https://github.com/rust-lang/rust/commit/fae75cd216c481de048e4951697c8f8525669c65 to https://github.com/rust-lang/rust/commit/95f437b3cfb2fec966d7eaf69d7c2e36f9c274d1
regressed commit: https://github.com/rust-lang/rust/commit/b7176b44a203322c834302f3b515f8c10a54f2c1
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.

cc @pnkfelix , is it a good idea to assign this one to you Felix? regressed here https://github.com/rust-lang/rust/pull/65519

@rustbot modify labels: -E-needs-bisection

Was this page helpful?
0 / 5 - 0 ratings