Commit Graph

113 Commits

Author SHA1 Message Date
sinkuu
8a64cf7fb7 Fix suggestion span error with a line containing non-ASCIIs 2017-02-25 22:11:54 +09:00
Niko Matsakis
d9aaca71cc store typeck lints in the TypeckTables
Otherwise they are a "hidden output"
2017-02-02 20:38:16 -05:00
bors
d2d8ae6575 Auto merge of #39214 - estebank:fix-labels-without-msg, r=nikomatsakis
Fix multiple labels when some don't have message

The diagnostic emitter now accounts for labels with no text message, presenting the underline on its own, without drawing the line for the non existing message below it. Go from

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ----^^^^^^^----
  |   |   |
  |   |   `b` is a good letter
  |
```

to

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ----^^^^^^^----
  |       |
  |       `b` is a good letter
```

from

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ^^^^-------^^^^
  |   |   |
  |   |
  |   `a` is a good letter
```

to

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ^^^^-------^^^^ `a` is a good letter
```

and from

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ^^^^-------^^^^
  |   |   |
  |   |
  |
```

to

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ^^^^-------^^^^
```
r? @nikomatsakis
cc @jonathandturner, @GuillaumeGomez, @nrc
2017-01-24 11:51:34 +00:00
Jeffrey Seyfried
191abc4264 Remove unused extern crates. 2017-01-22 01:31:02 +00:00
Jeffrey Seyfried
356fa2c5db Warn on unused #[macro_use] imports. 2017-01-22 01:31:00 +00:00
Esteban Küber
469ecef422 Fix multiple labels when some don't have message
The diagnostic emitter now accounts for labels with no text message,
presenting the underline on its own, without drawing the line for the
non existing message below it. Go from

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ----^^^^^^^----
  |   |   |
  |   |   `b` is a good letter
  |
```

to

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ----^^^^^^^----
  |       |
  |       `b` is a good letter
```

and from

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ^^^^-------^^^^
  |   |   |
  |   |
  |   `a` is a good letter
```

to

```
error: foo
 --> test.rs:3:6
  |
3 |   a { b { c } d }
  |   ^^^^-------^^^^ `a` is a good letter
```
2017-01-20 21:15:24 -08:00
Esteban Küber
fc774e629f Teach Diagnostics to highlight text 2017-01-17 14:28:53 -08:00
bors
e57f061be2 Auto merge of #38916 - estebank:pad-suggestion-list, r=nikomatsakis
Teach diagnostics to correct margin of multiline messages

Make the suggestion list have a correct padding:

```
error[E0308]: mismatched types
 --> file.rs:3:20
  |
3 |     let x: usize = "";
  |                    ^^ expected usize, found reference
  |
  = note: expected type `usize`
  = note:    found type `&'static str`
  = help: here are some functions which might fulfill your needs:
          - .len()
          - .foo()
          - .bar()
```
2017-01-11 05:27:11 +00:00
Esteban Küber
04e4a60b45 Deduplicate and document logic 2017-01-09 09:11:26 -08:00
Esteban Küber
690476191d Remove magic number 2017-01-08 21:18:24 -08:00
Esteban Küber
b206064fc8 Teach diagnostics to correct margin on multiline messages
Make any diagnostic line to have the correct margin to align with the
first line:

```
error: message
 --> file.rs:3:20
  |
3 |     <CODE>
  |      ^^^^
  |
  = note: this is a multiline
          note with a correct
          margin
  = note: this is a single line note
  = help: here are some functions which might fulfill your needs:
          - .len()
          - .foo()
          - .bar()
  = suggestion: this is a multiline
                suggestion with a
                correct margin
```
2017-01-08 16:07:14 -08:00
Esteban Küber
f65a907ef9 Use fold instead of collect/join and add comments 2017-01-08 13:12:13 -08:00
Esteban Küber
43b10fa8ed Teach diagnostics to have correctly padded lists
Make the suggestion list have a correct padding:

```
error[E0308]: mismatched types
 --> file.rs:3:20
  |
3 |     let x: usize = "";
  |                    ^^ expected usize, found reference
  |
  = note: expected type `usize`
  = note:    found type `&'static str`
  = help: here are some functions which might fulfill your needs:
          - .len()
          - .foo()
          - .bar()
```
2017-01-07 23:34:37 -08:00
Alex Crichton
9b0b5b45db Remove not(stage0) from deny(warnings)
Historically this was done to accommodate bugs in lints, but there hasn't been a
bug in a lint since this feature was added which the warnings affected. Let's
completely purge warnings from all our stages by denying warnings in all stages.
This will also assist in tracking down `stage0` code to be removed whenever
we're updating the bootstrap compiler.
2016-12-29 21:07:20 -08:00
bors
b4b1e5ece2 Auto merge of #38049 - frewsxcv:libunicode, r=alexcrichton
Rename 'librustc_unicode' crate to 'libstd_unicode'.

Fixes https://github.com/rust-lang/rust/issues/26554.
2016-12-12 13:19:33 +00:00
Alex Crichton
2186660b51 Update the bootstrap compiler
Now that we've got a beta build, let's use it!
2016-11-30 10:38:08 -08:00
Corey Farwell
274777a158 Rename 'librustc_unicode' crate to 'libstd_unicode'.
Fixes #26554.
2016-11-30 01:24:01 -05:00
Esteban Küber
b7982bbbe0 review comments 2016-11-23 23:44:17 -08:00
Esteban Küber
eb53ca3aad Show multiline spans in full if short enough
When dealing with multiline spans that span few lines, show the complete
span instead of restricting to the first character of the first line.

For example, instead of:

```
% ./rustc foo.rs
error[E0277]: the trait bound `{integer}: std::ops::Add<()>` is not satisfied
  --> foo.rs:13:9
   |
13 |    foo(1 + bar(x,
   |        ^ trait `{integer}: std::ops::Add<()>` not satisfied
   |
```

show

```
% ./rustc foo.rs
error[E0277]: the trait bound `{integer}: std::ops::Add<()>` is not satisfied
  --> foo.rs:13:9
   |
13 |      foo(1 + bar(x,
   |  ________^ starting here...
14 | |            y),
   | |_____________^ ...ending here: trait `{integer}: std::ops::Add<()>` not satisfied
   |
```
2016-11-22 13:42:36 -08:00
Alex Crichton
0eff43ff75 Merge branch 'new-rustbuild' into rollup 2016-11-05 10:50:26 -07:00
Alex Crichton
a270b8014c rustbuild: Rewrite user-facing interface
This commit is a rewrite of the user-facing interface to the rustbuild build
system. The intention here is to make it much easier to compile/test the project
without having to remember weird rule names and such. An overall view of the new
interface is:

    # build everything
    ./x.py build

    # document everyting
    ./x.py doc

    # test everything
    ./x.py test

    # test libstd
    ./x.py test src/libstd

    # build libcore stage0
    ./x.py build src/libcore --stage 0

    # run stage1 run-pass tests
    ./x.py test src/test/run-pass --stage 1

The `src/bootstrap/bootstrap.py` script is now aliased as a top-level `x.py`
script. This `x` was chosen to be both short and easily tab-completable (no
collisions in that namespace!). The build system now accepts a "subcommand" of
what to do next, the main ones being build/doc/test.

Each subcommand then receives an optional list of arguments. These arguments are
paths in the source repo of what to work with. That is, if you want to test a
directory, you just pass that directory as an argument.

The purpose of this rewrite is to do away with all of the arcane renames like
"rpass" is the "run-pass" suite, "cfail" is the "compile-fail" suite, etc. By
simply working with directories and files it's much more intuitive of how to run
a test (just pass it as an argument).

The rustbuild step/dependency management was also rewritten along the way to
make this easy to work with and define, but that's largely just a refactoring of
what was there before.

The *intention* is that this support is extended for arbitrary files (e.g.
`src/test/run-pass/my-test-case.rs`), but that isn't quite implemented just yet.
Instead directories work for now but we can follow up with stricter path
filtering logic to plumb through all the arguments.
2016-11-02 17:57:28 -07:00
Niko Matsakis
ad46ad6a77 pacify the mercilous tidy 2016-11-01 14:08:56 -04:00
Niko Matsakis
2b5bc487c5 improve early lint to use multispan from diagnostic 2016-11-01 14:08:56 -04:00
Niko Matsakis
ddabd509a8 compare-method lint 2016-11-01 14:08:56 -04:00
Niko Matsakis
f652651275 retool EarlyLint to track a Diagnostic 2016-11-01 14:07:45 -04:00
Niko Matsakis
888a92cef3 separate Diagnostic from DiagnosticBuilder 2016-11-01 14:07:45 -04:00
Srinivas Reddy Thatiparthy
b260617345
run rustfmt on librustc_errors folder 2016-10-18 23:13:02 +05:30
Nick Cameron
9bc6d26092 Stabilise ?
cc [`?` tracking issue](https://github.com/rust-lang/rust/issues/31436)
2016-10-12 08:40:22 +13:00
Nick Cameron
e8a4db25ac Allow supplying an error destination via the compiler driver
Allows replacing stderr with a buffer from the client.

Also, some refactoring around run_compiler.
2016-09-28 16:20:30 +13:00
Guillaume Gomez
f17bdb7eec Rollup merge of #36498 - jonathandturner:macro_std_lib, r=nikomatsakis
Fix wording for out-of-crate macro error

This fixes the wording of the note for out-of-crate macro errors to fix https://github.com/rust-lang/rust/issues/36469

The previous wording came from older logic in the PR that was replaced without updating the note.
2016-09-24 00:15:44 +02:00
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