Show fn traits in signature info for trait implementors · rust-lang/rust@6438554 (original) (raw)
`@@ -140,7 +140,7 @@ pub use {
`
140
140
` display::{ClosureStyle, HirDisplay, HirDisplayError, HirWrite},
`
141
141
` layout::LayoutError,
`
142
142
` mir::{MirEvalError, MirLowerError},
`
143
``
`-
PointerCast, Safety,
`
``
143
`+
FnAbi, PointerCast, Safety,
`
144
144
`},
`
145
145
`// FIXME: Properly encapsulate mir
`
146
146
` hir_ty::{mir, Interner as ChalkTyInterner},
`
`@@ -2227,7 +2227,7 @@ impl Param {
`
2227
2227
`let InFile { file_id, value } = Function { id: func }.source(db)?;
`
2228
2228
`let params = value.param_list()?;
`
2229
2229
`if let Some(self_param) = params.self_param() {
`
2230
``
`-
if let Some(idx) = self.idx.checked_sub(1 as usize) {
`
``
2230
`+
if let Some(idx) = self.idx.checked_sub(1) {
`
2231
2231
` params.params().nth(idx).map(Either::Right)
`
2232
2232
`} else {
`
2233
2233
`Some(Either::Left(self_param))
`
`@@ -4321,23 +4321,26 @@ impl Type {
`
4321
4321
`TyKind::Function(_) => Callee::FnPtr,
`
4322
4322
`TyKind::FnDef(..) => Callee::Def(self.ty.callable_def(db)?),
`
4323
4323
` kind => {
`
4324
``
`-
// This branch shouldn't be necessary?
`
4325
``
`-
if let TyKind::Ref(_, _, ty) = kind {
`
4326
``
`-
if let TyKind::Closure(closure, subst) = ty.kind(Interner) {
`
4327
``
`-
let sig = ty.callable_sig(db)?;
`
4328
``
`-
return Some(Callable {
`
4329
``
`-
ty: self.clone(),
`
4330
``
`-
sig,
`
4331
``
`-
callee: Callee::Closure(*closure, subst.clone()),
`
4332
``
`-
is_bound_method: false,
`
4333
``
`-
});
`
4334
``
`-
}
`
``
4324
`+
// This will happen when it implements fn or fn mut, since we add an autoborrow adjustment
`
``
4325
`+
let (ty, kind) = if let TyKind::Ref(_, _, ty) = kind {
`
``
4326
`+
(ty, ty.kind(Interner))
`
``
4327
`+
} else {
`
``
4328
`+
(&self.ty, kind)
`
``
4329
`+
};
`
``
4330
`+
if let TyKind::Closure(closure, subst) = kind {
`
``
4331
`+
let sig = ty.callable_sig(db)?;
`
``
4332
`+
return Some(Callable {
`
``
4333
`+
ty: self.clone(),
`
``
4334
`+
sig,
`
``
4335
`+
callee: Callee::Closure(*closure, subst.clone()),
`
``
4336
`+
is_bound_method: false,
`
``
4337
`+
});
`
4335
4338
`}
`
4336
``
`-
let sig = hir_ty::callable_sig_from_fnonce(&self.ty, self.env.clone(), db)?;
`
``
4339
`+
let (fn_trait, sig) = hir_ty::callable_sig_from_fn_trait(ty, self.env.clone(), db)?;
`
4337
4340
`return Some(Callable {
`
4338
4341
`ty: self.clone(),
`
4339
4342
` sig,
`
4340
``
`-
callee: Callee::Other,
`
``
4343
`+
callee: Callee::FnImpl(fn_trait),
`
4341
4344
`is_bound_method: false,
`
4342
4345
`});
`
4343
4346
`}
`
`@@ -4968,7 +4971,7 @@ enum Callee {
`
4968
4971
`Def(CallableDefId),
`
4969
4972
`Closure(ClosureId, Substitution),
`
4970
4973
`FnPtr,
`
4971
``
`-
Other,
`
``
4974
`+
FnImpl(FnTrait),
`
4972
4975
`}
`
4973
4976
``
4974
4977
`pub enum CallableKind {
`
`@@ -4977,8 +4980,7 @@ pub enum CallableKind {
`
4977
4980
`TupleEnumVariant(Variant),
`
4978
4981
`Closure(Closure),
`
4979
4982
`FnPtr,
`
4980
``
`` -
/// Some other type that implements FnOnce
.
``
4981
``
`-
Other,
`
``
4983
`+
FnImpl(FnTrait),
`
4982
4984
`}
`
4983
4985
``
4984
4986
`impl Callable {
`
`@@ -4993,7 +4995,7 @@ impl Callable {
`
4993
4995
`CallableKind::Closure(Closure { id, subst: subst.clone() })
`
4994
4996
`}
`
4995
4997
`Callee::FnPtr => CallableKind::FnPtr,
`
4996
``
`-
Callee::Other => CallableKind::Other,
`
``
4998
`+
Callee::FnImpl(fn_) => CallableKind::FnImpl(fn_),
`
4997
4999
`}
`
4998
5000
`}
`
4999
5001
`pub fn receiver_param(&self, db: &dyn HirDatabase) -> Option<(SelfParam, Type)> {
`
`@@ -5023,6 +5025,10 @@ impl Callable {
`
5023
5025
`pub fn sig(&self) -> &CallableSig {
`
5024
5026
`&self.sig
`
5025
5027
`}
`
``
5028
+
``
5029
`+
pub fn ty(&self) -> &Type {
`
``
5030
`+
&self.ty
`
``
5031
`+
}
`
5026
5032
`}
`
5027
5033
``
5028
5034
`#[derive(Clone, Debug, Eq, PartialEq)]
`