Skip to content

Only 'static is permitted within type bounds (causes ICE: Cannot relate bound region) #5121

Closed

Description

@nikomatsakis

Once we can declare lifetime parameters, there is no reason not to permit them in type bounds. Also, I am not entirely sure if the way we are handling them is correct/sound. I've tagged places where such bounds appear with FIXMEs so that I can look into them later.


Example:

trait Iterable<'a> {
    fn my_iter(&'a self);
}

fn foo<'a, C: Iterable<'a>>(c: C) {
    c.my_iter();
}

fn main() { }
5121.rs:6:5: 6:6 error: internal compiler error: Cannot relate bound region: ReLateBound(12, BrNamed(syntax::ast::DefId{crate: 0u32, node: 21u32}, a)) <= ReInfer(1)
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
5121.rs:6     c.my_iter();
              ^
task 'rustc' failed at 'explicit failure', /home/huon/rust/src/libsyntax/diagnostic.rs:41
task '<main>' failed at 'explicit failure', /home/huon/rust/src/librustc/lib.rs:440

pnkfelix: I am adding a checklist to the bottom of this bug, where the unchecked issues represent problems that still remain unfixed (and the entire list of issues were closed as duplicates of this ticket).

Activity

  1. nikomatsakis commented on Apr 5, 2013

    @nikomatsakis
    ContributorAuthor

    see also #5715

  2. emberian commented on Jun 25, 2013

    @emberian
    Contributor

    @nikomatsakis this going to land in time for 0.7? I really hope so, it's really obnoxious.

  3. emberian commented on Jun 25, 2013

    @emberian
    Contributor

    (Also, 'self is allowed too, I think)

  4. brson commented on Jul 3, 2013

    @brson
    Contributor

    Bumping from 0.7

  5. bblum commented on Jul 19, 2013

    @bblum
    Contributor

    I ran into this when trying to devise a too-clever interface for select2 that would let me avoid code duplication, but it would not let me use non-static borrowed pointers. https://gist.github.com/bblum/6042762

  6. nikomatsakis commented on Oct 29, 2013

    @nikomatsakis
    ContributorAuthor

    This will be the final part of #4846. Turns out that this is not so simple as I originally thought (but also not horribly scary or complex). I'll put up a blog post soon (and link it here) describing my proposal.

  7. nikomatsakis commented on Oct 29, 2013

    @nikomatsakis
    ContributorAuthor

    See http://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ for a detailed write-up of the changes I propose to fix this.

  8. 17 remaining items

  9. added a commit that references this issue on Mar 12, 2014
  10. flaper87 commented on Mar 13, 2014

    @flaper87
    Contributor

    Taken from #12851

    trait MyTrait<'a> {
        fn yo(&'a self);
    }
    
    struct MyStruct<'a> {
        inner: &'a  MyTrait<'a>,
    }
    
    impl<'a> MyStruct<'a> {
    
        fn foo_inner(&mut self) {
            self.inner.yo()
        }
    }
  11. pnkfelix commented on Mar 13, 2014

    @pnkfelix
    Contributor

    well, I guess it is a good thing I didn't have bors automatically close this ticket with PR #12807.

    Will investigate these ICE's. (i had noted others above, may be related.)

  12. added a commit that references this issue on Mar 25, 2014
    677eeb2
  13. pnkfelix commented on Mar 25, 2014

    @pnkfelix
    Contributor

    I have a patch that fixes most of the ICE's above, though not all of them.

    I will try to put it up for review either tonight or tomorrow.

  14. pnkfelix commented on Mar 26, 2014

    @pnkfelix
    Contributor

    After reviewing the bugs that have been marked as duplicates of this bug, I've collected all of the cases that were not fixed by the original Early/Late patch and put them into their own modules. (Sometimes I tried to reduce them into smaller test cases, but usually when I did that I made a variant module with the reduced case while also keeping the original.)

    The result of this collection process is posted in a file at the following gist:
    https://gist.github.com/pnkfelix/9788730

    (It wasn't originally a single file, but that is the easiest way to distribute the collection. It is easy enough to go back and forth between separate files and a single file for the modules, thanks to the beauty of Rust's module system.)

  15. pnkfelix commented on Mar 26, 2014

    @pnkfelix
    Contributor

    PR #13157 fixes most of the ICE's exposed by https://gist.github.com/pnkfelix/9788730

    The main exceptions are the ICE's that are exposed by passing --cfg defer_for_5121_fix2 and --cfg defer_for_5121_fix3.

    The other important things that are not fixed by PR #13157 (a fix to issue #13140) are the non-ICE unsoundness issues that are represented by the print out from the gisted code when you run it, namely the output:

    Warning, non-3 value from m3: 140658622872720
    bar.get(0) = 9
    bar = [9, 9, 9, 9, 9], should be [1, 2, 3, 4, 5]
    

    corresponding to #11971 and #12856.

  16. added a commit that references this issue on Mar 29, 2014
  17. pnkfelix commented on Mar 31, 2014

    @pnkfelix
    Contributor

    So, as mentioned above, there still remain issues #11971 and #12856 that remain unfixed. (They are already open, since they were not marked as dupes, just related.)

    Also, we probably need to make some other changes, such as allowing one to put a lifetime bound on a trait (which means that all impls need to have that bound on themSelfs (sic)).

    But, most of the work has been done here, and I claim that new bugs related to this one should not be closed as dupes of this one (but rather should be classified as unique on their own or classified as dupes of some other, more specific bug). So I am going to close this bug.

  18. added 2 commits that reference this issue on May 2, 2020
  19. added a commit that references this issue on Dec 3, 2021
  20. added a commit that references this issue on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions