Commit Graph

692 Commits

Author SHA1 Message Date
Matthias Krüger a8f7acd8f8
Rollup merge of #117114 - nnethercote:improve-stringify-test, r=petrochenkov
Improve `stringify.rs` test

Best reviewed one commit at a time.

r? `@petrochenkov`
2023-10-26 22:26:11 +02:00
Nicholas Nethercote 2e2e7806ab Augment `stringify.rs` test.
By adding tests (or placeholders, or comments) for missing AST variants.
2023-10-24 16:00:45 +11:00
bohan 482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Michael Goulet e8e9f6a32a Uplift movability and mutability, the simple way 2023-10-19 16:42:58 +00:00
bors a48396984a Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates

Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped).

This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else.

I will also add this commit to the ignore list after it has landed.

The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree.
```
~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates
~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif
```

cc `@rust-lang/rustfmt`
r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :>

cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-15 13:23:55 +00:00
Matthias Krüger 6fef4f089f
Rollup merge of #116696 - c410-f3r:in-doc, r=petrochenkov
Misc improvements

cc https://github.com/rust-lang/rust/pull/116323#discussion_r1355282195

r? `@petrochenkov`
2023-10-14 13:36:28 +02:00
Caio 6b59f6fbea Misc improvements 2023-10-13 10:22:33 -03:00
Michael Goulet b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Nicholas Nethercote 33aff5b152 Use `TokenStream::token_alone` in one place. 2023-10-12 08:46:16 +11:00
Nicholas Nethercote becf4942a2 Rename `Token::is_op` as `Token::is_punct`.
For consistency with `proc_macro::Punct`.
2023-10-12 08:46:15 +11:00
Michael Howell c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Jubilee ea3454eabb
Rollup merge of #116223 - catandcoder:master, r=cjgillot
Fix misuses of a vs an

Fixes the misuse of "a" vs "an", according to English grammatical
expectations and using https://www.a-or-an.com/
2023-10-05 00:56:29 -07:00
cui fliter f44d116e1f Fix misuses of a vs an
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-04 08:01:11 +08:00
Nicholas Nethercote 7326cd98b9 Factor out the two `entry_point_type` functions.
They are very similar, and each one has a comment about the importance
of being kept in sync with the other. This commit removes the
duplication.
2023-10-01 20:45:09 +11:00
bors 327e6cf55c Auto merge of #114452 - weiznich:feature/diagnostic_on_unimplemented, r=compiler-errors
`#[diagnostic::on_unimplemented]` without filters

This commit adds support for a `#[diagnostic::on_unimplemented]` attribute with the following options:

* `message` to customize the primary error message
* `note` to add a customized note message to an error message
* `label` to customize the label part of the error message

The relevant behavior is specified in [RFC-3366](https://rust-lang.github.io/rfcs/3366-diagnostic-attribute-namespace.html)
2023-09-17 10:00:15 +00:00
Georg Semmler 5b8a7a0917
`#[diagnostic::on_unimplemented]` without filters
This commit adds support for a `#[diagnostic::on_unimplemented]`
attribute with the following options:

* `message` to customize the primary error message
* `note` to add a customized note message to an error message
* `label` to customize the label part of the error message

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
Co-authored-by: Michael Goulet <michael@errs.io>
2023-09-12 20:03:18 +02:00
Matthew Jasper 333388fd3c Move let expression checking to parsing
There was an incomplete version of the check in parsing and a second
version in AST validation. This meant that some, but not all, invalid
uses were allowed inside macros/disabled cfgs. It also means that later
passes have a hard time knowing when the let expression is in a valid
location, sometimes causing ICEs.

- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a
  valid location.
- Suppress later errors and MIR construction for invalid let
  expressions.
2023-09-11 15:51:18 +00:00
mojave2 f404990eb0
improve `AttrTokenStream` 2023-09-04 20:07:28 +08:00
bors 18be2728bd Auto merge of #115131 - frank-king:feature/unnamed-fields-lite, r=petrochenkov
Parse unnamed fields and anonymous structs or unions (no-recovery)

It is part of #114782 which implements #49804. Only parse anonymous structs or unions in struct field definition positions.

r? `@petrochenkov`
2023-08-24 12:52:35 +00:00
Frank King 868706d9b5 Parse unnamed fields and anonymous structs or unions
Anonymous structs or unions are only allowed in struct field
definitions.

Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-08-24 11:17:54 +08:00
John Kåre Alsaker 1e87ef66f4 Fix a stack overflow with long else if chains 2023-08-19 13:11:16 +02:00
bors f88a8b71ce Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk
correctly lower `impl const` to bind to host effect param

r? `@oli-obk`
2023-08-08 19:23:41 +00:00
David Tolnay 704aa56ba0
Generate better function argument names in global_allocator expansion 2023-08-06 07:36:05 -07:00
Deadbeef 92f4c59e48 lower impl const to bind to host effect param 2023-08-06 13:34:53 +00:00
Nilstrieb 5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
bors fb31b3c34e Auto merge of #114353 - nnethercote:parser-ast-cleanups, r=petrochenkov
Some parser and AST cleanups

Things I found while looking closely at this code.

r? `@petrochenkov`
2023-08-03 04:26:42 +00:00
Nicholas Nethercote d75ee2a6bc Remove `MacDelimiter`.
It's the same as `Delimiter`, minus the `Invisible` variant. I'm
generally in favour of using types to make impossible states
unrepresentable, but this one feels very low-value, and the conversions
between the two types are annoying and confusing.

Look at the change in `src/tools/rustfmt/src/expr.rs` for an example:
the old code converted from `MacDelimiter` to `Delimiter` and back
again, for no good reason. This suggests the author was confused about
the types.
2023-08-03 09:03:30 +10:00
Nilstrieb 0475873813
Rollup merge of #114321 - SparrowLii:parallel_test, r=oli-obk
get auto traits for parallel rustc

test for #106930
#[Edit] Since this doesn't block try build now, we can close https://github.com/rust-lang/rust/issues/106930

fixes #106930
2023-08-02 13:46:55 +02:00
SparrowLii 90db1132c7 get auto traits for parallel rustc
Signed-off-by: SparrowLii <liyuan179@huawei.com>
2023-08-02 16:21:45 +08:00
Nicholas Nethercote ba294a816b Fix an erroneous comment.
The `None` variant has already been renamed `Invisible`.
2023-08-02 10:32:35 +10:00
Nicholas Nethercote d72fc5ce44 Remove `TokenTreeCursor::replace_prev_and_rewind`.
It's no longer used.
2023-07-31 14:47:06 +10:00
Nicholas Nethercote ff7d5ba65e Move doc comment desugaring out of `TokenCursor`.
`TokenCursor` currently does doc comment desugaring on the fly, if the
`desugar_doc_comment` field is set. This requires also modifying the
token stream on the fly with `replace_prev_and_rewind`.

This commit moves the doc comment desugaring out of `TokenCursor`, by
introducing a new `TokenStream::desugar_doc_comment` method. This
separation of desugaring and iterating makes the code nicer.
2023-07-31 14:47:03 +10:00
León Orell Valerian Liehr afd009a8d8
Parse generic const items 2023-07-28 22:21:33 +02:00
bors b95fd857fe Auto merge of #114119 - nnethercote:opt-TokenKind-clone, r=petrochenkov
Optimize `TokenKind::clone`.

`TokenKind` would impl `Copy` if it weren't for
`TokenKind::Interpolated`. This commit makes `clone` reflect that.

r? `@ghost`
2023-07-28 12:30:27 +00:00
bors 0699d99516 Auto merge of #114115 - nnethercote:less-token-tree-cloning, r=petrochenkov
Less `TokenTree` cloning

`TokenTreeCursor` has this comment on it:
```
// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
```
This PR completes that FIXME. It doesn't have much perf effect, but at least we now know that.

r? `@petrochenkov`
2023-07-28 01:21:27 +00:00
Nicholas Nethercote ac747a8481 Optimize `TokenKind::clone`.
`TokenKind` would impl `Copy` if it weren't for
`TokenKind::Interpolated`. This commit makes `clone` reflect that.
2023-07-27 15:05:23 +10:00
Nicholas Nethercote 4ebf2be8bb Remove `Iterator` impl for `TokenTreeCursor`.
This is surprising, but the new comment explains why. It's a logical
conclusion in the drive to avoid `TokenTree` clones.

`TokenTreeCursor` is now only used within `Parser`. It's still needed
due to `replace_prev_and_rewind`.
2023-07-27 11:59:03 +10:00
Nicholas Nethercote 55a732461d Make `TokenTree::uninterpolate` take `&self` and return a `Cow`.
Making it similar to `Token::uninterpolate`. This avoids some more token
tree cloning.
2023-07-27 11:58:42 +10:00
Nicholas Nethercote 103bd4a820 Use `TokenStream::trees` instead of `into_trees` for attributes.
This avoids cloning some token trees. A couple of `clone` calls were
inserted, but only on some paths, and the next commit will remove them.
2023-07-27 11:58:42 +10:00
Matthias Krüger af2b370100 more clippy::style fixes:
get_first
single_char_add_str
unnecessary_mut_passed
manual_map
manual_is_ascii_check
2023-07-23 23:39:04 +02:00
Matthias Krüger 0ed5f091a6
Rollup merge of #112508 - compiler-errors:trait-sig-lifetime-sugg-ice, r=cjgillot
Tweak spans for self arg, fix borrow suggestion for signature mismatch

1. Adjust a suggestion message that was annoying me
2. Fix #112503 by recording the right spans for the `self` part of the `&self` 0th argument
3. Remove the suggestion for adjusting a trait signature on type mismatch, bc that's gonna probably break all the other impls of the trait even if it fixes its one usage 😅
2023-07-22 19:57:35 +02:00
Mark Rousskov 67b0cfc761 Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
bors 921f669749 Auto merge of #113270 - the8472:opt-macro-tts, r=nnethercote
perform TokenStream replacement in-place when possible in expand_macro
2023-07-07 08:04:48 +00:00
Deadbeef 1c837cb6f7 Add effects during lowering for `~const` bounds 2023-07-04 11:47:45 +00:00
The 8472 7916a2c1c9 Use Lrc::make_mut instead of Lrc::get_mut 2023-07-03 13:40:25 +02:00
The 8472 14e57d7c13 perform TokenStream replacement in-place when possible in expand_macro 2023-07-03 13:29:15 +02:00
Michael Goulet 0f7ef1a202 Adjust inner span of implicit self ref argument 2023-06-28 17:51:01 +00:00
Maybe Waffle d7713feb99 Syntatically accept `become` expressions 2023-06-19 12:54:34 +00:00
Nilstrieb a647ba250a Remember names of `cfg`-ed out items to mention them in diagnostics
`#[cfg]`s are frequently used to gate crate content behind cargo
features. This can lead to very confusing errors when features are
missing. For example, `serde` doesn't have the `derive` feature by
default. Therefore, `serde::Serialize` fails to resolve with a generic
error, even though the macro is present in the docs.

This commit adds a list of all stripped item names to metadata. This is
filled during macro expansion and then, through a fed query, persisted
in metadata. The downstream resolver can then access the metadata to
look at possible candidates for mentioning in the errors.

This slightly increases metadata (800k->809k for the feature-heavy
windows crate), but not enough to really matter.
2023-06-01 19:17:19 +02:00
许杰友 Jieyou Xu (Joe) b9606589c4
Add warn-by-default lint for local binding shadowing exported glob re-export item 2023-05-27 18:49:07 +08:00