mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Revert function structs back to using bool to track self param, use first param for self information in syntax highlighting instead
This commit is contained in:
parent
aca3d6c57e
commit
c5cc24cb31
@ -11,7 +11,6 @@ use hir_def::{
|
||||
docs::Documentation,
|
||||
expr::{BindingAnnotation, Pat, PatId},
|
||||
import_map,
|
||||
item_tree::SelfParam,
|
||||
per_ns::PerNs,
|
||||
resolver::{HasResolver, Resolver},
|
||||
src::HasSource as _,
|
||||
@ -671,8 +670,8 @@ impl Function {
|
||||
db.function_data(self.id).name.clone()
|
||||
}
|
||||
|
||||
pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
|
||||
db.function_data(self.id).self_param
|
||||
pub fn has_self_param(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).has_self_param
|
||||
}
|
||||
|
||||
pub fn params(self, db: &dyn HirDatabase) -> Vec<TypeRef> {
|
||||
|
@ -49,7 +49,7 @@ pub use hir_def::{
|
||||
docs::Documentation,
|
||||
nameres::ModuleSource,
|
||||
path::{ModPath, Path, PathKind},
|
||||
type_ref::Mutability,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
};
|
||||
pub use hir_expand::{
|
||||
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc,
|
||||
|
@ -10,7 +10,7 @@ use crate::{
|
||||
attr::Attrs,
|
||||
body::Expander,
|
||||
db::DefDatabase,
|
||||
item_tree::{AssocItem, ItemTreeId, ModItem, SelfParam},
|
||||
item_tree::{AssocItem, ItemTreeId, ModItem},
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
visibility::RawVisibility,
|
||||
AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId,
|
||||
@ -25,7 +25,7 @@ pub struct FunctionData {
|
||||
pub attrs: Attrs,
|
||||
/// True if the first param is `self`. This is relevant to decide whether this
|
||||
/// can be called as a method.
|
||||
pub self_param: Option<SelfParam>,
|
||||
pub has_self_param: bool,
|
||||
pub is_unsafe: bool,
|
||||
pub is_varargs: bool,
|
||||
pub visibility: RawVisibility,
|
||||
@ -42,7 +42,7 @@ impl FunctionData {
|
||||
params: func.params.to_vec(),
|
||||
ret_type: func.ret_type.clone(),
|
||||
attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(),
|
||||
self_param: func.self_param,
|
||||
has_self_param: func.has_self_param,
|
||||
is_unsafe: func.is_unsafe,
|
||||
is_varargs: func.is_varargs,
|
||||
visibility: item_tree[func.visibility].clone(),
|
||||
|
@ -500,7 +500,7 @@ pub struct Function {
|
||||
pub name: Name,
|
||||
pub visibility: RawVisibilityId,
|
||||
pub generic_params: GenericParamsId,
|
||||
pub self_param: Option<SelfParam>,
|
||||
pub has_self_param: bool,
|
||||
pub is_unsafe: bool,
|
||||
pub params: Box<[TypeRef]>,
|
||||
pub is_varargs: bool,
|
||||
@ -508,12 +508,6 @@ pub struct Function {
|
||||
pub ast_id: FileAstId<ast::Fn>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct SelfParam {
|
||||
pub is_ref: bool,
|
||||
pub is_mut: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Struct {
|
||||
pub name: Name,
|
||||
|
@ -283,7 +283,7 @@ impl Ctx {
|
||||
let name = func.name()?.as_name();
|
||||
|
||||
let mut params = Vec::new();
|
||||
let mut func_self_param = None;
|
||||
let mut has_self_param = false;
|
||||
if let Some(param_list) = func.param_list() {
|
||||
if let Some(self_param) = param_list.self_param() {
|
||||
let self_type = match self_param.ty() {
|
||||
@ -302,10 +302,7 @@ impl Ctx {
|
||||
}
|
||||
};
|
||||
params.push(self_type);
|
||||
func_self_param = Some(SelfParam {
|
||||
is_ref: self_param.amp_token().is_some(),
|
||||
is_mut: self_param.mut_token().is_some(),
|
||||
});
|
||||
has_self_param = true;
|
||||
}
|
||||
for param in param_list.params() {
|
||||
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
|
||||
@ -338,7 +335,7 @@ impl Ctx {
|
||||
name,
|
||||
visibility,
|
||||
generic_params: GenericParamsId::EMPTY,
|
||||
self_param: func_self_param,
|
||||
has_self_param,
|
||||
is_unsafe: func.unsafe_token().is_some(),
|
||||
params: params.into_boxed_slice(),
|
||||
is_varargs,
|
||||
|
@ -640,7 +640,7 @@ fn is_valid_candidate(
|
||||
}
|
||||
}
|
||||
if let Some(receiver_ty) = receiver_ty {
|
||||
if data.self_param.is_none() {
|
||||
if !data.has_self_param {
|
||||
return false;
|
||||
}
|
||||
let transformed_receiver_ty = match transform_receiver_ty(db, m, self_ty) {
|
||||
|
@ -48,7 +48,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &T
|
||||
let mut seen_methods = FxHashSet::default();
|
||||
let traits_in_scope = ctx.scope.traits_in_scope();
|
||||
receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {
|
||||
if func.self_param(ctx.db).is_some()
|
||||
if func.has_self_param(ctx.db)
|
||||
&& ctx.scope.module().map_or(true, |m| func.is_visible_from(ctx.db, m))
|
||||
&& seen_methods.insert(func.name(ctx.db))
|
||||
{
|
||||
|
@ -136,7 +136,7 @@ fn add_function_impl(
|
||||
.lookup_by(fn_name)
|
||||
.set_documentation(func.docs(ctx.db));
|
||||
|
||||
let completion_kind = if func.self_param(ctx.db).is_some() {
|
||||
let completion_kind = if func.has_self_param(ctx.db) {
|
||||
CompletionItemKind::Method
|
||||
} else {
|
||||
CompletionItemKind::Function
|
||||
|
@ -191,7 +191,7 @@ impl Completions {
|
||||
func: hir::Function,
|
||||
local_name: Option<String>,
|
||||
) {
|
||||
let has_self_param = func.self_param(ctx.db).is_some();
|
||||
let has_self_param = func.has_self_param(ctx.db);
|
||||
|
||||
let name = local_name.unwrap_or_else(|| func.name(ctx.db).to_string());
|
||||
let ast_node = func.source(ctx.db).value;
|
||||
|
@ -4,7 +4,7 @@ mod injection;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use hir::{Name, Semantics, VariantDef};
|
||||
use hir::{Name, Semantics, TypeRef, VariantDef};
|
||||
use ra_ide_db::{
|
||||
defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass},
|
||||
RootDatabase,
|
||||
@ -756,8 +756,13 @@ fn is_method_call_unsafe(
|
||||
}
|
||||
|
||||
let func = sema.resolve_method_call(&method_call_expr)?;
|
||||
if func.self_param(sema.db)?.is_ref {
|
||||
Some(())
|
||||
if func.has_self_param(sema.db) {
|
||||
let params = func.params(sema.db);
|
||||
if matches!(params.into_iter().next(), Some(TypeRef::Reference(..))) {
|
||||
Some(())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user