Skip to content
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

Coercion creates false region inference error #37655

Closed
nikomatsakis opened this issue Nov 8, 2016 · 1 comment
Closed

Coercion creates false region inference error #37655

nikomatsakis opened this issue Nov 8, 2016 · 1 comment

Comments

@nikomatsakis
Copy link
Contributor

This test case, derived from @sfackler's PR #36340, fails to compile incorrectly:

trait SliceExt<T> {
    type Item;

    fn get_me<I>(&self, index: I) -> &I::Output
        where I: SliceIndex<Self::Item>;
}

impl<T> SliceExt<T> for [T] {
    type Item = T;

    fn get_me<I>(&self, index: I) -> &I::Output
        where I: SliceIndex<T>
    {
        panic!()
    }
}

pub trait SliceIndex<T> {
    type Output: ?Sized;
}

impl<T> SliceIndex<T> for usize {
    type Output = T;
}

fn foo<'a>(split: &[&'a [u8]]) -> &'a [u8] {
    split.get_me(0)
}

fn main() { }

I get the error:

lunch-box. rustc --stage0 ~/tmp/issue-36340.rs
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
  --> /home/nmatsakis/tmp/issue-36340.rs:27:11
   |
27 |     split.get_me(0)
   |           ^^^^^^
   |
help: consider using an explicit lifetime parameter as shown: fn foo<'a>(split: &'a [&'a [u8]]) -> &'a [u8]
  --> /home/nmatsakis/tmp/issue-36340.rs:26:1
   |
26 | fn foo<'a>(split: &[&'a [u8]]) -> &'a [u8] {
   | ^

error: aborting due to previous error

This is because coercion is going wrong, basically. Note that small changes (such as &**split.get_me(0)) work fine.

@nikomatsakis
Copy link
Contributor Author

Explanation of error is here: #36340 (comment)

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Nov 8, 2016
eddyb added a commit to eddyb/rust that referenced this issue Nov 11, 2016
…eddyb

introduce a `fudge_regions_if_ok` to address false region edges

Fixes rust-lang#37655.

r? @eddyb
cc @sfackler
eddyb added a commit to eddyb/rust that referenced this issue Nov 12, 2016
…eddyb

introduce a `fudge_regions_if_ok` to address false region edges

Fixes rust-lang#37655.

r? @eddyb
cc @sfackler
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant