mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Fix add-new assist
This commit is contained in:
parent
1889b3c7b5
commit
20186cdf89
1 changed files with 64 additions and 5 deletions
|
@ -158,9 +158,12 @@ fn find_struct_impl(
|
||||||
let same_ty = blk.target_ty(db) == struct_ty;
|
let same_ty = blk.target_ty(db) == struct_ty;
|
||||||
let not_trait_impl = blk.target_trait(db).is_none();
|
let not_trait_impl = blk.target_trait(db).is_none();
|
||||||
|
|
||||||
found_new_fn = has_new_fn(impl_blk);
|
if !(same_ty && not_trait_impl) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
same_ty && not_trait_impl
|
found_new_fn = has_new_fn(impl_blk);
|
||||||
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
if found_new_fn {
|
if found_new_fn {
|
||||||
|
@ -186,9 +189,10 @@ fn has_new_fn(imp: &ast::ImplBlock) -> bool {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target};
|
use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn test_add_new() {
|
fn test_add_new() {
|
||||||
|
@ -376,4 +380,59 @@ struct EvenMoreIrrelevant;
|
||||||
struct Foo<'a, T: Foo<'a>> {}",
|
struct Foo<'a, T: Foo<'a>> {}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unrelated_new() {
|
||||||
|
check_assist(
|
||||||
|
add_new,
|
||||||
|
r##"
|
||||||
|
pub struct AstId<N: AstNode> {
|
||||||
|
file_id: HirFileId,
|
||||||
|
file_ast_id: FileAstId<N>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<N: AstNode> AstId<N> {
|
||||||
|
pub fn new(file_id: HirFileId, file_ast_id: FileAstId<N>) -> AstId<N> {
|
||||||
|
AstId { file_id, file_ast_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Source<T> {
|
||||||
|
pub file_id: HirFileId,<|>
|
||||||
|
pub ast: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Source<T> {
|
||||||
|
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
|
||||||
|
Source { file_id: self.file_id, ast: f(self.ast) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"##,
|
||||||
|
r##"
|
||||||
|
pub struct AstId<N: AstNode> {
|
||||||
|
file_id: HirFileId,
|
||||||
|
file_ast_id: FileAstId<N>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<N: AstNode> AstId<N> {
|
||||||
|
pub fn new(file_id: HirFileId, file_ast_id: FileAstId<N>) -> AstId<N> {
|
||||||
|
AstId { file_id, file_ast_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Source<T> {
|
||||||
|
pub file_id: HirFileId,
|
||||||
|
pub ast: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Source<T> {
|
||||||
|
pub fn new(file_id: HirFileId, ast: T) -> Self { Self { file_id, ast } }<|>
|
||||||
|
|
||||||
|
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
|
||||||
|
Source { file_id: self.file_id, ast: f(self.ast) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"##,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue