Lukas Wirth
90499d4390
Use boxed slices instead ovecs in decl macros
2023-05-02 17:04:53 +02:00
Lukas Wirth
d1ca505525
fix: Fix pat fragment handling in 2021 edition
2023-04-24 22:21:37 +02:00
Jake Heinz
a497e9a05e
mbe: fix token conversion for doc comments
2023-04-22 03:06:06 +00:00
bors
2400b36a2e
Auto merge of #14577 - jsoref:spelling, r=lnicola
...
Spelling
This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling ).
The misspellings have been reported at https://github.com/jsoref/rust-analyzer/actions/runs/4699991040#summary-12751355796
The action reports that the changes in this PR would make it happy: https://github.com/jsoref/rust-analyzer/actions/runs/4699991284#summary-12751356293
closes #14567
2023-04-19 14:05:40 +00:00
Josh Soref
bc7d84c3ce
Spelling
...
* a rule
* access
* after
* amount
* annotations
* assignment
* assist
* associated
* attribute
* borrowed
* built-in type
* clarification
* command
* const
* constructor
* corresponding
* counterparts
* curlies
* dependencies
* deterministic
* diagnostic
* duplicates
* edge
* edited
* efficient
* elsewhere
* execution
* expression
* extensions
* extracted
* fill
* github
* helper
* heuristic
* incomplete
* indent end
* inlay
* invocation
* lifetime
* looking
* maybe
* move
* mutability
* mutable
* necessarily
* necessary
* negative
* nonexistent
* occurred
* offsets
* offsetted
* overridden
* parameters
* params
* params_and_where_preds_in_scope
* paredit
* parent
* parentheses
* prepended if
* punctuation
* receive
* receiver
* referring
* repeated
* representing
* semantically
* separately
* shouldnot
* siblings
* similar
* something's
* statement
* struct
* structure
* surprise
* the
* this
* transparent
* unimplemented
* unnamed
* unnecessary
* unneeded
* unreachable
* unterminated
* utilities
* variant
* variants
* visibility
* work around (v)
* workaround
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-19 09:45:55 -04:00
Lukas Wirth
a2a3fecae3
Option begone part 2
2023-04-16 19:20:48 +02:00
Lukas Wirth
71b50f9f09
Record eager expansion errors in EagerCallInfo
2023-04-16 16:11:59 +02:00
Lukas Wirth
a756c9ad08
Fixup comments
2023-02-07 18:08:05 +01:00
Lukas Wirth
e59487de38
Add tests for float access macro call inputs
2023-02-07 17:12:24 +01:00
Lukas Wirth
c6e7917d6e
Fix up token_tree_to_syntax_node float split handling
2023-02-07 15:21:37 +01:00
Lukas Wirth
9053bcc65c
Make mbe compile with parser changes
2023-02-03 21:39:24 +01:00
Lukas Wirth
41a46a78f2
Make tt generic over the span data
2023-01-31 14:58:16 +01:00
bors
f32f64bffc
Auto merge of #13929 - danieleades:simplify, r=lnicola
...
internal: a number of code simplifications
2023-01-11 09:38:34 +00:00
Daniel Eades
ac3844a0bb
a number of code simplifications
2023-01-10 18:48:51 +00:00
Daniel Eades
95d14c393c
avoid 'cloning' types that implement 'Copy'
2023-01-10 18:20:12 +00:00
Daniel Eades
4f8ffd0ba4
remove unnecessary lifetimes that can be elided
2023-01-02 15:02:54 +00:00
Daniel Eades
efd2c20e96
remove useless conversions
2023-01-02 15:02:54 +00:00
Daniel Eades
cc80c5bd07
remove unnecessary lazy evaluations
2023-01-02 15:02:54 +00:00
Daniel Eades
ed128872eb
remove needless borrows
2023-01-02 14:52:32 +00:00
Ryo Yoshida
a7d411425c
mbe: handle multi-character separator
2022-12-28 00:59:56 +09:00
Ryo Yoshida
767351fb87
mbe: treat <-
as one punct
2022-12-27 18:34:46 +09:00
Ryo Yoshida
ec7148b091
mbe: split Op::Leaf
and handle multi-character puncts
2022-12-27 18:23:01 +09:00
Ryo Yoshida
47c6c8e2f3
Extract multi-character punct handling into a method
2022-12-27 18:21:01 +09:00
Yuri Astrakhan
e16c76e3c3
Inline all format arguments where possible
...
This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.
The change was automatically created with, so there are far less change
of an accidental typo.
```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2022-12-24 14:36:10 -05:00
Ryo Yoshida
e027ac0fbf
fix: don't let mbe expr fragments match let exprs and inline consts
2022-12-20 20:31:47 +09:00
Ryo Yoshida
41b0c54c07
Fix tt::Punct
's spacing calculation
2022-11-05 19:42:09 +09:00
Ryo Yoshida
b87a23b91b
Rename convertor -> converter
2022-11-05 19:41:08 +09:00
Lukas Wirth
78f33c0e96
Expand unmatched mbe fragments to reasonable default token trees
...
Currently we expand unmatched fragments by not replacing them at all,
leaving us with `$ident`. This trips up the parser or subsequent macro
calls. Instead it makes more sense to replace these with some reasonable
default depending on the fragment kind which should make more recursive
macro calls work better for completions.
2022-10-10 14:27:05 +02:00
Jonas Platte
c4a87ee0ce
mbe: Remove unneeded unwrap
2022-09-14 23:49:08 +02:00
Jonas Platte
d6f0fd04ee
mbe: Remove unnecessary reference to usize
2022-09-14 23:42:11 +02:00
Jonas Platte
54305545a5
mbe: Remove Vec reference in container
2022-09-14 23:35:12 +02:00
Jonas Platte
b6aed7914d
mbe: Remove double reference in container
2022-09-14 23:30:44 +02:00
Jonas Platte
f7f6d2870f
mbe: Use extend instead of push in loop
2022-09-14 23:26:24 +02:00
Jonas Platte
5e2f9e322f
mbe: Return Bindings from build_inner
2022-09-14 23:22:38 +02:00
Dezhi Wu
23747419ca
fix: a bunch of typos
...
This PR will fix some typos detected by [typos].
There are also some other typos in the function names, variable names, and file
names, which I leave as they are. I'm more certain that typos in comments
should be fixed.
[typos]: https://github.com/crate-ci/typos
2022-08-17 21:44:58 +08:00
Edwin Cheng
23e17cd581
Improve insert whitespace in mbe
2022-08-10 16:28:56 +08:00
Amos Wenger
816f7fe12a
Run cargo fix --edition-idioms
2022-07-20 15:02:08 +02:00
Amos Wenger
23d25a3094
Enable extra warnings required by rust-lang/rust
2022-07-20 15:00:17 +02:00
Florian Diebold
0a4065d12d
Improve syntax fixup a bit, handle incomplete if
...
- allow appending tokens after a token, not just a node
- allow inserting delimiters (and remove them again)
- fix up `if {}` and `if` without anything following
2022-07-16 13:03:32 +02:00
Jonas Schievink
df66eb74ab
Implement ignore
and index
metavar expression
2022-07-11 18:31:42 +02:00
Tim Neumann
40bfb29e50
feat: Support $$
in macros.
...
The implementation mirrors what `rustc` currently does [1]. Part of #11952 .
[1]: 0595ea1d12/compiler/rustc_expand/src/mbe/quoted.rs (L230-L241)
2022-06-02 21:48:28 +02:00
Jonas Schievink
9bd11459ba
Revert "Auto merge of #12149 - jonas-schievink:literally-just-a-literal, r=jonas-schievink"
...
This reverts commit cc9ae2b89e
, reversing
changes made to 7dfd1cb572
.
2022-05-13 15:08:14 +02:00
Jonas Schievink
2287ae22c6
Revert "Skip only the tt::Literal
when consuming float tokens"
...
This reverts commit 7db55313a1
.
2022-05-13 15:06:16 +02:00
Jonas Schievink
bde036b74e
Revert "Fix conversion of float literals in TtTreeSink
"
...
This reverts commit 43a066c5a8
.
2022-05-13 15:05:34 +02:00
Jonas Schievink
73e0e17b52
Revert "Don't remap float tokens to INT_NUMBER
"
...
This reverts commit cb5e8da88a
.
2022-05-13 15:04:36 +02:00
Jonas Schievink
cb5e8da88a
Don't remap float tokens to INT_NUMBER
2022-05-12 19:01:09 +02:00
Jonas Schievink
43a066c5a8
Fix conversion of float literals in TtTreeSink
2022-05-06 18:39:06 +02:00
Jonas Schievink
7db55313a1
Skip only the tt::Literal
when consuming float tokens
2022-05-06 16:10:54 +02:00
Jonas Schievink
37443eb9a1
Maybe everything else *should* have to deal with it
2022-05-05 16:28:59 +02:00
Jonas Schievink
1bc3305d95
Split float literal tokens at the .
2022-05-05 16:28:58 +02:00
Matthias Krüger
7912e33ed6
fix clippy::needless_borrow
2022-03-12 16:50:49 +01:00
Chayim Refael Friedman
10d30be331
Do not consider _
to be an expression for macro_rules!
2022-03-02 01:51:25 +00:00
Lukas Wirth
1505b6a9b4
internal: Split unresolve proc-macro error out of mbe
2022-02-22 10:08:00 +01:00
bellau
ff4024eebd
Impr mbe: remove unecessary temporary vec
2022-02-15 10:21:14 +01:00
Florian Diebold
dfd2cef0d0
Add back an assertion
2022-02-09 16:36:45 +01:00
Florian Diebold
63fd643d72
Various fixes
2022-02-09 16:30:10 +01:00
Florian Diebold
bdb7ae5dd0
Rename syntax_node_to_token_tree_censored
2022-02-09 13:45:31 +01:00
Florian Diebold
ecf3cff4a6
Replace expressions with errors in them
2022-02-09 11:58:52 +01:00
Florian Diebold
1a5aa84e9f
Track synthetic tokens, to be able to remove them again later
2022-02-08 18:13:18 +01:00
Florian Diebold
c3601e9860
Reverse fixups
2022-02-07 19:53:39 +01:00
Florian Diebold
86b968ba94
Add a check
2022-02-07 18:19:00 +01:00
Florian Diebold
b9c5d23f69
Simplify a bit
2022-02-07 18:17:28 +01:00
Florian Diebold
cff209f152
WIP: Actually fix up syntax errors in attribute macro input
2022-02-07 18:12:51 +01:00
Lukas Wirth
2ad71f1350
Shrink mbe::ExpandError
and mbe::ParseError
2022-02-03 17:25:24 +01:00
Jonas Schievink
5088926ec3
Make syntax bridge fully infallible
2022-01-24 17:27:39 +01:00
Aleksey Kladov
303814189a
simplify
2022-01-03 16:27:16 +03:00
Aleksey Kladov
966983c707
simplify
2022-01-03 16:22:41 +03:00
bors[bot]
2e7170e07b
Merge #11166
...
11166: minor: Simplify r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-02 16:49:40 +00:00
Lukas Wirth
f31863b189
minor: Simplify
2022-01-02 17:37:16 +01:00
Aleksey Kladov
3836b195dd
minor: replace panics with types
2022-01-02 19:05:37 +03:00
Aleksey Kladov
174c439c56
minor: drop dead code
2022-01-02 19:03:38 +03:00
Aleksey Kladov
d846afdeef
check top level entry point invariants
2022-01-02 18:41:32 +03:00
Aleksey Kladov
7989d567e2
internal: more macro tests
2022-01-02 17:18:21 +03:00
Lukas Wirth
8fad24d3c2
minor: Simplify
2022-01-02 12:40:46 +01:00
Lukas Wirth
65a1538dd1
internal: Use basic NonEmptyVec in mbe::syntax_bridge
2022-01-02 03:48:19 +01:00
Lukas Wirth
a0e0e4575b
Simplify
2022-01-02 02:39:14 +01:00
Aleksey Kladov
afffa096f6
add TopEntryPoint
2021-12-28 17:00:55 +03:00
Aleksey Kladov
8e7fc7be65
simplify
2021-12-28 17:00:55 +03:00
Aleksey Kladov
369001615f
move path
2021-12-28 17:00:55 +03:00
Aleksey Kladov
c5d8a9b341
move expr
2021-12-28 17:00:55 +03:00
Aleksey Kladov
04ae18de29
move ty
2021-12-28 17:00:55 +03:00
Aleksey Kladov
5636bef2ec
move pat to prefix entry points
2021-12-28 17:00:55 +03:00
Aleksey Kladov
f10f51833c
move stmt to entry points
2021-12-28 17:00:55 +03:00
Aleksey Kladov
519ee21bcb
internal: move block to prefix entry point
2021-12-28 17:00:55 +03:00
Aleksey Kladov
350d5dc152
internal: move visibility to a prefix entry point
2021-12-28 17:00:55 +03:00
Aleksey Kladov
d3ba55bd06
cleanup imports
2021-12-28 17:00:55 +03:00
Aleksey Kladov
23ce31e836
simplify
2021-12-28 17:00:55 +03:00
Aleksey Kladov
74de79b1da
internal: rename
2021-12-25 22:02:26 +03:00
Aleksey Kladov
d0d05075ed
internal: replace TreeSink with a data structure
...
The general theme of this is to make parser a better independent
library.
The specific thing we do here is replacing callback based TreeSink with
a data structure. That is, rather than calling user-provided tree
construction methods, the parser now spits out a very bare-bones tree,
effectively a log of a DFS traversal.
This makes the parser usable without any *specifc* tree sink, and allows
us to, eg, move tests into this crate.
Now, it's also true that this is a distinction without a difference, as
the old and the new interface are equivalent in expressiveness. Still,
this new thing seems somewhat simpler. But yeah, I admit I don't have a
suuper strong motivation here, just a hunch that this is better.
2021-12-25 22:02:26 +03:00
Aleksey Kladov
a022ad68c9
internal: move all the lexing to the parser crate
2021-12-18 17:20:38 +03:00
Aleksey Kladov
57e6ef0bfb
tighten up invariants
2021-12-12 19:22:37 +03:00
Aleksey Kladov
1055a6111a
port mbe to soa tokens
2021-12-12 19:06:40 +03:00
Lukas Wirth
a9c4c6da4c
Fix mbe::Shift::new not accounting for non-ident token ids
2021-11-22 18:00:32 +01:00
Lukas Wirth
64cb09ddea
Add to macro testing infra to emit token map ids
2021-11-22 16:51:09 +01:00
Aleksey Kladov
5a83d1be66
internal: replace L_DOLLAR/R_DOLLAR with parenthesis hack
...
The general problem we are dealing with here is this:
```
macro_rules! thrice {
($e:expr) => { $e * 3}
}
fn main() {
let x = thrice!(1 + 2);
}
```
we really want this to print 9 rather than 7.
The way rustc solves this is rather ad-hoc. In rustc, token trees are
allowed to include whole AST fragments, so 1+2 is passed through macro
expansion as a single unit. This is a significant violation of token
tree model.
In rust-analyzer, we intended to handle this in a more elegant way,
using token trees with "invisible" delimiters. The idea was is that we
introduce a new kind of parenthesis, "left $"/"right $", and let the
parser intelligently handle this.
The idea was inspired by the relevant comment in the proc_macro crate:
https://doc.rust-lang.org/stable/proc_macro/enum.Delimiter.html#variant.None
> An implicit delimiter, that may, for example, appear around tokens
> coming from a “macro variable” $var. It is important to preserve
> operator priorities in cases like $var * 3 where $var is 1 + 2.
> Implicit delimiters might not survive roundtrip of a token stream
> through a string.
Now that we are older and wiser, we conclude that the idea doesn't work.
_First_, the comment in the proc-macro crate is wishful thinking. Rustc
currently completely ignores none delimiters. It solves the (1 + 2) * 3
problem by having magical token trees which can't be duplicated:
* https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/TIL.20that.20token.20streams.20are.20magic
* https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Handling.20of.20Delimiter.3A.3ANone.20by.20the.20parser
_Second_, it's not like our implementation in rust-analyzer works. We
special-case expressions (as opposed to treating all kinds of $var
captures the same) and we don't know how parser error recovery should
work with these dollar-parenthesis.
So, in this PR we simplify the whole thing away by not pretending that
we are doing something proper and instead just explicitly special-casing
expressions by wrapping them into real `()`.
In the future, to maintain bug-parity with `rustc` what we are going to
do is probably adding an explicit `CAPTURED_EXPR` *token* which we can
explicitly account for in the parser.
If/when rustc starts handling delimiter=none properly, we'll port that
logic as well, in addition to special handling.
2021-10-23 20:44:31 +03:00
Aleksey Kladov
d4d67406d7
internal: clean up code duplication
2021-10-10 21:08:10 +03:00
Aleksey Kladov
634f047d90
internal: add integrated test for token censoring
2021-10-10 16:52:21 +03:00
Aleksey Kladov
bfc5d8529a
drop obsolete tests
2021-10-10 15:11:33 +03:00
Aleksey Kladov
0f849a7a35
move test
2021-10-10 15:06:41 +03:00
Aleksey Kladov
dce41e5a03
move tests
2021-10-10 14:58:25 +03:00
Aleksey Kladov
42fd71e6c8
move tests
2021-10-10 14:40:13 +03:00
Aleksey Kladov
be73cc8f83
move test
2021-10-10 14:28:04 +03:00
Aleksey Kladov
af76db3c36
move tests
2021-10-10 14:26:47 +03:00
Aleksey Kladov
6253213a6e
move test
2021-10-10 14:23:52 +03:00
Aleksey Kladov
e55797f59d
move tests
2021-10-10 14:21:47 +03:00
Aleksey Kladov
8997d742dc
move tests
2021-10-10 14:08:49 +03:00
Aleksey Kladov
5ad502dbdb
move test
2021-10-10 13:54:44 +03:00
Aleksey Kladov
c986568cbb
move test
2021-10-10 13:26:07 +03:00
Aleksey Kladov
5b44770102
move test
2021-10-10 13:24:48 +03:00
Aleksey Kladov
e255e9577f
internal: move test
2021-10-10 13:21:42 +03:00
Aleksey Kladov
8670e83cec
move test
2021-10-10 12:57:18 +03:00
Aleksey Kladov
7d92b9f6ff
move test
2021-10-10 12:55:31 +03:00
Aleksey Kladov
748e6881fc
move tests
2021-10-10 12:52:28 +03:00
Aleksey Kladov
6fd2f1d25b
internal: move tests
2021-10-10 12:45:17 +03:00
Aleksey Kladov
5a854a7253
internal: move tests
2021-10-10 12:39:58 +03:00
Aleksey Kladov
c88cda04db
move some tests
2021-10-10 11:44:46 +03:00
Aleksey Kladov
a3470a8114
move tests
2021-10-10 11:39:08 +03:00
Aleksey Kladov
7e53a3ce23
move test
2021-10-10 11:29:26 +03:00
Aleksey Kladov
408475a593
move test
2021-10-10 11:26:18 +03:00
Aleksey Kladov
9c819eaa9a
move tests
2021-10-10 11:15:42 +03:00
Aleksey Kladov
1c15f47e00
internal: move tests
2021-10-10 11:11:50 +03:00
Aleksey Kladov
c6d5c1c946
dead code
2021-10-10 11:09:16 +03:00
Aleksey Kladov
e9902b92ab
internal: move some mbe tests
2021-10-10 11:08:02 +03:00
Aleksey Kladov
f17f5d68f9
move tests
2021-10-10 11:08:02 +03:00
Aleksey Kladov
3a47dba761
fix tests
2021-10-10 11:08:02 +03:00
Aleksey Kladov
de136a5340
move test
2021-10-09 19:11:04 +03:00
Aleksey Kladov
e838da18a9
internal: move tests
2021-10-09 18:54:15 +03:00
Aleksey Kladov
0dc87badd7
internal: move test
2021-10-09 18:51:26 +03:00
Aleksey Kladov
0a32c20142
internal: move test
2021-10-09 18:49:14 +03:00
Aleksey Kladov
993ff1c239
internal: drop duplicated test
2021-10-09 18:47:04 +03:00
Aleksey Kladov
419c234333
internal: move test
2021-10-09 18:46:16 +03:00
Aleksey Kladov
b1cfa51ef5
internal: move tests
2021-10-09 18:43:15 +03:00
Aleksey Kladov
3e8ef943c6
internal: move some tests
2021-10-09 18:18:56 +03:00
Aleksey Kladov
a060b9a4b2
internal: move some macro tests
2021-10-09 18:15:05 +03:00
Aleksey Kladov
c41b7bbe69
internal: allow macro tests to inspect parse tree
2021-10-09 17:58:17 +03:00
Aleksey Kladov
aac23f7832
move tests
2021-10-09 17:43:07 +03:00
Aleksey Kladov
036c0ff8c7
move some tests
2021-10-09 17:27:38 +03:00
Aleksey Kladov
959da8caa1
internal: move test
2021-10-09 16:31:26 +03:00
Aleksey Kladov
75b0ce17cf
move test
2021-10-09 16:27:19 +03:00
Aleksey Kladov
0dd1b35479
move test
2021-10-09 16:25:37 +03:00
Aleksey Kladov
574df660e4
move test
2021-10-09 16:22:42 +03:00
Aleksey Kladov
b21244e080
internal: move test
2021-10-09 16:19:19 +03:00
Aleksey Kladov
ef1251f696
feat: report errors in macro definition
...
Reporting macro *definition* error at the macro *call site* is a rather
questionable approach, but at least we don't erase the errors
altogether!
2021-10-09 15:23:55 +03:00
Aleksey Kladov
8e9003447c
future proof structure
2021-10-09 14:48:38 +03:00
Aleksey Kladov
5ecda802f1
move test
2021-10-09 14:45:52 +03:00
Aleksey Kladov
f4ee0d736c
move tests
2021-10-09 14:39:24 +03:00
Aleksey Kladov
1abe3f8275
internal: move tests
2021-10-09 14:22:49 +03:00
Aleksey Kladov
49f5fecf06
internal: move test
2021-10-09 14:18:53 +03:00
Aleksey Kladov
78ca43ef3d
internal: move test
2021-10-09 13:51:02 +03:00
Aleksey Kladov
093f99b809
internal: start new macro test suite
...
I don't like our macro tests -- they are brittle and don't inspire
confidence. I think the reason for that is that we try to unit-test
them, but that is at odds with reality, where macro expansion
fundamentally depends on name resolution.
2021-10-09 13:42:32 +03:00