Rust: fix compilation errors

This commit is contained in:
Paolo Tranquilli
2025-06-20 17:52:36 +02:00
parent efd318dc01
commit 02a9d4c86d
5 changed files with 42 additions and 39 deletions

1
Cargo.lock generated
View File

@@ -3449,4 +3449,3 @@ dependencies = [
name = "rustc_apfloat" name = "rustc_apfloat"
version = "0.2.2+llvm-462a31f5a5ab" version = "0.2.2+llvm-462a31f5a5ab"
source = "git+https://github.com/redsun82/rustc_apfloat.git?rev=32968f16ef1b082243f9bf43a3fbd65c381b3e27#32968f16ef1b082243f9bf43a3fbd65c381b3e27" source = "git+https://github.com/redsun82/rustc_apfloat.git?rev=32968f16ef1b082243f9bf43a3fbd65c381b3e27#32968f16ef1b082243f9bf43a3fbd65c381b3e27"

View File

@@ -52,7 +52,7 @@ pub struct Config {
pub cargo_target: Option<String>, pub cargo_target: Option<String>,
pub cargo_features: Vec<String>, pub cargo_features: Vec<String>,
pub cargo_cfg_overrides: 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_extra_args: Vec<String>,
pub cargo_all_targets: bool, pub cargo_all_targets: bool,
pub logging_flamegraph: Option<PathBuf>, pub logging_flamegraph: Option<PathBuf>,

View File

@@ -1,5 +1,5 @@
use serde::Deserializer; use serde::Deserializer;
use serde::de::{Error, Unexpected, Visitor}; use serde::de::Visitor;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::Formatter; use std::fmt::Formatter;
use std::hash::BuildHasher; use std::hash::BuildHasher;
@@ -36,23 +36,22 @@ impl<'de, T: From<String>> Visitor<'de> for VectorVisitor<T> {
} }
impl<'de, S: BuildHasher + Default> Visitor<'de> for MapVisitor<S> { 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 { fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
formatter.write_str( 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> { fn visit_str<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> {
value Ok(value
.split(['\n', ',']) .split(['\n', ','])
.map(|s| { .map(|s| match s.split_once('=') {
s.split_once('=') Some((key, value)) => (key.to_owned(), Some(value.to_owned())),
.ok_or_else(|| E::custom(format!("key=value expected, found {s}"))) None => (s.to_owned(), None),
.map(|(key, value)| (key.to_owned(), value.to_owned()))
}) })
.collect() .collect())
} }
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error> fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
@@ -61,10 +60,14 @@ impl<'de, S: BuildHasher + Default> Visitor<'de> for MapVisitor<S> {
{ {
let mut ret = HashMap::with_hasher(Default::default()); let mut ret = HashMap::with_hasher(Default::default());
while let Some(el) = seq.next_element::<String>()? { while let Some(el) = seq.next_element::<String>()? {
let (key, value) = el match el.split_once('=') {
.split_once('=') None => {
.ok_or_else(|| A::Error::invalid_value(Unexpected::Str(&el), &self))?; ret.insert(el.to_owned(), None);
ret.insert(key.to_owned(), value.to_owned()); }
Some((key, value)) => {
ret.insert(key.to_owned(), Some(value.to_owned()));
}
}
} }
Ok(ret) Ok(ret)
} }
@@ -83,7 +86,7 @@ pub(crate) fn deserialize_newline_or_comma_separated_vec<
deserializer.deserialize_seq(VectorVisitor(PhantomData)) 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 sequence of elements serializable into `String`s, or
/// * a single element serializable into `String`, then split on `,` and `\n` /// * a single element serializable into `String`, then split on `,` and `\n`
pub(crate) fn deserialize_newline_or_comma_separated_map< pub(crate) fn deserialize_newline_or_comma_separated_map<
@@ -92,6 +95,6 @@ pub(crate) fn deserialize_newline_or_comma_separated_map<
S: BuildHasher + Default, S: BuildHasher + Default,
>( >(
deserializer: D, deserializer: D,
) -> Result<HashMap<String, String, S>, D::Error> { ) -> Result<HashMap<String, Option<String>, S>, D::Error> {
deserializer.deserialize_map(MapVisitor(PhantomData)) deserializer.deserialize_map(MapVisitor(PhantomData))
} }

View File

@@ -77,11 +77,7 @@ impl<'a> RustAnalyzer<'a> {
let editioned_file_id = semantics let editioned_file_id = semantics
.attach_first_edition(file_id) .attach_first_edition(file_id)
.ok_or("failed to determine rust edition")?; .ok_or("failed to determine rust edition")?;
Ok(( Ok((semantics, editioned_file_id, input))
semantics,
EditionedFileId::new(semantics.db, editioned_file_id),
input,
))
} }
} }
} }

View File

@@ -174,7 +174,7 @@ impl<'a> Translator<'a> {
if let Some(semantics) = self.semantics.as_ref() { if let Some(semantics) = self.semantics.as_ref() {
let file_range = semantics.original_range(node.syntax()); let file_range = semantics.original_range(node.syntax());
let file_id = self.file_id?; 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) Some(file_range.range)
} else { } else {
None None
@@ -298,20 +298,18 @@ impl<'a> Translator<'a> {
if let Some(value) = semantics if let Some(value) = semantics
.hir_file_for(expanded) .hir_file_for(expanded)
.macro_file() .macro_file()
.and_then(|macro_file| { .and_then(|macro_call_id| semantics.db.parse_macro_expansion_error(macro_call_id))
semantics
.db
.parse_macro_expansion_error(macro_file.macro_call_id)
})
{ {
if let Some(err) = &value.err { if let Some(err) = &value.err {
let error = err.render_to_string(semantics.db); let error = err.render_to_string(semantics.db);
let hir_file_id = semantics.hir_file_for(node.syntax());
if err.span().anchor.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))
{
let location = err.span().range let location = err.span().range
+ semantics + semantics
.db .db
.ast_id_map(err.span().anchor.file_id.into()) .ast_id_map(hir_file_id)
.get_erased(err.span().anchor.ast_id) .get_erased(err.span().anchor.ast_id)
.text_range() .text_range()
.start(); .start();
@@ -363,10 +361,10 @@ impl<'a> Translator<'a> {
.as_ref() .as_ref()
.and_then(|s| s.expand_macro_call(mcall)) .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);
let expand_to = ra_ap_hir_expand::ExpandTo::from_call_site(mcall); let expand_to = ra_ap_hir_expand::ExpandTo::from_call_site(mcall);
let kind = expanded.kind(); 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( generated::MacroCall::emit_macro_call_expansion(
label, label,
value, value,
@@ -669,11 +667,11 @@ impl<'a> Translator<'a> {
) { ) {
// work around a bug in rust-analyzer AST generation machinery // work around a bug in rust-analyzer AST generation machinery
// this code was inspired by rust-analyzer's own workaround for this: // 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 // https://github.com/rust-lang/rust-analyzer/blob/a642aa8023be11d6bc027fc6a68c71c2f3fc7f72/crates/syntax/src/ast/node_ext.rs#L290-L297
if item.l_angle_token().is_some() { if let Some(anchor) = item.type_anchor() {
// <T> or <T as Trait> // <T> or <T as Trait>
// T is any TypeRef, Trait has to be a PathType // T is any TypeRef, Trait has to be a PathType
let mut type_refs = item let mut type_refs = anchor
.syntax() .syntax()
.children() .children()
.filter(|node| ast::Type::can_cast(node.kind())); .filter(|node| ast::Type::can_cast(node.kind()));
@@ -691,6 +689,13 @@ impl<'a> Translator<'a> {
{ {
generated::PathSegment::emit_trait_type_repr(label, t, &mut self.trap.writer) 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(),
);
} }
} }
@@ -743,9 +748,9 @@ impl<'a> Translator<'a> {
} }
let ExpandResult { let ExpandResult {
value: expanded, .. value: expanded, ..
} = semantics.expand_attr_macro(node)?; } = self.semantics.and_then(|s| s.expand_attr_macro(node))?;
self.emit_macro_expansion_parse_errors(node, &expanded); self.emit_macro_expansion_parse_errors(node, &expanded.value);
let macro_items = ast::MacroItems::cast(expanded).or_else(|| { let macro_items = ast::MacroItems::cast(expanded.value).or_else(|| {
let message = "attribute macro expansion cannot be cast to MacroItems".to_owned(); let message = "attribute macro expansion cannot be cast to MacroItems".to_owned();
let location = self.location_for_node(node); let location = self.location_for_node(node);
self.emit_diagnostic( self.emit_diagnostic(