Skip to content

Commit 92f5e80

Browse files
committed
Fix edition used for include macro parsing
1 parent f4199f7 commit 92f5e80

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
name, quote,
1919
quote::dollar_crate,
2020
tt::{self, DelimSpan},
21-
ExpandError, ExpandResult, HirFileIdExt, MacroCallId, MacroFileIdExt,
21+
ExpandError, ExpandResult, HirFileIdExt, Lookup as _, MacroCallId,
2222
};
2323

2424
macro_rules! register_builtin {
@@ -687,8 +687,8 @@ fn relative_file(
687687
path_str: &str,
688688
allow_recursion: bool,
689689
) -> Result<EditionedFileId, ExpandError> {
690-
let call_site =
691-
call_id.as_macro_file().parent(db).original_file_respecting_includes(db).file_id();
690+
let lookup = call_id.lookup(db);
691+
let call_site = lookup.kind.file_id().original_file_respecting_includes(db).file_id();
692692
let path = AnchoredPath { anchor: call_site, path: path_str };
693693
let res = db
694694
.resolve_path(path)
@@ -697,7 +697,7 @@ fn relative_file(
697697
if res == call_site && !allow_recursion {
698698
Err(ExpandError::other(format!("recursive inclusion of `{path_str}`")))
699699
} else {
700-
Ok(EditionedFileId::new(res, Edition::CURRENT_FIXME))
700+
Ok(EditionedFileId::new(res, db.crate_graph()[lookup.krate].edition))
701701
}
702702
}
703703

crates/parser/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
3434

3535
impl<'t> Parser<'t> {
3636
pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
37-
Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition: edition }
37+
Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition }
3838
}
3939

4040
pub(crate) fn finish(self) -> Vec<Event> {

crates/rust-analyzer/src/cli/diagnostics.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use project_model::{CargoConfig, RustLibSource};
55
use rustc_hash::FxHashSet;
66

77
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module};
8-
use ide::{AnalysisHost, AssistResolveStrategy, DiagnosticsConfig, Severity};
9-
use ide_db::base_db::SourceDatabaseExt;
8+
use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Severity};
9+
use ide_db::{base_db::SourceDatabaseExt, LineIndexDatabase};
1010
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
1111

1212
use crate::cli::flags;
@@ -74,7 +74,11 @@ impl flags::Diagnostics {
7474
found_error = true;
7575
}
7676

77-
println!("{diagnostic:?}");
77+
let Diagnostic { code, message, range, severity, .. } = diagnostic;
78+
let line_index = db.line_index(range.file_id);
79+
let start = line_index.line_col(range.range.start());
80+
let end = line_index.line_col(range.range.end());
81+
println!("{severity:?} {code:?} from {start:?} to {end:?}: {message}");
7882
}
7983

8084
visited_files.insert(file_id);

crates/syntax/src/parsing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) use crate::parsing::reparsing::incremental_reparse;
1212
pub(crate) fn parse_text(text: &str, edition: parser::Edition) -> (GreenNode, Vec<SyntaxError>) {
1313
let _p = tracing::info_span!("parse_text").entered();
1414
let lexed = parser::LexedStr::new(edition, text);
15-
let parser_input = lexed.to_input();
15+
let parser_input = lexed.to_input(edition);
1616
let parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input, edition);
1717
let (node, errors, _eof) = build_tree(lexed, parser_output);
1818
(node, errors)
@@ -25,7 +25,7 @@ pub(crate) fn parse_text_at(
2525
) -> (GreenNode, Vec<SyntaxError>) {
2626
let _p = tracing::info_span!("parse_text_at").entered();
2727
let lexed = parser::LexedStr::new(edition, text);
28-
let parser_input = lexed.to_input();
28+
let parser_input = lexed.to_input(edition);
2929
let parser_output = entry.parse(&parser_input, edition);
3030
let (node, errors, _eof) = build_tree(lexed, parser_output);
3131
(node, errors)

crates/syntax/src/parsing/reparsing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn reparse_block(
9292
let text = get_text_after_edit(node.clone().into(), edit);
9393

9494
let lexed = parser::LexedStr::new(edition, text.as_str());
95-
let parser_input = lexed.to_input();
95+
let parser_input = lexed.to_input(edition);
9696
if !is_balanced(&lexed) {
9797
return None;
9898
}

xtask/src/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
time::{Instant, SystemTime, UNIX_EPOCH},
77
};
88

9-
use anyhow::{bail, format_err};
9+
use anyhow::format_err;
1010
use xshell::{cmd, Shell};
1111

1212
use crate::flags::{self, MeasurementType};
@@ -193,7 +193,7 @@ impl Metrics {
193193
impl Host {
194194
fn new(sh: &Shell) -> anyhow::Result<Host> {
195195
if cfg!(not(target_os = "linux")) {
196-
bail!("can only collect metrics on Linux ");
196+
return Ok(Host { os: "unknown".into(), cpu: "unknown".into(), mem: "unknown".into() });
197197
}
198198

199199
let os = read_field(sh, "/etc/os-release", "PRETTY_NAME=")?.trim_matches('"').to_owned();

0 commit comments

Comments
 (0)