Skip to content

Commit

Permalink
Auto merge of rust-lang#136117 - lnicola:sync-from-ra, r=lnicola
Browse files Browse the repository at this point in the history
Subtree update of `rust-analyzer`

r? `@ghost`
  • Loading branch information
bors committed Jan 29, 2025
2 parents ccc9ba5 + a7cbe4b commit 61cc3e5
Show file tree
Hide file tree
Showing 126 changed files with 2,163 additions and 1,325 deletions.
7 changes: 0 additions & 7 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,6 @@ dependencies = [
"dashmap",
"hashbrown",
"rustc-hash 2.0.0",
"sptr",
"triomphe",
]

Expand Down Expand Up @@ -1927,12 +1926,6 @@ dependencies = [
"vfs",
]

[[package]]
name = "sptr"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a"

[[package]]
name = "stdx"
version = "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
resolver = "2"

[workspace.package]
rust-version = "1.83"
rust-version = "1.84"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer team"]
Expand Down
6 changes: 6 additions & 0 deletions src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,9 @@ impl ExprCollector<'_> {
}
}
ast::Stmt::Item(ast::Item::MacroDef(macro_)) => {
if self.check_cfg(&macro_).is_none() {
return;
}
let Some(name) = macro_.name() else {
statements.push(Statement::Item(Item::Other));
return;
Expand All @@ -1390,6 +1393,9 @@ impl ExprCollector<'_> {
self.collect_macro_def(statements, macro_id);
}
ast::Stmt::Item(ast::Item::MacroRules(macro_)) => {
if self.check_cfg(&macro_).is_none() {
return;
}
let Some(name) = macro_.name() else {
statements.push(Statement::Item(Item::Other));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn outer() {
block scope::tests
name: _
outer: v
outer: vg
crate
outer: v
Expand Down
25 changes: 19 additions & 6 deletions src/tools/rust-analyzer/crates/hir-def/src/find_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ fn find_in_dep(
};
cov_mark::hit!(partially_imported);
if info.is_unstable {
if !ctx.cfg.allow_unstable {
// the item is unstable and we are not allowed to use unstable items
continue;
}
choice.stability = Unstable;
}

Expand Down Expand Up @@ -670,6 +674,7 @@ mod tests {
prefer_prelude: bool,
prefer_absolute: bool,
prefer_no_std: bool,
allow_unstable: bool,
expect: Expect,
) {
let (db, pos) = TestDB::with_position(ra_fixture);
Expand Down Expand Up @@ -711,7 +716,7 @@ mod tests {
module,
prefix,
ignore_local_imports,
ImportPathConfig { prefer_no_std, prefer_prelude, prefer_absolute },
ImportPathConfig { prefer_no_std, prefer_prelude, prefer_absolute, allow_unstable },
);
format_to!(
res,
Expand All @@ -732,31 +737,39 @@ mod tests {
path: &str,
expect: Expect,
) {
check_found_path_(ra_fixture, path, false, false, false, expect);
check_found_path_(ra_fixture, path, false, false, false, false, expect);
}

fn check_found_path_prelude(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
path: &str,
expect: Expect,
) {
check_found_path_(ra_fixture, path, true, false, false, expect);
check_found_path_(ra_fixture, path, true, false, false, false, expect);
}

fn check_found_path_absolute(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
path: &str,
expect: Expect,
) {
check_found_path_(ra_fixture, path, false, true, false, expect);
check_found_path_(ra_fixture, path, false, true, false, false, expect);
}

fn check_found_path_prefer_no_std(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
path: &str,
expect: Expect,
) {
check_found_path_(ra_fixture, path, false, false, true, expect);
check_found_path_(ra_fixture, path, false, false, true, false, expect);
}

fn check_found_path_prefer_no_std_allow_unstable(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
path: &str,
expect: Expect,
) {
check_found_path_(ra_fixture, path, false, false, true, true, expect);
}

#[test]
Expand Down Expand Up @@ -1951,7 +1964,7 @@ pub mod ops {

#[test]
fn respect_unstable_modules() {
check_found_path_prefer_no_std(
check_found_path_prefer_no_std_allow_unstable(
r#"
//- /main.rs crate:main deps:std,core
extern crate std;
Expand Down
18 changes: 7 additions & 11 deletions src/tools/rust-analyzer/crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc_hash::FxHashSet;
use smallvec::SmallVec;
use span::Edition;
use stdx::{format_to, TupleExt};
use syntax::ToSmolStr;
use triomphe::Arc;

use crate::{
Expand Down Expand Up @@ -88,9 +87,9 @@ impl ImportMap {
.iter()
// We've only collected items, whose name cannot be tuple field so unwrapping is fine.
.flat_map(|(&item, (info, _))| {
info.iter().enumerate().map(move |(idx, info)| {
(item, info.name.unescaped().display(db.upcast()).to_smolstr(), idx as u32)
})
info.iter()
.enumerate()
.map(move |(idx, info)| (item, info.name.as_str(), idx as u32))
})
.collect();
importables.sort_by(|(_, l_info, _), (_, r_info, _)| {
Expand Down Expand Up @@ -168,7 +167,8 @@ impl ImportMap {
let attr_id = if let Some(import) = import {
match import {
ImportOrExternCrate::ExternCrate(id) => Some(id.into()),
ImportOrExternCrate::Import(id) => Some(id.import.into()),
ImportOrExternCrate::Import(id) => Some(id.use_.into()),
ImportOrExternCrate::Glob(id) => Some(id.use_.into()),
}
} else {
match item {
Expand Down Expand Up @@ -441,7 +441,7 @@ pub fn search_dependencies(
}

fn search_maps(
db: &dyn DefDatabase,
_db: &dyn DefDatabase,
import_maps: &[Arc<ImportMap>],
mut stream: fst::map::Union<'_>,
query: &Query,
Expand All @@ -464,11 +464,7 @@ fn search_maps(
.then(|| (item, &import_infos[info_idx as usize]))
})
.filter(|&(_, info)| {
query.search_mode.check(
&query.query,
query.case_sensitive,
&info.name.unescaped().display(db.upcast()).to_smolstr(),
)
query.search_mode.check(&query.query, query.case_sensitive, info.name.as_str())
});
res.extend(iter.map(TupleExt::head));
}
Expand Down
Loading

0 comments on commit 61cc3e5

Please sign in to comment.