Skip to content

Commit

Permalink
Auto merge of rust-lang#17898 - Veykril:descend-2.0, r=Veykril
Browse files Browse the repository at this point in the history
internal: Improve macro token mapping heuristics

Fixes rust-lang/rust-analyzer#16235
  • Loading branch information
bors committed Aug 22, 2024
2 parents 06228b9 + 71c7cea commit 81a9956
Show file tree
Hide file tree
Showing 26 changed files with 487 additions and 419 deletions.
2 changes: 2 additions & 0 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ style = { level = "warn", priority = -1 }
suspicious = { level = "warn", priority = -1 }

## allow following lints
# subjective
single_match = "allow"
# () makes a fine error in most cases
result_unit_err = "allow"
# We don't expose public APIs that matter like this
Expand Down
9 changes: 9 additions & 0 deletions src/tools/rust-analyzer/crates/hir-expand/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,12 @@ impl<N: AstNode> InFile<N> {
Some(InRealFile::new(file_id, value))
}
}

impl<T> InFile<T> {
pub fn into_real_file(self) -> Result<InRealFile<T>, InFile<T>> {
match self.file_id.repr() {
HirFileIdRepr::FileId(file_id) => Ok(InRealFile { file_id, value: self.value }),
HirFileIdRepr::MacroFile(_) => Err(self),
}
}
}
7 changes: 7 additions & 0 deletions src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ pub enum MacroCallKind {
}

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

Expand All @@ -293,6 +294,12 @@ pub trait HirFileIdExt {
}

impl HirFileIdExt for HirFileId {
fn edition(self, db: &dyn ExpandDatabase) -> Edition {
match self.repr() {
HirFileIdRepr::FileId(file_id) => file_id.edition(),
HirFileIdRepr::MacroFile(m) => m.macro_call_id.lookup(db).def.edition,
}
}
fn original_file(self, db: &dyn ExpandDatabase) -> EditionedFileId {
let mut file_id = self;
loop {
Expand Down
3 changes: 1 addition & 2 deletions src/tools/rust-analyzer/crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ pub use crate::{
diagnostics::*,
has_source::HasSource,
semantics::{
DescendPreference, PathResolution, Semantics, SemanticsImpl, SemanticsScope, TypeInfo,
VisibleTraits,
PathResolution, Semantics, SemanticsImpl, SemanticsScope, TypeInfo, VisibleTraits,
},
};
pub use hir_ty::method_resolution::TyFingerprint;
Expand Down
Loading

0 comments on commit 81a9956

Please sign in to comment.