Skip to content

Incorrect recursion in type inference #49017

Open
@0ndorio

Description

@0ndorio

I encountered a recursion overflow error on a trait implementation of HashMap (Encodable) when I tried to extend an unrelated trait (Inner) by a where clause for the same trait. This might end in a case of 'You are holding it wrong', but I couldn't find any clue why the change should infer with the given implementation:

Minimal Example

Playground

use std::collections::HashMap;

pub trait Encodable {}

pub trait Inner
where
    for<'a> &'a Self: Encodable,
{
}

pub trait Outer {
    type Inner: Inner;
}

impl<'a, K, V, S> Encodable for &'a HashMap<K, V, S>
where
    &'a V: Encodable,
{
}

Error Log

 Compiling playground v0.0.1 (file:///playground)
error[E0275]: overflow evaluating the requirement `_: std::marker::Sized`
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
  = note: required because of the requirements on the impl of `for<'a> Encodable` for `&'a std::collections::HashMap<_, _, _>`
  = note: required because of the requirements on the impl of `for<'a> Encodable` for `&'a std::collections::HashMap<_, std::collections::HashMap<_, _, _>, _>`
  = note: required because of the requirements on the impl of `for<'a> Encodable` for `&'a std::collections::HashMap<_, std::collections::HashMap<_, std::collections::HashMap<_, _, _>, _>, _>`
  = note: required because of the requirements on the impl of `for<'a> Encodable` for `&'a std::collections::HashMap<_, std::collections::HashMap<_, std::collections::HashMap<_, std::collections::HashMap<_, _, _>, _>, _>, _>`
  = note: required because of the requirements on the impl of `for<'a> Encodable` for `&'a std::collections::HashMap<_, std::collections::HashMap<_, std::collections::HashMap<_, std::collections::HashMap<_, std::collections::HashMap<_, _, _>, _>, _>, _>, _>`
[...]

Reproduced with:

  • stable: rustc 1.24.1 (d3ae9a9 2018-02-27)
  • nightly: rustc 1.26.0-nightly (2789b06 2018-03-06)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-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