Unnamed repository; edit this file 'description' to name the repository.
Fix edition used for include macro parsing
Lukas Wirth 2024-07-20
parent f4199f7 · commit 92f5e80
-rw-r--r--crates/hir-expand/src/builtin_fn_macro.rs8
-rw-r--r--crates/parser/src/parser.rs2
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs10
-rw-r--r--crates/syntax/src/parsing.rs4
-rw-r--r--crates/syntax/src/parsing/reparsing.rs2
-rw-r--r--xtask/src/metrics.rs4
6 files changed, 17 insertions, 13 deletions
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index 7f25b7dc03..6272e1df7d 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -18,7 +18,7 @@ use crate::{
name, quote,
quote::dollar_crate,
tt::{self, DelimSpan},
- ExpandError, ExpandResult, HirFileIdExt, MacroCallId, MacroFileIdExt,
+ ExpandError, ExpandResult, HirFileIdExt, Lookup as _, MacroCallId,
};
macro_rules! register_builtin {
@@ -687,8 +687,8 @@ fn relative_file(
path_str: &str,
allow_recursion: bool,
) -> Result<EditionedFileId, ExpandError> {
- let call_site =
- call_id.as_macro_file().parent(db).original_file_respecting_includes(db).file_id();
+ let lookup = call_id.lookup(db);
+ let call_site = lookup.kind.file_id().original_file_respecting_includes(db).file_id();
let path = AnchoredPath { anchor: call_site, path: path_str };
let res = db
.resolve_path(path)
@@ -697,7 +697,7 @@ fn relative_file(
if res == call_site && !allow_recursion {
Err(ExpandError::other(format!("recursive inclusion of `{path_str}`")))
} else {
- Ok(EditionedFileId::new(res, Edition::CURRENT_FIXME))
+ Ok(EditionedFileId::new(res, db.crate_graph()[lookup.krate].edition))
}
}
diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs
index 40e3c11a1d..7d3eb5de25 100644
--- a/crates/parser/src/parser.rs
+++ b/crates/parser/src/parser.rs
@@ -34,7 +34,7 @@ static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
impl<'t> Parser<'t> {
pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
- Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition: edition }
+ Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition }
}
pub(crate) fn finish(self) -> Vec<Event> {
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index 489bb42eec..4ddeb4ab1b 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -5,8 +5,8 @@ use project_model::{CargoConfig, RustLibSource};
use rustc_hash::FxHashSet;
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module};
-use ide::{AnalysisHost, AssistResolveStrategy, DiagnosticsConfig, Severity};
-use ide_db::base_db::SourceDatabaseExt;
+use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Severity};
+use ide_db::{base_db::SourceDatabaseExt, LineIndexDatabase};
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
use crate::cli::flags;
@@ -74,7 +74,11 @@ impl flags::Diagnostics {
found_error = true;
}
- println!("{diagnostic:?}");
+ let Diagnostic { code, message, range, severity, .. } = diagnostic;
+ let line_index = db.line_index(range.file_id);
+ let start = line_index.line_col(range.range.start());
+ let end = line_index.line_col(range.range.end());
+ println!("{severity:?} {code:?} from {start:?} to {end:?}: {message}");
}
visited_files.insert(file_id);
diff --git a/crates/syntax/src/parsing.rs b/crates/syntax/src/parsing.rs
index e52daa42f1..2c7828c052 100644
--- a/crates/syntax/src/parsing.rs
+++ b/crates/syntax/src/parsing.rs
@@ -12,7 +12,7 @@ pub(crate) use crate::parsing::reparsing::incremental_reparse;
pub(crate) fn parse_text(text: &str, edition: parser::Edition) -> (GreenNode, Vec<SyntaxError>) {
let _p = tracing::info_span!("parse_text").entered();
let lexed = parser::LexedStr::new(edition, text);
- let parser_input = lexed.to_input();
+ let parser_input = lexed.to_input(edition);
let parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input, edition);
let (node, errors, _eof) = build_tree(lexed, parser_output);
(node, errors)
@@ -25,7 +25,7 @@ pub(crate) fn parse_text_at(
) -> (GreenNode, Vec<SyntaxError>) {
let _p = tracing::info_span!("parse_text_at").entered();
let lexed = parser::LexedStr::new(edition, text);
- let parser_input = lexed.to_input();
+ let parser_input = lexed.to_input(edition);
let parser_output = entry.parse(&parser_input, edition);
let (node, errors, _eof) = build_tree(lexed, parser_output);
(node, errors)
diff --git a/crates/syntax/src/parsing/reparsing.rs b/crates/syntax/src/parsing/reparsing.rs
index a895d9e274..a5cc4e90df 100644
--- a/crates/syntax/src/parsing/reparsing.rs
+++ b/crates/syntax/src/parsing/reparsing.rs
@@ -92,7 +92,7 @@ fn reparse_block(
let text = get_text_after_edit(node.clone().into(), edit);
let lexed = parser::LexedStr::new(edition, text.as_str());
- let parser_input = lexed.to_input();
+ let parser_input = lexed.to_input(edition);
if !is_balanced(&lexed) {
return None;
}
diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs
index 9a7785dd43..21001c28da 100644
--- a/xtask/src/metrics.rs
+++ b/xtask/src/metrics.rs
@@ -6,7 +6,7 @@ use std::{
time::{Instant, SystemTime, UNIX_EPOCH},
};
-use anyhow::{bail, format_err};
+use anyhow::format_err;
use xshell::{cmd, Shell};
use crate::flags::{self, MeasurementType};
@@ -193,7 +193,7 @@ impl Metrics {
impl Host {
fn new(sh: &Shell) -> anyhow::Result<Host> {
if cfg!(not(target_os = "linux")) {
- bail!("can only collect metrics on Linux ");
+ return Ok(Host { os: "unknown".into(), cpu: "unknown".into(), mem: "unknown".into() });
}
let os = read_field(sh, "/etc/os-release", "PRETTY_NAME=")?.trim_matches('"').to_owned();