about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2024-08-04don't suggest turning crate-level attributes into outer styleyukang-12/+31
2024-08-03Rollup merge of #128483 - nnethercote:still-more-cfg-cleanups, r=petrochenkovMatthias Krüger-152/+168
Still more `cfg` cleanups Found while looking closely at `cfg`/`cfg_attr` processing code. r? `````````@petrochenkov`````````
2024-08-01Rollup merge of #128496 - clubby789:box-syntax-multipart, r=compiler-errorsMatthias Krüger-11/+22
Fix removed `box_syntax` diagnostic if source isn't available Fix #128442
2024-08-01Fix removed `box_syntax` diagnostic if source isn't availableclubby789-11/+22
2024-08-01Auto merge of #127543 - carbotaniuman:more_unsafe_attr_verification, ↵bors-60/+110
r=estebank,traviscross More unsafe attr verification This code denies unsafe on attributes such as `#[test]` and `#[ignore]`, while also changing the `MetaItem` parsing so `unsafe` in args like `#[allow(unsafe(dead_code))]` is not accidentally allowed. Tracking: - https://github.com/rust-lang/rust/issues/123757
2024-08-01Distinguish the two kinds of token range.Nicholas Nethercote-77/+123
When collecting tokens there are two kinds of range: - a range relative to the parser's full token stream (which we get when we are parsing); - a range relative to a single AST node's token stream (which we use within `LazyAttrTokenStreamImpl` when replacing tokens). These are currently both represented with `Range<u32>` and it's easy to mix them up -- until now I hadn't properly understood the difference. This commit introduces `ParserRange` and `NodeRange` to distinguish them. This also requires splitting `ReplaceRange` in two, giving the new types `ParserReplacement` and `NodeReplacement`. (These latter two names reduce the overloading of the word "range".) The commit also rewrites some comments to be clearer. The end result is a little more verbose, but much clearer.
2024-08-01Move a comment to a better spot.Nicholas Nethercote-2/+1
2024-08-01Streamline attribute stitching on AST nodes.Nicholas Nethercote-15/+10
It can be done more concisely.
2024-07-31Rollup merge of #126697 - vincenzopalazzo:macros/find_the_expression_tok, ↵Matthias Krüger-1/+10
r=eholk,compiler-errors [RFC] mbe: consider the `_` in 2024 an expression This commit is adding the possibility to parse the `_` as an expression inside the esition 2024. Link: https://rust-lang.zulipchat.com/#narrow/stream/404510-wg-macros/topic/supporting.20.60_.60.20expressions Issue https://github.com/rust-lang/rust/issues/123742 r? `@eholk`
2024-07-31tweak comment on `NonterminalKind::Expr`Michael Goulet-1/+1
Co-authored-by: Eric Holk <eric@theincredibleholk.org>
2024-07-31rustc_parser: consider the in 2024 an expressionVincenzo Palazzo-1/+10
This commit is adding the possibility to parse the `_` as an expression inside the esition 2024. Link: https://rust-lang.zulipchat.com/#narrow/stream/404510-wg-macros/topic/supporting.20.60_.60.20expressions Co-authored-by: Eric Holk <eric@theincredibleholk.org> Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-07-31Remove `LhsExpr`.Nicholas Nethercote-42/+28
`parse_expr_assoc_with` has an awkward structure -- sometimes the lhs is already parsed. This commit splits the post-lhs part into a new method `parse_expr_assoc_rest_with`, which makes everything shorter and simpler.
2024-07-31Inline and remove `parse_local_mk`.Nicholas Nethercote-16/+6
It has a single use. This makes the `let` handling case in `parse_stmt_without_recovery` more similar to the statement path and statement expression cases.
2024-07-30Add toggle for `parse_meta_item` unsafe parsingcarbotaniuman-45/+59
This makes it possible for the `unsafe(...)` syntax to only be valid at the top level, and the `NestedMetaItem`s will automatically reject `unsafe(...)`.
2024-07-30Rollup merge of #128376 - compiler-errors:finish-ur-vegetables, r=jieyouxuMatthias Krüger-11/+26
Mark `Parser::eat`/`check` methods as `#[must_use]` These methods return a `bool`, but we probably should either use these values or explicitly throw them away (e.g. when we just want to unconditionally eat a token if it exists). I changed a few places from `eat` to `expect`, but otherwise I tried to leave a comment explaining why the `eat` was okay. This also adds a test for the `pattern_type!` macro, which used to silently accept a missing `is` token.
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-6/+1
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-30Auto merge of #127955 - ↵bors-3/+18
chenyukang:yukang-fix-mismatched-delimiter-issue-12786, r=nnethercote Add limit for unclosed delimiters in lexer diagnostic Fixes #127868 The first commit shows the original diagnostic, and the second commit shows the changes.
2024-07-29Deny unsafe on more builtin attributescarbotaniuman-56/+92
2024-07-29Mark Parser::eat/check methods as must_useMichael Goulet-11/+26
2024-07-29Reformat `use` declarations.Nicholas Nethercote-176/+185
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28step cfg(bootstrap)Mark Rousskov-6/+1
2024-07-27Rollup merge of #128207 - folkertdev:asm-parser-generalize, r=AmanieuTrevor Gross-2/+5
improve error message when `global_asm!` uses `asm!` options specifically, what was error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags` --> $DIR/bad-options.rs:45:25 | LL | global_asm!("", options(preserves_flags)); | ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` is now error: the `preserves_flags` option cannot be used with `global_asm!` --> $DIR/bad-options.rs:45:25 | LL | global_asm!("", options(preserves_flags)); | ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly mirroring the phrasing of the [reference](https://doc.rust-lang.org/reference/inline-assembly.html#options). This is also a bit of a refactor for a future `naked_asm!` macro (for use in `#[naked]` functions). Currently this sort of error can come up when switching from inline to global asm, or when a user just isn't that experienced with assembly. With `naked_asm!` added to the mix hitting this error is more likely.
2024-07-26Rollup merge of #128229 - tdittr:unsafe-extern-abi-error, r=compiler-errorsTrevor Gross-3/+6
Improve `extern "<abi>" unsafe fn()` error message These errors were already reported in #87217, and fixed by #87235 but missed the case of an explicit ABI. This PR does not cover multiple keywords like `extern "C" pub const unsafe fn()`, but I don't know what a good way to cover this would be. It also seems rarer than `extern "C" unsafe` which I saw happen a few times in workshops.
2024-07-26Rollup merge of #128224 - nnethercote:fewer-replace_ranges, r=petrochenkovTrevor Gross-25/+21
Remove unnecessary range replacements This PR removes an unnecessary range replacement in `collect_tokens_trailing_token`, and does a couple of other small cleanups. r? ````@petrochenkov````
2024-07-26Rollup merge of #128223 - nnethercote:refactor-collect_tokens, r=petrochenkovTrevor Gross-45/+43
Refactor complex conditions in `collect_tokens_trailing_token` More readability improvements for this complicated function. r? ````@petrochenkov````
2024-07-26Improve error message for `extern "C" unsafe fn()`Tamme Dittrich-3/+6
This was handled correctly already for `extern unsafe fn()`. Co-authored-by: Folkert <folkert@folkertdev.nl>
2024-07-26Remove an unnecessary block.Nicholas Nethercote-11/+9
2024-07-26Tweak a loop.Nicholas Nethercote-5/+7
A fully imperative style is easier to read than a half-iterator, half-imperative style. Also, rename `inner_attr` as `attr` because it might be an outer attribute.
2024-07-26Fix a comment.Nicholas Nethercote-3/+3
Imagine you have replace ranges (2..20,X) and (5..15,Y), and these tokens: ``` a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x ``` If we replace (5..15,Y) first, then (2..20,X) we get this sequence ``` a,b,c,d,e,Y,_,_,_,_,_,_,_,_,_,p,q,r,s,t,u,v,w,x a,b,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,u,v,w,x ``` which is what we want. If we do it in the other order, we get this: ``` a,b,X,_,_,_,_,_,_,_,_,_,_,_,_,p,q,r,s,t,u,v,w,x a,b,X,_,_,Y,_,_,_,_,_,_,_,_,_,_,_,_,_,_,u,v,w,x ``` which is wrong. So it's true that we need the `.rev()` but the comment is wrong about why.
2024-07-26Don't include inner attribute ranges in `CaptureState`.Nicholas Nethercote-6/+2
The current code is this: ``` self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target))); self.capture_state.replace_ranges.extend(inner_attr_replace_ranges); ``` What's not obvious is that every range in `inner_attr_replace_ranges` must be a strict sub-range of `start_pos..end_pos`. Which means, in `LazyAttrTokenStreamImpl::to_attr_token_stream`, they will be done first, and then the `start_pos..end_pos` replacement will just overwrite them. So they aren't needed.
2024-07-26Invert the sense of `is_complete` and rename it as `needs_tokens`.Nicholas Nethercote-11/+13
I have always found `is_complete` an unhelpful name. The new name (and inverted sense) fits in better with the conditions at its call sites.
2024-07-26Move `is_complete` to the module that uses it.Nicholas Nethercote-13/+13
And make it non-`pub`.
2024-07-26Inline and remove `AttrWrapper::is_complete`.Nicholas Nethercote-8/+4
It has a single call site. This change makes the two `needs_collect` conditions more similar to each other, and therefore easier to understand.
2024-07-26Invert early exit conditions in `collect_tokens_trailing_token`.Nicholas Nethercote-29/+29
This has been bugging me for a while. I find complex "if any of these are true" conditions easier to think about than complex "if all of these are true" conditions, because you can stop as soon as one is true.
2024-07-25improve error message when `global_asm!` uses `asm!` optionsFolkert-2/+5
2024-07-25Fix a span error when parsing a wrong param of function.surechen-1/+8
fixes #128042
2024-07-25add limit for unclosed delimiters in lexer diagnosticyukang-3/+18
2024-07-25Rollup merge of #127054 - compiler-errors:bound-ordering, r=fmeaseMatthias Krüger-3/+87
Reorder trait bound modifiers *after* `for<...>` binder in trait bounds This PR suggests changing the grammar of trait bounds from: ``` [CONSTNESS] [ASYNCNESS] [?] [BINDER] [TRAIT_PATH] const async ? for<'a> Sized ``` to ``` ([BINDER] [CONSTNESS] [ASYNCNESS] | [?]) [TRAIT_PATH] ``` i.e., either ``` ? Sized ``` or ``` for<'a> const async Sized ``` (but not both) ### Why? I think it's strange that the binder applies "more tightly" than the `?` trait polarity. This becomes even weirder when considering that we (or at least, I) want to have `async` trait bounds expressed like: ``` where T: for<'a> async Fn(&'a ()) -> i32, ``` and not: ``` where T: async for<'a> Fn(&'a ()) -> i32, ``` ### Fallout No crates on crater use this syntax, presumably because it's literally useless. This will require modifying the reference grammar, though. ### Alternatives If this is not desirable, then we can alternatively keep parsing `for<'a>` after the `?` but deprecate it with either an FCW (or an immediate hard error), and begin parsing `for<'a>` *before* the `?`.
2024-07-25Apply suggestions from code reviewLeón Orell Valerian Liehr-2/+6
2024-07-23Stabilize unsafe extern blocks (RFC 3484)Santiago Pastorino-3/+0
2024-07-22Always pass the visitor as the first argument to walk* functionsOli Scherer-6/+6
2024-07-22Sync `mut_visit` function names with immut `visit` ones (s/noop_visit/walk/)Oli Scherer-8/+8
2024-07-19Auto merge of #127957 - matthiaskrgr:rollup-1u5ivck, r=matthiaskrgrbors-75/+159
Rollup of 6 pull requests Successful merges: - #127350 (Parser: Suggest Placing the Return Type After Function Parameters) - #127621 (Rewrite and rename `issue-22131` and `issue-26006` `run-make` tests to rmake) - #127662 (When finding item gated behind a `cfg` flag, point at it) - #127903 (`force_collect` improvements) - #127932 (rustdoc: fix `current` class on sidebar modnav) - #127943 (Don't allow unsafe statics outside of extern blocks) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-19Rollup merge of #127903 - nnethercote:force_collect-improvements, r=petrochenkovMatthias Krüger-36/+38
`force_collect` improvements Yet more cleanups relating to `cfg_attr` processing. r? ````@petrochenkov````
2024-07-19Rollup merge of #127350 - veera-sivarajan:bugfix-126311, r=lcnrMatthias Krüger-39/+121
Parser: Suggest Placing the Return Type After Function Parameters Fixes #126311 This PR suggests placing the return type after the function parameters when it's misplaced after a `where` clause. This also tangentially improves diagnostics for cases like [this](https://github.com/veera-sivarajan/rust/blob/86d6f1312a77997ef994240e716288d61a343a6d/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.rs#L1C1-L1C28) and adds doc comments for `parser::AllowPlus`.
2024-07-19Overhaul comments in `collect_tokens_trailing_token`.Nicholas Nethercote-75/+129
Adding details, clarifying lots of little things, etc. In particular, the commit adds details of an example. I find this very helpful, because it's taken me a long time to understand how this code works.
2024-07-19Make `Parser::num_bump_calls` 0-indexed.Nicholas Nethercote-6/+11
Currently in `collect_tokens_trailing_token`, `start_pos` and `end_pos` are 1-indexed by `replace_ranges` is 0-indexed, which is really confusing. Making them both 0-indexed makes debugging much easier.
2024-07-19Move `inner_attr` code downwards.Nicholas Nethercote-10/+10
This puts it just before the `replace_ranges` initialization, which makes sense because the two variables are closely related.
2024-07-19Remove `final_attrs` local variable.Nicholas Nethercote-4/+2
It's no shorter than `ret.attrs()`, and `ret.attrs()` is used multiple times earlier in the function.
2024-07-19Simplify `CaptureState::inner_attr_ranges`.Nicholas Nethercote-5/+5
The `Option`s within the `ReplaceRange`s within the hashmap are always `None`. This PR omits them and inserts them when they are extracted from the hashmap.