}
let prohibit_opaque = match item.kind {
- ItemKind::OpaqueTy(hir::OpaqueTy { origin: hir::OpaqueTyOrigin::AsyncFn, .. })
- | ItemKind::OpaqueTy(hir::OpaqueTy { origin: hir::OpaqueTyOrigin::FnReturn, .. }) => {
+ ItemKind::OpaqueTy(hir::OpaqueTy {
+ origin: hir::OpaqueTyOrigin::AsyncFn | hir::OpaqueTyOrigin::FnReturn,
+ ..
+ }) => {
let mut visitor = ProhibitOpaqueVisitor {
opaque_identity_ty: tcx
.mk_opaque(def_id, InternalSubsts::identity_for_item(tcx, def_id)),
sig: &ty::FnSig<'_>,
ident: Ident,
predicates: ty::GenericPredicates<'_>,
+ assoc: &ty::AssocItem,
) -> String {
let args = sig
.inputs()
.iter()
- .map(|ty| {
+ .enumerate()
+ .map(|(i, ty)| {
Some(match ty.kind {
- ty::Param(param) if param.name == kw::SelfUpper => "self".to_string(),
- ty::Ref(reg, ref_ty, mutability) => {
+ ty::Param(_) if assoc.fn_has_self_parameter && i == 0 => "self".to_string(),
+ ty::Ref(reg, ref_ty, mutability) if i == 0 => {
let reg = match &format!("{}", reg)[..] {
"'_" | "" => String::new(),
reg => format!("{} ", reg),
};
- match ref_ty.kind {
- ty::Param(param) if param.name == kw::SelfUpper => {
- format!("&{}{}self", reg, mutability.prefix_str())
+ if assoc.fn_has_self_parameter {
+ match ref_ty.kind {
+ ty::Param(param) if param.name == kw::SelfUpper => {
+ format!("&{}{}self", reg, mutability.prefix_str())
+ }
+
+ _ => format!("self: {}", ty),
}
- _ => format!("_: {:?}", ty),
+ } else {
+ format!("_: {:?}", ty)
+ }
+ }
+ _ => {
+ if assoc.fn_has_self_parameter && i == 0 {
+ format!("self: {:?}", ty)
+ } else {
+ format!("_: {:?}", ty)
}
}
- _ => format!("_: {:?}", ty),
})
})
.chain(std::iter::once(if sig.c_variadic { Some("...".to_string()) } else { None }))
tcx.fn_sig(assoc.def_id).skip_binder(),
assoc.ident,
tcx.predicates_of(assoc.def_id),
+ assoc,
)
}
ty::AssocKind::Type => format!("type {} = Type;", assoc.ident),
ty::Float(ast::FloatTy::F32) => {
variadic_error(tcx.sess, arg.span, arg_ty, "c_double");
}
- ty::Int(ast::IntTy::I8) | ty::Int(ast::IntTy::I16) | ty::Bool => {
+ ty::Int(ast::IntTy::I8 | ast::IntTy::I16) | ty::Bool => {
variadic_error(tcx.sess, arg.span, arg_ty, "c_int");
}
- ty::Uint(ast::UintTy::U8) | ty::Uint(ast::UintTy::U16) => {
+ ty::Uint(ast::UintTy::U8 | ast::UintTy::U16) => {
variadic_error(tcx.sess, arg.span, arg_ty, "c_uint");
}
ty::FnDef(..) => {
ty::Adt(adt, substs) => Some((adt.variant_of_res(def), adt.did, substs)),
_ => bug!("unexpected type: {:?}", ty),
},
- Res::Def(DefKind::Struct, _)
- | Res::Def(DefKind::Union, _)
- | Res::Def(DefKind::TyAlias, _)
- | Res::Def(DefKind::AssocTy, _)
+ Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
| Res::SelfTy(..) => match ty.kind {
ty::Adt(adt, substs) if !adt.is_enum() => {
Some((adt.non_enum_variant(), adt.did, substs))
};
let mut msg = "call this function";
match hir.get_if_local(def_id) {
- Some(Node::Item(hir::Item { kind: ItemKind::Fn(.., body_id), .. }))
- | Some(Node::ImplItem(hir::ImplItem {
- kind: hir::ImplItemKind::Fn(_, body_id),
- ..
- }))
- | Some(Node::TraitItem(hir::TraitItem {
- kind: hir::TraitItemKind::Fn(.., hir::TraitFn::Provided(body_id)),
- ..
- })) => {
+ Some(
+ Node::Item(hir::Item { kind: ItemKind::Fn(.., body_id), .. })
+ | Node::ImplItem(hir::ImplItem {
+ kind: hir::ImplItemKind::Fn(_, body_id), ..
+ })
+ | Node::TraitItem(hir::TraitItem {
+ kind: hir::TraitItemKind::Fn(.., hir::TraitFn::Provided(body_id)),
+ ..
+ }),
+ ) => {
let body = hir.body(*body_id);
sugg_call = body
.params
is_alias_variant_ctor = true;
}
}
- Res::Def(DefKind::AssocFn, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
+ Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => {
let container = tcx.associated_item(def_id).container;
debug!("instantiate_value_path: def_id={:?} container={:?}", def_id, container);
match container {