Skip to content

Infinite recursion error instead of trait bound error #40827

Closed

Description

@dnorman

Observed behavior:
Receiving the following error when attempting to compile the sample program.

Expected behavior:
Indicate that there is a trait bound error.


rustc 1.16.0 (30cf806ef 2017-03-10)
error[E0275]: overflow evaluating the requirement `TransmitterInternal: std::marker::Send`
  --> <anon>:22:16
   |
22 | fn g(x: Memo) {f(x)}
   |                ^
   |
   = note: consider adding a `#![recursion_limit="128"]` attribute to your crate
   = note: required because of the requirements on the impl of `std::marker::Sync` for `std::sync::Arc<TransmitterInternal>`
   = note: required because it appears within the type `SlabRef`
   = note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<SlabRef>`
   = note: required because it appears within the type `alloc::raw_vec::RawVec<SlabRef>`
   = note: required because it appears within the type `std::vec::Vec<SlabRef>`
   = note: required because it appears within the type `TransmitterInternal`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<TransmitterInternal>`
   = note: required because it appears within the type `SlabRef`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<SlabRef>`
   = note: required because it appears within the type `alloc::raw_vec::RawVec<SlabRef>`
   = note: required because it appears within the type `std::vec::Vec<SlabRef>`
   = note: required because it appears within the type `TransmitterInternal`
   = note: required because of the requirements on the impl of `std::marker::Sync` for `std::sync::Arc<TransmitterInternal>`
   = note: required because it appears within the type `SlabRef`
...

Minimal reproduction case:

https://is.gd/KgD5Tk
Many thanks to the tireless efforts of @stephaneyfx in creating the repro above!

Bonus round
I haven't yet figured out a minimal repro for this second part, but if I'm interpreting correctly, it's possible that a variant of this endless recursion error does not require a trait bound error to be triggered. (noob warning: it's possible that the omission of +Send+Sync in 4ab0fdf is actually a trait bounds error, but I don't presently understand why)

Non-minimal repro:
https://travis-ci.org/dnorman/unbase/jobs/209643435#L240

Minimal change that fixed it:
dnorman/unbase@47c68bf
https://travis-ci.org/dnorman/unbase/jobs/209649602#L228

Activity

  1. stephaneyfx commented on Mar 25, 2017

    @stephaneyfx
    Contributor

    This is a simplified example reproducing the issue (playground).

    use std::rc::Rc;
    use std::sync::Arc;
    
    // Rc<_>: !Send
    // => Bar: !Send
    // => Arc<Bar>: !Send
    // => Foo: !Send
    //
    // Shouldn't the compiler come to the same conclusion instead of entering this
    // infinite recursion?
    struct Foo(Arc<Bar>);
    
    enum Bar {
        A(Rc<Foo>),
        B(Option<Foo>),
    }
    
    fn f<T: Send>(_: T) {}
    
    fn main() {
        f(Foo(Arc::new(Bar::B(None))));
    }
    rustc 1.16.0 (30cf806ef 2017-03-10)
    error[E0275]: overflow evaluating the requirement `Foo: std::marker::Send`
      --> <anon>:21:5
       |
    21 |     f(Foo(Arc::new(Bar::B(None))));
       |     ^
       |
       = note: consider adding a `#![recursion_limit="128"]` attribute to your crate
       = note: required because it appears within the type `std::option::Option<Foo>`
       = note: required because it appears within the type `Bar`
       = note: required because of the requirements on the impl of `std::marker::Sync` for `std::sync::Arc<Bar>`
       = note: required because it appears within the type `Foo`
       = note: required because it appears within the type `std::option::Option<Foo>`
       = note: required because it appears within the type `Bar`
       = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<Bar>`
       = note: required because it appears within the type `Foo`
    ...
    
  2. stephaneyfx commented on Mar 26, 2017

    @stephaneyfx
    Contributor

    Note that if Rc is removed (or replaced by Arc, for example), the compiler does not enter this infinite recursion and deduces Foo is Send (playground).

  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 20, 2017
  4. dnorman commented on Aug 18, 2017

    @dnorman
    Author

    This is the case I was referring to @aturon :)

  5. aturon commented on Aug 18, 2017

    @aturon
    Contributor

    @dnorman Thanks! Fascinating bug...

  6. orium commented on Jul 23, 2018

    @orium
    Contributor

    I think I have hit the same bug with

    use std::rc::Rc;
    use std::sync::Arc;
    
    struct List {
        value: Rc<i32>,
        next:  Option<Arc<List>>
    }
    
    fn is_send() {
        let _: Box<Send> = Box::new(List { value: Rc::new(4), next: None });
    }
    error[E0275]: overflow evaluating the requirement `std::sync::Arc<List>: std::marker::Send`
      --> src/lib.rs:12:24
       |
    12 |     let _: Box<Send> = Box::new(List { value: Rc::new(4), next: None });
       |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
       = note: required because it appears within the type `std::option::Option<std::sync::Arc<List>>`
       = note: required because it appears within the type `List`
       = note: required because of the requirements on the impl of `std::marker::Sync` for `std::sync::Arc<List>`
       = note: required because it appears within the type `std::option::Option<std::sync::Arc<List>>`
    

    I did some digging around in the trait resolver and I believe what causes it is pointed by @nikomatsakis in #30533 (comment):

    1. If you find that a new obligation is a duplicate of one already in the tree, the proper processing is:
      • if that other location is your parent, you should abort with a cycle error (or accept it, if coinductive)
      • if that other location is not an ancestor, you can safely ignore the new obligation

    If this is truly the cause of the bug I will give it a go and try to fix it, but I would really appreciate some mentoring instructions. @nikomatsakis can you give me a few pointers?

  7. added a commit that references this issue on Sep 30, 2018
    fc403ad
  8. added 3 commits that reference this issue on Feb 5, 2025
  9. added a commit that references this issue on Feb 6, 2025
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-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions