Skip to content

Commit 1685c82

Browse files
authored
Merge branch 'rust-lang:master' into master
2 parents 776fc10 + 9923b00 commit 1685c82

File tree

123 files changed

+1917
-1082
lines changed

Some content is hidden

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

123 files changed

+1917
-1082
lines changed

crates/base-db/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub trait SourceRootDatabase: SourceDatabase {
136136
#[ra_salsa::input]
137137
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
138138

139-
/// Crates whose root fool is in `id`.
139+
/// Crates whose root file is in `id`.
140140
fn source_root_crates(&self, id: SourceRootId) -> Arc<[CrateId]>;
141141
}
142142

crates/hir-def/src/attr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ impl Attrs {
122122
AttrQuery { attrs: self, key }
123123
}
124124

125+
pub fn rust_analyzer_tool(&self) -> impl Iterator<Item = &Attr> {
126+
self.iter()
127+
.filter(|&attr| attr.path.segments().first().is_some_and(|s| *s == sym::rust_analyzer))
128+
}
129+
125130
pub fn cfg(&self) -> Option<CfgExpr> {
126131
let mut cfgs = self.by_key(&sym::cfg).tt_values().map(CfgExpr::parse);
127132
let first = cfgs.next()?;

crates/hir-def/src/body/lower.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::mem;
88
use base_db::CrateId;
99
use either::Either;
1010
use hir_expand::{
11+
mod_path::tool_path,
1112
name::{AsName, Name},
1213
span_map::{ExpansionSpanMap, SpanMap},
1314
InFile, MacroDefId,
@@ -27,6 +28,7 @@ use text_size::TextSize;
2728
use triomphe::Arc;
2829

2930
use crate::{
31+
attr::Attrs,
3032
body::{Body, BodyDiagnostic, BodySourceMap, ExprPtr, HygieneId, LabelPtr, PatPtr},
3133
builtin_type::BuiltinUint,
3234
data::adt::StructKind,
@@ -212,6 +214,43 @@ impl ExprCollector<'_> {
212214
body: Option<ast::Expr>,
213215
is_async_fn: bool,
214216
) -> (Body, BodySourceMap) {
217+
let skip_body = match self.owner {
218+
DefWithBodyId::FunctionId(it) => self.db.attrs(it.into()),
219+
DefWithBodyId::StaticId(it) => self.db.attrs(it.into()),
220+
DefWithBodyId::ConstId(it) => self.db.attrs(it.into()),
221+
DefWithBodyId::InTypeConstId(_) => Attrs::EMPTY,
222+
DefWithBodyId::VariantId(it) => self.db.attrs(it.into()),
223+
}
224+
.rust_analyzer_tool()
225+
.any(|attr| *attr.path() == tool_path![skip]);
226+
// If #[rust_analyzer::skip] annotated, only construct enough information for the signature
227+
// and skip the body.
228+
if skip_body {
229+
self.body.body_expr = self.missing_expr();
230+
if let Some((param_list, mut attr_enabled)) = param_list {
231+
if let Some(self_param) =
232+
param_list.self_param().filter(|_| attr_enabled.next().unwrap_or(false))
233+
{
234+
let is_mutable =
235+
self_param.mut_token().is_some() && self_param.amp_token().is_none();
236+
let binding_id: la_arena::Idx<Binding> = self.alloc_binding(
237+
Name::new_symbol_root(sym::self_.clone()),
238+
BindingAnnotation::new(is_mutable, false),
239+
);
240+
self.body.self_param = Some(binding_id);
241+
self.source_map.self_param =
242+
Some(self.expander.in_file(AstPtr::new(&self_param)));
243+
}
244+
self.body.params = param_list
245+
.params()
246+
.zip(attr_enabled)
247+
.filter(|(_, enabled)| *enabled)
248+
.map(|_| self.missing_pat())
249+
.collect();
250+
};
251+
return (self.body, self.source_map);
252+
}
253+
215254
self.awaitable_context.replace(if is_async_fn {
216255
Awaitable::Yes
217256
} else {

crates/hir-def/src/body/scope.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ mod tests {
345345
}
346346
}
347347

348-
fn do_check(ra_fixture: &str, expected: &[&str]) {
348+
fn do_check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: &[&str]) {
349349
let (offset, code) = extract_offset(ra_fixture);
350350
let code = {
351351
let mut buf = String::new();
@@ -509,7 +509,7 @@ fn foo() {
509509
);
510510
}
511511

512-
fn do_check_local_name(ra_fixture: &str, expected_offset: u32) {
512+
fn do_check_local_name(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_offset: u32) {
513513
let (db, position) = TestDB::with_position(ra_fixture);
514514
let file_id = position.file_id;
515515
let offset = position.offset;

crates/hir-def/src/body/tests.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{test_db::TestDB, ModuleDefId};
77

88
use super::*;
99

10-
fn lower(ra_fixture: &str) -> (TestDB, Arc<Body>, DefWithBodyId) {
10+
fn lower(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (TestDB, Arc<Body>, DefWithBodyId) {
1111
let db = TestDB::with_files(ra_fixture);
1212

1313
let krate = db.fetch_test_crate();
@@ -27,22 +27,22 @@ fn lower(ra_fixture: &str) -> (TestDB, Arc<Body>, DefWithBodyId) {
2727
(db, body, fn_def)
2828
}
2929

30-
fn def_map_at(ra_fixture: &str) -> String {
30+
fn def_map_at(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
3131
let (db, position) = TestDB::with_position(ra_fixture);
3232

3333
let module = db.module_at_position(position);
3434
module.def_map(&db).dump(&db)
3535
}
3636

37-
fn check_block_scopes_at(ra_fixture: &str, expect: Expect) {
37+
fn check_block_scopes_at(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
3838
let (db, position) = TestDB::with_position(ra_fixture);
3939

4040
let module = db.module_at_position(position);
4141
let actual = module.def_map(&db).dump_block_scopes(&db);
4242
expect.assert_eq(&actual);
4343
}
4444

45-
fn check_at(ra_fixture: &str, expect: Expect) {
45+
fn check_at(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
4646
let actual = def_map_at(ra_fixture);
4747
expect.assert_eq(&actual);
4848
}
@@ -444,3 +444,18 @@ fn foo() {
444444
}"#
445445
);
446446
}
447+
448+
#[test]
449+
fn skip_skips_body() {
450+
let (db, body, owner) = lower(
451+
r#"
452+
#[rust_analyzer::skip]
453+
async fn foo(a: (), b: i32) -> u32 {
454+
0 + 1 + b()
455+
}
456+
"#,
457+
);
458+
let printed = body.pretty_print(&db, owner, Edition::CURRENT);
459+
expect!["fn foo(�: (), �: i32) -> impl ::core::future::Future::<Output = u32> �"]
460+
.assert_eq(&printed);
461+
}

crates/hir-def/src/find_path.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ mod tests {
665665
/// module the cursor is in.
666666
#[track_caller]
667667
fn check_found_path_(
668-
ra_fixture: &str,
668+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
669669
path: &str,
670670
prefer_prelude: bool,
671671
prefer_absolute: bool,
@@ -727,19 +727,35 @@ mod tests {
727727
expect.assert_eq(&res);
728728
}
729729

730-
fn check_found_path(ra_fixture: &str, path: &str, expect: Expect) {
730+
fn check_found_path(
731+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
732+
path: &str,
733+
expect: Expect,
734+
) {
731735
check_found_path_(ra_fixture, path, false, false, false, expect);
732736
}
733737

734-
fn check_found_path_prelude(ra_fixture: &str, path: &str, expect: Expect) {
738+
fn check_found_path_prelude(
739+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
740+
path: &str,
741+
expect: Expect,
742+
) {
735743
check_found_path_(ra_fixture, path, true, false, false, expect);
736744
}
737745

738-
fn check_found_path_absolute(ra_fixture: &str, path: &str, expect: Expect) {
746+
fn check_found_path_absolute(
747+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
748+
path: &str,
749+
expect: Expect,
750+
) {
739751
check_found_path_(ra_fixture, path, false, true, false, expect);
740752
}
741753

742-
fn check_found_path_prefer_no_std(ra_fixture: &str, path: &str, expect: Expect) {
754+
fn check_found_path_prefer_no_std(
755+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
756+
path: &str,
757+
expect: Expect,
758+
) {
743759
check_found_path_(ra_fixture, path, false, false, true, expect);
744760
}
745761

crates/hir-def/src/import_map.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,12 @@ mod tests {
509509
}
510510
}
511511

512-
fn check_search(ra_fixture: &str, crate_name: &str, query: Query, expect: Expect) {
512+
fn check_search(
513+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
514+
crate_name: &str,
515+
query: Query,
516+
expect: Expect,
517+
) {
513518
let db = TestDB::with_files(ra_fixture);
514519
let crate_graph = db.crate_graph();
515520
let krate = crate_graph
@@ -587,7 +592,7 @@ mod tests {
587592
))
588593
}
589594

590-
fn check(ra_fixture: &str, expect: Expect) {
595+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
591596
let db = TestDB::with_files(ra_fixture);
592597
let crate_graph = db.crate_graph();
593598

crates/hir-def/src/item_tree/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use test_fixture::WithFixture;
44

55
use crate::{db::DefDatabase, test_db::TestDB};
66

7-
fn check(ra_fixture: &str, expect: Expect) {
7+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
88
let (db, file_id) = TestDB::with_single_file(ra_fixture);
99
let item_tree = db.file_item_tree(file_id.into());
1010
let pretty = item_tree.pretty_print(&db, Edition::CURRENT);

crates/hir-def/src/macro_expansion_tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::{
4747
};
4848

4949
#[track_caller]
50-
fn check_errors(ra_fixture: &str, expect: Expect) {
50+
fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
5151
let db = TestDB::with_files(ra_fixture);
5252
let krate = db.fetch_test_crate();
5353
let def_map = db.crate_def_map(krate);
@@ -77,7 +77,7 @@ fn check_errors(ra_fixture: &str, expect: Expect) {
7777
}
7878

7979
#[track_caller]
80-
fn check(ra_fixture: &str, mut expect: Expect) {
80+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, mut expect: Expect) {
8181
let extra_proc_macros = vec![(
8282
r#"
8383
#[proc_macro_attribute]

crates/hir-def/src/nameres/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ use triomphe::Arc;
1111

1212
use crate::{db::DefDatabase, nameres::DefMap, test_db::TestDB};
1313

14-
fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> {
14+
fn compute_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> Arc<DefMap> {
1515
let db = TestDB::with_files(ra_fixture);
1616
let krate = db.fetch_test_crate();
1717
db.crate_def_map(krate)
1818
}
1919

20-
fn render_crate_def_map(ra_fixture: &str) -> String {
20+
fn render_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
2121
let db = TestDB::with_files(ra_fixture);
2222
let krate = db.fetch_test_crate();
2323
db.crate_def_map(krate).dump(&db)
2424
}
2525

26-
fn check(ra_fixture: &str, expect: Expect) {
26+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
2727
let actual = render_crate_def_map(ra_fixture);
2828
expect.assert_eq(&actual);
2929
}

0 commit comments

Comments
 (0)