Skip to content

Commit

Permalink
Auto merge of rust-lang#16163 - Veykril:goto-impl-fix, r=Veykril
Browse files Browse the repository at this point in the history
fix: Deduplicate annotations

Fixes rust-lang/rust-analyzer#16157
  • Loading branch information
bors committed Dec 19, 2023
2 parents dbd0b03 + 002e611 commit 7204ee1
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 161 deletions.
2 changes: 1 addition & 1 deletion crates/hir-expand/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl InFile<TextRange> {
}

impl<N: AstNode> InFile<N> {
pub fn original_ast_node(self, db: &dyn db::ExpandDatabase) -> Option<InRealFile<N>> {
pub fn original_ast_node_rooted(self, db: &dyn db::ExpandDatabase) -> Option<InRealFile<N>> {
// This kind of upmapping can only be achieved in attribute expanded files,
// as we don't have node inputs otherwise and therefore can't find an `N` node in the input
let file_id = match self.file_id.repr() {
Expand Down
5 changes: 2 additions & 3 deletions crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ impl<'db> SemanticsImpl<'db> {
}

/// Descend the token into its macro call if it is part of one, returning the tokens in the
/// expansion that it is associated with. If `offset` points into the token's range, it will
/// be considered for the mapping in case of inline format args.
/// expansion that it is associated with.
pub fn descend_into_macros(
&self,
mode: DescendPreference,
Expand Down Expand Up @@ -850,7 +849,7 @@ impl<'db> SemanticsImpl<'db> {
/// Attempts to map the node out of macro expanded files.
/// This only work for attribute expansions, as other ones do not have nodes as input.
pub fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map(
self.wrap_node_infile(node).original_ast_node_rooted(self.db.upcast()).map(
|InRealFile { file_id, value }| {
self.cache(find_root(value.syntax()), file_id.into());
value
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/generate_enum_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn add_variant_to_accumulator(
parent: PathParent,
) -> Option<()> {
let db = ctx.db();
let InRealFile { file_id, value: enum_node } = adt.source(db)?.original_ast_node(db)?;
let InRealFile { file_id, value: enum_node } = adt.source(db)?.original_ast_node_rooted(db)?;

acc.add(
AssistId("generate_enum_variant", AssistKind::Generate),
Expand Down
4 changes: 2 additions & 2 deletions crates/ide-db/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ fn source_edit_from_def(
if let Definition::Local(local) = def {
let mut file_id = None;
for source in local.sources(sema.db) {
let source = match source.source.clone().original_ast_node(sema.db) {
let source = match source.source.clone().original_ast_node_rooted(sema.db) {
Some(source) => source,
None => match source
.source
Expand Down Expand Up @@ -560,7 +560,7 @@ fn source_edit_from_def(
}
} else {
// Foo { ref mut field } -> Foo { field: ref mut new_name }
// ^ insert `field: `
// original_ast_node_rootedd: `
// ^^^^^ replace this with `new_name`
edit.insert(
pat.syntax().text_range().start(),
Expand Down
Loading

0 comments on commit 7204ee1

Please sign in to comment.