Skip to content

Commit 0d56ff2

Browse files
bors[bot]matklad
andauthored
Merge #9758
9758: internal: explain that we don't `ref` in style.md r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents d6f2352 + 12d7f5b commit 0d56ff2

File tree

8 files changed

+31
-20
lines changed

8 files changed

+31
-20
lines changed

crates/hir/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl Crate {
217217

218218
let doc_url = doc_attr_q.tt_values().map(|tt| {
219219
let name = tt.token_trees.iter()
220-
.skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url"))
220+
.skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident { text, ..} )) if text == "html_root_url"))
221221
.nth(2);
222222

223223
match name {
@@ -2397,9 +2397,9 @@ impl Type {
23972397
}
23982398

23992399
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
2400-
let (variant_id, substs) = match *self.ty.kind(&Interner) {
2401-
TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs),
2402-
TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs),
2400+
let (variant_id, substs) = match self.ty.kind(&Interner) {
2401+
TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), substs) => ((*s).into(), substs),
2402+
TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), substs) => ((*u).into(), substs),
24032403
_ => return Vec::new(),
24042404
};
24052405

crates/hir_def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl DocsRangeMap {
615615

616616
let relative_range = range - line_docs_range.start();
617617

618-
let &InFile { file_id, value: ref source } = &self.source_map.source_of_id(idx);
618+
let InFile { file_id, value: source } = self.source_map.source_of_id(idx);
619619
match source {
620620
Either::Left(_) => None, // FIXME, figure out a nice way to handle doc attributes here
621621
// as well as for whats done in syntax highlight doc injection

crates/hir_def/src/resolver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ impl Scope {
479479
});
480480
}
481481
}
482-
&Scope::GenericParams { ref params, def: parent } => {
482+
Scope::GenericParams { params, def: parent } => {
483+
let parent = *parent;
483484
for (local_id, param) in params.types.iter() {
484485
if let Some(ref name) = param.name {
485486
let id = TypeParamId { parent, local_id };

crates/hir_ty/src/diagnostics/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ impl ExprValidator {
376376
};
377377

378378
let (params, required) = match mismatch.expected.kind(&Interner) {
379-
TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters)
379+
TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), parameters)
380380
if *enum_id == core_result_enum =>
381381
{
382382
(parameters, "Ok".to_string())
383383
}
384-
TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters)
384+
TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), parameters)
385385
if *enum_id == core_option_enum =>
386386
{
387387
(parameters, "Some".to_string())

crates/hir_ty/src/display.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,13 @@ impl HirDisplay for Ty {
381381
TyKind::Dyn(dyn_ty) if dyn_ty.bounds.skip_binders().interned().len() > 1 => {
382382
dyn_ty.bounds.skip_binders().interned().iter().cloned().collect()
383383
}
384-
&TyKind::Alias(AliasTy::Opaque(OpaqueTy {
384+
TyKind::Alias(AliasTy::Opaque(OpaqueTy {
385385
opaque_ty_id,
386-
substitution: ref parameters,
386+
substitution: parameters,
387387
}))
388-
| &TyKind::OpaqueType(opaque_ty_id, ref parameters) => {
389-
let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into());
388+
| TyKind::OpaqueType(opaque_ty_id, parameters) => {
389+
let impl_trait_id =
390+
f.db.lookup_intern_impl_trait_id((*opaque_ty_id).into());
390391
if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id {
391392
datas =
392393
f.db.return_type_impl_traits(func)

crates/hir_ty/src/infer/pat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ impl<'a> InferenceContext<'a> {
132132
let expected = expected;
133133

134134
let ty = match &body[pat] {
135-
&Pat::Tuple { ref args, ellipsis } => {
135+
Pat::Tuple { args, ellipsis } => {
136136
let expectations = match expected.as_tuple() {
137137
Some(parameters) => &*parameters.as_slice(&Interner),
138138
_ => &[],
139139
};
140140

141141
let ((pre, post), n_uncovered_patterns) = match ellipsis {
142142
Some(idx) => {
143-
(args.split_at(idx), expectations.len().saturating_sub(args.len()))
143+
(args.split_at(*idx), expectations.len().saturating_sub(args.len()))
144144
}
145145
None => ((&args[..], &[][..]), 0),
146146
};
@@ -157,7 +157,7 @@ impl<'a> InferenceContext<'a> {
157157
TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys))
158158
.intern(&Interner)
159159
}
160-
Pat::Or(ref pats) => {
160+
Pat::Or(pats) => {
161161
if let Some((first_pat, rest)) = pats.split_first() {
162162
let ty = self.infer_pat(*first_pat, &expected, default_bm);
163163
for pat in rest {

crates/ide/src/annotations.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ pub(crate) fn annotations(
133133
}
134134

135135
pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) -> Annotation {
136-
match annotation.kind {
137-
AnnotationKind::HasImpls { position, ref mut data } => {
138-
*data = goto_implementation(db, position).map(|range| range.info);
136+
match &mut annotation.kind {
137+
AnnotationKind::HasImpls { position, data } => {
138+
*data = goto_implementation(db, *position).map(|range| range.info);
139139
}
140-
AnnotationKind::HasReferences { position, ref mut data } => {
141-
*data = find_all_refs(&Semantics::new(db), position, None).map(|result| {
140+
AnnotationKind::HasReferences { position, data } => {
141+
*data = find_all_refs(&Semantics::new(db), *position, None).map(|result| {
142142
result
143143
.references
144144
.into_iter()

docs/dev/style.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,15 @@ if let Some(expected_type) = ctx.expected_type.as_ref() {
915915
**Rationale:** `match` is almost always more compact.
916916
The `else` branch can get a more precise pattern: `None` or `Err(_)` instead of `_`.
917917

918+
## Match Ergonomics
919+
920+
Don't use the `ref` keyword.
921+
922+
**Rationale:** consistency & simplicity.
923+
`ref` was required before [match ergonomics](https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md).
924+
Today, it is redundant.
925+
Between `ref` and mach ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword).
926+
918927
## Helper Functions
919928

920929
Avoid creating singe-use helper functions:

0 commit comments

Comments
 (0)