Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
442 commits
Select commit Hold shift + click to select a range
3705cc2
Merge pull request rust-analyzer/ungrammar#1 from rust-analyzer/stmt
matklad Aug 1, 2020
f129b3e
Add ungrammar2json tool
matklad Aug 1, 2020
0deafdd
Fmt
matklad Aug 1, 2020
8d8d4f5
Allow empty fields
matklad Aug 1, 2020
d7dcd02
Shorten Pointer -> Ptr
matklad Aug 1, 2020
cdecf60
Shorten ReferenceType -> RefType
matklad Aug 1, 2020
37150eb
Merge pull request rust-analyzer/ungrammar#2 from rust-analyzer/fixes
matklad Aug 1, 2020
7bc5cfb
Bump version
matklad Aug 1, 2020
210f724
Typo fix
Aug 3, 2020
74d7f48
Another typo fix
Aug 3, 2020
e4b6301
Merge pull request rust-analyzer/ungrammar#3 from jmg-duarte/patch-1
matklad Aug 3, 2020
4c04751
Make type in Param optional
Apanatshka Aug 7, 2020
2a5b30a
Merge pull request rust-analyzer/ungrammar#4 from Apanatshka/patch-1
matklad Aug 7, 2020
366d647
Allow pipes in parameters
matklad Aug 21, 2020
a9cae3e
Name MethodCall's receiver
matklad Aug 21, 2020
4d441ca
v1.1.2
matklad Aug 21, 2020
ca09035
Allow type aliases in extern blocks
jonas-schievink Aug 24, 2020
3c19796
Bump to 1.1.3
jonas-schievink Aug 24, 2020
1c82b88
Merge rust-analyzer/ungrammar#10
bors[bot] Aug 24, 2020
43354a5
Continious release
matklad Aug 24, 2020
d9d0ed2
Allow both const & async modifiers
matklad Aug 24, 2020
a8c9fa5
Merge rust-analyzer/ungrammar#11
bors[bot] Aug 24, 2020
78f5d1b
Fix .gitignore
matklad Aug 24, 2020
643354e
Merge rust-analyzer/ungrammar#12
bors[bot] Aug 24, 2020
7a744b9
Add new_inline const-fn constructor
matklad Sep 20, 2020
60e075e
:arrow_up: proptest
matklad Sep 20, 2020
951523a
Switch CI to actions
matklad Sep 20, 2020
c7b86a6
Bump major version
matklad Sep 20, 2020
56f34ee
Drop benchmarking
matklad Sep 20, 2020
a5fc8a0
Merge rust-analyzer/smol_str#23
bors[bot] Sep 20, 2020
7e76690
Document MSRV
matklad Sep 21, 2020
77a4fa5
Update CI badge in readme to point to Github Actions
ComputerDruid Oct 7, 2020
f03a19e
Minor
matklad Oct 24, 2020
c3f2679
Link post
matklad Oct 24, 2020
61257d6
Move towards upstream `macro_rules!` model
jonas-schievink Nov 27, 2020
7a1c02e
Merge pull request rust-analyzer/ungrammar#14 from jonas-schievink/ma…
Dec 14, 2020
a10691c
Bump to 1.2.0
jonas-schievink Dec 14, 2020
58aade1
Fixup MacroRules to work with xtask codegen
jonas-schievink Dec 14, 2020
9e4810f
Roll back `MacroArm` change
jonas-schievink Dec 15, 2020
a6073ec
Add `MacroDef` for "Macros 2.0"
jonas-schievink Dec 15, 2020
8bb6876
Fix labels missing the colon token in rust ungrammar
Veykril Dec 14, 2020
a28544c
Node-ify lifetime
Veykril Dec 14, 2020
feb28d7
Merge rust-analyzer/ungrammar#16
bors[bot] Dec 16, 2020
c6092c6
Bump to 1.3.0
Dec 16, 2020
17af0b3
Merge rust-analyzer/ungrammar#15
bors[bot] Dec 16, 2020
edb64ad
Bump to 1.4.0
Dec 16, 2020
eb04a44
Add inline const expression and pattern
Veykril Dec 15, 2020
2d3670b
Merge rust-analyzer/ungrammar#17
bors[bot] Dec 23, 2020
3d965ac
Rename tail_expr
matklad Jan 5, 2021
2866baa
Merge rust-analyzer/ungrammar#18
bors[bot] Jan 5, 2021
80950ad
Add YieldExpr
sasurau4 Jan 11, 2021
0c88083
Bump to 1.7.0
sasurau4 Jan 12, 2021
4052e85
Merge rust-analyzer/ungrammar#19
bors[bot] Jan 12, 2021
9e31083
Allow binary-searching an array of disjoint ranges
matklad Jan 13, 2021
6a2ad86
Replace self/super/crate in PathSegment with NameRef
Veykril Jan 15, 2021
e0f2db2
Merge rust-analyzer/ungrammar#20
bors[bot] Jan 15, 2021
3e3a917
Replace other self/super/crate usages with NameRef
Veykril Jan 15, 2021
0ae6fb5
Merge rust-analyzer/ungrammar#21
bors[bot] Jan 15, 2021
59d1f3e
`Type` can also be `MacroCall`
jonas-schievink Jan 18, 2021
5a779cc
Merge pull request rust-analyzer/ungrammar#22 from jonas-schievink/ty…
Jan 18, 2021
c2c9018
Wrap type macro in new `MacroType` node
jonas-schievink Jan 18, 2021
d0da6a6
Merge pull request rust-analyzer/ungrammar#23 from jonas-schievink/ty…
Jan 18, 2021
88dda04
Swap RecordExprField optional part
Veykril Jan 18, 2021
6b1284e
Correct `const` keyword position in `Impl` rule
Veykril Jan 18, 2021
9290b82
Merge rust-analyzer/ungrammar#24
bors[bot] Jan 18, 2021
074cf58
Derive more for Node and Token
azdavis Jan 22, 2021
f97b360
Add a tokens iterator
azdavis Jan 22, 2021
e92c41b
Write docs
azdavis Jan 22, 2021
15960eb
Reorder
azdavis Jan 22, 2021
30cbbc2
Fix typo
azdavis Jan 22, 2021
feea02a
Pluralize
azdavis Jan 22, 2021
2435886
Add more doc
azdavis Jan 22, 2021
2a55a50
Fix typo
azdavis Jan 22, 2021
f6a8208
Bump minor version
azdavis Jan 22, 2021
435db30
Merge rust-analyzer/ungrammar#25
bors[bot] Jan 22, 2021
a97499a
adt
matklad Feb 7, 2021
1404a59
Split out macro calls in item position
jonas-schievink Feb 18, 2021
bc0e6a5
Merge rust-analyzer/ungrammar#27
bors[bot] Feb 18, 2021
580420c
Make ExternItem and AssocItem use MacroItem
jonas-schievink Feb 18, 2021
d1c43f1
Merge rust-analyzer/ungrammar#28
bors[bot] Feb 18, 2021
07fa8ea
Macro Statements should be expr
edwin0cheng Mar 8, 2021
c62d67d
Revert "Make ExternItem and AssocItem use MacroItem"
jonas-schievink Mar 15, 2021
c10cb56
Revert "Split out macro calls in item position"
jonas-schievink Mar 15, 2021
88e52b7
Restore current version
jonas-schievink Mar 15, 2021
38c82cb
Merge rust-analyzer/ungrammar#30
bors[bot] Mar 15, 2021
02cc956
Merge rust-analyzer/ungrammar#29
bors[bot] Mar 15, 2021
50349a3
extended_key_value_attributes
Veykril Mar 18, 2021
3a5f76e
Merge rust-analyzer/ungrammar#31
bors[bot] Mar 18, 2021
4a003cc
Report 1-based indices in Error's Display impl
CAD97 May 2, 2021
2e0a88f
Merge rust-analyzer/ungrammar#32
bors[bot] May 2, 2021
0471dc7
Add a `Meta` node representing attribute contents
jonas-schievink Jun 11, 2021
6241ee3
Bump to 1.14.0
jonas-schievink Jun 11, 2021
b78c266
Merge rust-analyzer/ungrammar#33
bors[bot] Jun 11, 2021
a8c9f3c
fix indentation
matklad Jun 19, 2021
c0b028c
More specific error for leading pipes
ammkrn Jun 19, 2021
c2d6982
Merge rust-analyzer/ungrammar#35
bors[bot] Jun 19, 2021
7994418
Implement arbitrary behind a feature flag
Jun 26, 2021
428c2f5
Merge rust-analyzer/smol_str#35
bors[bot] Jun 26, 2021
7b44ce1
Add GenericParamList to AssocTypeArg
Veykril Jul 17, 2021
d547272
Merge rust-analyzer/ungrammar#36
bors[bot] Jul 17, 2021
9dbc8b8
Add `#![no_std]` support
ark0f Aug 12, 2021
45d15c5
Merge rust-analyzer/smol_str#36
bors[bot] Aug 12, 2021
53c92c3
Add syntax elements for `if let` match guards
jonas-schievink Aug 12, 2021
d6c6923
Merge rust-analyzer/ungrammar#38
bors[bot] Aug 12, 2021
3daeb5f
Add both variants of half open range patterns to the grammar
lf- Aug 4, 2021
1c6ac78
Bump version and remove soft-deprecated authors field
lf- Aug 5, 2021
c5dc2a4
Merge rust-analyzer/ungrammar#37
bors[bot] Aug 13, 2021
dda1d2b
Merge rust-analyzer/smol_str#26
bors[bot] Sep 13, 2021
bbc21f8
Add ungrammar extensions
azdavis Sep 14, 2021
d291414
Merge rust-analyzer/ungrammar#39
bors[bot] Sep 14, 2021
e364b1b
avoid attribute ambiguity in ExprStmt
matklad Sep 26, 2021
5fc518d
canonical grammar for block expressions
matklad Sep 26, 2021
51afcb2
bump version
matklad Sep 26, 2021
2cabc6c
Merge rust-analyzer/ungrammar#40
bors[bot] Sep 26, 2021
d60265b
add Attr to RestPat
xffxff Oct 3, 2021
26ce02d
Merge rust-analyzer/ungrammar#41
bors[bot] Oct 3, 2021
7fdbd98
Add support for `let ... else`
jonas-schievink Oct 6, 2021
89e0746
Merge rust-analyzer/ungrammar#42
bors[bot] Oct 6, 2021
cf23edd
Make `LetElse` its own node
jonas-schievink Oct 7, 2021
9b6c90a
Merge rust-analyzer/ungrammar#43
bors[bot] Oct 7, 2021
ba63277
Add `~const` bounds to rust grammar
Veykril Oct 19, 2021
78965b4
Merge rust-analyzer/ungrammar#44
bors[bot] Oct 19, 2021
c3d80a5
implement FromStr
matklad Nov 1, 2021
30ddc12
Merge rust-analyzer/smol_str#39
bors[bot] Nov 1, 2021
817384a
fix no_std support
matklad Nov 1, 2021
ba96a7a
Merge rust-analyzer/smol_str#40
bors[bot] Nov 1, 2021
d79843d
Remove unnecessary Into<String> bound from From<T> impl
Veykril Nov 4, 2021
20b435d
Merge rust-analyzer/smol_str#41
bors[bot] Nov 4, 2021
df98469
Support if- and while-let chains
ChayimFriedman2 Jan 24, 2022
01249f6
Merge rust-analyzer/ungrammar#45
bors[bot] Jan 31, 2022
7476546
Fix some rust.ungram inconsistencies
Veykril Feb 8, 2022
42089fd
Merge rust-analyzer/ungrammar#46
bors[bot] Feb 20, 2022
67a1939
Revert the visibility removal of macro_rules visibility (#46)
ChayimFriedman2 Feb 24, 2022
ceca999
Merge rust-analyzer/ungrammar#48
bors[bot] Feb 24, 2022
5fd296a
Support destructuring assignments (RFC 2909)
ChayimFriedman2 Feb 24, 2022
8199ed2
Merge rust-analyzer/ungrammar#47
bors[bot] Feb 26, 2022
f590f83
Include `Self` specifically in NameRef
Veykril Mar 5, 2022
d404779
Merge rust-analyzer/ungrammar#50
bors[bot] Mar 5, 2022
267c02f
Add a new test for bad size hint
Dr-Emann Jul 7, 2020
11468b9
Use ASCII to get the "too big" char iterator
Dr-Emann Mar 11, 2022
c243a10
Merge rust-analyzer/smol_str#21
bors[bot] Mar 11, 2022
c2c13df
Merge rust-analyzer/smol_str#18
bors[bot] Apr 3, 2022
978213d
Clarify what `WS` is
Veykril Apr 3, 2022
b0bf973
Merge rust-analyzer/smol_str#43
bors[bot] Apr 3, 2022
25674ca
Bump dependencies
Veykril Apr 3, 2022
a9a54f2
Merge rust-analyzer/smol_str#44
bors[bot] Apr 3, 2022
d7d6d8a
Use new optional dependency feature syntax making serde truly optional
Veykril Apr 8, 2022
4e6fdc3
Merge rust-analyzer/smol_str#46
bors[bot] Apr 8, 2022
e4af25d
Revert usage of optional dependency feature syntax
Veykril Apr 26, 2022
972fb6c
One more byte for inlined
Austaras Jan 22, 2023
b131ea0
0.1.24
Austaras Jan 23, 2023
929193f
Update README.MD
Austaras Jan 23, 2023
4d67cb3
Remove redundant enum value
Austaras Jan 24, 2023
b7db632
Update test
Austaras Feb 5, 2023
5fcb2c8
Merge pull request rust-analyzer/smol_str#53 from Austaras/master
Veykril Feb 5, 2023
5abfc6c
Use optional dependency feature syntax to make serde actually optional
Veykril Mar 30, 2023
cce7b9a
Merge pull request rust-analyzer/smol_str#54 from rust-analyzer/opt-d…
Veykril Mar 30, 2023
0809c97
Implement AsRef<str> in favor of generic From impls
Veykril Mar 31, 2023
778ed65
Clarify size of SmolStr better
Veykril Mar 31, 2023
79103e2
Release 0.2.0
Veykril Mar 31, 2023
037f0ee
Merge pull request rust-analyzer/smol_str#55 from rust-analyzer/as-ref
Veykril Apr 11, 2023
5ef9b42
Update ungrammar.ungram with proper labeled rule
eliben Jun 19, 2023
89845d3
Merge pull request rust-analyzer/ungrammar#52 from eliben/patch-1
matklad Jun 19, 2023
5a306f0
Constify some constructors
Veykril Jun 30, 2023
46a88ea
Update repo link in Cargo.toml
tisonkun Jul 1, 2023
d66d274
Merge pull request rust-analyzer/ungrammar#54 from tisonkun/patch-1
lnicola Jul 2, 2023
a77b530
Implementing `From<Arc<str>> for SmolStr` and `From<SmolStr> for Arc<…
msdrigg Aug 25, 2023
f782802
Enforcing stack if can be put on stack
msdrigg Sep 5, 2023
d49c031
Merge pull request rust-analyzer/smol_str#58 from msdrigg/master
Veykril Sep 10, 2023
721388f
docs: fix missing codeblock backtick
MultisampledNight Sep 20, 2023
6f39671
Merge pull request rust-analyzer/smol_str#59 from MultisampledNight/f…
Veykril Sep 22, 2023
161b7d8
feat: Add `SmolStr::from_static`
moulins Jan 2, 2024
9a888a0
Add Writer and ToSmolStr
novacrazy Jan 15, 2024
0ac5232
Cleanup
novacrazy Jan 16, 2024
423862b
Fix new_inline codegen
novacrazy Jan 16, 2024
bb98e6d
Publish 0.2.1
Veykril Jan 16, 2024
369b5d4
add benchmarks
AntonSol919 Jan 17, 2024
26c059d
fix clone regression
AntonSol919 Jan 17, 2024
9721fb3
Manually impl clone
AntonSol919 Jan 17, 2024
248d7dc
remove nightly benchmark feature
AntonSol919 Jan 17, 2024
bf3675f
reformat
AntonSol919 Jan 31, 2024
95b5178
Add StrExt, to_lowercase_smolstr & friends
alexheretic Jan 30, 2024
df43843
Add must_use to StrExt methods
alexheretic Feb 8, 2024
88118f0
Add `PartialEq` shortcut for `ptr_eq` strings
Swatinem Jan 17, 2024
181a408
Add StrExt::replace_smolstr, replacen_smolstr
alexheretic Feb 8, 2024
4ce41f2
Update rust.ungram
Veykril Apr 18, 2024
88fbf18
Document unsafe blocks
Veykril May 14, 2024
0f87f48
Publish 0.2.2
Veykril May 14, 2024
042a1ec
Document crate feature guards
robjtede Jun 1, 2024
de14bdb
Migrate CI to actions-rust-lang/setup-rust-toolchain
robjtede Jun 1, 2024
18019ff
Bump deps
Veykril Sep 2, 2024
f899ce6
Various cleanups
Veykril Sep 2, 2024
b848dd1
Add more trait impls
Veykril Sep 2, 2024
82b4cf2
Expose SmolStrBuilder
Veykril Sep 3, 2024
9ac40e3
Add support for borsh
corvusrabus Apr 17, 2024
340cdde
Drop unstable__schema
Veykril Sep 3, 2024
32262a7
SmolStrBuilder::push
Veykril Sep 3, 2024
af10249
Publish 0.3.0
Veykril Sep 3, 2024
7a596f0
Make SmolStrBuilder fields private
Veykril Sep 3, 2024
eda9119
Publish 0.3.1
Veykril Sep 3, 2024
81bc5cf
Add CHANGELOG.md
Veykril Sep 3, 2024
2f0c57b
Add 0.2.2 changelog & fix lints
alexheretic Sep 3, 2024
b5498b3
Update CHANGELOG.md
alexheretic Sep 3, 2024
c3ee8d0
Merge pull request rust-analyzer/smol_str#87 from alexheretic/changel…
lnicola Sep 3, 2024
703c04d
Fix SmoLStrBuilder pushing null bytes on heap spill
Veykril Oct 23, 2024
7331497
Publish 0.3.2
Veykril Oct 23, 2024
3100e01
Fix lints
alexheretic Sep 14, 2025
d1ebc65
Merge pull request rust-analyzer/smol_str#99 from alexheretic/fix-lints
lnicola Sep 15, 2025
2780b2c
Use serde_core over serde
james7132 Sep 22, 2025
618bc27
Optimise to_ascii_{upper,lower}case_smolstr
alexheretic Sep 13, 2025
7b1f42c
Update changelog
alexheretic Sep 14, 2025
11b618e
Add SmolStr vs String benchmarks
alexheretic Sep 13, 2025
843416f
Only bench smol_str stuff
alexheretic Sep 13, 2025
9c7c502
CI: Add TEST_BENCHES
alexheretic Sep 14, 2025
54647b0
Optimise `to_{lower,upper}case_smolstr`
alexheretic Sep 14, 2025
3050661
Update changelog
alexheretic Sep 14, 2025
eae01f8
Add test from_buf_and_chars_size_hinted_heap & fix
alexheretic Sep 15, 2025
6af6169
Optimise replacen_smolstr for single ascii replace
alexheretic Sep 15, 2025
63cf0b8
Optimise replacen 1-ascii when count >= len
alexheretic Sep 15, 2025
4cc0d91
Mark replacen_1_ascii as unsafe
alexheretic Sep 15, 2025
c9d3188
Update changelog
alexheretic Sep 15, 2025
9d0d73d
Publish 0.3.3
Veykril Oct 23, 2025
b0eee7d
Publish 0.3.4
Veykril Oct 23, 2025
150ef00
fix: Fix panicking while resolving callable sigs for `AsyncFnMut`
ShoyuVanilla Nov 4, 2025
45db7ad
Merge pull request #20971 from ShoyuVanilla/async-fn-sig
ChayimFriedman2 Nov 4, 2025
724b9a5
fix demorgan assist to handle method call
Natural-selection1 Nov 5, 2025
1d4efff
Move safe computation out of unsafe block
chirizxc Nov 6, 2025
41c28b5
Merge pull request #20977 from chirizxc/patch-1
lnicola Nov 6, 2025
8a88c92
refactor
Natural-selection1 Nov 6, 2025
2b05436
Merge pull request #20973 from Natural-selection1/demorgan
Veykril Nov 6, 2025
3fb6d22
implement `Clone` for `Rule`
aDotInTheVoid Jun 29, 2023
0064a83
Merge remote-tracking branch 'ungrammar/master' into rebuild-master-a…
lnicola Nov 15, 2025
9698369
Merge remote-tracking branch 'text-size/master' into rebuild-master-a…
lnicola Nov 15, 2025
35c23cd
Merge remote-tracking branch 'smol_str/master' into rebuild-master-again
lnicola Nov 15, 2025
dad1224
Update Cargo.toml and lockfile
Veykril Nov 7, 2025
1c00a2a
Reformat
Veykril Nov 7, 2025
7750e50
Reformat
Veykril Nov 7, 2025
219268d
Reformat
Veykril Nov 7, 2025
a7e4e45
Merge pull request #21002 from Veykril/veykril/push-nztxvpnntmrx
Veykril Nov 9, 2025
aebaa6d
Merge pull request #20994 from Veykril/push-npvyklkuxnlr
Veykril Nov 8, 2025
960e4dc
Merge pull request #20995 from Veykril/push-kysxxnruzslp
Veykril Nov 8, 2025
68e380b
Merge pull request #20909 from taj-p/master
Veykril Nov 9, 2025
86d9421
Merge pull request #20997 from Veykril/push-zsuorxrkpupr
Veykril Nov 9, 2025
70c49a4
Merge pull request #21005 from fgamador/book-testing
ChayimFriedman2 Nov 9, 2025
3b7d1b8
Merge pull request #21003 from A4-Tacks/missing-curly-postfix-with-mo…
ShoyuVanilla Nov 10, 2025
71f983a
Merge pull request #20972 from A4-Tacks/impl-never-type
ShoyuVanilla Nov 10, 2025
2ea2c53
Merge pull request #20542 from A4-Tacks/if-let-to-match-guard
ShoyuVanilla Nov 10, 2025
e75b572
Merge pull request #20985 from Natural-selection1/rename
ChayimFriedman2 Nov 10, 2025
ef17e58
Merge pull request #21007 from joe-p/feat/more_param_names
ChayimFriedman2 Nov 10, 2025
dde4b6c
Merge pull request #21021 from A4-Tacks/lib-smol_str-doc-feature
ChayimFriedman2 Nov 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
568 changes: 542 additions & 26 deletions src/tools/rust-analyzer/Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["xtask/", "lib/*", "crates/*"]
members = ["xtask/", "lib/*", "lib/ungrammar/ungrammar2json", "crates/*"]
exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
resolver = "2"

Expand Down Expand Up @@ -42,7 +42,7 @@ debug = 2
# lsp-server = { path = "lib/lsp-server" }


# ungrammar = { path = "../ungrammar" }
# ungrammar = { path = "lin/ungrammar" }

# salsa = { path = "../salsa" }
# salsa-macros = { path = "../salsa/components/salsa-macros" }
Expand Down
5 changes: 4 additions & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,13 @@ impl<'db> InferenceTable<'db> {
let args = [ty, arg_ty];
let trait_ref = TraitRef::new(self.interner(), fn_trait.into(), args);

let proj_args = self
.infer_ctxt
.fill_rest_fresh_args(output_assoc_type.into(), args.into_iter().map(Into::into));
let projection = Ty::new_alias(
self.interner(),
rustc_type_ir::AliasTyKind::Projection,
AliasTy::new(self.interner(), output_assoc_type.into(), args),
AliasTy::new(self.interner(), output_assoc_type.into(), proj_args),
);

let pred = Predicate::upcast_from(trait_ref, self.interner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,31 @@ fn g(it: *const (dyn Trait)) {
"#,
);
}

#[test]
fn regression_20951() {
check_infer(
r#"
//- minicore: async_fn
trait DoesSomething {
fn do_something(&self) -> impl Future<Output = usize>;
}

impl<F> DoesSomething for F
where
F: AsyncFn() -> usize,
{
fn do_something(&self) -> impl Future<Output = usize> {
self()
}
}
"#,
expect![[r#"
43..47 'self': &'? Self
168..172 'self': &'? F
205..227 '{ ... }': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
215..219 'self': &'? F
215..221 'self()': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
"#]],
);
}
7 changes: 5 additions & 2 deletions src/tools/rust-analyzer/crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub mod term_search;

mod display;

#[doc(hidden)]
pub use hir_def::ModuleId;

use std::{
fmt,
mem::discriminant,
Expand All @@ -48,8 +51,8 @@ use hir_def::{
AdtId, AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId,
CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId,
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, SyntheticSyntax,
TupleId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
LocalFieldId, Lookup, MacroExpander, MacroId, StaticId, StructId, SyntheticSyntax, TupleId,
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
expr_store::{ExpressionStoreDiagnostics, ExpressionStoreSourceMap},
hir::{
BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, LabelId, Pat,
Expand Down
54 changes: 39 additions & 15 deletions src/tools/rust-analyzer/crates/hir/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use hir_ty::{
};
use intern::Symbol;
use rustc_hash::FxHashMap;
use syntax::{AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};
use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};

use crate::{HasCrate, Module, ModuleDef, Semantics};

Expand All @@ -29,7 +29,7 @@ pub struct FileSymbol {
pub name: Symbol,
pub def: ModuleDef,
pub loc: DeclarationLocation,
pub container_name: Option<SmolStr>,
pub container_name: Option<Symbol>,
/// Whether this symbol is a doc alias for the original symbol.
pub is_alias: bool,
pub is_assoc: bool,
Expand Down Expand Up @@ -65,23 +65,29 @@ pub struct SymbolCollector<'a> {
db: &'a dyn HirDatabase,
symbols: FxIndexSet<FileSymbol>,
work: Vec<SymbolCollectorWork>,
current_container_name: Option<SmolStr>,
current_container_name: Option<Symbol>,
collect_pub_only: bool,
}

/// Given a [`ModuleId`] and a [`HirDatabase`], use the DefMap for the module's crate to collect
/// all symbols that should be indexed for the given module.
impl<'a> SymbolCollector<'a> {
pub fn new(db: &'a dyn HirDatabase) -> Self {
pub fn new(db: &'a dyn HirDatabase, collect_pub_only: bool) -> Self {
SymbolCollector {
db,
symbols: Default::default(),
work: Default::default(),
current_container_name: None,
collect_pub_only,
}
}

pub fn new_module(db: &dyn HirDatabase, module: Module) -> Box<[FileSymbol]> {
let mut symbol_collector = SymbolCollector::new(db);
pub fn new_module(
db: &dyn HirDatabase,
module: Module,
collect_pub_only: bool,
) -> Box<[FileSymbol]> {
let mut symbol_collector = SymbolCollector::new(db, collect_pub_only);
symbol_collector.collect(module);
symbol_collector.finish()
}
Expand All @@ -108,12 +114,16 @@ impl<'a> SymbolCollector<'a> {
tracing::info!(?work, "SymbolCollector::do_work");
self.db.unwind_if_revision_cancelled();

let parent_name = work.parent.map(|name| name.as_str().to_smolstr());
let parent_name = work.parent.map(|name| Symbol::intern(name.as_str()));
self.with_container_name(parent_name, |s| s.collect_from_module(work.module_id));
}

fn collect_from_module(&mut self, module_id: ModuleId) {
let push_decl = |this: &mut Self, def, name| {
let collect_pub_only = self.collect_pub_only;
let push_decl = |this: &mut Self, def: ModuleDefId, name, vis| {
if collect_pub_only && vis != Visibility::Public {
return;
}
match def {
ModuleDefId::ModuleId(id) => this.push_module(id, name),
ModuleDefId::FunctionId(id) => {
Expand All @@ -125,7 +135,7 @@ impl<'a> SymbolCollector<'a> {
}
ModuleDefId::AdtId(AdtId::EnumId(id)) => {
this.push_decl(id, name, false, None);
let enum_name = this.db.enum_signature(id).name.as_str().to_smolstr();
let enum_name = Symbol::intern(this.db.enum_signature(id).name.as_str());
this.with_container_name(Some(enum_name), |this| {
let variants = id.enum_variants(this.db);
for (variant_id, variant_name, _) in &variants.variants {
Expand Down Expand Up @@ -175,6 +185,9 @@ impl<'a> SymbolCollector<'a> {
};

let mut push_import = |this: &mut Self, i: ImportId, name: &Name, def: ModuleDefId, vis| {
if collect_pub_only && vis != Visibility::Public {
return;
}
let source = import_child_source_cache
.entry(i.use_)
.or_insert_with(|| i.use_.child_source(this.db));
Expand Down Expand Up @@ -209,6 +222,9 @@ impl<'a> SymbolCollector<'a> {

let push_extern_crate =
|this: &mut Self, i: ExternCrateId, name: &Name, def: ModuleDefId, vis| {
if collect_pub_only && vis != Visibility::Public {
return;
}
let loc = i.lookup(this.db);
let source = loc.source(this.db);
let rename = source.value.rename().and_then(|rename| rename.name());
Expand Down Expand Up @@ -258,7 +274,7 @@ impl<'a> SymbolCollector<'a> {
continue;
}
// self is a declaration
push_decl(self, def, name)
push_decl(self, def, name, vis)
}

for (name, Item { def, vis, import }) in scope.macros() {
Expand All @@ -271,7 +287,7 @@ impl<'a> SymbolCollector<'a> {
continue;
}
// self is a declaration
push_decl(self, def.into(), name)
push_decl(self, ModuleDefId::MacroId(def), name, vis)
}

for (name, Item { def, vis, import }) in scope.values() {
Expand All @@ -283,7 +299,7 @@ impl<'a> SymbolCollector<'a> {
continue;
}
// self is a declaration
push_decl(self, def, name)
push_decl(self, def, name, vis)
}

for const_id in scope.unnamed_consts() {
Expand All @@ -304,6 +320,9 @@ impl<'a> SymbolCollector<'a> {
}

fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>, name: Option<Name>) {
if self.collect_pub_only {
return;
}
let body_id = body_id.into();
let body = self.db.body(body_id);

Expand All @@ -328,23 +347,28 @@ impl<'a> SymbolCollector<'a> {
)
.to_smolstr(),
);
self.with_container_name(impl_name, |s| {
self.with_container_name(impl_name.as_deref().map(Symbol::intern), |s| {
for &(ref name, assoc_item_id) in &impl_id.impl_items(self.db).items {
if s.collect_pub_only && s.db.assoc_visibility(assoc_item_id) != Visibility::Public
{
continue;
}

s.push_assoc_item(assoc_item_id, name, None)
}
})
}

fn collect_from_trait(&mut self, trait_id: TraitId, trait_do_not_complete: Complete) {
let trait_data = self.db.trait_signature(trait_id);
self.with_container_name(Some(trait_data.name.as_str().into()), |s| {
self.with_container_name(Some(Symbol::intern(trait_data.name.as_str())), |s| {
for &(ref name, assoc_item_id) in &trait_id.trait_items(self.db).items {
s.push_assoc_item(assoc_item_id, name, Some(trait_do_not_complete));
}
});
}

fn with_container_name(&mut self, container_name: Option<SmolStr>, f: impl FnOnce(&mut Self)) {
fn with_container_name(&mut self, container_name: Option<Symbol>, f: impl FnOnce(&mut Self)) {
if let Some(container_name) = container_name {
let prev = self.current_container_name.replace(container_name);
f(self);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use ide_db::syntax_helpers::node_ext::for_each_break_and_continue_expr;
use ide_db::{
source_change::SourceChangeBuilder, syntax_helpers::node_ext::for_each_break_and_continue_expr,
};
use syntax::{
T,
ast::{self, AstNode, HasLoopBody},
SyntaxToken, T,
ast::{
self, AstNode, HasLoopBody,
make::{self, tokens},
syntax_factory::SyntaxFactory,
},
syntax_editor::{Position, SyntaxEditor},
};

use crate::{AssistContext, AssistId, Assists};
Expand All @@ -21,9 +28,9 @@ use crate::{AssistContext, AssistId, Assists};
// ->
// ```
// fn main() {
// 'l: loop {
// break 'l;
// continue 'l;
// ${1:'l}: loop {
// break ${2:'l};
// continue ${0:'l};
// }
// }
// ```
Expand All @@ -39,30 +46,56 @@ pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
"Add Label",
loop_expr.syntax().text_range(),
|builder| {
builder.insert(loop_kw.text_range().start(), "'l: ");
let make = SyntaxFactory::with_mappings();
let mut editor = builder.make_editor(loop_expr.syntax());

let label = make.lifetime("'l");
let elements = vec![
label.syntax().clone().into(),
make::token(T![:]).into(),
tokens::single_space().into(),
];
editor.insert_all(Position::before(&loop_kw), elements);

if let Some(cap) = ctx.config.snippet_cap {
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet(cap));
}

let loop_body = loop_expr.loop_body().and_then(|it| it.stmt_list());
for_each_break_and_continue_expr(
loop_expr.label(),
loop_body,
&mut |expr| match expr {
ast::Expr::BreakExpr(break_expr) => {
if let Some(break_token) = break_expr.break_token() {
builder.insert(break_token.text_range().end(), " 'l")
}
}
ast::Expr::ContinueExpr(continue_expr) => {
if let Some(continue_token) = continue_expr.continue_token() {
builder.insert(continue_token.text_range().end(), " 'l")
}
}
_ => {}
},
);
for_each_break_and_continue_expr(loop_expr.label(), loop_body, &mut |expr| {
let token = match expr {
ast::Expr::BreakExpr(break_expr) => break_expr.break_token(),
ast::Expr::ContinueExpr(continue_expr) => continue_expr.continue_token(),
_ => return,
};
if let Some(token) = token {
insert_label_after_token(&mut editor, &make, &token, ctx, builder);
}
});

editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
builder.rename();
},
)
}

fn insert_label_after_token(
editor: &mut SyntaxEditor,
make: &SyntaxFactory,
token: &SyntaxToken,
ctx: &AssistContext<'_>,
builder: &mut SourceChangeBuilder,
) {
let label = make.lifetime("'l");
let elements = vec![tokens::single_space().into(), label.syntax().clone().into()];
editor.insert_all(Position::after(token), elements);

if let Some(cap) = ctx.config.snippet_cap {
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet(cap));
}
}

#[cfg(test)]
mod tests {
use crate::tests::{check_assist, check_assist_not_applicable};
Expand All @@ -82,9 +115,9 @@ fn main() {
}"#,
r#"
fn main() {
'l: loop {
break 'l;
continue 'l;
${1:'l}: loop {
break ${2:'l};
continue ${0:'l};
}
}"#,
);
Expand All @@ -107,9 +140,9 @@ fn main() {
}"#,
r#"
fn main() {
'l: loop {
break 'l;
continue 'l;
${1:'l}: loop {
break ${2:'l};
continue ${0:'l};
loop {
break;
continue;
Expand Down Expand Up @@ -139,9 +172,9 @@ fn main() {
loop {
break;
continue;
'l: loop {
break 'l;
continue 'l;
${1:'l}: loop {
break ${2:'l};
continue ${0:'l};
}
}
}"#,
Expand Down
Loading
Loading