diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 4428d0644f..76a7f75b7a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -217,7 +217,7 @@ impl Crate { let doc_url = doc_attr_q.tt_values().map(|tt| { let name = tt.token_trees.iter() - .skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url")) + .skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident { text, ..} )) if text == "html_root_url")) .nth(2); match name { @@ -2397,9 +2397,9 @@ impl Type { } pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> { - let (variant_id, substs) = match *self.ty.kind(&Interner) { - TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs), - TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs), + let (variant_id, substs) = match self.ty.kind(&Interner) { + TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), substs) => ((*s).into(), substs), + TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), substs) => ((*u).into(), substs), _ => return Vec::new(), }; diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index e79b301c8c..0ef046e469 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs @@ -615,7 +615,7 @@ impl DocsRangeMap { let relative_range = range - line_docs_range.start(); - let &InFile { file_id, value: ref source } = &self.source_map.source_of_id(idx); + let InFile { file_id, value: source } = self.source_map.source_of_id(idx); match source { Either::Left(_) => None, // FIXME, figure out a nice way to handle doc attributes here // as well as for whats done in syntax highlight doc injection diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index 188e2aea9a..cd1a6c6864 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -479,7 +479,8 @@ impl Scope { }); } } - &Scope::GenericParams { ref params, def: parent } => { + Scope::GenericParams { params, def: parent } => { + let parent = *parent; for (local_id, param) in params.types.iter() { if let Some(ref name) = param.name { let id = TypeParamId { parent, local_id }; diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index dc8f20138f..9a6d5e082b 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs @@ -376,12 +376,12 @@ impl ExprValidator { }; let (params, required) = match mismatch.expected.kind(&Interner) { - TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters) + TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), parameters) if *enum_id == core_result_enum => { (parameters, "Ok".to_string()) } - TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters) + TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), parameters) if *enum_id == core_option_enum => { (parameters, "Some".to_string()) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 55a566a33d..3f7455959d 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -381,12 +381,13 @@ impl HirDisplay for Ty { TyKind::Dyn(dyn_ty) if dyn_ty.bounds.skip_binders().interned().len() > 1 => { dyn_ty.bounds.skip_binders().interned().iter().cloned().collect() } - &TyKind::Alias(AliasTy::Opaque(OpaqueTy { + TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, - substitution: ref parameters, + substitution: parameters, })) - | &TyKind::OpaqueType(opaque_ty_id, ref parameters) => { - let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into()); + | TyKind::OpaqueType(opaque_ty_id, parameters) => { + let impl_trait_id = + f.db.lookup_intern_impl_trait_id((*opaque_ty_id).into()); if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id { datas = f.db.return_type_impl_traits(func) diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 603237f944..df438d2ac4 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -132,7 +132,7 @@ impl<'a> InferenceContext<'a> { let expected = expected; let ty = match &body[pat] { - &Pat::Tuple { ref args, ellipsis } => { + Pat::Tuple { args, ellipsis } => { let expectations = match expected.as_tuple() { Some(parameters) => &*parameters.as_slice(&Interner), _ => &[], @@ -140,7 +140,7 @@ impl<'a> InferenceContext<'a> { let ((pre, post), n_uncovered_patterns) = match ellipsis { Some(idx) => { - (args.split_at(idx), expectations.len().saturating_sub(args.len())) + (args.split_at(*idx), expectations.len().saturating_sub(args.len())) } None => ((&args[..], &[][..]), 0), }; @@ -157,7 +157,7 @@ impl<'a> InferenceContext<'a> { TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys)) .intern(&Interner) } - Pat::Or(ref pats) => { + Pat::Or(pats) => { if let Some((first_pat, rest)) = pats.split_first() { let ty = self.infer_pat(*first_pat, &expected, default_bm); for pat in rest { diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 9069854353..b7b4bd8fbe 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -133,12 +133,12 @@ pub(crate) fn annotations( } pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) -> Annotation { - match annotation.kind { - AnnotationKind::HasImpls { position, ref mut data } => { - *data = goto_implementation(db, position).map(|range| range.info); + match &mut annotation.kind { + AnnotationKind::HasImpls { position, data } => { + *data = goto_implementation(db, *position).map(|range| range.info); } - AnnotationKind::HasReferences { position, ref mut data } => { - *data = find_all_refs(&Semantics::new(db), position, None).map(|result| { + AnnotationKind::HasReferences { position, data } => { + *data = find_all_refs(&Semantics::new(db), *position, None).map(|result| { result .references .into_iter() diff --git a/docs/dev/style.md b/docs/dev/style.md index 6309fd02ce..d5340e2b8e 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md @@ -915,6 +915,15 @@ if let Some(expected_type) = ctx.expected_type.as_ref() { **Rationale:** `match` is almost always more compact. The `else` branch can get a more precise pattern: `None` or `Err(_)` instead of `_`. +## Match Ergonomics + +Don't use the `ref` keyword. + +**Rationale:** consistency & simplicity. +`ref` was required before [match ergonomics](https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md). +Today, it is redundant. +Between `ref` and mach ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword). + ## Helper Functions Avoid creating singe-use helper functions: