Skip to content

Backwards-incompatible lifetime change (regression) #85574

Closed
@staktrace

Description

@staktrace
Contributor

I tried this:

rustup update nightly
git clone https://github.com/rust-lang/git2-rs && cd git2-rs
cargo +nightly build

I expected to see this happen: build completes

Instead, this happened: build failed with this output:

error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
  --> src/attr.rs:74:15
   |
74 |         match (self, other) {
   |               ^^^^^^^^^^^^^
   |
note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 73:26...
  --> src/attr.rs:73:26
   |
73 |     fn eq(&self, other: &AttrValue<'_>) -> bool {
   |                          ^^^^^^^^^^^^^
note: ...so that the types are compatible
  --> src/attr.rs:74:15
   |
74 |         match (self, other) {
   |               ^^^^^^^^^^^^^
   = note: expected `(&AttrValue<'_>, &AttrValue<'_>)`
              found `(&AttrValue<'_>, &AttrValue<'_>)`
note: but, the lifetime must be valid for the lifetime `'_` as defined on the impl at 72:30...
  --> src/attr.rs:72:30
   |
72 | impl PartialEq for AttrValue<'_> {
   |                              ^^
note: ...so that the types are compatible
  --> src/attr.rs:79:16
   |
79 |             | (Self::Bytes(bytes), AttrValue::String(string)) => string.as_bytes() == *bytes,
   |                ^^^^^^^^^^^^^^^^^^
   = note: expected `AttrValue<'_>`
              found `AttrValue<'_>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
error: could not compile `git2`

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

Meta

rustc +nightly --version --verbose:

rustc 1.54.0-nightly (5dc8789e3 2021-05-21)
binary: rustc
commit-hash: 5dc8789e300930751a78996da0fa906be5a344a2
commit-date: 2021-05-21
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1

This was working with the rustc nightly from rustc 1.54.0-nightly (f94942d84 2021-05-19) so this is a very recent regression.

Activity

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on May 22, 2021
added
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
on May 22, 2021
Mark-Simulacrum

Mark-Simulacrum commented on May 22, 2021

@Mark-Simulacrum
Member

Might be #85511, but would be good to bisect.

ehuss

ehuss commented on May 22, 2021

@ehuss
Contributor

Bisect confirmed it is #85511. This is blocking cargo's CI. Let me know if there's any way I can help.

ehuss

ehuss commented on May 22, 2021

@ehuss
Contributor

Here's a reproduction:

pub enum Foo<'string> {
    String(&'string str),
}

impl Foo<'_> {
    fn f(&self, other: &Foo<'_>) {
        match (self, other) {
            // Important: a and b swap between the two patterns, and one pattern uses `Self`
            (Foo::String(a), Foo::String(b))
            | (Self::String(b), Foo::String(a)) => {}
        }
    }
}

I couldn't get it smaller than that.

I don't know if this is helpful, but the following will ICE on stable/beta, but returns E0495 on nightly:

enum Foo<'a> {
    Var(&'a str)
}

impl Foo<'_> {
    fn f(other: Foo<'_>) {
        match other {
            Self::Var(..) => {}
        }
    }
}
matthiaskrgr

matthiaskrgr commented on May 22, 2021

@matthiaskrgr
Member

Note for those also affected by this:
git2 0.12 still builds so you might be able to temporarily downgrade your git2 dependency as a workaround until there is a solution.

Mark-Simulacrum

Mark-Simulacrum commented on May 22, 2021

@Mark-Simulacrum
Member

Cc @nikomatsakis

I'd lean towards reverting for now (and potentially landing as future compat or something). I'm not sure if this is technically a soundness fix, Niko can likely give a better reading there. I think the problem is that Self::String as a constructor is now (I believe arguably correctly, but not sure if it has any soundness implications) requiring the argument to outlive the lifetime on Self - but of course this isn't necessarily true of the other branch.

This means that changing Self to the actual name of the type will fix this, so maybe patching git2 quickly is a good idea; it'll fix things before the next nightly at least for Cargo.

added and removed
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
on May 22, 2021

47 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-highHigh priorityT-releaseRelevant to the release subteam, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.relnotesMarks issues that should be documented in the release notes of the next release.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cuviper@ehuss@arturoc@nikomatsakis@matthiaskrgr

        Issue actions

          Backwards-incompatible lifetime change (regression) · Issue #85574 · rust-lang/rust