Commit Graph

5571 Commits

Author SHA1 Message Date
Tanishq Rajesh Jain
202fa22cee
Fix: ICE when formatting builtins
Replace `unreachable!` with `None`. Now rustfmt won't
panic when it comes across a `builtin # offset_of` or any other builtin
2024-03-17 13:32:41 -04:00
Deadbeef
dd301b0c04 Initial work on formatting headers 2024-03-12 21:36:52 -06:00
ding-young
9580747a76
Fix failure with => in comment after match => (#6092)
* Find arrow with find_last_uncommented
* Add version gate for arrow finding fix
2024-03-11 22:26:28 -04:00
MarcusGrass
73c81495cd
Ensure space after binary exprs that ends with . before range expr
Removing the space would lead to compilation errors.
2024-03-04 22:19:57 -05:00
klensy
35c1b7d734 fix clap deprecations
Run 'cargo check --features clap/deprecated' and fix all warnings
2024-03-04 19:09:09 -07:00
cui fliter
21f353a637
Spelling fixes(#6088)
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-02-23 09:57:24 -05:00
rzhb
b5dcc6ff0e doc: simplify environment variable setting 2024-02-17 10:24:39 -07:00
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
Wim Looman
8486837d55 Bless the target file instead of the source file 2024-02-09 06:53:07 -07:00
Michael Ciraci
ead0fc9529
Consolidating dependencies (#6034)
* Updating dependencies for rustfmt in an attempt to consolidate rustc dependencies
* Updating link for dirs 5.0.1
2024-01-29 08:44:11 -05: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
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
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
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
Caleb Cartwright
85e21fabf4
Merge pull request #5994 from ytmimi/subtree_sync_with_1.77.0_nightly_2023_12_28
Subtree push with 1.77.0 nightly 2023-12-28
2023-12-28 21:18:48 -06:00
Yacin Tmimi
621904f452 chore: bump to nightly 2023_12_27 toolchain 2023-12-28 17:28:01 -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
Yacin Tmimi
fd78575c9c Bump Update itertools to 0.11. 2023-12-28 16:48:54 -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
Caleb Cartwright
20196767d4
Merge pull request #5980 from ytmimi/subtree_push_2023_12_12
Subtree push 2023-12-12
2023-12-13 14:18:07 -06:00
Yacin Tmimi
03510f3515 chore: bump to the nightly 2023-12-12 toolchain 2023-12-12 11:46:59 -05:00
Yacin Tmimi
227e361187 Merge remote-tracking branch 'upstream/master' into subtree_push_2023_12_12 2023-12-12 11:45:27 -05:00
Guillaume Gomez
948c9047d5 Rollup merge of #118802 - ehuss:remove-edition-preview, r=TaKO8Ki
Remove edition umbrella features.

In the 2018 edition, there was an "umbrella" feature `#[feature(rust_2018_preview)]` which was used to enable several other features at once. This umbrella mechanism was not used in the 2021 edition and likely will not be used in 2024 either. During 2018 users reported that setting the feature was awkward, especially since they already needed to opt-in via the edition mechanism.

This PR removes this mechanism because I believe it will not be used (and will clean up and simplify the code). I believe that there are better ways to handle features and editions. In short:

- For highly experimental features, that may or may not be involved in an edition, they can implement regular feature gates like `tcx.features().my_feature`.
- For experimental features that *might* be involved in an edition, they should implement gates with `tcx.features().my_feature && span.at_least_rust_20xx()`. This requires the user to still specify `#![feature(my_feature)]`, to avoid disrupting testing of other edition features which are ready and have been accepted within the edition.
- For experimental features that have graduated to definitely be part of an edition, they should implement gates with `tcx.features().my_feature || span.at_least_rust_20xx()`, or just remove the feature check altogether and just check `span.at_least_rust_20xx()`.
- For relatively simple changes, they can skip the whole feature gating thing and just check `span.at_least_rust_20xx()`, and rely on the instability of the edition itself (which requires `-Zunstable-options`) to gate it.

I am working on documenting all of this in the rustc-dev-guide.
2023-12-11 11:40:36 +01: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
Eric Huss
b9ad02421a Remove edition umbrella features. 2023-12-10 13:03:28 -08: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