Commit graph

539 commits

Author SHA1 Message Date
bors 95561b336c Auto merge of #94584 - pnkfelix:inject-use-suggestion-sites, r=ekuber
More robust fallback for `use` suggestion

Our old way to suggest where to add `use`s would first look for pre-existing `use`s in the relevant crate/module, and if there are *no* uses, it would fallback on trying to use another item as the basis for the suggestion.

But this was fragile, as illustrated in issue #87613

This PR instead identifies span of the first token after any inner attributes, and uses *that* as the fallback for the `use` suggestion.

Fix #87613
2022-03-15 03:56:33 +00:00
bors f103b2969b Auto merge of #94865 - notriddle:notriddle/single-colon-path-not-const-generics, r=cjgillot
diagnostics: single colon within `<>` probably, not type ascription

Fixes #94812
2022-03-12 19:10:33 +00:00
Michael Howell 26e299a4a7 Use consistent prose for ::
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2022-03-12 08:20:36 -07:00
Michael Howell 7e323370b3 diagnostics: single colon within <> probably, not type ascription
Fixes #94812
2022-03-11 15:35:18 -07:00
Dylan DPC 298c9a0e14
Rollup merge of #94839 - TaKO8Ki:suggest-using-double-colon-for-struct-field-type, r=cjgillot
Suggest using double colon when a struct field type include single colon

#92685
2022-03-11 20:29:47 +01:00
Takayuki Maeda 813f00dd4f fix a suggestion message 2022-03-11 21:26:06 +09:00
Takayuki Maeda bdc3177868 suggest using double colon when using single colon in struct field type path 2022-03-11 16:15:57 +09:00
Michael Howell fbd4cfa0f8 diagnostics: only talk about Cargo.toml if running under Cargo
Fixes #94646
2022-03-07 10:54:17 -07:00
bors ad0d1d71d3 Auto merge of #90076 - jackh726:wherethewhere, r=nikomatsakis
Change location of where clause on GATs

Closes #89122

~Blocked on lang FCP~

r? `@nikomatsakis`
2022-03-06 07:22:09 +00:00
Jack Huey c20b4f5584 Change syntax for TyAlias where clauses 2022-03-05 13:13:45 -05:00
Ralf Jung e887e6647c
Rollup merge of #94633 - TaKO8Ki:suggest-removing-semicolon-after-derive-attribute, r=cjgillot
Suggest removing a semicolon after derive attributes

closes #93942
2022-03-05 12:53:16 -05:00
Takayuki Maeda 47d91bc9e6 suggest removing a semicolon after derive attributes
use current token span
2022-03-06 01:28:35 +09:00
Esteban Kuber 004f2ed219 Do not recover from Ty? in macro parsing
Follow up to #92746. Address #94510.
2022-03-04 02:03:55 +00:00
Felix S. Klock II d37da1e332 Adjusted diagnostic output so that if there is no use in a item sequence,
then we just suggest the first legal position where you could inject a use.

To do this, I added `inject_use_span` field to `ModSpans`, and populate it in
parser (it is the span of the first token found after inner attributes, if any).
Then I rewrote the use-suggestion code to utilize it, and threw out some stuff
that is now unnecessary with this in place. (I think the result is easier to
understand.)

Then I added a test of issue 87613.
2022-03-03 18:58:37 -05:00
Felix S. Klock II b82795244e Associate multiple with a crate too. 2022-03-03 18:45:25 -05:00
Felix S. Klock II e9035f7bef refactor: prepare to associate multiple spans with a module. 2022-03-03 14:38:50 -05:00
mark e489a94dee rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
Matthias Krüger 5be38d2bb3
Rollup merge of #94445 - c410-f3r:more-let-chains, r=cjgillot
4 - Make more use of `let_chains`

Continuation of #94376.

cc #53667
2022-02-28 20:05:17 +01:00
Esteban Kuber f42b4f595e Tweak diagnostics
* Recover from invalid `'label: ` before block.
* Make suggestion to enclose statements in a block multipart.
* Point at `match`, `while`, `loop` and `unsafe` keywords when failing
  to parse their expression.
* Do not suggest `{ ; }`.
* Do not suggest `|` when very unlikely to be what was wanted (in `let`
  statements).
2022-02-28 18:22:45 +00:00
Caio e3e902bb06 4 - Make more use of let_chains
Continuation of #94376.

cc #53667
2022-02-28 07:49:56 -03:00
Michael Goulet 6b52ac240a Suggest {} around more bad const generic exprs 2022-02-25 17:16:58 -08:00
Matthias Krüger 731cd3fbeb
Rollup merge of #94344 - notriddle:notriddle/suggest-parens-more, r=oli-obk
diagnostic: suggest parens when users want logical ops, but get closures

Fixes #93536
2022-02-25 14:14:40 +01:00
Michael Howell fd35770e8d diagnostic: suggest parens when users want logical ops, but get closures 2022-02-24 17:02:38 -07:00
Eduard-Mihai Burtescu b7e95dee65 rustc_errors: let DiagnosticBuilder::emit return a "guarantee of emission". 2022-02-23 06:38:52 +00:00
Eduard-Mihai Burtescu 0b9d70cf6d rustc_errors: take self by value in DiagnosticBuilder::cancel. 2022-02-23 06:08:06 +00:00
Eduard-Mihai Burtescu 8562d6b752 rustc_errors: remove struct_dummy. 2022-02-23 05:38:24 +00:00
Eduard-Mihai Burtescu 02ff9e0aef Replace &mut DiagnosticBuilder, in signatures, with &mut Diagnostic. 2022-02-23 05:38:19 +00:00
est31 76ea566677 Better error if the user tries to do assignment ... else 2022-02-21 08:59:39 +01:00
Matthias Krüger f2d6770f77
Rollup merge of #94146 - est31:let_else, r=cjgillot
Adopt let else in more places

Continuation of #89933, #91018, #91481, #93046, #93590, #94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
2022-02-20 00:37:34 +01:00
est31 2ef8af6619 Adopt let else in more places 2022-02-19 17:27:43 +01:00
Matthias Krüger a144ea1c4b
Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk
compiler: clippy::complexity fixes

useless_format
map_flatten
useless_conversion
needless_bool
filter_next
clone_on_copy
needless_option_as_deref
2022-02-18 16:23:33 +01:00
Matthias Krüger 637d8b89e8
Rollup merge of #94011 - est31:let_else, r=lcnr
Even more let_else adoptions

Continuation of #89933, #91018, #91481, #93046, #93590.
2022-02-17 23:00:59 +01:00
est31 60f969a4f2 Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
Erin Petra Sofiya Moon e59cda9ee1
suggest using raw string literals when invalid escapes appear
i'd guess about 70% of "bad escape" cases occur when someone meant to
use a raw string literal because they're passing it directly to
Regex::new(). this emits an advisory (Applicability::MaybeIncorrect)
help: suggestion to the user that they use an r"" string,
on top of the normal notes about looking at the
string literal documentation/spec.
2022-02-14 15:11:38 -05:00
Matthias Krüger 602898a305
Rollup merge of #93595 - compiler-errors:ice-on-lifetime-arg, r=jackh726
fix ICE when parsing lifetime as function argument

I don't really like this, but we basically need to emit an error instead of just delaying an bug, because there are too many places in the AST that aren't covered by my previous PRs...

cc: https://github.com/rust-lang/rust/issues/93282#issuecomment-1028052945
2022-02-12 09:26:21 +01:00
Matthias Krüger b80057d08d compiler: clippy::complexity fixes
useless_format
map_flatten
useless_conversion
needless_bool
filter_next
clone_on_copy
needless_option_as_deref
2022-02-03 23:16:03 +01:00
Matthias Krüger de2abc29e9 clippy::perf fixes
single_char_pattern and to_string_in_format_args
2022-02-03 21:45:51 +01:00
Michael Goulet b79fc92db3 fix ICE when parsing lifetime as function argument 2022-02-02 10:33:13 -08:00
Michael Goulet f35d43cdf0 better suggestion for duplicated where 2022-02-02 00:29:45 -08:00
Eric Huss d7c0b4f706
Rollup merge of #93019 - 5225225:uppercase-suffix, r=wesleywiser
If an integer is entered with an upper-case base prefix (0Xbeef, 0O755, 0B1010), suggest to make it lowercase

The current error for this case isn't really great, it just complains about the whole thing past the `0` being an invalid suffix.
2022-01-31 20:12:55 -08:00
5225225 ec3b711a4b Write UI tests, tweak message 2022-01-31 17:34:10 +00:00
Matthias Krüger 2f4602a64c
Rollup merge of #93395 - camelid:reserved-sugg, r=davidtwco
Improve suggestion for escaping reserved keywords

r? `@davidtwco`
2022-01-31 07:00:40 +01:00
Noah Lev c8198a608e Improve suggestion for escaping reserved keywords 2022-01-27 14:53:39 -08:00
5225225 7f24778102 Suggest making base prefix lowercase if parsing fails 2022-01-27 21:31:28 +00:00
Tomasz Miąsko 6236882127 Introduce a limit to Levenshtein distance computation
Incorporate distance limit from `find_best_match_for_name` directly into
Levenshtein distance computation.

Use the string size difference as a lower bound on the distance and exit
early when it exceeds the specified limit.

After finding a candidate within a limit, lower the limit further to
restrict the search space.
2022-01-26 12:38:22 +01:00
Michael Goulet 37bed05986 delay the bug once again, generalize turbofish suggestion 2022-01-25 11:11:13 -08:00
Michael Goulet a090bb1dea Remove delayed bug when encountering label in bad turbofish 2022-01-25 10:47:10 -08:00
Caio cbb0fffe59 Fix let_chains and if_let_guard feature flags 2022-01-22 17:45:45 -03:00
Matthias Krüger f372476d2c
Rollup merge of #91150 - dtolnay:qpath, r=davidtwco
Let qpath contain NtTy: `<$:ty as $:ty>::…`

Example:

```rust
macro_rules! m {
    (<$type:ty as $trait:ty>::$name:ident) => {
        <$type as $trait>::$name
    };
}

fn main() {
    let _: m!(<str as ToOwned>::Owned);
}
```

Previous behavior:

```console
error: expected identifier, found `ToOwned`
 --> src/main.rs:3:19
  |
3 |         <$type as $trait>::$name
  |                   ^^^^^^ expected identifier
...
8 |     let _: m!(<str as ToOwned>::Owned);
  |            ---------------------------
  |            |
  |            this macro call doesn't expand to a type
  |            in this macro invocation
```

The <code>expected identifier, found \`ToOwned\`</code> error is particularly silly. I think it should be fine to accept this code as long as $trait is of the form `TyKind::Path(None, path)`; if it is any other kind of `NtTy`, we'll keep the same behavior as before.
2022-01-18 22:00:43 +01:00
kadmin 1c1ce2fbda Add term to ExistentialProjection
Also prevent ICE when adding a const in associated const equality.
2022-01-17 20:01:22 +00:00