]> git.lizzy.rs Git - rust.git/commitdiff
internal: explain that we don't `ref` in style.md
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 2 Aug 2021 12:59:28 +0000 (15:59 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 2 Aug 2021 12:59:28 +0000 (15:59 +0300)
crates/hir/src/lib.rs
crates/hir_def/src/attr.rs
crates/hir_def/src/resolver.rs
crates/hir_ty/src/diagnostics/expr.rs
crates/hir_ty/src/display.rs
crates/hir_ty/src/infer/pat.rs
crates/ide/src/annotations.rs
docs/dev/style.md

index 4428d0644f274616b767f50358ea8a7c0837bd03..76a7f75b7a3eb5fb70614847117bae58fcba80cf 100644 (file)
@@ -217,7 +217,7 @@ pub fn get_html_root_url(self: &Crate, db: &dyn HirDatabase) -> Option<String> {
 
         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 @@ fn go(ty: &Ty) -> bool {
     }
 
     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(),
         };
 
index e79b301c8c3ba40732a6ecc30606972cb915e4b8..0ef046e4690916ed89bcd5f493dc0c84eaa80cd9 100644 (file)
@@ -615,7 +615,7 @@ pub fn map(&self, range: TextRange) -> Option<InFile<TextRange>> {
 
         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
index 188e2aea9abcc5c6bfbab15198fd54b584a577b3..cd1a6c6864f67917e11ef3ae7539efa7d168bcc2 100644 (file)
@@ -479,7 +479,8 @@ fn process_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef))
                     });
                 }
             }
-            &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 };
index dc8f20138fa654c88b6acef022f85625ddd7a26a..9a6d5e082babd8edd2f1a1ee60731cbd42169f10 100644 (file)
@@ -376,12 +376,12 @@ fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &dy
         };
 
         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())
index 55a566a33d987245a2478816561501c2f03bcc71..3f7455959d763779e5311901c95805111f643c8f 100644 (file)
@@ -381,12 +381,13 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
                     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)
index 603237f944beec4e1f8df3e279895ee8441538a5..df438d2ac4c333715818e02554f1d3315448b47b 100644 (file)
@@ -132,7 +132,7 @@ pub(super) fn infer_pat(
         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 @@ pub(super) fn infer_pat(
 
                 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 @@ pub(super) fn infer_pat(
                 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 {
index 9069854353c7ab42d05d128cd3ee92a8307eba60..b7b4bd8fbee6d6e749fb10dbe9d677bfe5b86ae1 100644 (file)
@@ -133,12 +133,12 @@ fn name_range<T: NameOwner>(node: &InFile<T>, file_id: FileId) -> Option<TextRan
 }
 
 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()
index 6309fd02ce4163b7b46b2ad4b607fd31c7b78392..d5340e2b8e38a9cbc7a940e21b14ddc2cf6799a0 100644 (file)
@@ -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: