Skip to content

Type annotation required in a trait method call but not with UFCS #23346

Closed
@gkoz

Description

@gkoz

The compiler is only able to resolve the type with a UFCS syntax that doesn't seem to add any information.
Could be related to #22165.

#![feature(core)]
use std::ptr;

pub trait Wrapper {
    type Inner;
}

pub trait IsA<T> {}

pub trait Fudge<P> {
    fn fudge(&self) -> P;
}

impl <PAR: Wrapper, CHI: IsA<PAR>> Fudge<*mut <PAR as Wrapper>::Inner> for CHI {
    fn fudge(&self) -> *mut <PAR as Wrapper>::Inner {
        ptr::null_mut()
    }
}

pub struct Envelope<T> (*mut T);

impl <T> Wrapper for Envelope<T> {
    type Inner = T;
}

pub struct WidgetInner;
type Widget = Envelope<WidgetInner>;

pub fn fudge<W: IsA<Widget>>(widget: &W) {
    // OK
    let _x = Fudge::<_>::fudge(widget);
    // error: type annotations required: cannot resolve `<_ as Wrapper>::Inner == WidgetInner` [E0284]
    let _y = widget.fudge();
}

fn main() {}

Error message:

<anon>:34:21: 34:28 error: type annotations required: cannot resolve `<_ as Wrapper>::Inner == WidgetInner` [E0284]
<anon>:34     let _y = widget.fudge();
                              ^~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions