Commit Graph

797 Commits

Author SHA1 Message Date
Matthias Krüger
d5dca26a94
Rollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkov
Clean up `LitKind`

r? ``@petrochenkov``
2022-08-17 12:32:49 +02:00
Nicholas Nethercote
5d3cc1713a Rename some things related to literals.
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is
  `token::Lit`, which is not a token. (This has been confusing me for a
  long time.)
  reasonable because we have an `ast::token::Lit` inside an `ast::Lit`.
- Rename `LitKind::{from,to}_lit_token` as
  `LitKind::{from,to}_token_lit`, to match the above change and
  `token::Lit`.
2022-08-16 13:41:34 +10:00
Nicholas Nethercote
9619a2e3a3 Avoid unnecessary cloning in Parser::get_ident_from_generic_arg. 2022-08-16 12:14:52 +10:00
Nicholas Nethercote
3e04fed6fa Remove {ast,hir}::WhereEqPredicate::id.
These fields are unused.
2022-08-16 12:13:23 +10:00
Matthias Krüger
e14d12cb66
Rollup merge of #100559 - nnethercote:parser-simplifications, r=compiler-errors
Parser simplifications

Best reviewed one commit at a time.

r? ``@compiler-errors``
2022-08-15 20:11:38 +02:00
Matthias Krüger
e369ec871e
Rollup merge of #100458 - compiler-errors:fn-argument-span, r=estebank
Adjust span of fn argument declaration

Span of a fn argument declaration goes from:

```
fn foo(i : i32 , ...)
       ^^^^^^^^
```

to:

```
fn foo(i : i32 , ...)
       ^^^^^^^
```

That is, we don't include the extra spacing up to the trailing comma, which I think is more correct.

cc https://github.com/rust-lang/rust/pull/99646#discussion_r944568074
r? ``@estebank``

---

The two tests that had dramatic changes in their rendering I think actually are improved, though they are kinda poor spans both before and after the changes. 🤷 Thoughts?
2022-08-15 20:11:35 +02:00
Matthias Krüger
fece51174b
Rollup merge of #100566 - TaKO8Ki:use-create-snapshot-for-diagnostic, r=cjgillot
Use `create_snapshot_for_diagnostic` instead of `clone` for `Parser`

follow-up to #98020
2022-08-15 10:28:14 +02:00
Matthias Krüger
748925bf1b
Rollup merge of #100534 - Rageking8:Rageking8-refactor1, r=compiler-errors
Make code slightly more uniform
2022-08-15 10:28:13 +02:00
Takayuki Maeda
84f0d5e460 use create_snapshot_for_diagnostic instead of clone for Parser 2022-08-15 16:42:58 +09:00
Nicholas Nethercote
2ef0479568 Simplify attribute handling in parse_bottom_expr.
`Parser::parse_bottom_expr` currently constructs an empty `attrs` and
then passes it to a large number of other functions. This makes the code
harder to read than it should be, because it's not clear that many
`attrs` arguments are always empty.

This commit removes `attrs` and the passing, simplifying a lot of
functions. The commit also renames `Parser::mk_expr` (which takes an
`attrs` argument) as `mk_expr_with_attrs`, and introduces a new
`mk_expr` which creates an expression with no attributes, which is the
more common case.
2022-08-15 13:29:28 +10:00
Nicholas Nethercote
1e8497351d Streamline parse_path_start_expr.
Let-chaining avoids some code duplication.
2022-08-15 09:51:11 +10:00
Matthias Krüger
13b8b6ede0
Rollup merge of #100253 - obeis:issue-100197, r=cjgillot
Recover from mutable variable declaration where `mut` is placed before `let`

Closes #100197
2022-08-14 20:16:00 +02:00
Rageking8
44f878d75f
Make code slightly more uniform 2022-08-14 22:17:49 +08:00
Dylan DPC
7473484d52
Rollup merge of #100115 - obeis:issue-99910, r=cjgillot
Suggest removing `let` if `const let` or `let const` is used

Closes #99910
2022-08-14 17:09:15 +05:30
Michael Goulet
86e1d1e28f
Rollup merge of #100446 - TaKO8Ki:suggest-removing-semicolon-after-impl-trait-items, r=compiler-errors
Suggest removing a semicolon after impl/trait items

fixes #99822
2022-08-13 21:06:51 -07:00
Michael Goulet
2af344595a
Rollup merge of #99646 - compiler-errors:arg-mismatch-single-arg-label, r=estebank
Only point out a single function parameter if we have a single arg incompatibility

Fixes #99635
2022-08-13 21:06:46 -07:00
Michael Goulet
29f905bfaf
Rollup merge of #100475 - chenyukang:fix-100461, r=fee1-dead
Give a helpful diagnostic when the next struct field has an attribute

Fixes #100461
2022-08-13 14:10:12 -07:00
Takayuki Maeda
d47df26784 use span_suggestion instead of span_suggestion_verbose 2022-08-13 22:10:54 +09:00
yukang
52a15180d2 give a helpful diagnostic even when the next struct field has an attribute 2022-08-13 12:50:53 +08:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Michael Goulet
9b0edd099d Adjust span of fn arguments 2022-08-12 15:21:39 +00:00
Michael Goulet
237cbe91a8 Adjust span of closure param 2022-08-12 15:18:40 +00:00
Dylan DPC
9914c96f06
Rollup merge of #100396 - chenyukang:fix-100394, r=petrochenkov
Suggest const and static for global variable

Fixing #100394
2022-08-12 20:39:16 +05:30
Takayuki Maeda
48c0341a70 suggest removing a semicolon after impl/trait items 2022-08-12 18:11:01 +09:00
Matthias Krüger
6ae0414122
Rollup merge of #100350 - jhpratt:stringify-vis, r=cjgillot
Stringify non-shorthand visibility correctly

This makes `stringify!(pub(in crate))` evaluate to `pub(in crate)` rather than `pub(crate)`, matching the behavior before the `crate` shorthand was removed. Further, this changes `stringify!(pub(in super))` to evaluate to `pub(in super)` rather than the current `pub(super)`. If the latter is not desired (it is _technically_ breaking), it can be undone.

Fixes #99981

`@rustbot` label +C-bug +regression-from-stable-to-beta +T-compiler
2022-08-11 22:53:06 +02:00
Dylan DPC
b5f5bdce87
Rollup merge of #100351 - compiler-errors:diagnostic-convention, r=fee1-dead
Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder` unless needed

This seems to be the established convention (02ff9e0) when `DiagnosticBuilder` was first added. I am guilty of introducing some of these.
2022-08-11 22:47:03 +05:30
chenyukang
98518c2379 suggest const or static for global variable 2022-08-11 23:15:39 +08:00
Camille GILLOT
9701845287 Do not consider method call receiver as an argument in AST. 2022-08-10 18:34:54 +02:00
Michael Goulet
a2b6744af0 Use &mut Diagnostic instead of &mut DiagnosticBuilder unless needed 2022-08-10 03:45:42 +00:00
Jacob Pratt
be5672ecb2
Stringify non-shorthand visibility correctly 2022-08-09 23:31:45 -04:00
Takayuki Maeda
6d85bb9535 suggest a missing semicolon before an array 2022-08-10 02:29:28 +09:00
Obei Sideg
ea2df3a798 Recover from mutable variable declaration where mut is placed before let 2022-08-09 00:55:37 +03:00
Matthias Krüger
18ddb41184
Rollup merge of #100167 - chenyukang:require-suggestion, r=estebank
Recover `require`, `include` instead of `use` in item

Fix #100140
2022-08-06 16:15:59 +02:00
Dylan DPC
e7ed8443ea
Rollup merge of #100168 - WaffleLapkin:improve_diagnostics_for_missing_type_in_a_const_item, r=compiler-errors
Improve diagnostics for `const a: = expr;`

Adds a suggestion to write a type when there is a colon, but the type is not present.
I've also shrunk spans a little, so the suggestions are a little nicer.

Resolves #100146

r? `@compiler-errors`
2022-08-05 21:54:37 +05:30
Maybe Waffle
743ad07c4b Improve diagnostics for const a: = expr; 2022-08-05 16:19:28 +04:00
yukang
2b15fc6d9a recover require,include instead of use in item 2022-08-05 19:20:03 +08:00
Matthias Krüger
f6ea143f93
Rollup merge of #98796 - compiler-errors:no-semi-if-comma, r=estebank
Do not exclusively suggest `;` when `,` is also a choice

Fixes #96791
2022-08-04 22:24:59 +02:00
Obei Sideg
accb8e34c5 Suggest removing let if let const is used 2022-08-04 01:23:14 +03:00
Matthias Krüger
9c18fdc71f
Rollup merge of #99786 - obeis:issue-99625, r=compiler-errors
Recover from C++ style `enum struct`

Closes #99625
2022-08-03 22:29:29 +02:00
Obei Sideg
2af92bbf2e Suggest removing let if const let is used 2022-08-03 18:43:29 +03:00
Matthias Krüger
beb4cdddde
Rollup merge of #100011 - compiler-errors:let-chain-restriction, r=fee1-dead
Use Parser's `restrictions` instead of `let_expr_allowed`

This also means that the `ALLOW_LET` flag is reset properly for subexpressions, so we can properly deny things like `a && (b && let c = d)`. Also the parser is a tiny bit smaller now.

It doesn't reject _all_ bad `let` expr usages, just a bit more.

cc `@c410-f3r`
2022-08-02 07:30:44 +02:00
Michael Goulet
6be7a87f9c Use expr parse restrictions for let expr parsing 2022-08-01 01:13:16 +00:00
Nicholas Nethercote
99f5c79d64 Shrink Token.
From 72 bytes to 12 bytes (on x86-64).

There are two parts to this:
- Changing various source code offsets from 64-bit to 32-bit. This is
  not a problem because the rest of rustc also uses 32-bit source code
  offsets. This means `Token` is no longer `Copy` but this causes no
  problems.
- Removing the `RawStrError` from `LiteralKind`. Raw string literal
  invalidity is now indicated by a `None` value within
  `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be
  used to re-lex an invalid raw string literal to get the `RawStrError`.

There is one very small change in behaviour. Previously, if a raw string
literal matched both the `InvalidStarter` and `TooManyHashes` cases,
the latter would override the former. This has now changed, because
`raw_double_quoted_string` now uses `?` and so returns immediately upon
detecting the `InvalidStarter` case. I think this is a slight
improvement to report the earlier-detected error, and it explains the
change in the `test_too_many_hashes` test.

The commit also removes a couple of comments that refer to #77629 and
say that the size of these types don't affect performance. These
comments are wrong, though the performance effect is small.
2022-08-01 08:53:04 +10:00
Nicholas Nethercote
e6b9fccfb1 Add a size assertion for Token. 2022-08-01 08:27:43 +10:00
Nicholas Nethercote
ddf62b5bd4 Inline TokenStreamBuilder::push.
Because it's small and hot.
2022-08-01 08:27:41 +10:00
Nicholas Nethercote
c01a36d5e4 Avoid an unnecessary return. 2022-08-01 08:25:56 +10:00
Nicholas Nethercote
bd23d68b41 Remove StringReader::end_src_index.
It not needed, always being set to the end of the text.
2022-08-01 08:11:15 +10:00
Nicholas Nethercote
55185992d6 Improve shebang handling.
Avoid doing stuff until it's necessary.
2022-08-01 08:11:15 +10:00
bors
038f9e6bef Auto merge of #99948 - Dylan-DPC:rollup-ed5136t, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #99311 (change maybe_body_owned_by to take local def id)
 - #99862 (Improve type mismatch w/ function signatures)
 - #99895 (don't call type ascription "cast")
 - #99900 (remove some manual hash stable impls)
 - #99903 (Add diagnostic when using public instead of pub)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-30 17:30:50 +00:00
Dylan DPC
df2cf97830
Rollup merge of #99903 - gimbles:pub, r=davidtwco
Add diagnostic when using public instead of pub

Forwarding from https://github.com/rust-lang/rust/pull/99706

I accidentally broke something(??) in git and the commits in that PR are absolutely not what I did in that branch

Anyways, this is the PR for this now. Adding tests again in a minute.

cc `@davidtwco`
2022-07-30 20:39:50 +05:30