mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
fix: Fix proc-macro server not using the supplied span in Ident::new
This commit is contained in:
parent
45ff51ba22
commit
f6def3ccdf
@ -234,15 +234,6 @@ fn highlight_name_ref(
|
|||||||
None if syntactic_name_ref_highlighting => {
|
None if syntactic_name_ref_highlighting => {
|
||||||
return highlight_name_ref_by_syntax(name_ref, sema, krate)
|
return highlight_name_ref_by_syntax(name_ref, sema, krate)
|
||||||
}
|
}
|
||||||
// FIXME: Workaround for https://github.com/rust-analyzer/rust-analyzer/issues/10708
|
|
||||||
//
|
|
||||||
// Some popular proc macros (namely async_trait) will rewrite `self` in such a way that it no
|
|
||||||
// longer resolves via NameRefClass. If we can't be resolved, but we know we're a self token,
|
|
||||||
// within a function with a self param, pretend to still be `self`, rather than
|
|
||||||
// an unresolved reference.
|
|
||||||
None if name_ref.self_token().is_some() && is_in_fn_with_self_param(&name_ref) => {
|
|
||||||
return SymbolKind::SelfParam.into()
|
|
||||||
}
|
|
||||||
// FIXME: This is required for helper attributes used by proc-macros, as those do not map down
|
// FIXME: This is required for helper attributes used by proc-macros, as those do not map down
|
||||||
// to anything when used.
|
// to anything when used.
|
||||||
// We can fix this for derive attributes since derive helpers are recorded, but not for
|
// We can fix this for derive attributes since derive helpers are recorded, but not for
|
||||||
@ -712,14 +703,3 @@ fn parents_match(mut node: NodeOrToken<SyntaxNode, SyntaxToken>, mut kinds: &[Sy
|
|||||||
fn parent_matches<N: AstNode>(token: &SyntaxToken) -> bool {
|
fn parent_matches<N: AstNode>(token: &SyntaxToken) -> bool {
|
||||||
token.parent().map_or(false, |it| N::can_cast(it.kind()))
|
token.parent().map_or(false, |it| N::can_cast(it.kind()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_in_fn_with_self_param(node: &ast::NameRef) -> bool {
|
|
||||||
node.syntax()
|
|
||||||
.ancestors()
|
|
||||||
.find_map(ast::Item::cast)
|
|
||||||
.and_then(|item| match item {
|
|
||||||
ast::Item::Fn(fn_) => fn_.param_list()?.self_param(),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.is_some()
|
|
||||||
}
|
|
||||||
|
@ -463,13 +463,8 @@ impl server::Punct for Rustc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl server::Ident for Rustc {
|
impl server::Ident for Rustc {
|
||||||
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
|
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
|
||||||
IdentId(
|
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
|
||||||
self.ident_interner.intern(&IdentData(tt::Ident {
|
|
||||||
text: string.into(),
|
|
||||||
id: tt::TokenId::unspecified(),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
||||||
|
@ -463,13 +463,8 @@ impl server::Punct for Rustc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl server::Ident for Rustc {
|
impl server::Ident for Rustc {
|
||||||
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
|
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
|
||||||
IdentId(
|
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
|
||||||
self.ident_interner.intern(&IdentData(tt::Ident {
|
|
||||||
text: string.into(),
|
|
||||||
id: tt::TokenId::unspecified(),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
||||||
|
@ -464,13 +464,8 @@ impl server::Punct for Rustc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl server::Ident for Rustc {
|
impl server::Ident for Rustc {
|
||||||
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
|
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
|
||||||
IdentId(
|
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
|
||||||
self.ident_interner.intern(&IdentData(tt::Ident {
|
|
||||||
text: string.into(),
|
|
||||||
id: tt::TokenId::unspecified(),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
||||||
|
@ -468,13 +468,8 @@ impl server::Punct for Rustc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl server::Ident for Rustc {
|
impl server::Ident for Rustc {
|
||||||
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
|
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
|
||||||
IdentId(
|
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
|
||||||
self.ident_interner.intern(&IdentData(tt::Ident {
|
|
||||||
text: string.into(),
|
|
||||||
id: tt::TokenId::unspecified(),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
||||||
|
Loading…
Reference in New Issue
Block a user