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

impl Trait with < as Trait>::Type syntax does not work in return position #59023

Closed
mtak- opened this issue Mar 8, 2019 · 3 comments · Fixed by #70741
Closed

impl Trait with < as Trait>::Type syntax does not work in return position #59023

mtak- opened this issue Mar 8, 2019 · 3 comments · Fixed by #70741
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. A-lazy-normalization Area: lazy normalization (tracking issue: #60471) A-traits Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mtak-
Copy link
Contributor

mtak- commented Mar 8, 2019

Using the as syntax does not work as a generic to an impl Trait in return position.

trait A { type Foo; }
impl<T> A for T { type Foo = (); }

fn foo() -> impl std::borrow::Borrow<<u8 as A>::Foo> {
    ()
}

Error

error[E0277]: the trait bound `(): std::borrow::Borrow<<u8 as A>::Foo>` is not satisfied
 --> src/lib.rs:4:13
  |
4 | fn foo() -> impl std::borrow::Borrow<<u8 as A>::Foo> {
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::borrow::Borrow<<u8 as A>::Foo>` is not implemented for `()`
  |
  = help: consider adding a `where (): std::borrow::Borrow<<u8 as A>::Foo>` bound
  = note: the return type of a function must have a statically known size

As a parameter it does work:

trait A { type Foo; }
impl<T> A for T { type Foo = (); }

fn foo(p: impl std::borrow::Borrow<<u8 as A>::Foo>) {}

fn call_foo() {
    foo(())
}

This issue looks related, but specifically calls out type equality constraints. #53984

@jonas-schievink jonas-schievink added A-traits Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. labels Mar 8, 2019
@Centril
Copy link
Contributor

Centril commented Mar 9, 2019

cc @nikomatsakis, is this a lazy-norm issue?

@Centril Centril added the A-lazy-normalization Area: lazy normalization (tracking issue: #60471) label Jul 28, 2019
@Centril Centril added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 3, 2020
@jonas-schievink
Copy link
Contributor

This was fixed by #62221, which includes tests, so maybe this should just be closed?

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 3, 2020
@nikomatsakis
Copy link
Contributor

Closing per @jonas-schievink's comment

Centril added a commit to Centril/rust that referenced this issue Apr 3, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 3, 2020
Rollup of 9 pull requests

Successful merges:

 - rust-lang#69860 (Use associated numeric consts in documentation)
 - rust-lang#70576 (Update the description of the ticket to point at RFC 1721)
 - rust-lang#70597 (Fix double-free and undefined behaviour in libstd::syn::unix::Thread::new)
 - rust-lang#70640 (Hide `task_context` when lowering body)
 - rust-lang#70641 (Remove duplicated code in trait selection)
 - rust-lang#70707 (Remove unused graphviz emitter)
 - rust-lang#70720 (Place TLS initializers with relocations in .tdata)
 - rust-lang#70735 (Clean up E0502 explanation)
 - rust-lang#70741 (Add test for rust-lang#59023)

Failed merges:

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. A-lazy-normalization Area: lazy normalization (tracking issue: #60471) A-traits Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants