Commit Graph

5673 Commits

Author SHA1 Message Date
Yacin Tmimi
30eb54b5ca Add config_proc_macro to system tests
Also formats unforamatted files in the crate.
2024-06-13 00:43:21 -04:00
Yacin Tmimi
8abbcad938 format #![feature(unsafe_attributes)]
Our diff-check job was failing in part due to removing `unsafe` from any
`#[unsafe(attributes)]`. To prevent that I added a quick implementation
for this.
2024-06-12 23:53:53 -04:00
Yacin Tmimi
8e80f8aa3a don't apply formatting to builtin type ascription syntax
The syntax changed from `expr: ty` -> `builtin # type_ascribe(expr, ty)`
For now, rustfmt will just emit the contents of the span.
2024-06-12 22:40:15 -04:00
Yacin Tmimi
8c4c336e37 remove archived error-chain crate from integration tests
Can't run `cargo test --all` for `error-chain` anymore. The tests don't
compile because of `#[deny(invalid_doc_attributes)]`. Here's  the error
message:

```
error: this attribute can only be applied at the crate level
   --> tests/tests.rs:508:7
    |
508 | #[doc(test)]
    |       ^^^^
    |
    = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
    = note: `#[deny(invalid_doc_attributes)]` on by default
help: to apply to the crate, use an inner attribute
    |
508 | #![doc(test)]
    |  +
```
2024-06-12 22:40:05 -04:00
Yacin Tmimi
acc687735a Bumped bytecount 0.6.4 -> 0.6.8
fixes compilation issues with the `generic-simd` feature
2024-06-12 22:39:26 -04:00
Yacin Tmimi
2db10950fe allow dead code for StyleEditionDefault
We need to allow `StyleEditionDefault` because it will be used to
implement `style_edition`, but that work is currently ongoing.
2024-06-12 22:39:13 -04:00
Yacin Tmimi
afa731e42f bump toolchain to nightly-2024-06-13 2024-06-12 22:38:19 -04:00
Yacin Tmimi
76cd550c54 Merge remote-tracking branch 'upstream/master' into subtree-push-nightly-2024-06-13 2024-06-12 22:37:39 -04:00
Rémy Rakic
783a411f67 Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco"
This reverts commit 57dad1d75e, reversing
changes made to 36316df9fe.
2024-06-06 20:39:54 +00:00
bors
c1ea87876f Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obk
Unsafe extern blocks

This implements RFC 3484.

Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484

This is better reviewed commit by commit.
2024-06-06 08:14:58 +00:00
Nicholas Nethercote
ecb2dd151c rustfmt: Remove an unnecessary catch_unwind use.
The `Input::File` and `Input::Text` cases should be very similar.
However, currently the `Input::File` case uses `catch_unwind` because,
until recently (#125815) there was a fallible version of
`new_parser_from_source_str` but only an infallible version of
`new_parser_from_file`. This difference wasn't fundamental, just an
overlooked gap in the API of `rustc_parse`.

Both of those operations are now fallible, so the `Input::File` and
`Input::Text` cases can made more similar, with no need for
`catch_unwind`. This also lets us simplify an `Option<Vec<Diag>>` to
`Vec<Diag>`.
2024-06-05 10:38:03 +10:00
Nicholas Nethercote
5962aa96f1 Make top-level rustc_parse functions fallible.
Currently we have an awkward mix of fallible and infallible functions:
```
       new_parser_from_source_str
 maybe_new_parser_from_source_str
       new_parser_from_file
(maybe_new_parser_from_file)        // missing
      (new_parser_from_source_file) // missing
 maybe_new_parser_from_source_file
       source_str_to_stream
 maybe_source_file_to_stream
```
We could add the two missing functions, but instead this commit removes
of all the infallible ones and renames the fallible ones leaving us with
these which are all fallible:
```
new_parser_from_source_str
new_parser_from_file
new_parser_from_source_file
source_str_to_stream
source_file_to_stream
```
This requires making `unwrap_or_emit_fatal` public so callers of
formerly infallible functions can still work.

This does make some of the call sites slightly more verbose, but I think
it's worth it for the simpler API. Also, there are two `catch_unwind`
calls and one `catch_fatal_errors` call in this diff that become
removable thanks this change. (I will do that in a follow-up PR.)
2024-06-05 10:38:03 +10:00
Nicholas Nethercote
eeefcd66cb Remove stream_to_parser.
It's a zero-value wrapper of `Parser::new`.
2024-06-05 10:37:59 +10:00
Santiago Pastorino
6478d9e59c Handle safety keyword for extern block inner items 2024-06-04 14:19:42 -03:00
Amr Hesham
c97996fab6 collapse nested if detected by clippy 2024-06-03 21:08:58 -06:00
benluiwj
76ef162af7 add check_diff crate skeleton code 2024-06-03 20:47:45 -06:00
WeiTheShinobi
bf7bb56524 Prevent rustfmt from removing inner attributes in inline const blocks
Fixes 6158
2024-05-31 20:40:07 -06:00
George Bateman
871113eb42 Remove lazy_static dependency 2024-05-31 07:39:15 -06:00
León Orell Valerian Liehr
a2c6f80a45 Rename HIR TypeBinding to AssocItemConstraint and related cleanup 2024-05-30 22:52:33 +02:00
Nilstrieb
28e43b6fb4 Use with_capacity in rewrite_path
It not only makes rustfmt faster, but also makes the code nicer imo.

performance:
```
Summary
  ./build/host/stage2/bin/rustfmt library/std/src/lib.rs --edition 2021 ran
    1.03 ± 0.02 times faster than ../rust3/build/host/stage2/bin/rustfmt library/std/src/lib.rs --edition 2021
```

Final string lengths when formatting `core`:
```
143144 counts
(  1)    23535 (16.4%, 16.4%): 4
(  2)    16138 (11.3%, 27.7%): 3
(  3)    15143 (10.6%, 38.3%): 5
(  4)    13477 ( 9.4%, 47.7%): 6
(  5)     9122 ( 6.4%, 54.1%): 7
(  6)     8715 ( 6.1%, 60.2%): 1
(  7)     6321 ( 4.4%, 64.6%): 8
(  8)     6178 ( 4.3%, 68.9%): 11
(  9)     5826 ( 4.1%, 73.0%): 2
( 10)     5168 ( 3.6%, 76.6%): 9
( 11)     4162 ( 2.9%, 79.5%): 10
( 12)     3555 ( 2.5%, 82.0%): 13
( 13)     3337 ( 2.3%, 84.3%): 14
( 14)     3017 ( 2.1%, 86.4%): 17
( 15)     2875 ( 2.0%, 88.4%): 12
( 16)     2345 ( 1.6%, 90.1%): 15
( 17)     1956 ( 1.4%, 91.4%): 16
( 18)     1946 ( 1.4%, 92.8%): 18
( 19)     1410 ( 1.0%, 93.8%): 19
( 20)     1187 ( 0.8%, 94.6%): 20
( 21)     1045 ( 0.7%, 95.3%): 22
( 22)     1042 ( 0.7%, 96.1%): 21
( 23)      792 ( 0.6%, 96.6%): 23
( 24)      649 ( 0.5%, 97.1%): 24
( 25)      619 ( 0.4%, 97.5%): 27
( 26)      569 ( 0.4%, 97.9%): 28
( 27)      540 ( 0.4%, 98.3%): 26
( 28)      460 ( 0.3%, 98.6%): 25
( 29)      328 ( 0.2%, 98.8%): 29
( 30)      243 ( 0.2%, 99.0%): 31
[...]
```
2024-05-28 09:31:47 -06:00
Santiago Pastorino
97bdbd96f1 Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
Vadim Petrochenkov
05a2db7624 delegation: Implement list delegation
```rust
reuse prefix::{a, b, c}
```
2024-05-15 02:32:59 +03:00
Matthias Krüger
2c7016776d Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb
Remove braces when fixing a nested use tree into a single item

[Back in 2019](https://github.com/rust-lang/rust/pull/56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
2024-05-08 23:33:24 +02:00
Guillaume Gomez
d5f1200ed6 Add documentation for negated ignored files and add a test for it as well 2024-05-01 10:53:06 -06:00
Matthias Krüger
27d320d1b6 Rollup merge of #124524 - spastorino:make-foreign-static-use-struct, r=oli-obk
Add StaticForeignItem and use it on ForeignItemKind

This is in preparation for unsafe extern blocks that adds a safe variant for functions inside extern blocks.

r? `@oli-obk`
cc `@compiler-errors`
2024-04-30 06:43:42 +02:00
Santiago Pastorino
fafa690716 Add StaticForeignItem and use it on ForeignItemKind 2024-04-29 13:15:51 -03:00
George Bateman
997d5f2bec Move rustfmt changes out
Now in https://github.com/rust-lang/rustfmt/pull/6154
2024-04-28 21:38:55 +01:00
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