Skip to content

Commit 33422e7

Browse files
committed
Auto merge of #126865 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents aabbf84 + 70e9582 commit 33422e7

File tree

284 files changed

+8852
-4803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+8852
-4803
lines changed

src/tools/rust-analyzer/.cargo/config.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ tq = "test -- -q"
44
qt = "tq"
55
lint = "clippy --all-targets -- --cap-lints warn"
66
codegen = "run --package xtask --bin xtask -- codegen"
7+
dist = "run --package xtask --bin xtask -- dist"
78

89
[target.x86_64-pc-windows-msvc]
910
linker = "rust-lld"

src/tools/rust-analyzer/Cargo.lock

+13-2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ dependencies = [
328328
"dirs-sys",
329329
]
330330

331+
[[package]]
332+
name = "dirs"
333+
version = "5.0.1"
334+
source = "registry+https://github.com/rust-lang/crates.io-index"
335+
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
336+
dependencies = [
337+
"dirs-sys",
338+
]
339+
331340
[[package]]
332341
name = "dirs-sys"
333342
version = "0.4.1"
@@ -503,6 +512,7 @@ dependencies = [
503512
"hir-def",
504513
"hir-expand",
505514
"hir-ty",
515+
"intern",
506516
"itertools",
507517
"once_cell",
508518
"rustc-hash",
@@ -891,9 +901,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
891901

892902
[[package]]
893903
name = "libc"
894-
version = "0.2.154"
904+
version = "0.2.155"
895905
source = "registry+https://github.com/rust-lang/crates.io-index"
896-
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
906+
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
897907

898908
[[package]]
899909
name = "libloading"
@@ -1665,6 +1675,7 @@ dependencies = [
16651675
"anyhow",
16661676
"cfg",
16671677
"crossbeam-channel",
1678+
"dirs",
16681679
"dissimilar",
16691680
"expect-test",
16701681
"flycheck",

src/tools/rust-analyzer/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ xshell = "0.2.5"
162162
dashmap = { version = "=5.5.3", features = ["raw-api"] }
163163

164164
[workspace.lints.rust]
165-
rust_2018_idioms = "warn"
165+
bare_trait_objects = "warn"
166+
elided_lifetimes_in_paths = "warn"
167+
ellipsis_inclusive_range_patterns = "warn"
168+
explicit_outlives_requirements = "warn"
169+
unused_extern_crates = "warn"
166170
unused_lifetimes = "warn"
167171
unreachable_pub = "warn"
168172
semicolon_in_expressions_from_macros = "warn"

src/tools/rust-analyzer/crates/base-db/src/change.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl FileChange {
5151
}
5252

5353
pub fn apply(self, db: &mut dyn SourceDatabaseExt) {
54-
let _p = tracing::span!(tracing::Level::INFO, "FileChange::apply").entered();
54+
let _p = tracing::info_span!("FileChange::apply").entered();
5555
if let Some(roots) = self.roots {
5656
for (idx, root) in roots.into_iter().enumerate() {
5757
let root_id = SourceRootId(idx as u32);

src/tools/rust-analyzer/crates/base-db/src/input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl CrateGraph {
412412
from: CrateId,
413413
dep: Dependency,
414414
) -> Result<(), CyclicDependenciesError> {
415-
let _p = tracing::span!(tracing::Level::INFO, "add_dep").entered();
415+
let _p = tracing::info_span!("add_dep").entered();
416416

417417
self.check_cycle_after_dependency(from, dep.crate_id)?;
418418

src/tools/rust-analyzer/crates/base-db/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn toolchain_channel(db: &dyn SourceDatabase, krate: CrateId) -> Option<ReleaseC
8585
}
8686

8787
fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
88-
let _p = tracing::span!(tracing::Level::INFO, "parse", ?file_id).entered();
88+
let _p = tracing::info_span!("parse", ?file_id).entered();
8989
let text = db.file_text(file_id);
9090
// FIXME: Edition based parsing
9191
SourceFile::parse(&text, span::Edition::CURRENT)
@@ -187,7 +187,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
187187
}
188188

189189
fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
190-
let _p = tracing::span!(tracing::Level::INFO, "relevant_crates").entered();
190+
let _p = tracing::info_span!("relevant_crates").entered();
191191
let source_root = self.0.file_source_root(file_id);
192192
self.0.source_root_crates(source_root)
193193
}

src/tools/rust-analyzer/crates/flycheck/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl FlycheckActor {
304304
Some(c) => c,
305305
None => continue,
306306
};
307-
let formatted_command = format!("{:?}", command);
307+
let formatted_command = format!("{command:?}");
308308

309309
tracing::debug!(?command, "will restart flycheck");
310310
let (sender, receiver) = unbounded();
@@ -318,8 +318,7 @@ impl FlycheckActor {
318318
}
319319
Err(error) => {
320320
self.report_progress(Progress::DidFailToRestart(format!(
321-
"Failed to run the following command: {} error={}",
322-
formatted_command, error
321+
"Failed to run the following command: {formatted_command} error={error}"
323322
)));
324323
self.status = FlycheckStatus::Finished;
325324
}
@@ -331,7 +330,7 @@ impl FlycheckActor {
331330
// Watcher finished
332331
let command_handle = self.command_handle.take().unwrap();
333332
self.command_receiver.take();
334-
let formatted_handle = format!("{:?}", command_handle);
333+
let formatted_handle = format!("{command_handle:?}");
335334

336335
let res = command_handle.join();
337336
if let Err(error) = &res {
@@ -387,6 +386,7 @@ impl FlycheckActor {
387386
"did cancel flycheck"
388387
);
389388
command_handle.cancel();
389+
self.command_receiver.take();
390390
self.report_progress(Progress::DidCancel);
391391
self.status = FlycheckStatus::Finished;
392392
}

src/tools/rust-analyzer/crates/hir-def/src/attr.rs

+54-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
//! A higher level attributes based on TokenTree, with also some shortcuts.
22
3-
pub mod builtin;
4-
5-
#[cfg(test)]
6-
mod tests;
7-
83
use std::{borrow::Cow, hash::Hash, ops, slice::Iter as SliceIter};
94

105
use base_db::CrateId;
@@ -75,7 +70,7 @@ impl Attrs {
7570
db: &dyn DefDatabase,
7671
v: VariantId,
7772
) -> Arc<ArenaMap<LocalFieldId, Attrs>> {
78-
let _p = tracing::span!(tracing::Level::INFO, "fields_attrs_query").entered();
73+
let _p = tracing::info_span!("fields_attrs_query").entered();
7974
// FIXME: There should be some proper form of mapping between item tree field ids and hir field ids
8075
let mut res = ArenaMap::default();
8176

@@ -326,7 +321,7 @@ impl AttrsWithOwner {
326321
}
327322

328323
pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs {
329-
let _p = tracing::span!(tracing::Level::INFO, "attrs_query").entered();
324+
let _p = tracing::info_span!("attrs_query").entered();
330325
// FIXME: this should use `Trace` to avoid duplication in `source_map` below
331326
let raw_attrs = match def {
332327
AttrDefId::ModuleId(module) => {
@@ -646,3 +641,55 @@ pub(crate) fn fields_attrs_source_map(
646641

647642
Arc::new(res)
648643
}
644+
645+
#[cfg(test)]
646+
mod tests {
647+
//! This module contains tests for doc-expression parsing.
648+
//! Currently, it tests `#[doc(hidden)]` and `#[doc(alias)]`.
649+
650+
use triomphe::Arc;
651+
652+
use base_db::FileId;
653+
use hir_expand::span_map::{RealSpanMap, SpanMap};
654+
use mbe::{syntax_node_to_token_tree, DocCommentDesugarMode};
655+
use syntax::{ast, AstNode, TextRange};
656+
657+
use crate::attr::{DocAtom, DocExpr};
658+
659+
fn assert_parse_result(input: &str, expected: DocExpr) {
660+
let source_file = ast::SourceFile::parse(input, span::Edition::CURRENT).ok().unwrap();
661+
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
662+
let map = SpanMap::RealSpanMap(Arc::new(RealSpanMap::absolute(FileId::from_raw(0))));
663+
let tt = syntax_node_to_token_tree(
664+
tt.syntax(),
665+
map.as_ref(),
666+
map.span_for_range(TextRange::empty(0.into())),
667+
DocCommentDesugarMode::ProcMacro,
668+
);
669+
let cfg = DocExpr::parse(&tt);
670+
assert_eq!(cfg, expected);
671+
}
672+
673+
#[test]
674+
fn test_doc_expr_parser() {
675+
assert_parse_result("#![doc(hidden)]", DocAtom::Flag("hidden".into()).into());
676+
677+
assert_parse_result(
678+
r#"#![doc(alias = "foo")]"#,
679+
DocAtom::KeyValue { key: "alias".into(), value: "foo".into() }.into(),
680+
);
681+
682+
assert_parse_result(r#"#![doc(alias("foo"))]"#, DocExpr::Alias(["foo".into()].into()));
683+
assert_parse_result(
684+
r#"#![doc(alias("foo", "bar", "baz"))]"#,
685+
DocExpr::Alias(["foo".into(), "bar".into(), "baz".into()].into()),
686+
);
687+
688+
assert_parse_result(
689+
r#"
690+
#[doc(alias("Bar", "Qux"))]
691+
struct Foo;"#,
692+
DocExpr::Alias(["Bar".into(), "Qux".into()].into()),
693+
);
694+
}
695+
}

src/tools/rust-analyzer/crates/hir-def/src/attr/tests.rs

-48
This file was deleted.

src/tools/rust-analyzer/crates/hir-def/src/body.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl Body {
124124
db: &dyn DefDatabase,
125125
def: DefWithBodyId,
126126
) -> (Arc<Body>, Arc<BodySourceMap>) {
127-
let _p = tracing::span!(tracing::Level::INFO, "body_with_source_map_query").entered();
127+
let _p = tracing::info_span!("body_with_source_map_query").entered();
128128
let mut params = None;
129129

130130
let mut is_async_fn = false;
@@ -395,6 +395,12 @@ impl BodySourceMap {
395395
self.expr_map.get(&src).copied()
396396
}
397397

398+
pub fn expansions(
399+
&self,
400+
) -> impl Iterator<Item = (&InFile<AstPtr<ast::MacroCall>>, &MacroFileId)> {
401+
self.expansions.iter()
402+
}
403+
398404
pub fn implicit_format_args(
399405
&self,
400406
node: InFile<&ast::FormatArgsExpr>,

src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use intern::Interned;
1212
use rustc_hash::FxHashMap;
1313
use smallvec::SmallVec;
1414
use span::AstIdMap;
15+
use stdx::never;
1516
use syntax::{
1617
ast::{
1718
self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasLoopBody, HasName,
@@ -480,7 +481,8 @@ impl ExprCollector<'_> {
480481
} else if e.const_token().is_some() {
481482
Mutability::Shared
482483
} else {
483-
unreachable!("parser only remaps to raw_token() if matching mutability token follows")
484+
never!("parser only remaps to raw_token() if matching mutability token follows");
485+
Mutability::Shared
484486
}
485487
} else {
486488
Mutability::from_mutable(e.mut_token().is_some())
@@ -963,7 +965,7 @@ impl ExprCollector<'_> {
963965
.resolve_path(
964966
self.db,
965967
module,
966-
&path,
968+
path,
967969
crate::item_scope::BuiltinShadowMode::Other,
968970
Some(MacroSubNs::Bang),
969971
)
@@ -1006,9 +1008,9 @@ impl ExprCollector<'_> {
10061008
Some((mark, expansion)) => {
10071009
// Keep collecting even with expansion errors so we can provide completions and
10081010
// other services in incomplete macro expressions.
1009-
self.source_map
1010-
.expansions
1011-
.insert(macro_call_ptr, self.expander.current_file_id().macro_file().unwrap());
1011+
if let Some(macro_file) = self.expander.current_file_id().macro_file() {
1012+
self.source_map.expansions.insert(macro_call_ptr, macro_file);
1013+
}
10121014
let prev_ast_id_map = mem::replace(
10131015
&mut self.ast_id_map,
10141016
self.db.ast_id_map(self.expander.current_file_id()),

src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,30 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
4848
let mut p = Printer { db, body, buf: header, indent_level: 0, needs_indent: false };
4949
if let DefWithBodyId::FunctionId(it) = owner {
5050
p.buf.push('(');
51-
let params = &db.function_data(it).params;
52-
let mut params = params.iter();
51+
let function_data = &db.function_data(it);
52+
let (mut params, ret_type) = (function_data.params.iter(), &function_data.ret_type);
5353
if let Some(self_param) = body.self_param {
5454
p.print_binding(self_param);
55-
p.buf.push(':');
55+
p.buf.push_str(": ");
5656
if let Some(ty) = params.next() {
5757
p.print_type_ref(ty);
58+
p.buf.push_str(", ");
5859
}
5960
}
6061
body.params.iter().zip(params).for_each(|(&param, ty)| {
6162
p.print_pat(param);
62-
p.buf.push(':');
63+
p.buf.push_str(": ");
6364
p.print_type_ref(ty);
65+
p.buf.push_str(", ");
6466
});
67+
// remove the last ", " in param list
68+
if body.params.len() > 0 {
69+
p.buf.truncate(p.buf.len() - 2);
70+
}
6571
p.buf.push(')');
72+
// return type
73+
p.buf.push_str(" -> ");
74+
p.print_type_ref(ret_type);
6675
p.buf.push(' ');
6776
}
6877
p.print_expr(body.body_expr);

0 commit comments

Comments
 (0)