about summary refs log tree commit diff
path: root/src/librustc_errors
AgeCommit message (Collapse)AuthorLines
2018-01-26Merge branch 'explain' of https://github.com/estebank/rust into rollupAlex Crichton-1/+23
2018-01-26Do not capture stderr in the compiler. Instead just panic silently for fatal ↵John Kåre Alsaker-1/+15
errors
2018-01-25Add description to field and methodEsteban Küber-0/+8
2018-01-23Avoid underflow in render_source_lineRyan Cumming-0/+4
While testing rust-lang/rust#47655 I was able to make the compiler panic when it's compiled with debug assertions: ```shell > rustc /dev/null --crate-type proc-macro error: internal compiler error: unexpected panic note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports note: rustc 1.25.0-dev running on x86_64-apple-darwin note: run with `RUST_BACKTRACE=1` for a backtrace thread 'rustc' panicked at 'attempt to subtract with overflow', librustc_errors/emitter.rs:287:49 ``` Without debug assertions the following warning is emitted: ```shell > rustc /dev/null --crate-type proc-macro warning: unused variable: `registrar` --> /dev/null:0:1 | | = note: #[warn(unused_variables)] on by default = note: to avoid this warning, consider using `_registrar` instead ``` The panic is due to the unused variable warning being spanned to `/dev/null:0:1`. When `render_source_line` subtracts 1 from the line number to look up the source line it panics due to underflow. Without debug assertions this would wrap and cause us to return a blank string instead. Fix by explicitly testing for 0 and exiting early. I'm unsure how to automatically test this now that rust-lang/rust#46655 has been approved.
2018-01-22Only emit expanded diagnostic information onceEsteban Küber-1/+15
2018-01-18Rollup merge of #47407 - gaurikholkar:master, r=estebankkennytm-2/+2
fix mispositioned span This fixes #47377 The output now looks like this ``` error[E0369]: binary operation `+` cannot be applied to type `&str` --> h.rs:3:11 | 3 | let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | 3 | let _a = b.to_owned() + ", World!"; | ^^^^^^^^^ error: aborting due to previous error ``` For the case when emojis are involved, it gives the new output for proper indentation. But for an indentation as follows, ``` fn main() { let b = "hello"; let _a = b + ", World!"; } ``` it still mispositions the span ``` 3 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings | 3 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!"; | ^^^^^^^ error: aborting due to previous erro ``` cc @estebank @est31
2018-01-14Auto merge of #47274 - Manishearth:rustdoc-span, r=QuietMisdreavusbors-2/+3
Use correct line offsets for doctests Not yet tested. This doesn't handle char positions. It could if I collected a map of char offsets and lines, but this is a bit more work and requires hooking into the parser much more (unsure if it's possible). r? @QuietMisdreavus (fixes #45868)
2018-01-13add ui testGauri-1/+1
2018-01-13fix mispositioned spanGauri-1/+1
2018-01-10Use correct line offsets for doctests (fixes #45868)Manish Goregaokar-2/+3
2018-01-08Clean emitted diagnostics when `reset_err_count` is called.Rafael Fernández López-2/+6
When external tools like `rustfmt` calls to `reset_err_count` for handler reusing, it will set the error count on the handler to 0, but since https://github.com/rust-lang/rust/pull/47146 the handler will contain status that will prevent the error count to be bumped if this handler is reused. This caused `rustfmt` idempotency tests to fail: https://github.com/rust-lang-nursery/rustfmt/issues/2338 Fixes: https://github.com/rust-lang-nursery/rustfmt/issues/2338
2018-01-03Only bump error count when we are sure that the diagnostic is not a repetition.Rafael Fernández López-15/+9
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
2017-12-21Make err_count thread safeJohn Kåre Alsaker-8/+10
2017-12-14When attempting to write str with single quote suggest double quotesEsteban Küber-1/+7
2017-12-14Use PathBuf instead of String where applicableOliver Schneider-5/+11
2017-12-14Auto merge of #46605 - estebank:macro-backtrace-spans, r=pnkfelixbors-53/+49
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-09Resolve type on return type suggestionEsteban Küber-1/+1
2017-12-09Use spans for -Z external-macro-backtraceEsteban Küber-53/+49
``` % 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-06Auto merge of #45953 - estebank:tab-4, r=nikomatsakisbors-3/+14
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-01Auto merge of #45997 - estebank:pub-ident, r=nikomatsakisbors-1/+1
Account for missing keyword in fn/struct definition Fix #38911.
2017-11-26mention nightly in -Z external-macro-backtrace noteAlex Burka-1/+2
2017-11-24Display `\t` in diagnostics code as four spacesEsteban Küber-3/+14
2017-11-24Fix underline in suggestionsEsteban Küber-1/+1
2017-11-22Rollup merge of #46052 - oli-obk:rendered_diagnostics_in_json, r=petrochenkovkennytm-1/+1
Include rendered diagnostic in json r? @petrochenkov
2017-11-20address review commentsAlex Burka-26/+52
2017-11-20The end of a span can be *before* the first char in a lineOliver Schneider-1/+1
2017-11-19use -Z flag instead of env varAlex Burka-23/+36
2017-11-19add UI testAlex Burka-3/+6
2017-11-19show macro backtrace with env varAlex Burka-13/+47
2017-11-16Remove left over dead code from suggestion diagnostic refactoringOliver Schneider-60/+26
2017-11-09Auto merge of #45741 - oli-obk:refactor_suggestions, r=estebankbors-118/+108
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-06Do not highlight surrounding whitespaceOliver Schneider-6/+7
2017-11-04Auto merge of #45711 - tirr-c:unicode-span, r=estebankbors-7/+7
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-03Refactor internal suggestion APIOliver Schneider-122/+111
2017-11-03Display spans correctly when there are non-half-width charactersWonwoo Choi-7/+7
2017-11-02Make the difference between lint codes and error codes explicitOliver Schneider-30/+38
2017-11-02Report lint names in json diagnosticsOliver Schneider-1/+2
2017-10-26Auto merge of #45519 - michaelwoerister:dedup-errors, r=arielb1bors-9/+35
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-25Auto merge of #44636 - GuillaumeGomez:little-error-msg, r=michaelwoeristerbors-131/+165
Add short error message-format Fixes #42653.
2017-10-25librustc_errors: Don't emit the same error message twice.Michael Woerister-9/+35
2017-10-24Update docs for Diagnostic::span_suggestion(s)Oliver Schneider-0/+2
2017-10-20Add short message-formatGuillaume Gomez-131/+165
2017-09-29fix comment typo, `CodeSuggestion` path in doc commentZack M. Davis-3/+3
`CodeSuggestion` doesn't live in the `diagnostic` module.
2017-09-07Fix mispositioned error indicatorsest31-10/+7
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-08-30Rollup merge of #44125 - SergioBenitez:master, r=nrcAlex Crichton-1/+14
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-30Auto merge of #43968 - petrochenkov:span2, r=michaelwoeristerbors-17/+13
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-30Make fields of `Span` privateVadim Petrochenkov-17/+13
2017-08-29Rollup merge of #43778 - topecongiro:handler-reset-err-count, r=arielb1Ariel Ben-Yehuda-0/+6
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-28Initial diagnostic API for proc-macros.Sergio Benitez-1/+14
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-27Additional libc cleanupTatsuyuki Ishi-1/+2