Commit Graph

233 Commits

Author SHA1 Message Date
Aleksey Kladov
104cd0ce88 internal: make name consistent with usage 2021-09-06 18:34:03 +03:00
Aleksey Kladov
dbb702cfc1 internal: remove accidental code re-use
FragmentKind played two roles:

* entry point to the parser
* syntactic category of a macro call

These are different use-cases, and warrant different types. For example,
macro can't expand to visibility, but we have such fragment today.

This PR introduces `ExpandsTo` enum to separate this two use-cases.

I suspect we might further split `FragmentKind` into `$x:specifier` enum
specific to MBE, and a general parser entry point, but that's for
another PR!
2021-09-05 22:36:36 +03:00
Lukas Wirth
36a5ce9790 minor: fix some clippy lints 2021-09-03 16:00:50 +02:00
Aleksey Kladov
81602f8a5d internal: reduce coupling
tt is a data structure, data structures cant' go wrong, they shouldn't
have the knowledge that the world outside of them has all kinds of
errors.
2021-08-31 19:14:33 +03:00
Aleksey Kladov
51b955ec8a internal: simplify 2021-08-31 15:09:46 +03:00
Mario Carneiro
b22eb02f8b
fail -> failed 2021-08-30 02:47:10 -07:00
Mario Carneiro
2d349aed2e
Update crates/hir_expand/src/db.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-08-30 02:43:13 -07:00
Mario Carneiro
6e8dedadcd
Fix error message
I'm not entirely sure if the message is still correct, it seems to have survived a number of refactors, but it is mangled english anyway.
2021-08-30 02:36:21 -07:00
Dezhi Wu
ba0947dded switch log crate to tracing 2021-08-30 15:11:42 +08:00
Lukas Wirth
c5059e0623 Return all ranges corresponding to a token id in TokenMap 2021-08-29 00:49:57 +02:00
bors[bot]
fae440c32a
Merge #10025
10025: Don't mutate syntax trees when preparing proc-macro input r=Veykril a=Veykril

Fixes #10013

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-28 14:14:54 +00:00
bors[bot]
97409e5fc8
Merge #9970
9970: feat: Implement attribute input token mapping, fix attribute item token mapping r=Veykril a=Veykril

![image](https://user-images.githubusercontent.com/3757771/130328577-4c1ad72c-51b1-47c3-8d3d-3242ec44a355.png)

The token mapping for items with attributes got overwritten partially by the attributes non-item input, since attributes have two different inputs, the item and the direct input both.
This PR gives attributes a second TokenMap for its direct input. We now shift all normal input IDs by the item input maximum(we maybe wanna swap this see below) similar to what we do for macro-rules/def. For mapping down we then have to figure out whether we are inside the direct attribute input or its item input to pick the appropriate mapping which can be done with some token range comparisons.

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9867

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 19:30:36 +00:00
oxalica
15eccf29e8
Fix missing unsafe block for the nightly change
Fix #10022
2021-08-26 17:21:23 +08:00
Lukas Wirth
d6134b6802 Don't mutate syntax trees when preparing proc-macro input 2021-08-25 18:57:24 +02:00
Lukas Wirth
4933beca87 Respect attributes in Hygiene token up-mapping 2021-08-22 19:12:45 +02:00
Florian Diebold
424dda8113 Refactor & improve handling of overloaded binary operators
Fixes #9971. Also records them as method resolutions, which we could use
later.
2021-08-22 17:35:50 +02:00
Lukas Wirth
5507512eaf Replace stripped derives with whitespace in process_macro_input 2021-08-22 14:23:59 +02:00
Lukas Wirth
5fb8c0ddfd Remove MappedSubtree 2021-08-21 18:19:18 +02:00
Lukas Wirth
177c70128c Map attribute input tokens correctly 2021-08-21 18:13:41 +02:00
Lukas Wirth
cee02673d1 Don't ask for the builtin attribute input twice 2021-08-21 12:55:05 +02:00
Aleksey Kladov
1850849325 internal: prep to 2021 edition 2021-08-20 16:20:18 +03:00
Lukas Wirth
82728eb757 Switch AstDatabase::exapnd_proc_macro to ExpandResult 2021-08-20 14:34:46 +02:00
Lukas Wirth
269de9abe3 Switch BuiltinDeriveExpander::expand to ExpandResult 2021-08-20 14:28:36 +02:00
Lukas Wirth
557df6ff3f Use correct HirFileId in find_related_test 2021-08-20 13:50:40 +02:00
Lukas Wirth
7342dcf0b0 Fix runnables not seeing test and bench attributes 2021-08-20 13:50:06 +02:00
Lukas Wirth
351cec0cb4 Do not replace items annotated with builtin attrs with the attr input 2021-08-20 13:50:06 +02:00
Lukas Wirth
c67ecbebc4 Rename fails on renaming definitions created by macros 2021-08-20 00:12:47 +02:00
bors[bot]
6a07bf6a9f
Merge #9920
9920: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-16 14:13:04 +00:00
Lukas Wirth
0c0142f61a Simplify 2021-08-16 16:12:20 +02:00
Aleksey Kladov
438d1da6c6 minor: simplify 2021-08-16 14:45:54 +03:00
Aleksey Kladov
d29c52354c minor: remove dead code 2021-08-16 14:28:04 +03:00
Aleksey Kladov
3e5b155716 fix: avoid pathological macro expansions
Today, rust-analyzer (and rustc, and bat, and IntelliJ) fail badly on
some kinds of maliciously constructed code, like a deep sequence of
nested parenthesis.

"Who writes 100k nested parenthesis" you'd ask?

Well, in a language with macros, a run-away macro expansion might do
that (see the added tests)! Such expansion can be broad, rather than
deep, so it bypasses recursion check at the macro-expansion layer, but
triggers deep recursion in parser.

In the ideal world, the parser would just handle deeply nested structs
gracefully. We'll get there some day, but at the moment, let's try to be
simple, and just avoid expanding macros with unbalanced parenthesis in
the first place.

closes #9358
2021-08-09 16:15:02 +03:00
Aleksey Kladov
9aa6be71a5 internal: remove useless helpers
We generally avoid "syntax only" helper wrappers, which don't do much:
they make code easier to write, but harder to read. They also make
investigations harder, as "find_usages" needs to be invoked both for the
wrapped and unwrapped APIs
2021-08-09 15:58:21 +03:00
Lukas Wirth
3b7c713af3 Implement if_to_bool_then assist 2021-08-08 17:56:34 +02:00
Jonas Schievink
260936d0b7 Fix detection of macro file in inactive-code diag 2021-08-04 18:02:45 +02:00
Aleksey Kladov
f952dc61d1 internal: add API to check what are the max limits in practice 2021-07-31 18:26:43 +03:00
Robert Bartlensky
0b3d0cde8b Add Limit struct.
Fixes #9286.
2021-07-19 13:26:11 +01:00
Lukas Wirth
13d3928d0b Update list of safe intrinsics 2021-07-08 15:49:39 +02:00
Aleksey Kladov
86720f2953 minor: drop dummy authors field 2021-07-05 14:19:41 +03:00
Lukas Wirth
9a1b9b3c78 Resolve attribute paths in attribute highlighting 2021-06-28 21:53:17 +02:00
Clemens Wasser
47747cd412 Apply some clippy suggestions 2021-06-21 16:40:21 +02:00
Laurențiu Nicola
e3ce88f6f2 Minor clippy perf fixes 2021-06-18 14:40:51 +03:00
Lukas Wirth
95c8c65139 Nest all the or-patterns! 2021-06-17 17:37:14 +02:00
bors[bot]
5a8ddb4b2d
Merge #9260
9260: tree-wide: make rustdoc links spiky so they are clickable r=matklad a=lf-

Rustdoc was complaining about these while I was running with --document-private-items and I figure they should be fixed.

Co-authored-by: Jade <software@lfcode.ca>
2021-06-14 07:16:48 +00:00
Jade
20b325c7d5 tree-wide: make rustdoc links spiky so they are clickable 2021-06-13 21:58:05 -07:00
Maan2003
5ac6804bb3
cargo fmt 2021-06-13 09:48:15 +05:30
Maan2003
c50b4579ec
clippy::useless_return 2021-06-13 09:35:29 +05:30
Maan2003
705f7e6e26
clippy::clone_on_copy 2021-06-13 09:27:19 +05:30
Maan2003
6cc6dee9e9
clippy::useless_conversion 2021-06-13 09:25:55 +05:30
Maan2003
c9b4ac5be4
clippy::redudant_borrow 2021-06-13 09:24:16 +05:30