From bed115d6e1a634d79e175e543a7936cd03200ebc Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sun, 3 May 2020 17:56:45 +0200 Subject: add support of cfg attributes on enum variants #4279 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_hir_ty/src/tests.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'crates/ra_hir_ty/src/tests.rs') diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 588d81282..d60732e19 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -360,6 +360,33 @@ fn no_such_field_with_feature_flag_diagnostics() { assert_snapshot!(diagnostics, @r###""###); } +#[test] +fn no_such_field_enum_with_feature_flag_diagnostics() { + let diagnostics = TestDB::with_files( + r#" + //- /lib.rs crate:foo cfg:feature=foo + enum Foo { + #[cfg(not(feature = "foo"))] + Buz, + #[cfg(feature = "foo")] + Bar, + Baz + } + + fn test_fn(f: Foo) { + match f { + Foo::Bar => {}, + Foo::Baz => {}, + } + } + "#, + ) + .diagnostics() + .0; + + assert_snapshot!(diagnostics, @r###""###); +} + #[test] fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() { let diagnostics = TestDB::with_files( -- cgit v1.2.3 From fe93675e8ac2b55d051156151489dbe0496efec3 Mon Sep 17 00:00:00 2001 From: Timo Freiberg Date: Sat, 25 Apr 2020 16:57:59 +0200 Subject: New HirDisplay method for displaying sourcecode --- crates/ra_hir_ty/src/tests.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/tests.rs') diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index d60732e19..623d00010 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -6,6 +6,7 @@ mod patterns; mod traits; mod method_resolution; mod macros; +mod display_source_code; use std::sync::Arc; @@ -16,7 +17,7 @@ use hir_def::{ item_scope::ItemScope, keys, nameres::CrateDefMap, - AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, + AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, ModuleId, }; use hir_expand::{db::AstDatabase, InFile}; use insta::assert_snapshot; @@ -37,6 +38,18 @@ use crate::{ // update the snapshots. fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { + type_at_pos_displayed(db, pos, |ty, _| ty.display(db).to_string()) +} + +fn displayed_source_at_pos(db: &TestDB, pos: FilePosition) -> String { + type_at_pos_displayed(db, pos, |ty, module_id| ty.display_source_code(db, module_id).unwrap()) +} + +fn type_at_pos_displayed( + db: &TestDB, + pos: FilePosition, + display_fn: impl FnOnce(&Ty, ModuleId) -> String, +) -> String { let file = db.parse(pos.file_id).ok().unwrap(); let expr = algo::find_node_at_offset::(file.syntax(), pos.offset).unwrap(); let fn_def = expr.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); @@ -49,7 +62,7 @@ fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { if let Some(expr_id) = source_map.node_expr(InFile::new(pos.file_id.into(), &expr)) { let infer = db.infer(func.into()); let ty = &infer[expr_id]; - return ty.display(db).to_string(); + return display_fn(ty, module); } panic!("Can't find expression") } -- cgit v1.2.3 From d0129c4ddba3b72e7b26e94e9c25546d37dbf166 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 8 May 2020 19:48:03 +0200 Subject: Add diagnostic for break outside of loop --- crates/ra_hir_ty/src/tests.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'crates/ra_hir_ty/src/tests.rs') diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index d60732e19..5af88b368 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -518,3 +518,21 @@ fn missing_record_pat_field_no_diagnostic_if_not_exhaustive() { assert_snapshot!(diagnostics, @""); } + +#[test] +fn break_outside_of_loop() { + let diagnostics = TestDB::with_files( + r" + //- /lib.rs + fn foo() { + break; + } + ", + ) + .diagnostics() + .0; + + assert_snapshot!(diagnostics, @r###""break": break outside of loop + "### + ); +} -- cgit v1.2.3