Skip to content

⬆️ rust-analyzer #100049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e45a250
fix: Insert spaces when inlining a function defined in a macro.
zachs18 Jul 25, 2022
b1e3daf
Find standalone proc-macro-srv on windows too
fasterthanlime Jul 26, 2022
1c75284
Auto merge of #12878 - fasterthanlime:standalone-pms-exe, r=lnicola
bors Jul 26, 2022
c8ff70e
fix: Fix server panicking on project loading when proc-macros are dis…
Veykril Jul 26, 2022
7a30f62
Auto merge of #12881 - Veykril:proc-srv, r=Veykril
bors Jul 26, 2022
add33b6
Remove FIXME comment for unreachable fallback.
zachs18 Jul 26, 2022
c2eebd7
Auto merge of #12877 - zachs18:inline-def-in-macro, r=zachs18
bors Jul 26, 2022
6c379b9
fix: Fix Semantics::original_ast_node not caching the resulting file
Veykril Jul 27, 2022
8e4d9b8
Auto merge of #12886 - Veykril:sema-cache, r=Veykril
bors Jul 27, 2022
1f8daa1
fix: Honor ref expressions for compute_ref_match completions
Veykril Jul 27, 2022
cb32e26
Auto merge of #12887 - Veykril:compl-pref-fix, r=Veykril
bors Jul 27, 2022
349dfc7
Find original ast node before compute ref match in fn render
0xPoe Jul 27, 2022
b4d652a
Auto merge of #12830 - hi-rustin:rustin-patch-issue-12717-fix, r=Veykril
bors Jul 27, 2022
bf893d5
internal: Assume condition/iterable is missing if there is only a Blo…
Veykril Jul 27, 2022
9a1ec45
Auto merge of #12890 - Veykril:syntax-blocks, r=Veykril
bors Jul 27, 2022
f83738e
Use large stack on expander thread
umanwizard Jul 27, 2022
4087535
Auto merge of #12891 - brennanvincent:expander_stack, r=lnicola
bors Jul 27, 2022
e782e59
fix: Calculate completions after type anchors
Veykril Jul 28, 2022
02f9ec4
Auto merge of #12895 - Veykril:compl-anchor, r=Veykril
bors Jul 28, 2022
7c59d7c
fix: Fix pattern completions adding unnecessary braces
Veykril Jul 28, 2022
02c240f
Auto merge of #12898 - Veykril:compl-pat-brace, r=Veykril
bors Jul 28, 2022
74abd44
fix: Do completions in path qualifier position
Veykril Jul 28, 2022
5986d21
Auto merge of #12899 - Veykril:compl-qualifier, r=Veykril
bors Jul 28, 2022
8658425
publish: Use cargo ws rename to rename crates
pksunkara Jul 28, 2022
af2b806
Auto merge of #12900 - pksunkara:master, r=lnicola
bors Jul 28, 2022
ce75412
fix: Don't complete marker traits in expression position
Veykril Jul 28, 2022
32e640e
Auto merge of #12901 - Veykril:completion-trait-expr, r=Veykril
bors Jul 28, 2022
f867ddc
fix: Order ItemScope::entries results
Veykril Jul 28, 2022
b8763fe
Auto merge of #12902 - Veykril:item-scope, r=Veykril
bors Jul 28, 2022
948c9af
Only run rainbow highlighting test on 64-bit Unix
lnicola Jul 28, 2022
cab1055
Auto merge of #12903 - lnicola:rainbows, r=Veykril
bors Jul 28, 2022
11ef494
Be more explicit when filtering built-in completions
lnicola Jul 28, 2022
ec3586e
Auto merge of #12904 - lnicola:completion-builtin-filter, r=lnicola
bors Jul 28, 2022
902fd6d
fix: complete path of existing record expr
cynecx Jul 29, 2022
fb5e496
Auto merge of #12906 - cynecx:fix-completions, r=Veykril
bors Jul 29, 2022
618cfd7
fix: Fix ast-id up when merging raw attributes
Veykril Jul 30, 2022
e0ff4be
Auto merge of #12913 - Veykril:attr-merge, r=Veykril
bors Jul 30, 2022
58c3a56
Update xtask promote and release instructions
lnicola Jul 31, 2022
d31f360
Properly cfg the `max` field of Limit
Veykril Jul 31, 2022
3b2ecf4
Give variables more descriptive names
Veykril Jul 31, 2022
af64662
Auto merge of #12916 - Veykril:nits, r=Veykril
bors Jul 31, 2022
2b472f6
Auto merge of #12915 - lnicola:promote-subtree, r=lnicola
bors Jul 31, 2022
30a3706
:arrow_up: rust-analyzer
lnicola Aug 2, 2022
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
17 changes: 15 additions & 2 deletions src/tools/rust-analyzer/.github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,21 @@ jobs:
git config --global user.email "[email protected]"
git config --global user.name "Github Action"
rm Cargo.lock
# Fix names for crates that were published before switch to kebab-case.
cargo workspaces rename --from base-db base_db
cargo workspaces rename --from hir-def hir_def
cargo workspaces rename --from hir-expand hir_expand
cargo workspaces rename --from hir-ty hir_ty
cargo workspaces rename --from ide-assists ide_assists
cargo workspaces rename --from ide-completion ide_completion
cargo workspaces rename --from ide-db ide_db
cargo workspaces rename --from ide-diagnostics ide_diagnostics
cargo workspaces rename --from ide-ssr ide_ssr
cargo workspaces rename --from proc-macro-api proc_macro_api
cargo workspaces rename --from proc-macro-srv proc_macro_srv
cargo workspaces rename --from project-model project_model
cargo workspaces rename --from test-utils test_utils
cargo workspaces rename --from text-edit text_edit
cargo workspaces rename ra_ap_%n
find crates/rust-analyzer -type f -name '*.rs' -exec sed -i 's/rust_analyzer/ra_ap_rust_analyzer/g' {} +
# Fix names for crates that were published before switch to kebab-case.
find crates -name 'Cargo.toml' -exec sed -i "s/ra_ap_base-db/ra_ap_base_db/g; s/ra_ap_hir-def/ra_ap_hir_def/g; s/ra_ap_hir-expand/ra_ap_hir_expand/g; s/ra_ap_hir-ty/ra_ap_hir_ty/g; s/ra_ap_ide-assists/ra_ap_ide_assists/g; s/ra_ap_ide-completion/ra_ap_ide_completion/g; s/ra_ap_ide-db/ra_ap_ide_db/g; s/ra_ap_ide-diagnostics/ra_ap_ide_diagnostics/g; s/ra_ap_ide-ssr/ra_ap_ide_ssr/g; s/ra_ap_proc-macro-api/ra_ap_proc_macro_api/g; s/ra_ap_proc-macro-srv/ra_ap_proc_macro_srv/g; s/ra_ap_project-model/ra_ap_project_model/g; s/ra_ap_test-utils/ra_ap_test_utils/g; s/ra_ap_text-edit/ra_ap_text_edit/g" {} +
cargo workspaces publish --yes --force '*' --exact --no-git-commit --allow-dirty --skip-published custom 0.0.$PATCH
21 changes: 16 additions & 5 deletions src/tools/rust-analyzer/crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,24 @@ impl RawAttrs {

pub(crate) fn merge(&self, other: Self) -> Self {
// FIXME: This needs to fixup `AttrId`s
match (&self.entries, &other.entries) {
match (&self.entries, other.entries) {
(None, None) => Self::EMPTY,
(Some(entries), None) | (None, Some(entries)) => {
Self { entries: Some(entries.clone()) }
}
(None, entries @ Some(_)) => Self { entries },
(Some(entries), None) => Self { entries: Some(entries.clone()) },
(Some(a), Some(b)) => {
Self { entries: Some(a.iter().chain(b.iter()).cloned().collect()) }
let last_ast_index = a.last().map_or(0, |it| it.id.ast_index + 1);
Self {
entries: Some(
a.iter()
.cloned()
.chain(b.iter().map(|it| {
let mut it = it.clone();
it.id.ast_index += last_ast_index;
it
}))
.collect(),
),
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::collections::hash_map::Entry;

use base_db::CrateId;
use hir_expand::{name::Name, AstId, MacroCallId};
use itertools::Itertools;
use once_cell::sync::Lazy;
use profile::Count;
use rustc_hash::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -97,15 +98,14 @@ pub(crate) enum BuiltinShadowMode {
impl ItemScope {
pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, PerNs)> + 'a {
// FIXME: shadowing
let keys: FxHashSet<_> = self
.types
self.types
.keys()
.chain(self.values.keys())
.chain(self.macros.keys())
.chain(self.unresolved.iter())
.collect();

keys.into_iter().map(move |name| (name, self.get(name)))
.sorted()
.unique()
.map(move |name| (name, self.get(name)))
}

pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ {
Expand Down
13 changes: 7 additions & 6 deletions src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ impl DefCollector<'_> {
};
let mut res = ReachedFixedPoint::Yes;
macros.retain(|directive| {
let resolver2 = |path| {
let resolver = |path| {
let resolved_res = self.def_map.resolve_path_fp_with_macro(
self.db,
ResolveMode::Other,
Expand All @@ -1068,7 +1068,7 @@ impl DefCollector<'_> {
.take_macros()
.map(|it| (it, macro_id_to_def_id(self.db, it)))
};
let resolver = |path| resolver2(path).map(|(_, it)| it);
let resolver_def_id = |path| resolver(path).map(|(_, it)| it);

match &directive.kind {
MacroDirectiveKind::FnLike { ast_id, expand_to } => {
Expand All @@ -1077,7 +1077,7 @@ impl DefCollector<'_> {
ast_id,
*expand_to,
self.def_map.krate,
&resolver,
&resolver_def_id,
&mut |_err| (),
);
if let Ok(Ok(call_id)) = call_id {
Expand All @@ -1093,7 +1093,7 @@ impl DefCollector<'_> {
*derive_attr,
*derive_pos as u32,
self.def_map.krate,
&resolver2,
&resolver,
);

if let Ok((macro_id, def_id, call_id)) = id {
Expand Down Expand Up @@ -1158,7 +1158,7 @@ impl DefCollector<'_> {
}
}

let def = match resolver(path.clone()) {
let def = match resolver_def_id(path.clone()) {
Some(def) if def.is_attribute() => def,
_ => return true,
};
Expand Down Expand Up @@ -1292,7 +1292,8 @@ impl DefCollector<'_> {
true
});
// Attribute resolution can add unresolved macro invocations, so concatenate the lists.
self.unresolved_macros.extend(macros);
macros.extend(mem::take(&mut self.unresolved_macros));
self.unresolved_macros = macros;

for (module_id, depth, container, macro_call_id) in resolved {
self.collect_macro_expansion(module_id, macro_call_id, depth, container);
Expand Down
5 changes: 5 additions & 0 deletions src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub trait TyExt {
fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig>;

fn strip_references(&self) -> &Ty;
fn strip_reference(&self) -> &Ty;

/// If this is a `dyn Trait`, returns that trait.
fn dyn_trait(&self) -> Option<TraitId>;
Expand Down Expand Up @@ -182,6 +183,10 @@ impl TyExt for Ty {
t
}

fn strip_reference(&self) -> &Ty {
self.as_reference().map_or(self, |(ty, _, _)| ty)
}

fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>> {
match self.kind(Interner) {
TyKind::OpaqueType(opaque_ty_id, subst) => {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/rust-analyzer/crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,10 @@ impl Type {
self.derived(self.ty.strip_references().clone())
}

pub fn strip_reference(&self) -> Type {
self.derived(self.ty.strip_reference().clone())
}

pub fn is_unknown(&self) -> bool {
self.ty.is_unknown()
}
Expand Down
25 changes: 24 additions & 1 deletion src/tools/rust-analyzer/crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
self.imp.resolve_type(ty)
}

pub fn resolve_trait(&self, trait_: &ast::Path) -> Option<Trait> {
self.imp.resolve_trait(trait_)
}

// FIXME: Figure out a nice interface to inspect adjustments
pub fn is_implicit_reborrow(&self, expr: &ast::Expr) -> Option<Mutability> {
self.imp.is_implicit_reborrow(expr)
Expand Down Expand Up @@ -924,7 +928,12 @@ impl<'db> SemanticsImpl<'db> {
}

fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map(|it| it.value)
self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map(
|InFile { file_id, value }| {
self.cache(find_root(value.syntax()), file_id);
value
},
)
}

fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange {
Expand Down Expand Up @@ -1009,6 +1018,20 @@ impl<'db> SemanticsImpl<'db> {
Some(Type::new_with_resolver(self.db, &analyze.resolver, ty))
}

fn resolve_trait(&self, path: &ast::Path) -> Option<Trait> {
let analyze = self.analyze(path.syntax())?;
let hygiene = hir_expand::hygiene::Hygiene::new(self.db.upcast(), analyze.file_id);
let ctx = body::LowerCtx::with_hygiene(self.db.upcast(), &hygiene);
let hir_path = Path::from_src(path.clone(), &ctx)?;
match analyze
.resolver
.resolve_path_in_type_ns_fully(self.db.upcast(), hir_path.mod_path())?
{
TypeNs::TraitId(id) => Some(Trait { id }),
_ => None,
}
}

fn is_implicit_reborrow(&self, expr: &ast::Expr) -> Option<Mutability> {
self.analyze(expr.syntax())?.is_implicit_reborrow(self.db, expr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
// pub struct Baz;
// }
//
// use foo::{Baz, Bar};
// use foo::{Bar, Baz};
//
// fn qux(bar: Bar, baz: Baz) {}
// ```
Expand Down Expand Up @@ -281,7 +281,7 @@ mod foo {
pub fn f() {}
}

use foo::{Baz, Bar, f};
use foo::{Bar, Baz, f};

fn qux(bar: Bar, baz: Baz) {
f();
Expand Down Expand Up @@ -351,7 +351,7 @@ mod foo {
pub fn f() {}
}

use foo::{Baz, Bar, f};
use foo::{Bar, Baz, f};

fn qux(bar: Bar, baz: Baz) {
f();
Expand Down Expand Up @@ -440,7 +440,7 @@ mod foo {
}
}

use foo::{bar::{Baz, Bar, f}, baz::*};
use foo::{bar::{Bar, Baz, f}, baz::*};

fn qux(bar: Bar, baz: Baz) {
f();
Expand Down Expand Up @@ -561,7 +561,7 @@ mod foo {

use foo::{
bar::{*, f},
baz::{g, qux::{q, h}}
baz::{g, qux::{h, q}}
};

fn qux(bar: Bar, baz: Baz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ide_db::{
imports::insert_use::remove_path_if_in_use_stmt,
path_transform::PathTransform,
search::{FileReference, SearchScope},
syntax_helpers::node_ext::expr_as_name_ref,
syntax_helpers::{insert_whitespace_into_node::insert_ws_into, node_ext::expr_as_name_ref},
RootDatabase,
};
use itertools::{izip, Itertools};
Expand Down Expand Up @@ -301,7 +301,16 @@ fn inline(
params: &[(ast::Pat, Option<ast::Type>, hir::Param)],
CallInfo { node, arguments, generic_arg_list }: &CallInfo,
) -> ast::Expr {
let body = fn_body.clone_for_update();
let body = if sema.hir_file_for(fn_body.syntax()).is_macro() {
cov_mark::hit!(inline_call_defined_in_macro);
if let Some(body) = ast::BlockExpr::cast(insert_ws_into(fn_body.syntax().clone())) {
body
} else {
fn_body.clone_for_update()
}
} else {
fn_body.clone_for_update()
};
let usages_for_locals = |local| {
Definition::Local(local)
.usages(sema)
Expand Down Expand Up @@ -1144,6 +1153,41 @@ fn bar() -> u32 {
x
}) + foo()
}
"#,
)
}

#[test]
fn inline_call_defined_in_macro() {
cov_mark::check!(inline_call_defined_in_macro);
check_assist(
inline_call,
r#"
macro_rules! define_foo {
() => { fn foo() -> u32 {
let x = 0;
x
} };
}
define_foo!();
fn bar() -> u32 {
foo$0()
}
"#,
r#"
macro_rules! define_foo {
() => { fn foo() -> u32 {
let x = 0;
x
} };
}
define_foo!();
fn bar() -> u32 {
{
let x = 0;
x
}
}
"#,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ mod foo {
pub struct Baz;
}

use foo::{Baz, Bar};
use foo::{Bar, Baz};

fn qux(bar: Bar, baz: Baz) {}
"#####,
Expand Down
13 changes: 11 additions & 2 deletions src/tools/rust-analyzer/crates/ide-completion/src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl Completions {
) {
if let PathCompletionCtx { kind: PathKind::Pat { pat_ctx }, .. } = path_ctx {
cov_mark::hit!(enum_variant_pattern_path);
self.add_variant_pat(ctx, pat_ctx, variant, local_name);
self.add_variant_pat(ctx, pat_ctx, Some(path_ctx), variant, local_name);
return;
}

Expand Down Expand Up @@ -484,12 +484,14 @@ impl Completions {
&mut self,
ctx: &CompletionContext<'_>,
pattern_ctx: &PatternContext,
path_ctx: Option<&PathCompletionCtx>,
variant: hir::Variant,
local_name: Option<hir::Name>,
) {
self.add_opt(render_variant_pat(
RenderContext::new(ctx),
pattern_ctx,
path_ctx,
variant,
local_name.clone(),
None,
Expand All @@ -504,7 +506,14 @@ impl Completions {
path: hir::ModPath,
) {
let path = Some(&path);
self.add_opt(render_variant_pat(RenderContext::new(ctx), pattern_ctx, variant, None, path));
self.add_opt(render_variant_pat(
RenderContext::new(ctx),
pattern_ctx,
None,
variant,
None,
path,
));
}

pub(crate) fn add_struct_pat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub(crate) fn complete_attribute_path(
});
acc.add_nameref_keywords_with_colon(ctx);
}
Qualified::Infer | Qualified::With { .. } => {}
Qualified::TypeAnchor { .. } | Qualified::With { .. } => {}
}

let attributes = annotated_item_kind.and_then(|kind| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub(crate) fn complete_derive_path(
});
acc.add_nameref_keywords_with_colon(ctx);
}
Qualified::Infer | Qualified::With { .. } => {}
Qualified::TypeAnchor { .. } | Qualified::With { .. } => {}
}
}

Expand Down
Loading