Skip to content

DST leads to unintuitive errors with traits like Int #16874

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
huonw opened this issue Aug 30, 2014 · 3 comments
Closed

DST leads to unintuitive errors with traits like Int #16874

huonw opened this issue Aug 30, 2014 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-DSTs Area: Dynamically-sized types (DSTs) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@huonw
Copy link
Member

huonw commented Aug 30, 2014

The Int trait has a very similar name to the int primitive type, so if someone accidentally uses Int (e.g. forgetting that primitive types have special names/if they come from Haskell or some such) they can get confusing messages, especially now that DST allows for bare traits to be used more often, e.g.

struct Foo { x: Int }

fn main() {}

gives

<anon>:1:17: 1:20 error: explicit lifetime bound required
<anon>:1 struct Foo { x: Int }
                         ^~~

which is really confusing.

I'm not really sure how we fix this, but mentioning "trait" somewhere in the message would be helpful.

@steveklabnik
Copy link
Member

This ticket is interesting. First of all, this now actually compiles just fine:

trait Int {}

struct Foo { x: Int }

fn main() {}

just gives

hello.rs:3:1: 3:22 warning: struct is never used: `Foo`, #[warn(dead_code)] on by default
hello.rs:3 struct Foo { x: Int }
           ^~~~~~~~~~~~~~~~~~~~~
hello.rs:3:14: 3:20 warning: struct field is never used: `x`, #[warn(dead_code)] on by default
hello.rs:3 struct Foo { x: Int }
                        ^~~~~~

Second, the confusingly-named traits have been removed.

As such, I think this ticket is probably resolved. What do you think, @huonw ?

@bltavares
Copy link
Contributor

Triaging:

The following code now only prompts one warning:

trait Int {}

struct Foo { x: Int }

fn main() {}
<anon>:3:1: 3:22 warning: struct is never used: `Foo`, #[warn(dead_code)] on by default
<anon>:3 struct Foo { x: Int }
         ^~~~~~~~~~~~~~~~~~~~~

As @steveklabnik said, it compiles just fine, as the declared Int trait has not lifetime parameter.
If we modify to code to introduce a new lifetime paramenter, we have a different error message which points to the missing lifetime argument.

trait Int<'a> {}

struct Foo { x: Int }

fn main() {}
<anon>:3:17: 3:20 error: wrong number of lifetime parameters: expected 1, found 0 [E0107]
<anon>:3 struct Foo { x: Int }
                         ^~~
<anon>:3:17: 3:20 help: see the detailed explanation for E0107
error: aborting due to previous error
playpen: application terminated with error code 101

As Int no longer exists, I think this issue could be closed.

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

Yeah, I don't see any real problem here; closing.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 31, 2024
Use `--workspace` and `--no-fail-fast` in test explorer

This PR contains:
* Using `--workspace` in `cargo test` command, to running all tests even when there is a crate in the root of a workspace
* Using `--no-fail-fast` to run all requested tests
* Excluding bench in the test explorer
* Fixing a bug in the `hack_recover_crate_name`

fix rust-lang#16874
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 A-DSTs Area: Dynamically-sized types (DSTs) 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

4 participants