Skip to content

Rust thinks std::marker::Sized differ from std::marker::Sized #44835

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Zoxc opened this issue Sep 25, 2017 · 1 comment
Closed

Rust thinks std::marker::Sized differ from std::marker::Sized #44835

Zoxc opened this issue Sep 25, 2017 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@Zoxc
Copy link
Contributor

Zoxc commented Sep 25, 2017

trait DescriptiveSpec<'r> {}

impl<'r, T> DescriptiveSpec<'r> for &'r T {}

fn from_spec<'r, T: DescriptiveSpec<'r>>(spec: &'r T)  {}

fn matching_contains<'s, T: 's, I>(a: &mut &'s I) where &'s I: Sized {
    from_spec(a);
}

fn main() {}

gives this error

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'r` due to conflicting requirements
 --> src/main.rs:9:5
  |
9 |     from_spec(a);
  |     ^^^^^^^^^
  |
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 8:1...
 --> src/main.rs:8:1
  |
8 | / fn matching_contains<'s, T: 's, I>(a: &mut &'s I) where &'s I: Sized {
9 | |     from_spec(a);
10| | }
  | |_^
note: ...so that reference does not outlive borrowed content
 --> src/main.rs:9:15
  |
9 |     from_spec(a);
  |               ^
note: but, the lifetime must be valid for the lifetime 's as defined on the function body at 8:1...
 --> src/main.rs:8:1
  |
8 | / fn matching_contains<'s, T: 's, I>(a: &mut &'s I) where &'s I: Sized {
9 | |     from_spec(a);
10| | }
  | |_^
note: ...so that types are compatible (expected std::marker::Sized, found std::marker::Sized)
 --> src/main.rs:9:5
  |
9 |     from_spec(a);
  |     ^^^^^^^^^

The note ...so that types are compatible (expected std::marker::Sized, found std::marker::Sized) does not seem correct. This error is likely due to the function having two &'a I: Sized bounds where 's have two different lifetimes, see #21974.

@TimNN TimNN added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 27, 2017
@Mark-Simulacrum
Copy link
Member

This test case works today.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants