Repository: rust-analyzer/rust-analyzer
Pull request #8923 (2021-05-22 14:20:29)

Add even more docs
bors r+
🤖


Patch:
diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs
index ef67ea2e99..b07fbf8b3f 100644
--- a/crates/hir_expand/src/name.rs
+++ b/crates/hir_expand/src/name.rs
@@ -1,4 +1,4 @@
-//! FIXME: write short doc here
+//! See [`Name`].
 
 use std::fmt;
 
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index f8233cac39..21d3fb54e9 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -435,7 +435,7 @@ mod resolve {
     use super::InferenceTable;
     use crate::{
         ConcreteConst, Const, ConstData, ConstValue, DebruijnIndex, GenericArg, InferenceVar,
-        Interner, Lifetime, Ty, TyVariableKind, VariableKind,
+        Interner, Ty, TyVariableKind, VariableKind,
     };
     use chalk_ir::{
         cast::Cast,
@@ -524,17 +524,5 @@ mod resolve {
             };
             Ok(result)
         }
-
-        fn fold_inference_lifetime(
-            &mut self,
-            _var: InferenceVar,
-            _outer_binder: DebruijnIndex,
-        ) -> Fallible<Lifetime> {
-            // fall back all lifetimes to 'static -- currently we don't deal
-            // with any lifetimes, but we can sometimes get some lifetime
-            // variables through Chalk's unification, and this at least makes
-            // sure we don't leak them outside of inference
-            Ok(crate::static_lifetime())
-        }
     }
 }
diff --git a/crates/ide_assists/src/handlers/fill_match_arms.rs b/crates/ide_assists/src/handlers/fill_match_arms.rs
index 97435f0211..58b0010505 100644
--- a/crates/ide_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ide_assists/src/handlers/fill_match_arms.rs
@@ -1,4 +1,4 @@
-use std::iter::{self, Peekable};
+use std::iter;
 
 use either::Either;
 use hir::{Adt, HasSource, ModuleDef, Semantics};
@@ -63,61 +63,50 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<
 
     let module = ctx.sema.scope(expr.syntax()).module()?;
 
-    let mut missing_pats: Peekable<Box<dyn Iterator<Item = ast::Pat>>> = if let Some(enum_def) =
-        resolve_enum_def(&ctx.sema, &expr)
-    {
+    let missing_arms: Vec<MatchArm> = if let Some(enum_def) = resolve_enum_def(&ctx.sema, &expr) {
         let variants = enum_def.variants(ctx.db());
 
-        let missing_pats = variants
+        let mut variants = variants
             .into_iter()
             .filter_map(|variant| build_pat(ctx.db(), module, variant))
-            .filter(|variant_pat| is_variant_missing(&top_lvl_pats, variant_pat));
-
-        let missing_pats: Box<dyn Iterator<Item = _>> = if Some(enum_def)
-            == FamousDefs(&ctx.sema, Some(module.krate())).core_option_Option().map(lift_enum)
+            .filter(|variant_pat| is_variant_missing(&top_lvl_pats, variant_pat))
+            .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block()))
+            .map(|it| it.clone_for_update())
+            .collect::<Vec<_>>();
+        if Some(enum_def)
+            == FamousDefs(&ctx.sema, Some(module.krate()))
+                .core_option_Option()
+                .map(|x| lift_enum(x))
         {
             // Match `Some` variant first.
             cov_mark::hit!(option_order);
-            Box::new(missing_pats.rev())
-        } else {
-            Box::new(missing_pats)
-        };
-        missing_pats.peekable()
+            variants.reverse()
+        }
+        variants
     } else if let Some(enum_defs) = resolve_tuple_of_enum_def(&ctx.sema, &expr) {
-        let mut n_arms = 1;
-        let variants_of_enums: Vec<Vec<ExtendedVariant>> = enum_defs
-            .into_iter()
-            .map(|enum_def| enum_def.variants(ctx.db()))
-            .inspect(|variants| n_arms *= variants.len())
-            .collect();
-
         // When calculating the match arms for a tuple of enums, we want
         // to create a match arm for each possible combination of enum
         // values. The `multi_cartesian_product` method transforms
         // Vec<Vec<EnumVariant>> into Vec<(EnumVariant, .., EnumVariant)>
         // where each tuple represents a proposed match arm.
-
-        // A number of arms grows very fast on even a small tuple of large enums.
-        // We skip the assist beyond an arbitrary threshold.
-        if n_arms > 256 {
-            return None;
-        }
-        let missing_pats = variants_of_enums
+        enum_defs
             .into_iter()
+            .map(|enum_def| enum_def.variants(ctx.db()))
             .multi_cartesian_product()
-            .inspect(|_| cov_mark::hit!(fill_match_arms_lazy_computation))
             .map(|variants| {
                 let patterns =
                     variants.into_iter().filter_map(|variant| build_pat(ctx.db(), module, variant));
                 ast::Pat::from(make::tuple_pat(patterns))
             })
-            .filter(|variant_pat| is_variant_missing(&top_lvl_pats, variant_pat));
-        (Box::new(missing_pats) as Box<dyn Iterator<Item = _>>).peekable()
+            .filter(|variant_pat| is_variant_missing(&top_lvl_pats, variant_pat))
+            .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block()))
+            .map(|it| it.clone_for_update())
+            .collect()
     } else {
         return None;
     };
 
-    if missing_pats.peek().is_none() {
+    if missing_arms.is_empty() {
         return None;
     }
 
@@ -128,9 +117,6 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<
         target,
         |builder| {
             let new_match_arm_list = match_arm_list.clone_for_update();
-            let missing_arms = missing_pats
-                .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block()))
-                .map(|it| it.clone_for_update());
 
             let catch_all_arm = new_match_arm_list
                 .arms()
@@ -181,13 +167,13 @@ fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool {
     }
 }
 
-#[derive(Eq, PartialEq, Clone, Copy)]
+#[derive(Eq, PartialEq, Clone)]
 enum ExtendedEnum {
     Bool,
     Enum(hir::Enum),
 }
 
-#[derive(Eq, PartialEq, Clone, Copy)]
+#[derive(Eq, PartialEq, Clone)]
 enum ExtendedVariant {
     True,
     False,
@@ -199,7 +185,7 @@ fn lift_enum(e: hir::Enum) -> ExtendedEnum {
 }
 
 impl ExtendedEnum {
-    fn variants(self, db: &RootDatabase) -> Vec<ExtendedVariant> {
+    fn variants(&self, db: &RootDatabase) -> Vec<ExtendedVariant> {
         match self {
             ExtendedEnum::Enum(e) => {
                 e.variants(db).into_iter().map(|x| ExtendedVariant::Variant(x)).collect::<Vec<_>>()
@@ -280,9 +266,7 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: ExtendedVariant) -> Op
 mod tests {
     use ide_db::helpers::FamousDefs;
 
-    use crate::tests::{
-        check_assist, check_assist_not_applicable, check_assist_target, check_assist_unresolved,
-    };
+    use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
 
     use super::fill_match_arms;
 
@@ -1061,19 +1045,4 @@ fn foo(t: Test) {
 }"#,
         );
     }
-
-    #[test]
-    fn lazy_computation() {
-        // Computing a single missing arm is enough to determine applicability of the assist.
-        cov_mark::check_count!(fill_match_arms_lazy_computation, 1);
-        check_assist_unresolved(
-            fill_match_arms,
-            r#"
-enum A { One, Two, }
-fn foo(tuple: (A, A)) {
-    match $0tuple {};
-}
-"#,
-        );
-    }
 }
diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs
index a05cab0f37..bde370fdb1 100644
--- a/crates/mbe/src/subtree_source.rs
+++ b/crates/mbe/src/subtree_source.rs
@@ -1,4 +1,6 @@
-//! FIXME: write short doc here
+//! Our parser is generic over the source of tokens it parses.
+//!
+//! This module defines tokens sourced from declarative macros.
 
 use parser::{Token, TokenSource};
 use syntax::{lex_single_syntax_kind, SmolStr, SyntaxKind, SyntaxKind::*, T};
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index a7c8c13c63..b13168bd3d 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -1,4 +1,4 @@
-//! FIXME: write short doc here
+//! Conversions between [`SyntaxNode`] and [`tt::TokenTree`].
 
 use parser::{FragmentKind, ParseError, TreeSink};
 use rustc_hash::FxHashMap;
diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs
index 195b8cf30b..99a8d250b7 100644
--- a/crates/mbe/src/tt_iter.rs
+++ b/crates/mbe/src/tt_iter.rs
@@ -1,4 +1,5 @@
-//! FIXME: write short doc here
+//! A "Parser" structure for token trees. We use this when parsing a declarative
+//! macro definition into a list of patterns and templates.
 
 use crate::{subtree_source::SubtreeTokenSource, ExpandError, ExpandResult};
 
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs
index 9bdf0b5fa2..790908aeac 100644
--- a/crates/parser/src/grammar.rs
+++ b/crates/parser/src/grammar.rs
@@ -27,6 +27,7 @@
 //! node or an error, rules like `opt_where_clause` may produce nothing.
 //! Non-opt rules typically start with `assert!(p.at(FIRST_TOKEN))`, the
 //! caller is responsible for branching on the first token.
+
 mod attributes;
 mod expressions;
 mod items;
diff --git a/crates/parser/src/grammar/attributes.rs b/crates/parser/src/grammar/attributes.rs
index 124a10eb26..b8242cd2f0 100644
--- a/crates/parser/src/grammar/attributes.rs
+++ b/crates/parser/src/grammar/attributes.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) fn inner_attrs(p: &mut Parser) {
diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs
index 0d9dc93489..9d22e1950d 100644
--- a/crates/parser/src/grammar/expressions.rs
+++ b/crates/parser/src/grammar/expressions.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 mod atom;
 
 pub(crate) use self::atom::{block_expr, match_arm_list};
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs
index 093a9890d3..269f223e6e 100644
--- a/crates/parser/src/grammar/expressions/atom.rs
+++ b/crates/parser/src/grammar/expressions/atom.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 // test expr_literals
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs
index adec74ef3d..1057ca8c29 100644
--- a/crates/parser/src/grammar/items.rs
+++ b/crates/parser/src/grammar/items.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 mod consts;
 mod adt;
 mod traits;
diff --git a/crates/parser/src/grammar/items/adt.rs b/crates/parser/src/grammar/items/adt.rs
index 67c0c56970..386d3806c3 100644
--- a/crates/parser/src/grammar/items/adt.rs
+++ b/crates/parser/src/grammar/items/adt.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) fn strukt(p: &mut Parser, m: Marker) {
diff --git a/crates/parser/src/grammar/items/consts.rs b/crates/parser/src/grammar/items/consts.rs
index 12130df40d..ed3bee4a46 100644
--- a/crates/parser/src/grammar/items/consts.rs
+++ b/crates/parser/src/grammar/items/consts.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) fn static_(p: &mut Parser, m: Marker) {
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs
index d3327271cc..74f11b45a1 100644
--- a/crates/parser/src/grammar/items/traits.rs
+++ b/crates/parser/src/grammar/items/traits.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 // test trait_item
diff --git a/crates/parser/src/grammar/items/use_item.rs b/crates/parser/src/grammar/items/use_item.rs
index 5cb8b08e71..2339d0c69c 100644
--- a/crates/parser/src/grammar/items/use_item.rs
+++ b/crates/parser/src/grammar/items/use_item.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) fn use_(p: &mut Parser, m: Marker) {
diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs
index 9e2f02d435..01ee26a530 100644
--- a/crates/parser/src/grammar/params.rs
+++ b/crates/parser/src/grammar/params.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 // test param_list
diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs
index b10f48fe12..e633646c3b 100644
--- a/crates/parser/src/grammar/paths.rs
+++ b/crates/parser/src/grammar/paths.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) const PATH_FIRST: TokenSet =
diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs
index f1d1f9eaa6..bd092e0af8 100644
--- a/crates/parser/src/grammar/patterns.rs
+++ b/crates/parser/src/grammar/patterns.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) const PATTERN_FIRST: TokenSet =
diff --git a/crates/parser/src/grammar/type_args.rs b/crates/parser/src/grammar/type_args.rs
index be36cad172..ed2322e52c 100644
--- a/crates/parser/src/grammar/type_args.rs
+++ b/crates/parser/src/grammar/type_args.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
diff --git a/crates/parser/src/grammar/type_params.rs b/crates/parser/src/grammar/type_params.rs
index b1f9792814..49d6fa6d0b 100644
--- a/crates/parser/src/grammar/type_params.rs
+++ b/crates/parser/src/grammar/type_params.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) fn opt_generic_param_list(p: &mut Parser) {
diff --git a/crates/parser/src/grammar/types.rs b/crates/parser/src/grammar/types.rs
index 6ae3e734fe..72476c1907 100644
--- a/crates/parser/src/grammar/types.rs
+++ b/crates/parser/src/grammar/types.rs
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(TokenSet::new(&[
diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs
index 81e26e009a..3f87d98a86 100644
--- a/crates/parser/src/parser.rs
+++ b/crates/parser/src/parser.rs
@@ -1,4 +1,4 @@
-//! FIXME: write short doc here
+//! See [`Parser`].
 
 use std::cell::Cell;
 
diff --git a/crates/parser/src/syntax_kind.rs b/crates/parser/src/syntax_kind.rs
index 9ea0e4f9ba..4d4377422b 100644
--- a/crates/parser/src/syntax_kind.rs
+++ b/crates/parser/src/syntax_kind.rs
@@ -1,4 +1,5 @@
-//! FIXME: write short doc here
+//! Defines [`SyntaxKind`] -- a fieldless enum of all possible syntactic
+//! constructs of the Rust language.
 
 #[macro_use]
 mod generated;
diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs
index e31cc2a673..f97e751c58 100644
--- a/xtask/src/tidy.rs
+++ b/xtask/src/tidy.rs
@@ -348,7 +348,7 @@ struct TidyDocs {
 impl TidyDocs {
     fn visit(&mut self, path: &Path, text: &str) {
         // Tests and diagnostic fixes don't need module level comments.
-        if is_exclude_dir(path, &["tests", "test_data", "fixes"]) {
+        if is_exclude_dir(path, &["tests", "test_data", "fixes", "grammar"]) {
             return;
         }
 
@@ -392,7 +392,7 @@ impl TidyDocs {
             )
         }
 
-        let poorly_documented = ["hir_expand", "mbe", "parser", "hir_ty"];
+        let poorly_documented = ["hir_ty"];
 
         let mut has_fixmes =
             poorly_documented.iter().map(|it| (*it, false)).collect::<HashMap<&str, bool>>();


Test patch:
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs
index 6a9231e078..1739302bf0 100644
--- a/crates/ide_assists/src/tests.rs
+++ b/crates/ide_assists/src/tests.rs
@@ -65,12 +65,6 @@ pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) {
     check(assist, ra_fixture, ExpectedResult::NotApplicable, None);
 }
 
-/// Check assist in unresolved state. Useful to check assists for lazy computation.
-#[track_caller]
-pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) {
-    check(assist, ra_fixture, ExpectedResult::Unresolved, None);
-}
-
 #[track_caller]
 fn check_doc_test(assist_id: &str, before: &str, after: &str) {
     let after = trim_indent(after);
@@ -107,7 +101,6 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
 
 enum ExpectedResult<'a> {
     NotApplicable,
-    Unresolved,
     After(&'a str),
     Target(&'a str),
 }
@@ -122,11 +115,7 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
     let sema = Semantics::new(&db);
     let config = TEST_CONFIG;
     let ctx = AssistContext::new(sema, &config, frange);
-    let resolve = match expected {
-        ExpectedResult::Unresolved => AssistResolveStrategy::None,
-        _ => AssistResolveStrategy::All,
-    };
-    let mut acc = Assists::new(&ctx, resolve);
+    let mut acc = Assists::new(&ctx, AssistResolveStrategy::All);
     handler(&mut acc, &ctx);
     let mut res = acc.finish();
 
@@ -174,14 +163,8 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
             let range = assist.target;
             assert_eq_text!(&text_without_caret[range], target);
         }
-        (Some(assist), ExpectedResult::Unresolved) => assert!(
-            assist.source_change.is_none(),
-            "unresolved assist should not contain source changes"
-        ),
         (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"),
-        (None, ExpectedResult::After(_))
-        | (None, ExpectedResult::Target(_))
-        | (None, ExpectedResult::Unresolved) => {
+        (None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => {
             panic!("code action is not applicable")
         }
         (None, ExpectedResult::NotApplicable) => (),