Skip to content

Rust: upgrade rust-analyzer to 0.0.288 #19524

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 19 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/extractor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct Config {
pub cargo_target: Option<String>,
pub cargo_features: Vec<String>,
pub cargo_cfg_overrides: Vec<String>,
pub cargo_extra_env: FxHashMap<String, String>,
pub cargo_extra_env: FxHashMap<String, Option<String>>,
pub cargo_extra_args: Vec<String>,
pub cargo_all_targets: bool,
pub logging_flamegraph: Option<PathBuf>,
Expand Down
33 changes: 18 additions & 15 deletions rust/extractor/src/config/deserialize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Deserializer;
use serde::de::{Error, Unexpected, Visitor};
use serde::de::Visitor;
use std::collections::HashMap;
use std::fmt::Formatter;
use std::hash::BuildHasher;
Expand Down Expand Up @@ -36,23 +36,22 @@ impl<'de, T: From<String>> Visitor<'de> for VectorVisitor<T> {
}

impl<'de, S: BuildHasher + Default> Visitor<'de> for MapVisitor<S> {
type Value = HashMap<String, String, S>;
type Value = HashMap<String, Option<String>, S>;

fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
formatter.write_str(
"either a sequence, or a comma or newline separated string of key=value entries",
"either a sequence, or a comma or newline separated string of key[=value] entries",
)
}

fn visit_str<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> {
value
Ok(value
.split(['\n', ','])
.map(|s| {
s.split_once('=')
.ok_or_else(|| E::custom(format!("key=value expected, found {s}")))
.map(|(key, value)| (key.to_owned(), value.to_owned()))
.map(|s| match s.split_once('=') {
Some((key, value)) => (key.to_owned(), Some(value.to_owned())),
None => (s.to_owned(), None),
})
.collect()
.collect())
}

fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
Expand All @@ -61,10 +60,14 @@ impl<'de, S: BuildHasher + Default> Visitor<'de> for MapVisitor<S> {
{
let mut ret = HashMap::with_hasher(Default::default());
while let Some(el) = seq.next_element::<String>()? {
let (key, value) = el
.split_once('=')
.ok_or_else(|| A::Error::invalid_value(Unexpected::Str(&el), &self))?;
ret.insert(key.to_owned(), value.to_owned());
match el.split_once('=') {
None => {
ret.insert(el.to_owned(), None);
}
Some((key, value)) => {
ret.insert(key.to_owned(), Some(value.to_owned()));
}
}
}
Ok(ret)
}
Expand All @@ -83,7 +86,7 @@ pub(crate) fn deserialize_newline_or_comma_separated_vec<
deserializer.deserialize_seq(VectorVisitor(PhantomData))
}

/// deserialize into a map of `String`s to `String`s either of:
/// deserialize into a map of `String`s to `Option<String>`s either of:
/// * a sequence of elements serializable into `String`s, or
/// * a single element serializable into `String`, then split on `,` and `\n`
pub(crate) fn deserialize_newline_or_comma_separated_map<
Expand All @@ -92,6 +95,6 @@ pub(crate) fn deserialize_newline_or_comma_separated_map<
S: BuildHasher + Default,
>(
deserializer: D,
) -> Result<HashMap<String, String, S>, D::Error> {
) -> Result<HashMap<String, Option<String>, S>, D::Error> {
deserializer.deserialize_map(MapVisitor(PhantomData))
}
6 changes: 1 addition & 5 deletions rust/extractor/src/rust_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ impl<'a> RustAnalyzer<'a> {
let editioned_file_id = semantics
.attach_first_edition(file_id)
.ok_or("failed to determine rust edition")?;
Ok((
semantics,
EditionedFileId::new(semantics.db, editioned_file_id),
input,
))
Ok((semantics, editioned_file_id, input))
}
}
}
Expand Down
39 changes: 22 additions & 17 deletions rust/extractor/src/translate/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'a> Translator<'a> {
if let Some(semantics) = self.semantics.as_ref() {
let file_range = semantics.original_range(node.syntax());
let file_id = self.file_id?;
if file_id.file_id(semantics.db) == file_range.file_id {
if file_id == file_range.file_id {
Some(file_range.range)
} else {
None
Expand Down Expand Up @@ -298,20 +298,18 @@ impl<'a> Translator<'a> {
if let Some(value) = semantics
.hir_file_for(expanded)
.macro_file()
.and_then(|macro_file| {
semantics
.db
.parse_macro_expansion_error(macro_file.macro_call_id)
})
.and_then(|macro_call_id| semantics.db.parse_macro_expansion_error(macro_call_id))
{
if let Some(err) = &value.err {
let error = err.render_to_string(semantics.db);

if err.span().anchor.file_id == semantics.hir_file_for(node.syntax()) {
let hir_file_id = semantics.hir_file_for(node.syntax());
if Some(err.span().anchor.file_id.file_id())
== hir_file_id.file_id().map(|f| f.file_id(semantics.db))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you figure out that you needed the file_id of the file_id of the file_id of file_id ? ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turtles all the way down... 🤷

{
let location = err.span().range
+ semantics
.db
.ast_id_map(err.span().anchor.file_id.into())
.ast_id_map(hir_file_id)
.get_erased(err.span().anchor.ast_id)
.text_range()
.start();
Expand Down Expand Up @@ -363,10 +361,10 @@ impl<'a> Translator<'a> {
.as_ref()
.and_then(|s| s.expand_macro_call(mcall))
{
self.emit_macro_expansion_parse_errors(mcall, &expanded);
self.emit_macro_expansion_parse_errors(mcall, &expanded.value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does expanded also have an err field? If so, let log it, hopefully it'll provide some useful information of why an expansion failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the latest version of the PR does that

let expand_to = ra_ap_hir_expand::ExpandTo::from_call_site(mcall);
let kind = expanded.kind();
if let Some(value) = self.emit_expanded_as(expand_to, expanded) {
if let Some(value) = self.emit_expanded_as(expand_to, expanded.value) {
generated::MacroCall::emit_macro_call_expansion(
label,
value,
Expand Down Expand Up @@ -669,11 +667,11 @@ impl<'a> Translator<'a> {
) {
// work around a bug in rust-analyzer AST generation machinery
// this code was inspired by rust-analyzer's own workaround for this:
// https://github.com/rust-lang/rust-analyzer/blob/1f86729f29ea50e8491a1516422df4fd3d1277b0/crates/syntax/src/ast/node_ext.rs#L268-L277
if item.l_angle_token().is_some() {
// https://github.com/rust-lang/rust-analyzer/blob/a642aa8023be11d6bc027fc6a68c71c2f3fc7f72/crates/syntax/src/ast/node_ext.rs#L290-L297
if let Some(anchor) = item.type_anchor() {
// <T> or <T as Trait>
// T is any TypeRef, Trait has to be a PathType
let mut type_refs = item
let mut type_refs = anchor
.syntax()
.children()
.filter(|node| ast::Type::can_cast(node.kind()));
Expand All @@ -691,6 +689,13 @@ impl<'a> Translator<'a> {
{
generated::PathSegment::emit_trait_type_repr(label, t, &mut self.trap.writer)
}
// moreover as we're skipping emission of TypeAnchor, we need to attach its comments to
// this path segment
self.emit_tokens(
&anchor,
label.into(),
anchor.syntax().children_with_tokens(),
);
}
}

Expand Down Expand Up @@ -743,9 +748,9 @@ impl<'a> Translator<'a> {
}
let ExpandResult {
value: expanded, ..
} = semantics.expand_attr_macro(node)?;
self.emit_macro_expansion_parse_errors(node, &expanded);
let macro_items = ast::MacroItems::cast(expanded).or_else(|| {
} = self.semantics.and_then(|s| s.expand_attr_macro(node))?;
self.emit_macro_expansion_parse_errors(node, &expanded.value);
let macro_items = ast::MacroItems::cast(expanded.value).or_else(|| {
let message = "attribute macro expansion cannot be cast to MacroItems".to_owned();
let location = self.location_for_node(node);
self.emit_diagnostic(
Expand Down