Commit Graph

3686 Commits

Author SHA1 Message Date
Jules Bertholet
5805040d28
Search span using *unnormalized* ident (#6073)
Fixes 6069

Calling `item.ident.as_str()` returns an NFC normalized ident, which
might not be what's written in the source code. To avoid panics when
calling `snippet_provider.span_after` use the ident from the source.
2024-02-14 14:40:55 -05:00
Guillaume Gomez
e504c64a41 Rollup merge of #121035 - compiler-errors:rustfmt-asyncness, r=calebcartwright
Format `async` trait bounds in rustfmt

r? `@ytmimi` or `@calebcartwright`

This PR opts to do formatting in the rust-lang/rust tree because otherwise we'd have to wait until a full sync, and rustfmt is currently totally removing the `async` keyword.

cc https://github.com/rust-lang/rustfmt/issues/6070
2024-02-14 15:41:27 +01:00
Michael Goulet
bed388348b Format async bounds in rustfmt 2024-02-13 16:05:41 +00:00
Frank King
88c5838c06 Lower anonymous structs or unions to HIR 2024-02-12 12:47:23 +08:00
Wim Looman
8486837d55 Bless the target file instead of the source file 2024-02-09 06:53:07 -07:00
Nicholas Nethercote
18f51f79f3 Make Emitter::emit_diagnostic consuming.
All the other `emit`/`emit_diagnostic` methods were recently made
consuming (e.g. #119606), but this one wasn't. But it makes sense to.

Much of this is straightforward, and lots of `clone` calls are avoided.
There are a couple of tricky bits.
- `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and
  returns a pair. Instead it takes the two fields from `Diagnostic` that
  it used (`span` and `suggestions`) as `&mut`, and modifies them. This
  is necessary to avoid the cloning of `diag.children` in two emitters.
- `from_errors_diagnostic` is rearranged so various uses of `diag` occur
  before the consuming `emit_diagnostic` call.
2024-02-05 21:27:01 +11:00
David Bar-On
7bedb9fb8c
wrap macro line with width off by one char beyond max width (#5582)
Fix issue 3805
2024-01-28 19:07:30 -05:00
Josh Soref
cedb7b5058
Spelling (#5753)
various spelling fixes
---------

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2024-01-25 18:55:23 -05:00
Josh McKinney
7f44a0825d Format diff line to be easily clickable
Instead of {filename} at {line}, use {filename}:{line} as this is a
format that many editors allow to be clicked to navigate directly to the
line.
2024-01-25 10:30:22 -07:00
Michael Goulet
a0958082b3 Actually, just use nonterminal_may_begin_with 2024-01-22 02:19:42 +00:00
Michael Goulet
f8847ff3ec Do not eagerly recover malformed AST in rustfmt 2024-01-22 01:49:33 +00:00
Michael Goulet
b92320c39b Check that a token can begin a nonterminal kind before parsing it as a macro arg in rustfmt 2024-01-22 01:49:33 +00:00
IVIURRAY
bf967319e2
Add config option generated_marker_line_search_limit (#5993)
`generated_marker_line_search_limit` allows users to configure how many
lines rustfmt should search for an `@generated` marker comment when
`format_generated_files=false`

---------

Co-authored-by: Jordan Eldredge <jordan@jordaneldredge.com>
2024-01-20 11:14:50 -05:00
Lieselotte
255d2cf8f1 Add PatKind::Err 2024-01-17 03:14:16 +01:00
Bryanskiy
6078b96b23 Delegation implementation: step 1 2024-01-12 14:11:16 +03:00
Nicholas Nethercote
381ef817b7 Stop using DiagnosticBuilder::buffer in the parser.
One consequence is that errors returned by
`maybe_new_parser_from_source_str` now must be consumed, so a bunch of
places that previously ignored those errors now cancel them. (Most of
them explicitly dropped the errors before. I guess that was to indicate
"we are explicitly ignoring these", though I'm not 100% sure.)
2024-01-11 18:37:56 +11:00
Nicholas Nethercote
192c4a0cf4 Change how force-warn lint diagnostics are recorded.
`is_force_warn` is only possible for diagnostics with `Level::Warning`,
but it is currently stored in `Diagnostic::code`, which every diagnostic
has.

This commit:
- removes the boolean `DiagnosticId::Lint::is_force_warn` field;
- adds a `ForceWarning` variant to `Level`.

Benefits:
- The common `Level::Warning` case now has no arguments, replacing
  lots of `Warning(None)` occurrences.
- `rustc_session::lint::Level` and `rustc_errors::Level` are more
  similar, both having `ForceWarning` and `Warning`.
2024-01-11 07:56:17 +11:00
IVIURRAY
6356fca675
Prevent enum variant attributes from wrapping one character early
Fixes 5801 when using `version=Two`

Previously, doc comments would wrap one character less than the
`comment_width` when using `wrap_comments=true`, and fn-like attributes
would wrap one character before the `attr_fn_like_width`.

Now, when using `version=Two` enum variant attributes won't wrap early
2024-01-08 10:06:25 -05:00
Nicholas Nethercote
141b31a23f Make DiagnosticBuilder::emit consuming.
This works for most of its call sites. This is nice, because `emit` very
much makes sense as a consuming operation -- indeed,
`DiagnosticBuilderState` exists to ensure no diagnostic is emitted
twice, but it uses runtime checks.

For the small number of call sites where a consuming emit doesn't work,
the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will
be removed in subsequent commits.)

Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes
consuming, while `delay_as_bug_without_consuming` is added (which will
also be removed in subsequent commits.)

All this requires significant changes to `DiagnosticBuilder`'s chaining
methods. Currently `DiagnosticBuilder` method chaining uses a
non-consuming `&mut self -> &mut Self` style, which allows chaining to
be used when the chain ends in `emit()`, like so:
```
    struct_err(msg).span(span).emit();
```
But it doesn't work when producing a `DiagnosticBuilder` value,
requiring this:
```
    let mut err = self.struct_err(msg);
    err.span(span);
    err
```
This style of chaining won't work with consuming `emit` though. For
that, we need to use to a `self -> Self` style. That also would allow
`DiagnosticBuilder` production to be chained, e.g.:
```
    self.struct_err(msg).span(span)
```
However, removing the `&mut self -> &mut Self` style would require that
individual modifications of a `DiagnosticBuilder` go from this:
```
    err.span(span);
```
to this:
```
    err = err.span(span);
```
There are *many* such places. I have a high tolerance for tedious
refactorings, but even I gave up after a long time trying to convert
them all.

Instead, this commit has it both ways: the existing `&mut self -> Self`
chaining methods are kept, and new `self -> Self` chaining methods are
added, all of which have a `_mv` suffix (short for "move"). Changes to
the existing `forward!` macro lets this happen with very little
additional boilerplate code. I chose to add the suffix to the new
chaining methods rather than the existing ones, because the number of
changes required is much smaller that way.

This doubled chainging is a bit clumsy, but I think it is worthwhile
because it allows a *lot* of good things to subsequently happen. In this
commit, there are many `mut` qualifiers removed in places where
diagnostics are emitted without being modified. In subsequent commits:
- chaining can be used more, making the code more concise;
- more use of chaining also permits the removal of redundant diagnostic
  APIs like `struct_err_with_code`, which can be replaced easily with
  `struct_err` + `code_mv`;
- `emit_without_diagnostic` can be removed, which simplifies a lot of
  machinery, removing the need for `DiagnosticBuilderState`.
2024-01-08 15:24:49 +11:00
Matthias Krüger
75e3172aaa
fix a couply of clippy findings (#6007)
* clippy: autofix some lint warnings
* fix a couple more clippy warnings
2024-01-06 17:52:26 -05:00
Michael Goulet
250d7e764c Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obk
`Emitter` cleanups

Some improvements I found while looking at this code.

r? `@oli-obk`
2024-01-05 10:57:24 -05:00
Nicholas Nethercote
840824f3bb Rename EmitterWriter as HumanEmitter.
For consistency with other `Emitter` impls, such as `JsonEmitter`,
`SilentEmitter`, `SharedEmitter`, etc.
2024-01-05 10:02:40 +11:00
Jake Goulding
4a1b4182fe Rename unused_tuple_struct_fields in rustfmt
Otherwise tests fail due to unknown lint and dead code warnings.
2024-01-02 15:34:37 -05:00
Jake Goulding
ae760e695c Address unused tuple struct fields in rustfmt 2024-01-01 17:47:54 -05:00
Yacin Tmimi
6cc513f5e5 Merge remote-tracking branch 'origin/master' into subtree_sync_with_1.77.0_nightly_2023_12_27 2023-12-28 16:50:17 -05:00
Sam Tay
d86fc1bf64
Make trace! formatting consistent with other log macros (#5989)
Fixes 5987

rustfmt already special cases the formatting for the `debug!`, `info!`,
`warn!`, and `error!`, macros from the `log` crate. However, this
speical case handling did not apply to the `trace!` macro.

Now when using `Version=Two` rustfmt will also special case the
formatting for the `trace!` macro.
2023-12-23 22:39:01 -05:00
trevyn
c926898ff0 Clarify format_macro_bodies description 2023-12-23 17:07:53 -07:00
Matthias Krüger
f002221a53 Rollup merge of #119231 - aDotInTheVoid:PatKind-struct-bool-docs, r=compiler-errors
Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool

The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.

See cee794ee98/compiler/rustc_parse/src/parser/pat.rs (L890-L897) for the only place this is constructed.

r? ``@compiler-errors``
2023-12-23 16:23:54 +01:00
Alona Enraght-Moony
d9ea1027b5 bool->enum for ast::PatKind::Struct presence of ..
See cee794ee98/compiler/rustc_parse/src/parser/pat.rs (L890-L897) for the only place this is constructed.
2023-12-23 02:50:31 +00:00
Nicholas Nethercote
101bc225d8 Improve some names.
Lots of vectors of messages called `message` or `msg`. This commit
pluralizes them.

Note that `emit_message_default` and `emit_messages_default` both
already existed, and both process a vector, so I renamed the former
`emit_messages_default_inner` because it's called by the latter.
2023-12-23 13:23:28 +11:00
bors
b29b02ca5b Auto merge of #118847 - eholk:for-await, r=compiler-errors
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue.

r? `@compiler-errors`
2023-12-22 14:17:10 +00:00
bors
5085bf51dd Auto merge of #119163 - fmease:refactor-ast-trait-bound-modifiers, r=compiler-errors
Refactor AST trait bound modifiers

Instead of having two types to represent trait bound modifiers in the parser / the AST (`parser::ty::BoundModifiers` & `ast::TraitBoundModifier`), only to map one to the other later, just use `parser::ty::BoundModifiers` (moved & renamed to `ast::TraitBoundModifiers`).

The struct type is more extensible and easier to deal with (see [here](https://github.com/rust-lang/rust/pull/119099/files#r1430749981) and [here](https://github.com/rust-lang/rust/pull/119099/files#r1430752116) for context) since it more closely models what it represents: A compound of two kinds of modifiers, constness and polarity. Modeling this as an enum (the now removed `ast::TraitBoundModifier`) meant one had to add a new variant per *combination* of modifier kind, which simply isn't scalable and which lead to a lot of explicit non-DRY matches.

NB: `hir::TraitBoundModifier` being an enum is fine since HIR doesn't need to worry representing invalid modifier kind combinations as those get rejected during AST validation thereby immensely cutting down the number of possibilities.
2023-12-22 02:00:55 +00:00
León Orell Valerian Liehr
60419aa08a Refactor AST trait bound modifiers 2023-12-20 19:39:46 +01:00
Alona Enraght-Moony
df30a7a2e4 Give VariantData::Struct named fields, to clairfy recovered. 2023-12-20 00:07:34 +00:00
Eric Holk
0315daafee Plumb awaitness of for loops 2023-12-19 12:26:20 -08:00
Nicholas Nethercote
ca2472edd7 Rename many DiagCtxt and EarlyDiagCtxt locals. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
ef315b3d7f Rename default_handler as default_dcx. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
cce3961f9a Rename ParseSess::with_span_handler as ParseSess::with_dcx. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
7738d69007 Rename ParseSess::span_diagnostic as ParseSess::dcx. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
c7992aff25 Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
Aleksey Kononov
d739d93787
rename hide_parse_errors as show_parse_errors
Closes 3390

`hide_parse_errors` is now deprecated, and was renamed
`show_parse_errors` to avoid confusion around the double negative
default of `hide_parse_errors=false`.
2023-12-16 11:43:26 -05:00
Nicholas Nethercote
7045cad330 Split Handler::emit_diagnostic in two.
Currently, `emit_diagnostic` takes `&mut self`.

This commit changes it so `emit_diagnostic` takes `self` and the new
`emit_diagnostic_without_consuming` function takes `&mut self`.

I find the distinction useful. The former case is much more common, and
avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the
latter with `pub(crate)` which is nice.
2023-12-15 10:13:12 +11:00
Yacin Tmimi
227e361187 Merge remote-tracking branch 'upstream/master' into subtree_push_2023_12_12 2023-12-12 11:45:27 -05:00
Nicholas Nethercote
1cb804b520 Add spacing information to delimiters.
This is an extension of the previous commit. It means the output of
something like this:
```
stringify!(let a: Vec<u32> = vec![];)
```
goes from this:
```
let a: Vec<u32> = vec![] ;
```
With this PR, it now produces this string:
```
let a: Vec<u32> = vec![];
```
2023-12-11 09:36:40 +11:00
surechen
1b9bf8adf3 remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Yacin Tmimi
2174e6052d Add StyleEdition enum and StyleEditionDefault trait
**Note** This does not add the `style_edition` config option to rustfmt.
The `StyleEdition` enum will eventually be used to allow users to
configure the `style_edition`, but for now it's added so we can
introduce the the `StyleEditionDefault` trait.
2023-12-09 13:05:47 -06:00
bors
9c809ce8de Auto merge of #118420 - compiler-errors:async-gen, r=eholk
Introduce support for `async gen` blocks

I'm delighted to demonstrate that `async gen` block are not very difficult to support. They're simply coroutines that yield `Poll<Option<T>>` and return `()`.

**This PR is WIP and in draft mode for now** -- I'm mostly putting it up to show folks that it's possible. This PR needs a lang-team experiment associated with it or possible an RFC, since I don't think it falls under the jurisdiction of the `gen` RFC that was recently authored by oli (https://github.com/rust-lang/rfcs/pull/3513, https://github.com/rust-lang/rust/issues/117078).

### Technical note on the pre-generator-transform yield type:

The reason that the underlying coroutines yield `Poll<Option<T>>` and not `Poll<T>` (which would make more sense, IMO, for the pre-transformed coroutine), is because the `TransformVisitor` that is used to turn coroutines into built-in state machine functions would have to destructure and reconstruct the latter into the former, which requires at least inserting a new basic block (for a `switchInt` terminator, to match on the `Poll` discriminant).

This does mean that the desugaring (at the `rustc_ast_lowering` level) of `async gen` blocks is a bit more involved. However, since we already need to intercept both `.await` and `yield` operators, I don't consider it much of a technical burden.

r? `@ghost`
2023-12-08 19:13:57 +00:00
Michael Goulet
3ffacf75fe Make some matches exhaustive to avoid bugs, fix tools 2023-12-08 17:23:26 +00:00
Michael Goulet
6ebb66cea9 coro_kind -> coroutine_kind 2023-12-08 17:23:25 +00:00
bors
77bb46dedb Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errors
never_patterns: Parse match arms with no body

Never patterns are meant to signal unreachable cases, and thus don't take bodies:
```rust
let ptr: *const Option<!> = ...;
match *ptr {
    None => { foo(); }
    Some(!),
}
```
This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser).

~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit

r? `@compiler-errors`
2023-12-08 17:08:52 +00:00
Eric Holk
f114bb42ec Address code review feedback 2023-12-04 14:33:46 -08:00
Eric Holk
13d284d177 Option<CoroutineKind> 2023-12-04 13:03:37 -08:00
Eric Holk
97fdae1034 Merge Async and Gen into CoroutineKind 2023-12-04 12:48:01 -08:00
Nadrieril
a445ba8a9d Parse a pattern with no arm 2023-12-03 12:25:46 +01:00
Matthias Krüger
1ab7fc99af Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors
Add `never_patterns` feature gate

This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment.

`@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29 12:34:47 +01:00
Nadrieril
f2f243109b Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
Nicholas Nethercote
d84d8d2604 Rework ast::BinOpKind::to_string and ast::UnOp::to_string.
- Rename them both `as_str`, which is the typical name for a function
  that returns a `&str`. (`to_string` is appropriate for functions
  returning `String` or maybe `Cow<'a, str>`.)
- Change `UnOp::as_str` from an associated function (weird!) to a
  method.
- Avoid needless `self` dereferences.
2023-11-28 09:42:07 +11:00
Deadbeef
24ce52a199 Add Span to TraitBoundModifier 2023-11-24 14:32:05 +00:00
Dinu Blanovschi
494560cb57 fixes for rustfmt + ast visitor 2023-11-04 20:39:15 +01:00
GambitingMan
8d2c4157e6 Fixes comma added to comment in where-clause 2023-11-01 20:21:05 -05:00
Oli Scherer
a3be235fcc Add gen blocks to ast and do some broken ast lowering 2023-10-27 13:05:48 +00:00
GambitingMan
041f113159
Fixed error caused by combination of match_arm_blocks and control_brace_style
Fixes 5912

When `control_brace_style = "AlwaysNextLine"`, the code seems to always assume that `body_prefix` is `{`. This is however not the case when `match_arm_blocks = false`. This causes `block_sep` to introduce extra white space that causes the error.

The fix was to check if `body_prefix` is empty before matching on `ControlBraceStyle::AlwaysNextLine`.
2023-10-23 20:27:26 -04:00
bors
d5bf53b454 Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
report `unused_import` for empty reexports even it is pub

Fixes #116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing #115993.)
2023-10-23 20:24:09 +00:00
Caleb Cartwright
04bd7201a9 Merge commit '81fe905ca83cffe84322f27ca43950b617861ff7' into rustfmt-sync 2023-10-22 20:21:44 -05:00
Caleb Cartwright
746bf48ec4 chore: bump toolchain and apply minor updates 2023-10-22 12:59:03 -05:00
Caleb Cartwright
f35f25287f Merge remote-tracking branch 'upstream/master' into subtree-sync-2023-10-22 2023-10-22 12:45:06 -05:00
bohan
4335c28677 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Yacin Tmimi
547577fa5d implement sinlge line let-chain rules
for now, let-chains can only be formatted on a single line if the chain
consits of 2 expressions where the first is an identifier proceeded by
any number of unary operators and the second is a let-expr.
2023-10-10 20:13:50 -05:00
Cameron Steffen
457dc79a35 Add support for ExprKind::Let 2023-10-10 20:13:50 -05:00
Caleb Cartwright
2707103154 fix: adjust span derivation for const generics 2023-10-08 19:55:04 -04:00
Michael Goulet
f867858755 Fix spans for comments in rustfmt 2023-10-04 21:09:54 +00:00
Michael Goulet
8ac561afef Fix spans for comments in rustfmt 2023-10-04 21:09:54 +00:00
GambitingMan
a1fabbf386
Bugfix/comment duplication (#5913)
* Fix #5871

* Only idempotence test is necessary

* Update src/expr.rs

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

---------

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2023-09-20 14:29:02 -05:00
Ed Page
da7f67810f
feat(cargo): Style --help like cargo nightly (#5908)
* chore: Update clap
* refactor(cargo): Update style of derive
* feat(cargo): Style help like cargo nightly
2023-09-11 22:12:58 -04:00
pan93412
18737ddc72
Prefer light_rewrite_comment if it is not a doccomment (#5536)
Fixes 5533, 5568, 5907

Prevent `format_code_in_doc_comments=true` from affecting how non-doc comments are formatted.


---------

Co-authored-by: Yacin Tmimi <yacintmimi@gmail.com>
2023-09-11 14:15:59 -04:00
Matthew Jasper
e0d90ccd45 Update tools and fulldeps tests 2023-09-11 15:51:19 +00:00
Matthew Jasper
b8e3cb0377 Update tools and fulldeps tests 2023-09-11 15:51:19 +00:00
Linda_pp
262feb3337
Fix checking if newline is needed before else in let-else statement
Fixes 5901

Take leading attributes and comments into consideration when determining if we need to wrap the `else` keyword onto the next line.
2023-09-08 21:05:07 -04:00
Camille GILLOT
45e19aa80c Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
Camille GILLOT
96e583fd52 Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
David Bar-On
c7c57f8a16 Fix issue with extra semicolon when import comment preceeds semicolon 2023-08-30 23:55:13 -04:00
Robert Sammelson
1340fc412a Fix issues with formatting imports with comments 2023-08-30 23:55:13 -04:00
John Kåre Alsaker
eb349e35aa Use conditional synchronization for Lock 2023-08-30 06:10:02 +02:00
John Kåre Alsaker
9c25fbfa06 Use conditional synchronization for Lock 2023-08-30 06:10:02 +02:00
xxchan
f89cd3c1f3
Don't treat lines starting with . or ) as ordered markdown lists (#5839)
Fixes 5835

Ordered markdown lists start with 0-9 digits followed by a `.` or a `)`.
Now, rustfmt ensure that the `.` or `)` is only preceded by numeric
characters before deciding that it's reached an `ItemizedBlock`
2023-08-29 08:46:44 -04:00
Frank King
af6a6a3c2c 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
Frank King
cef3117302 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
tdanniels
e480739e56
Prevent ICE when formatting item-only vec!{} (#5879)
* Prevent ICE when formatting item-only `vec!{}`

Fixes 5735

Attempting to format invocations of macros which are considered "forced
bracket macros" (currently only `vec!`), but are invoked with braces
instead of brackets, and contain only items in their token trees,
currently triggers an ICE in rustfmt. This is because the function that
handles formatting macro invocations containing only items,
`rewrite_macro_with_items`, assumes that the forced delimiter style of
the macro being formatted is the same as the delimiter style in the
macro's source text when attempting to locate the span after the macro's
opening delimiter. This leads to the construction of an invalid span,
triggering the ICE.

The fix here is to pass the old delimiter style to
`rewrite_macro_with_items` as well, so that it can successfully locate
the span.
2023-08-17 15:21:53 -04:00
Kevin Ji
a57d57b16a Remove newlines in where clauses for v2
Fixes #5655.
2023-08-16 12:34:21 -04:00
fee1-dead
4b01e62943
refactor ABI formatting (#5845)
fixes 5701

Whenever we see an `extern "Rust"` on a function, we don't strip it from the function.

If there's any future desire to have rustfmt remove an explicit "Rust" ABI, as it historically did prior to this change, then we can consider updating the rustfmt config surface to support that scenario
2023-08-14 08:19:23 -04:00
Yuri Astrakhan
b069aac44d
Inline format arguments for easier reading (#5881)
* Inline format arguments for easier reading

Code becomes shorter and often easier to read when format args are inlined.  Note that I skipped the mixed cases to make it more straightforward (could be done separatelly).

Also, there are two FIXME comments - for some reasons inlining makes format string exceed 100 char line width and crash.

```
cargo clippy --workspace --allow-dirty --fix --benches --tests --bins -- -A clippy::all -W clippy::uninlined_format_args
```

* address feedback
2023-08-13 14:14:31 -05:00
Yacin Tmimi
e86c2ba545 Don't flatten blocks that have labels 2023-08-13 14:03:58 -05:00
Yacin Tmimi
d8aeabaee1 include block label length when calculating pat_shape of a match arm
Previously we alwasy assumed the match arm pattern would have
`shape.width` - 5 characters of space to work with.

Now if we're formatting a block expression with a label we'll take the
label into account.
2023-08-13 14:03:58 -05:00
Yacin Tmimi
0d4c1431f5 Improve formatting of empty macro_rules! definitions
Fixes 5882
2023-08-13 13:04:33 -05:00
Charles Lew
9f58224123 Update Unicode data to 15.0 2023-08-13 13:01:38 -05:00
Richard
36af403e6b
improve the --file-lines help (#5846)
* improve the file-lines example

* fix help order
2023-08-12 17:05:04 -05:00
bors
327903e669 Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #113945 (Fix wrong span for trait selection failure error reporting)
 - #114351 ([rustc_span][perf] Remove unnecessary string joins and allocs.)
 - #114418 (bump parking_lot to 0.12)
 - #114434 (Improve spans for indexing expressions)
 - #114450 (Fix ICE failed to get layout for ReferencesError)
 - #114461 (Fix unwrap on None)
 - #114462 (interpret: add mplace_to_ref helper method)
 - #114472 (Reword `confusable_idents` lint)
 - #114477 (Account for `Rc` and `Arc` when suggesting to clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-04 20:31:40 +00:00
bors
00b60cdd46 Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #113945 (Fix wrong span for trait selection failure error reporting)
 - #114351 ([rustc_span][perf] Remove unnecessary string joins and allocs.)
 - #114418 (bump parking_lot to 0.12)
 - #114434 (Improve spans for indexing expressions)
 - #114450 (Fix ICE failed to get layout for ReferencesError)
 - #114461 (Fix unwrap on None)
 - #114462 (interpret: add mplace_to_ref helper method)
 - #114472 (Reword `confusable_idents` lint)
 - #114477 (Account for `Rc` and `Arc` when suggesting to clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-04 20:31:40 +00:00
Matthias Krüger
6e87f866ec Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

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.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Matthias Krüger
af72b88a20 Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

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.

r? compiler-errors
2023-08-04 21:31:57 +02:00
bors
e3d6bf8daa Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
Lots of tiny incremental simplifications of `EmitterWriter` internals

ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version.

Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them.

After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-04 18:46:19 +00:00
bors
e6c4606bfe Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
Lots of tiny incremental simplifications of `EmitterWriter` internals

ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version.

Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them.

After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-04 18:46:19 +00:00
Nilstrieb
aca22c73fd 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
Nilstrieb
e83a7cadd2 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
Matthias Krüger
4cc22af56c Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebank
Suggests turbofish in patterns

Fixes #114112

r? ```@estebank```
2023-08-03 17:29:07 +02:00
Matthias Krüger
2c8cc96ac3 Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebank
Suggests turbofish in patterns

Fixes #114112

r? ```@estebank```
2023-08-03 17:29:07 +02:00
Nicholas Nethercote
14101ed5a5 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
Nicholas Nethercote
d165d4ad38 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
Mu001999
35d875a3a0 Fix rustfmt dep 2023-08-03 00:13:41 +08:00
Mu001999
e42bc9ec66 Fix rustfmt dep 2023-08-03 00:13:41 +08:00
Catherine
a72613be50 Add parenthesis around closure method call 2023-08-01 04:36:16 -04:00
Oli Scherer
aac383e3ea Use builder pattern instead of lots of arguments for EmitterWriter::new 2023-07-31 09:34:30 +00:00
Oli Scherer
f122a3328d Use builder pattern instead of lots of arguments for EmitterWriter::new 2023-07-31 09:34:30 +00:00
bors
1f369f8b6a 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
Yacin Tmimi
cdfa2f86b7 Handle dyn* syntax when rewriting ast::TyKind::TraitObject
Resolves 5542

Prior to rust-lang/rust#101212 the `ast::TraitObjectSyntax` enum only
had two variants `Dyn` and `None`. The PR that introduced the `dyn*`
syntax added a new variant `DynStar`, but did not update the formatting
rules to account for the new variant.

Now the new `DynStar` variant is properly handled and is no longer
removed by rustfmt.
2023-07-27 19:52:26 -05:00
Nicholas Nethercote
e60a9e2c97 Avoid into_trees usage in rustfmt.
Token tree cloning is only needed in one place.
2023-07-27 11:58:42 +10:00
Trevor Gross
08fd1644d2 Unite bless environment variables under RUSTC_BLESS
Currently, Clippy, Miri, Rustfmt, and rustc all use an environment variable to
indicate that output should be blessed, but they use different variable names.
In order to improve consistency, this patch applies the following changes:

- Emit `RUSTC_BLESS` within `prepare_cargo_test` so it is always
  available
- Change usage of `MIRI_BLESS` in the Miri subtree to use `RUSTC_BLESS`
- Change usage of `BLESS` in the Clippy subtree to `RUSTC_BLESS`
- Change usage of `BLESS` in the Rustfmt subtree to `RUSTC_BLESS`
- Adjust the blessable test in `rustc_errors` to use this same
  convention
- Update documentation where applicable

Any tools that uses `RUSTC_BLESS` should check that it is set to any value
other than `"0"`.
2023-07-26 16:54:02 -04:00
Oli Scherer
c0ee8f5fea Make x test src/tools/rustfmt --bless format rustfmt with the freshly built in-tree version 2023-07-26 08:22:52 +00:00
Oli Scherer
a3dfd82559 Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00:00
Deadbeef
a9ae746267 misc code cleanup 2023-07-19 22:26:43 -05:00
Michael Goulet
2db13f448c Support non-lifetime binders 2023-07-19 22:18:51 -05:00
Esteban Küber
6013a8014b On nightly, dump ICE backtraces to disk
Implement rust-lang/compiler-team#578.

When an ICE is encountered on nightly releases, the new rustc panic
handler will also write the contents of the backtrace to disk. If any
`delay_span_bug`s are encountered, their backtrace is also added to the
file. The platform and rustc version will also be collected.
2023-07-19 14:10:07 +00:00
tdanniels
b944a32e5c
Prevent ICE when formatting an empty-ish macro arm (#5833)
Fixes 5730

Previously rustfmt was attempting to slice a string with an invalid
range (`start > end`), leading to the ICE.

When formatting a macro transcriber snippet consisting of a lone
semicolon, the snippet was being formatted into the empty string,
leading the enclosing `fn main() {\n}` added by `format_code_block` to
be formatted into `fn main() {}`. However, rustfmt was assuming that the
enclosing function string's length had been left unchanged. This was
leading to an invalid range being constructed when attempting to trim
off the enclosing function.

The fix is to just clamp the range's start to be less than or equal
to the range's end, since if `end < start` there's nothing to iterate
over anyway.
2023-07-18 20:48:57 -05:00
Jordan McQueen
e0e633ef14
Use matches!() macro to improve readability (#5830)
* Use matches!() macro to improve readability

1. Use `matches!()` macro in `is_line_comment` and `is_block_comment` to
improve readability.
2. Very sightly improve the wording of the doc comment for these two functions.

* Update wording on doc comment on is_line_comment()
2023-07-17 17:51:51 -05:00
Deadbeef
5ed7f74d10 Actually use tracing for logging 2023-07-06 12:03:44 -04:00
Caleb Cartwright
f2bad9c7af fix: handle skip_macro_invocations from config file 2023-07-05 17:46:03 -04:00
Cosmic Horror
d9a09925d7 Switch ast::Stmt rewriting use to stmt::Stmt::from_simple_block 2023-07-03 12:06:25 -05:00
Cosmic Horror
8850854746 Don't skip semicolon if exprs follow 2023-07-03 12:06:25 -05:00
Deadbeef
bb87a1b717 Rewrite float literals ending in dots with parens in method calls 2023-07-03 12:03:12 -05:00
Deadbeef
326af2bd21 Switch to tracing for logging 2023-07-03 11:52:38 -05:00
Caleb Cartwright
78331eefaf Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rustfmt 2023-07-01 02:49:12 -05:00
Maybe Waffle
aa691480c0 Implement become expression formatting in rustfmt 2023-07-01 02:05:29 -05:00
Yacin Tmimi
1de65a2711 wrap else to next line if let-else pattern is multi-lined
This rule wasn't explicity stated in the style guide so it was missed,
but luckily we caught it during testing.
2023-07-01 01:06:35 -05:00
Yacin Tmimi
7b4e8a6d31 update else_block_exceeds_width calculation in let-else rewrite
By reversing the logic I felt that the code became a clearer. Also,
added a comment to make it clear that we need to take the trailing
semicolon for the `let-else` statement into account.
2023-07-01 01:06:35 -05:00
Yacin Tmimi
fe8b72d98e implement single_line_let_else_max_width
This allows users to configure the maximum length of a single line
`let-else` statements. `let-else` statements that otherwise meet the
requirements to be formatted on a single line will have their divergent
`else` block formatted over multiple lines if they exceed this length.

**Note**: `single_line_let_else_max_widt` will be introduced as a stable
configuration option.
2023-07-01 01:06:35 -05:00
Nilstrieb
80bf3ea542 Rollup merge of #112790 - WaffleLapkin:syntactically, r=Nilstrieb
Syntactically accept `become` expressions (explicit tail calls experiment)

This adds `ast::ExprKind::Become`, implements parsing and properly gates the feature.

cc `@scottmcm`
2023-06-21 07:37:02 +02:00
Yacin Tmimi
9386b32f5a wrap else { for long, single-lined initializer expressions
This helps to prevent max width errors.
2023-06-20 08:26:11 -05:00
Yacin Tmimi
521f86bae5 Prevent single-line let-else if it would exceed max_width 2023-06-20 08:26:11 -05:00
Yacin Tmimi
00fef2d51d Implement wrapping rules to force else on a newline in let-else 2023-06-20 08:26:11 -05:00
Yacin Tmimi
7a3e4fca40 Implement let-else rewriting in terms of rewrite_let_else_block
`rewrite_let_else_block` gives us more control over allowing the `else`
block to be formatted on a single line than
`<ast::Block as Rewrite>::rewrite`.
2023-06-20 08:26:11 -05:00
Yacin Tmimi
8be748dbb7 Allow callers to determine if blocks can be formatted on a single line
This will make it easier to format the divergent blocks of `let-else`
statements since it'll be easier to prevent the block from being
formatted on a single line if the preconditions aren't met.
2023-06-20 08:26:11 -05:00
Yacin Tmimi
9316df0ca2 Initial pass at implementing let-else 2023-06-20 08:26:11 -05:00
Yacin Tmimi
75870c55b9 Extract logic for rewriting else keyword into function
The function properly handles recovering comments before and after the
`else` keyword, and properly handles how to write the else when users
configure `control_brace_style`.
2023-06-20 08:26:11 -05:00
Caleb Cartwright
ed3e96e3d1 Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-sync 2023-06-19 23:13:56 -05:00
Caleb Cartwright
0b17d7ea46 chore: address merge and bump toolchain 2023-06-19 21:29:15 -05:00
Caleb Cartwright
312a86b46b Merge remote-tracking branch 'upstream/master' into subtree-sync-2023-06-19 2023-06-19 20:56:20 -05:00
Lukasz Anforowicz
f4201ef2cb Handling of numbered markdown lists.
Fixes issue #5416
2023-06-19 20:50:01 -05:00
KaDiWa
66b9951dcd update some dependencies 2023-06-19 11:20:51 -05:00
Yacin Tmimi
2c30fa5a82 Adjust enum variant spans to exclude any explicit discriminant
Fixes 5686

For reference, explicit discriminants were proposed in [RFC-2363].

`ast::Variant` spans extend to include explicit discriminants when they
are present.

Now we'll adjust the span of enum variants to exclude any explicit
discriminant.

[RFC-2363]: https://rust-lang.github.io/rfcs/2363-arbitrary-enum-discriminant.html
2023-06-19 10:12:19 -05:00
Yacin Tmimi
ac2ebd3a78 Prevent ICE when calling parse_attribute without an attribute
Fixes 5729

`parse_attribute` will panic if the first token is not a `#`. To prevent
this we return early instead of trying to parse an invalid attribute.
2023-06-19 09:58:12 -05:00
Deadbeef
a463f231f5 remove derive_new dependency 2023-06-19 09:46:37 -05:00
Deadbeef
7d48be355a bump deps to new versions that use syn 2.0 2023-06-19 09:46:37 -05:00
Maybe Waffle
dc7dc3e74c Implement become expression formatting in rustfmt 2023-06-19 12:54:34 +00:00
Deadbeef
5f9de6bfc9 Recover comments between attrs and generic param
Fixes #5320.
2023-06-11 19:34:36 -05:00
Matthias Krüger
48e380fa40 Rollup merge of #110989 - jyn514:bug-report-url, r=WaffleLapkin
Make the BUG_REPORT_URL configurable by tools

This greatly simplifies how hard it is to set a custom bug report url; previously tools had to copy
the entire hook implementation.

I haven't changed clippy in case they want to make the change upstream instead of the subtree, but
I'm happy to do so here if the maintainers want - cc ````@rust-lang/clippy````

Fixes https://github.com/rust-lang/rust/issues/109486.
2023-05-06 13:30:04 +02:00
Michael Goulet
8ed5d5de3d Rustfmt support for negative bounds, test 2023-05-02 22:36:25 +00:00
Michael Goulet
8e330f9d5b Make tools happy 2023-05-02 22:36:24 +00:00
jyn
34a71f67d1 Make the BUG_REPORT_URL configurable by tools
This greatly simplifies how hard it is to set a custom bug report url; previously tools had to copy
the entire hook implementation.

- Switch clippy to the new hook

  This also adds a `extra_info` callback so clippy can include its own version number, which differs
  from rustc's.

- Call `install_ice_hook` in rustfmt
2023-05-01 21:44:04 -05:00
Lukas Markeffsky
a44c7ea592 fix broken markdown 2023-04-27 13:44:17 -05:00
Michael Goulet
6b9c151686 Tweak await span 2023-04-27 17:18:11 +00:00
DrMeepster
f4c9b4c26f rustfmt fmt 2023-04-21 08:59:30 -07:00
DrMeepster
ecfdec44df minor tweaks 2023-04-21 02:14:04 -07:00
DrMeepster
84385bff42 offset_of 2023-04-21 02:14:02 -07:00
Oli Scherer
f1781396bf box a bunch of large types 2023-04-04 13:58:50 +00:00
Oli Scherer
3ecb9ed53c Split out ast::ItemKind::Const into its own struct 2023-04-04 09:44:50 +00:00
Oli Scherer
ced3cd8d40 rust-analyzer guided tuple field to named field 2023-04-04 09:44:50 +00:00
Oli Scherer
c2890ec2d7 rust-analyzer guided enum variant structification 2023-04-04 09:44:45 +00:00
Greg Jandl
a3b2bfc2db Honor --color option when emitting errors
Fixes issue 5717.
2023-04-01 16:51:30 -04:00
Yacin Tmimi
475396a03c Prevent ICE when calling parse_attribute in parse_cfg_if_inner
Fixes 5728

Previously we were ignoring the diagnostic error, which lead to the ICE.
Now we properly cancel the error.
2023-04-01 13:21:12 -05:00
Guillaume Gomez
5cbb08db00 Rollup merge of #109354 - Swatinem:rm-closureid, r=compiler-errors
Remove the `NodeId` of `ast::ExprKind::Async`

This is a followup to https://github.com/rust-lang/rust/pull/104833#pullrequestreview-1314537416.

In my original attempt, I was using `LoweringContext::expr`, which was not correct as it creates a fresh `DefId`.
It now uses the correct `DefId` for the wrapping `Expr`, and also makes forwarding `#[track_caller]` attributes more explicit.
2023-03-27 18:56:19 +02:00
Vadim Petrochenkov
809dd77b80 rustc: Remove unused Session argument from some attribute functions 2023-03-22 13:55:55 +04:00
Arpad Borsos
3ef194c14c Remove the NodeId of ast::ExprKind::Async 2023-03-19 19:01:31 +01:00
clubby789
4e658cc01e Remove box_syntax from AST and use in tools 2023-03-12 13:19:46 +00:00
David Wood
386ea3770f various: translation resources from cg backend
Extend `CodegenBackend` trait with a function returning the translation
resources from the codegen backend, which can be added to the complete
list of resources provided to the emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22 09:15:54 +00:00
David Wood
8b7f8116d6 errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in
`rustc_error_messages`, each crate generates typed identifiers for its
own diagnostics and creates a static which are pulled together in the
`rustc_driver` crate and provided to the diagnostic emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22 09:15:53 +00:00
Nicholas Nethercote
01ed9ddf0e Use ThinVec in a few more AST types. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
23007fc9e4 Use ThinVec in ast::Block. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
af75a2f7f1 Use ThinVec in various AST types.
This commit changes the sequence parsers to produce `ThinVec`, which
triggers numerous conversions.
2023-02-21 11:51:56 +11:00
Caleb Cartwright
34f9ca28f2 fix: use correct span for struct generics 2023-02-16 00:03:36 -05:00
Esteban Küber
24f4ecec25 Introduce -Zterminal-urls to use OSC8 for error codes
Terminals supporting the OSC8 Hyperlink Extension can support inline
anchors where the text is user defineable but clicking on it opens a
browser to a specified URLs, just like `<a href="URL">` does in HTML.

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
2023-02-09 14:52:54 +00:00
Nicholas Nethercote
c6b822d855 Rename Cursor/CursorRef as TokenTreeCursor/RefTokenTreeCursor.
This makes it clear they return token trees, and makes for a nice
comparison against `TokenCursor` which returns tokens.
2023-02-03 10:06:52 +11:00
Rajiv Sharma
5391847ea5 Fix #5488 - prevent shorthand init for tuple struct
Closes #5488

Fix for #5488. Before applying shorthand initialization for structs,
check if identifier is a literal (e.g. tuple struct). If yes, then do
not apply short hand initialization.

Added test case to validate the changes for the fix.
2023-02-01 21:33:19 -06:00
Thaqib
e2996a807b
Lists doc comments fix4041 (#5560)
* add + start of an itemized line

* add test

* fix format

* fix tests

* update doc comment
2023-02-01 21:26:12 -06:00
Wim Looman
368a63305c Fix typo 2023-01-29 16:47:06 -06:00
Ayaz Hafiz
846662cdb3 Don't wrap comments that are part of a table
Closes #4210
2023-01-29 16:47:06 -06:00
Tom French
61d82acf53
refactor: fix typo in comment (#5581) 2023-01-29 16:43:40 -06:00
David Bar-On
b08130c590
Fix #5234 - handling of empty code block (#5601) 2023-01-29 12:55:14 -06:00
Arthur Carcano
567bd97723
Document which comments are excluded from wrapping (#5637)
* Document which comments are excluded from wrapping

Cf: https://github.com/rust-lang/rustfmt/issues/5634

* Add examples in wrap_commments doc

* fix failling tests
2023-01-28 15:16:46 -06:00
bors
6d133152f8 Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
Move format_args!() into AST (and expand it during AST lowering)

Implements https://github.com/rust-lang/compiler-team/issues/541

This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier.

This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`.

This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
2023-01-26 12:44:47 +00:00
Caleb Cartwright
094b7f599c Merge commit '1d8491b120223272b13451fc81265aa64f7f4d5b' into sync-from-rustfmt 2023-01-24 14:16:03 -06:00
Caleb Cartwright
5139b14620 fix: version gate changes for multiline single generic bound 2023-01-24 11:38:44 -06:00
Caleb Cartwright
e7d87ad61d Merge remote-tracking branch 'upstream/master' into subtree-sync-2023-01-24 2023-01-23 21:19:31 -06:00
Caleb Cartwright
aae222c974 fix: correct span for structs with const generics 2023-01-23 12:55:02 -05:00
Deadbeef
19c2286d5c parse const closures 2023-01-12 02:28:37 +00:00
Mara Bos
80d196d789 Update rustfmt for ast::ExprKind::FormatArgs.
Rustfmt doesn't expand macros, so that's easy: FormatArgs nodes do not
occur in the unexpanded AST.
2023-01-12 00:25:46 +01:00
bjorn3
d7fa2ee3e6 Add missing extern crate rustc_driver 2022-12-31 17:20:13 +00:00
Nilstrieb
ac8eaa1ba7 Rename Rptr to Ref in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already
as well.
2022-12-28 18:52:36 +01:00
bors
53ca2598d3 Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov
Remove `token::Lit` from `ast::MetaItemLit`.

Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-12 05:16:50 +00:00
Matthias Krüger
2119f7d7d1 Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot
Keep track of the start of the argument block of a closure

This removes a call to `tcx.sess.source_map()` from [compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs](https://github.com/rust-lang/rust/compare/master...SarthakSingh31:issue-97417-1?expand=1#diff-8406bbc0d0b43d84c91b1933305df896ecdba0d1f9269e6744f13d87a2ab268a) as required by #97417.

VsCode automatically applied `rustfmt` to the files I edited under `src/tools`. I can undo that if its a problem.

r? `@cjgillot`
2022-12-03 17:37:41 +01:00
Nicholas Nethercote
c91dd22870 Remove token::Lit from ast::MetaItemLit.
`token::Lit` contains a `kind` field that indicates what kind of literal
it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has
its own `kind` field. This means that `ast::MetaItemLit` encodes the
literal kind in two different ways.

This commit changes `ast::MetaItemLit` so it no longer wraps
`token::Lit`. It now contains the `symbol` and `suffix` fields from
`token::Lit`, but not the `kind` field, eliminating the redundancy.
2022-12-02 13:49:19 +11:00