about summary refs log tree commit diff
path: root/clippy_utils/src/ast_utils.rs
AgeCommit message (Collapse)AuthorLines
2023-12-28Merge commit 'ac4c2094a6030530661bee3876e0228ddfeb6b8b' into clippy-subtree-syncPhilipp Krones-0/+1
2023-12-22Auto merge of #118847 - eholk:for-await, r=compiler-errorsbors-3/+16
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-20Give `VariantData::Struct` named fields, to clairfy `recovered`.Alona Enraght-Moony-1/+3
2023-12-19Plumb awaitness of for loopsEric Holk-3/+16
2023-12-16Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyupPhilipp Krones-7/+10
2023-12-08Auto merge of #118420 - compiler-errors:async-gen, r=eholkbors-5/+6
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-08Make some matches exhaustive to avoid bugs, fix toolsMichael Goulet-1/+2
2023-12-08coro_kind -> coroutine_kindMichael Goulet-4/+4
2023-12-08Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errorsbors-1/+1
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-04Option<CoroutineKind>Eric Holk-2/+11
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-3/+3
2023-12-03Parse a pattern with no armNadrieril-1/+1
2023-10-27Add gen blocks to ast and do some broken ast loweringOli Scherer-1/+1
2023-09-11Update tools and fulldeps testsMatthew Jasper-1/+1
2023-08-11Merge commit '1e8fdf492808a25d78a97e1242b835ace9924e4d' into clippyupPhilipp Krones-1/+3
2023-08-04Improve spans for indexing expressionsNilstrieb-1/+1
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
2023-07-28Make Clippy understand generic const itemsLeón Orell Valerian Liehr-2/+6
2023-04-27Make clippy happyMichael Goulet-1/+1
2023-04-11Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyupPhilipp Krones-3/+36
2023-04-04Rename `ast::Static` to `ast::StaticItem` to match `ast::ConstItem`Oli Scherer-1/+1
2023-04-04box a bunch of large typesOli Scherer-3/+3
2023-04-04Split out ast::ItemKind::Const into its own structOli Scherer-2/+2
2023-04-04rust-analyzer guided tuple field to named fieldOli Scherer-1/+1
2023-04-04rust-analyzer guided enum variant structificationOli Scherer-1/+1
2023-03-19Remove the `NodeId` of `ast::ExprKind::Async`Arpad Borsos-1/+1
2023-03-12Remove `box_syntax` from AST and use in toolsclubby789-1/+1
2023-02-21Use `ThinVec` in various AST types.Nicholas Nethercote-1/+2
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
2022-12-28Rename `Rptr` to `Ref` in AST and HIRNilstrieb-1/+1
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-01rustc_ast_lowering: Stop lowering imports into multiple itemsVadim Petrochenkov-1/+1
Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-11-23Fix clippy codeEsteban Küber-1/+1
2022-11-22Auto merge of #104688 - flip1995:clippyup, r=Manishearth,flip1995bors-6/+14
Update Clippy r? `@Manishearth` Sorry for taking so long. There were so many blockers and so little time. This situation should be mitigated with #104007 in the future.
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-8/+12
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.
2022-11-21Merge commit 'f4850f7292efa33759b4f7f9b7621268979e9914' into clippyupPhilipp Krones-6/+14
2022-11-17Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote-5/+27
patterns.
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-1/+1
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-10-10Rename AssocItemKind::TyAlias to AssocItemKind::TypeMichael Goulet-2/+2
2022-08-16Shrink `ast::Attribute`.Nicholas Nethercote-1/+1
2022-08-10Do not consider method call receiver as an argument in AST.Camille GILLOT-1/+3
2022-07-18Merge commit 'fdb84cbfd25908df5683f8f62388f663d9260e39' into clippyupPhilipp Krones-4/+10
2022-07-12Fix clippy buildMaybe Waffle-2/+11
2022-07-02ast: Add span to `Extern`Nixon Enraght-Moony-2/+2
2022-05-23Rollup merge of #97254 - jhpratt:remove-crate-vis, r=cjgillotDylan DPC-1/+1
Remove feature: `crate` visibility modifier FCP completed in #53120.
2022-05-21Merge crate and restricted visibilitiesJacob Pratt-1/+1
2022-05-21Remove feature: `crate` visibility modifierJacob Pratt-1/+1
2022-05-21Merge 'rust-clippy/master' into clippyupxFrednet-1/+1
2022-05-05Overhaul `MacArgs::Eq`.Nicholas Nethercote-1/+2
The value in `MacArgs::Eq` is currently represented as a `Token`. Because of `TokenKind::Interpolated`, `Token` can be either a token or an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a literal or macro call AST fragment, and then is later lowered to a literal token. But this is very non-obvious. `Token` is a much more general type than what is needed. This commit restricts things, by introducing a new type `MacArgsEqKind` that is either an AST expression (pre-lowering) or an AST literal (post-lowering). The downside is that the code is a bit more verbose in a few places. The benefit is that makes it much clearer what the possibilities are (though also shorter in some other places). Also, it removes one use of `TokenKind::Interpolated`, taking us a step closer to removing that variant, which will let us make `Token` impl `Copy` and remove many "handle Interpolated" code paths in the parser. Things to note: - Error messages have improved. Messages like this: ``` unexpected token: `"bug" + "found"` ``` now say "unexpected expression", which makes more sense. Although arbitrary expressions can exist within tokens thanks to `TokenKind::Interpolated`, that's not obvious to anyone who doesn't know compiler internals. - In `parse_mac_args_common`, we no longer need to collect tokens for the value expression.
2022-03-14Merge commit 'dc5423ad448877e33cca28db2f1445c9c4473c75' into clippyupflip1995-6/+48
2022-03-05Change syntax for TyAlias where clausesJack Huey-42/+6
2022-01-27Merge commit 'a98e7ab8b94485be6bd03e0c6b8682ecab5b52e6' into clippyupflip1995-5/+5
2022-01-17Add termkadmin-2/+9
Instead of having a separate enum variant for types and consts have one but have either a const or type.