Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zombiezen opened this issue Mar 7, 2018 · 4 comments
Closed
Labels
A-associated-items Area: Associated items (types, constants & functions) A-traits Area: Trait system A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804

Comments

@zombiezen
Copy link
Contributor

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
@Centril Centril added A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. A-traits Area: Trait system A-associated-items Area: Associated items (types, constants & functions) T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 labels Mar 7, 2018
@zombiezen
Copy link
Contributor Author

Also, to be clear: this makes it impossible for me to store an IEvent in a Box.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 8, 2018

minimal repro:

trait Foo {
    type Error;
}

trait Bar {
    type Error;
}

trait Cake : Foo + Bar {}

struct S {
    f: Box<Cake<Error = i32>>,
}

fn main() {
}

@syntacticsugarglider
Copy link
Contributor

This seems to be a duplicate of #48285. Moreover, has there been any momentum on this since filing? I see that it's marked WG-compiler-traits but there's no further discussion here and this issue has been around for a couple years at this point.

@oli-obk
Copy link
Contributor

oli-obk commented May 2, 2020

duplicate of #48285

@oli-obk oli-obk closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-traits Area: Trait system A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804
Projects
None yet
Development

No branches or pull requests

4 participants