Skip to content

impl Trait binary operations #50626

Closed
Closed
@DutchGhost

Description

@DutchGhost

having a function signature like the following, results in a stack overflow during compilation on rustc 1.26.0 (a775680 2018-05-07), rustc 1.26.0-beta.18 (2018-05-03 1f200ac), and rustc 1.27.0-nightly (e5f80f2 2018-05-09)

fn test_impl_Add() -> impl std::ops::Add {1 + 1}
fn test_impl_Sub() -> impl std::ops::Sub {1 - 1}
fn test_impl_Mul() -> impl std::ops::Mul {1 * 1}
fn test_impl_Div() -> impl std::ops::Div {2 / 1}

fn test_impl_AddAssign() -> impl std::ops::AddAssign { 1 }
fn test_impl_SubAssign() -> impl std::ops::SubAssign { 1 }
fn test_impl_MulAssign() -> impl std::ops::MulAssign { 1 }
fn test_impl_DivAssign() -> impl std::ops::DivAssign { 1 }

Adding the Output parameter, like the example below, still results in a stack overflow:

fn test_impl_Add() -> impl std::ops::Add<Output = i32> {1 + 1}
fn test_impl_Sub() -> impl std::ops::Sub<Output = i32> {1 - 1}
fn test_impl_Mul() -> impl std::ops::Mul<Output = i32> {1 * 1}
fn test_impl_Div() -> impl std::ops::Div<Output = i32> {2 / 1}

A signature looking like fn test_iml_add() -> impl std::ops::Add<u32> {1 + 1} however does compile.

A playground link to make things more clear: https://play.rust-lang.org/?gist=9990fff6d401794400ba4d424ec89f54&version=beta&mode=debug

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions