]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #71231 - cuviper:rustc_or_patterns, r=Mark-Simulacrum
authorbors <bors@rust-lang.org>
Sun, 19 Apr 2020 16:43:02 +0000 (16:43 +0000)
committerbors <bors@rust-lang.org>
Sun, 19 Apr 2020 16:43:02 +0000 (16:43 +0000)
Dogfood more or_patterns in the compiler

Another step toward the stabilization of `or_patterns`...

cc #54883 @Centril
r? @Mark-Simulacrum

1  2 
src/librustc_typeck/check/mod.rs

index 9bb81c322ab1b9ed9a127a389fdd2df169b9e773,d75d57b026c9bf8bc5093e3e7ddb18c2286cce5f..1be8d258dcb18d29333f7e2b447c4e51173d485b
@@@ -1639,8 -1639,10 +1639,10 @@@ fn check_opaque_for_inheriting_lifetime
      }
  
      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)),
@@@ -2251,39 -2253,26 +2253,39 @@@ fn fn_sig_suggestion
      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 }))
@@@ -2322,7 -2311,6 +2324,7 @@@ fn suggestion_signature(assoc: &ty::Ass
                  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),
@@@ -4127,10 -4115,10 +4129,10 @@@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> 
                      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 {