Commit Graph

171 Commits

Author SHA1 Message Date
Manish Goregaokar
730679685e Use correct line offsets for doctests (fixes #45868) 2018-01-10 10:10:34 +05:30
Rafael Fernández López
063607eecb
Only bump error count when we are sure that the diagnostic is not a repetition.
This ensures that if we emit the same diagnostic twice, the error count will
match the real number of errors shown to the user.

Fixes #42106
2018-01-03 00:42:12 +01:00
John Kåre Alsaker
94b712413b Make err_count thread safe 2017-12-21 19:21:39 +01:00
Esteban Küber
c60aab29f1 When attempting to write str with single quote suggest double quotes 2017-12-14 22:51:42 -08:00
Oliver Schneider
d732da813b
Use PathBuf instead of String where applicable 2017-12-14 11:22:08 +01:00
bors
8954b16beb Auto merge of #46605 - estebank:macro-backtrace-spans, r=pnkfelix
Use spans for -Z external-macro-backtrace

```
% rustc ui/type-check/cannot_infer_local_or_vec.rs -Z external-macro-backtrace
error[E0282]: type annotations needed
  --> <vec macros>:3:1
   |
1  | / ( $ elem : expr ; $ n : expr ) => (
2  | | $ crate :: vec :: from_elem ( $ elem , $ n ) ) ; ( $ ( $ x : expr ) , * ) => (
3  | | < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ) ) ; ( $ ( $ x : expr , ) * )
   | | ^^^^^^^^^^^^^^^^^^^^^
   | | |
   | | cannot infer type for `T`
4  | | => ( vec ! [ $ ( $ x ) , * ] )
   | |______________________________- in this expansion of `vec!`
   |
  ::: ui/type-check/cannot_infer_local_or_vec.rs
   |
12 |       let x = vec![];
   |           -   ------ in this macro invocation
   |           |
   |           consider giving `x` a type

error: aborting due to previous error
```
2017-12-14 07:06:02 +00:00
Esteban Küber
95a0458358 Resolve type on return type suggestion 2017-12-09 15:19:39 -08:00
Esteban Küber
b7bb67abd3 Use spans for -Z external-macro-backtrace
```
% rustc ui/type-check/cannot_infer_local_or_vec.rs -Z external-macro-backtrace
error[E0282]: type annotations needed
  --> <vec macros>:3:1
   |
1  | / ( $ elem : expr ; $ n : expr ) => (
2  | | $ crate :: vec :: from_elem ( $ elem , $ n ) ) ; ( $ ( $ x : expr ) , * ) => (
3  | | < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ) ) ; ( $ ( $ x : expr , ) * )
   | | ^^^^^^^^^^^^^^^^^^^^^
   | | |
   | | cannot infer type for `T`
4  | | => ( vec ! [ $ ( $ x ) , * ] )
   | |______________________________- in this expansion of `vec!`
   |
  ::: ui/type-check/cannot_infer_local_or_vec.rs
   |
12 |       let x = vec![];
   |           -   ------ in this macro invocation
   |           |
   |           consider giving `x` a type

error: aborting due to previous error
```
2017-12-09 12:43:46 -08:00
bors
5a2465e2b4 Auto merge of #45953 - estebank:tab-4, r=nikomatsakis
Display `\t` in diagnostics code as four spaces

Follow up to #44386 using the unicode variable width machinery from #45711 to replace tabs in the source code when displaying a diagnostic error with four spaces (instead of only one), while properly accounting for this when calculating underlines.

Partly addresses #44618.
2017-12-06 21:05:53 +00:00
bors
d1364a65c0 Auto merge of #45997 - estebank:pub-ident, r=nikomatsakis
Account for missing keyword in fn/struct definition

Fix #38911.
2017-12-01 06:06:06 +00:00
Alex Burka
5da957cbc6 mention nightly in -Z external-macro-backtrace note 2017-11-26 18:28:38 +00:00
Esteban Küber
9d80e2200a Display \t in diagnostics code as four spaces 2017-11-24 08:24:31 -08:00
Esteban Küber
1737d69c3b Fix underline in suggestions 2017-11-24 07:34:31 -08:00
kennytm
0af67a4df0 Rollup merge of #46052 - oli-obk:rendered_diagnostics_in_json, r=petrochenkov
Include rendered diagnostic in json

r? @petrochenkov
2017-11-22 01:12:59 +08:00
Alex Burka
b34a7ffb25 address review comments 2017-11-20 18:03:20 +00:00
Oliver Schneider
ddaf523aa4
The end of a span can be *before* the first char in a line 2017-11-20 09:37:54 +01:00
Alex Burka
7a5a1f9857 use -Z flag instead of env var 2017-11-19 22:30:14 +00:00
Alex Burka
bcd1fedf03 add UI test 2017-11-19 22:22:22 +00:00
Alex Burka
c73bcf043e show macro backtrace with env var 2017-11-19 22:22:22 +00:00
Oliver Schneider
47c7e430d3
Remove left over dead code from suggestion diagnostic refactoring 2017-11-16 16:36:49 +01:00
bors
98e791e7e1 Auto merge of #45741 - oli-obk:refactor_suggestions, r=estebank
Refactor internal suggestion API

~~The only functional change is that whitespace, which is suggested to be added, also gets `^^^^` under it. An example is shown in the tests (the only test that changed).~~

Continuation of #41876

r? @nagisa

the changes are probably best viewed [without whitespace](https://github.com/rust-lang/rust/pull/45741/files?w=1)
2017-11-09 15:42:26 +00:00
Oliver Schneider
dfe218ac97
Do not highlight surrounding whitespace 2017-11-06 09:58:53 +01:00
bors
12e6b53744 Auto merge of #45711 - tirr-c:unicode-span, r=estebank
Display spans correctly when there are zero-width or wide characters

Hopefully...
* fixes #45211
* fixes #8706

---

Before:
```
error: invalid width `7` for integer literal
  --> unicode_2.rs:12:25
   |
12 |     let _ = ("a̐éö̲", 0u7);
   |                         ^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: invalid width `42` for integer literal
  --> unicode_2.rs:13:20
   |
13 |     let _ = ("아あ", 1i42);
   |                    ^^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: aborting due to 2 previous errors
```

After:
```
error: invalid width `7` for integer literal
  --> unicode_2.rs:12:25
   |
12 |     let _ = ("a̐éö̲", 0u7);
   |                     ^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: invalid width `42` for integer literal
  --> unicode_2.rs:13:20
   |
13 |     let _ = ("아あ", 1i42);
   |                      ^^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: aborting due to 2 previous errors
```

Spans might display incorrectly on the browser.

r? @estebank
2017-11-04 23:09:19 +00:00
Oliver Schneider
443332afaf
Refactor internal suggestion API 2017-11-03 16:30:04 +01:00
Wonwoo Choi
272c2faa1d Display spans correctly when there are non-half-width characters 2017-11-03 03:15:39 +09:00
Oliver Schneider
6ae440e048
Make the difference between lint codes and error codes explicit 2017-11-02 10:19:41 +01:00
Oliver Schneider
88fb4c4fda
Report lint names in json diagnostics 2017-11-02 10:19:41 +01:00
bors
b218a02ad8 Auto merge of #45519 - michaelwoerister:dedup-errors, r=arielb1
Don't emit the same compiler diagnostic twice.

This PR makes the compiler filter out diagnostic messages that have already been emitted during the same compilation session.
2017-10-26 18:16:15 +00:00
bors
f9d2416594 Auto merge of #44636 - GuillaumeGomez:little-error-msg, r=michaelwoerister
Add short error message-format

Fixes #42653.
2017-10-25 18:19:42 +00:00
Michael Woerister
6fccd71f75 librustc_errors: Don't emit the same error message twice. 2017-10-25 15:01:06 +02:00
Oliver Schneider
1ce1d99b25 Update docs for Diagnostic::span_suggestion(s) 2017-10-24 13:08:30 +02:00
Guillaume Gomez
83bca40350 Add short message-format 2017-10-20 16:04:32 +02:00
Zack M. Davis
d663003e03 fix comment typo, CodeSuggestion path in doc comment
`CodeSuggestion` doesn't live in the `diagnostic` module.
2017-09-29 23:42:24 -07:00
est31
d58281097a Fix mispositioned error indicators
Fixes #38384

Most of the Rust community uses 4 spaces for indentation,
but there are also tab users of Rust (including myself!).

This patch fixes a bug in error printing which mispositions
error indicators when near code with tabs.

The code attempted to fix the issue by replacing spaces
with tabs, but it sadly wasn't enough, as sometimes
you may not print spaces but _ or ^ instead.

This patch employs the reverse strategy: it replaces each
tab with a space, so that the number of _ and ^ and spaces
in error indicators below the code snippet line up
perfectly.

In a study [1] preceeding this patch, we could see that
this strategy is also chosen by gcc version 6.3.0.

Its not perfect, as the output is not beautiful, but its
the easiest to implement. If anyone wants to improve on
this, be my guest! This patch is meant as improvement of
the status quo, not as perfect end status. It fixes the
actual issue of mispositioning error indicators.

[1]: https://github.com/rust-lang/rust/issues/38384#issuecomment-326813710
2017-09-07 10:26:27 +02:00
Alex Crichton
fd4f362b30 Rollup merge of #44125 - SergioBenitez:master, r=nrc
Initial diagnostic API for proc-macros.

This commit introduces the ability to create and emit `Diagnostic` structures from proc-macros, allowing for proc-macro authors to emit warning, error, note, and help messages just like the compiler does.

The API is somewhat based on the diagnostic API already present in `rustc` with several changes that improve usability. The entry point into the diagnostic API is a new `Diagnostic` type which is primarily created through new `error`, `warning`, `help`, and `note` methods on `Span`. The `Diagnostic` type records the diagnostic level, message, and optional `Span` for the top-level diagnostic and contains a `Vec` of all of the child diagnostics. Child diagnostics can be added through builder methods on `Diagnostic`.

A typical use of the API may look like:

```rust
let token = parse_token();
let val = parse_val();

val.span
    .error(format!("expected A but found {}", val))
    .span_note(token.span, "because of this token")
    .help("consider using a different token")
    .emit();
```

cc @jseyfried @nrc @dtolnay @alexcrichton
2017-08-30 11:11:12 -05:00
bors
ca9cf3594a Auto merge of #43968 - petrochenkov:span2, r=michaelwoerister
Make fields of `Span` private

I actually tried to intern spans and benchmark the result<sup>*</sup>, and this was a prerequisite.
This kind of encapsulation will be a prerequisite for any other attempt to compress span's representation, so I decided to submit this change alone.

The issue https://github.com/rust-lang/rust/issues/43088 seems relevant, but it looks like `SpanId` won't be able to reuse this interface, unless the tables are global (like interner that I tried) and are not a part of HIR.
r? @michaelwoerister anyway

<sup>*</sup> Interning means 2-3 times more space is required for a single span, but duplicates are free. In practice it turned out that duplicates are not *that* common, so more memory was wasted by interning rather than saved.
2017-08-30 11:08:26 +00:00
Vadim Petrochenkov
3da868dcb6 Make fields of Span private 2017-08-30 01:38:54 +03:00
Ariel Ben-Yehuda
64a21f875f Rollup merge of #43778 - topecongiro:handler-reset-err-count, r=arielb1
Add reset_err_count() to errors::Handler

The motivation here is to allow rustfmt to recover from parse errors after failing to parse macros (cc https://github.com/rust-lang-nursery/rustfmt/issues/1742).
r? @nrc
2017-08-29 21:40:54 +00:00
Sergio Benitez
8be132e9d7 Initial diagnostic API for proc-macros.
This commit introduces the ability to create and emit `Diagnostic`
structures from proc-macros, allowing for proc-macro authors to emit
warning, error, note, and help messages just like the compiler does.
2017-08-28 02:58:22 -07:00
Tatsuyuki Ishi
7a8d38e522 Additional libc cleanup 2017-08-27 19:02:24 +09:00
bors
669d4770f2 Auto merge of #44081 - est31:master, r=eddyb
Fix a byte/char confusion issue in the error emitter

Fixes #44078. Fixes #44023.

The start_col member is given in chars, while the code previously assumed it was given in bytes.

The more basic issue #44080 doesn't get fixed.
2017-08-26 12:50:11 +00:00
bors
e7070dd019 Auto merge of #44071 - alexcrichton:no-cycles, r=nikomatsakis
rustc: Start moving toward "try_get is a bug" for incremental

This PR is an effort to burn down some of the work items on #42633. The basic change here was to leave the `try_get` function exposed but have it return a `DiagnosticBuilder` instead of a `CycleError`. This means that it should be a compiler bug to *not* handle the error as dropping a diagnostic should result in a complier panic.

After that change it was then necessary to update the compiler's callsites of `try_get` to handle the error coming out. These were handled as:

* The `sized_constraint` and `needs_drop_raw` checks take the diagnostic and defer it as a compiler bug. This was a new piece of functionality added to the error handling infrastructure, and the idea is that for both these checks a "real" compiler error should be emitted elsewhere, so it's only a bug if we don't actually emit the complier error elsewhere.
* MIR inlining was updated to just ignore the diagnostic. This is being tracked by https://github.com/rust-lang/rust/issues/43542 which sounded like it either already had some work underway or was planning to change regardless.
* The final case, `item_path`, is still sort of up for debate. At the time of this writing this PR simply removes the invocations of `try_get` there, assuming that the query will always succeed. This turns out to be true for the test suite anyway! It sounds like, though, that this logic was intended to assist in "weird" situations like `RUST_LOG` where debug implementations can trigger at any time. This PR would therefore, however, break those implementations.

I'm unfortunately sort of out of ideas on how to handle `item_path`, but other thoughts would be welcome!

Closes #42633
2017-08-26 08:25:44 +00:00
Alex Crichton
64b0b2bfeb rustc_errors: Add the ability to delay as bugs
This adds a function to `DiagnosticBuilder` to delay the entire diagnostic as a
bug to be emitted at a later time. This'll end up getting used in the compiler
in the subsequent commits...
2017-08-25 16:08:35 -07:00
bors
83fcd4dbba Auto merge of #43994 - tamird:remove-attributes, r=alexcrichton
*: remove crate_{name,type} attributes

Fixes #41701.

r? @arielb1
2017-08-25 22:54:00 +00:00
Tamir Duberstein
b3f50caee0
*: remove crate_{name,type} attributes
Fixes #41701.
2017-08-25 16:18:21 -04:00
est31
5a71e12351 Fix a byte/char confusion issue in the error emitter
Fixes #44078. Fixes #44023.

The start_col member is given in chars,
while the code previously assumed it was given in bytes.

The more basic issue #44080 doesn't get fixed.
2017-08-25 21:46:54 +02:00
Alex Crichton
8e95b3a939 rustc: Capture diagnostics from all queries
This commit alters the `rustc::ty::maps` implementation to ensure that all
output diagnostics from the compiler are tracked for the duration of each query.
These are then intended to be replayed back the first time a cached value is
loaded, and otherwise the cache should operate the same as it does today.

Closes #42513
2017-08-24 15:18:06 -07:00
Seiichi Uchida
601e3dac6c Add reset_err_count() to errors::Handler
The motivation here is to allow rustfmt to recover from parse errors
after failing to parse macros.
2017-08-23 21:56:09 +09:00
bors
757b7ac2ab Auto merge of #43986 - petrochenkov:pubcrate3, r=pnkfelix
rustc: Remove some dead code

Extracted from https://github.com/rust-lang/rust/pull/43192

r? @eddyb
2017-08-21 08:14:17 +00:00
bors
06bf94a129 Auto merge of #43929 - oli-obk:use_placement, r=nrc
Improve placement of `use` suggestions

r? @nrc

cc @estebank @Mark-Simulacrum

fixes #42835
fixes #42548
fixes #43769
2017-08-21 05:18:03 +00:00