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

Trait-objects need associated-types of subtraits to be specified even when that's already done by the boxed trait #29328

Closed
qrlpx opened this issue Oct 26, 2015 · 10 comments
Labels
A-stability Area: issues related to #[stable] and #[unstable] attributes themselves. A-traits Area: Trait system P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@qrlpx
Copy link

qrlpx commented Oct 26, 2015

If someone has a shorter/more conclusive title in mind, shoot.

code

trait Foo {
    type Bar;
}

trait FooBar: Foo<Bar = String> {}

struct Arb {
    foobar: Box<FooBar>,
}

Playpen: http://is.gd/6QKndB

output

test.rs:8:17: 8:23 error: the value of the associated type `Bar` (from the trait `Foo`) must be specified [E0191]
test.rs:8     foobar: Box<FooBar>,
                          ^~~~~~
test.rs:8:17: 8:23 help: run `rustc --explain E0191` to see a detailed explanation
error: aborting due to previous error

rustc version

rustc 1.5.0-nightly (0be1bcd06 2015-10-24)
@qrlpx qrlpx changed the title In trait-object-types, associated-types of subtraits need to be specified even when that's already done by the boxed trait Trait-objects need associated-types of subtraits to be specified even when that's already done by the boxed trait Oct 26, 2015
@steveklabnik steveklabnik added the A-traits Area: Trait system label Oct 26, 2015
@arielb1
Copy link
Contributor

arielb1 commented Oct 26, 2015

I would like to claim that this is a part of "non-supertrait predicates are not elaborated", but this quite ugly.

However, with the current acyclicity requirements, this would break stuff like

trait Foo : Iterator where Self::Item: Copy {}

Maybe just give them the ProjectionPredicate treatment?

@gwillen
Copy link
Contributor

gwillen commented Oct 29, 2015

I just hit this issue and discovered this bug by searching. I don't understand most of the words in the comment explaining why this behavior is this way. :-) But it's definitely a weird UX issue, in that it's not at all obvious to a user why it would do this.

@Wyverald
Copy link

This also makes it hard to parameterize associated types.

trait Foo { type Bar; }
trait Foobar<T> : Foo<Bar=T> {}
struct Quux<'a> {
    foobar: &'a Foobar<String>,
}

That doesn't compile. I'll need to write foobar: &'a Foobar<String, Bar=String> instead.

@durka
Copy link
Contributor

durka commented Feb 6, 2016

In combination with Fn traits, this seems like a hole in stability! Check out this code:

trait FnAlias: Fn() {}

fn main() {
    let _: FnAlias;            // error
    let _: FnAlias<Output=()>; // no error, but I shouldn't be able to do this!
}

Normally I can't write an Fn trait while specifying the return type as an associated type, at least without #![feature(unboxed_closures)]. But here I have to.

@peterhj
Copy link
Contributor

peterhj commented Apr 27, 2016

Appears to be the same as #23856 and possibly #24010?

@bstrie bstrie added the A-stability Area: issues related to #[stable] and #[unstable] attributes themselves. label May 2, 2016
@bstrie
Copy link
Contributor

bstrie commented May 2, 2016

Tagging with A-stability based on durka's comment.

@aturon aturon added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 2, 2016
@alexcrichton alexcrichton added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 4, 2016
@nikomatsakis
Copy link
Contributor

So while it's true that this bug allows you to name the Output parameter, in a sense, of the Fn traits, which we are normally not permitting, I don't think there is any plan to change the Fn traits in a way that would make this a problem. Still, an interesting thing.

@nikomatsakis
Copy link
Contributor

In particular, we are more concerned about the input argument types, which may want to become variadic or otherwise change.

@nikomatsakis
Copy link
Contributor

triage: P-medium

@rust-highfive rust-highfive added P-medium Medium priority and removed I-nominated labels May 5, 2016
@nikomatsakis
Copy link
Contributor

Closing as dup of #24010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stability Area: issues related to #[stable] and #[unstable] attributes themselves. A-traits Area: Trait system P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests