]> git.lizzy.rs Git - rust.git/commitdiff
Add extra insert_use test for pub(crate) re-export handling
authorLukas Wirth <lukastw97@gmail.com>
Thu, 3 Sep 2020 16:44:39 +0000 (18:44 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Thu, 3 Sep 2020 18:26:27 +0000 (20:26 +0200)
crates/assists/src/handlers/extract_struct_from_enum_variant.rs
crates/assists/src/utils/insert_use.rs

index eb812c1c9f13bf681211d09dbe2ea15733908497..80c62d8bba7ff78ded65d04ca5dad2fb5e93701b 100644 (file)
@@ -97,6 +97,7 @@ fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVari
         .any(|(name, _)| name.to_string() == variant_name.to_string())
 }
 
+#[allow(dead_code)]
 fn insert_import(
     ctx: &AssistContext,
     builder: &mut AssistBuilder,
@@ -174,9 +175,9 @@ fn update_reference(
     builder: &mut AssistBuilder,
     reference: Reference,
     source_file: &SourceFile,
-    enum_module_def: &ModuleDef,
-    variant_hir_name: &Name,
-    visited_modules_set: &mut FxHashSet<Module>,
+    _enum_module_def: &ModuleDef,
+    _variant_hir_name: &Name,
+    _visited_modules_set: &mut FxHashSet<Module>,
 ) -> Option<()> {
     let path_expr: ast::PathExpr = find_node_at_offset::<ast::PathExpr>(
         source_file.syntax(),
@@ -185,7 +186,7 @@ fn update_reference(
     let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?;
     let list = call.arg_list()?;
     let segment = path_expr.path()?.segment()?;
-    let module = ctx.sema.scope(&path_expr.syntax()).module()?;
+    let _module = ctx.sema.scope(&path_expr.syntax()).module()?;
     let list_range = list.syntax().text_range();
     let inside_list_range = TextRange::new(
         list_range.start().checked_add(TextSize::from(1))?,
index 40ff31075d168aa4749ea6c64cf13c98c44f631c..8a4c8520d73336acffc5bb3c71ada89ddd42590e 100644 (file)
@@ -1,3 +1,4 @@
+//! Handle syntactic aspects of inserting a new `use`.
 use std::iter::{self, successors};
 
 use algo::skip_trivia_token;
@@ -10,7 +11,6 @@
     ast::{self, make, AstNode},
     Direction, InsertPosition, SyntaxElement, SyntaxNode, T,
 };
-
 use test_utils::mark;
 
 #[derive(Debug)]
@@ -55,7 +55,7 @@ fn indent_level(&self) -> IndentLevel {
     fn first_insert_pos(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) {
         match self {
             ImportScope::File(_) => (InsertPosition::First, AddBlankLine::AfterTwice),
-            // don't insert the impotrs before the item lists curly brace
+            // don't insert the imports before the item list's opening curly brace
             ImportScope::Module(item_list) => item_list
                 .l_curly_token()
                 .map(|b| (InsertPosition::After(b.into()), AddBlankLine::Around))
@@ -64,7 +64,7 @@ fn first_insert_pos(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) {
     }
 
     fn insert_pos_after_inner_attribute(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) {
-        // check if the scope has a inner attributes, we dont want to insert in front of it
+        // check if the scope has inner attributes, we dont want to insert in front of them
         match self
             .as_syntax_node()
             .children()
@@ -119,7 +119,7 @@ pub(crate) fn insert_use(
         }
 
         if let ident_level @ 1..=usize::MAX = scope.indent_level().0 as usize {
-            // TODO: this alone doesnt properly re-align all cases
+            // FIXME: this alone doesnt properly re-align all cases
             buf.push(make::tokens::whitespace(&" ".repeat(4 * ident_level)).into());
         }
         buf.push(use_item.syntax().clone().into());
@@ -530,8 +530,6 @@ fn insert_empty_file() {
 
     #[test]
     fn insert_after_inner_attr() {
-        // empty files will get two trailing newlines
-        // this is due to the test case insert_no_imports above
         check_full(
             "foo::bar",
             r"#![allow(unused_imports)]",
@@ -543,8 +541,6 @@ fn insert_after_inner_attr() {
 
     #[test]
     fn insert_after_inner_attr2() {
-        // empty files will get two trailing newlines
-        // this is due to the test case insert_no_imports above
         check_full(
             "foo::bar",
             r"#![allow(unused_imports)]
@@ -647,6 +643,16 @@ fn merge_groups_skip_pub() {
         )
     }
 
+    #[test]
+    fn merge_groups_skip_pub_crate() {
+        check_full(
+            "std::io",
+            r"pub(crate) use std::fmt::{Result, Display};",
+            r"pub(crate) use std::fmt::{Result, Display};
+use std::io;",
+        )
+    }
+
     #[test]
     #[ignore] // FIXME: Support this
     fn split_out_merge() {