Skip to content

Commit c635d7e

Browse files
authored
Merge pull request rust-lang#18835 from Veykril/push-wnmwwoktmpyt
Hide synthetic locals from completions
2 parents bfafdd9 + 28b0a95 commit c635d7e

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,17 @@ pub(crate) fn complete_expr_path(
293293
[..] => acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases),
294294
}
295295
}
296+
// synthetic names currently leak out as we lack synthetic hygiene, so filter them
297+
// out here
298+
ScopeDef::Local(_) => {
299+
if !name.as_str().starts_with('<') {
300+
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases)
301+
}
302+
}
296303
_ if scope_def_applicable(def) => {
297304
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases)
298305
}
306+
299307
_ => (),
300308
});
301309

src/tools/rust-analyzer/crates/ide-completion/src/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,11 @@ impl<'a> CompletionContext<'a> {
754754
let mut locals = FxHashMap::default();
755755
scope.process_all_names(&mut |name, scope| {
756756
if let ScopeDef::Local(local) = scope {
757+
// synthetic names currently leak out as we lack synthetic hygiene, so filter them
758+
// out here
759+
if name.as_str().starts_with('<') {
760+
return;
761+
}
757762
locals.insert(name, local);
758763
}
759764
});

src/tools/rust-analyzer/crates/ide-completion/src/tests/expression.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,3 +1785,75 @@ fn foo<T: ExcludedTrait>() {
17851785
"#]],
17861786
);
17871787
}
1788+
1789+
#[test]
1790+
fn hide_ragennew_synthetic_identifiers() {
1791+
check_empty(
1792+
r#"
1793+
//- minicore: iterator
1794+
fn bar() {
1795+
for i in [0; 10] {
1796+
r$0
1797+
}
1798+
}
1799+
"#,
1800+
expect![[r#"
1801+
en Option Option<{unknown}>
1802+
en Result Result<{unknown}, {unknown}>
1803+
fn bar() fn()
1804+
lc i i32
1805+
ma const_format_args!(…) macro_rules! const_format_args
1806+
ma format_args!(…) macro_rules! format_args
1807+
ma format_args_nl!(…) macro_rules! format_args_nl
1808+
ma panic!(…) macro_rules! panic
1809+
ma print!(…) macro_rules! print
1810+
md core
1811+
md result (use core::result)
1812+
md rust_2015 (use core::prelude::rust_2015)
1813+
md rust_2018 (use core::prelude::rust_2018)
1814+
md rust_2021 (use core::prelude::rust_2021)
1815+
tt Clone
1816+
tt Copy
1817+
tt IntoIterator
1818+
tt Iterator
1819+
ta Result (use core::fmt::Result)
1820+
ev Err(…) Err(E)
1821+
ev None None
1822+
ev Ok(…) Ok(T)
1823+
ev Some(…) Some(T)
1824+
bt u32 u32
1825+
kw async
1826+
kw break
1827+
kw const
1828+
kw continue
1829+
kw crate::
1830+
kw enum
1831+
kw extern
1832+
kw false
1833+
kw fn
1834+
kw for
1835+
kw if
1836+
kw if let
1837+
kw impl
1838+
kw let
1839+
kw loop
1840+
kw match
1841+
kw mod
1842+
kw return
1843+
kw self::
1844+
kw static
1845+
kw struct
1846+
kw trait
1847+
kw true
1848+
kw type
1849+
kw union
1850+
kw unsafe
1851+
kw use
1852+
kw while
1853+
kw while let
1854+
sn macro_rules
1855+
sn pd
1856+
sn ppd
1857+
"#]],
1858+
);
1859+
}

0 commit comments

Comments
 (0)