Commit Graph

54 Commits

Author SHA1 Message Date
Aman Arora
c923da0b49 pretty.rs: Update Closure and Generator print
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
Co-authored-by: Logan Mosier <logmosier@gmail.com>
2020-09-28 01:27:19 -04:00
Dan Aloni
07e7823c01 pretty: trim paths of unique symbols
If a symbol name can only be imported from one place for a type, and
as long as it was not glob-imported anywhere in the current crate, we
can trim its printed path and print only the name.

This has wide implications on error messages with types, for example,
shortening `std::vec::Vec` to just `Vec`, as long as there is no other
`Vec` importable anywhere.

This adds a new '-Z trim-diagnostic-paths=false' option to control this
feature.

On the good path, with no diagnosis printed, we should try to avoid
issuing this query, so we need to prevent trimmed_def_paths query on
several cases.

This change also relies on a previous commit that differentiates
between `Debug` and `Display` on various rustc types, where the latter
is trimmed and presented to the user and the former is not.
2020-09-02 22:26:37 +03:00
Aaron Hill
e3cd43eb00
Use smaller def span for functions
Currently, the def span of a funtion encompasses the entire function
signature and body. However, this is usually unnecessarily verbose - when we are
pointing at an entire function in a diagnostic, we almost always want to
point at the signature. The actual contents of the body tends to be
irrelevant to the diagnostic we are emitting, and just takes up
additional screen space.

This commit changes the `def_span` of all function items (freestanding
functions, `impl`-block methods, and `trait`-block methods) to be the
span of the signature. For example, the function

```rust
pub fn foo<T>(val: T) -> T { val }
```

now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T`
(everything before the opening curly brace).

Trait methods without a body have a `def_span` which includes the
trailing semicolon. For example:

```rust
trait Foo {
    fn bar();
}```

the function definition `Foo::bar` has a `def_span` of `fn bar();`

This makes our diagnostic output much shorter, and emphasizes
information that is relevant to whatever diagnostic we are reporting.

We continue to use the full span (including the body) in a few of
places:

* MIR building uses the full span when building source scopes.
* 'Outlives suggestions' use the full span to sort the diagnostics being
  emitted.
* The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]`
attribute points the entire scope body.
* The 'unconditional recursion' lint uses the full span to show
  additional context for the recursive call.

All of these cases work only with local items, so we don't need to
add anything extra to crate metadata.
2020-08-22 18:41:49 -04:00
Yuki Okushi
ec31b4e3a8
Audit uses of span_suggestion_short 2020-07-02 15:18:33 +09:00
flip1995
898cbf265a
update_tests 2020-04-24 00:22:50 +02:00
RoccoDev
b85c64c3ea
rustc: Add a warning count upon completion 2020-04-11 16:15:24 +02:00
Mark Mansi
b6518f0f66 update tests 2020-03-12 15:47:36 -05:00
Esteban Küber
2c5766f2d4 Unify output of "variant not found" errors 2020-01-08 08:05:31 -08:00
Mazdak Farrokhzad
ab050d6a83 MatchExpressionArmPattern: Use more generic wording.
The existing wording was inappropriate for e.g.
`if let Ok(_) = expr { .. }`. The diagnostic would
leak the fact that we desugar to a `match`.
2019-12-30 13:50:20 +01:00
Esteban Küber
6f8f70624b Surround types with backticks in type errors 2019-11-18 11:03:04 -08:00
Esteban Küber
94c6425464 Remove E0308 note when primary label has all info 2019-11-18 11:03:03 -08:00
Esteban Küber
b2e6aef073 review comments: tweak prefix strings 2019-11-18 11:02:44 -08:00
Esteban Küber
83ffda5216 Specific labels when referring to "expected" and "found" types 2019-11-18 11:02:22 -08:00
Esteban Küber
bc1a4f52e3 review comments: typo and rewording 2019-08-09 07:18:05 -07:00
Esteban Küber
33d1082d6e review comment: review wording or missing return error 2019-08-09 07:18:05 -07:00
Esteban Küber
efa62d66e3 Tweak wording of fn without explicit return 2019-08-09 07:18:05 -07:00
Esteban Küber
01a61394f8 Change wording for function without return value
Fix #62677
2019-08-09 07:18:05 -07:00
Samy Kacimi
e5e1397adb
normalize use of backticks in compiler messages for librustc/lint
https://github.com/rust-lang/rust/issues/60532
2019-07-17 22:49:48 +02:00
Mazdak Farrokhzad
547735457f Make WhileTrue into an EarlyLintPass lint. 2019-07-06 06:43:58 +02:00
Andy Russell
b6f148c8bd
hide --explain hint if error has no extended info 2019-04-18 13:29:28 -04:00
Andy Russell
757ef38431
improve unknown enum variant errors 2019-04-09 14:19:20 -04:00
Vadim Petrochenkov
fa72a81bea Update tests 2019-03-11 23:10:26 +03:00
Esteban Küber
edbbfad88f Suggest removal of & when borrowing macro and appropriate
Fix #58815.
2019-03-02 11:25:00 -08:00
Esteban Küber
45a95b512c Use structured suggestion in stead of notes 2019-01-20 21:41:25 -08:00
Esteban Küber
72d965f7b7 Reword label as per review comment 2019-01-12 19:36:28 -08:00
Esteban Küber
a873337f21 Point at the match discriminant when arm pattern has a type mismatch 2019-01-12 19:36:28 -08:00
Esteban Küber
5d086c3282 Tweak E0308 error for clarity 2018-12-30 21:59:27 -08:00
Esteban Küber
f62f540b4e Point at function name span 2018-12-30 15:41:19 -08:00
Esteban Küber
1f65dc0770 Point at the return type span on type mismatch due to missing return
Do not point at the entire block span on fn return type mismatches
caused by missing return.
2018-12-30 13:55:00 -08:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Andy Russell
6474de904c
make non_camel_case_types an early lint 2018-12-24 12:58:52 -05:00
Zack M. Davis
f3e9b1a703 in which the E0618 "expected function" diagnostic gets a makeover
Now the main span focuses on the erroneous not-a-function callee,
while showing the entire call expression is relegated to a secondary
span. In the case where the erroneous callee is itself a call, we
point out the definition, and, if the call expression spans multiple
lines, tentatively suggest a semicolon (because we suspect that the
"outer" call is actually supposed to be a tuple).

The new `bug!` assertion is, in fact, safe (`confirm_builtin_call` is
only called by `check_call`, which is only called with a first arg of
kind `ExprKind::Call` in `check_expr_kind`).

Resolves #51055.
2018-11-10 22:12:33 -08:00
Matthias Krüger
4972beaf65 fix typos in various places 2018-10-23 15:56:25 +02:00
Guillaume Gomez
2e104a77cf update tests 2018-03-14 00:53:24 +01:00
Vadim Petrochenkov
7ba5fd168a Update UI tests 2018-02-26 20:24:42 +03:00
Vadim Petrochenkov
fa2d9fc4b9 Update UI tests 2018-02-26 20:24:02 +03:00
Guillaume Gomez
5747fd6611 Update ui tests 2018-02-25 12:15:05 +01:00
Esteban Küber
4a7691692c Further tweaks to the output
- Properly address Variant Ctors
- Show signature if span of trait method without `self` is not available
2018-01-15 12:35:15 -08:00
Vadim Petrochenkov
1f5b201aff Remove NOTE/HELP annotations from UI tests 2017-12-14 23:26:39 +03:00
Oliver Schneider
8937d6a6cf
Merge cfail and ui tests into ui tests 2017-11-24 11:32:35 +01:00
Niko Matsakis
d0bda669ea move the signature into the closure type 2017-11-18 07:47:37 -05:00
Thomas Jespersen
09defbcb5b Add suggestions for misspelled method names
Use the syntax::util::lev_distance module to provide suggestions when a
named method cannot be found.

Part of #30197
2017-09-21 12:05:56 +02:00
Esteban Küber
9bd62a4691 Readd backticks around () 2017-08-09 10:48:33 -07:00
Esteban Küber
3fcdb8ba72 Only refer to return type when it matches 2017-08-08 22:59:55 -07:00
Esteban Küber
d96f9d47ac Point at return type always when type mismatch against it
Before this, the diagnostic errors would only point at the return type
when changing it would be a possible solution to a type error. Add a
label to the return type without a suggestion to change in order to make
the source of the expected type obvious.

Follow up to #42850, fixes #25133, fixes #41897.
2017-07-25 22:11:15 -07:00
Oliver Schneider
401ab612c2 Adjust new suggestions to the suggestion guidelines 2017-07-21 13:59:17 +02: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
Ariel Ben-Yehuda
fb7ab9e43d report the total number of errors on compilation failure
Prior to this PR, when we aborted because a "critical pass" failed, we
displayed the number of errors from that critical pass. While that's the
number of errors that caused compilation to abort in *that place*,
that's not what people really want to know. Instead, always report the
total number of errors, and don't bother to track the number of errors
from the last pass that failed.

This changes the compiler driver API to handle errors more smoothly,
and therefore is a compiler-api-[breaking-change].

Fixes #42793.
2017-07-02 16:16:44 +03:00
Esteban Küber
7dad2958be Review comments
- Fix typo
- Add docstring
- Remove spurious test output file
2017-06-27 13:34:56 -07:00
Esteban Küber
c13a913e5b Don't naively point to return type on type error 2017-06-24 19:28:43 -07:00