Merge #9758
9758: internal: explain that we don't `ref` in style.md r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
0d56ff2a02
@ -217,7 +217,7 @@ impl Crate {
|
|||||||
|
|
||||||
let doc_url = doc_attr_q.tt_values().map(|tt| {
|
let doc_url = doc_attr_q.tt_values().map(|tt| {
|
||||||
let name = tt.token_trees.iter()
|
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);
|
.nth(2);
|
||||||
|
|
||||||
match name {
|
match name {
|
||||||
@ -2397,9 +2397,9 @@ impl Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
|
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
|
||||||
let (variant_id, substs) = match *self.ty.kind(&Interner) {
|
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::StructId(s)), substs) => ((*s).into(), substs),
|
||||||
TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs),
|
TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), substs) => ((*u).into(), substs),
|
||||||
_ => return Vec::new(),
|
_ => return Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -615,7 +615,7 @@ impl DocsRangeMap {
|
|||||||
|
|
||||||
let relative_range = range - line_docs_range.start();
|
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 {
|
match source {
|
||||||
Either::Left(_) => None, // FIXME, figure out a nice way to handle doc attributes here
|
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
|
// as well as for whats done in syntax highlight doc injection
|
||||||
|
@ -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() {
|
for (local_id, param) in params.types.iter() {
|
||||||
if let Some(ref name) = param.name {
|
if let Some(ref name) = param.name {
|
||||||
let id = TypeParamId { parent, local_id };
|
let id = TypeParamId { parent, local_id };
|
||||||
|
@ -376,12 +376,12 @@ impl ExprValidator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (params, required) = match mismatch.expected.kind(&Interner) {
|
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 =>
|
if *enum_id == core_result_enum =>
|
||||||
{
|
{
|
||||||
(parameters, "Ok".to_string())
|
(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 =>
|
if *enum_id == core_option_enum =>
|
||||||
{
|
{
|
||||||
(parameters, "Some".to_string())
|
(parameters, "Some".to_string())
|
||||||
|
@ -381,12 +381,13 @@ impl HirDisplay for Ty {
|
|||||||
TyKind::Dyn(dyn_ty) if dyn_ty.bounds.skip_binders().interned().len() > 1 => {
|
TyKind::Dyn(dyn_ty) if dyn_ty.bounds.skip_binders().interned().len() > 1 => {
|
||||||
dyn_ty.bounds.skip_binders().interned().iter().cloned().collect()
|
dyn_ty.bounds.skip_binders().interned().iter().cloned().collect()
|
||||||
}
|
}
|
||||||
&TyKind::Alias(AliasTy::Opaque(OpaqueTy {
|
TyKind::Alias(AliasTy::Opaque(OpaqueTy {
|
||||||
opaque_ty_id,
|
opaque_ty_id,
|
||||||
substitution: ref parameters,
|
substitution: parameters,
|
||||||
}))
|
}))
|
||||||
| &TyKind::OpaqueType(opaque_ty_id, ref parameters) => {
|
| TyKind::OpaqueType(opaque_ty_id, parameters) => {
|
||||||
let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into());
|
let impl_trait_id =
|
||||||
|
f.db.lookup_intern_impl_trait_id((*opaque_ty_id).into());
|
||||||
if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id {
|
if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id {
|
||||||
datas =
|
datas =
|
||||||
f.db.return_type_impl_traits(func)
|
f.db.return_type_impl_traits(func)
|
||||||
|
@ -132,7 +132,7 @@ impl<'a> InferenceContext<'a> {
|
|||||||
let expected = expected;
|
let expected = expected;
|
||||||
|
|
||||||
let ty = match &body[pat] {
|
let ty = match &body[pat] {
|
||||||
&Pat::Tuple { ref args, ellipsis } => {
|
Pat::Tuple { args, ellipsis } => {
|
||||||
let expectations = match expected.as_tuple() {
|
let expectations = match expected.as_tuple() {
|
||||||
Some(parameters) => &*parameters.as_slice(&Interner),
|
Some(parameters) => &*parameters.as_slice(&Interner),
|
||||||
_ => &[],
|
_ => &[],
|
||||||
@ -140,7 +140,7 @@ impl<'a> InferenceContext<'a> {
|
|||||||
|
|
||||||
let ((pre, post), n_uncovered_patterns) = match ellipsis {
|
let ((pre, post), n_uncovered_patterns) = match ellipsis {
|
||||||
Some(idx) => {
|
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),
|
None => ((&args[..], &[][..]), 0),
|
||||||
};
|
};
|
||||||
@ -157,7 +157,7 @@ impl<'a> InferenceContext<'a> {
|
|||||||
TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys))
|
TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys))
|
||||||
.intern(&Interner)
|
.intern(&Interner)
|
||||||
}
|
}
|
||||||
Pat::Or(ref pats) => {
|
Pat::Or(pats) => {
|
||||||
if let Some((first_pat, rest)) = pats.split_first() {
|
if let Some((first_pat, rest)) = pats.split_first() {
|
||||||
let ty = self.infer_pat(*first_pat, &expected, default_bm);
|
let ty = self.infer_pat(*first_pat, &expected, default_bm);
|
||||||
for pat in rest {
|
for pat in rest {
|
||||||
|
@ -133,12 +133,12 @@ pub(crate) fn annotations(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) -> Annotation {
|
pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) -> Annotation {
|
||||||
match annotation.kind {
|
match &mut annotation.kind {
|
||||||
AnnotationKind::HasImpls { position, ref mut data } => {
|
AnnotationKind::HasImpls { position, data } => {
|
||||||
*data = goto_implementation(db, position).map(|range| range.info);
|
*data = goto_implementation(db, *position).map(|range| range.info);
|
||||||
}
|
}
|
||||||
AnnotationKind::HasReferences { position, ref mut data } => {
|
AnnotationKind::HasReferences { position, data } => {
|
||||||
*data = find_all_refs(&Semantics::new(db), position, None).map(|result| {
|
*data = find_all_refs(&Semantics::new(db), *position, None).map(|result| {
|
||||||
result
|
result
|
||||||
.references
|
.references
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -915,6 +915,15 @@ if let Some(expected_type) = ctx.expected_type.as_ref() {
|
|||||||
**Rationale:** `match` is almost always more compact.
|
**Rationale:** `match` is almost always more compact.
|
||||||
The `else` branch can get a more precise pattern: `None` or `Err(_)` instead of `_`.
|
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
|
## Helper Functions
|
||||||
|
|
||||||
Avoid creating singe-use helper functions:
|
Avoid creating singe-use helper functions:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user