@@ -829,283 +829,6 @@ fn main() {
829829 . assert_run_success ( ) ;
830830 }
831831
832- mod warnings {
833- use crate :: warning:: WarningName ;
834- use crate :: TemplateProgram ;
835-
836- fn warning_names ( prog_text : & str ) -> Vec < WarningName > {
837- TemplateProgram :: new ( prog_text)
838- . expect ( "Program should compile" )
839- . warnings ( )
840- . iter ( )
841- . map ( |w| w. canonical_name . clone ( ) )
842- . collect ( )
843- }
844-
845- #[ test]
846- fn unused_variable_warns ( ) {
847- let prog = r#"fn main() {
848- let (carry, sum): (bool, u8) = jet::add_8(2, 3);
849- assert!(jet::eq_8(sum, 5))
850- }"# ;
851- let names = warning_names ( prog) ;
852- assert_eq ! ( names. len( ) , 1 ) ;
853- assert ! (
854- matches!( & names[ 0 ] , WarningName :: UnusedVariable ( id) if id. as_inner( ) == "carry" ) ,
855- "Expected VariableUnused(carry), got: {:?}" ,
856- names,
857- ) ;
858- }
859-
860- #[ test]
861- fn used_variable_no_warning ( ) {
862- // Both carry and sum are used in the tuple expression.
863- let prog = r#"fn main() {
864- let (carry, sum): (bool, u8) = jet::add_8(2, 3);
865- let _: (bool, u8) = (carry, sum);
866- }"# ;
867- assert ! ( warning_names( prog) . is_empty( ) ) ;
868- }
869-
870- #[ test]
871- fn underscore_prefix_silences_warning ( ) {
872- let prog = r#"fn main() {
873- let (_carry, sum): (bool, u8) = jet::add_8(2, 3);
874- assert!(jet::eq_8(sum, 5))
875- }"# ;
876- assert ! ( warning_names( prog) . is_empty( ) ) ;
877- }
878-
879- #[ test]
880- fn ignore_pattern_no_warning ( ) {
881- let prog = r#"fn main() {
882- let (_, sum): (bool, u8) = jet::add_8(2, 3);
883- assert!(jet::eq_8(sum, 5))
884- }"# ;
885- assert ! ( warning_names( prog) . is_empty( ) ) ;
886- }
887-
888- #[ test]
889- fn multiple_unused_variables_warn ( ) {
890- let prog = r#"fn main() {
891- let x: u8 = 1;
892- let y: u8 = 2;
893- assert!(jet::eq_8(0, 0))
894- }"# ;
895- let names = warning_names ( prog) ;
896- let unused: Vec < & str > = names
897- . iter ( )
898- . map ( |w| match w {
899- WarningName :: UnusedVariable ( id) => id. as_inner ( ) ,
900- } )
901- . collect ( ) ;
902- assert_eq ! (
903- unused. len( ) ,
904- 2 ,
905- "Expected 2 unused-variable warnings, got: {unused:?}"
906- ) ;
907- // Warnings are emitted in source order (sorted by span start).
908- assert_eq ! ( unused, [ "x" , "y" ] ) ;
909- }
910-
911- #[ test]
912- fn variable_used_in_nested_block_no_warning ( ) {
913- let prog = r#"fn main() {
914- let x: u8 = 1;
915- let y: u8 = {
916- x
917- };
918- assert!(jet::eq_8(y, 1))
919- }"# ;
920- assert ! ( warning_names( prog) . is_empty( ) ) ;
921- }
922-
923- #[ test]
924- fn deny_unused_variable_is_error ( ) {
925- let prog = r#"fn main() {
926- let (carry, sum): (bool, u8) = jet::add_8(2, 3);
927- assert!(jet::eq_8(sum, 5))
928- }"# ;
929- assert ! (
930- TemplateProgram :: new( prog) . unwrap( ) . deny_warnings( ) . is_err( ) ,
931- "Expected compilation to fail with --deny-warnings" ,
932- ) ;
933- }
934-
935- #[ test]
936- fn unused_match_arm_binding_warns ( ) {
937- let prog = r#"fn main() {
938- let val: Either<u32, bool> = Left(42);
939- match val {
940- Left(x: u32) => assert!(jet::eq_32(0, 0)),
941- Right(_: bool) => assert!(jet::eq_32(0, 0)),
942- }
943- }"# ;
944- let names = warning_names ( prog) ;
945- assert_eq ! ( names. len( ) , 1 ) ;
946- assert ! (
947- matches!( & names[ 0 ] , WarningName :: UnusedVariable ( id) if id. as_inner( ) == "x" ) ,
948- "Expected VariableUnused(x), got: {:?}" ,
949- names,
950- ) ;
951- }
952-
953- #[ test]
954- fn used_match_arm_binding_no_warning ( ) {
955- let prog = r#"fn main() {
956- let val: Either<u32, bool> = Left(42);
957- match val {
958- Left(x: u32) => assert!(jet::eq_32(x, 42)),
959- Right(_: bool) => assert!(jet::eq_32(0, 0)),
960- }
961- }"# ;
962- assert ! ( warning_names( prog) . is_empty( ) ) ;
963- }
964-
965- #[ test]
966- fn underscore_prefix_silences_match_arm_warning ( ) {
967- let prog = r#"fn main() {
968- let val: Either<u32, bool> = Left(42);
969- match val {
970- Left(_x: u32) => assert!(jet::eq_32(0, 0)),
971- Right(_: bool) => assert!(jet::eq_32(0, 0)),
972- }
973- }"# ;
974- assert ! ( warning_names( prog) . is_empty( ) ) ;
975- }
976-
977- #[ test]
978- fn unused_function_param_warns ( ) {
979- let prog = r#"fn always_zero(x: u32) -> u32 {
980- 0
981- }
982-
983- fn main() {
984- assert!(jet::eq_32(always_zero(42), 0))
985- }"# ;
986- let names = warning_names ( prog) ;
987- assert_eq ! ( names. len( ) , 1 ) ;
988- assert ! (
989- matches!( & names[ 0 ] , WarningName :: UnusedVariable ( id) if id. as_inner( ) == "x" ) ,
990- "Expected VariableUnused(x), got: {:?}" ,
991- names,
992- ) ;
993- }
994-
995- #[ test]
996- fn used_function_param_no_warning ( ) {
997- let prog = r#"fn identity(x: u32) -> u32 {
998- x
999- }
1000-
1001- fn main() {
1002- assert!(jet::eq_32(identity(42), 42))
1003- }"# ;
1004- assert ! ( warning_names( prog) . is_empty( ) ) ;
1005- }
1006-
1007- #[ test]
1008- fn shadowed_outer_variable_unused_warns ( ) {
1009- // Outer `x` is never referenced; inner `x` shadows it and is used.
1010- // Only the outer binding should warn.
1011- let prog = r#"fn main() {
1012- let x: u8 = 1;
1013- let y: u8 = {
1014- let x: u8 = 2;
1015- x
1016- };
1017- assert!(jet::eq_8(y, 2))
1018- }"# ;
1019- let names = warning_names ( prog) ;
1020- assert_eq ! (
1021- names. len( ) ,
1022- 1 ,
1023- "Expected exactly one warning (outer x), got: {names:?}" ,
1024- ) ;
1025- assert ! (
1026- matches!( & names[ 0 ] , WarningName :: UnusedVariable ( id) if id. as_inner( ) == "x" ) ,
1027- "Expected UnusedVariable(x) for the outer binding, got: {:?}" ,
1028- names,
1029- ) ;
1030- }
1031-
1032- #[ test]
1033- fn shadowed_inner_variable_unused_warns ( ) {
1034- // Outer `x` is used as the RHS of the inner binding.
1035- // Inner `x` is never referenced after being bound, so it should warn.
1036- let prog = r#"fn main() {
1037- let x: u8 = 1;
1038- let y: u8 = {
1039- let x: u8 = x;
1040- 0
1041- };
1042- assert!(jet::eq_8(y, 0))
1043- }"# ;
1044- let names = warning_names ( prog) ;
1045- assert_eq ! (
1046- names. len( ) ,
1047- 1 ,
1048- "Expected exactly one warning (inner x), got: {names:?}" ,
1049- ) ;
1050- assert ! (
1051- matches!( & names[ 0 ] , WarningName :: UnusedVariable ( id) if id. as_inner( ) == "x" ) ,
1052- "Expected UnusedVariable(x) for the inner binding, got: {:?}" ,
1053- names,
1054- ) ;
1055- }
1056-
1057- #[ test]
1058- fn outer_variable_used_after_inner_scope_no_warning ( ) {
1059- // `x` is bound in the outer scope, referenced after an inner block
1060- // that binds a different name. Neither binding should warn.
1061- let prog = r#"fn main() {
1062- let x: u8 = 1;
1063- let y: u8 = {
1064- let z: u8 = 2;
1065- z
1066- };
1067- let (_, sum): (bool, u8) = jet::add_8(x, y);
1068- assert!(jet::eq_8(sum, 3))
1069- }"# ;
1070- assert ! (
1071- warning_names( prog) . is_empty( ) ,
1072- "Expected no warnings when all variables are used" ,
1073- ) ;
1074- }
1075-
1076- #[ test]
1077- fn deny_warning_by_category_is_error ( ) {
1078- use crate :: WarnCategory ;
1079- let prog = r#"fn main() {
1080- let (carry, sum): (bool, u8) = jet::add_8(2, 3);
1081- assert!(jet::eq_8(sum, 5))
1082- }"# ;
1083- assert ! (
1084- TemplateProgram :: new( prog)
1085- . unwrap( )
1086- . deny_warning( WarnCategory :: UnusedVariable )
1087- . is_err( ) ,
1088- "deny_warning(UnusedVariable) should fail when there is an unused variable" ,
1089- ) ;
1090- }
1091-
1092- #[ test]
1093- fn allow_warning_by_category_suppresses_it ( ) {
1094- use crate :: WarnCategory ;
1095- let prog = r#"fn main() {
1096- let (carry, sum): (bool, u8) = jet::add_8(2, 3);
1097- assert!(jet::eq_8(sum, 5))
1098- }"# ;
1099- let template = TemplateProgram :: new ( prog)
1100- . unwrap ( )
1101- . allow_warning ( WarnCategory :: UnusedVariable ) ;
1102- assert ! (
1103- template. warnings( ) . is_empty( ) ,
1104- "allow_warning(UnusedVariable) should remove the warning" ,
1105- ) ;
1106- }
1107- }
1108-
1109832 #[ cfg( feature = "serde" ) ]
1110833 mod regression {
1111834 use super :: TestCase ;
0 commit comments