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 {
}
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(),
};
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
});
}
}
- &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 };
};
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())
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)
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),
_ => &[],
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),
};
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 {
}
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()
**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: