mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
internal: explain that we don't ref
in style.md
This commit is contained in:
parent
5f3662e01c
commit
12d7f5b56e
8 changed files with 31 additions and 20 deletions
|
@ -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(),
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue