Commit Graph

113 Commits

Author SHA1 Message Date
gaurikholkar
26a8357f5c reorder span labels 2017-07-18 00:07:37 +05:30
Oliver Schneider
a9d9a4aab4
Change some helps to suggestions 2017-07-17 10:03:37 +02:00
Kevin Mehall
17bd76a516 Remove unused code from librustc_errors 2017-07-06 18:49:32 -07:00
Esteban Küber
697c85a4f1 Only underline suggestion if it is not the only code being shown 2017-07-06 14:36:49 -07:00
Esteban Küber
eb478e2381 Add extra whitespace for suggestions 2017-07-06 14:36:48 -07:00
Esteban Küber
7c84914635 Make suggestion include the line number
When there're more than one suggestions in the same diagnostic, they are
displayed in their own block, instead of inline. In order to reduce
confusion, those blocks now display the line number.
2017-07-06 14:36:48 -07:00
Ariel Ben-Yehuda
77f4022303 Revert "Change error count messages"
This reverts commit 5558c64f33.
2017-07-02 13:49:30 +03:00
Esteban Küber
ecde91a69d Suggest removal of semicolon (instead of being help) 2017-06-24 10:08:51 -07:00
Alex Crichton
be7ebdd512 Bump version and stage0 compiler 2017-06-19 22:25:05 -07:00
bors
28cc0c5a7b Auto merge of #42593 - ibabushkin:on-demand-external-source, r=eddyb
Implement lazy loading of external crates' sources. Fixes #38875

Fixes #38875. This is a follow-up to #42507. When a (now correctly translated) span from an external crate is referenced in a error, warning or info message, we still don't have the source code being referenced.
Since stuffing the source in the serialized metadata of an rlib is extremely wasteful, the following scheme has been implemented:

* File maps now contain a source hash that gets serialized as well.
* When a span is rendered in a message, the source hash in the corresponding file map(s) is used to try and load the source from the corresponding file on disk. If the file is not found or the hashes don't match, the failed attempt is recorded (and not retried).
* The machinery fetching source lines from file maps is augmented to use the lazily loaded external source as a secondary fallback for file maps belonging to external crates.

This required a small change to the expected stderr of one UI test (it now renders a span, where previously was none).

Further work can be done based on this - some of the machinery previously used to hide external spans is possibly obsolete and the hashing code can be reused in different places as well.

r? @eddyb
2017-06-18 10:41:05 +00:00
bors
4581e89a49 Auto merge of #42690 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests

- Successful merges: #42616, #42651, #42654, #42656, #42685
- Failed merges:
2017-06-16 05:43:38 +00:00
Esteban Küber
8074a88787 Position span label correctly when it isn't last 2017-06-15 11:21:19 -07:00
Inokentiy Babushkin
271133b03e
External spans: address review.
* The lazy loading mechanism has been moved to a more appropriate place.
* Return values from the functions invoked there are properly used.
* Documentation has gotten some minor improvements.
* Possibly some larger restructuring will need to take place still.
2017-06-12 15:37:26 +02:00
Esteban Küber
3a7dbf48fe Suggest non-ambiguous comparison after cast
```
warning: `<` is interpreted as a start of generic arguments for `usize`, not comparison
  --> $DIR/issue-22644.rs:16:33
   |
16 |     println!("{}", a as usize < b);
   |                                 ^ expected one of `!`, `(`, `+`, `,`, `::`, or `>` here
   |
help: if you want to compare the casted value then write
   |     println!("{}", (a as usize) < b);
```
2017-06-11 23:47:26 -07:00
Inokentiy Babushkin
a5b8851e22
Added consumption logic for external sources in FileMap
We now fetch source lines from the `external_src` member as a secondary
fallback if no regular source is present, that is, if the file map
belongs to an external crate and the source has been fetched from disk.
2017-06-11 13:31:40 +02:00
Inokentiy Babushkin
c04aa4ed0c
Improved lazy external source loading and inserted calls. 2017-06-11 11:47:00 +02:00
Inokentiy Babushkin
c2c31b2db3
Added external crates' sources to FileMap.
They are now handled in their own member to prevent mutating access to
the `src` member. This way, we can safely load external sources, while
keeping the mutation of local source strings off-limits.
2017-06-10 21:08:32 +02:00
bors
0418fa9d38 Auto merge of #42362 - estebank:type, r=arielb1
Show trait method signature when impl differs

When the trait's span is available, it is already being used, add a
`note` for the cases where the span isn't available:

<pre>
error[E0053]: <b>method `fmt` has an incompatible type for trait</b>
  --> $DIR/trait_type.rs:17:4
   |
17 |    fn fmt(&self, x: &str) -> () { }
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
   |
   = note: expected type `<b>fn(&MyType, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error></b>`
              found type `<b>fn(&MyType, &str)</b>`

error[E0050]: <b>method `fmt` has 1 parameter but the declaration in trait `std::fmt::Display::fmt` has 2</b>
  --> $DIR/trait_type.rs:21:11
   |
21 |    fn fmt(&self) -> () { }
   |           ^^^^^ expected 2 parameters, found 1
   |
   = note: `fmt` from trait: `<b>fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error></b>`

error[E0186]: <b>method `fmt` has a `&self` declaration in the trait, but not in the impl</b>
  --> $DIR/trait_type.rs:25:4
   |
25 |    fn fmt() -> () { }
   |    ^^^^^^^^^^^^^^^^^^ expected `&self` in impl
   |
   = note: `fmt` from trait: `<b>fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error></b>`

error[E0046]: <b>not all trait items implemented, missing: `fmt`</b>
  --> $DIR/trait_type.rs:28:1
   |
28 | impl std::fmt::Display for MyType4 {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `fmt` in implementation
   |
   = note: `fmt` from trait: `<b>fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error></b>`
</code></pre>

Fix #28011.
2017-06-04 20:16:09 +00:00
Esteban Küber
e324919ec5 Show trait method signature when impl differs
When the trait's span is available, it is already being used, add a
`note` for the cases where the span isn't available:

```
error[E0053]: method `fmt` has an incompatible type for trait
  --> $DIR/trait_type.rs:17:4
   |
17 |    fn fmt(&self, x: &str) -> () { }
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
   |
   = note: expected type `fn(&MyType, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>`
              found type `fn(&MyType, &str)`

error[E0050]: method `fmt` has 1 parameter but the declaration in trait `std::fmt::Display::fmt` has 2
  --> $DIR/trait_type.rs:21:11
   |
21 |    fn fmt(&self) -> () { }
   |           ^^^^^ expected 2 parameters, found 1
   |
   = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>`

error[E0186]: method `fmt` has a `&self` declaration in the trait, but not in the impl
  --> $DIR/trait_type.rs:25:4
   |
25 |    fn fmt() -> () { }
   |    ^^^^^^^^^^^^^^^^^^ expected `&self` in impl
   |
   = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>`

error[E0046]: not all trait items implemented, missing: `fmt`
  --> $DIR/trait_type.rs:28:1
   |
28 | impl std::fmt::Display for MyType4 {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `fmt` in implementation
   |
   = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>`
```
2017-06-04 12:52:55 -07:00
Esteban Küber
4142d7bb89 Use callsite's span for macro calls on suggestion
When suggesting an appropriate mutability for a macro call, use the call
span instead of the expanded macro's span.
2017-05-31 23:48:19 -07:00
Guillaume Gomez
a333be7cfe Add new error code 2017-05-30 19:19:34 +02:00
Michael Kohl
5558c64f33 Change error count messages
See #33525 for details.
2017-05-24 16:14:38 +07:00
Andre Bogus
fc513861b1 fix some clippy warnings in librustc_errors 2017-05-19 01:20:48 +02:00
bors
ef3ec5ece5 Auto merge of #41965 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 15 pull requests

- Successful merges: #41820, #41860, #41876, #41896, #41912, #41916, #41918, #41921, #41923, #41934, #41935, #41940, #41942, #41943, #41951
- Failed merges:
2017-05-13 11:35:59 +00:00
Mark Simulacrum
c17811cce3 Rollup merge of #41942 - tommyip:master, r=Mark-Simulacrum
Fix unexpected panic with the -Z treat-err-as-bug option

This fix an issue where the compiler panics even if there is no error when passed with the `-Z treat-err-as-bug` option.

Fixes #35886.

r? @Mark-Simulacrum
2017-05-12 18:57:37 -06:00
Mark Simulacrum
f6bf99af5c Rollup merge of #41934 - est31:remove_unused_macros, r=nagisa
Remove unused macros from the codebase

Thanks to the lint I've implemented in #41907 I've found some unused macros inside the rustc codebase.
2017-05-12 18:57:34 -06:00
Tommy Ip
7a03b4c75a Fix unexpected panic with the -Z treat-err-as-bug option
This fix an issue where the compiler panics even if there is no
error when passed with the `-Z treat-err-as-bug` option.

Fixes #35886.
2017-05-12 12:54:20 +01:00
est31
80891f6e47 Remove some unused macros from the rust codebase
Removes unused macros from:
  * libcore
  * libcollections
    The last use of these two macros was removed in commit
    b64c9d5670
    when the char_range_at_reverse function was been removed.
  * librustc_errors
    Their last use was removed by commits
    2f2c3e1783
    and 11dc974a38.
  * libsyntax_ext
  * librustc_trans
    Also, put the otry macro in back/msvc/mod.rs under the
    same cfg argument as the places that use it.
2017-05-12 09:37:28 +02:00
Alex Crichton
ab54f4b226 rustc: Remove #![unstable] annotation
These are now no longer necessary with `-Z force-unstable-if-unmarked`
2017-05-11 16:03:05 -07:00
Oliver Schneider
644ce5e535 Address PR reviews 2017-05-11 15:26:22 +02:00
Oliver Schneider
e2f781c7ea
Example usage of multiple suggestions 2017-05-10 13:20:27 +02:00
Oliver Schneider
67d762d896
Refactor suggestion diagnostic API to allow for multiple suggestions 2017-05-10 13:20:26 +02:00
Corey Farwell
1940c31c92 Rollup merge of #41520 - estebank:trace-macro, r=nikomatsakis
Use diagnostics for trace_macro instead of println

When using `trace_macro`, use `span_label`s instead of `println`:

```rust
note: trace_macro
  --> $DIR/trace-macro.rs:14:5
   |
14 |     println!("Hello, World!");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: expands to `println! { "Hello, World!" }`
   = note: expands to `print! { concat ! ( "Hello, World!" , "\n" ) }`
```

Fix #22597.
2017-05-08 22:34:47 -04:00
Oliver Schneider
dd87eabd83 Remove need for &format!(...) or &&"" dances in span_label calls 2017-05-08 12:56:15 +02:00
Esteban Küber
8c9ad8d72c Group "macro expansion" notes per call span 2017-05-06 00:55:42 -07:00
Esteban Küber
56411443f2 Use diagnostics for trace_macro instead of println 2017-05-05 15:51:48 -07:00
kennytm
81bfdc83ca
Fix issue #41652.
Don't print the source code in emit_message_default() and
render_source_line() if the source code is None.
2017-05-03 13:00:33 +08:00
bors
33535afda4 Auto merge of #40851 - oli-obk:multisugg, r=jonathandturner
Minimize single span suggestions into a label

changes

```
14 |     println!("☃{}", tup[0]);
   |                     ^^^^^^
   |
help: to access tuple elements, use tuple indexing syntax as shown
   |     println!("☃{}", tup.0);
```

into

```
14 |     println!("☃{}", tup[0]);
   |                     ^^^^^^ to access tuple elements, use `tup.0`
```

Also makes suggestions explicit in the backend in preparation of adding multiple suggestions to a single diagnostic. Currently that's already possible, but results in a full help message + modified code snippet per suggestion, and has no rate limit (might show 100+ suggestions).
2017-05-02 01:04:27 +00:00
Ariel Ben-Yehuda
a260df27e0 typeck: resolve type vars before calling try_index_step
`try_index_step` does not resolve type variables by itself and would
fail otherwise. Also harden the failure path in `confirm` to cause less
confusing errors.
2017-04-27 16:44:27 +03:00
Oliver Schneider
d64af4a627 Rebase and address comments 2017-04-25 13:35:04 +02:00
Oliver Schneider
f4b1e2af68
Improve E0178 suggestion placement 2017-04-25 11:07:42 +02:00
Oliver Schneider
3a5567bad4
Address PR comments 2017-04-25 11:07:42 +02:00
Oliver Schneider
0e920fde4f
Minimize single span suggestions into a note 2017-04-25 11:04:34 +02:00
Esteban Küber
cc07c357e4 Reduce visual clutter of multiline start when possible
When a span starts on a line with nothing but whitespace to the left,
and there are no other annotations in that line, simplify the visual
representation of the span.

Go from:

```rust
error[E0072]: recursive type `A` has infinite size
 --> file2.rs:1:1
  |
1 |   struct A {
  |  _^ starting here...
2 | |     a: A,
3 | | }
  | |_^ ...ending here: recursive type has infinite size
  |
```

To:

```rust
error[E0072]: recursive type `A` has infinite size
 --> file2.rs:1:1
  |
1 | / struct A {
2 | |     a: A,
3 | | }
  | |_^ recursive type has infinite size
```

Remove `starting here...`/`...ending here` labels from all multiline
diagnostics.
2017-04-20 17:31:20 -07:00
Tim Neumann
afb300d831 Rollup merge of #41205 - estebank:shorter-mismatched-types-2, r=nikomatsakis
Highlight and simplify mismatched types

Shorten mismatched types errors by replacing subtypes that are not
different with `_`, and highlighting only the subtypes that are
different.

Given a file

```rust
struct X<T1, T2> {
    x: T1,
    y: T2,
}

fn foo() -> X<X<String, String>, String> {
    X { x: X {x: "".to_string(), y: 2}, y: "".to_string()}
}

fn bar() -> Option<String> {
    "".to_string()
}
```

provide the following output

```rust
error[E0308]: mismatched types
  --> file.rs:6:5
   |
 6 |     X { x: X {x: "".to_string(), y: 2}, y: "".to_string()}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found {integer}
   |
   = note: expected type `X<X<_, std::string::String>, _>`
                                 ^^^^^^^^^^^^^^^^^^^   // < highlighted
              found type `X<X<_, {integer}>, _>`
                                 ^^^^^^^^^             // < highlighted

error[E0308]: mismatched types
  --> file.rs:6:5
   |
10 |     "".to_string()
   |     ^^^^^^^^^^^^^^ expected struct `std::option::Option`, found `std::string::String`
   |
   = note: expected type `Option<std::string::String>`
                          ^^^^^^^                   ^  // < highlighted
              found type `std::string::String`
```

Fix #21025. Re: #40186. Follow up to #39906.

I'm looking to change how this output is accomplished so that it doesn't create list of strings to pass around, but rather add an elided `Ty` placeholder, and use the same string formatting for normal types. I'll be doing that soonish.

r? @nikomatsakis
2017-04-12 14:45:45 +02:00
Esteban Küber
2389830dea Highlight and simplify mismatched types
Shorten mismatched types errors by replacing subtypes that are not
different with `_`, and highlighting only the subtypes that are
different.

Given a file

```rust
struct X<T1, T2> {
    x: T1,
    y: T2,
}

fn foo() -> X<X<String, String>, String> {
    X { x: X {x: "".to_string(), y: 2}, y: "".to_string()}
}

fn bar() -> Option<String> {
    "".to_string()
}
```

provide the following output

```rust
error[E0308]: mismatched types
  --> file.rs:6:5
   |
 6 |     X { x: X {x: "".to_string(), y: 2}, y: "".to_string()}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found {integer}
   |
   = note: expected type `X<X<_, std::string::String>, _>`
                                 ^^^^^^^^^^^^^^^^^^^   // < highlighted
              found type `X<X<_, {integer}>, _>`
                                 ^^^^^^^^^             // < highlighted

error[E0308]: mismatched types
  --> file.rs:6:5
   |
10 |     "".to_string()
   |     ^^^^^^^^^^^^^^ expected struct `std::option::Option`, found `std::string::String`
   |
   = note: expected type `Option<std::string::String>`
                          ^^^^^^^                   ^  // < highlighted
              found type `std::string::String`
```
2017-04-11 15:45:00 -07:00
Esteban Küber
4bc7f5b52c Always show end line of multiline annotations
```rust
error[E0046]: not all trait items implemented, missing: `Item`
  --> $DIR/issue-23729.rs:20:9
   |
20 |           impl Iterator for Recurrence {
   |  _________^ starting here...
21 | |             //~^ ERROR E0046
22 | |             //~| NOTE missing `Item` in implementation
23 | |             //~| NOTE `Item` from trait: `type Item;`
...  |
36 | |             }
37 | |         }
   | |_________^ ...ending here: missing `Item` in implementation
   |
   = note: `Item` from trait: `type Item;`
```

instead of

```rust
error[E0046]: not all trait items implemented, missing: `Item`
  --> $DIR/issue-23729.rs:20:9
   |
20 |         impl Iterator for Recurrence {
   |         ^ missing `Item` in implementation
   |
   = note: `Item` from trait: `type Item;`
```
2017-04-09 13:48:25 -07:00
Jeffrey Seyfried
ec7c0aece1 Merge ExpnId and SyntaxContext. 2017-03-29 00:41:10 +00:00
Alex Crichton
c253eb23a6 Rollup merge of #40287 - estebank:label-overlap, r=nrc
Fix incorrect span label formatting

Fix #40157.
2017-03-10 16:18:28 -08:00
Esteban Küber
7b0dd7bdb8 Fix incorrect span label formatting 2017-03-10 08:14:31 -08:00