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

Better error message about [T] as a bare type (and in general) #12347

Closed
SimonSapin opened this issue Feb 17, 2014 · 4 comments
Closed

Better error message about [T] as a bare type (and in general) #12347

SimonSapin opened this issue Feb 17, 2014 · 4 comments

Comments

@SimonSapin
Copy link
Contributor

From twitter:

Compilers really need to make suggestions about what can be done to resolve an error. e.g. for rustc the compiler complains about using T[] as a bare type. Should suggest that you need to use ~, etc. otherwise the error is very opaque.

https://twitter.com/alex_gaynor/status/435446756264779777
https://twitter.com/alex_gaynor/status/435446869452263424

This bug is not only about giving a better error message for this specific case, but also about giving suggestions in general.

@adrientetar
Copy link
Contributor

This sounds like #12144.

@SimonSapin
Copy link
Contributor Author

It’s related to #12144 (the suggestions of how to fix a problem could be given by rustc --explain, although having a short version inline would be valuable IMO), but not quite the same.

@treeman
Copy link
Contributor

treeman commented Sep 2, 2014

Edited as I used an outdated rustc. Now with DST, cc #12938

fn foo(x: [uint]) { }
fn main() { }
tst.rs:1:8: 1:9 error: mismatched types: expected `[uint]`, found `<generic #0>` (expected vector, found inferred type)
tst.rs:1 fn foo(x: [uint]) { }
                ^
error: aborting due to previous error

Which still could be improved.

@thestinger
Copy link
Contributor

It's now a valid bare type and the error message is fine:

foo.rs:1:8: 1:9 error: variable `x` has dynamically sized type `[uint]` [E0151]
foo.rs:1 fn foo(x: [uint]) { }

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
fix(extract_module) resolving import panics and improve import resolution

- Should solve rust-lang#11766
- While adding a test case for this issue, I observed another issue:
For this test case:
```rust
            mod x {
                pub struct Foo;
                pub struct Bar;
            }

            use x::{Bar, Foo};

            $0type A = (Foo, Bar);$0
```
extract module should yield this:

```rust
            mod x {
                pub struct Foo;
                pub struct Bar;
            }

            use x::{};

            mod modname {
                use super::x::Bar;

                use super::x::Foo;

                pub(crate) type A = (Foo, Bar);
            }
```

instead it gave:

```rust
            mod x {
                pub struct Foo;
                pub struct Bar;
            }

            use x::{};

            mod modname {
                use x::Bar;

                use x::Foo;

                pub(crate) type A = (Foo, Bar);
            }
```

So fixed this problem with second commit
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

4 participants