about summary refs log tree commit diff
path: root/src/tools/rustfmt
AgeCommit message (Collapse)AuthorLines
2025-01-28Refactor FnKind variant to hold &FnCelina G. Val-11/+21
2025-01-09Only treat plain literal patterns as shortOli Scherer-12/+43
2025-01-08Rename PatKind::Lit to ExprOli Scherer-3/+3
2025-01-07rustfmt: drop nightly-gating of the `--style-edition` flag registration许杰友 Jieyou Xu (Joe)-6/+6
2024-12-31Stabilize style_edition 2024 in-treeMichael Goulet-10/+6
2024-12-22Make sure we don't lose default struct value when formatting structMichael Goulet-0/+42
2024-12-19Speed up `Parser::expected_token_types`.Nicholas Nethercote-16/+17
The parser pushes a `TokenType` to `Parser::expected_token_types` on every call to the various `check`/`eat` methods, and clears it on every call to `bump`. Some of those `TokenType` values are full tokens that require cloning and dropping. This is a *lot* of work for something that is only used in error messages and it accounts for a significant fraction of parsing execution time. This commit overhauls `TokenType` so that `Parser::expected_token_types` can be implemented as a bitset. This requires changing `TokenType` to a C-style parameterless enum, and adding `TokenTypeSet` which uses a `u128` for the bits. (The new `TokenType` has 105 variants.) The new types `ExpTokenPair` and `ExpKeywordPair` are now arguments to the `check`/`eat` methods. This is for maximum speed. The elements in the pairs are always statically known; e.g. a `token::BinOp(token::Star)` is always paired with a `TokenType::Star`. So we now compute `TokenType`s in advance and pass them in to `check`/`eat` rather than the current approach of constructing them on insertion into `expected_token_types`. Values of these pair types can be produced by the new `exp!` macro, which is used at every `check`/`eat` call site. The macro is for convenience, allowing any pair to be generated from a single identifier. The ident/keyword filtering in `expected_one_of_not_found` is no longer necessary. It was there to account for some sloppiness in `TokenKind`/`TokenType` comparisons. The existing `TokenType` is moved to a new file `token_type.rs`, and all its new infrastructure is added to that file. There is more boilerplate code than I would like, but I can't see how to make it shorter.
2024-12-18Rollup merge of #134253 - nnethercote:overhaul-keywords, r=petrochenkov许杰友 Jieyou Xu (Joe)-75/+12
Overhaul keyword handling The compiler's list of keywords has some problems. - It contains several items that aren't keywords. - The order isn't quite right in a couple of places. - Some of the names of predicates relating to keywords are confusing. - rustdoc and rustfmt have their own (incorrect) versions of the keyword list. - `AllKeywords` is unnecessarily complex. r? ```@jieyouxu```
2024-12-18Only have one source of truth for keywords.Nicholas Nethercote-75/+12
`rustc_symbol` is the source of truth for keywords. rustdoc has its own implicit definition of keywords, via the `is_doc_keyword`. It (presumably) intends to include all keywords, but it omits `yeet`. rustfmt has its own explicit list of Rust keywords. It also (presumably) intends to include all keywords, but it omits `await`, `builtin`, `gen`, `macro_rules`, `raw`, `reuse`, `safe`, and `yeet`. Also, it does linear searches through this list, which is inefficient. This commit fixes all of the above problems by introducing a new predicate `is_any_keyword` in rustc and using it in rustdoc and rustfmt. It documents that it's not the right predicate in most cases.
2024-12-18Rename `RefTokenTreeCursor`.Nicholas Nethercote-15/+15
Because `TokenStreamIter` is a much better name for a `TokenStream` iterator. Also rename the `TokenStream::trees` method as `TokenStream::iter`, and some local variables.
2024-12-18Simplify `RefTokenTreeCursor::look_ahead`.Nicholas Nethercote-2/+2
It's only ever used with a lookahead of 0, so this commit removes the lookahead and renames it `peek`.
2024-12-18Change the lookahead in `MacroParser::new`.Nicholas Nethercote-1/+1
As it happens, lookahead values of 0, 1, and 2 all work fine here, due to the structure of the code. (Values or 3 or greater cause test failures.) This commit changes the lookahead to zero because that will facilitate cleanups in subsequent commits.
2024-12-13Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obkMatthias Krüger-1/+48
Add AST support for unsafe binders I'm splitting up #130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later. r? `@oli-obk` cc `@BoxyUwU` and `@lcnr` who also may want to look at this, though this PR doesn't do too much yet
2024-12-12Fix toolsMichael Goulet-1/+48
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-6/+5
involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
2024-12-09Auto merge of #134052 - matthiaskrgr:rollup-puxwqrk, r=matthiaskrgrbors-12/+17
Rollup of 7 pull requests Successful merges: - #133567 (A bunch of cleanups) - #133789 (Add doc alias 'then_with' for `then` method on `bool`) - #133880 (Expand home_dir docs) - #134036 (crash tests: use individual mir opts instead of mir-opt-level where easily possible) - #134045 (Fix some triagebot mentions paths) - #134046 (Remove ignored tests for hangs w/ new solver) - #134050 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-08Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-deadMatthias Krüger-2/+16
Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](https://github.com/rust-lang/rust/issues/129967)). This PR is extracted from https://github.com/rust-lang/rust/pull/129996 with minor modifications. cc `@max-niederman`
2024-12-06Store a single copy of the error registry in DiagCtxtbjorn3-12/+17
And pass this to the individual emitters when necessary.
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-11/+6
2024-11-24Fix rustfmt according to reviewNadrieril-2/+14
2024-11-24cover guard patterns in rustfmtMax Niederman-1/+3
2024-11-21Implement the unsafe-fields RFC.Luca Versari-3/+30
Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
2024-11-21Introduce `InvisibleOrigin` on invisible delimiters.Nicholas Nethercote-1/+1
It's not used meaningfully yet, but will be needed to get rid of interpolated tokens.
2024-11-15Make Visitor::FnKind and MutVisitor::FnKind compatiblemaxcabrajac-21/+7
2024-11-02Do not format generic constsMichael Goulet-6/+46
2024-10-15Rewrite for<..> async correctlyMichael Goulet-23/+29
2024-10-15Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgrbors-8/+6
Rollup of 9 pull requests Successful merges: - #122670 (Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode) - #131095 (Use environment variables instead of command line arguments for merged doctests) - #131339 (Expand set_ptr_value / with_metadata_of docs) - #131652 (Move polarity into `PolyTraitRef` rather than storing it on the side) - #131675 (Update lint message for ABI not supported) - #131681 (Fix up-to-date checking for run-make tests) - #131702 (Suppress import errors for traits that couldve applied for method lookup error) - #131703 (Resolved python deprecation warning in publish_toolstate.py) - #131710 (Remove `'apostrophes'` from `rustc_parse_format`) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-15Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errorsMatthias Krüger-4/+31
Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new. Tracking: - #130494 r? `@compiler-errors`
2024-10-14Move trait bound modifiers into ast::PolyTraitRefMichael Goulet-8/+6
2024-10-11Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiserbors-33/+0
Retire the `unnamed_fields` feature for now `#![feature(unnamed_fields)]` was implemented in part in #115131 and #115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature. However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly. Fixes #117942 Fixes #121161 Fixes #121263 Fixes #121299 Fixes #121722 Fixes #121799 Fixes #126969 Fixes #131041 Tracking: * https://github.com/rust-lang/rust/issues/49804 [^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields [^2]: https://github.com/rust-lang/rust/issues/49804#issuecomment-1972619108
2024-10-07Add basic pin sugar support to rustfmtEric Holk-1/+26
2024-10-07Fix clippy and rustfmt compilationEric Holk-5/+6
2024-10-07Add sugar for &pin (const|mut) typesEric Holk-2/+3
2024-10-07Auto merge of #131354 - matthiaskrgr:rollup-hprnng2, r=matthiaskrgrbors-4/+4
Rollup of 4 pull requests Successful merges: - #131331 (Revert "warn_old_master_branch" check) - #131344 (Avoid `&Lrc<T>` in various places) - #131346 (Restrict `ignore-mode-*` directives) - #131353 (Add documentation for `runtest::check_rustdoc_test_option` method) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-07Rollup merge of #131344 - nnethercote:ref-Lrc, r=compiler-errorsMatthias Krüger-4/+4
Avoid `&Lrc<T>` in various places Seeing `&Lrc<T>` is a bit suspicious, and `&T` or `Lrc<T>` is often better. r? `@oli-obk`
2024-10-07Auto merge of #131235 - ↵bors-31/+27
codemountains:rename-nestedmetaitem-to-metaitemlnner, r=nnethercote Rename `NestedMetaItem` to `MetaItemInner` Fixes #131087 r? `@nnethercote`
2024-10-07Rename nested_meta to meta_item_innercodemountains-8/+7
2024-10-07Convert `Option<&Lrc<T>>` return types to `Option<&T>`.Nicholas Nethercote-4/+4
It's simpler and more concise.
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-1/+1
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-10-06disallow `asm!` in `#[naked]` functionsFolkert de Vries-2/+2
also disallow the `noreturn` option, and infer `naked_asm!` as `!`
2024-10-06implement `naked_asm` macroFolkert-2/+2
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-27/+24
2024-10-01Remove anon struct and union typesMichael Goulet-33/+0
2024-09-19Merge commit 'b23b69900eab1260be510b2bd8922f4b6de6cf1e' into sync-from-rustfmtYacin Tmimi-1556/+4708
2024-09-06Fix toolsMichael Goulet-9/+26
2024-08-30Remove `#[macro_use] extern crate tracing` from rustfmt.Nicholas Nethercote-2/+17
2024-08-30Remove `#[macro_use] extern crate tracing` from rustfmt helpers.Nicholas Nethercote-6/+2
2024-08-17Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercotebors-1/+0
Stabilize `unsafe_attributes` # Stabilization report ## Summary This is a tracking issue for the RFC 3325: unsafe attributes We are stabilizing `#![feature(unsafe_attributes)]`, which makes certain attributes considered 'unsafe', meaning that they must be surrounded by an `unsafe(...)`, as in `#[unsafe(no_mangle)]`. RFC: rust-lang/rfcs#3325 Tracking issue: #123757 ## What is stabilized ### Summary of stabilization Certain attributes will now be designated as unsafe attributes, namely, `no_mangle`, `export_name`, and `link_section` (stable only), and these attributes will need to be called by surrounding them in `unsafe(...)` syntax. On editions prior to 2024, this is simply an edition lint, but it will become a hard error in 2024. This also works in `cfg_attr`, but `unsafe` is not allowed for any other attributes, including proc-macros ones. ```rust #[unsafe(no_mangle)] fn a() {} #[cfg_attr(any(), unsafe(export_name = "c"))] fn b() {} ``` For a table showing the attributes that were considered to be included in the list to require unsafe, and subsequent reasoning about why each such attribute was or was not included, see [this comment here](https://github.com/rust-lang/rust/pull/124214#issuecomment-2124753464) ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-attributes` and `tests/ui/attributes/unsafe`.
2024-08-14Use `impl PartialEq<TokenKind> for Token` more.Nicholas Nethercote-5/+3
This lets us compare a `Token` with a `TokenKind`. It's used a lot, but can be used even more, avoiding the need for some `.kind` uses.
2024-08-11Link `std` statically in `rustc_driver`John Kåre Alsaker-0/+4