mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #5838
5838: ⬆️ autocfg r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
aab5aaccf2
11 changed files with 21 additions and 19 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -76,9 +76,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
|
@ -1688,9 +1688,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ungrammar"
|
name = "ungrammar"
|
||||||
version = "1.1.1"
|
version = "1.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4e20e58a08ee1bcf8a4695cf74550cf054d6c489105f594beacb2c684210aad"
|
checksum = "bab6142ac77be714b1ea78faca6efaed5478c50724786b0fe80d8528d10692b3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
|
|
|
@ -239,7 +239,7 @@ impl ImportCandidate {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Self::TraitMethod(
|
Some(Self::TraitMethod(
|
||||||
sema.type_of_expr(&method_call.expr()?)?,
|
sema.type_of_expr(&method_call.receiver()?)?,
|
||||||
method_call.name_ref()?.syntax().to_string(),
|
method_call.name_ref()?.syntax().to_string(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
|
||||||
if name.text() != "unwrap" {
|
if name.text() != "unwrap" {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let caller = method_call.expr()?;
|
let caller = method_call.receiver()?;
|
||||||
let ty = ctx.sema.type_of_expr(&caller)?;
|
let ty = ctx.sema.type_of_expr(&caller)?;
|
||||||
let happy_variant = TryEnum::from_ty(&ctx.sema, &ty)?.happy_case();
|
let happy_variant = TryEnum::from_ty(&ctx.sema, &ty)?.happy_case();
|
||||||
let target = method_call.syntax().text_range();
|
let target = method_call.syntax().text_range();
|
||||||
|
|
|
@ -573,7 +573,7 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
|
|
||||||
fn is_unsafe_method_call(&self, method_call_expr: &ast::MethodCallExpr) -> bool {
|
fn is_unsafe_method_call(&self, method_call_expr: &ast::MethodCallExpr) -> bool {
|
||||||
method_call_expr
|
method_call_expr
|
||||||
.expr()
|
.receiver()
|
||||||
.and_then(|expr| {
|
.and_then(|expr| {
|
||||||
let field_expr = match expr {
|
let field_expr = match expr {
|
||||||
ast::Expr::FieldExpr(field_expr) => field_expr,
|
ast::Expr::FieldExpr(field_expr) => field_expr,
|
||||||
|
|
|
@ -329,7 +329,7 @@ impl ExprCollector<'_> {
|
||||||
self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
|
self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::Expr::MethodCallExpr(e) => {
|
ast::Expr::MethodCallExpr(e) => {
|
||||||
let receiver = self.collect_expr_opt(e.expr());
|
let receiver = self.collect_expr_opt(e.receiver());
|
||||||
let args = if let Some(arg_list) = e.arg_list() {
|
let args = if let Some(arg_list) = e.arg_list() {
|
||||||
arg_list.args().map(|e| self.collect_expr(e)).collect()
|
arg_list.args().map(|e| self.collect_expr(e)).collect()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -457,7 +457,7 @@ impl<'a> CompletionContext<'a> {
|
||||||
if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
|
if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
|
||||||
// As above
|
// As above
|
||||||
self.dot_receiver = method_call_expr
|
self.dot_receiver = method_call_expr
|
||||||
.expr()
|
.receiver()
|
||||||
.map(|e| e.syntax().text_range())
|
.map(|e| e.syntax().text_range())
|
||||||
.and_then(|r| find_node_with_range(original_file, r));
|
.and_then(|r| find_node_with_range(original_file, r));
|
||||||
self.is_call = true;
|
self.is_call = true;
|
||||||
|
|
|
@ -724,7 +724,8 @@ fn highlight_method_call(
|
||||||
hir::Access::Shared => (),
|
hir::Access::Shared => (),
|
||||||
hir::Access::Exclusive => h |= HighlightModifier::Mutable,
|
hir::Access::Exclusive => h |= HighlightModifier::Mutable,
|
||||||
hir::Access::Owned => {
|
hir::Access::Owned => {
|
||||||
if let Some(receiver_ty) = method_call.expr().and_then(|it| sema.type_of_expr(&it))
|
if let Some(receiver_ty) =
|
||||||
|
method_call.receiver().and_then(|it| sema.type_of_expr(&it))
|
||||||
{
|
{
|
||||||
if !receiver_ty.is_copy(sema.db) {
|
if !receiver_ty.is_copy(sema.db) {
|
||||||
h |= HighlightModifier::Consuming
|
h |= HighlightModifier::Consuming
|
||||||
|
|
|
@ -546,10 +546,12 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
|
||||||
// information on the placeholder match about autoderef and autoref. This allows us to use
|
// information on the placeholder match about autoderef and autoref. This allows us to use
|
||||||
// the placeholder in a context where autoderef and autoref don't apply.
|
// the placeholder in a context where autoderef and autoref don't apply.
|
||||||
if code_resolved_function.self_param(self.sema.db).is_some() {
|
if code_resolved_function.self_param(self.sema.db).is_some() {
|
||||||
if let (Some(pattern_type), Some(expr)) = (&pattern_ufcs.qualifier_type, &code.expr()) {
|
if let (Some(pattern_type), Some(expr)) =
|
||||||
|
(&pattern_ufcs.qualifier_type, &code.receiver())
|
||||||
|
{
|
||||||
let deref_count = self.check_expr_type(pattern_type, expr)?;
|
let deref_count = self.check_expr_type(pattern_type, expr)?;
|
||||||
let pattern_receiver = pattern_args.next();
|
let pattern_receiver = pattern_args.next();
|
||||||
self.attempt_match_opt(phase, pattern_receiver.clone(), code.expr())?;
|
self.attempt_match_opt(phase, pattern_receiver.clone(), code.receiver())?;
|
||||||
if let Phase::Second(match_out) = phase {
|
if let Phase::Second(match_out) = phase {
|
||||||
if let Some(placeholder_value) = pattern_receiver
|
if let Some(placeholder_value) = pattern_receiver
|
||||||
.and_then(|n| self.get_placeholder_for_node(n.syntax()))
|
.and_then(|n| self.get_placeholder_for_node(n.syntax()))
|
||||||
|
@ -568,7 +570,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.attempt_match_opt(phase, pattern_args.next(), code.expr())?;
|
self.attempt_match_opt(phase, pattern_args.next(), code.receiver())?;
|
||||||
}
|
}
|
||||||
let mut code_args =
|
let mut code_args =
|
||||||
code.arg_list().ok_or_else(|| match_error!("Code method call has no args"))?.args();
|
code.arg_list().ok_or_else(|| match_error!("Code method call has no args"))?.args();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use crate::{resolving::ResolvedRule, Match, SsrMatches};
|
use crate::{resolving::ResolvedRule, Match, SsrMatches};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use syntax::ast::{self, AstToken};
|
use syntax::ast::{self, AstNode, AstToken};
|
||||||
use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize};
|
use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
use text_edit::TextEdit;
|
use text_edit::TextEdit;
|
||||||
|
@ -93,7 +93,6 @@ impl ReplacementRenderer<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_node(&mut self, node: &SyntaxNode) {
|
fn render_node(&mut self, node: &SyntaxNode) {
|
||||||
use syntax::ast::AstNode;
|
|
||||||
if let Some(mod_path) = self.match_info.rendered_template_paths.get(&node) {
|
if let Some(mod_path) = self.match_info.rendered_template_paths.get(&node) {
|
||||||
self.out.push_str(&mod_path.to_string());
|
self.out.push_str(&mod_path.to_string());
|
||||||
// Emit everything except for the segment's name-ref, since we already effectively
|
// Emit everything except for the segment's name-ref, since we already effectively
|
||||||
|
@ -206,11 +205,10 @@ impl ReplacementRenderer<'_> {
|
||||||
/// method call doesn't count. e.g. if the token is `$a`, then `$a.foo()` will return true, while
|
/// method call doesn't count. e.g. if the token is `$a`, then `$a.foo()` will return true, while
|
||||||
/// `($a + $b).foo()` or `x.foo($a)` will return false.
|
/// `($a + $b).foo()` or `x.foo($a)` will return false.
|
||||||
fn token_is_method_call_receiver(token: &SyntaxToken) -> bool {
|
fn token_is_method_call_receiver(token: &SyntaxToken) -> bool {
|
||||||
use syntax::ast::AstNode;
|
|
||||||
// Find the first method call among the ancestors of `token`, then check if the only token
|
// Find the first method call among the ancestors of `token`, then check if the only token
|
||||||
// within the receiver is `token`.
|
// within the receiver is `token`.
|
||||||
if let Some(receiver) =
|
if let Some(receiver) =
|
||||||
token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.expr())
|
token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.receiver())
|
||||||
{
|
{
|
||||||
let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| {
|
let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| {
|
||||||
match node_or_token {
|
match node_or_token {
|
||||||
|
@ -226,7 +224,6 @@ fn token_is_method_call_receiver(token: &SyntaxToken) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_as_kind(code: &str, kind: SyntaxKind) -> Option<SyntaxNode> {
|
fn parse_as_kind(code: &str, kind: SyntaxKind) -> Option<SyntaxNode> {
|
||||||
use syntax::ast::AstNode;
|
|
||||||
if ast::Expr::can_cast(kind) {
|
if ast::Expr::can_cast(kind) {
|
||||||
if let Ok(expr) = ast::Expr::parse(code) {
|
if let Ok(expr) = ast::Expr::parse(code) {
|
||||||
return Some(expr.syntax().clone());
|
return Some(expr.syntax().clone());
|
||||||
|
|
|
@ -66,6 +66,7 @@ impl ParamList {
|
||||||
pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
|
pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
|
||||||
pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
|
pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
|
||||||
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
|
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
|
||||||
|
pub fn pipe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![|]) }
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct RetType {
|
pub struct RetType {
|
||||||
|
@ -809,7 +810,7 @@ pub struct MethodCallExpr {
|
||||||
impl ast::AttrsOwner for MethodCallExpr {}
|
impl ast::AttrsOwner for MethodCallExpr {}
|
||||||
impl ast::ArgListOwner for MethodCallExpr {}
|
impl ast::ArgListOwner for MethodCallExpr {}
|
||||||
impl MethodCallExpr {
|
impl MethodCallExpr {
|
||||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
pub fn receiver(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||||
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
|
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
|
||||||
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
||||||
pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
|
pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
|
||||||
|
|
|
@ -477,6 +477,7 @@ impl Field {
|
||||||
"#" => "pound",
|
"#" => "pound",
|
||||||
"?" => "question_mark",
|
"?" => "question_mark",
|
||||||
"," => "comma",
|
"," => "comma",
|
||||||
|
"|" => "pipe",
|
||||||
_ => name,
|
_ => name,
|
||||||
};
|
};
|
||||||
format_ident!("{}_token", name)
|
format_ident!("{}_token", name)
|
||||||
|
|
Loading…
Reference in a new issue