Rust: cannot infer lifetime for type_id

Created on 6 Mar 2019  路  4Comments  路  Source: rust-lang/rust

from a crater run:

Error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
[INFO] [stderr]    --> /opt/crater/cargo-home/registry/src/github.com-1ecc6299db9ec823/data-buffer-0.4.3/src/lib.rs:214:38
[INFO] [stderr]     |
[INFO] [stderr] 214 |         if TypeId::of::<T>() != self.type_id() { None } else { Some(self) }
[INFO] [stderr]     |                                      ^^^^^^^
[INFO] [stderr]     |
[INFO] [stderr] note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 213:5...
[INFO] [stderr]    --> /opt/crater/cargo-home/registry/src/github.com-1ecc6299db9ec823/data-buffer-0.4.3/src/lib.rs:213:5
[INFO] [stderr]     |
[INFO] [stderr] 213 | /     pub fn check_mut<T: Any>(&mut self) -> Option<&mut Self> {
[INFO] [stderr] 214 | |         if TypeId::of::<T>() != self.type_id() { None } else { Some(self) }
[INFO] [stderr] 215 | |     }
[INFO] [stderr]     | |_____^
[INFO] [stderr]     = note: ...so that the types are compatible:
[INFO] [stderr]             expected &&mut DataBuffer
[INFO] [stderr]                found &&mut DataBuffer
[INFO] [stderr]     = note: but, the lifetime must be valid for the static lifetime...
[INFO] [stderr] note: ...so that the type `&mut DataBuffer` will meet its required lifetime bounds
[INFO] [stderr]    --> /opt/crater/cargo-home/registry/src/github.com-1ecc6299db9ec823/data-buffer-0.4.3/src/lib.rs:214:38
[INFO] [stderr]     |
[INFO] [stderr] 214 |         if TypeId::of::<T>() != self.type_id() { None } else { Some(self) }

crate affected: data-buffer
Owner: @elrnv
Log:
https://crater-reports.s3.amazonaws.com/beta-1.34-1/beta-2019-02-27/reg/data-buffer-0.4.3/log.txt

T-libs regression-from-stable-to-beta

Most helpful comment

Reduced I believe this looks like:

use std::any::Any;

struct A;

impl A {
    pub fn by_mut(&mut self) {
        self.type_id();
    }

    fn type_id(&self) {
        println!("hi");
    }
}

fn main() {
    A.by_mut();
}

Today this compiles on stable but it fails to compile on beta.

The cause of this is almost certainly https://github.com/rust-lang/rust/pull/57834/files where the type_id method was renamed during stabilization. Historically this sort of breakage, while definitely unfortunate, is acceptable under our current semver and compatibility policy. Barring a large amount of practical breakage in the ecosystem we're unlikely to revert the change.

Sorry again @elrnv for the regression, but good to hear that this is fixed already as well!

All 4 comments

cc @rust-lang/libs

Thanks for reporting! This should be fixed in data-buffer 0.5, which I published just an hour ago or so. Since I used type_id in the api, it was a breaking change.

Reduced I believe this looks like:

use std::any::Any;

struct A;

impl A {
    pub fn by_mut(&mut self) {
        self.type_id();
    }

    fn type_id(&self) {
        println!("hi");
    }
}

fn main() {
    A.by_mut();
}

Today this compiles on stable but it fails to compile on beta.

The cause of this is almost certainly https://github.com/rust-lang/rust/pull/57834/files where the type_id method was renamed during stabilization. Historically this sort of breakage, while definitely unfortunate, is acceptable under our current semver and compatibility policy. Barring a large amount of practical breakage in the ecosystem we're unlikely to revert the change.

Sorry again @elrnv for the regression, but good to hear that this is fixed already as well!

This seems to be resolved, so I'll close this. Feel free to reopen if that's wrong.

Was this page helpful?
0 / 5 - 0 ratings