Skip to content

Commit 81a9956

Browse files
committed
Auto merge of rust-lang#17898 - Veykril:descend-2.0, r=Veykril
internal: Improve macro token mapping heuristics Fixes rust-lang/rust-analyzer#16235
2 parents 06228b9 + 71c7cea commit 81a9956

26 files changed

+487
-419
lines changed

src/tools/rust-analyzer/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ style = { level = "warn", priority = -1 }
184184
suspicious = { level = "warn", priority = -1 }
185185

186186
## allow following lints
187+
# subjective
188+
single_match = "allow"
187189
# () makes a fine error in most cases
188190
result_unit_err = "allow"
189191
# We don't expose public APIs that matter like this

src/tools/rust-analyzer/crates/hir-expand/src/files.rs

+9
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,12 @@ impl<N: AstNode> InFile<N> {
461461
Some(InRealFile::new(file_id, value))
462462
}
463463
}
464+
465+
impl<T> InFile<T> {
466+
pub fn into_real_file(self) -> Result<InRealFile<T>, InFile<T>> {
467+
match self.file_id.repr() {
468+
HirFileIdRepr::FileId(file_id) => Ok(InRealFile { file_id, value: self.value }),
469+
HirFileIdRepr::MacroFile(_) => Err(self),
470+
}
471+
}
472+
}

src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ pub enum MacroCallKind {
279279
}
280280

281281
pub trait HirFileIdExt {
282+
fn edition(self, db: &dyn ExpandDatabase) -> Edition;
282283
/// Returns the original file of this macro call hierarchy.
283284
fn original_file(self, db: &dyn ExpandDatabase) -> EditionedFileId;
284285

@@ -293,6 +294,12 @@ pub trait HirFileIdExt {
293294
}
294295

295296
impl HirFileIdExt for HirFileId {
297+
fn edition(self, db: &dyn ExpandDatabase) -> Edition {
298+
match self.repr() {
299+
HirFileIdRepr::FileId(file_id) => file_id.edition(),
300+
HirFileIdRepr::MacroFile(m) => m.macro_call_id.lookup(db).def.edition,
301+
}
302+
}
296303
fn original_file(self, db: &dyn ExpandDatabase) -> EditionedFileId {
297304
let mut file_id = self;
298305
loop {

src/tools/rust-analyzer/crates/hir/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ pub use crate::{
9393
diagnostics::*,
9494
has_source::HasSource,
9595
semantics::{
96-
DescendPreference, PathResolution, Semantics, SemanticsImpl, SemanticsScope, TypeInfo,
97-
VisibleTraits,
96+
PathResolution, Semantics, SemanticsImpl, SemanticsScope, TypeInfo, VisibleTraits,
9897
},
9998
};
10099
pub use hir_ty::method_resolution::TyFingerprint;

0 commit comments

Comments
 (0)