Commit Graph

283 Commits

Author SHA1 Message Date
Jonathan Turner
2ea3ab3a90 Add the ability to merge spans to codemap 2016-09-19 12:31:56 -07:00
bors
89500e9341 Auto merge of #36338 - estebank:primitive-shadow, r=jseyfried
Be more specific when type parameter shadows primitive type

When a type parameter shadows a primitive type, the error message
was non obvious. For example, given the file `file.rs`:

```rust
trait Parser<T> {
    fn parse(text: &str) -> Option<T>;
}

impl<bool> Parser<bool> for bool {
    fn parse(text: &str) -> Option<bool> {
        Some(true)
    }
}

fn main() {
    println!("{}", bool::parse("ok").unwrap_or(false));
}
```

The output was:

```bash
% rustc file.rs
error[E0308]: mismatched types
 --> file.rs:7:14
  |
7 |         Some(true)
  |              ^^^^ expected type parameter, found bool a
  |
  = note: expected type `bool`
  = note:    found type `bool`

error: aborting due to previous error
```

We now show extra information about the type:

```bash
% rustc file.rs
error[E0308]: mismatched types
 --> file.rs:7:14
  |
7 |         Some(true)
  |              ^^^^ expected type parameter, found bool a
  |
  = note: expected type `bool` (type parameter)
  = note:    found type `bool` (bool)

error: aborting due to previous error
```

Fixes #35030
2016-09-16 00:39:27 -07:00
Esteban Küber
68e8624d05 Specify when type parameter shadows primitive type
When a type parameter shadows a primitive type, the error message
was non obvious. For example, given the file `file.rs`:

```rust
trait Parser<T> {
    fn parse(text: &str) -> Option<T>;
}

impl<bool> Parser<bool> for bool {
    fn parse(text: &str) -> Option<bool> {
        Some(true)
    }
}

fn main() {
    println!("{}", bool::parse("ok").unwrap_or(false));
}
```

The output was:

```bash
% rustc file.rs
error[E0308]: mismatched types
 --> file.rs:7:14
  |
7 |         Some(true)
  |              ^^^^ expected type parameter, found bool
  |
  = note: expected type `bool`
  = note:    found type `bool`

error: aborting due to previous error
```

We now show extra information about the type:

```bash
% rustc file.rs
error[E0308]: mismatched types
 --> file.rs:7:14
  |
7 |         Some(true)
  |              ^^^^ expected type parameter, found bool
  |
  = note: expected type `bool` (type parameter)
  = note:    found type `bool` (bool)

error: aborting due to previous error
```

Fixes #35030
2016-09-15 20:06:29 -07:00
Jonathan Turner
d7428944c2 Fix wording for out-of-crate macro error 2016-09-15 10:12:56 -07:00
Ahmed Charles
8391760bd8 Use question_mark feature in librustc_errors. 2016-09-11 16:00:50 -07:00
Jonathan Turner
1b0476297e Special case a few colors for Windows 2016-08-31 15:19:43 -07:00
Jonathan Turner
a65b201d94 prevent error message interleaving on win/unix 2016-08-25 13:28:35 -07:00
Jonathan Turner
9072861c20 Rollup merge of #35839 - jonathandturner:error_touchup, r=Aatch
Wording fixes in error messages

This PR is largely wording fixes to existing PRs that I found going back through the ones that have already been updated.  Sometimes seeing the message in context made me think "oh there's a better wording!"

There's one additional fix.  This will also prevent the secondary underlining of derive call (since they look like macros to the system in the way I was using):

```
error[E0184]: the trait `Copy` may not be implemented for this type; the type has a destructor
  --> src/test/compile-fail/E0184.rs:11:10
   |
11 | #[derive(Copy)] //~ ERROR E0184
   |          ^^^^
   |          |
   |          in this macro invocation
```

Is now just:

```
error[E0184]: the trait `Copy` may not be implemented for this type; the type has a destructor
  --> src/test/compile-fail/E0184.rs:11:10
   |
11 | #[derive(Copy)] //~ ERROR E0184
   |          ^^^^
```
2016-08-20 07:09:37 -07:00
bors
38fa82a314 Auto merge of #33922 - estebank:doc-comment, r=alexcrichton
Specific error message for missplaced doc comments

Identify when documetation comments have been missplaced in the following places:

 * After a struct element:

    ```rust
    // file.rs:
    struct X {
        a: u8 /** document a */,
    }
    ```

    ```bash
    $ rustc file.rs
    file.rs:2:11: 2:28 error: found documentation comment that doesn't
    document anything
    file.rs:2     a: u8 /** document a */,
                        ^~~~~~~~~~~~~~~~~
    file.rs:2:11: 2:28 help: doc comments must come before what they document,
    maybe a comment was intended with `//`?
    ```

 * As the last line of a struct:

    ```rust
    // file.rs:
    struct X {
        a: u8,
        /// incorrect documentation
    }
    ```

    ```bash
    $ rustc file.rs
    file.rs:3:5: 3:27 error: found a documentation comment that doesn't
    document anything
    file.rs:3     /// incorrect documentation
                  ^~~~~~~~~~~~~~~~~~~~~~
    file.rs:3:5: 3:27 help: doc comments must come before what they document,
    maybe a comment was intended with `//`?
    ```

 * As the last line of a `fn`:

    ```rust
    // file.rs:
    fn main() {
        let x = 1;
        /// incorrect documentation
    }
    ```

    ```bash
    $ rustc file.rs
    file.rs:3:5: 3:27 error: found a documentation comment that doesn't
    document anything
    file.rs:3     /// incorrect documentation
                  ^~~~~~~~~~~~~~~~~~~~~~
    file.rs:3:5: 3:27 help: doc comments must come before what they document,
    maybe a comment was intended with `//`?
    ```

Fix #27429, #30322
2016-08-19 18:14:53 -07:00
Jonathan Turner
54d0acd2fc wording fixes in error messages 2016-08-19 16:05:37 -07:00
Jonathan Turner
54d42cc912 Rebase. Fix mutable iteration nit. 2016-08-17 15:11:18 -07:00
Jonathan Turner
61865384b8 Replace local backtrace with def-use, repair std macro spans 2016-08-17 14:26:14 -07:00
Jonathan Turner
fad4f32c31 Turn on new errors, json mode. Remove duplicate unicode test 2016-08-07 07:46:49 -07:00
Ariel Ben-Yehuda
1e4f6d5683 rustc_errors: fix a few bugs 2016-07-22 22:47:38 +03:00
Jonathan Turner
dae8d073d4 Nudge travis by commenting a little 2016-07-15 06:52:19 -04:00
Jonathan Turner
d162b97c4b Teach EmitterWriter about the dangers of quasi-quoting 2016-07-14 07:57:46 -04:00
Jonathan Turner
1fd014a965 Add fix for tabs. Move error unit tests->ui tests 2016-07-14 07:57:46 -04:00
Jonathan Turner
2e8e73cb95 Add in styled_buffer.rs and remove some unused code 2016-07-14 07:57:46 -04:00
Jonathan Turner
012ff15c94 Fix up some tidy-unfriendly spacing 2016-07-14 07:57:46 -04:00
Jonathan Turner
2f2c3e1783 DCE and fixing some internal tests 2016-07-14 07:57:46 -04:00
Jonathan Turner
f481879d2a Fix a couple UI test failures 2016-07-14 07:57:46 -04:00
Jonathan Turner
8612838dd0 Add back in old school mode 2016-07-14 07:57:46 -04:00
Jonathan Turner
71ec2867e3 Implement latest rfc style using simpler rendering 2016-07-14 07:57:46 -04:00
Jonathan Turner
a019c2c6ba Remove CoreEmitter and focus on Emitter 2016-07-14 07:57:46 -04:00
Jonathan Turner
a6e7239e7b Rename emit_struct->emit 2016-07-14 07:57:46 -04:00
Jonathan Turner
55f06883b8 Remove emit from emitter, leaving emit_struct 2016-07-14 07:57:46 -04:00
Jonathan Turner
8f044fae36 Remove BasicEmitter 2016-07-14 07:57:46 -04:00
Esteban Küber
c8498cc2c2 Specific error message for missplaced doc comments
Identify when documetation comments have been missplaced in the
following places:

 * After a struct element:

    ```rust
    // file.rs:
    struct X {
        a: u8 /** document a */,
    }
    ```

    ```bash
    $ rustc file.rs
    file.rs:2:11: 2:28 error: found documentation comment that doesn't
    document anything
    file.rs:2     a: u8 /** document a */,
                        ^~~~~~~~~~~~~~~~~
    file.rs:2:11: 2:28 help: doc comments must come before what they document,
    maybe a comment was intended with `//`?
    ```

 * As the last line of a struct:

    ```rust
    // file.rs:
    struct X {
        a: u8,
        /// incorrect documentation
    }
    ```

    ```bash
    $ rustc file.rs
    file.rs:3:5: 3:27 error: found a documentation comment that doesn't
    document anything
    file.rs:3     /// incorrect documentation
                  ^~~~~~~~~~~~~~~~~~~~~~
    file.rs:3:5: 3:27 help: doc comments must come before what they document,
    maybe a comment was intended with `//`?
    ```

 * As the last line of a `fn`:

    ```rust
    // file.rs:
    fn main() {
        let x = 1;
        /// incorrect documentation
    }
    ```

    ```bash
    $ rustc file.rs
    file.rs:3:5: 3:27 error: found a documentation comment that doesn't
    document anything
    file.rs:3     /// incorrect documentation
                  ^~~~~~~~~~~~~~~~~~~~~~
    file.rs:3:5: 3:27 help: doc comments must come before what they document,
    maybe a comment was intended with `//`?
    ```

Fix #27429, #30322
2016-07-05 23:09:02 -07:00
Jonathan Turner
80f1c78752 make old school mode a bit more configurable 2016-06-23 15:19:40 -04:00
Jonathan Turner
2b8bab095d Move test helper functions to consolidated codemap testing 2016-06-23 10:50:05 -04:00
Jonathan Turner
f2fe204dcc Consolidate codemap tests and fix more errors for travis 2016-06-23 08:07:35 -04:00
Jonathan Turner
2829fbc638 Address comments and fix travis warning 2016-06-23 08:07:35 -04:00
Jonathan Turner
6ae3502134 Move errors from libsyntax to its own crate 2016-06-23 08:07:35 -04:00