mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Auto merge of #14036 - Veykril:write-method-resolution, r=Veykril
Record method resolution for remaining operator expressions This allows goto def and future substituted hover to work for the concrete impls.
This commit is contained in:
commit
bfe82cda48
13 changed files with 163 additions and 103 deletions
|
@ -347,6 +347,7 @@ pub mod known {
|
||||||
recursion_limit,
|
recursion_limit,
|
||||||
feature,
|
feature,
|
||||||
// known methods of lang items
|
// known methods of lang items
|
||||||
|
call_once,
|
||||||
eq,
|
eq,
|
||||||
ne,
|
ne,
|
||||||
ge,
|
ge,
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl<D> TyBuilder<D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_internal(self) -> (D, Substitution) {
|
fn build_internal(self) -> (D, Substitution) {
|
||||||
assert_eq!(self.vec.len(), self.param_kinds.len());
|
assert_eq!(self.vec.len(), self.param_kinds.len(), "{:?}", &self.param_kinds);
|
||||||
for (a, e) in self.vec.iter().zip(self.param_kinds.iter()) {
|
for (a, e) in self.vec.iter().zip(self.param_kinds.iter()) {
|
||||||
self.assert_match_kind(a, e);
|
self.assert_match_kind(a, e);
|
||||||
}
|
}
|
||||||
|
@ -282,6 +282,21 @@ impl TyBuilder<Tuple> {
|
||||||
let (Tuple(size), subst) = self.build_internal();
|
let (Tuple(size), subst) = self.build_internal();
|
||||||
TyKind::Tuple(size, subst).intern(Interner)
|
TyKind::Tuple(size, subst).intern(Interner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tuple_with<I>(elements: I) -> Ty
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = Ty>,
|
||||||
|
<I as IntoIterator>::IntoIter: ExactSizeIterator,
|
||||||
|
{
|
||||||
|
let elements = elements.into_iter();
|
||||||
|
let len = elements.len();
|
||||||
|
let mut b =
|
||||||
|
TyBuilder::new(Tuple(len), iter::repeat(ParamKind::Type).take(len).collect(), None);
|
||||||
|
for e in elements {
|
||||||
|
b = b.push(e);
|
||||||
|
}
|
||||||
|
b.build()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TyBuilder<TraitId> {
|
impl TyBuilder<TraitId> {
|
||||||
|
|
|
@ -938,19 +938,24 @@ impl<'a> InferenceContext<'a> {
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Item])
|
self.db.trait_data(trait_).associated_type_by_name(&name![Item])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> {
|
fn resolve_output_on(&self, trait_: TraitId) -> Option<TypeAliasId> {
|
||||||
let trait_ = self.resolve_lang_item(LangItem::Try)?.as_trait()?;
|
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Output])
|
self.db.trait_data(trait_).associated_type_by_name(&name![Output])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_lang_trait(&self, lang: LangItem) -> Option<TraitId> {
|
||||||
|
self.resolve_lang_item(lang)?.as_trait()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_ops_try_output(&self) -> Option<TypeAliasId> {
|
||||||
|
self.resolve_output_on(self.resolve_lang_trait(LangItem::Try)?)
|
||||||
|
}
|
||||||
|
|
||||||
fn resolve_ops_neg_output(&self) -> Option<TypeAliasId> {
|
fn resolve_ops_neg_output(&self) -> Option<TypeAliasId> {
|
||||||
let trait_ = self.resolve_lang_item(LangItem::Neg)?.as_trait()?;
|
self.resolve_output_on(self.resolve_lang_trait(LangItem::Neg)?)
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Output])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_ops_not_output(&self) -> Option<TypeAliasId> {
|
fn resolve_ops_not_output(&self) -> Option<TypeAliasId> {
|
||||||
let trait_ = self.resolve_lang_item(LangItem::Not)?.as_trait()?;
|
self.resolve_output_on(self.resolve_lang_trait(LangItem::Not)?)
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Output])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_future_future_output(&self) -> Option<TypeAliasId> {
|
fn resolve_future_future_output(&self) -> Option<TypeAliasId> {
|
||||||
|
@ -960,7 +965,7 @@ impl<'a> InferenceContext<'a> {
|
||||||
.lookup(self.db.upcast())
|
.lookup(self.db.upcast())
|
||||||
.container
|
.container
|
||||||
else { return None };
|
else { return None };
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Output])
|
self.resolve_output_on(trait_)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_boxed_box(&self) -> Option<AdtId> {
|
fn resolve_boxed_box(&self) -> Option<AdtId> {
|
||||||
|
@ -998,13 +1003,8 @@ impl<'a> InferenceContext<'a> {
|
||||||
Some(struct_.into())
|
Some(struct_.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_ops_index(&self) -> Option<TraitId> {
|
|
||||||
self.resolve_lang_item(LangItem::Index)?.as_trait()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn resolve_ops_index_output(&self) -> Option<TypeAliasId> {
|
fn resolve_ops_index_output(&self) -> Option<TypeAliasId> {
|
||||||
let trait_ = self.resolve_ops_index()?;
|
self.resolve_output_on(self.resolve_lang_trait(LangItem::Index)?)
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Output])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_va_list(&self) -> Option<AdtId> {
|
fn resolve_va_list(&self) -> Option<AdtId> {
|
||||||
|
|
|
@ -13,11 +13,12 @@ use hir_def::{
|
||||||
ArithOp, Array, BinaryOp, ClosureKind, Expr, ExprId, LabelId, Literal, Statement, UnaryOp,
|
ArithOp, Array, BinaryOp, ClosureKind, Expr, ExprId, LabelId, Literal, Statement, UnaryOp,
|
||||||
},
|
},
|
||||||
generics::TypeOrConstParamData,
|
generics::TypeOrConstParamData,
|
||||||
|
lang_item::LangItem,
|
||||||
path::{GenericArg, GenericArgs},
|
path::{GenericArg, GenericArgs},
|
||||||
resolver::resolver_for_expr,
|
resolver::resolver_for_expr,
|
||||||
ConstParamId, FieldId, ItemContainerId, Lookup,
|
ConstParamId, FieldId, ItemContainerId, Lookup,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::{name, Name};
|
||||||
use stdx::always;
|
use stdx::always;
|
||||||
use syntax::ast::RangeOp;
|
use syntax::ast::RangeOp;
|
||||||
|
|
||||||
|
@ -157,7 +158,8 @@ impl<'a> InferenceContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ok-ish type that is expected from the last expression
|
// The ok-ish type that is expected from the last expression
|
||||||
let ok_ty = self.resolve_associated_type(try_ty.clone(), self.resolve_ops_try_ok());
|
let ok_ty =
|
||||||
|
self.resolve_associated_type(try_ty.clone(), self.resolve_ops_try_output());
|
||||||
|
|
||||||
self.with_breakable_ctx(BreakableKind::Block, ok_ty.clone(), None, |this| {
|
self.with_breakable_ctx(BreakableKind::Block, ok_ty.clone(), None, |this| {
|
||||||
this.infer_expr(*body, &Expectation::has_type(ok_ty));
|
this.infer_expr(*body, &Expectation::has_type(ok_ty));
|
||||||
|
@ -331,11 +333,18 @@ impl<'a> InferenceContext<'a> {
|
||||||
derefed_callee.callable_sig(self.db).map_or(false, |sig| sig.is_varargs)
|
derefed_callee.callable_sig(self.db).map_or(false, |sig| sig.is_varargs)
|
||||||
|| res.is_none();
|
|| res.is_none();
|
||||||
let (param_tys, ret_ty) = match res {
|
let (param_tys, ret_ty) = match res {
|
||||||
Some(res) => {
|
Some((func, params, ret_ty)) => {
|
||||||
let adjustments = auto_deref_adjust_steps(&derefs);
|
let adjustments = auto_deref_adjust_steps(&derefs);
|
||||||
// FIXME: Handle call adjustments for Fn/FnMut
|
// FIXME: Handle call adjustments for Fn/FnMut
|
||||||
self.write_expr_adj(*callee, adjustments);
|
self.write_expr_adj(*callee, adjustments);
|
||||||
res
|
if let Some((trait_, func)) = func {
|
||||||
|
let subst = TyBuilder::subst_for_def(self.db, trait_, None)
|
||||||
|
.push(callee_ty.clone())
|
||||||
|
.push(TyBuilder::tuple_with(params.iter().cloned()))
|
||||||
|
.build();
|
||||||
|
self.write_method_resolution(tgt_expr, func, subst.clone());
|
||||||
|
}
|
||||||
|
(params, ret_ty)
|
||||||
}
|
}
|
||||||
None => (Vec::new(), self.err_ty()), // FIXME diagnostic
|
None => (Vec::new(), self.err_ty()), // FIXME diagnostic
|
||||||
};
|
};
|
||||||
|
@ -587,7 +596,18 @@ impl<'a> InferenceContext<'a> {
|
||||||
}
|
}
|
||||||
Expr::Try { expr } => {
|
Expr::Try { expr } => {
|
||||||
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
|
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
|
||||||
self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok())
|
if let Some(trait_) = self.resolve_lang_trait(LangItem::Try) {
|
||||||
|
if let Some(func) = self.db.trait_data(trait_).method_by_name(&name!(branch)) {
|
||||||
|
let subst = TyBuilder::subst_for_def(self.db, trait_, None)
|
||||||
|
.push(inner_ty.clone())
|
||||||
|
.build();
|
||||||
|
self.write_method_resolution(tgt_expr, func, subst.clone());
|
||||||
|
}
|
||||||
|
let try_output = self.resolve_output_on(trait_);
|
||||||
|
self.resolve_associated_type(inner_ty, try_output)
|
||||||
|
} else {
|
||||||
|
self.err_ty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Expr::Cast { expr, type_ref } => {
|
Expr::Cast { expr, type_ref } => {
|
||||||
// FIXME: propagate the "castable to" expectation (and find a test case that shows this is necessary)
|
// FIXME: propagate the "castable to" expectation (and find a test case that shows this is necessary)
|
||||||
|
@ -626,6 +646,7 @@ impl<'a> InferenceContext<'a> {
|
||||||
Expr::UnaryOp { expr, op } => {
|
Expr::UnaryOp { expr, op } => {
|
||||||
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
|
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
|
||||||
let inner_ty = self.resolve_ty_shallow(&inner_ty);
|
let inner_ty = self.resolve_ty_shallow(&inner_ty);
|
||||||
|
// FIXME: Note down method resolution her
|
||||||
match op {
|
match op {
|
||||||
UnaryOp::Deref => {
|
UnaryOp::Deref => {
|
||||||
autoderef::deref(&mut self.table, inner_ty).unwrap_or_else(|| self.err_ty())
|
autoderef::deref(&mut self.table, inner_ty).unwrap_or_else(|| self.err_ty())
|
||||||
|
@ -735,7 +756,7 @@ impl<'a> InferenceContext<'a> {
|
||||||
let base_ty = self.infer_expr_inner(*base, &Expectation::none());
|
let base_ty = self.infer_expr_inner(*base, &Expectation::none());
|
||||||
let index_ty = self.infer_expr(*index, &Expectation::none());
|
let index_ty = self.infer_expr(*index, &Expectation::none());
|
||||||
|
|
||||||
if let Some(index_trait) = self.resolve_ops_index() {
|
if let Some(index_trait) = self.resolve_lang_trait(LangItem::Index) {
|
||||||
let canonicalized = self.canonicalize(base_ty.clone());
|
let canonicalized = self.canonicalize(base_ty.clone());
|
||||||
let receiver_adjustments = method_resolution::resolve_indexing_op(
|
let receiver_adjustments = method_resolution::resolve_indexing_op(
|
||||||
self.db,
|
self.db,
|
||||||
|
@ -748,6 +769,15 @@ impl<'a> InferenceContext<'a> {
|
||||||
adj.apply(&mut self.table, base_ty)
|
adj.apply(&mut self.table, base_ty)
|
||||||
});
|
});
|
||||||
self.write_expr_adj(*base, adj);
|
self.write_expr_adj(*base, adj);
|
||||||
|
if let Some(func) =
|
||||||
|
self.db.trait_data(index_trait).method_by_name(&name!(index))
|
||||||
|
{
|
||||||
|
let substs = TyBuilder::subst_for_def(self.db, index_trait, None)
|
||||||
|
.push(self_ty.clone())
|
||||||
|
.push(index_ty.clone())
|
||||||
|
.build();
|
||||||
|
self.write_method_resolution(tgt_expr, func, substs.clone());
|
||||||
|
}
|
||||||
self.resolve_associated_type_with_params(
|
self.resolve_associated_type_with_params(
|
||||||
self_ty,
|
self_ty,
|
||||||
self.resolve_ops_index_output(),
|
self.resolve_ops_index_output(),
|
||||||
|
|
|
@ -8,6 +8,7 @@ use chalk_ir::{
|
||||||
};
|
};
|
||||||
use chalk_solve::infer::ParameterEnaVariableExt;
|
use chalk_solve::infer::ParameterEnaVariableExt;
|
||||||
use ena::unify::UnifyKey;
|
use ena::unify::UnifyKey;
|
||||||
|
use hir_def::{FunctionId, TraitId};
|
||||||
use hir_expand::name;
|
use hir_expand::name;
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
|
|
||||||
|
@ -626,18 +627,26 @@ impl<'a> InferenceTable<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn callable_sig(&mut self, ty: &Ty, num_args: usize) -> Option<(Vec<Ty>, Ty)> {
|
pub(crate) fn callable_sig(
|
||||||
|
&mut self,
|
||||||
|
ty: &Ty,
|
||||||
|
num_args: usize,
|
||||||
|
) -> Option<(Option<(TraitId, FunctionId)>, Vec<Ty>, Ty)> {
|
||||||
match ty.callable_sig(self.db) {
|
match ty.callable_sig(self.db) {
|
||||||
Some(sig) => Some((sig.params().to_vec(), sig.ret().clone())),
|
Some(sig) => Some((None, sig.params().to_vec(), sig.ret().clone())),
|
||||||
None => self.callable_sig_from_fn_trait(ty, num_args),
|
None => self.callable_sig_from_fn_trait(ty, num_args),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn callable_sig_from_fn_trait(&mut self, ty: &Ty, num_args: usize) -> Option<(Vec<Ty>, Ty)> {
|
fn callable_sig_from_fn_trait(
|
||||||
|
&mut self,
|
||||||
|
ty: &Ty,
|
||||||
|
num_args: usize,
|
||||||
|
) -> Option<(Option<(TraitId, FunctionId)>, Vec<Ty>, Ty)> {
|
||||||
let krate = self.trait_env.krate;
|
let krate = self.trait_env.krate;
|
||||||
let fn_once_trait = FnTrait::FnOnce.get_id(self.db, krate)?;
|
let fn_once_trait = FnTrait::FnOnce.get_id(self.db, krate)?;
|
||||||
let output_assoc_type =
|
let trait_data = self.db.trait_data(fn_once_trait);
|
||||||
self.db.trait_data(fn_once_trait).associated_type_by_name(&name![Output])?;
|
let output_assoc_type = trait_data.associated_type_by_name(&name![Output])?;
|
||||||
|
|
||||||
let mut arg_tys = vec![];
|
let mut arg_tys = vec![];
|
||||||
let arg_ty = TyBuilder::tuple(num_args)
|
let arg_ty = TyBuilder::tuple(num_args)
|
||||||
|
@ -675,7 +684,11 @@ impl<'a> InferenceTable<'a> {
|
||||||
if self.db.trait_solve(krate, canonical.value.cast(Interner)).is_some() {
|
if self.db.trait_solve(krate, canonical.value.cast(Interner)).is_some() {
|
||||||
self.register_obligation(obligation.goal);
|
self.register_obligation(obligation.goal);
|
||||||
let return_ty = self.normalize_projection_ty(projection);
|
let return_ty = self.normalize_projection_ty(projection);
|
||||||
Some((arg_tys, return_ty))
|
Some((
|
||||||
|
Some(fn_once_trait).zip(trait_data.method_by_name(&name!(call_once))),
|
||||||
|
arg_tys,
|
||||||
|
return_ty,
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -986,14 +986,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn method_resolution_encountering_fn_type() {
|
fn explicit_fn_once_call_fn_item() {
|
||||||
check_types(
|
check_types(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- minicore: fn
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
trait FnOnce { fn call(self); }
|
fn test() { foo.call_once(); }
|
||||||
fn test() { foo.call(); }
|
//^^^^^^^^^^^^^^^ ()
|
||||||
//^^^^^^^^^^ {unknown}
|
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1757,25 +1757,19 @@ fn test() {
|
||||||
fn fn_trait() {
|
fn fn_trait() {
|
||||||
check_infer_with_mismatches(
|
check_infer_with_mismatches(
|
||||||
r#"
|
r#"
|
||||||
trait FnOnce<Args> {
|
//- minicore: fn
|
||||||
type Output;
|
|
||||||
|
|
||||||
fn call_once(self, args: Args) -> <Self as FnOnce<Args>>::Output;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
|
fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
|
||||||
f.call_once((1, 2));
|
f.call_once((1, 2));
|
||||||
}"#,
|
}"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
56..60 'self': Self
|
38..39 'f': F
|
||||||
62..66 'args': Args
|
44..72 '{ ...2)); }': ()
|
||||||
149..150 'f': F
|
50..51 'f': F
|
||||||
155..183 '{ ...2)); }': ()
|
50..69 'f.call...1, 2))': u128
|
||||||
161..162 'f': F
|
62..68 '(1, 2)': (u32, u64)
|
||||||
161..180 'f.call...1, 2))': u128
|
63..64 '1': u32
|
||||||
173..179 '(1, 2)': (u32, u64)
|
66..67 '2': u64
|
||||||
174..175 '1': u32
|
|
||||||
177..178 '2': u64
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1784,12 +1778,7 @@ fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
|
||||||
fn fn_ptr_and_item() {
|
fn fn_ptr_and_item() {
|
||||||
check_infer_with_mismatches(
|
check_infer_with_mismatches(
|
||||||
r#"
|
r#"
|
||||||
#[lang="fn_once"]
|
//- minicore: fn
|
||||||
trait FnOnce<Args> {
|
|
||||||
type Output;
|
|
||||||
|
|
||||||
fn call_once(self, args: Args) -> Self::Output;
|
|
||||||
}
|
|
||||||
|
|
||||||
trait Foo<T> {
|
trait Foo<T> {
|
||||||
fn foo(&self) -> T;
|
fn foo(&self) -> T;
|
||||||
|
@ -1815,27 +1804,25 @@ fn test() {
|
||||||
opt.map(f);
|
opt.map(f);
|
||||||
}"#,
|
}"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
74..78 'self': Self
|
28..32 'self': &Self
|
||||||
80..84 'args': Args
|
132..136 'self': &Bar<F>
|
||||||
139..143 'self': &Self
|
149..160 '{ loop {} }': (A1, R)
|
||||||
243..247 'self': &Bar<F>
|
151..158 'loop {}': !
|
||||||
260..271 '{ loop {} }': (A1, R)
|
156..158 '{}': ()
|
||||||
262..269 'loop {}': !
|
244..248 'self': Opt<T>
|
||||||
267..269 '{}': ()
|
250..251 'f': F
|
||||||
355..359 'self': Opt<T>
|
266..277 '{ loop {} }': Opt<U>
|
||||||
361..362 'f': F
|
268..275 'loop {}': !
|
||||||
377..388 '{ loop {} }': Opt<U>
|
273..275 '{}': ()
|
||||||
379..386 'loop {}': !
|
291..407 '{ ...(f); }': ()
|
||||||
384..386 '{}': ()
|
301..304 'bar': Bar<fn(u8) -> u32>
|
||||||
402..518 '{ ...(f); }': ()
|
330..333 'bar': Bar<fn(u8) -> u32>
|
||||||
412..415 'bar': Bar<fn(u8) -> u32>
|
330..339 'bar.foo()': (u8, u32)
|
||||||
441..444 'bar': Bar<fn(u8) -> u32>
|
350..353 'opt': Opt<u8>
|
||||||
441..450 'bar.foo()': (u8, u32)
|
372..373 'f': fn(u8) -> u32
|
||||||
461..464 'opt': Opt<u8>
|
394..397 'opt': Opt<u8>
|
||||||
483..484 'f': fn(u8) -> u32
|
394..404 'opt.map(f)': Opt<u32>
|
||||||
505..508 'opt': Opt<u8>
|
402..403 'f': fn(u8) -> u32
|
||||||
505..515 'opt.map(f)': Opt<u32>
|
|
||||||
513..514 'f': fn(u8) -> u32
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2308,10 +2295,8 @@ fn unselected_projection_in_trait_env_no_cycle() {
|
||||||
// this is not a cycle
|
// this is not a cycle
|
||||||
check_types(
|
check_types(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- minicore: index
|
||||||
trait Index {
|
use core::ops::Index;
|
||||||
type Output;
|
|
||||||
}
|
|
||||||
|
|
||||||
type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
|
type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key;
|
||||||
|
|
||||||
|
|
|
@ -2411,7 +2411,7 @@ impl Local {
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct DeriveHelper {
|
pub struct DeriveHelper {
|
||||||
pub(crate) derive: MacroId,
|
pub(crate) derive: MacroId,
|
||||||
pub(crate) idx: usize,
|
pub(crate) idx: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeriveHelper {
|
impl DeriveHelper {
|
||||||
|
@ -2421,15 +2421,18 @@ impl DeriveHelper {
|
||||||
|
|
||||||
pub fn name(&self, db: &dyn HirDatabase) -> Name {
|
pub fn name(&self, db: &dyn HirDatabase) -> Name {
|
||||||
match self.derive {
|
match self.derive {
|
||||||
MacroId::Macro2Id(it) => {
|
MacroId::Macro2Id(it) => db
|
||||||
db.macro2_data(it).helpers.as_deref().and_then(|it| it.get(self.idx)).cloned()
|
.macro2_data(it)
|
||||||
}
|
.helpers
|
||||||
|
.as_deref()
|
||||||
|
.and_then(|it| it.get(self.idx as usize))
|
||||||
|
.cloned(),
|
||||||
MacroId::MacroRulesId(_) => None,
|
MacroId::MacroRulesId(_) => None,
|
||||||
MacroId::ProcMacroId(proc_macro) => db
|
MacroId::ProcMacroId(proc_macro) => db
|
||||||
.proc_macro_data(proc_macro)
|
.proc_macro_data(proc_macro)
|
||||||
.helpers
|
.helpers
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.and_then(|it| it.get(self.idx))
|
.and_then(|it| it.get(self.idx as usize))
|
||||||
.cloned(),
|
.cloned(),
|
||||||
}
|
}
|
||||||
.unwrap_or_else(|| Name::missing())
|
.unwrap_or_else(|| Name::missing())
|
||||||
|
@ -2440,7 +2443,7 @@ impl DeriveHelper {
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct BuiltinAttr {
|
pub struct BuiltinAttr {
|
||||||
krate: Option<CrateId>,
|
krate: Option<CrateId>,
|
||||||
idx: usize,
|
idx: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuiltinAttr {
|
impl BuiltinAttr {
|
||||||
|
@ -2449,7 +2452,8 @@ impl BuiltinAttr {
|
||||||
if let builtin @ Some(_) = Self::builtin(name) {
|
if let builtin @ Some(_) = Self::builtin(name) {
|
||||||
return builtin;
|
return builtin;
|
||||||
}
|
}
|
||||||
let idx = db.crate_def_map(krate.id).registered_attrs().iter().position(|it| it == name)?;
|
let idx =
|
||||||
|
db.crate_def_map(krate.id).registered_attrs().iter().position(|it| it == name)? as u32;
|
||||||
Some(BuiltinAttr { krate: Some(krate.id), idx })
|
Some(BuiltinAttr { krate: Some(krate.id), idx })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2457,21 +2461,21 @@ impl BuiltinAttr {
|
||||||
hir_def::builtin_attr::INERT_ATTRIBUTES
|
hir_def::builtin_attr::INERT_ATTRIBUTES
|
||||||
.iter()
|
.iter()
|
||||||
.position(|tool| tool.name == name)
|
.position(|tool| tool.name == name)
|
||||||
.map(|idx| BuiltinAttr { krate: None, idx })
|
.map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self, db: &dyn HirDatabase) -> SmolStr {
|
pub fn name(&self, db: &dyn HirDatabase) -> SmolStr {
|
||||||
// FIXME: Return a `Name` here
|
// FIXME: Return a `Name` here
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(krate) => db.crate_def_map(krate).registered_attrs()[self.idx].clone(),
|
Some(krate) => db.crate_def_map(krate).registered_attrs()[self.idx as usize].clone(),
|
||||||
None => SmolStr::new(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx].name),
|
None => SmolStr::new(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx as usize].name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
|
pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
None => Some(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx].template),
|
None => Some(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx as usize].template),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2479,7 +2483,7 @@ impl BuiltinAttr {
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct ToolModule {
|
pub struct ToolModule {
|
||||||
krate: Option<CrateId>,
|
krate: Option<CrateId>,
|
||||||
idx: usize,
|
idx: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolModule {
|
impl ToolModule {
|
||||||
|
@ -2488,7 +2492,8 @@ impl ToolModule {
|
||||||
if let builtin @ Some(_) = Self::builtin(name) {
|
if let builtin @ Some(_) = Self::builtin(name) {
|
||||||
return builtin;
|
return builtin;
|
||||||
}
|
}
|
||||||
let idx = db.crate_def_map(krate.id).registered_tools().iter().position(|it| it == name)?;
|
let idx =
|
||||||
|
db.crate_def_map(krate.id).registered_tools().iter().position(|it| it == name)? as u32;
|
||||||
Some(ToolModule { krate: Some(krate.id), idx })
|
Some(ToolModule { krate: Some(krate.id), idx })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2496,14 +2501,14 @@ impl ToolModule {
|
||||||
hir_def::builtin_attr::TOOL_MODULES
|
hir_def::builtin_attr::TOOL_MODULES
|
||||||
.iter()
|
.iter()
|
||||||
.position(|&tool| tool == name)
|
.position(|&tool| tool == name)
|
||||||
.map(|idx| ToolModule { krate: None, idx })
|
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self, db: &dyn HirDatabase) -> SmolStr {
|
pub fn name(&self, db: &dyn HirDatabase) -> SmolStr {
|
||||||
// FIXME: Return a `Name` here
|
// FIXME: Return a `Name` here
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(krate) => db.crate_def_map(krate).registered_tools()[self.idx].clone(),
|
Some(krate) => db.crate_def_map(krate).registered_tools()[self.idx as usize].clone(),
|
||||||
None => SmolStr::new(hir_def::builtin_attr::TOOL_MODULES[self.idx]),
|
None => SmolStr::new(hir_def::builtin_attr::TOOL_MODULES[self.idx as usize]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2831,7 +2836,7 @@ impl Impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub struct TraitRef {
|
pub struct TraitRef {
|
||||||
env: Arc<TraitEnvironment>,
|
env: Arc<TraitEnvironment>,
|
||||||
trait_ref: hir_ty::TraitRef,
|
trait_ref: hir_ty::TraitRef,
|
||||||
|
|
|
@ -628,7 +628,7 @@ impl SourceAnalyzer {
|
||||||
{
|
{
|
||||||
return Some(PathResolution::DeriveHelper(DeriveHelper {
|
return Some(PathResolution::DeriveHelper(DeriveHelper {
|
||||||
derive: *macro_id,
|
derive: *macro_id,
|
||||||
idx,
|
idx: idx as u32,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ pub enum Definition {
|
||||||
TypeAlias(TypeAlias),
|
TypeAlias(TypeAlias),
|
||||||
BuiltinType(BuiltinType),
|
BuiltinType(BuiltinType),
|
||||||
SelfType(Impl),
|
SelfType(Impl),
|
||||||
Local(Local),
|
|
||||||
GenericParam(GenericParam),
|
GenericParam(GenericParam),
|
||||||
|
Local(Local),
|
||||||
Label(Label),
|
Label(Label),
|
||||||
DeriveHelper(DeriveHelper),
|
DeriveHelper(DeriveHelper),
|
||||||
BuiltinAttr(BuiltinAttr),
|
BuiltinAttr(BuiltinAttr),
|
||||||
|
|
|
@ -325,7 +325,7 @@ fn main(a: SliceIter<'_, Container>) {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 2248..2256,
|
range: 2611..2619,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
|
@ -338,7 +338,7 @@ fn main(a: SliceIter<'_, Container>) {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 2248..2256,
|
range: 2611..2619,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
|
|
|
@ -435,7 +435,7 @@ fn main() {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 2248..2256,
|
range: 2611..2619,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
|
@ -455,7 +455,7 @@ fn main() {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 2248..2256,
|
range: 2611..2619,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
|
@ -475,7 +475,7 @@ fn main() {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
range: 2248..2256,
|
range: 2611..2619,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
|
|
|
@ -106,6 +106,11 @@ pub mod marker {
|
||||||
impl<T: ?Sized> Copy for &T {}
|
impl<T: ?Sized> Copy for &T {}
|
||||||
}
|
}
|
||||||
// endregion:copy
|
// endregion:copy
|
||||||
|
|
||||||
|
// region:fn
|
||||||
|
#[lang = "tuple_trait"]
|
||||||
|
pub trait Tuple {}
|
||||||
|
// endregion:fn
|
||||||
}
|
}
|
||||||
|
|
||||||
// region:default
|
// region:default
|
||||||
|
@ -347,19 +352,26 @@ pub mod ops {
|
||||||
|
|
||||||
// region:fn
|
// region:fn
|
||||||
mod function {
|
mod function {
|
||||||
|
use crate::marker::Tuple;
|
||||||
|
|
||||||
#[lang = "fn"]
|
#[lang = "fn"]
|
||||||
#[fundamental]
|
#[fundamental]
|
||||||
pub trait Fn<Args>: FnMut<Args> {}
|
pub trait Fn<Args: Tuple>: FnMut<Args> {
|
||||||
|
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
|
||||||
|
}
|
||||||
|
|
||||||
#[lang = "fn_mut"]
|
#[lang = "fn_mut"]
|
||||||
#[fundamental]
|
#[fundamental]
|
||||||
pub trait FnMut<Args>: FnOnce<Args> {}
|
pub trait FnMut<Args: Tuple>: FnOnce<Args> {
|
||||||
|
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
|
||||||
|
}
|
||||||
|
|
||||||
#[lang = "fn_once"]
|
#[lang = "fn_once"]
|
||||||
#[fundamental]
|
#[fundamental]
|
||||||
pub trait FnOnce<Args> {
|
pub trait FnOnce<Args: Tuple> {
|
||||||
#[lang = "fn_once_output"]
|
#[lang = "fn_once_output"]
|
||||||
type Output;
|
type Output;
|
||||||
|
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub use self::function::{Fn, FnMut, FnOnce};
|
pub use self::function::{Fn, FnMut, FnOnce};
|
||||||
|
|
Loading…
Reference in a new issue