mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 21:25:25 +00:00 
			
		
		
		
	Merge pull request #18951 from Veykril/push-zpvunsvlpuxt
Add missing `#[rust_analyzer::rust_fixture]` annotations
This commit is contained in:
		
						commit
						132a2a03c4
					
				
					 12 changed files with 149 additions and 51 deletions
				
			
		| 
						 | 
					@ -4855,6 +4855,7 @@ impl Type {
 | 
				
			||||||
        self.normalize_trait_assoc_type(db, &[], iterator_item.into())
 | 
					        self.normalize_trait_assoc_type(db, &[], iterator_item.into())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Resolves the projection `<Self as IntoIterator>::IntoIter` and returns the resulting type
 | 
				
			||||||
    pub fn into_iterator_iter(self, db: &dyn HirDatabase) -> Option<Type> {
 | 
					    pub fn into_iterator_iter(self, db: &dyn HirDatabase) -> Option<Type> {
 | 
				
			||||||
        let trait_ = db.lang_item(self.env.krate, LangItem::IntoIterIntoIter).and_then(|it| {
 | 
					        let trait_ = db.lang_item(self.env.krate, LangItem::IntoIterIntoIter).and_then(|it| {
 | 
				
			||||||
            let into_iter_fn = it.as_function()?;
 | 
					            let into_iter_fn = it.as_function()?;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1128,7 +1128,10 @@ fn main {
 | 
				
			||||||
            destructure_tuple_binding_impl(acc, ctx, false)
 | 
					            destructure_tuple_binding_impl(acc, ctx, false)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pub(crate) fn check_in_place_assist(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					        pub(crate) fn check_in_place_assist(
 | 
				
			||||||
 | 
					            #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					            #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					        ) {
 | 
				
			||||||
            check_assist_by_label(
 | 
					            check_assist_by_label(
 | 
				
			||||||
                in_place_assist,
 | 
					                in_place_assist,
 | 
				
			||||||
                ra_fixture_before,
 | 
					                ra_fixture_before,
 | 
				
			||||||
| 
						 | 
					@ -1138,7 +1141,10 @@ fn main {
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pub(crate) fn check_sub_pattern_assist(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					        pub(crate) fn check_sub_pattern_assist(
 | 
				
			||||||
 | 
					            #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					            #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					        ) {
 | 
				
			||||||
            check_assist_by_label(
 | 
					            check_assist_by_label(
 | 
				
			||||||
                assist,
 | 
					                assist,
 | 
				
			||||||
                ra_fixture_before,
 | 
					                ra_fixture_before,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -209,7 +209,10 @@ mod tests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn check(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					    fn check(
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
        check_assist(
 | 
					        check_assist(
 | 
				
			||||||
            remove_dbg,
 | 
					            remove_dbg,
 | 
				
			||||||
            &format!("fn main() {{\n{ra_fixture_before}\n}}"),
 | 
					            &format!("fn main() {{\n{ra_fixture_before}\n}}"),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,7 +77,11 @@ pub(crate) fn with_single_file(text: &str) -> (RootDatabase, EditionedFileId) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					pub(crate) fn check_assist(
 | 
				
			||||||
 | 
					    assist: Handler,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
					    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
				
			||||||
    check(assist, ra_fixture_before, ExpectedResult::After(&ra_fixture_after), None);
 | 
					    check(assist, ra_fixture_before, ExpectedResult::After(&ra_fixture_after), None);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -85,8 +89,8 @@ pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_assist_no_snippet_cap(
 | 
					pub(crate) fn check_assist_no_snippet_cap(
 | 
				
			||||||
    assist: Handler,
 | 
					    assist: Handler,
 | 
				
			||||||
    ra_fixture_before: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
    ra_fixture_after: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
					    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
				
			||||||
    check_with_config(
 | 
					    check_with_config(
 | 
				
			||||||
| 
						 | 
					@ -101,8 +105,8 @@ pub(crate) fn check_assist_no_snippet_cap(
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_assist_import_one(
 | 
					pub(crate) fn check_assist_import_one(
 | 
				
			||||||
    assist: Handler,
 | 
					    assist: Handler,
 | 
				
			||||||
    ra_fixture_before: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
    ra_fixture_after: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
					    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
				
			||||||
    check_with_config(
 | 
					    check_with_config(
 | 
				
			||||||
| 
						 | 
					@ -118,8 +122,8 @@ pub(crate) fn check_assist_import_one(
 | 
				
			||||||
// so this is here to allow you choose.
 | 
					// so this is here to allow you choose.
 | 
				
			||||||
pub(crate) fn check_assist_by_label(
 | 
					pub(crate) fn check_assist_by_label(
 | 
				
			||||||
    assist: Handler,
 | 
					    assist: Handler,
 | 
				
			||||||
    ra_fixture_before: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
    ra_fixture_after: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
    label: &str,
 | 
					    label: &str,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
					    let ra_fixture_after = trim_indent(ra_fixture_after);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,10 +32,11 @@ pub(crate) fn complete_dot(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Suggest .await syntax for types that implement Future trait
 | 
					    // Suggest .await syntax for types that implement Future trait
 | 
				
			||||||
    if let Some(future_output) = receiver_ty.into_future_output(ctx.db) {
 | 
					    if let Some(future_output) = receiver_ty.into_future_output(ctx.db) {
 | 
				
			||||||
 | 
					        let await_str = SmolStr::new_static("await");
 | 
				
			||||||
        let mut item = CompletionItem::new(
 | 
					        let mut item = CompletionItem::new(
 | 
				
			||||||
            CompletionItemKind::Keyword,
 | 
					            CompletionItemKind::Keyword,
 | 
				
			||||||
            ctx.source_range(),
 | 
					            ctx.source_range(),
 | 
				
			||||||
            SmolStr::new_static("await"),
 | 
					            await_str.clone(),
 | 
				
			||||||
            ctx.edition,
 | 
					            ctx.edition,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        item.detail("expr.await");
 | 
					        item.detail("expr.await");
 | 
				
			||||||
| 
						 | 
					@ -58,17 +59,13 @@ pub(crate) fn complete_dot(
 | 
				
			||||||
            acc,
 | 
					            acc,
 | 
				
			||||||
            ctx,
 | 
					            ctx,
 | 
				
			||||||
            &future_output,
 | 
					            &future_output,
 | 
				
			||||||
            |acc, field, ty| {
 | 
					            |acc, field, ty| acc.add_field(ctx, &dot_access, Some(await_str.clone()), field, &ty),
 | 
				
			||||||
                acc.add_field(ctx, &dot_access, Some(SmolStr::new_static("await")), field, &ty)
 | 
					            |acc, field, ty| acc.add_tuple_field(ctx, Some(await_str.clone()), field, &ty),
 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            |acc, field, ty| {
 | 
					 | 
				
			||||||
                acc.add_tuple_field(ctx, Some(SmolStr::new_static("await")), field, &ty)
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            is_field_access,
 | 
					            is_field_access,
 | 
				
			||||||
            is_method_access_with_parens,
 | 
					            is_method_access_with_parens,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        complete_methods(ctx, &future_output, &traits_in_scope, |func| {
 | 
					        complete_methods(ctx, &future_output, &traits_in_scope, |func| {
 | 
				
			||||||
            acc.add_method(ctx, &dot_access, func, Some(SmolStr::new_static("await")), None)
 | 
					            acc.add_method(ctx, &dot_access, func, Some(await_str.clone()), None)
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,20 +82,23 @@ pub(crate) fn complete_dot(
 | 
				
			||||||
        acc.add_method(ctx, dot_access, func, None, None)
 | 
					        acc.add_method(ctx, dot_access, func, None, None)
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // FIXME:
 | 
				
			||||||
    // Checking for the existence of `iter()` is complicated in our setup, because we need to substitute
 | 
					    // Checking for the existence of `iter()` is complicated in our setup, because we need to substitute
 | 
				
			||||||
    // its return type, so we instead check for `<&Self as IntoIterator>::IntoIter`.
 | 
					    // its return type, so we instead check for `<&Self as IntoIterator>::IntoIter`.
 | 
				
			||||||
 | 
					    // Does <&receiver_ty as IntoIterator>::IntoIter` exist? Assume `iter` is valid
 | 
				
			||||||
    let iter = receiver_ty
 | 
					    let iter = receiver_ty
 | 
				
			||||||
        .strip_references()
 | 
					        .strip_references()
 | 
				
			||||||
        .add_reference(hir::Mutability::Shared)
 | 
					        .add_reference(hir::Mutability::Shared)
 | 
				
			||||||
        .into_iterator_iter(ctx.db)
 | 
					        .into_iterator_iter(ctx.db)
 | 
				
			||||||
        .map(|ty| (ty, SmolStr::new_static("iter()")))
 | 
					        .map(|ty| (ty, SmolStr::new_static("iter()")));
 | 
				
			||||||
        .or_else(|| {
 | 
					    // Does <receiver_ty as IntoIterator>::IntoIter` exist?
 | 
				
			||||||
            receiver_ty
 | 
					    let into_iter = || {
 | 
				
			||||||
                .clone()
 | 
					        receiver_ty
 | 
				
			||||||
                .into_iterator_iter(ctx.db)
 | 
					            .clone()
 | 
				
			||||||
                .map(|ty| (ty, SmolStr::new_static("into_iter()")))
 | 
					            .into_iterator_iter(ctx.db)
 | 
				
			||||||
        });
 | 
					            .map(|ty| (ty, SmolStr::new_static("into_iter()")))
 | 
				
			||||||
    if let Some((iter, iter_sym)) = iter {
 | 
					    };
 | 
				
			||||||
 | 
					    if let Some((iter, iter_sym)) = iter.or_else(into_iter) {
 | 
				
			||||||
        // Skip iterators, e.g. complete `.iter().filter_map()`.
 | 
					        // Skip iterators, e.g. complete `.iter().filter_map()`.
 | 
				
			||||||
        let dot_access_kind = match &dot_access.kind {
 | 
					        let dot_access_kind = match &dot_access.kind {
 | 
				
			||||||
            DotAccessKind::Field { receiver_is_ambiguous_float_literal: _ } => {
 | 
					            DotAccessKind::Field { receiver_is_ambiguous_float_literal: _ } => {
 | 
				
			||||||
| 
						 | 
					@ -1437,5 +1437,33 @@ async fn bar() {
 | 
				
			||||||
    me into_future() (use core::future::IntoFuture) fn(self) -> <Self as IntoFuture>::IntoFuture
 | 
					    me into_future() (use core::future::IntoFuture) fn(self) -> <Self as IntoFuture>::IntoFuture
 | 
				
			||||||
"#]],
 | 
					"#]],
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					        check_edit(
 | 
				
			||||||
 | 
					            "foo",
 | 
				
			||||||
 | 
					            r#"
 | 
				
			||||||
 | 
					//- minicore: future
 | 
				
			||||||
 | 
					struct Foo;
 | 
				
			||||||
 | 
					impl Foo {
 | 
				
			||||||
 | 
					    fn foo(self) {}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async fn foo() -> Foo { Foo }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async fn bar() {
 | 
				
			||||||
 | 
					    foo().$0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					"#,
 | 
				
			||||||
 | 
					            r#"
 | 
				
			||||||
 | 
					struct Foo;
 | 
				
			||||||
 | 
					impl Foo {
 | 
				
			||||||
 | 
					    fn foo(self) {}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async fn foo() -> Foo { Foo }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async fn bar() {
 | 
				
			||||||
 | 
					    foo().await.foo();$0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					"#,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -220,7 +220,11 @@ fn render_completion_list(completions: Vec<CompletionItem>) -> String {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					pub(crate) fn check_edit(
 | 
				
			||||||
 | 
					    what: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    check_edit_with_config(TEST_CONFIG, what, ra_fixture_before, ra_fixture_after)
 | 
					    check_edit_with_config(TEST_CONFIG, what, ra_fixture_before, ra_fixture_after)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1244,8 +1244,8 @@ use ::ext::foo::Foo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn check_with_config(
 | 
					fn check_with_config(
 | 
				
			||||||
    path: &str,
 | 
					    path: &str,
 | 
				
			||||||
    ra_fixture_before: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
    ra_fixture_after: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
    config: &InsertUseConfig,
 | 
					    config: &InsertUseConfig,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    let (db, file_id, pos) = if ra_fixture_before.contains(CURSOR_MARKER) {
 | 
					    let (db, file_id, pos) = if ra_fixture_before.contains(CURSOR_MARKER) {
 | 
				
			||||||
| 
						 | 
					@ -1277,8 +1277,8 @@ fn check_with_config(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn check(
 | 
					fn check(
 | 
				
			||||||
    path: &str,
 | 
					    path: &str,
 | 
				
			||||||
    ra_fixture_before: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
    ra_fixture_after: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
    granularity: ImportGranularity,
 | 
					    granularity: ImportGranularity,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    check_with_config(
 | 
					    check_with_config(
 | 
				
			||||||
| 
						 | 
					@ -1295,19 +1295,35 @@ fn check(
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn check_crate(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					fn check_crate(
 | 
				
			||||||
 | 
					    path: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Crate)
 | 
					    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Crate)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn check_module(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					fn check_module(
 | 
				
			||||||
 | 
					    path: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Module)
 | 
					    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Module)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					fn check_none(
 | 
				
			||||||
 | 
					    path: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Item)
 | 
					    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Item)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn check_one(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					fn check_one(
 | 
				
			||||||
 | 
					    path: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::One)
 | 
					    check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::One)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,10 @@ use crate::{DiagnosticsConfig, ExprFillDefaultMode, Severity};
 | 
				
			||||||
///  * the first diagnostic fix trigger range touches the input cursor position
 | 
					///  * the first diagnostic fix trigger range touches the input cursor position
 | 
				
			||||||
///  * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
 | 
					///  * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					pub(crate) fn check_fix(
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    check_nth_fix(0, ra_fixture_before, ra_fixture_after);
 | 
					    check_nth_fix(0, ra_fixture_before, ra_fixture_after);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
/// Takes a multi-file input fixture with annotated cursor positions,
 | 
					/// Takes a multi-file input fixture with annotated cursor positions,
 | 
				
			||||||
| 
						 | 
					@ -26,14 +29,21 @@ pub(crate) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
				
			||||||
///  * a diagnostic is produced
 | 
					///  * a diagnostic is produced
 | 
				
			||||||
///  * every diagnostic fixes trigger range touches the input cursor position
 | 
					///  * every diagnostic fixes trigger range touches the input cursor position
 | 
				
			||||||
///  * that the contents of the file containing the cursor match `after` after each diagnostic fix is applied
 | 
					///  * that the contents of the file containing the cursor match `after` after each diagnostic fix is applied
 | 
				
			||||||
pub(crate) fn check_fixes(ra_fixture_before: &str, ra_fixtures_after: Vec<&str>) {
 | 
					pub(crate) fn check_fixes(
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    ra_fixtures_after: Vec<&str>,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    for (i, ra_fixture_after) in ra_fixtures_after.iter().enumerate() {
 | 
					    for (i, ra_fixture_after) in ra_fixtures_after.iter().enumerate() {
 | 
				
			||||||
        check_nth_fix(i, ra_fixture_before, ra_fixture_after)
 | 
					        check_nth_fix(i, ra_fixture_before, ra_fixture_after)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					fn check_nth_fix(
 | 
				
			||||||
 | 
					    nth: usize,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    let mut config = DiagnosticsConfig::test_sample();
 | 
					    let mut config = DiagnosticsConfig::test_sample();
 | 
				
			||||||
    config.expr_fill_default = ExprFillDefaultMode::Default;
 | 
					    config.expr_fill_default = ExprFillDefaultMode::Default;
 | 
				
			||||||
    check_nth_fix_with_config(config, nth, ra_fixture_before, ra_fixture_after)
 | 
					    check_nth_fix_with_config(config, nth, ra_fixture_before, ra_fixture_after)
 | 
				
			||||||
| 
						 | 
					@ -41,8 +51,8 @@ fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_fix_with_disabled(
 | 
					pub(crate) fn check_fix_with_disabled(
 | 
				
			||||||
    ra_fixture_before: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
    ra_fixture_after: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
    disabled: impl Iterator<Item = String>,
 | 
					    disabled: impl Iterator<Item = String>,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    let mut config = DiagnosticsConfig::test_sample();
 | 
					    let mut config = DiagnosticsConfig::test_sample();
 | 
				
			||||||
| 
						 | 
					@ -55,8 +65,8 @@ pub(crate) fn check_fix_with_disabled(
 | 
				
			||||||
fn check_nth_fix_with_config(
 | 
					fn check_nth_fix_with_config(
 | 
				
			||||||
    config: DiagnosticsConfig,
 | 
					    config: DiagnosticsConfig,
 | 
				
			||||||
    nth: usize,
 | 
					    nth: usize,
 | 
				
			||||||
    ra_fixture_before: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
    ra_fixture_after: &str,
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
    let after = trim_indent(ra_fixture_after);
 | 
					    let after = trim_indent(ra_fixture_after);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,14 +105,20 @@ fn check_nth_fix_with_config(
 | 
				
			||||||
    assert_eq_text!(&after, &actual);
 | 
					    assert_eq_text!(&after, &actual);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub(crate) fn check_fixes_unordered(ra_fixture_before: &str, ra_fixtures_after: Vec<&str>) {
 | 
					pub(crate) fn check_fixes_unordered(
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    ra_fixtures_after: Vec<&str>,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    for ra_fixture_after in ra_fixtures_after.iter() {
 | 
					    for ra_fixture_after in ra_fixtures_after.iter() {
 | 
				
			||||||
        check_has_fix(ra_fixture_before, ra_fixture_after)
 | 
					        check_has_fix(ra_fixture_before, ra_fixture_after)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_has_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					pub(crate) fn check_has_fix(
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    let after = trim_indent(ra_fixture_after);
 | 
					    let after = trim_indent(ra_fixture_after);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
 | 
					    let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
 | 
				
			||||||
| 
						 | 
					@ -145,7 +161,10 @@ pub(crate) fn check_has_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[track_caller]
 | 
					#[track_caller]
 | 
				
			||||||
pub(crate) fn check_has_single_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					pub(crate) fn check_has_single_fix(
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					    #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
    let after = trim_indent(ra_fixture_after);
 | 
					    let after = trim_indent(ra_fixture_after);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
 | 
					    let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -307,7 +307,10 @@ mod tests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn check_join_lines(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					    fn check_join_lines(
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
        let config = JoinLinesConfig {
 | 
					        let config = JoinLinesConfig {
 | 
				
			||||||
            join_else_if: true,
 | 
					            join_else_if: true,
 | 
				
			||||||
            remove_trailing_comma: true,
 | 
					            remove_trailing_comma: true,
 | 
				
			||||||
| 
						 | 
					@ -333,7 +336,10 @@ mod tests {
 | 
				
			||||||
        assert_eq_text!(ra_fixture_after, &actual);
 | 
					        assert_eq_text!(ra_fixture_after, &actual);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn check_join_lines_sel(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					    fn check_join_lines_sel(
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
        let config = JoinLinesConfig {
 | 
					        let config = JoinLinesConfig {
 | 
				
			||||||
            join_else_if: true,
 | 
					            join_else_if: true,
 | 
				
			||||||
            remove_trailing_comma: true,
 | 
					            remove_trailing_comma: true,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -456,7 +456,11 @@ mod tests {
 | 
				
			||||||
    use super::{RangeInfo, RenameError};
 | 
					    use super::{RangeInfo, RenameError};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[track_caller]
 | 
					    #[track_caller]
 | 
				
			||||||
    fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					    fn check(
 | 
				
			||||||
 | 
					        new_name: &str,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
        let ra_fixture_after = &trim_indent(ra_fixture_after);
 | 
					        let ra_fixture_after = &trim_indent(ra_fixture_after);
 | 
				
			||||||
        let (analysis, position) = fixture::position(ra_fixture_before);
 | 
					        let (analysis, position) = fixture::position(ra_fixture_before);
 | 
				
			||||||
        if !ra_fixture_after.starts_with("error: ") {
 | 
					        if !ra_fixture_after.starts_with("error: ") {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -436,14 +436,18 @@ mod tests {
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn type_char(char_typed: char, ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					    fn type_char(
 | 
				
			||||||
 | 
					        char_typed: char,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
        let actual = do_type_char(char_typed, ra_fixture_before)
 | 
					        let actual = do_type_char(char_typed, ra_fixture_before)
 | 
				
			||||||
            .unwrap_or_else(|| panic!("typing `{char_typed}` did nothing"));
 | 
					            .unwrap_or_else(|| panic!("typing `{char_typed}` did nothing"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        assert_eq_text!(ra_fixture_after, &actual);
 | 
					        assert_eq_text!(ra_fixture_after, &actual);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn type_char_noop(char_typed: char, ra_fixture_before: &str) {
 | 
					    fn type_char_noop(char_typed: char, #[rust_analyzer::rust_fixture] ra_fixture_before: &str) {
 | 
				
			||||||
        let file_change = do_type_char(char_typed, ra_fixture_before);
 | 
					        let file_change = do_type_char(char_typed, ra_fixture_before);
 | 
				
			||||||
        assert_eq!(file_change, None)
 | 
					        assert_eq!(file_change, None)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -208,7 +208,10 @@ mod tests {
 | 
				
			||||||
        Some(actual)
 | 
					        Some(actual)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn do_check(ra_fixture_before: &str, ra_fixture_after: &str) {
 | 
					    fn do_check(
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_before: &str,
 | 
				
			||||||
 | 
					        #[rust_analyzer::rust_fixture] ra_fixture_after: &str,
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
        let ra_fixture_after = &trim_indent(ra_fixture_after);
 | 
					        let ra_fixture_after = &trim_indent(ra_fixture_after);
 | 
				
			||||||
        let actual = apply_on_enter(ra_fixture_before).unwrap();
 | 
					        let actual = apply_on_enter(ra_fixture_before).unwrap();
 | 
				
			||||||
        assert_eq_text!(ra_fixture_after, &actual);
 | 
					        assert_eq_text!(ra_fixture_after, &actual);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue