about summary refs log tree commit diff
path: root/compiler/rustc_ast/src
AgeCommit message (Collapse)AuthorLines
2022-05-05Overhaul `MacArgs::Eq`.Nicholas Nethercote-30/+86
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-05-04Auto merge of #96683 - nnethercote:speed-up-Token-ident-lifetime, r=petrochenkovbors-7/+17
Speed up `Token::{ident,lifetime}` Some speed and cleanliness improvements. r? `@petrochenkov`
2022-05-04Show invisible delimeters (within comments) when pretty printing.Nicholas Nethercote-2/+3
2022-05-04Remove unnecessary `NtIdent` in `Token::is_whole_expr`.Nicholas Nethercote-1/+1
The comment on this function explains that it's a specialized version of `maybe_whole_expr`. But `maybe_whole_expr` doesn't do anything with `NtIdent`, so `is_whole_expr` also doesn't need to.
2022-05-04Speed up `Token::{ident,lifetime}`.Nicholas Nethercote-6/+16
They're hot enough that the repeated matching done by `uninterpolate` has a measurable effect.
2022-05-02fix most compiler/ doctestsElliot Roberts-1/+1
2022-04-30Add `do yeet` expressions to allow experimentation in nightlyScott McMurray-1/+14
Using an obviously-placeholder syntax. An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point. But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-30Save colon span to suggest bounds.Camille GILLOT-1/+5
2022-04-29Remove the `T::VISIT_TOKENS` test in `visit_mac_args`.Nicholas Nethercote-11/+7
The two paths are equivalent -- they both end up calling `visit_expr()`. I have kept the more restrictive path, the one that requires that `token` be an expression nonterminal. (The next commit will simplify this function further.)
2022-04-29Rename `visit_interpolated` as `visit_nonterminal`.Nicholas Nethercote-2/+2
Because `Nonterminal` is the type it visits.
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-38/+45
2022-04-27Avoid producing `NoDelim` values in `MacArgs::delim()`.Nicholas Nethercote-3/+3
2022-04-25Auto merge of #96246 - SparrowLii:bound_contxet, r=compiler-errorsbors-12/+34
Add `BoundKind` in `visit_param_bounds` to check questions in bounds From the FIXME in the impl of `AstValidator`. Better bound checks by adding `BoundCtxt` type parameter to `visit_param_bound` cc `@ecstatic-morse`
2022-04-21Auto merge of #96210 - nnethercote:speed-up-TokenCursor, r=petrochenkovbors-15/+12
Speed up `TokenCursor` Plus a few related clean-ups. r? `@petrochenkov`
2022-04-21Introduced `Cursor::next_with_spacing_ref`.Nicholas Nethercote-0/+8
This lets us clone just the parts within a `TokenTree` that need cloning, rather than the entire thing. This is a surprisingly large performance win, up to 4% on `async-std-1.10.0`.
2022-04-21rename to `BoundKind` and add commentsSparrowLii-14/+26
2022-04-20Add `BoundCtxt` in `visit_param_bounds` to check questions in boundsSparrowLii-12/+22
2022-04-20Inline `Cursor::next_with_spacing`.Nicholas Nethercote-0/+1
2022-04-19rustc_metadata: Store a flag telling whether an item may have doc links in ↵Vadim Petrochenkov-0/+13
its attributes This should be cheap on rustc side, but it's significant optimization for rustdoc that won't need to decode and process attributes unnecessarily
2022-04-19Inline and remove `TokenTree::{open_tt,close_tt}`.Nicholas Nethercote-10/+0
They both have a single call site.
2022-04-19Tweak `Cursor::next_with_spacing`.Nicholas Nethercote-5/+3
This makes it more like `CursorRef::next_with_spacing`. There is no performance effect, just a consistency improvement.
2022-04-17Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkovbors-10/+9
Report undeclared lifetimes during late resolution. First step in https://github.com/rust-lang/rust/pull/91557 We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes. r? `@petrochenkov`
2022-04-17Auto merge of #96016 - Aaron1011:hash-name-cleanup, r=cjgillotbors-2/+2
Remove last vestiges of skippng ident span hashing This removes a comment that no longer applies, and properly hashes the full ident for path segments.
2022-04-17Visit generics inside visit_fn.Camille GILLOT-10/+9
2022-04-16Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisabors-10/+54
Implement sym operands for global_asm! Tracking issue: #93333 This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are: - At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`. - At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails). - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`. - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to. - The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression. - At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details. - On Mach-O, all symbols have a leading underscore. - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall. - No mangling is needed on other platforms. r? `@nagisa` cc `@eddyb`
2022-04-15Rollup merge of #94461 - jhpratt:2024-edition, r=pnkfelixDylan DPC-1/+1
Create (unstable) 2024 edition [On Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Deprecating.20macro.20scoping.20shenanigans/near/272860652), there was a small aside regarding creating the 2024 edition now as opposed to later. There was a reasonable amount of support and no stated opposition. This change creates the 2024 edition in the compiler and creates a prelude for the 2024 edition. There is no current difference between the 2021 and 2024 editions. Cargo and other tools will need to be updated separately, as it's not in the same repository. This change permits the vast majority of work towards the next edition to proceed _now_ instead of waiting until 2024. For sanity purposes, I've merged the "hello" UI tests into a single file with multiple revisions. Otherwise we'd end up with a file per edition, despite them being essentially identical. ````@rustbot```` label +T-lang +S-waiting-on-review Not sure on the relevant team, to be honest.
2022-04-14Reimplement lowering of sym operands for asm! so that it also works with ↵Amanieu d'Antras-10/+54
global_asm!
2022-04-13Remove last vestiges of skippng ident span hashingAaron Hill-2/+2
This removes a comment that no longer applies, and properly hashes the full ident for path segments.
2022-04-11Use const Box::default in P::<[T]>::newJosh Stone-8/+3
2022-04-10better error for binder on associated type boundMichael Goulet-1/+1
2022-04-08Fix invalid array access in `beautify_doc_string`Guillaume Gomez-1/+4
2022-04-07Shrink `Nonterminal`.Nicholas Nethercote-6/+8
By heap allocating the argument within `NtPath`, `NtVis`, and `NtStmt`. This slightly reduces cumulative and peak allocation amounts, most notably on `deep-vector`.
2022-04-02Create 2024 editionJacob Pratt-1/+1
2022-03-31Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errorsDylan DPC-1/+1
Spellchecking compiler comments This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-31Rollup merge of #95251 - GrishaVar:hashes-u16-to-u8, r=dtolnayDylan DPC-3/+3
Reduce max hash in raw strings from u16 to u8 [Relevant discussion](https://rust-lang.zulipchat.com/#narrow/stream/237824-t-lang.2Fdoc/topic/Max.20raw.20string.20delimiters)
2022-03-30Spellchecking compiler commentsYuri Astrakhan-1/+1
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-28Remove `Nonterminal::NtTT`.Nicholas Nethercote-9/+1
It's only needed for macro expansion, not as a general element in the AST. This commit removes it, adds `NtOrTt` for the parser and macro expansion cases, and renames the variants in `NamedMatch` to better match the new type.
2022-03-23Update syntax tree definitionGrisha Vartanyan-3/+3
2022-03-15Auto merge of #94584 - pnkfelix:inject-use-suggestion-sites, r=ekuberbors-6/+23
More robust fallback for `use` suggestion Our old way to suggest where to add `use`s would first look for pre-existing `use`s in the relevant crate/module, and if there are *no* uses, it would fallback on trying to use another item as the basis for the suggestion. But this was fragile, as illustrated in issue #87613 This PR instead identifies span of the first token after any inner attributes, and uses *that* as the fallback for the `use` suggestion. Fix #87613
2022-03-09Implement macro meta-variable expressionsCaio-1/+1
2022-03-05IgnoreJack Huey-2/+2
2022-03-05Add commment covering the case with no where clauseJack Huey-0/+2
2022-03-05Review changesJack Huey-0/+12
2022-03-05Change syntax for TyAlias where clausesJack Huey-6/+41
2022-03-03Adjusted diagnostic output so that if there is no `use` in a item sequence,Felix S. Klock II-4/+7
then we just suggest the first legal position where you could inject a use. To do this, I added `inject_use_span` field to `ModSpans`, and populate it in parser (it is the span of the first token found after inner attributes, if any). Then I rewrote the use-suggestion code to utilize it, and threw out some stuff that is now unnecessary with this in place. (I think the result is easier to understand.) Then I added a test of issue 87613.
2022-03-03Associate multiple with a crate too.Felix S. Klock II-4/+5
2022-03-03refactor: prepare to associate multiple spans with a module.Felix S. Klock II-2/+15
2022-02-262 - Make more use of let_chainsCaio-59/+53
Continuation of #94376. cc #53667
2022-02-24Rollup merge of #94316 - nnethercote:improve-string-literal-unescaping, ↵Dylan DPC-17/+23
r=petrochenkov Improve string literal unescaping Some easy wins that affect a few popular crates. r? ```@matklad```
2022-02-24Rollup merge of #94288 - Mark-Simulacrum:ser-opt, r=nnethercoteMatthias Krüger-2/+1
Cleanup a few Decoder methods This is just some simple follow up to #93839. r? `@nnethercote`