Skip to content

Better error message for trait bounds on structs. #15110

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

Closed
smosher opened this issue Jun 23, 2014 · 5 comments
Closed

Better error message for trait bounds on structs. #15110

smosher opened this issue Jun 23, 2014 · 5 comments

Comments

@smosher
Copy link

smosher commented Jun 23, 2014

I was looking at this issue on SO:

https://stackoverflow.com/questions/24363369/polymorphism-in-rust

The reported error doesn't help much for someone who doesn't already know better:

error: trait bounds are not allowed in structure definitions
test.rs:20:1: 22:2 error: trait bounds are not allowed in structure definitions
test.rs:20 struct Board<R: Rules> {
test.rs:21     rules: R
test.rs:22 }
error: aborting due to previous error

The explanation in the first response is straight-forward: You need to refine that in the trait implementation, not the struct definition.

There's enough information present when someone tries to apply trait bounds in a struct to spit out the impl declaration line by way of example, so in this case (note R, Rules, and Board are all present in intelligible positions in the error report above):

test.rs:20:1: 22:2 error: trait bounds are not allowed in structure definitions. 
[ ... error context as above ... ]
Use a trait implementation instead, eg.:
    impl<R: Rules> Board<R> { ... }
@nikomatsakis
Copy link
Contributor

Note that this will not be an error much longer (trait bounds in struct declarations).

@smosher
Copy link
Author

smosher commented Jun 25, 2014

Ah, in that case it's probably not worth going the distance to producing an example impl declaration.

@Valve
Copy link

Valve commented Jul 30, 2014

@nikomatsakis Niko, why will it not be an error much longer?

@nikomatsakis
Copy link
Contributor

@ghost
Copy link

ghost commented Oct 25, 2014

This is now implemented, closing.

@ghost ghost closed this as completed Oct 25, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 17, 2023
internal: Add run-tests command

This command is similar to `cargo test` except that it uses r-a to run tests instead of compiling and running them with rustc. This is slower than `cargo test` and it is only useful for me to see a bird view of what needs to be fixed. The current output is:
```
48 passed, 5028 failed, 2 ignored
All tests            174.74s, 648ginstr
```
48 is very low, but higher than what I originally thought.

Now that there is some passing tests, I can show the plan:

https://github.com/rust-lang/rust-analyzer/assets/45197576/76d7d777-1843-4ca4-b7fe-e463bdade6cb

That is, at the end, I want to be able to immediately re run every test after every change. (0.5s is not really immediate, but it's not finished yet, and it is way better than 8s that running a typical test in r-a will take on my system)
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants