Commit Graph

5775 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
fd204262e5 Rename ModSep to PathSep 2024-04-04 19:44:04 +02:00
Jules Bertholet
31a4eae7ea Add rustfmt test for mut ref mut 2024-03-27 16:38:56 -04:00
Jules Bertholet
645b94c155 Implement mut ref/mut ref mut 2024-03-27 09:53:23 -04:00
Matthias Krüger
5e141e034c Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco
conditionally ignore fatal diagnostic in the SilentEmitter

This change is primarily meant to allow rustfmt to ignore all diagnostics when using the `SilentEmitter`. Back in #121301 the `SilentEmitter` was shared between rustc and rustfmt. This changed rustfmt's behavior from ignoring all diagnostic to emitting fatal diagnostics, which lead to https://github.com/rust-lang/rustfmt/issues/6109.

These changes allow rustfmt to maintain its previous behaviour when using the `SilentEmitter`, while allowing rustc code to still emit fatal diagnostics.
2024-03-24 17:08:15 +01:00
Matthias Krüger
0aa66d1705 Rollup merge of #121619 - RossSmyth:pfix_match, r=petrochenkov
Experimental feature postfix match

This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, #121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ```@scottmcm``` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md).

This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement.

It is entirely implemented in the parser, so it should be relatively easy to remove if needed.

This PR is split in to 5 commits to ease review.

1. The implementation of the feature & gating.
2. Add a MatchKind field, fix uses, fix pretty.
3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix.
4. Add new MatchSource to HIR for Clippy & other HIR consumers
2024-03-22 11:36:58 +01:00
Michael Goulet
f670f3b5e0 Implement macro-based deref!() syntax for deref patterns
Stop using `box PAT` syntax for deref patterns, as it's misleading and
also causes their semantics being tangled up.
2024-03-21 11:42:49 -04:00
Mark Rousskov
8f62a2dedb step cfgs 2024-03-20 08:49:13 -04:00
Yacin Tmimi
911f6a438f conditionally ignore fatal diagnostic in the SilentEmitter
This change is primarily meant to allow rustfmt to ignore all
diagnostics when using the `SilentEmitter`. Back in PR 121301 the
`SilentEmitter` was shared between rustc and rustfmt. This changed
rustfmt's behavior from ignoring all diagnostic to emitting fatal
diagnostics.

These changes allow rustfmt to maintain it's previous behaviour when
using the SilentEmitter, while allowing rustc code to still emit fatal
diagnostics.
2024-03-19 13:48:07 -04:00
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
Guillaume Gomez
fe0415e17a Rename ast::StmtKind::Local into ast::StmtKind::Let 2024-03-14 12:42:04 +01: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
Matthias Krüger
5f8d353fe1 Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, r=davidtwco
Rework `untranslatable_diagnostic` lint

Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`.

r? ``@davidtwco``
2024-03-06 22:02:46 +01:00
Ross Smyth
1709dd59bd Add basic rustfmt implementation & test 2024-03-06 00:51:45 -05:00
Ross Smyth
f3892a06cc Add MatchKind member to the Match expr for pretty printing & fmt 2024-03-06 00:35:19 -05:00
Nicholas Nethercote
677c1d8059 Rewrite the untranslatable_diagnostic lint.
Currently it only checks calls to functions marked with
`#[rustc_lint_diagnostics]`. This commit changes it to check calls to
any function with an `impl Into<{D,Subd}iagMessage>` parameter. This
greatly improves its coverage and doesn't rely on people remembering to
add `#[rustc_lint_diagnostics]`.

The commit also adds `#[allow(rustc::untranslatable_diagnostic)`]
attributes to places that need it that are caught by the improved lint.
These places that might be easy to convert to translatable diagnostics.

Finally, it also:
- Expands and corrects some comments.
- Does some minor formatting improvements.
- Adds missing `DecorateLint` cases to
  `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
2024-03-06 14:19:01 +11:00
David Wood
124808b582 errors: share SilentEmitter between rustc and rustfmt
Signed-off-by: David Wood <david@davidtw.co>
2024-03-05 10:14:36 +00: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
Nicholas Nethercote
fe9ceab356 Rename DiagnosticMessage as DiagMessage. 2024-03-05 12:14:49 +11:00
Nicholas Nethercote
78c99ebfea Rename all ParseSess variables/fields/lifetimes as psess.
Existing names for values of this type are `sess`, `parse_sess`,
`parse_session`, and `ps`. `sess` is particularly annoying because
that's also used for `Session` values, which are often co-located, and
it can be difficult to know which type a value named `sess` refers to.
(That annoyance is the main motivation for this change.) `psess` is nice
and short, which is good for a name used this much.

The commit also renames some `parse_sess_created` values as
`psess_created`.
2024-03-05 08:11:45 +11:00
Nicholas Nethercote
0b56261cef Tweak parse_asm_args.
It doesn't need a `Parser` and a `ParseSess`, because the former
contains the latter.
2024-03-04 16:12:33 +11:00
Matthias Krüger
050610e772 Rollup merge of #121326 - fmease:detect-empty-leading-where-clauses-on-ty-aliases, r=compiler-errors
Detect empty leading where clauses on type aliases

1. commit: refactor the AST of type alias where clauses
   * I could no longer bear the look of `.0.1` and `.1.0`
   * Arguably moving `split` out of `TyAlias` into a substruct might not make that much sense from a semantic standpoint since it reprs an index into `TyAlias.predicates` but it's alright and it cleans up the usage sites of `TyAlias`
2. commit: fix an oversight: An empty leading where clause is still a leading where clause
   * semantically reject empty leading where clauses on lazy type aliases
     * e.g., on `#![feature(lazy_type_alias)] type X where = ();`
   * make empty leading where clauses on assoc types trigger lint `deprecated_where_clause_location`
     * e.g., `impl Trait for () { type X where = (); }`
2024-02-29 20:50:02 +01:00
León Orell Valerian Liehr
fc64cbdbe7 AST: Refactor type alias where clauses 2024-02-29 17:18:40 +01:00
Guillaume Gomez
6f2722b2fa Rollup merge of #121783 - nnethercote:emitter-cleanups, r=oli-obk
Emitter cleanups

Some cleanups I made when reading emitter code. In particular, `HumanEmitter` and `JsonEmitter` have gone from three constructors to one.

r? `@oli-obk`
2024-02-29 17:08:38 +01:00
Nicholas Nethercote
9c85ae873c Inline and remove HumanEmitter::stderr.
Because `HumanEmitter::new` is enough, in conjunction with the (renamed)
`stderr_destination` function.
2024-02-29 17:50:23 +11:00
Nicholas Nethercote
0811e8f877 Rename DiagCtxt::with_emitter as DiagCtxt::new.
Because it's now the only constructor.
2024-02-29 16:30:12 +11:00
Nicholas Nethercote
45aad17905 Reinstate emit_stashed_diagnostics in DiagCtxtInner::drop.
I removed it in #121206 because I thought thought it wasn't necessary.
But then I had to add an `emit_stashed_diagnostics` call elsewhere in
rustfmt to avoid the assertion failure (which took two attempts to get
right, #121487 and #121615), and now there's an assertion failure in
clippy as well (https://github.com/rust-lang/rust-clippy/issues/12364).

So this commit just reinstates the call in `DiagCtxtInner::drop`. It
also reverts the rustfmt changes from #121487 and #121615, though it
keeps the tests added for those PRs.
2024-02-29 11:08:29 +11:00
Nicholas Nethercote
4026fd735c Rename DiagnosticBuilder as Diag.
Much better!

Note that this involves renaming (and updating the value of)
`DIAGNOSTIC_BUILDER` in clippy.
2024-02-28 08:55:35 +11:00
Nicholas Nethercote
d84567c0ff Rename Diagnostic as DiagInner.
I started by changing it to `DiagData`, but that didn't feel right.
`DiagInner` felt much better.
2024-02-28 08:33:25 +11:00
bors
f9dba393ea Auto merge of #121636 - matthiaskrgr:rollup-1tt2o5n, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #121389 (llvm-wrapper: fix few warnings)
 - #121493 (By changing some attributes to only_local, reducing encoding attributes in the crate metadate.)
 - #121615 (Move `emit_stashed_diagnostic` call in rustfmt.)
 - #121617 (Actually use the right closure kind when checking async Fn goals)
 - #121628 (Do not const prop unions)
 - #121629 (fix some references to no-longer-existing ReprOptions.layout_seed)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-26 17:14:13 +00:00
Matthias Krüger
c18226de7d Rollup merge of #121615 - nnethercote:fix-121517, r=oli-obk
Move `emit_stashed_diagnostic` call in rustfmt.

This call was added to `parse_crate_mod` in #121487, to fix a case where a stashed diagnostic wasn't emitted. But there is another path where a stashed diagnostic might fail to be emitted if there's a parse error, if the `build` call in `parse_crate_inner` fails before `parse_crate_mod` is reached.

So this commit moves the `emit_stashed_diagnostic` call outwards, from `parse_crate_mod` to `format_project`, just after the `Parser::parse_crate` call. This should be far out enough to catch any parsing errors.

Fixes #121517.

r? `@oli-obk`
cc `@ytmimi`
2024-02-26 16:06:03 +01:00
bors
50987bb36d Auto merge of #120586 - ShE3py:exprkind-err, r=fmease
Add `ErrorGuaranteed` to `ast::ExprKind::Err`

See #119967 for context
```
      \
       \
          _~^~^~_
      \) /  o o  \ (/
        '_   -   _'
        / '-----' \
```

r? fmease
2024-02-26 14:43:15 +00:00
Nicholas Nethercote
90af751966 Move emit_stashed_diagnostic call in rustfmt.
This call was added to `parse_crate_mod` in #121487, to fix a case where
a stashed diagnostic wasn't emitted. But there is another path where a
stashed diagnostic might fail to be emitted if there's a parse error, if
the `build` call in `parse_crate_inner` fails before `parse_crate_mod`
is reached.

So this commit moves the `emit_stashed_diagnostic` call outwards, from
`parse_crate_mod` to `format_project`, just after the
`Parser::parse_crate` call. This should be far out enough to catch any
parsing errors.

Fixes #121517.
2024-02-26 10:45:45 +11:00
Lieselotte
1bbfb76993 Add ErrorGuaranteed to ast::ExprKind::Err 2024-02-25 22:24:31 +01:00
Lieselotte
7d82dd0d31 Add ast::ExprKind::Dummy 2024-02-25 22:22:09 +01:00
bors
8c337451c1 Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
Implement RFC 3373: Avoid non-local definitions in functions

This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-25 19:11:06 +00:00
cui fliter
21f353a637
Spelling fixes(#6088)
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-02-23 09:57:24 -05:00
Nicholas Nethercote
ce71137b96 Explicitly call emit_stashed_diagnostics.
Commit 72b172b in #121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But
rustfmt doesn't use `run_compiler`, so it needs to call
`emit_stashed_diagnostics` itself to avoid an abort in
`DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes #121450.
2024-02-23 16:09:51 +11:00
Matthias Krüger
163c3ebf52 Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercote
errors: only eagerly translate subdiagnostics

Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context.

This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change).

r? ```@nnethercote```
2024-02-17 18:47:40 +01:00
rzhb
b5dcc6ff0e doc: simplify environment variable setting 2024-02-17 10:24:39 -07:00
Urgau
263910118c Allow newly added non_local_definitions in rustfmt 2024-02-17 13:59:46 +01:00
David Wood
aba5f546de errors: only eagerly translate subdiagnostics
Subdiagnostics don't need to be lazily translated, they can always be
eagerly translated. Eager translation is slightly more complex as we need
to have a `DiagCtxt` available to perform the translation, which involves
slightly more threading of that context.

This slight increase in complexity should enable later simplifications -
like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages
into the diagnostic structs rather than having them in separate files
(working on that was what led to this change).

Signed-off-by: David Wood <david@davidtw.co>
2024-02-15 10:34:41 +00:00
Nicholas Nethercote
6674be9657 Add an ErrorGuaranteed to ast::TyKind::Err.
This makes it more like `hir::TyKind::Err`, and avoids a
`span_delayed_bug` call in `LoweringContext::lower_ty_direct`.

It also requires adding `ast::TyKind::Dummy`, now that
`ast::TyKind::Err` can't be used for that purpose in the absence of an
error emission.

There are a couple of cases that aren't as neat as I would have liked,
marked with `FIXME` comments.
2024-02-15 09:35:11 +11: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
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
16250ea7ba Add rustfmt test from #117942 2024-02-12 12:47:30 +08: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