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

Wrong error message when attempting to use a trait method's result as array length #48701

Closed
gnzlbg opened this issue Mar 3, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Mar 3, 2018

The following code came up on IRC. It cannot ever work, but the error message is completely wrong (playground):

pub trait Foo { fn foo() -> usize; }

struct Bar();
impl Foo for Bar { fn foo() -> usize { 3 } }

fn baz<F: Foo>() {
    let _x = [0_u32; <F as Foo>::foo()];
}

fn main() {
    baz::<Bar>();
}

outputs:

error[E0277]: the trait bound `F: Foo` is not satisfied
 --> src/main.rs:7:22
  |
7 |     let _x = [0_u32; <F as Foo>::foo()];
  |                      ^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `F`
  |
  = help: consider adding a `where F: Foo` bound
  = note: required by `Foo::foo`

This error messages is 100% wrong: F does implement the trait Foo since the function signature does require it.

@gnzlbg gnzlbg changed the title Confusing error message when using trait method for array length Wrong error message when using trait method for array length Mar 3, 2018
@gnzlbg gnzlbg changed the title Wrong error message when using trait method for array length Wrong error message when attempting to use a trait method's result as array length Mar 3, 2018
@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 6, 2018
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 8, 2018

Is this a duplicate of: #44168 ? That one uses an associated constant but they do look really similar otherwise.

@dtolnay
Copy link
Member

dtolnay commented Jun 9, 2018

Closing as a duplicate of #44168. The "trait bounds don't work in array length" aspect of this is the same issue.

@dtolnay dtolnay closed this as completed Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

3 participants