Commit Graph

5796 Commits

Author SHA1 Message Date
George Bateman
e606bb626e Remove direct dependencies on lazy_static, once_cell and byteorder
The functionality of all three crates is now available in the standard library.
2024-04-28 14:35:00 +01:00
Febriananda Wida Pramudita
f781b1b9d3 fix linter 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
003bab7523 fix linter 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
76ab3c19d8 refactor if into match 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
1f806d979a Update src/matches.rs
Co-authored-by: Yacin Tmimi <yacintmimi@gmail.com>
2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
23c11f3a08 rename file and remove unecessary file and add testcase 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
6540304790 add test and simplify code 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
3854ce9aca add test and simplify code 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
22a4306a7e fix the logic 2024-04-26 07:21:32 -06:00
klensy
4b1596f8a1 itertools bump to 0.12 2024-04-24 20:37:32 -06:00
Oli Scherer
20e40d5efe Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00
Matthias Krüger
9c0e5f2c34 Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco
Disallow ambiguous attributes on expressions

This implements the suggestion in [#15701](https://github.com/rust-lang/rust/issues/15701#issuecomment-2033124217) to disallow ambiguous outer attributes on expressions. This should resolve one of the concerns blocking the stabilization of `stmt_expr_attributes`.
2024-04-23 12:10:26 +02:00
Dominik Stolz
966dd60251 Disallow ambiguous attributes on expressions 2024-04-18 20:42:19 +02:00
Jules Bertholet
932f3ab762 Rename BindingAnnotation to BindingMode 2024-04-17 09:34:39 -04:00
bors
a568985c4f Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obk
Implement syntax for `impl Trait` to specify its captures explicitly (`feature(precise_capturing)`)

Implements `impl use<'a, 'b, T, U> Sized` syntax that allows users to explicitly list the captured parameters for an opaque, rather than inferring it from the opaque's bounds (or capturing *all* lifetimes under 2024-edition capture rules). This allows us to exclude some implicit captures, so this syntax may be used as a migration strategy for changes due to #117587.

We represent this list of captured params as `PreciseCapturingArg` in AST and HIR, resolving them between `rustc_resolve` and `resolve_bound_vars`. Later on, we validate that the opaques only capture the parameters in this list.

We artificially limit the feature to *require* mentioning all type and const parameters, since we don't currently have support for non-lifetime bivariant generics. This can be relaxed in the future.

We also may need to limit this to require naming *all* lifetime parameters for RPITIT, since GATs have no variance. I have to investigate this. This can also be relaxed in the future.

r? `@oli-obk`

Tracking issue:

- https://github.com/rust-lang/rust/issues/123432
2024-04-16 11:22:35 +00:00
León Orell Valerian Liehr
dac1a22ba0 Rollup merge of #123462 - fmease:rn-mod-sep-to-path-sep, r=nnethercote
Cleanup: Rename `ModSep` to `PathSep`

`::` is usually referred to as the *path separator* (citation needed).

The existing name `ModSep` for *module separator* is a bit misleading since it in fact separates the segments of arbitrary path segments, not only ones resolving to modules. Let me just give a shout-out to associated items (`T::Assoc`, `<Ty as Trait>::function`) and enum variants (`Option::None`).

Motivation: Reduce friction for new contributors, prevent potential confusion.

cc `@petrochenkov`
r? nnethercote or compiler
2024-04-16 01:12:37 +02:00
Michael Goulet
9400b9952e Rustfmt, clippy 2024-04-15 16:45:49 -04:00
Pietro Albini
afa482ef24 store the span of the nested part of the use tree in the ast 2024-04-14 18:45:28 +02:00
Oli Scherer
7af33b3076 Add pattern types to ast 2024-04-08 11:54:22 +00:00
hanghuge
728939191e chore: fix some typos
Signed-off-by: hanghuge <cmoman@outlook.com>
2024-04-07 15:20:42 -05:00
Yacin Tmimi
a848e28ff2 Revert "Initial work on formatting headers"
This reverts commit dd301b0c04.
2024-04-07 13:54:23 -05:00
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