mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
args -> params
This commit is contained in:
parent
5db5f5cc1d
commit
1ed7fbfc1b
@ -273,11 +273,11 @@ pub use crate::code_model_impl::function::ScopeEntryWithSyntax;
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FnSignature {
|
||||
pub(crate) name: Name,
|
||||
pub(crate) args: Vec<TypeRef>,
|
||||
pub(crate) params: Vec<TypeRef>,
|
||||
pub(crate) ret_type: TypeRef,
|
||||
/// True if the first arg is `self`. This is relevant to decide whether this
|
||||
/// True if the first param is `self`. This is relevant to decide whether this
|
||||
/// can be called as a method.
|
||||
pub(crate) has_self_arg: bool,
|
||||
pub(crate) has_self_param: bool,
|
||||
}
|
||||
|
||||
impl FnSignature {
|
||||
@ -285,8 +285,8 @@ impl FnSignature {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn args(&self) -> &[TypeRef] {
|
||||
&self.args
|
||||
pub fn params(&self) -> &[TypeRef] {
|
||||
&self.params
|
||||
}
|
||||
|
||||
pub fn ret_type(&self) -> &TypeRef {
|
||||
@ -295,8 +295,8 @@ impl FnSignature {
|
||||
|
||||
/// True if the first arg is `self`. This is relevant to decide whether this
|
||||
/// can be called as a method.
|
||||
pub fn has_self_arg(&self) -> bool {
|
||||
self.has_self_arg
|
||||
pub fn has_self_param(&self) -> bool {
|
||||
self.has_self_param
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ impl FnSignature {
|
||||
.name()
|
||||
.map(|n| n.as_name())
|
||||
.unwrap_or_else(Name::missing);
|
||||
let mut args = Vec::new();
|
||||
let mut has_self_arg = false;
|
||||
let mut params = Vec::new();
|
||||
let mut has_self_param = false;
|
||||
if let Some(param_list) = node.param_list() {
|
||||
if let Some(self_param) = param_list.self_param() {
|
||||
let self_type = if let Some(type_ref) = self_param.type_ref() {
|
||||
@ -60,12 +60,12 @@ impl FnSignature {
|
||||
}
|
||||
}
|
||||
};
|
||||
args.push(self_type);
|
||||
has_self_arg = true;
|
||||
params.push(self_type);
|
||||
has_self_param = true;
|
||||
}
|
||||
for param in param_list.params() {
|
||||
let type_ref = TypeRef::from_ast_opt(param.type_ref());
|
||||
args.push(type_ref);
|
||||
params.push(type_ref);
|
||||
}
|
||||
}
|
||||
let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) {
|
||||
@ -75,9 +75,9 @@ impl FnSignature {
|
||||
};
|
||||
let sig = FnSignature {
|
||||
name,
|
||||
args,
|
||||
params,
|
||||
ret_type,
|
||||
has_self_arg,
|
||||
has_self_param,
|
||||
};
|
||||
Arc::new(sig)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ impl FnScopes {
|
||||
scope_for: FxHashMap::default(),
|
||||
};
|
||||
let root = scopes.root_scope();
|
||||
scopes.add_params_bindings(root, body.args());
|
||||
scopes.add_params_bindings(root, body.params());
|
||||
compute_expr_scopes(body.body_expr(), &body, &mut scopes, root);
|
||||
scopes
|
||||
}
|
||||
|
@ -18,13 +18,13 @@ impl_arena_id!(ExprId);
|
||||
pub struct Body {
|
||||
exprs: Arena<ExprId, Expr>,
|
||||
pats: Arena<PatId, Pat>,
|
||||
/// The patterns for the function's arguments. While the argument types are
|
||||
/// The patterns for the function's parameters. While the parameter types are
|
||||
/// part of the function signature, the patterns are not (they don't change
|
||||
/// the external type of the function).
|
||||
///
|
||||
/// If this `Body` is for the body of a constant, this will just be
|
||||
/// empty.
|
||||
args: Vec<PatId>,
|
||||
params: Vec<PatId>,
|
||||
/// The `ExprId` of the actual body expression.
|
||||
body_expr: ExprId,
|
||||
}
|
||||
@ -44,8 +44,8 @@ pub struct BodySyntaxMapping {
|
||||
}
|
||||
|
||||
impl Body {
|
||||
pub fn args(&self) -> &[PatId] {
|
||||
&self.args
|
||||
pub fn params(&self) -> &[PatId] {
|
||||
&self.params
|
||||
}
|
||||
|
||||
pub fn body_expr(&self) -> ExprId {
|
||||
@ -699,11 +699,11 @@ impl ExprCollector {
|
||||
}
|
||||
}
|
||||
|
||||
fn into_body_syntax_mapping(self, args: Vec<PatId>, body_expr: ExprId) -> BodySyntaxMapping {
|
||||
fn into_body_syntax_mapping(self, params: Vec<PatId>, body_expr: ExprId) -> BodySyntaxMapping {
|
||||
let body = Body {
|
||||
exprs: self.exprs,
|
||||
pats: self.pats,
|
||||
args,
|
||||
params,
|
||||
body_expr,
|
||||
};
|
||||
BodySyntaxMapping {
|
||||
@ -719,8 +719,8 @@ impl ExprCollector {
|
||||
pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping {
|
||||
let mut collector = ExprCollector::new();
|
||||
|
||||
let args = if let Some(param_list) = node.param_list() {
|
||||
let mut args = Vec::new();
|
||||
let params = if let Some(param_list) = node.param_list() {
|
||||
let mut params = Vec::new();
|
||||
|
||||
if let Some(self_param) = param_list.self_param() {
|
||||
let self_param = LocalSyntaxPtr::new(
|
||||
@ -729,13 +729,13 @@ pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping {
|
||||
.expect("self param without self keyword")
|
||||
.syntax(),
|
||||
);
|
||||
let arg = collector.alloc_pat(
|
||||
let param = collector.alloc_pat(
|
||||
Pat::Bind {
|
||||
name: Name::self_param(),
|
||||
},
|
||||
self_param,
|
||||
);
|
||||
args.push(arg);
|
||||
params.push(param);
|
||||
}
|
||||
|
||||
for param in param_list.params() {
|
||||
@ -744,15 +744,15 @@ pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping {
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
args.push(collector.collect_pat(pat));
|
||||
params.push(collector.collect_pat(pat));
|
||||
}
|
||||
args
|
||||
params
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let body = collector.collect_block_opt(node.body());
|
||||
collector.into_body_syntax_mapping(args, body)
|
||||
collector.into_body_syntax_mapping(params, body)
|
||||
}
|
||||
|
||||
pub(crate) fn body_syntax_mapping(
|
||||
|
@ -432,7 +432,7 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
|
||||
let impl_block = f.impl_block(db)?;
|
||||
// TODO we ignore type parameters for now
|
||||
let input = signature
|
||||
.args()
|
||||
.params()
|
||||
.iter()
|
||||
.map(|tr| Ty::from_hir(db, &module, impl_block.as_ref(), tr))
|
||||
.collect::<Cancelable<Vec<_>>>()?;
|
||||
@ -876,7 +876,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
}
|
||||
Expr::Call { callee, args } => {
|
||||
let callee_ty = self.infer_expr(*callee, &Expectation::none())?;
|
||||
let (arg_tys, ret_ty) = match &callee_ty {
|
||||
let (param_tys, ret_ty) = match &callee_ty {
|
||||
Ty::FnPtr(sig) => (&sig.input[..], sig.output.clone()),
|
||||
_ => {
|
||||
// not callable
|
||||
@ -887,7 +887,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
self.infer_expr(
|
||||
*arg,
|
||||
&Expectation::has_type(arg_tys.get(i).cloned().unwrap_or(Ty::Unknown)),
|
||||
&Expectation::has_type(param_tys.get(i).cloned().unwrap_or(Ty::Unknown)),
|
||||
)?;
|
||||
}
|
||||
ret_ty
|
||||
@ -904,7 +904,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
None => Ty::Unknown,
|
||||
};
|
||||
let method_ty = self.insert_type_vars(method_ty);
|
||||
let (expected_receiver_ty, arg_tys, ret_ty) = match &method_ty {
|
||||
let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty {
|
||||
Ty::FnPtr(sig) => {
|
||||
if sig.input.len() > 0 {
|
||||
(&sig.input[0], &sig.input[1..], sig.output.clone())
|
||||
@ -920,7 +920,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
self.infer_expr(
|
||||
*arg,
|
||||
&Expectation::has_type(arg_tys.get(i).cloned().unwrap_or(Ty::Unknown)),
|
||||
&Expectation::has_type(param_tys.get(i).cloned().unwrap_or(Ty::Unknown)),
|
||||
)?;
|
||||
}
|
||||
ret_ty
|
||||
@ -1093,7 +1093,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
|
||||
fn collect_fn_signature(&mut self, signature: &FnSignature) -> Cancelable<()> {
|
||||
let body = Arc::clone(&self.body); // avoid borrow checker problem
|
||||
for (type_ref, pat) in signature.args().iter().zip(body.args()) {
|
||||
for (type_ref, pat) in signature.params().iter().zip(body.params()) {
|
||||
let ty = self.make_ty(type_ref)?;
|
||||
let ty = self.insert_type_vars(ty);
|
||||
self.write_pat_ty(*pat, ty);
|
||||
|
@ -114,7 +114,7 @@ impl Ty {
|
||||
pub fn lookup_method(self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<DefId>> {
|
||||
self.iterate_methods(db, |f| {
|
||||
let sig = f.signature(db);
|
||||
if sig.name() == name && sig.has_self_arg() {
|
||||
if sig.name() == name && sig.has_self_param() {
|
||||
Ok(Some(f.def_id()))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
@ -63,7 +63,7 @@ fn complete_methods(
|
||||
) -> Cancelable<()> {
|
||||
receiver.iterate_methods(ctx.db, |func| {
|
||||
let sig = func.signature(ctx.db);
|
||||
if sig.has_self_arg() {
|
||||
if sig.has_self_param() {
|
||||
CompletionItem::new(CompletionKind::Reference, sig.name().to_string())
|
||||
.from_function(ctx, func)
|
||||
.kind(CompletionItemKind::Method)
|
||||
|
@ -191,7 +191,7 @@ impl Builder {
|
||||
) -> Builder {
|
||||
// If not an import, add parenthesis automatically.
|
||||
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
||||
if function.signature(ctx.db).args().is_empty() {
|
||||
if function.signature(ctx.db).params().is_empty() {
|
||||
self.snippet = Some(format!("{}()$0", self.label));
|
||||
} else {
|
||||
self.snippet = Some(format!("{}($0)", self.label));
|
||||
|
Loading…
Reference in New Issue
Block a user