Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Backwards-incompatible lifetime change (regression) #85574

Closed

Description

@staktrace

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

  1. added
    C-bug
    on May 22, 2021
  2. added
    regression-from-stable-to-nightly
    on May 22, 2021
  3. added
    I-prioritize
    on May 22, 2021
  4. added
    E-needs-bisection
    on May 22, 2021
  5. Mark-Simulacrum commented on May 22, 2021

    @Mark-Simulacrum
    Member

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

  6. 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.

  7. 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(..) => {}
            }
        }
    }
  8. 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.

  9. 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.

  10. added
    P-critical
    and removed
    E-needs-bisection
    on May 22, 2021
  11. added this to the 1.54.0 milestone on May 22, 2021
  12. staktrace commented on May 22, 2021

    @staktrace
    ContributorAuthor

    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.

    Replacing the <'_> with <'a> in src/attr.rs in git2 seems to fix the error (with appropriate decorations on the impl)

  13. 14 remaining items

  14. changed the title [-]Backwards-incompatible lifetime change (regression) introduced in 2021-05-21[/-] [+]Backwards-incompatible lifetime change (regression)[/+] on Jul 2, 2021
  15. arturoc commented on Aug 11, 2021

    @arturoc
    Contributor

    I'm getting a similar problem on some rust code after updating stable from 1.53 to 1.54. Will try to find a small example to post but it seems related to use for<'a> ... to specify bounds on a trait implementation

  16. added a commit that references this issue on Aug 12, 2021
  17. nbdd0121 commented on Oct 4, 2021

    @nbdd0121
    Member

    A slightly modified version of @ehuss's mcve:

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

    This wouldn't compile on 1.53. The only change is to spell Self out explicitly (with Foo::<'a>). So I would say this should indeed be considered as a bugfix. I guess the issue should be closed? (at least it shouldn't be P-critical)

    Also the effected version is 1.54+, so retag:
    @rustbot label -regression-from-stable-to-beta +regression-from-stable-to-stable

  18. rustbot commented on Oct 4, 2021

    @rustbot
    Collaborator

    Error: Parsing relabel command in comment failed: ...'-to-beta +' | error: empty label at >| ' regressio'...

    Please let @rust-lang/release know if you're having trouble with this bot.

  19. added
    regression-from-stable-to-stable
    and removed
    regression-from-stable-to-beta
    on Oct 4, 2021
  20. apiraino commented on Dec 2, 2021

    @apiraino
    Contributor

    Demoting to P-high after reading the latest comments

    @rustbot label -P-critical +P-high

  21. added
    P-high
    and removed
    P-critical
    on Dec 2, 2021
  22. apiraino commented on Feb 3, 2022

    @apiraino
    Contributor

    I think this issue can be closed since the release notes were amended to also include this compatibility note in commit 9fc2bfa

    @rustbot label +T-release

  23. added
    T-release
    on Feb 3, 2022
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-bugP-highT-releaseregression-from-stable-to-stablerelnotes

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions