Skip to content

Syntax needed to disambiguate associated types in trait object bounds #48822

Closed
@zombiezen

Description

@zombiezen

Context: https://stackoverflow.com/questions/49143625/how-to-disambiguate-associated-types-in-trait-object-bounds

While fully qualified syntax allows me to disambiguate associated types in parameter and return types, I can't seem to use it for disambiguating associated types in trait object bounds. This came up while I tried to use a boxed IEvent from stdweb, which has supertraits of TryFrom<Value> and TryFrom<Reference>. For example, with the following code:

use stdweb::private::ConversionError;
use stdweb::web::event::IEvent;

struct Foo {
    bar: Box<IEvent<Error = ConversionError>>,
}

I get an error like:

error[E0221]: ambiguous associated type `Error` in bounds of `stdweb::traits::IEvent`
 --> src/main.rs:7:21
  |
7 |     bar: Box<IEvent<Error = ConversionError>>,
  |                     ^^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type `Error`
  |
note: associated type `stdweb::traits::IEvent` could derive from `stdweb::unstable::TryFrom<stdweb::Reference>`
 --> src/main.rs:7:21
  |
7 |     bar: Box<IEvent<Error = ConversionError>>,
  |                     ^^^^^^^^^^^^^^^^^^^^^^^
note: associated type `stdweb::traits::IEvent` could derive from `stdweb::unstable::TryFrom<stdweb::Value>`
 --> src/main.rs:7:21
  |
7 |     bar: Box<IEvent<Error = ConversionError>>,
  |                     ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

If you want more information on this error, try using "rustc --explain E0221"

I would expect to be able to disambiguate it with something like:

use stdweb::{Reference, Value};
use stdweb::private::ConversionError;
use stdweb::unstable::TryFrom;
use stdweb::web::event::IEvent;

struct Foo {
    bar: Box<IEvent<<<IEvent as TryFrom<Reference>>::Error = ConversionError, <IEvent as TryFrom<Value>>::Error = ConversionError>>,
}

But this emits a syntax error:

error: expected one of `(`, `::`, `<`, `>`, or `as`, found `=`
 --> src/main.rs:9:60
  |
9 |     bar: Box<IEvent<<<IEvent as TryFrom<Reference>>::Error = ConversionError, <IEvent as TryFrom<Value>>::Error = ConversionError>>,
  |                                                            ^ expected one of `(`, `::`, `<`, `>`, or `as` here

Meta

rustc --version --verbose:

rustc 1.26.0-nightly (2789b067d 2018-03-06)
binary: rustc
commit-hash: 2789b067da2ac921b86199bde21dd231ace1da39
commit-date: 2018-03-06
host: x86_64-apple-darwin
release: 1.26.0-nightly
LLVM version: 6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamWG-traits[RETIRED] Working group: Traits

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions