This suite of tests has two sections: compile/*.rs and compile/torture/*.rs.
The first section is comprised entirely of dg-compile tests, containing a
mixture of dg-warning and dg-error annotations and some with no annotations,
ensuring the creation of resulting asm output. The second section is the same,
but has tests which are ran with the full torture options, for coverage of test
cases that may have an issue with a specific optimization level.
gcc/testsuite/
* rust/compile/abi-options1.rs: New.
* rust/compile/array3.rs: New.
* rust/compile/array_empty_list.rs: New.
* rust/compile/arrays1.rs: New.
* rust/compile/arrays2.rs: New.
* rust/compile/attr-mismatch-crate-name.rs: New.
* rust/compile/attr_cold.rs: New.
* rust/compile/attr_deprecated.rs: New.
* rust/compile/attr_deprecated_2.rs: New.
* rust/compile/bad-crate-name.rs: New.
* rust/compile/bad=file-name.rs: New.
* rust/compile/bad_as_bool_char.rs: New.
* rust/compile/bad_file_name.txt.rs: New.
* rust/compile/bad_inner_doc.rs: New.
* rust/compile/bad_pub_enumitems.rs: New.
* rust/compile/bad_stmt_enums.rs: New.
* rust/compile/bad_toplevel_enums.rs: New.
* rust/compile/bad_tuple_index.rs: New.
* rust/compile/bad_type1.rs: New.
* rust/compile/bad_type2.rs: New.
* rust/compile/break1.rs: New.
* rust/compile/break2.rs: New.
* rust/compile/builtin_macro_compile_error.rs: New.
* rust/compile/builtin_macro_concat.rs: New.
* rust/compile/builtin_macro_env.rs: New.
* rust/compile/builtin_macro_include_bytes.rs: New.
* rust/compile/builtin_macro_include_str.rs: New.
* rust/compile/builtin_macro_not_found.rs: New.
* rust/compile/bytecharstring.rs: New.
* rust/compile/canonical_paths1.rs: New.
* rust/compile/cast1.rs: New.
* rust/compile/cfg1.rs: New.
* rust/compile/cfg2.rs: New.
* rust/compile/cfg3.rs: New.
* rust/compile/cfg4.rs: New.
* rust/compile/cfg5.rs: New.
* rust/compile/compile.exp: New.
* rust/compile/complex-path1.rs: New.
* rust/compile/const-issue1440.rs: New.
* rust/compile/const1.rs: New.
* rust/compile/const2.rs: New.
* rust/compile/const3.rs: New.
* rust/compile/const_generics_1.rs: New.
* rust/compile/const_generics_2.rs: New.
* rust/compile/const_generics_3.rs: New.
* rust/compile/const_generics_4.rs: New.
* rust/compile/const_generics_5.rs: New.
* rust/compile/const_generics_6.rs: New.
* rust/compile/continue1.rs: New.
* rust/compile/deadcode_err1.rs: New.
* rust/compile/deadcode_err2.rs: New.
* rust/compile/debug-diagnostics-default.rs: New.
* rust/compile/debug-diagnostics-off.rs: New.
* rust/compile/debug-diagnostics-on.rs: New.
* rust/compile/doc_isolated_cr_block_comment.rs: New.
* rust/compile/doc_isolated_cr_inner_block_comment.rs: New.
* rust/compile/doc_isolated_cr_inner_line_comment.rs: New.
* rust/compile/doc_isolated_cr_line_comment.rs: New.
* rust/compile/dup_fields.rs: New.
* rust/compile/empty_comment_before_match.rs: New.
* rust/compile/expected_type_args2.rs: New.
* rust/compile/expected_type_args3.rs: New.
* rust/compile/func1.rs: New.
* rust/compile/func2.rs: New.
* rust/compile/func3.rs: New.
* rust/compile/func4.rs: New.
* rust/compile/func5.rs: New.
* rust/compile/generic-default1.rs: New.
* rust/compile/generics1.rs: New.
* rust/compile/generics10.rs: New.
* rust/compile/generics11.rs: New.
* rust/compile/generics12.rs: New.
* rust/compile/generics13.rs: New.
* rust/compile/generics2.rs: New.
* rust/compile/generics3.rs: New.
* rust/compile/generics4.rs: New.
* rust/compile/generics5.rs: New.
* rust/compile/generics6.rs: New.
* rust/compile/generics7.rs: New.
* rust/compile/generics8.rs: New.
* rust/compile/generics9.rs: New.
* rust/compile/implicit_returns_err1.rs: New.
* rust/compile/implicit_returns_err2.rs: New.
* rust/compile/implicit_returns_err3.rs: New.
* rust/compile/implicit_returns_err4.rs: New.
* rust/compile/infer-crate-name.rs: New.
* rust/compile/inline_1.rs: New.
* rust/compile/inline_2.rs: New.
* rust/compile/issue-1005.rs: New.
* rust/compile/issue-1019.rs: New.
* rust/compile/issue-1023.rs: New.
* rust/compile/issue-1031.rs: New.
* rust/compile/issue-1034.rs: New.
* rust/compile/issue-1089.rs: New.
* rust/compile/issue-1128.rs: New.
* rust/compile/issue-1129-1.rs: New.
* rust/compile/issue-1129-2.rs: New.
* rust/compile/issue-1130.rs: New.
* rust/compile/issue-1131.rs: New.
* rust/compile/issue-1152.rs: New.
* rust/compile/issue-1165.rs: New.
* rust/compile/issue-1173.rs: New.
* rust/compile/issue-1226.rs: New.
* rust/compile/issue-1234.rs: New.
* rust/compile/issue-1235.rs: New.
* rust/compile/issue-1237.rs: New.
* rust/compile/issue-1251.rs: New.
* rust/compile/issue-1271.rs: New.
* rust/compile/issue-1289.rs: New.
* rust/compile/issue-1323-1.rs: New.
* rust/compile/issue-1323-2.rs: New.
* rust/compile/issue-1383.rs: New.
* rust/compile/issue-1393.rs: New.
* rust/compile/issue-1447.rs: New.
* rust/compile/issue-407-2.rs: New.
* rust/compile/issue-407.rs: New.
* rust/compile/issue-557.rs: New.
* rust/compile/issue-635-1.rs: New.
* rust/compile/issue-635-2.rs: New.
* rust/compile/lookup_err1.rs: New.
* rust/compile/macro-issue1053-2.rs: New.
* rust/compile/macro-issue1053.rs: New.
* rust/compile/macro-issue1224.rs: New.
* rust/compile/macro-issue1233.rs: New.
* rust/compile/macro-issue1395-2.rs: New.
* rust/compile/macro-issue1395.rs: New.
* rust/compile/macro-issue1400-2.rs: New.
* rust/compile/macro-issue1400.rs: New.
* rust/compile/macro1.rs: New.
* rust/compile/macro10.rs: New.
* rust/compile/macro11.rs: New.
* rust/compile/macro12.rs: New.
* rust/compile/macro13.rs: New.
* rust/compile/macro14.rs: New.
* rust/compile/macro15.rs: New.
* rust/compile/macro16.rs: New.
* rust/compile/macro17.rs: New.
* rust/compile/macro18.rs: New.
* rust/compile/macro19.rs: New.
* rust/compile/macro2.rs: New.
* rust/compile/macro20.rs: New.
* rust/compile/macro21.rs: New.
* rust/compile/macro22.rs: New.
* rust/compile/macro23.rs: New.
* rust/compile/macro25.rs: New.
* rust/compile/macro26.rs: New.
* rust/compile/macro27.rs: New.
* rust/compile/macro28.rs: New.
* rust/compile/macro29.rs: New.
* rust/compile/macro3.rs: New.
* rust/compile/macro30.rs: New.
* rust/compile/macro31.rs: New.
* rust/compile/macro32.rs: New.
* rust/compile/macro33.rs: New.
* rust/compile/macro34.rs: New.
* rust/compile/macro35.rs: New.
* rust/compile/macro36.rs: New.
* rust/compile/macro37.rs: New.
* rust/compile/macro38.rs: New.
* rust/compile/macro39.rs: New.
* rust/compile/macro4.rs: New.
* rust/compile/macro40.rs: New.
* rust/compile/macro41.rs: New.
* rust/compile/macro42.rs: New.
* rust/compile/macro5.rs: New.
* rust/compile/macro6.rs: New.
* rust/compile/macro7.rs: New.
* rust/compile/macro8.rs: New.
* rust/compile/macro9.rs: New.
* rust/compile/macro_return.rs: New.
* rust/compile/match1.rs: New.
* rust/compile/match2.rs: New.
* rust/compile/match3.rs: New.
* rust/compile/match4.rs: New.
* rust/compile/match5.rs: New.
* rust/compile/match6.rs: New.
* rust/compile/match7.rs: New.
* rust/compile/method1.rs: New.
* rust/compile/method2.rs: New.
* rust/compile/mismatch-crate-name.rs: New.
* rust/compile/missing_middle/both_path.rs: New.
* rust/compile/missing_middle/explicit.not.rs: New.
* rust/compile/missing_middle/inner_path.rs: New.
* rust/compile/missing_middle/other.rs: New.
* rust/compile/missing_middle/outer_path.rs: New.
* rust/compile/missing_middle/sub/mod.rs: New.
* rust/compile/missing_return1.rs: New.
* rust/compile/mod_missing_middle.rs: New.
* rust/compile/never_type_err1.rs: New.
* rust/compile/privacy1.rs: New.
* rust/compile/privacy2.rs: New.
* rust/compile/privacy3.rs: New.
* rust/compile/privacy4.rs: New.
* rust/compile/privacy5.rs: New.
* rust/compile/privacy6.rs: New.
* rust/compile/pub_restricted_1.rs: New.
* rust/compile/pub_restricted_2.rs: New.
* rust/compile/pub_restricted_3.rs: New.
* rust/compile/raw_identifiers_bad_keywords.rs: New.
* rust/compile/raw_identifiers_underscore.rs: New.
* rust/compile/redef_error1.rs: New.
* rust/compile/redef_error2.rs: New.
* rust/compile/redef_error3.rs: New.
* rust/compile/redef_error4.rs: New.
* rust/compile/redef_error5.rs: New.
* rust/compile/redef_error6.rs: New.
* rust/compile/reference1.rs: New.
* rust/compile/self-path1.rs: New.
* rust/compile/self-path2.rs: New.
* rust/compile/shadow1.rs: New.
* rust/compile/specify-crate-name.rs: New.
* rust/compile/static_var1.rs: New.
* rust/compile/stmt_with_block_err1.rs: New.
* rust/compile/struct_align1.rs: New.
* rust/compile/struct_align2.rs: New.
* rust/compile/struct_init1.rs: New.
* rust/compile/struct_pack1.rs: New.
* rust/compile/struct_pack2.rs: New.
* rust/compile/syntax-only.rs: New.
* rust/compile/test_mod.rs: New.
* rust/compile/torture/all_doc_comment_line_blocks.rs: New.
* rust/compile/torture/all_doc_comment_line_blocks_crlf.rs: New.
* rust/compile/torture/arithmetic_expressions1.rs: New.
* rust/compile/torture/array_const_fold_1.rs: New.
* rust/compile/torture/array_const_fold_2.rs: New.
* rust/compile/torture/array_function.rs: New.
* rust/compile/torture/array_type_infer.rs: New.
* rust/compile/torture/array_zero_length.rs: New.
* rust/compile/torture/arrays1.rs: New.
* rust/compile/torture/arrays2.rs: New.
* rust/compile/torture/arrays3.rs: New.
* rust/compile/torture/arrays4.rs: New.
* rust/compile/torture/arrays5.rs: New.
* rust/compile/torture/arrays6.rs: New.
* rust/compile/torture/arrays_index1.rs: New.
* rust/compile/torture/arrays_index2.rs: New.
* rust/compile/torture/arrays_index3.rs: New.
* rust/compile/torture/as_bool_char.rs: New.
* rust/compile/torture/associated_types1.rs: New.
* rust/compile/torture/autoderef1.rs: New.
* rust/compile/torture/block_expr1.rs: New.
* rust/compile/torture/block_expr2.rs: New.
* rust/compile/torture/block_expr3.rs: New.
* rust/compile/torture/block_expr4.rs: New.
* rust/compile/torture/block_expr5.rs: New.
* rust/compile/torture/block_expr_parser_bug.rs: New.
* rust/compile/torture/bom.rs: New.
* rust/compile/torture/bom_comment.rs: New.
* rust/compile/torture/bom_shebang.rs: New.
* rust/compile/torture/bom_whitespace.rs: New.
* rust/compile/torture/bools_eq.rs: New.
* rust/compile/torture/borrow1.rs: New.
* rust/compile/torture/borrow_function.rs: New.
* rust/compile/torture/break_function.rs: New.
* rust/compile/torture/byte_char_str.rs: New.
* rust/compile/torture/byte_str.rs: New.
* rust/compile/torture/cast1.rs: New.
* rust/compile/torture/cast2.rs: New.
* rust/compile/torture/cast3.rs: New.
* rust/compile/torture/cfg_attr.rs: New.
* rust/compile/torture/char1.rs: New.
* rust/compile/torture/check-doc-attr-string.rs: New.
* rust/compile/torture/coercion1.rs: New.
* rust/compile/torture/coercion2.rs: New.
* rust/compile/torture/comparison_expr1.rs: New.
* rust/compile/torture/compile.exp: New.
* rust/compile/torture/compound_assignment_expr1.rs: New.
* rust/compile/torture/conditional.rs: New.
* rust/compile/torture/constant1.rs: New.
* rust/compile/torture/constant2.rs: New.
* rust/compile/torture/constant3.rs: New.
* rust/compile/torture/deadcode1.rs: New.
* rust/compile/torture/deadcode2.rs: New.
* rust/compile/torture/deref1.rs: New.
* rust/compile/torture/deref_function.rs: New.
* rust/compile/torture/doc_comment.rs: New.
* rust/compile/torture/enum1.rs: New.
* rust/compile/torture/extern_mod1.rs: New.
* rust/compile/torture/extern_mod2.rs: New.
* rust/compile/torture/float1.rs: New.
* rust/compile/torture/float_types.rs: New.
* rust/compile/torture/forward_decl_1.rs: New.
* rust/compile/torture/forward_decl_2.rs: New.
* rust/compile/torture/forward_decl_3-unsafe.rs: New.
* rust/compile/torture/forward_decl_3.rs: New.
* rust/compile/torture/forward_decl_4.rs: New.
* rust/compile/torture/forward_decl_5.rs: New.
* rust/compile/torture/func1.rs: New.
* rust/compile/torture/func2.rs: New.
* rust/compile/torture/function_reference1.rs: New.
* rust/compile/torture/function_reference2.rs: New.
* rust/compile/torture/function_reference3.rs: New.
* rust/compile/torture/function_reference4.rs: New.
* rust/compile/torture/generics1.rs: New.
* rust/compile/torture/generics10.rs: New.
* rust/compile/torture/generics11.rs: New.
* rust/compile/torture/generics12.rs: New.
* rust/compile/torture/generics13.rs: New.
* rust/compile/torture/generics14.rs: New.
* rust/compile/torture/generics15.rs: New.
* rust/compile/torture/generics16.rs: New.
* rust/compile/torture/generics17.rs: New.
* rust/compile/torture/generics18.rs: New.
* rust/compile/torture/generics19.rs: New.
* rust/compile/torture/generics2.rs: New.
* rust/compile/torture/generics20.rs: New.
* rust/compile/torture/generics21.rs: New.
* rust/compile/torture/generics22.rs: New.
* rust/compile/torture/generics23.rs: New.
* rust/compile/torture/generics24.rs: New.
* rust/compile/torture/generics25.rs: New.
* rust/compile/torture/generics26.rs: New.
* rust/compile/torture/generics27.rs: New.
* rust/compile/torture/generics28.rs: New.
* rust/compile/torture/generics29.rs: New.
* rust/compile/torture/generics3.rs: New.
* rust/compile/torture/generics30.rs: New.
* rust/compile/torture/generics31.rs: New.
* rust/compile/torture/generics32.rs: New.
* rust/compile/torture/generics4.rs: New.
* rust/compile/torture/generics5.rs: New.
* rust/compile/torture/generics6.rs: New.
* rust/compile/torture/generics7.rs: New.
* rust/compile/torture/generics8.rs: New.
* rust/compile/torture/generics9.rs: New.
* rust/compile/torture/grouped_expr_function.rs: New.
* rust/compile/torture/identifier-missing-impl-1.rs: New.
* rust/compile/torture/if.rs: New.
* rust/compile/torture/if_elif.rs: New.
* rust/compile/torture/if_elif_else_expr1.rs: New.
* rust/compile/torture/if_else.rs: New.
* rust/compile/torture/ifunaryexpr.rs: New.
* rust/compile/torture/impl_block1.rs: New.
* rust/compile/torture/impl_block2.rs: New.
* rust/compile/torture/impl_block3.rs: New.
* rust/compile/torture/impl_block_unused.rs: New.
* rust/compile/torture/implicit_returns1.rs: New.
* rust/compile/torture/infer_type1.rs: New.
* rust/compile/torture/inner_attributes.rs: New.
* rust/compile/torture/integer_inference_var1.rs: New.
* rust/compile/torture/integer_inference_var2.rs: New.
* rust/compile/torture/integer_inference_var3.rs: New.
* rust/compile/torture/integer_inference_var4.rs: New.
* rust/compile/torture/integer_inference_var5.rs: New.
* rust/compile/torture/integer_types.rs: New.
* rust/compile/torture/intrinsics-1.rs: New.
* rust/compile/torture/intrinsics-2.rs: New.
* rust/compile/torture/isolated_cr_block_comment.rs: New.
* rust/compile/torture/isolated_cr_line_comment.rs: New.
* rust/compile/torture/issue-1024.rs: New.
* rust/compile/torture/issue-1075.rs: New.
* rust/compile/torture/issue-1432.rs: New.
* rust/compile/torture/issue-1434.rs: New.
* rust/compile/torture/issue-368.rs: New.
* rust/compile/torture/issue-808.rs: New.
* rust/compile/torture/issue-862.rs: New.
* rust/compile/torture/issue-893-2.rs: New.
* rust/compile/torture/issue-893.rs: New.
* rust/compile/torture/lazybooleanexpr_function.rs: New.
* rust/compile/torture/lifetime1.rs: New.
* rust/compile/torture/literals1.rs: New.
* rust/compile/torture/loop1.rs: New.
* rust/compile/torture/loop2.rs: New.
* rust/compile/torture/loop3.rs: New.
* rust/compile/torture/loop4.rs: New.
* rust/compile/torture/loop5.rs: New.
* rust/compile/torture/loop6.rs: New.
* rust/compile/torture/loop7.rs: New.
* rust/compile/torture/macro-issue1403.rs: New.
* rust/compile/torture/macro-issue1426.rs: New.
* rust/compile/torture/macro_as_expr.rs: New.
* rust/compile/torture/match1.rs: New.
* rust/compile/torture/methods1.rs: New.
* rust/compile/torture/methods2.rs: New.
* rust/compile/torture/methods3.rs: New.
* rust/compile/torture/mod-nameresolve.rs: New.
* rust/compile/torture/mod1.rs: New.
* rust/compile/torture/mod2.rs: New.
* rust/compile/torture/mod3.rs: New.
* rust/compile/torture/modules/mod.rs: New.
* rust/compile/torture/modules/valid_path.rs: New.
* rust/compile/torture/must_use1.rs: New.
* rust/compile/torture/must_use2.rs: New.
* rust/compile/torture/name_resolve1.rs: New.
* rust/compile/torture/negation_function.rs: New.
* rust/compile/torture/nested_fn1.rs: New.
* rust/compile/torture/nested_fn2.rs: New.
* rust/compile/torture/nested_struct1.rs: New.
* rust/compile/torture/never_type1.rs: New.
* rust/compile/torture/not_shebang.rs: New.
* rust/compile/torture/not_shebang_block_comment.rs: New.
* rust/compile/torture/not_shebang_comment.rs: New.
* rust/compile/torture/not_shebang_multiline_comment.rs: New.
* rust/compile/torture/not_shebang_spaces.rs: New.
* rust/compile/torture/parameter_usage1.rs: New.
* rust/compile/torture/parens1.rs: New.
* rust/compile/torture/pointer1.rs: New.
* rust/compile/torture/primconsts.rs: New.
* rust/compile/torture/prims_struct_eq.rs: New.
* rust/compile/torture/range-lang-item1.rs: New.
* rust/compile/torture/raw_identifiers.rs: New.
* rust/compile/torture/raw_identifiers_keywords.rs: New.
* rust/compile/torture/recursive_fn1.rs: New.
* rust/compile/torture/return_function.rs: New.
* rust/compile/torture/scoping1.rs: New.
* rust/compile/torture/self_type1.rs: New.
* rust/compile/torture/shadow1.rs: New.
* rust/compile/torture/shadow2.rs: New.
* rust/compile/torture/shebang.rs: New.
* rust/compile/torture/shebang_plus_attr.rs: New.
* rust/compile/torture/shebang_plus_attr2.rs: New.
* rust/compile/torture/static_function.rs: New.
* rust/compile/torture/static_var1.rs: New.
* rust/compile/torture/stmt_with_block1.rs: New.
* rust/compile/torture/str1.rs: New.
* rust/compile/torture/struct_access1.rs: New.
* rust/compile/torture/struct_base_init_1.rs: New.
* rust/compile/torture/struct_decl.rs: New.
* rust/compile/torture/struct_init.rs: New.
* rust/compile/torture/struct_init_10.rs: New.
* rust/compile/torture/struct_init_11.rs: New.
* rust/compile/torture/struct_init_2.rs: New.
* rust/compile/torture/struct_init_3.rs: New.
* rust/compile/torture/struct_init_4.rs: New.
* rust/compile/torture/struct_init_5.rs: New.
* rust/compile/torture/struct_init_6.rs: New.
* rust/compile/torture/struct_init_7.rs: New.
* rust/compile/torture/struct_init_8.rs: New.
* rust/compile/torture/struct_init_9.rs: New.
* rust/compile/torture/top_attr.rs: New.
* rust/compile/torture/traits1.rs: New.
* rust/compile/torture/traits10.rs: New.
* rust/compile/torture/traits11.rs: New.
* rust/compile/torture/traits12.rs: New.
* rust/compile/torture/traits13.rs: New.
* rust/compile/torture/traits14.rs: New.
* rust/compile/torture/traits15.rs: New.
* rust/compile/torture/traits16.rs: New.
* rust/compile/torture/traits17.rs: New.
* rust/compile/torture/traits18.rs: New.
* rust/compile/torture/traits19.rs: New.
* rust/compile/torture/traits2.rs: New.
* rust/compile/torture/traits3.rs: New.
* rust/compile/torture/traits4.rs: New.
* rust/compile/torture/traits5.rs: New.
* rust/compile/torture/traits6.rs: New.
* rust/compile/torture/traits7.rs: New.
* rust/compile/torture/traits8.rs: New.
* rust/compile/torture/traits9.rs: New.
* rust/compile/torture/transmute-size-check-1.rs: New.
* rust/compile/torture/transmute1.rs: New.
* rust/compile/torture/tuple1.rs: New.
* rust/compile/torture/tuple2.rs: New.
* rust/compile/torture/tuple3.rs: New.
* rust/compile/torture/tuple_enum_variants.rs: New.
* rust/compile/torture/tuple_field_access.rs: New.
* rust/compile/torture/tuple_function.rs: New.
* rust/compile/torture/tuple_index.rs: New.
* rust/compile/torture/tuple_struct1.rs: New.
* rust/compile/torture/tuple_struct2.rs: New.
* rust/compile/torture/tuple_struct_unit.rs: New.
* rust/compile/torture/tuple_struct_unused.rs: New.
* rust/compile/torture/type-alias1.rs: New.
* rust/compile/torture/type-alias2.rs: New.
* rust/compile/torture/type_infer1.rs: New.
* rust/compile/torture/type_infer2.rs: New.
* rust/compile/torture/type_infer3.rs: New.
* rust/compile/torture/type_infer4.rs: New.
* rust/compile/torture/type_infer5.rs: New.
* rust/compile/torture/type_infer6.rs: New.
* rust/compile/torture/unary_operators.rs: New.
* rust/compile/torture/undended-string-1.rs: New.
* rust/compile/torture/undended-string-2.rs: New.
* rust/compile/torture/underscore_id.rs: New.
* rust/compile/torture/union.rs: New.
* rust/compile/torture/union_union.rs: New.
* rust/compile/torture/unit_type1.rs: New.
* rust/compile/torture/unit_type2.rs: New.
* rust/compile/torture/unit_type3.rs: New.
* rust/compile/torture/unit_type4.rs: New.
* rust/compile/torture/unit_type5.rs: New.
* rust/compile/torture/unsafe1.rs: New.
* rust/compile/torture/unsafe2.rs: New.
* rust/compile/torture/unsafe3.rs: New.
* rust/compile/torture/unsafe4.rs: New.
* rust/compile/torture/unused.rs: New.
* rust/compile/torture/unused1.rs: New.
* rust/compile/torture/unused_struct.rs: New.
* rust/compile/torture/unused_struct_field.rs: New.
* rust/compile/torture/usize1.rs: New.
* rust/compile/torture/very-broken-attr-string.rs: New.
* rust/compile/torture/while_function.rs: New.
* rust/compile/traits1.rs: New.
* rust/compile/traits10.rs: New.
* rust/compile/traits11.rs: New.
* rust/compile/traits12.rs: New.
* rust/compile/traits2.rs: New.
* rust/compile/traits3.rs: New.
* rust/compile/traits4.rs: New.
* rust/compile/traits5.rs: New.
* rust/compile/traits6.rs: New.
* rust/compile/traits7.rs: New.
* rust/compile/traits8.rs: New.
* rust/compile/traits9.rs: New.
* rust/compile/tuple1.rs: New.
* rust/compile/tuple_struct1.rs: New.
* rust/compile/tuple_struct2.rs: New.
* rust/compile/tuple_struct3.rs: New.
* rust/compile/type-alias1.rs: New.
* rust/compile/type-bindings1.rs: New.
* rust/compile/unary_negation.rs: New.
* rust/compile/unary_not.rs: New.
* rust/compile/unconstrained_type_param.rs: New.
* rust/compile/unicode_escape.rs: New.
* rust/compile/unsafe1.rs: New.
* rust/compile/unsafe10.rs: New.
* rust/compile/unsafe2.rs: New.
* rust/compile/unsafe3.rs: New.
* rust/compile/unsafe4.rs: New.
* rust/compile/unsafe5.rs: New.
* rust/compile/unsafe6.rs: New.
* rust/compile/unsafe7.rs: New.
* rust/compile/unsafe8.rs: New.
* rust/compile/unsafe9.rs: New.
* rust/compile/unterminated_c_comment.rs: New.
* rust/compile/use_1.rs: New.
* rust/compile/usize1.rs: New.
* rust/compile/xfail/lifetime_param.rs: New.
* rust/compile/xfail/struct_field_vis.rs: New.
* rust/compile/xfail/xfail.exp: New.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
--- /dev/null
+extern "foobar" {
+ // { dg-error "unknown ABI option" "" { target *-*-* } .-1 }
+ fn printf(s: *const i8, ...);
+}
+
+pub extern "baz" fn test() {}
+// { dg-error "unknown ABI option" "" { target *-*-* } .-1 }
--- /dev/null
+fn foo(state: &mut [u32; 16], a: usize) {
+ // { dg-warning "function is never used: .foo." "" { target *-*-* } .-1 }
+ state[a] = 1;
+}
--- /dev/null
+fn main() {
+ let arr = [];
+ // { dg-error "type annotations needed" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let xs: [i32; 5] = [1, 2, 3, 4, 5];
+ let a: bool = xs[0]; // { dg-error "expected .bool. got .i32." }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+fn main() {
+ let array: [i32; 5] = [1, 2, 3];
+ // { dg-error "expected an array with a fixed size of 5 elements, found one with 3 elements" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-additional-options "-fdump-tree-gimple" }
+#![crate_name = "specified_name"]
+// { dg-final { scan-tree-dump-times {specified_name::main} 1 gimple } }
+fn main() {}
--- /dev/null
+// { dg-additional-options "-fdump-tree-gimple" }
+#[cold]
+fn cold_function() -> i32 {
+ 42
+}
+
+fn main() -> i32 {
+ // { dg-final { scan-tree-dump-times {__attribute__\(\(cdecl, cold\)\)} 1 gimple } }
+ cold_function();
+
+ 0
+}
--- /dev/null
+#[deprecated(since="1.0", note="do not use this function")]
+fn test1() {}
+
+#[deprecated]
+fn test() {}
+
+#[deprecated = "a different message"]
+fn test2() {}
+
+fn main() {
+ test(); // { dg-warning ".attr_deprecated::test. is deprecated" }
+ test1(); // { dg-warning ".attr_deprecated::test1. is deprecated: do not use this function" }
+ test2(); // { dg-warning ".attr_deprecated::test2. is deprecated: a different message" }
+}
--- /dev/null
+#[deprecated(since="1.0")]
+fn test1() {}
+
+// { dg-excess-errors "unknown meta item ...." }
+#[deprecated(invalid="invalid")]
+fn test2() {}
+
+fn main() {
+ test1(); // { dg-warning ".attr_deprecated_2::test1. is deprecated" }
+ test2();
+}
--- /dev/null
+// { dg-additional-options "-frust-crate=bad+name" }
+// { dg-excess-errors "invalid crate name: ...." }
+// { dg-excess-errors "unrecognized command-line option ...." }
+fn main() {}
--- /dev/null
+// { dg-additional-options "-fdump-tree-gimple -frust-crate=good_name" }
+pub fn does_nothing() {}
+fn main() {
+ does_nothing()
+}
+// { dg-final { scan-tree-dump-times {good_name::does_nothing} 2 gimple } }
+// { dg-final { scan-tree-dump-times {good_name::main} 1 gimple } }
--- /dev/null
+pub fn main ()
+{
+ let t = true;
+ let f = false;
+ let fone = t as f32; // { dg-error "invalid cast" }
+ let fzero = f as f64; // { dg-error "invalid cast" }
+
+ let nb = 0u8 as bool; // { dg-error "invalid cast" }
+ let nc = true as char; // { dg-error "invalid cast" }
+
+ let a = 'a';
+ let b = 'b';
+ let fa = a as f32; // { dg-error "invalid cast" }
+ let bb = b as bool; // { dg-error "invalid cast" }
+
+ let t32: u32 = 33;
+ let ab = t32 as char; // { dg-error "invalid cast" }
+}
--- /dev/null
+// { dg-excess-errors "invalid crate name: ...." }
+// { dg-bogus "unrecognized command-line option ...." }
+fn main() {}
--- /dev/null
+pub fn main ()
+{
+ //! inner doc allowed
+ let _x = 42;
+ // { dg-error "inner doc" "" { target *-*-* } .+1 }
+ //! inner doc disallowed
+ mod module
+ {
+ /*! inner doc allowed */
+ /// outer doc allowed
+ // { dg-error "inner doc" "" { target *-*-* } .+1 }
+ /*! but inner doc not here */
+ mod x { }
+ }
+}
--- /dev/null
+pub enum E
+{
+ pub A { a: i32 }, // { dg-error "visibility qualifier" }
+ B (u8),
+ pub C, // { dg-error "visibility qualifier" }
+ D
+}
+
+enum E1
+{
+ A,
+ pub B = 42, // { dg-error "visibility qualifier" }
+ C = 3,
+ D,
+ pub E // { dg-error "visibility qualifier" }
+}
+
+enum E2
+{
+ pub A (u8, i32, u64), // { dg-error "visibility qualifier" }
+ B { a: u8, a: u8 } // { dg-error "duplicate field" }}
+}
+
+fn main ()
+{
+ enum EE
+ {
+ Alpha { alpha: i32 },
+ pub Beta (u8), // { dg-error "visibility qualifier" }
+ pub Gamma, // { dg-error "visibility qualifier" }
+ Delta { delta: u32 }
+ }
+
+ enum EE1
+ {
+ pub Alpha, // { dg-error "visibility qualifier" }
+ Beta = 41,
+ pub Gamma = 3, // { dg-error "visibility qualifier" }
+ Delta,
+ }
+
+ enum E2
+ {
+ Alpha { a: u8, a: u8 }, // { dg-error "duplicate field" }}
+ pub Beta (u8, i32, u64) // { dg-error "visibility qualifier" }
+ }
+}
--- /dev/null
+fn main ()
+{
+ enum EE
+ {
+ Alpha { alpha: i32 },
+ pub Beta (u8),
+ pub Gamma,
+ Gamma { gamma: u32 } // { dg-error "redefined" }
+ }
+
+ struct EE2 { }
+ enum EE2 { } // { dg-error "redefined" }
+
+ enum EE1
+ {
+ pub Alpha,
+ Beta = 41,
+ Beta = 42, // { dg-error "redefined" }
+ pub Gamma = 3,
+ D,
+ }
+}
--- /dev/null
+pub enum E
+{
+ pub A { a: i32 },
+ B (u8),
+ pub C,
+ B // { dg-error "redefined" }
+}
+
+enum E2 { }
+struct E2 { } // { dg-error "redefined" }
+
+enum E1
+{
+ A,
+ pub B = 42,
+ C = 3,
+ A { a: u8 }, // { dg-error "redefined" }
+ pub D
+}
--- /dev/null
+fn main()
+{
+ // tuples
+ let z = ();
+
+ let o = (0,);
+ /* Binary, Octal and Hex literals are invalid. */
+ let _fb = o.0b0; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fo = o.0o0; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fh = o.0x0; // { dg-error "tuple index should be a pure decimal literal" }
+
+ /* No underscores. */
+ let _fua = o.0_; // { dg-error "tuple index should be a pure decimal literal" }
+
+ /* Suffix is not allowed. */
+ let _fu8 = o.0u8; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fi8 = o.0i8; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fu16 = o.0u16; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fi16 = o.0i16; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fu32 = o.0u32; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fi32 = o.0i32; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fu64 = o.0u64; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fi64 = o.0i64; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fu128 = o.0u128; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fi128 = o.0i128; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fusize = o.0usize; // { dg-error "tuple index should be a pure decimal literal" }
+ let _fisize = o.0isize; // { dg-error "tuple index should be a pure decimal literal" }
+
+ let t = (0,1);
+ /* No extra zero prefix. */
+ let _s = t.01; // { dg-error "tuple index should be a pure decimal literal" }
+
+ let m = (0,1,2,3,4,5,6,7,8,9,10);
+ /* No extra zero prefix. */
+ let _l = m.010; // { dg-error "tuple index should be a pure decimal literal" }
+
+ /* No underscores. */
+ let _lu = m.1_0; // { dg-error "tuple index should be a pure decimal literal" }
+
+ // tuple structs
+ struct E();
+ let _e = E();
+
+ struct O(i32);
+ let so = O(0);
+ /* No leading zeros, no underscores. */
+ let _sf = so.0_0; // { dg-error "tuple index should be a pure decimal literal" }
+ /* Binary, Octal and Hex literals are invalid. */
+ let _sb = so.0b0; // { dg-error "tuple index should be a pure decimal literal" }
+ let _so = so.0o0; // { dg-error "tuple index should be a pure decimal literal" }
+ let _sh = so.0x0; // { dg-error "tuple index should be a pure decimal literal" }
+
+ struct T(i32,i32);
+ let st = T(0,1);
+ /* Suffix is not allowed. */
+ let _stfu32 = st.1u32; // { dg-error "tuple index should be a pure decimal literal" }
+ let _stfi32 = st.1i32; // { dg-error "tuple index should be a pure decimal literal" }
+
+ struct M(i32,i32,i32,i32,i32,i32,i32,i32,i32,i32,i32);
+ let sm = M(0,1,2,3,4,5,6,7,8,9,10);
+ /* No underscores. */
+ let _sl2 = sm.1_0; // { dg-error "tuple index should be a pure decimal literal" }
+ let _sl3 = sm.10_; // { dg-error "tuple index should be a pure decimal literal" }
+
+ z
+}
--- /dev/null
+fn main() {
+ let logical: bool = 123; // { dg-error "expected .bool. got .<integer>." }
+}
--- /dev/null
+fn test(x: i32) -> i32 {
+ return x + 1;
+}
+
+fn main() {
+ let mut an_integer = 5;
+ an_integer = test(1) + 3;
+
+ let mut x;
+ x = 1;
+ x = true; // { dg-error "expected .<integer>. got .bool." }
+
+ let call_test = test(1);
+}
--- /dev/null
+fn main() {
+ let a;
+ a = 1;
+ break a; // { dg-error "cannot 'break' outside of a loop" }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ let mut c;
+ while b > 10 {
+ if (b == 2) {
+ break b; // { dg-error "can only break with a value inside 'loop'" }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-1 }
+ }
+ c = a + b;
+ a = b;
+ b = c;
+ }
+}
--- /dev/null
+#[rustc_builtin_macro]
+macro_rules! compile_error {
+ () => {{}};
+}
+
+fn main () {
+ let message = "error message";
+ compile_error! (message); // { dg-error "argument must be a string literal" "" }
+ compile_error! (); // { dg-error "macro takes 1 argument" "" }
+ compile_error! ("a", "b"); // { dg-error "macro takes 1 argument" "" }
+ compile_error! ("expected error message"); // { dg-error "expected error message" }
+ compile_error! ("expected error message",); // { dg-error "expected error message" }
+}
--- /dev/null
+#[rustc_builtin_macro]
+macro_rules! concat {
+ () => {{}};
+}
+
+fn main() {
+ let not_literal = "identifier";
+ concat!();
+ concat! (,); // { dg-error "argument must be a constant literal" }
+ concat!(not_literal); // { dg-error "argument must be a constant literal" }
+ concat!("message");
+ concat!("message",);
+ concat!("message", 1, true, false, 1.0, 10usize, 2000u64);
+ concat!("message", 1, true, false, 1.0, 10usize, 2000u64,);
+ concat! ("m", not_literal); // { dg-error "argument must be a constant literal" }
+ concat!(not_literal invalid 'm' !!,); // { dg-error "argument must be a constant literal" }
+}
--- /dev/null
+#[rustc_builtin_macro]
+macro_rules! env {
+ () => {{}};
+}
+
+fn main () {
+ let message = "error message";
+ env! (message); // { dg-error "argument must be a string literal" "" }
+ env! (); // { dg-error "env! takes 1 or 2 arguments" "" }
+ env! (,); // { dg-error "argument must be a string literal" "" }
+ env! (1); // { dg-error "argument must be a string literal" "" }
+ env! ("NOT_DEFINED"); // { dg-error "environment variable 'NOT_DEFINED' not defined" "" }
+ env! ("NOT_DEFINED",); // { dg-error "environment variable 'NOT_DEFINED' not defined" "" }
+ env! ("NOT_DEFINED", 1); // { dg-error "argument must be a string literal" "" }
+ env! ("NOT_DEFINED", "two", "three"); // { dg-error "env! takes 1 or 2 arguments" "" }
+ env! ("NOT_DEFINED" "expected error message"); // { dg-error "expected token: ','" "" }
+ env! ("NOT_DEFINED", "expected error message"); // { dg-error "expected error message" "" }
+ env! ("NOT_DEFINED", "expected error message",); // { dg-error "expected error message" "" }
+ env! (1, "two"); // { dg-error "argument must be a string literal" "" }
+}
--- /dev/null
+#[rustc_builtin_macro]
+macro_rules! include_bytes {
+ () => {{}};
+}
+
+fn main () {
+ let file = "include.txt";
+ include_bytes! (file); // { dg-error "argument must be a string literal" "" }
+ include_bytes! (); // { dg-error "macro takes 1 argument" "" }
+ include_bytes! ("foo.txt", "bar.txt"); // { dg-error "macro takes 1 argument" "" }
+ include_bytes! ("builtin_macro_include_bytes.rs"); // ok
+ include_bytes! ("builtin_macro_include_bytes.rs",); // trailing comma ok
+}
--- /dev/null
+#[rustc_builtin_macro]
+macro_rules! include_str {
+ () => {{}};
+}
+
+fn main () {
+ let file = "include.txt";
+ include_str! (file); // { dg-error "argument must be a string literal" "" }
+ include_str! (); // { dg-error "macro takes 1 argument" "" }
+ include_str! ("foo.txt", "bar.txt"); // { dg-error "macro takes 1 argument" "" }
+ include_str! ("builtin_macro_include_str.rs"); // ok
+ include_str! ("builtin_macro_include_str.rs",); // trailing comma ok
+}
--- /dev/null
+#[rustc_builtin_macro]
+macro_rules! crabby_crab_carb { // { dg-error "cannot find a built-in macro with name .crabby_crab_carb." }
+ () => {{}};
+}
--- /dev/null
+fn main ()
+{
+ let _bc = b'\x80';
+ let _bs = b"foo\x80bar";
+
+ let _c = '\xef'; // { dg-error "out of range" }
+ let _s = "Foo\xEFBar"; // { dg-error "out of range" }
+}
--- /dev/null
+// { dg-additional-options "-w -fdump-tree-gimple -frust-crate=example" }
+struct Foo(i32);
+
+trait TR {
+ fn test(&self) -> i32;
+}
+
+mod A {
+ impl ::Foo {
+ pub fn test(self) {}
+ // { dg-final { scan-tree-dump-times {example::A::<impl example::Foo>::test} 2 gimple } }
+ }
+
+ impl ::TR for ::Foo {
+ fn test(&self) -> i32 {
+ // { dg-final { scan-tree-dump-times {example::A::<impl example::Foo as example::TR>::test} 1 gimple } }
+ self.0
+ }
+ }
+}
+
+pub fn test() {
+ let a = Foo(123);
+ a.test();
+}
--- /dev/null
+fn main() {
+ let a: i32 = 123;
+ let b = a as char;
+ // { dg-error "invalid cast .i32. to .char." "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
+
+#[cfg(A)]
+fn test() {
+ unsafe {
+ let a = "test1\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+}
+
+#[cfg(B)]
+fn test() {
+ unsafe {
+ let a = "test2\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+}
+
+fn main() {
+ test();
+ // { dg-error "Cannot find path .test. in this scope" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-additional-options "-w -frust-cfg=A" }
+struct Foo;
+impl Foo {
+ #[cfg(not(A))]
+ fn test(&self) {}
+}
+
+fn main() {
+ let a = Foo;
+ a.test();
+ // { dg-error "failed to resolve method for .test." "" { target *-*-* } .-1 }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
+}
--- /dev/null
+// { dg-additional-options "-w -frust-cfg=A -frust-cfg=B" }
+struct Foo;
+impl Foo {
+ #[cfg(all(A, B))]
+ fn test(&self) {}
+}
+
+fn main() {
+ let a = Foo;
+ a.test();
+}
--- /dev/null
+// { dg-additional-options "-w -frust-cfg=A" }
+struct Foo;
+impl Foo {
+ #[cfg(any(A, B))]
+ fn test(&self) {}
+}
+
+fn main() {
+ let a = Foo;
+ a.test();
+}
--- /dev/null
+// { dg-additional-options "-w -frust-cfg=A=\"B\"" }
+struct Foo;
+impl Foo {
+ #[cfg(A = "B")]
+ fn test(&self) {}
+}
+
+fn main() {
+ let a = Foo;
+ a.test();
+}
--- /dev/null
+# Copyright (C) 2021-2022 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Compile tests, no torture testing.
+#
+# These tests raise errors in the front end; torture testing doesn't apply.
+
+# Load support procs.
+load_lib rust-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+set saved-dg-do-what-default ${dg-do-what-default}
+
+set dg-do-what-default "compile"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] "" ""
+set dg-do-what-default ${saved-dg-do-what-default}
+
+# All done.
+dg-finish
--- /dev/null
+// { dg-additional-options "-w" }
+mod a {
+ pub fn foo() {}
+}
+
+mod b {
+ pub fn foo() {
+ super::a::foo();
+ }
+}
+
+mod foo {
+ pub struct bar(pub i32);
+}
+
+fn test() -> crate::foo::bar {
+ foo::bar(123)
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+mod intrinsics {
+ extern "rust-intrinsic" {
+ pub fn wrapping_add<T>(a: T, b: T) -> T;
+ pub fn rotate_left<T>(a: T, b: T) -> T;
+ pub fn rotate_right<T>(a: T, b: T) -> T;
+ pub fn offset<T>(ptr: *const T, count: isize) -> *const T;
+ }
+}
+
+mod mem {
+ extern "rust-intrinsic" {
+ #[rustc_const_stable(feature = "const_transmute", since = "1.46.0")]
+ pub fn transmute<T, U>(_: T) -> U;
+ pub fn size_of<T>() -> usize;
+ }
+}
+
+macro_rules! impl_uint {
+ ($($ty:ident = $lang:literal),*) => {
+ $(
+ impl $ty {
+ pub fn wrapping_add(self, rhs: Self) -> Self {
+ // intrinsics::wrapping_add(self, rhs)
+ self + rhs
+ }
+
+ pub fn rotate_left(self, n: u32) -> Self {
+ unsafe {
+ intrinsics::rotate_left(self, n as Self)
+ }
+ }
+
+ pub fn rotate_right(self, n: u32) -> Self {
+ unsafe {
+ intrinsics::rotate_right(self, n as Self)
+ }
+ }
+
+ pub fn to_le(self) -> Self {
+ #[cfg(target_endian = "little")]
+ {
+ self
+ }
+ }
+
+ pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+ // { dg-error "only functions marked as .const. are allowed to be called from constant contexts" "" { target *-*-* } .-1 }
+ Self::from_le(Self::from_ne_bytes(bytes))
+ }
+
+ pub const fn from_le(x: Self) -> Self {
+ #[cfg(target_endian = "little")]
+ {
+ x
+ }
+ }
+
+ pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+ // { dg-error "only functions marked as .const. are allowed to be called from constant contexts" "" { target *-*-* } .-1 }
+ unsafe { mem::transmute(bytes) }
+ }
+ }
+ )*
+ }
+}
+
+impl_uint!(
+ u8 = "u8",
+ u16 = "u16",
+ u32 = "u32",
+ u64 = "u64",
+ u128 = "u128",
+ usize = "usize"
+);
--- /dev/null
+fn bar() {}
+
+const fn foo() {
+ bar(); // { dg-error "only functions marked as .const. are allowed to be called from constant contexts" }
+}
+
--- /dev/null
+// { dg-additional-options "-w" }
+
+const fn foo() {
+ const fn bar() {}
+
+ bar();
+}
--- /dev/null
+fn size() -> usize {
+ 15
+}
+
+fn main() {
+ let a = [15; size()]; // { dg-error "only functions marked as .const. are allowed to be called from constant contexts" }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+// There are errors about unused generic parameters, but we can't handle that yet.
+// Still, this code is invalid Rust.
+
+mod sain {
+ struct Foo<const N: usize>;
+ struct Bar<T, const N: usize>;
+ struct Baz<'l, T, const N: usize>;
+}
+
+mod doux {
+ struct Foo<const N: usize = 15>;
+ struct Bar<T, const N: usize = { 14 * 2 }>;
+
+ const N_DEFAULT: usize = 3;
+
+ struct Baz<'l, T, const N: usize = N_DEFAULT>;
+}
--- /dev/null
+struct Foo<const N>; // { dg-error "expecting .:. but .>. found" }
+struct Bar<const N: >; // { dg-error "unrecognised token .>. in type" }
+struct Baz<const N: usize = >; // { dg-error "invalid token for start of default value for const generic parameter" }
+// { dg-error "unrecognised token .>. in type" "" { target *-*-* } .-1 }
--- /dev/null
+// { dg-additional-options "-w" }
+
+const M: usize = 4;
+
+struct Foo<T, const N: usize = 1> {
+ // FIXME: This error is bogus. But having it means parsing is valid!
+ value: [i32; N], // { dg-error "failed to find name: N" }
+}
+
+fn main() {
+ let foo = Foo::<i32> { value: [15] };
+ let foo = Foo::<i32, 2> { value: [15, 13] };
+ let foo: Foo<i32, 2> = Foo { value: [15, 13] };
+ let foo: Foo<i32, 2> = Foo::<i32, 2> { value: [15, 13] };
+ let foo: Foo<i32, { 1 + 1 }> = Foo { value: [15, 13] };
+ let foo = Foo::<i32, { 1 + 1 }> { value: [15, 13] };
+ let foo: Foo<i32, { 1 + 1 }> = Foo::<i32, { 1 + 1 }> { value: [15, 13] };
+ let foo: Foo<i32, M> = Foo::<i32, 4> {
+ value: [15, 13, 11, 9],
+ };
+
+ // FIXME: Add proper const typecheck errors here
+ let invalid_foo: Foo<i32, { 1 + 1 }> = Foo::<i32, 3> { value: [15, 13] };
+ let invalid_foo: Foo<i32, { 1 + 1 }> = Foo::<i32, M> { value: [15, 13] };
+ let invalid_foo: Foo<i32> = Foo::<i32, 2> { value: [15, 13] };
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+const P: usize = 14;
+
+struct Foo<const N: usize = { M }>; // { dg-error "failed to find name: M" }
+struct Bar<const N: usize = { P }>;
+struct Baz<const N: NotAType = { P }>; // { dg-error "failed to resolve TypePath: NotAType in this scope" }
--- /dev/null
+struct Foo<const N: usize = { 14 }>;
+
+const M: usize = 15;
+type N = Foo<3>;
+
+fn main() {
+ let _: Foo<15> = Foo;
+ let _: Foo<{ M }> = Foo;
+ let _: Foo<M> = Foo;
+ // bogus error, but it means the above const generic gets disambiguated properly
+ let _: Foo<N> = Foo; // { dg-error "TypePath Foo<N> declares generic arguments but the type Foo{Foo {}} does not have any" }
+}
--- /dev/null
+struct Foo<const N: usize>;
+struct Bar<const N: usize = { 15i32 }>; // { dg-error "expected .usize. got .i32." }
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ let _fib = {
+ continue; // { dg-error "cannot 'continue' outside of a loop" }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-1 }
+ 123
+ };
+}
--- /dev/null
+fn foo() -> i32 {
+ return 1;
+
+ let mut a = 1; // { dg-warning "unreachable statement" }
+ a = 1.1; // { dg-warning "unreachable statement" }
+ // { dg-error "expected .<integer>. got .<float>." "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ foo();
+}
--- /dev/null
+fn foo() -> i32 {
+ return 1;
+ return 1.5; // { dg-error "expected .i32. got .<float>." }
+ // { dg-warning "unreachable statement" "" { target *-*-* } .-1 }
+}
+
+fn bar() -> i32 {
+ return 1.5; // { dg-error "expected .i32. got .<float>." }
+ return 1;
+ // { dg-warning "unreachable statement" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ foo();
+ bar();
+}
--- /dev/null
+// Make sure we don't see any 'note's:
+// { dg-bogus {note: } "" { target *-*-* } 0 }
+
+fn main() {
+}
--- /dev/null
+// { dg-additional-options "-fno-rust-debug" }
+
+// Make sure we don't see any 'note's:
+// { dg-bogus {note: } "" { target *-*-* } 0 }
+
+fn main() {
+}
--- /dev/null
+// { dg-additional-options "-frust-debug" }
+
+// Just scan for one of the Rust front end debug diagnostics:
+// { dg-message {note: Attempting to parse file: .+/gcc/testsuite/rust/compile/debug-diagnostics-on\.rs} "" { target *-*-* } 0 }
+
+fn main() {
+}
--- /dev/null
+// { dg-error "Isolated CR" "" { target *-*-* } .+1 }
+/** doc cr\r comment */
+pub fn main () { }
--- /dev/null
+pub fn main ()
+{
+// { dg-error "Isolated CR" "" { target *-*-* } .+1 }
+ /*! doc cr\r comment */
+}
--- /dev/null
+pub fn main ()
+{
+// { dg-error "Isolated CR" "" { target *-*-* } .+1 }
+ //! doc cr\r comment
+}
--- /dev/null
+// { dg-error "Isolated CR" "" { target *-*-* } .+1 }
+/// doc cr\r comment
+pub fn main () { }
--- /dev/null
+struct S { a: i32, b: i32, c: u8, a: i128 }
+// { dg-error "duplicate field" "" { target *-*-* } .-1 }
+
+union U
+ {
+ a: i32,
+ b: i32,
+ c: u8,
+ b: char // { dg-error "duplicate field" "" { target *-*-* } }
+ }
+
+fn main ()
+{
+ struct SS { alpha: i32, beta: i32, gamma: u8, gamma: i128 }
+ // { dg-error "duplicate field" "" { target *-*-* } .-1 }
+
+ union UU
+ {
+ alpha: i32, beta: i32,
+ gamma: u8, beta: char
+ // { dg-error "duplicate field" "" { target *-*-* } .-1 }
+ }
+}
--- /dev/null
+fn foo (x: i8) -> i32 { // { dg-warning "function is never used" }
+ //
+ match x {
+ 1 => { return 1; }
+ _ => { return 0; }
+ }
+}
--- /dev/null
+struct Foo<A>(A);
+
+fn main() {
+ let a: Foo = Foo::<i32>(123);
+ // { dg-error "generic item takes at least 1 type arguments but 0 were supplied" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<A>(A);
+
+impl Foo {
+ // { dg-error "generic item takes at least 1 type arguments but 0 were supplied" "" { target *-*-* } .-1 }
+ fn test() -> i32 {
+ 123
+ }
+}
--- /dev/null
+fn test(x: i32) -> bool {
+ return x + 1; // { dg-error "expected .bool. got .i32." }
+}
+
+fn main() {
+ let an_integer = 5;
+
+ let call_test = test(1);
+}
--- /dev/null
+fn test(a: i32, b: i32) -> i32 {
+ a + b
+}
+
+fn main() {
+ let a = test(1); // { dg-error "unexpected number of arguments 1 expected 2" }
+}
--- /dev/null
+fn test(a: i32, b: i32) -> i32 {
+ a + b
+}
+
+fn main() {
+ let a = test(1, true);
+ // { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 }
+ // { dg-error "Type Resolution failure on parameter" "" { target *-*-* } .-2 }
+}
--- /dev/null
+fn func() -> i32 { // { dg-error "expected .i32. got ...." }
+}
+
+fn main() {
+ func();
+}
--- /dev/null
+fn func() -> i32 {
+ return; // { dg-error "expected .i32. got ...." }
+}
+
+fn main() {
+ func();
+}
--- /dev/null
+struct Foo<A = i321>(A);
+// { dg-error "failed to resolve TypePath: i321" "" { target *-*-* } .-1 }
+
+fn main() {
+ let a;
+ a = Foo(123);
+}
--- /dev/null
+// { dg-error "expected .i32. got .i8." "" { target *-*-* } 0 }
+
+struct GenericStruct<T>(T, usize);
+
+fn main() {
+ let a2: GenericStruct<i8>;
+ a2 = GenericStruct::<_>(1, 456);
+
+ let b2: i32 = a2.0;
+ let c2: usize = a2.1;
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl<X = i32> Foo<X, f32> { // { dg-error "defaults for type parameters are not allowed here" }
+ fn new(a: X, b: f32) -> Self {
+ Self(a, b)
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo::new(123, 456f32);
+}
--- /dev/null
+struct Foo<T>(T, bool);
+
+impl<T> Foo<T> {
+ fn test() -> i32 {
+ 123
+ }
+}
+
+fn main() {
+ let a = Foo::test();
+ // { dg-error "type annotations needed" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ bar();
+ // { dg-error "type annotations needed" "" { target *-*-* } .-1 }
+}
+
+fn bar<T>() {}
--- /dev/null
+struct Foo<A, 'a>; // { dg-error "invalid order for generic parameters: lifetimes should always come before types" }
--- /dev/null
+// { dg-error "expected .i32. got .i8." "" { target *-*-* } 0 }
+
+struct GenericStruct<T>(T, usize);
+
+fn main() {
+ let a2: GenericStruct<i8>;
+ a2 = GenericStruct(1, 456);
+
+ let b2: i32 = a2.0;
+ let c2: usize = a2.1;
+}
--- /dev/null
+// { dg-error "expected .i32. got .i8." "" { target *-*-* } 0 }
+struct GenericStruct<T>(T, usize);
+
+fn main() {
+ let a2;
+ a2 = GenericStruct::<i8>(1, 456);
+
+ let b2: i32 = a2.0;
+ let c2: usize = a2.1;
+}
--- /dev/null
+struct GenericStruct<T>(T, usize);
+
+fn main() {
+ let a2;
+ a2 = GenericStruct::<i8, i32>(1, 456); // { dg-error "generic item takes at most 1 type arguments but 2 were supplied" }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-1 }
+ // { dg-error {Failed to resolve expression of function call} "" { target *-*-* } .-2 }
+ // { duplicate _dg-error {failed to type resolve expression} "" { target *-*-* } .-3 }
+
+ let b2: i32 = a2.0;
+ // { dg-error {Expected Tuple or ADT got: T\?} "" { target *-*-* } .-1 }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-2 }
+ let c2: usize = a2.1;
+ // { dg-error {Expected Tuple or ADT got: T\?} "" { target *-*-* } .-1 }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-2 }
+}
--- /dev/null
+struct GenericStruct<T>(T, usize);
+
+fn main() {
+ let a2;
+ a2 = GenericStruct::<i8, T>(1, 456);
+ // { dg-error "failed to resolve TypePath: T" "" { target *-*-* } .-1 }
+
+ let b2: i32 = a2.0;
+ let c2: usize = a2.1;
+}
--- /dev/null
+struct Foo<A> {
+ a: A,
+}
+
+impl Foo<isize> {
+ fn test() -> i32 { // { dg-error "possible candidate" "TODO" { xfail *-*-* } }
+ 123
+ }
+
+ fn bar(self) -> isize {
+ self.a
+ }
+}
+
+impl Foo<f32> {
+ fn test() -> i32 { // { dg-error "possible candidate" "TODO" { xfail *-*-* } }
+ 123
+ }
+
+ fn bar(self) -> f32 {
+ self.a
+ }
+}
+
+fn main() {
+ let a: i32 = Foo::test(); // { dg-error "multiple applicable items in scope for: test" }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-1 }
+ // { dg-error {Failed to resolve expression of function call} "" { target *-*-* } .-2 }
+ // { duplicate _dg-error {failed to type resolve expression} "" { target *-*-* } .-3 }
+}
+
--- /dev/null
+struct Foo<A> {
+ a: A,
+}
+
+impl Foo<isize> {
+ fn bar(self) -> isize { // { dg-error "duplicate definitions with name bar" }
+ self.a
+ }
+}
+
+impl Foo<char> {
+ fn bar(self) -> char { // { dg-error "duplicate definitions with name bar" }
+ self.a
+ }
+}
+
+impl<T> Foo<T> {
+ fn bar(self) -> T {
+ self.a
+ }
+}
+
+fn main() {
+ let a = Foo { a: 123 };
+ a.bar();
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl<T> Foo<i32, T> {
+ fn test(a: T) -> T {
+ a
+ }
+}
+
+impl Foo<i32, f32> {
+ fn test() -> f32 { // { dg-error "duplicate definitions with name test" }
+ 123f32
+ }
+}
+
+fn main() {}
--- /dev/null
+struct Foo<A, B = (A, B)>(A, B);
+// { dg-error "failed to resolve TypePath: B" "" { target *-*-* } .-1 }
+
+fn main() {
+ let a: Foo<bool>;
+ a = Foo::<bool>(true, (false, true));
+
+ let b: (bool, bool);
+ b = a.1;
+}
--- /dev/null
+fn test(x: i32) -> i32 {
+ if x > 1 { // { dg-error "expected .... got .<integer>." }
+ 1
+ } else {
+ 2
+ }
+ 3
+}
+
+fn main() {
+ let a = test(1);
+}
--- /dev/null
+fn test(x: i32) -> i32 {
+ // { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 }
+ return 1;
+ // { dg-warning "unreachable expression" "" { target *-*-* } .+1 }
+ true
+}
+
+fn main() {
+ let a = test(1);
+}
--- /dev/null
+fn test(x: i32) -> i32 { // { dg-error "expected .i32. got ...." }
+ if x > 1 {
+ 1
+ }
+}
+
+fn main() {
+ let a = test(9);
+}
--- /dev/null
+fn test(x: bool) -> bool {
+ // { dg-error "expected .bool. got ...." "" { target *-*-*} .-1 }
+ return x;
+ // { dg-warning "unreachable expression" "" { target *-*-* } .+1 }
+ ()
+}
+
+fn main() {
+ let a = test(true);
+}
--- /dev/null
+// { dg-additional-options "-fdump-tree-gimple" }
+pub fn does_nothing() {}
+fn main() {
+ does_nothing()
+}
+// { dg-final { scan-tree-dump-times {infer_crate_name::does_nothing} 2 gimple } }
+// { dg-final { scan-tree-dump-times {infer_crate_name::main} 1 gimple } }
--- /dev/null
+// { dg-additional-options "-fdump-tree-gimple" }
+#[inline]
+fn test_a() {}
+
+// { dg-final { scan-tree-dump-times {always_inline} 1 gimple } }
+#[inline(always)]
+fn test_b() {}
+
+#[inline(never)]
+fn test_c() {}
+
+fn main() {
+ test_a();
+ test_b();
+ test_c();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+#[inline(A)] // { dg-error "unknown inline option" }
+fn test_a() {}
+
+#[inline(A, B)] // { dg-error "invalid number of arguments" }
+fn test_b() {}
--- /dev/null
+// { dg-additional-options "-w" }
+impl<T> *const T {
+ fn test(self) {}
+}
--- /dev/null
+trait A<T> {
+ type Output;
+
+ fn test(self, a: &T) -> &Self::Output;
+}
+
+struct Foo<T> {
+ // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+ start: T,
+ end: T,
+}
+
+impl<X> A<X> for Foo<usize> {
+ type Output = X;
+
+ fn test(self, a: &X) -> &Self::Output {
+ a
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+fn foo(e: &str) -> &str {
+ &""
+}
--- /dev/null
+extern "rust-intrinsic" {
+ #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
+ pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
+}
+
+#[lang = "const_ptr"]
+impl<T> *const T {
+ pub const unsafe fn offset(self, count: isize) -> *const T {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ unsafe { offset(self, count) }
+ }
+
+ pub const unsafe fn add(self, count: usize) -> Self {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ unsafe { self.offset(count as isize) }
+ }
+}
--- /dev/null
+trait Foo<T> {
+ type Output;
+
+ fn test(self, slice: &T) -> &Self::Output;
+}
+
+struct Bar<T>(T);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+impl<T> Foo<[T]> for Bar<usize> {
+ type Output = [T];
+
+ fn test(self, slice: &[T]) -> &[T] {
+ slice
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+pub mod test_mod;
+
+fn main() {
+ let a = test_mod::Test(123);
+}
--- /dev/null
+pub trait Hasher {
+ fn write(&mut self, bytes: &[u8]);
+ fn write_u8(&mut self, i: u8) {
+ self.write(&[i])
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+fn write_u8(i: u8) {
+ let x: &[u8] = &[i];
+}
--- /dev/null
+// { dg-additional-options "-w" }
+pub trait Hasher {
+ fn finish(&self) -> u64;
+ fn write(&mut self, bytes: &[u8]);
+ fn write_u8(&mut self, i: u8) {
+ self.write(&[i])
+ }
+}
+
+struct SipHasher;
+
+impl Hasher for SipHasher {
+ #[inline]
+ fn write(&mut self, msg: &[u8]) {
+ loop {}
+ }
+
+ #[inline]
+ fn finish(&self) -> u64 {
+ 0
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+mod mem {
+ extern "rust-intrinsic" {
+ fn size_of<T>() -> usize;
+ fn transmute<U, V>(_: U) -> V;
+ }
+}
+
+impl u16 {
+ fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
+ unsafe { mem::transmute(self) }
+ }
+}
+
+pub trait Hasher {
+ fn finish(&self) -> u64;
+
+ fn write(&mut self, bytes: &[u8]);
+
+ fn write_u8(&mut self, i: u8) {
+ self.write(&[i])
+ }
+
+ fn write_i8(&mut self, i: i8) {
+ self.write_u8(i as u8)
+ }
+
+ fn write_u16(&mut self, i: u16) {
+ self.write(&i.to_ne_bytes())
+ }
+
+ fn write_i16(&mut self, i: i16) {
+ self.write_u16(i as u16)
+ }
+}
+
+pub struct SipHasher;
+
+impl Hasher for SipHasher {
+ #[inline]
+ fn write(&mut self, msg: &[u8]) {}
+
+ #[inline]
+ fn finish(&self) -> u64 {
+ 0
+ }
+}
--- /dev/null
+extern "rust-intrinsic" {
+ fn size_of<T>() -> usize;
+ fn offset<T>(dst: *const T, offset: isize) -> *const T;
+}
--- /dev/null
+fn test() {
+ let f = [0; -4_isize];
+ // { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
+ let f = [0_usize; -1_isize];
+ // { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
+}
--- /dev/null
+struct Foo<T>(T);
+
+fn main() {
+ &Foo(123);
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+#![feature(intrinsics)]
+
+mod mem {
+ extern "rust-intrinsic" {
+ pub fn transmute<U, V>(_: U) -> V;
+ }
+}
+
+pub trait Hasher {
+ fn write(&mut self, bytes: &[u8]);
+ fn write_u16(&mut self, i: u16) {
+ self.write(unsafe { &mem::transmute::<_, [u8; 2]>(i) })
+ }
+}
+
+pub struct SipHasher;
+
+impl Hasher for SipHasher {
+ #[inline]
+ fn write(&mut self, msg: &[u8]) {}
+}
--- /dev/null
+// { dg-additional-options "-w" }
+const TEST: *mut u8 = 123 as *mut u8;
+
+fn test() {
+ let a = TEST;
+}
--- /dev/null
+fn foo() -> u8 {
+ // { dg-warning "function is never used" "" { target *-*-* } .-1 }
+ 1u8 << 2u32
+}
--- /dev/null
+// { dg-additional-options "-w" }
+struct FatPtr<T> {
+ data: *const T,
+ len: usize,
+}
+
+pub union Repr<T> {
+ rust: *const [T],
+ rust_mut: *mut [T],
+ raw: FatPtr<T>,
+}
+
+impl<T> [T] {
+ pub const fn is_empty(&self) -> bool {
+ self.len() == 0
+ }
+
+ pub const fn len(&self) -> usize {
+ unsafe { Repr { rust: self }.raw.len }
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+mod intrinsics {
+ extern "rust-intrinsic" {
+ pub fn offset<T>(ptr: *const T, count: isize) -> *const T;
+ }
+}
+
+impl<T> *const T {
+ pub unsafe fn offset(self, count: isize) -> *const T {
+ unsafe { intrinsics::offset(self, count) }
+ }
+}
+
+impl<T> [T] {
+ pub unsafe fn get_unchecked(&self, index: usize) -> &T {
+ unsafe { &*(self as *const [T] as *const T).offset(index as isize) }
+ }
+}
+
+#[inline]
+unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
+ (unsafe { *buf.get_unchecked(start) } as u64)
+}
--- /dev/null
+// { dg-additional-options "-w" }
+mod a {
+ pub mod b {
+ pub mod a {
+ pub fn foo() {}
+ }
+ }
+
+ pub fn bidule() {
+ crate::a::b::a::foo()
+ }
+}
+
+fn main() {}
--- /dev/null
+// { dg-additional-options "-w" }
+fn test() {
+ let a: &str = "TEST 1";
+ let b: &str = &"TEST 2";
+}
--- /dev/null
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
+
+mod intrinsics {
+ extern "rust-intrinsic" {
+ #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
+ pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
+ }
+}
+
+#[lang = "mut_ptr"]
+impl<T> *mut T {
+ pub const unsafe fn offset(self, count: isize) -> *mut T {
+ unsafe { intrinsics::offset(self, count) as *mut T }
+ }
+
+ pub const unsafe fn add(self, count: usize) -> Self {
+ unsafe { self.offset(count as isize) }
+ }
+}
+
+#[lang = "const_ptr"]
+impl<T> *const T {
+ pub const unsafe fn offset(self, count: isize) -> *mut T {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ unsafe { intrinsics::offset(self, count) as *mut T }
+ }
+
+ pub const unsafe fn add(self, count: usize) -> Self {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ unsafe { self.offset(count as isize) }
+ }
+}
+
+fn main() -> i32 {
+ let a: *mut _ = &mut 123;
+ unsafe {
+ let _b = a.add(123);
+ }
+
+ 0
+}
--- /dev/null
+fn main() {
+ let mut x = [1, 2, 3];
+ let y: i32 = x[0];
+ print_int(y);
+}
+
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
+
+fn print_int(value: i32) {
+ let s = "%d\n\0";
+ let s_p = s as *const str;
+ let c_p = s_p as *const i8;
+ unsafe {
+ printf(c_p, value as isize);
+ }
+}
--- /dev/null
+fn print_int(value: i32) {
+ let s = "%d\n\0";
+ let s_p = s as *const str;
+ let c_p = s_p as *const i8;
+ unsafe {
+ printf(c_p, value as isize);
+ }
+}
+
+fn main() {
+ print_int(5);
+}
+
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
--- /dev/null
+pub fn generic_function<X>(a: X) -> X {
+ a
+}
+
+fn main() -> i32 {
+ let a = generic_function(123);
+ a - 123
+}
--- /dev/null
+fn tst() {
+ let a = 123;
+ let b = 0;
+ let _c = if b == 0 {
+ (a & 0x7fffff) << 1
+ } else {
+ (a & 0x7fffff) | 0x800000
+ };
+}
+
+fn main() {
+ tst()
+}
--- /dev/null
+// { dg-options "-w" }
+struct PhantomData<T>;
+
+struct Hasher<S> {
+ _marker: PhantomData<S>,
+}
+
+struct Sip24Rounds;
+
+struct SipHasher24 {
+ hasher: Hasher<Sip24Rounds>,
+}
+
+impl SipHasher24 {
+ pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher24 {
+ SipHasher24 {
+ hasher: Hasher::new_with_keys(),
+ }
+ }
+}
+
+impl<S> Hasher<S> {
+ fn new_with_keys() -> Hasher<S> {
+ Hasher {
+ _marker: PhantomData,
+ }
+ }
+}
--- /dev/null
+// #407
+pub fn loopy() {
+ let mut a = 1;
+ // { dg-error {failed to parse expr with block in parsing expr statement} "" { target *-*-* } .+2 }
+ // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .+1 }
+ loop {
+ // { dg-error {failed to parse expr with block in parsing expr statement} "" { target *-*-* } .+2 }
+ // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .+1 }
+ if a < 40 {
+ a + = 1; // { dg-error "found unexpected token '=' in null denotation" }
+ // { dg-error {failed to parse expression for expression without block \(pratt-parsed expression is null\)} "" { target *-*-* } .-1 }
+ // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .-2 }
+ // { dg-error {failed to parse if body block expression in if expression} "" { target *-*-* } .-3 }
+ // { dg-error {could not parse loop body in \(infinite\) loop expression} "" { target *-*-* } .+1 }
+ } else {
+ break;
+ }
+ }
+}
+// { dg-error {unrecognised token '\}' for start of item} "" { target *-*-* } .-1 }
+// { dg-error {failed to parse item in crate} "" { target *-*-* } .-2 }
--- /dev/null
+// This already worked before the #409 code changes.
+fn test() {
+ let mut a = 1;
+ a + = 1; // { dg-error "found unexpected token '=' in null denotation" }
+ // { dg-error {failed to parse expression for expression without block \(pratt-parsed expression is null\)} "" { target *-*-* } .-1 }
+ // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .-2 }
+ // { dg-error {unrecognised token 'integer literal' for start of item} "" { target *-*-* } .-3 }
+ // { dg-error {failed to parse item in crate} "" { target *-*-* } .-4 }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+fn test(a: i32, _: i32) {
+ let _ = 42 + a;
+}
--- /dev/null
+// { dg-additional-options "-w" }
+fn test() -> i32 {
+ return 10000000000000000000000000000000000000000000;
+ // { dg-error "integer overflows the respective type .i32." "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+fn test() -> f32 {
+ return 10000000000000000000000000000000000000000000.0f32;
+ // { dg-error "decimal overflows the respective type .f32." "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test() {
+ fn nested() {}
+}
+
+fn main() {
+ nested(); // { dg-error "Cannot find path .nested. in this scope" }
+}
--- /dev/null
+macro_rules! m {
+ ($e:expr $(forbidden)*) => {{}}; // { dg-error "token .identifier. is not allowed after .expr. fragment" }
+ // { dg-error "required first macro rule in macro rules definition could not be parsed" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
+}
--- /dev/null
+macro_rules! m {
+ ($e:expr $(,)*) => {{}};
+}
--- /dev/null
+macro_rules! impl_uint {
+ ($($ty:ident),*) => {
+ impl $ty {} // { dg-error "metavariable is still repeating at this depth" }
+ // { dg-error "unrecognised token" "" { target *-*-* } .-1 } // Spurious
+ // { dg-error "could not parse type" "" { target *-*-* } .-2 } // Spurious
+ };
+}
+
+impl_uint!(u8, u16, u32, u64, u128);
--- /dev/null
+// { dg-additional-options "-frust-cfg=A -w" }
+
+macro_rules! impl_uint {
+ ($($ty:ident = $lang:literal),*) => {
+ $(
+ impl $ty {
+ pub fn to_le(self) -> Self {
+ #[cfg(not(A))]
+ {
+ self
+ }
+ #[cfg(A)]
+ {
+ self
+ }
+ }
+ }
+ )*
+ }
+}
+
+impl_uint!(u8 = "u8", u16 = "u16", u32 = "u32");
--- /dev/null
+// { dg-additional-options "-frust-edition=2018" }
+
+macro_rules! try {
+ // { dg-error "expecting .identifier. but .try. found" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
+ () => {};
+}
--- /dev/null
+// Default edition is 2015 - this is valid
+
+macro_rules! try {
+ () => {};
+}
--- /dev/null
+macro_rules! foo {
+ ( ( $( $Trait: ident ),+ ) for $($Ty: ident)* ) => {
+ $(
+ impl $Trait for $Ty {
+ // { dg-error "different amount of matches used in merged repetitions: expected 4, got 1" "" { target *-*-* } .-1 }
+ fn bar() -> i32 {
+ 14
+ }
+ }
+ )+
+ }
+}
+
+trait Foo {
+ fn bar() -> i32;
+}
+
+trait Bar {
+ fn bar() -> i32;
+}
+
+trait Baz {
+ fn bar() -> i32;
+}
+
+trait Qux {
+ fn bar() -> i32;
+}
+
+struct S;
+
+foo! {(Foo, Bar, Baz, Qux) for S}
--- /dev/null
+// { dg-additional-options "-w" }
+
+macro_rules! foo {
+ ( ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
+ $(
+ impl $Trait for $Ty {
+ fn bar() -> i32 {
+ 14
+ }
+ }
+ )+
+ }
+}
+
+trait Foo {
+ fn bar() -> i32;
+}
+
+trait Bar {
+ fn bar() -> i32;
+}
+
+trait Baz {
+ fn bar() -> i32;
+}
+
+trait Qux {
+ fn bar() -> i32;
+}
+
+struct S;
+
+foo! {(Foo, Bar, Baz, Qux) for S}
--- /dev/null
+macro_rules! empty_parens {
+ () => ();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+macro_rules! foo {
+ {} => {
+ 15
+ };
+}
+
+fn main() {
+ let a = foo!();
+ let b = foo![];
+}
--- /dev/null
+macro_rules! call_f {
+ ($($f:ident)*) => { $($f();)* }
+}
+
+fn f() {}
+
+// This is valid and should parse items
+fn main() {
+ call_f!(f f f f);
+}
+
--- /dev/null
+// { dg-additional-options "-w" }
+macro_rules! define_vars {
+ ($($v:ident)*) => { $(let $v = 15;)* }
+}
+
+fn main() {
+ define_vars!(a0 b f __some_identifier);
+}
--- /dev/null
+// { dg-additional-options "-w" }
+macro_rules! create_type {
+ ($s:ident) => {
+ struct $s;
+ };
+}
+
+fn main() {
+ create_type!(A);
+
+ let a = A;
+}
--- /dev/null
+// { dg-additional-options "-w" }
+macro_rules! define_vars {
+ ($($v:ident)*) => { $(let $v = 15;)* }
+}
+
+fn main() -> i32 {
+ define_vars!(a0 b f __some_identifier);
+
+ b
+}
--- /dev/null
+// { dg-additional-options "-w" }
+macro_rules! create_type {
+ ($s:ident) => {
+ struct $s;
+ };
+}
+
+create_type!(SomeOuterType);
+
+fn main() {
+ let a = SomeOuterType;
+}
--- /dev/null
+fn main() {
+ macro_rules! create_type {
+ ($s:ident) => {
+ struct $s(i32);
+ };
+ }
+
+ create_type!(Wrapper);
+
+ let _ = Wrapper(15);
+}
--- /dev/null
+macro_rules! rep {
+ ($a:literal) => { $a }; // { dg-error "reached recursion limit" }
+ ($a:literal $(, $e:literal)*) => { // { dg-error "reached recursion limit" }
+ $a + rep!(0 $(, $e)*) // { dg-error "Failed to match" }
+ }
+}
+
+fn main() -> i32 {
+ rep!(1, 2)
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+macro_rules! take_stmt {
+ ($s:stmt) => {
+ $s;
+ };
+}
+
+fn main() -> i32 {
+ take_stmt!(let complete = 15;); // { dg-error "Failed to match any rule within macro" }
+ take_stmt!(let lacking = 14);
+
+ 0
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+macro_rules! call_without_semi {
+ () => {
+ f()
+ };
+ (block) => {{
+ f()
+ }};
+}
+
+fn f() {}
+
+fn main() -> i32 {
+ call_without_semi!();
+ call_without_semi!(block);
+
+ 0
+}
--- /dev/null
+macro_rules! empty_brackets {
+ [] => [];
+}
--- /dev/null
+macro_rules! define_trait {
+ ($assoc:ident, $i:item) => {
+ type $assoc;
+
+ $i
+ };
+}
+
+trait DefinedThroughMacros {
+ define_trait!(
+ Inner,
+ fn takes_inner(i: Self::Inner) -> Self::Inner {
+ i
+ }
+ );
+}
--- /dev/null
+macro_rules! c_fn {
+ {$name:ident ($($arg_name:ident $arg_ty:ty),*) -> $ret_ty:ty} => {
+ fn $name($($arg_name: $arg_ty)*) -> $ret_ty;
+ };
+}
+
+extern "C" {
+ c_fn! {puts (s *const i8) -> i64}
+}
--- /dev/null
+macro_rules! print {
+ () => {
+ fn puts(s: *const i8);
+ fn printf(fmt: *const i8, ...);
+ };
+}
+
+extern "C" {
+ print! {}
+}
--- /dev/null
+macro_rules! maybe_impl {
+ ($left:ident, $right:ident, $l_fn:ident, $r_fn:ident) => {
+ fn $l_fn(value: T) -> Maybe<T> {
+ Maybe::$left(value)
+ }
+
+ fn $r_fn() -> Maybe<T> {
+ Maybe::$right
+ }
+ };
+}
+
+enum Maybe<T> {
+ Just(T),
+ Nothing,
+}
+
+impl<T> Maybe<T> {
+ maybe_impl!(Just, Nothing, just, nothing);
+}
+
+fn main() {
+ let _ = Maybe::just(14);
+ let _: Maybe<i32> = Maybe::nothing();
+}
--- /dev/null
+macro_rules! valid {
+ ($($a:literal)* $i:ident) => {{}};
+}
+
+fn main() {
+ valid!(1 one_lit);
+ valid!(identifier_only);
+ valid!(1 2 two_lits);
+}
--- /dev/null
+macro_rules! repeat {
+ ( $( $i:literal ),* ; $( $j:literal ),* ) => (( $( ($i,$j) ),* ))
+ // { dg-error "different amount of matches used in merged repetitions" "" { target *-*-* } .-1 }
+}
+
+fn main() -> i32 {
+ let _ = repeat!(1, 2, 3; 2, 3);
+
+ 0
+}
--- /dev/null
+macro_rules! m {
+ ($a:expr tok) => {
+ // { dg-error "token .identifier. is not allowed after .expr. fragment" "" { target *-*-* } .-1 }
+ // { dg-error "required first macro rule in macro rules definition could not be parsed" "" { target *-*-* } .-2 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 }
+ $a
+ };
+}
--- /dev/null
+macro_rules! m {
+ ($a:expr $(tok $es:expr)*) => {
+ // { dg-error "token .identifier. is not allowed after .expr. fragment" "" { target *-*-* } .-1 }
+ // { dg-error "required first macro rule in macro rules definition could not be parsed" "" { target *-*-* } .-2 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 }
+ $a
+ };
+}
--- /dev/null
+macro_rules! m {
+ ($($es:expr)* tok) => {
+ // { dg-error "token .identifier. is not allowed after .expr. fragment" "" { target *-*-* } .-1 }
+ // { dg-error "required first macro rule in macro rules definition could not be parsed" "" { target *-*-* } .-2 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 }
+ $a
+ };
+}
--- /dev/null
+macro_rules! empty_curlies {
+ {} => {};
+}
--- /dev/null
+macro_rules! m {
+ ($e:expr $f:expr) => {
+ // { dg-error "fragment is not allowed after .expr. fragment" "" { target *-*-* } .-1 }
+ // { dg-error "required first macro rule in macro rules definition could not be parsed" "" { target *-*-* } .-2 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 }
+ $e
+ };
+}
--- /dev/null
+macro_rules! m {
+ ($($e:expr)* $($f:expr)*) => {
+ // { dg-error "fragment is not allowed after .expr. fragment" "" { target *-*-* } .-1 }
+ // { dg-error "required first macro rule in macro rules definition could not be parsed" "" { target *-*-* } .-2 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 }
+ $e
+ };
+}
--- /dev/null
+macro_rules! s {
+ ($s:stmt) => {{}};
+}
+
+macro_rules! multi_s {
+ ($($s:stmt)+) => {{}};
+}
+
+fn main() -> i32 {
+ s!(let a = 15);
+ s!(;); // Empty statement
+ s!(let a = 15;); // { dg-error "Failed to match any rule within macro" }
+ multi_s!(let a = 15;);
+ // ^ this actually gets parsed as two statements - one LetStmt and one
+ // empty statement. This is the same behavior as rustc, which you can
+ // see using a count!() macro
+
+ 32
+}
--- /dev/null
+macro_rules! forbidden_frag {
+ ($t:ty $not_block:ident) => {{}}; // { dg-error "fragment specifier .ident. is not allowed after .ty. fragments" }
+ // { dg-error "required first macro rule in macro rules definition could not be parsed" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
+}
--- /dev/null
+macro_rules! allowed_after_expr_matcher {
+ (($t:expr) bok) => {{}}; // follow-set restrictions do not apply after a matcher, but they do apply inside the matcher
+}
--- /dev/null
+macro_rules! inside_matcher {
+ (($e:expr tok) tok) => {{}}; // { dg-error "token .identifier. is not allowed after .expr. fragment" }
+ // { dg-error "failed to parse macro matcher" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse macro match" "" { target *-*-* } .-2 }
+ // { dg-error "required first macro rule" "" { target *-*-* } .-3 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-4 }
+}
--- /dev/null
+macro_rules! ty_allowed {
+ ($t:ty $b:block) => {{}};
+}
--- /dev/null
+macro_rules! invalid_after_zeroable {
+ ($e:expr $(,)* forbidden) => {{}}; // { dg-error "token .identifier. is not allowed after .expr. fragment" }
+ // { dg-error "required first macro rule" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
+}
--- /dev/null
+macro_rules! invalid_after_zeroable_multi {
+ ($e:expr $(,)? $(;)* $(=>)? forbidden) => {{}}; // { dg-error "token .identifier. is not allowed after .expr. fragment" }
+ // { dg-error "required first macro rule" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
+}
--- /dev/null
+macro_rules! m {
+ ($e:expr (, parenthesis_forbidden)) => {{}}; // { dg-error "token .\\(. at start of matcher is not allowed after .expr. fragment" }
+ // { dg-error "required first macro rule" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
+}
--- /dev/null
+macro_rules! one_keyword {
+ (kw) => {};
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+macro_rules! t {
+ () => {
+ i32
+ };
+}
+
+macro_rules! s {
+ () => {
+ *const i8
+ };
+}
+
+extern "C" {
+ fn printf(s: s!(), ...);
+}
+
+fn square(arg: t!()) -> t!() {
+ let input: t!() = arg;
+
+ input * input
+}
+
+trait Trait {
+ fn f() -> t!();
+ fn g(arg: t!());
+}
+
+struct Wrapper {
+ inner: t!(),
+}
+
+impl Trait for Wrapper {
+ fn f() -> t!() {
+ 1
+ }
+
+ fn g(arg: t!()) {}
+}
+
+fn id<T>(arg: T) -> T {
+ arg
+}
+
+fn main() {
+ id::<t!()>(15);
+}
--- /dev/null
+macro_rules! empty {
+ ($($t:tt)*) => {};
+}
+
+empty! {nothing}
+empty! {struct OuterItem;}
+empty! {}
+
+fn main() {
+ empty! {as statement};
+ empty! {any child item};
+ empty! {};
+}
--- /dev/null
+// { dg-additional-options "-w -frust-cfg=A" }
+#[rustc_builtin_macro]
+macro_rules! cfg {
+ () => {{}};
+}
+
+fn main() -> i32 {
+ let mut res = 0;
+ if cfg!(A) {
+ res = 1;
+ }
+
+ if cfg!(A) {
+ res = 2;
+ } else {
+ res = 3;
+ }
+
+ if cfg!(A) {
+ res = 4;
+ } else if cfg!(A) {
+ res = 5;
+ }
+
+ let res = if cfg!(A) {
+ 6
+ } else {
+ 7
+ };
+
+ return res;
+}
--- /dev/null
+macro_rules! rust_keyword {
+ (fn) => {};
+}
--- /dev/null
+macro_rules! zero_or_one {
+ ($($a:literal)?) => { // { dg-error "invalid amount of matches for macro invocation. Expected between 0 and 1, got 2" }
+ f();
+ }
+}
+
+fn main() {
+ zero_or_one!();
+ zero_or_one!(14);
+ zero_or_one!(125 12 "gcc"); // { dg-error "Failed to match any rule within macro" }
+}
--- /dev/null
+fn f() {}
+
+macro_rules! one_or_more {
+ ($($a:literal)+) => { // { dg-error "invalid amount of matches for macro invocation" }
+ f();
+ };
+}
+
+fn main() {
+ one_or_more!(1 1 1 1 1 1 1 1 1 1 1 "rust" 'c');
+ one_or_more!(1);
+ one_or_more!(); // { dg-error "Failed to match any rule within macro" }
+}
--- /dev/null
+fn f() {}
+
+macro_rules! expr {
+ ($($a:expr)?) => {
+ f();
+ };
+}
+
+fn main() {
+ expr!();
+ expr!(14);
+}
--- /dev/null
+macro_rules! add {
+ ($e:expr, $($es:expr),*) => {
+ $e + add!($($es),*)
+ };
+ ($e:expr) => {
+ $e
+ };
+}
+
+fn main() -> i32 {
+ let a = add!(15 2 9); // { dg-error "Failed to match any rule within macro" }
+ let b = add!(15);
+ let b = add!(15 14); // { dg-error "Failed to match any rule within macro" }
+ let b = add!(15, 14,); // { dg-error "Failed to match any rule within macro" }
+
+ 0
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+macro_rules! add {
+ ($a:expr) => { $a };
+ ($a:expr, $($b:expr),+) => { $a + add!($($b),*) }
+}
+
+fn main() -> i32 {
+ add!(add!(1, 2))
+}
--- /dev/null
+enum Foo {
+ A,
+ B,
+ C(char),
+ D { x: i64, y: i64 },
+}
+
+fn inspect(f: Foo) {
+ match f {
+ Foo::A => {}
+ Foo::B => {}
+ Foo::C(a, b) => {}
+ // { dg-error "this pattern has 2 fields but the corresponding tuple variant has 1 field" "" { target *-*-* } .-1 }
+ Foo::D { x, y } => {}
+ }
+}
--- /dev/null
+enum Foo {
+ A,
+ B,
+ C(char),
+ D { x: i64, y: i64 },
+}
+
+fn inspect(f: Foo) {
+ match f {
+ Foo::A => {}
+ Foo::B => {}
+ Foo::C(x) => {}
+ Foo::D { y } => {} // { dg-error "pattern does not mention fields x" }
+ }
+}
--- /dev/null
+enum Foo {
+ A,
+ B,
+ C(char),
+ D { x: i64, y: i64 },
+}
+
+fn inspect(f: Foo) {
+ match f {
+ Foo::A => {}
+ Foo::B => {}
+ Foo::C(x) => {}
+ Foo::D { z } => {} // { dg-error "variant D does not have a field named z" }
+ // { dg-error "pattern does not mention fields x, y" "" { target *-*-* } .-1 }
+ }
+}
--- /dev/null
+enum Foo {
+ A,
+ B,
+ C(char),
+ D { x: i64, y: i64 },
+}
+
+fn inspect(f: Foo) {
+ match f {
+ Foo::A => {}
+ Foo::B => {}
+ Foo::C { a } => {}
+ // { dg-error "expected struct variant, found tuple variant C" "" { target *-*-* } .-1 }
+ Foo::D { x, y } => {}
+ }
+}
--- /dev/null
+enum Foo {
+ A,
+ B,
+ C(char),
+ D { x: i64, y: i64 },
+}
+
+fn inspect(f: Foo) {
+ match f {
+ Foo::A => {}
+ Foo::B => {}
+ Foo::C(a) => {}
+ Foo::D(x, y) => {} // { dg-error "expected tuple struct or tuple variant, found struct variant 'Foo::D'" }
+ }
+}
--- /dev/null
+fn foo() -> bool {
+ true
+}
+
+fn int32() -> i32 {
+ 1
+}
+
+fn bar() -> i32 {
+ match foo() {
+ true => int32(),
+ false => 0
+ }
+}
+
+fn main() -> () {
+ bar();
+}
\ No newline at end of file
--- /dev/null
+fn bar (x: u8, y: u8) -> i32 {
+ match (x, y) {
+ (1, 1) => { return 1; }
+ (1, _) => { return -1; }
+ }
+
+ return 0;
+}
+
+fn main () -> () {
+ bar (1, 2);
+}
--- /dev/null
+struct Foo(i32);
+impl Foo {
+ fn test() {}
+}
+
+pub fn main() {
+ let a;
+ a = Foo(123);
+
+ a.test();
+ // { dg-error "failed to resolve method for .test." "" { target *-*-* } .-1 }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-2 }
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl Foo<i32, f32> {
+ fn test<X>(self, a: X) -> X {
+ a
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo(123, 456f32);
+
+ let b;
+ b = a.test::<asfasfr>(false);
+ // { dg-error "failed to resolve TypePath: asfasfr" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-additional-options "-frust-crate=another_name" }
+#![crate_name = "legit_name"]
+// { dg-error ".-frust-crate-name. and .#.crate_name.. are required to match, but .another_name. does not match .legit_name." "" { target *-*-* } .-1 }
+fn main() {}
--- /dev/null
+pub fn f() -> u32 {
+ 5
+}
--- /dev/null
+mod other;
--- /dev/null
+pub fn f() -> u32 {
+ 4
+}
--- /dev/null
+pub fn f() -> u32 {
+ 2
+}
--- /dev/null
+pub fn f() -> u32 {
+ 3
+}
--- /dev/null
+pub fn f() -> u32 {
+ 1
+}
--- /dev/null
+// { dg-error "expected .* got .*" "" { target *-*-* } 0 }
+fn test1() -> i32 {}
+
+fn main() {
+ let call1 = test1();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+mod missing_middle {
+ mod sub;
+
+ #[path = "explicit.not.rs"]
+ mod explicit;
+}
+
+#[path = "missing_middle"]
+mod with_outer_path_attr {
+ #[path = "outer_path.rs"]
+ mod inner;
+}
+
+mod with_inner_path_attr {
+ #![path = "missing_middle"]
+
+ #[path = "inner_path.rs"]
+ mod inner;
+}
+
+#[path = "missing_middle"]
+mod with_both_path_attr {
+ #![path = "this_is_ignored"]
+
+ #[path = "both_path.rs"]
+ mod inner;
+}
--- /dev/null
+fn test() {
+ let a;
+
+ // FIXME: Unimplemented features
+ a = if true { // { dg-error "expected .T.. got .!." }
+ return;
+ } else {
+ return;
+ };
+}
+
+fn main() {
+ test();
+}
--- /dev/null
+mod orange {
+ mod green {
+ fn sain() {}
+ pub fn doux() {}
+ }
+
+ fn brown() {
+ green::sain(); // { dg-error "definition is private in this context" }
+ green::doux();
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+mod orange {
+ fn tangerine() {}
+
+ mod green {
+ mod blue {
+ fn berry() {
+ tangerine();
+ }
+ }
+ }
+}
--- /dev/null
+mod orange {
+ mod green {
+ fn sain_void() {}
+ fn sain() -> bool {
+ false
+ }
+ pub fn doux() {}
+ }
+
+ fn brown() {
+ if green::sain() {
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+ green::doux();
+ }
+
+ {
+ green::sain();
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+ green::sain();
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+ green::sain_void()
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+ }
+
+ let a = green::sain();
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+ }
+}
--- /dev/null
+mod orange {
+ mod green {
+ fn bean<T>(value: T) -> T {
+ value
+ }
+ }
+
+ fn brown() {
+ green::bean::<bool>(false);
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+ let a = green::bean::<i32>(15);
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+
+ struct S;
+
+ let s = green::bean(S);
+ // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+ }
+}
--- /dev/null
+mod orange {
+ mod green {
+ struct Foo;
+ pub(in orange) struct Bar;
+ pub struct Baz;
+ }
+
+ fn brown() {
+ let _ = green::Foo; // { dg-error "definition is private in this context" }
+ let _ = green::Bar;
+ let _ = green::Baz;
+
+ let _: green::Foo; // { dg-error "definition is private in this context" }
+
+ fn any(a0: green::Foo, a1: green::Bar) {} // { dg-error "20:definition is private in this context" }
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+struct Adt;
+enum EAdt {
+ V0,
+ V1,
+}
+struct Registers {
+ r0: i64,
+ r1: i64,
+ r2: i64,
+ r3: i64,
+}
+trait Foo {}
+
+fn foo1(value: bool) {}
+fn foo2(value: char) {}
+fn foo3(value: i32) {}
+fn foo4(value: u16) {}
+fn foo5(value: f64) {}
+fn foo6(value: usize) {}
+fn foo7(value: isize) {}
+fn foo8(value: Adt) {}
+fn foo9(value: EAdt) {}
+fn foo10(value: &str) {}
+fn foo11(value: *const i8) {}
+fn foo12<T>(value: T) {}
+fn foo13(value: [i32; 5]) {}
+fn foo14(value: [Adt]) {}
+fn foo15(value: fn(i32) -> i32) {}
+fn foo16(value: (i32, Adt)) {}
+fn foo17(value: (i32, [f64; 5])) {}
+fn foo18(value: Registers) {}
+fn foo19(value: &dyn Foo) {}
+fn foo20(value: &[Adt]) {}
+// FIXME: Uncomment once #1257 is fixed
+// fn foo21(value: fn(i32)) {}
+// fn foo22(value: fn()) {}
+fn foo23(value: fn() -> i32) {}
--- /dev/null
+pub mod foo {
+ pub mod bar {
+ pub fn baz() {}
+
+ pub(in foo::bar) struct A0;
+ }
+}
+
+pub(in foo::fah::baz) struct A1; // { dg-error "cannot find simple path segment .fah." }
+pub(in fro::bulator::saindoux) struct A2; // { dg-error "cannot find simple path segment .fro." }
+pub(in foo::bar::saindoux) struct A3; // { dg-error "cannot find simple path segment .saindoux." }
+
+fn main() {}
--- /dev/null
+// { dg-additional-options "-w" }
+
+mod foo {
+ mod bar {
+ mod baz {
+ pub(in baz) struct A0;
+ pub(in bar::baz) struct A1;
+ pub(in foo::bar::baz) struct A2;
+
+ mod sain {
+ mod doux {}
+ }
+
+ pub(in sain) struct A3; // { dg-error "restricted path is not an ancestor of the current module" }
+ pub(in sain::doux) struct A4; // { dg-error "restricted path is not an ancestor of the current module" }
+ }
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+mod foo {
+ mod bar {
+ pub(in foo) fn baz() {}
+ }
+
+ fn baz() {
+ bar::baz(); // no error, foo::bar::baz is public in foo
+ }
+}
--- /dev/null
+pub fn plus(n: i32, m: i32) -> i32 {
+ r#crate /* { dg-error "forbidden raw identifier" } */
+}
--- /dev/null
+pub fn s(num: i32) -> i32 {
+ r#_ * num /* { dg-error "not a valid raw identifier" } */
+}
--- /dev/null
+struct S1 {
+ x: f64,
+ y: f64,
+}
+
+struct S1(i32, bool); // { dg-error "redefined multiple times" }
+
+fn main() {}
--- /dev/null
+const TEST: i32 = 2;
+const TEST: f32 = 3.0; // { dg-error "redefined multiple times" }
+
+fn main() {}
--- /dev/null
+fn test() -> bool {
+ true
+}
+
+fn test() -> i32 { // { dg-error "redefined multiple times" }
+ 123
+}
+
+fn main() {}
--- /dev/null
+struct Foo(i32, bool);
+
+impl Foo {
+ fn new(a: i32, b: bool) -> Foo {
+ Foo(a, b)
+ }
+
+ fn test() -> i32 {
+ test()
+ }
+
+ fn test() -> bool { // { dg-error "redefined multiple times" }
+ true
+ }
+}
+
+fn test() -> i32 {
+ 123
+}
+
+fn main() {
+ let a;
+ a = Foo::new(1, true);
+
+ let b;
+ b = Foo::test();
+}
--- /dev/null
+struct Foo(i32, bool);
+
+impl Foo {
+ const TEST: i32 = 123;
+ const TEST: bool = false; // { dg-error "redefined multiple times" }
+}
+
+fn main() {}
--- /dev/null
+struct Foo<T>(T, usize);
+
+impl Foo<i32> {
+ fn test() -> i32 {
+ 123
+ }
+
+ fn test(self) -> i32 { // { dg-error "redefined multiple times" }
+ self.0
+ }
+}
+
+fn main() {}
--- /dev/null
+fn main() {
+ let a = &123;
+ let b: &mut i32 = a;
+ // { dg-error "mismatched mutability" "" { target *-*-* } .-1 }
+ // { dg-error "expected .&mut i32. got .& i32." "" { target *-*-* } .-2 }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+struct foo;
+
+fn bar() -> self::foo {
+ crate::foo
+}
+
+fn baz() {
+ let a: foo = self::bar();
+
+ crate::bar();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+struct foo;
+
+fn bar() -> self::foo {
+ crate::foo
+}
+
+fn baz() {
+ let a: foo = self::bar();
+
+ crate::bar();
+
+ crate::self::foo();
+ // { dg-error "failed to resolve: .self. in paths can only be used in start position" "" { target *-*-* } .-1 }
+}
+
+type a = foo;
+type b = crate::foo;
+type c = self::foo;
+type d = crate::self::foo;
+// { dg-error "failed to resolve: .self. in paths can only be used in start position" "" { target *-*-* } .-1 }
--- /dev/null
+fn main() {
+ let mut x = 5;
+ let mut x;
+ x = true;
+ x = x + 2; // { dg-error "cannot apply this operator to types bool and <integer>" }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-additional-options "-frust-crate=fancy_crate_name -fdump-tree-gimple" }
+pub fn does_nothing() {}
+fn main() {
+ does_nothing()
+}
+// { dg-final { scan-tree-dump-times {fancy_crate_name::does_nothing} 2 gimple } }
+// { dg-final { scan-tree-dump-times {fancy_crate_name::main} 1 gimple } }
--- /dev/null
+static x = 3; // { dg-error "expecting ':' but '=' found" }
+
+fn main() {// { dg-error "failed to parse item in crate" }
+ let y = x +1;
+}
--- /dev/null
+fn test(x: i32) -> i32 {
+ if x > 1 { // { dg-error "expected .... got .<integer>." }
+ 1
+ } else {
+ 2
+ }
+
+ { // { dg-error "expected .... got .<integer>." }
+ 3
+ }
+
+ 3
+}
+
+fn main() {
+ let a = test(0);
+}
--- /dev/null
+#[repr(align(8))]
+struct Foo {
+ x: i16,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ y: i8,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ z: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+#[repr(align(8))]
+struct Bar(i8, i32);
+
+fn main () {
+ let f = Foo { x: 5, y: 2, z: 13 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = Bar (7, 262);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+
+fn main () {
+
+ #[repr(align(8))]
+ struct Baz {
+ x: u16,
+ y: u32,
+ };
+
+ #[repr(align(4))]
+ struct Qux (u8, i16);
+
+ let b = Baz { x: 5, y: 1984 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c = Qux (1, 2);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: f32,
+ b: f32,
+}
+
+fn main() {
+ let a = Foo { 0: 10.0, 1: 20.0 }; // { dg-error "failed to resolve type for field" }
+ // { dg-error "unknown field" "" { target *-*-* } .-1 }
+ // { dg-prune-output "compilation terminated" }
+}
--- /dev/null
+#[repr(packed(2))]
+struct Foo {
+ x: i16,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ y: i8,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ z: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+#[repr(packed)]
+struct Bar(i8, i32);
+
+fn main () {
+ let f = Foo { x: 5, y: 2, z: 13 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = Bar (7, 262);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+
+fn main () {
+
+ #[repr(packed(2))]
+ struct Baz {
+ x: u16,
+ y: u32,
+ };
+
+ #[repr(packed)]
+ struct Qux (u8, i16);
+
+ let b = Baz { x: 5, y: 1984 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c = Qux (1, 2);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-additional-options "-fsyntax-only" }
+
+fn main() {
+ let mut a = 15;
+ a = true;
+}
--- /dev/null
+//! test_mod inner doc comment
+//!
+//! foo bar baz cake pizza carbs
+
+pub struct Test(pub i32);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
--- /dev/null
+// comment line not a doc
+/* comment block not a doc */
+
+//! inner line comment for most outer crate
+/*! inner block comment for most outer crate */
+
+// comment line not a doc
+/* comment block not a doc */
+
+/// outer doc line for module
+/** outer doc block for module */
+pub mod module {
+ //! inner line doc
+ //!! inner line doc!
+ /*! inner block doc */
+ /*!! inner block doc! */
+
+ // line comment
+ /// outer line doc
+ //// line comment
+
+ /* block comment */
+ /** outer block doc */
+ /*** block comment */
+
+ mod block_doc_comments {
+ /* /* */ /** */ /*! */ */
+ /*! /* */ /** */ /*! */ */
+ /** /* */ /** */ /*! */ */
+ mod item {}
+ }
+
+ pub mod empty {
+ //!
+ /*!*/
+ //
+
+ ///
+ // the following warning is issued one line earlier
+ mod doc {}
+ /**/
+ /***/
+ }
+}
+pub fn main() {}
--- /dev/null
+// comment line not a doc\r
+/* comment block not a doc */\r
+\r
+//! inner line comment for most outer crate\r
+/*! inner block comment for most outer crate */\r
+\r
+// comment line not a doc\r
+/* comment block not a doc */\r
+\r
+/// outer doc line for module\r
+/** outer doc block for module */\r
+pub mod module\r
+{\r
+ //! inner line doc\r
+ //!! inner line doc!\r
+ /*! inner block doc */\r
+ /*!! inner block doc! */\r
+\r
+ // line comment\r
+ /// outer line doc\r
+ //// line comment\r
+\r
+ /* block comment */\r
+ /** outer block doc */\r
+ /*** block comment */\r
+\r
+ mod block_doc_comments\r
+ {\r
+ /* /* */ /** */ /*! */ */\r
+ /*! /* */ /** */ /*! */ */\r
+ /** /* */ /** */ /*! */ */\r
+ mod item { }\r
+ }\r
+\r
+ pub mod empty\r
+ {\r
+ //!\r
+ /*!*/\r
+ //\r
+\r
+ ///\r
+ mod doc { }\r
+\r
+ /**/\r
+ /***/\r
+ }\r
+}\r
+pub fn main () { }\r
--- /dev/null
+// { dg-prune-output "warning: unused name" } as there are many of these expected.
+
+fn main() {
+ let a: i32 = 1;
+ let b: f32 = 5f32;
+ let c: bool = true;
+
+ let a1: i32 = a + 1;
+ let a2: i32 = a - 2;
+ let a3: i32 = a * 3;
+ let a4: i32 = a / 4;
+ let a5: i32 = a % 5;
+
+ let b1: f32 = b + 1f32;
+ let b2: f32 = b - 2f32;
+ let b3: f32 = b * 3f32;
+ let b4: f32 = b / 4f32;
+ // let b5: f32 = b % 5f32;
+
+ let aa1: i32 = a & 1;
+ let aa2: i32 = a | 2;
+ let aa2: i32 = a ^ 3;
+
+ let c1: bool = c & true;
+ let c2: bool = c | false;
+ let c3: bool = c ^ true;
+
+ let aaa1: i32 = a << 1;
+ let aaa2: i32 = a >> 2;
+}
--- /dev/null
+const TEST: [i32; 16] = [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8];
+// { dg-warning "unused name" "" { target *-*-* } .-1 }
\ No newline at end of file
--- /dev/null
+const SIZE: usize = 14 + 2;
+const TEST: [i32; SIZE] = [2; SIZE];
+// { dg-warning "unused name" "" { target *-*-* } .-1 }
--- /dev/null
+fn foo() -> i32 {
+ 1
+}
+
+
+fn main() {
+ let _a: [i32; 1] = [foo()];
+}
\ No newline at end of file
--- /dev/null
+fn main() {
+ let arr: [_; 5] = [1, 2, 3, 4, 5];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let arr = ["Hello"; 0];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let xs: [i32; 5] = [1, 2, 3, 4, 5];
+ let xy = [6, 7, 8];
+
+ let a = xs[0];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = xy[2];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let mut array: [i32; 3] = [0; 3];
+
+ let a = array[0];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let mut c;
+ c = array[2];
+}
--- /dev/null
+const TEST: usize = 6;
+
+fn main() {
+ let a: [_; 12] = [123; TEST * 2];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+const TEST: usize = 4;
+
+fn main() {
+ let a: [_; TEST + 1 + 2] = [123; 7];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+
+// Checks that we don't try to allocate a 4TB array during compilation
+fn main () {
+ let x = [0; 4 * 1024 * 1024 * 1024 * 1024];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+
+// Checks that we don't try to allocate a 4TB array during compilation
+fn foo() -> [u8; 4 * 1024 * 1024 * 1024 * 1024] {
+ [0; 4 * 1024 * 1024 * 1024 * 1024]
+}
+
+fn main () {
+ let x = foo ();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let mut array: [i32; 3] = [0; 3];
+
+ let a = array[0];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let x = 0;
+ let mut c;
+ c = array[x+1];
+}
--- /dev/null
+fn main() {
+ let mut array: [i32; 3] = [0; 3];
+ array[0] = 1;
+}
--- /dev/null
+fn foo() -> usize {
+ 1
+}
+
+fn bar() -> [i32; 1] {
+ [0]
+}
+
+
+
+fn main() -> () {
+ let a = [10];
+ let _b = a[foo()];
+ let _c = bar()[foo()];
+}
--- /dev/null
+extern "C" { fn abort (); }
+
+pub fn main ()
+{
+ let t = true;
+ let f = false;
+ let one = t as u8;
+ let zero = f as u8;
+
+ if one != 1 || zero != 0 { unsafe { abort (); } }
+
+ let isizeone = true as isize;
+ let usizezero = false as usize;
+
+ if isizeone != 1 || usizezero != 0 { unsafe { abort (); } }
+
+ let i32zero = f as i32;
+ let u128one = t as u128;
+
+ if u128one != 1 || i32zero != 0 { unsafe { abort (); } }
+
+ let a = 'a';
+ let b = 'b';
+ let ua = a as u8;
+ let ib = b as i32;
+
+ if (ua + 1) as i32 != ib { unsafe { abort (); } }
+
+ let tt = ua;
+ let aa = tt as char;
+
+ let ttt = tt + 1;
+ let ab = ttt as char;
+
+ if aa != 'a' || ab != 'b' { unsafe { abort (); } }
+}
--- /dev/null
+pub trait Foo {
+ type A;
+
+ fn boo(&self) -> <Self as Foo>::A;
+}
+
+fn foo2<I: Foo>(x: I) {
+ // { dg-warning "function is never used: .foo2." "" { target *-*-* } .-1 }
+ x.boo();
+}
+
+pub fn main() {}
--- /dev/null
+struct Foo(i32, bool);
+struct Bar {
+ a: i32,
+ b: bool,
+}
+
+fn main() {
+ let a = &Foo(123, false);
+ let _b: i32 = a.0;
+ let _c: bool = a.1;
+
+ let a = &Bar { a: 456, b: false };
+ let _b: i32 = a.a;
+ let _c: bool = a.b;
+}
--- /dev/null
+fn test3(x: i32) -> i32 {
+ if x > 1 {
+ 5
+ } else {
+ 0
+ }
+}
+
+fn test5(x: i32) -> i32 {
+ if x > 1 {
+ if x == 5 {
+ 7
+ } else {
+ 9
+ }
+ } else {
+ 0
+ }
+}
+
+fn main() {
+ let call3: i32 = { test3(3) + 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call5 = {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let a = test5(5);
+ a + 1
+ };
+}
--- /dev/null
+fn test() -> i32 {
+ 123
+}
+
+fn main() {
+ let a = { test() };
+ let b = {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ if a > 10 {
+ a - 1
+ } else {
+ a + 1
+ }
+ };
+}
--- /dev/null
+fn main() {
+ let x = 111;
+
+ let a = {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ if x == 10 {
+ 123
+ } else if x < 10 {
+ 456
+ } else {
+ 789
+ }
+ };
+}
--- /dev/null
+fn foo() -> isize {
+ 0
+}
+
+fn main() {
+ let a = foo();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn foo() -> i32 {
+ 0
+}
+
+fn bar() -> i32 {
+ foo();
+ foo()
+}
+
+fn baz() -> i32 {
+ {
+ bar();
+ bar();
+ }
+ {
+ bar();
+ bar()
+ };
+ {
+ bar();
+ bar()
+ }
+}
+
+fn test(ok: i32) -> i32 {
+ if ok >= 1 {
+ foo()
+ } else if ok <= -1 {
+ bar()
+ } else {
+ baz()
+ }
+}
+
+fn main() {
+ let a = foo();
+ let b = bar();
+ let c = baz();
+ test(a + b + c);
+}
--- /dev/null
+fn main() {
+ let a = 123;
+ let b = if a > 10 { a - 1 } else { a + 1 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+pub fn main () { }
--- /dev/null
+// UTF8 BOM
+pub fn main () { }
--- /dev/null
+#!/usr/bin/cat
+pub fn main () { }
--- /dev/null
+
+pub fn main () { }
--- /dev/null
+extern "C"
+{
+ fn abort ();
+}
+
+fn beq (a: bool, b: bool) -> bool
+{
+ let bools_eq = a == b;
+ bools_eq
+}
+
+pub fn main ()
+{
+ let a = true;
+ let b = false;
+ let r = beq (a, b);
+ if r { unsafe { abort (); } }
+}
--- /dev/null
+fn main() {
+ let a: i32;
+ a = 123;
+
+ let b: &i32;
+ b = &a;
+
+ let aa;
+ aa = 456;
+ let bb: &_;
+ bb = &a;
+
+ let aaa;
+ aaa = 123;
+ let bbb;
+ bbb = &aaa;
+}
--- /dev/null
+fn foo() {}
+
+fn main() {
+ let _a = &foo;
+}
\ No newline at end of file
--- /dev/null
+fn foo() -> i32 {
+ 1
+}
+
+fn main() {
+ let _a = loop {
+ break foo();
+ };
+}
+
\ No newline at end of file
--- /dev/null
+pub fn main ()
+{
+ let _c = 'x';
+ let _bc = b'x';
+
+ let _s = "abc";
+ let _bs = b"abc";
+}
--- /dev/null
+pub fn main() {
+ let a: &[u8; 4];
+ a = b"test";
+}
--- /dev/null
+fn main() {
+ let a: *const i32 = &123;
+ let b: *mut i32 = (a as *mut i32);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let a: i32 = 123i32;
+ let b: u8 = a as u8;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let a = "foo\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+mod fake {} // Add one line so gccrs doesn't believe we're parsing a shebang
+
+#[cfg_attr(feature = "somefeature", attribute = "someattr")]
+struct Feature;
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+fn main() {}
--- /dev/null
+fn main() {
+ let a;
+ a = 'c';
+}
--- /dev/null
+#![crate_type = "lib"]
+
+#[doc(alias = "foo")] // ok!
+#[doc(alias("bar", "baz"))] // ok!
+pub struct Bar;
+
+#[doc(alias = "
+")] // { dg-error "invalid character used" "" { target *-*-* } .-1 }
+pub struct Foo;
+
+#[doc(alias(
+ "
+"
+))] // ko but unchecked for now
+pub struct Foo2;
+
+#[doc(whatever = "buidule")] // ko as well but unchecked for now
+struct Boo;
--- /dev/null
+pub fn main() {
+ let a: &i32 = &123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b: &mut i32 = &mut 123;
+
+ let c: &i32 = &mut 123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let d: &i32 = b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+pub fn main() {
+ let a: *const i32 = &123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b: &i32 = &123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c: &mut i32 = &mut 123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let d: *mut i32 = &mut 123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let e: &i32 = &mut 123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let f: *const i32 = &mut 123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let g = &123;
+ let h: *const i32 = g;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn is_zero(x: i32) -> bool {
+ x == 0
+}
+
+fn is_not_zero(x: i32) -> bool {
+ x != 0
+}
+
+fn is_positive(x: i32) -> bool {
+ x > 0
+}
+
+fn is_negative(x: i32) -> bool {
+ x < 0
+}
+
+fn is_positive_or_zero(x: i32) -> bool {
+ x >= 0
+}
+
+fn is_negative_or_zero(x: i32) -> bool {
+ x <= 0
+}
+
+fn main() {
+ let a: bool = is_zero(1);
+ let b: bool = is_not_zero(2);
+ let c: bool = is_positive(3);
+ let d: bool = is_negative(4);
+ let e: bool = is_positive_or_zero(5);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let f: bool = is_negative_or_zero(6);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let g: bool = a || b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let h: bool = c && d;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+# Copyright (C) 2021-2022 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Compile tests, torture testing.
+
+# Load support procs.
+load_lib rust-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+set saved-dg-do-what-default ${dg-do-what-default}
+
+set dg-do-what-default "compile"
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] "" ""
+set dg-do-what-default ${saved-dg-do-what-default}
+
+# All done.
+dg-finish
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 2;
+ let mut c = 3;
+ let mut d = 4;
+ let mut e = 5;
+ let mut f = 6;
+ let mut g = 7;
+ let mut h = 8;
+ let mut i = 9;
+ let mut j = 10;
+
+ a += 1;
+ b -= 2;
+ c *= 3;
+ d /= 4;
+ e %= 5;
+ f &= 6;
+ g |= 7;
+ h ^= 8;
+ i <<= 9;
+ j >>= 10;
+}
--- /dev/null
+fn main() {
+ let mut x = 5;
+
+ if x == 5 {
+ x = 1;
+ } else if x == 3 {
+ x = 2;
+ } else {
+ x = 3;
+ }
+}
--- /dev/null
+const TEST_CONST:i32 = 10;
+
+fn main() {
+ let mut x = TEST_CONST;
+ x = x + 1;
+
+ let mut y = x + TEST_CONST;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ const C: usize = 42;
+
+ let _a = C;
+ let _b: [i32; C] = [0; C];
+}
--- /dev/null
+fn main() {
+ const A: [i32; 3] = [1, 2, 3];
+ const B: i32 = A[1];
+ const C: usize = 42;
+ const D: i32 = 7;
+
+ let _a = C;
+ let _b: [i32; C] = [0; C];
+ let _c = B + D;
+}
--- /dev/null
+fn test1() -> i32 {
+ return 2;
+ // { dg-warning "unreachable expression" "" { target *-*-* } .+1 }
+ 1
+}
+
+fn test2(x: i32) -> i32 {
+ if x > 1 {
+ return 5;
+ } else {
+ return 0;
+ }
+ // { dg-warning "unreachable statement" "" { target *-*-* } .+1 }
+ return 1;
+}
+
+fn main() {
+ let call1 = test1();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call2 = test2(2);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn foo() -> i32 {
+ return 1;
+
+ let a = -1; // { dg-warning "unreachable statement" }
+ a // { dg-warning "unreachable expression" }
+}
+
+fn main() {
+ foo();
+}
--- /dev/null
+fn main() {
+ let a = 123;
+ let b = &a;
+ let c = *b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn foo() {}
+
+
+fn main() {
+ let _c = *{
+ let _a = foo;
+ let b = &1;
+ b
+ };
+}
\ No newline at end of file
--- /dev/null
+/// doc comment 1
+/// doc comment 2
+/// `blah blah` markdown
+pub struct TestStruct {}
+
+#[doc(hidden)]
+pub struct DocAttribute {}
+
+#[doc(a,b)]
+pub struct UnkAttribute {}
+
+fn main() {
+ let _ = TestStruct {};
+ let _ = DocAttribute {};
+ let _ = UnkAttribute {};
+}
--- /dev/null
+enum Foo {
+ A,
+ B,
+ C(char),
+ D { x: i64, y: i64 },
+}
+
+fn main() {
+ let _a = Foo::A;
+ let _b = Foo::B;
+ let _c = Foo::C('x');
+ let _d = Foo::D { x: 20, y: 80 };
+}
--- /dev/null
+// { dg-additional-options "-w" }
+mod modules;
+
+fn main() {
+ let twelve = modules::return_12();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+
+#[path = "modules/valid_path.rs"]
+mod not_a_valid_path;
+
+#[path ="modules/valid_path.rs"]
+mod path_without_extra_equal;
+
+#[path= "modules/valid_path.rs"]
+mod no_leading_equal;
+
+#[path = "modules/valid_path.rs"]
+mod extra_spaces;
+
+#[path] // { dg-error "path attributes must contain a filename" }
+mod error; // { dg-error "no candidate found" }
+
+// This is "valid", and should only error out when parsing
+// the file
+#[path = "not_a_valid_file.rs"]
+mod another_error; // { dg-error "No such file or directory" }
+
+fn main() {}
--- /dev/null
+fn test(x: f32) -> f32 {
+ return x + 1.0;
+}
+
+fn main() {
+ let a_float = 5.123;
+ let call_test = test(a_float + 1.0);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-prune-output "warning: unused name" } as there are many of these expected.
+
+fn main() {
+ let a1: f32 = 1.0f32;
+ let a2: f64 = 2.0f64;
+ let a3: f32 = 3f32;
+ let a4: f64 = 4f64;
+
+ let b1 = 1.0f32;
+ let b2 = 2.0f64;
+ let b3 = 3f32;
+ let b4 = 4f64;
+}
--- /dev/null
+fn main() {
+ let mut an_integer = 5;
+ an_integer = test(1) + 3;
+
+ let call_test = test(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
+
+fn test(x: i32) -> i32 {
+ return x + 1;
+}
--- /dev/null
+fn main() {
+ let y = x + 1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
+
+static x: i32 = 3;
--- /dev/null
+fn main() {
+ unsafe {
+ let struct_test = Foo { one: 1, two: 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ };
+}
+
+struct Foo {
+ one: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ two: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let struct_test = Foo { one: 1, two: 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
+
+struct Foo {
+ one: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ two: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let mut x = TEST_CONST;
+ x = x + 1;
+
+ let mut y = x + TEST_CONST;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
+
+const TEST_CONST: i32 = 10;
--- /dev/null
+pub fn main() {
+ let a;
+ a = foo { a: 123, b: 456f32 };
+
+ let mut a = 123;
+ a = bar(a);
+
+ let mut b = 456f32;
+ b = bar(b);
+
+ fn bar<T>(x: T) -> T {
+ x
+ }
+
+ struct foo {
+ a: i32,
+ b: f32,
+ };
+}
--- /dev/null
+fn not_void() -> i32 {
+ 8
+}
+
+fn main() {
+ not_void();
+}
--- /dev/null
+fn foo() {
+ 8;
+ 8;
+}
+
+fn bar() -> i32 {
+ 8;
+ 8
+}
+
+fn baz() -> i32 {
+ 8;
+ return 8;
+}
+
+fn main() {
+ let a = foo(); // { dg-warning "unused name" }
+ let b = bar(); // { dg-warning "unused name" }
+ let c = baz(); // { dg-warning "unused name" }
+}
--- /dev/null
+fn test(a: i32) -> i32 {
+ a + 1
+}
+
+fn main() {
+ let a = test;
+ let b = a(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test(a: i32) -> i32 {
+ a + 1
+}
+
+fn main() {
+ let a: fn(i32) -> i32 = test;
+ let b = a(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: fn(i32) -> i32,
+ b: i32,
+}
+
+fn test(a: i32) -> i32 {
+ a + 1
+}
+
+fn main() {
+ let a = test(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b: fn(i32) -> i32 = test;
+ let c = b(1);
+
+ let d = Foo { a: test, b: c };
+ let e = (d.a)(d.b);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test(a: i32) -> i32 {
+ a + 1
+}
+
+fn main() {
+ let a: fn(_) -> _ = test;
+ let b = a(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: f32,
+ b: bool,
+}
+
+struct GenericStruct<T> {
+ a: T,
+ b: usize,
+}
+
+fn main() {
+ let a1;
+ a1 = Foo { a: 1.0, b: false };
+
+ let b1: f32 = a1.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c1: bool = a1.b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a2: GenericStruct<i8>;
+ a2 = GenericStruct::<i8> { a: 1, b: 456 };
+
+ let b2: i8 = a2.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c2: usize = a2.b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a3;
+ a3 = GenericStruct::<i32> { a: 123, b: 456 };
+
+ let b3: i32 = a3.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c3: usize = a3.b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a4;
+ a4 = GenericStruct { a: 1.0, b: 456 };
+
+ let b4: f32 = a4.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c4: usize = a4.b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a5;
+ a5 = GenericStruct::<_> { a: true, b: 456 };
+
+ let b5: bool = a5.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c5: usize = a5.b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T);
+
+struct Bar<T> {
+ a: Foo<T>,
+ b: bool,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn test<T>(a: Bar<T>) -> Foo<T> {
+ a.a
+}
+
+fn main() {
+ let a: Bar<i32> = Bar::<i32> {
+ a: Foo::<i32>(123),
+ b: true,
+ };
+ let b: Foo<i32> = test(a);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T, u32);
+
+type TypeAlias = Foo<i32>;
+
+fn main() {
+ let a: Foo<i32>;
+ a = TypeAlias { 0: 123, 1: 456 };
+}
--- /dev/null
+struct GenericStruct<T>(T, usize);
+
+impl GenericStruct<i32> {
+ fn new(a: i32, b: usize) -> Self {
+ GenericStruct(a, b)
+ }
+
+ fn get(self) -> i32 {
+ self.0
+ }
+}
+
+fn main() {
+ let a: GenericStruct<i32> = GenericStruct::<i32>::new(123, 456);
+ let aa: i32 = a.get();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<A> {
+ a: A,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+struct GenericStruct<T> {
+ a: T,
+ b: usize,
+}
+
+impl Foo<isize> {
+ fn test() -> i32 {
+ 123
+ }
+
+ fn bar(self) -> isize {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ self.a
+ }
+}
+
+fn main() {
+ let a: i32 = Foo::test();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a2: GenericStruct<i8>;
+ a2 = GenericStruct::<i8> { a: 1, b: 456 };
+
+ let b2: i8 = a2.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c2: usize = a2.b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a4;
+ a4 = GenericStruct { a: 1.0, b: 456 };
+
+ let b4: f32 = a4.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c4: usize = a4.b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<A> {
+ a: A,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl Foo<isize> {
+ fn test() -> i32 {
+ 123
+ }
+
+ fn bar(self) -> isize {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ self.a
+ }
+}
+
+fn main() {
+ let a: i32 = Foo::test();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T, bool);
+
+impl Foo<i32> {
+ fn bar(self) -> i32 {
+ self.0
+ }
+}
+
+impl Foo<f32> {
+ fn bar(self) -> f32 {
+ self.0
+ }
+}
+
+fn main() {
+ let a = Foo(123, true);
+ let aa = a.bar();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b = Foo(456f32, true);
+ let bb = b.bar();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T, bool);
+
+impl Foo<i32> {
+ fn new() -> Self {
+ Foo(123, true)
+ }
+
+ fn bar(self) -> i32 {
+ self.0
+ }
+}
+
+impl Foo<f32> {
+ fn new() -> Self {
+ Foo(123f32, true)
+ }
+
+ fn bar(self) -> f32 {
+ self.0
+ }
+}
+
+fn main() {
+ let a = Foo::<i32>::new();
+ let aa: i32 = a.bar();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b = Foo::<f32>::new();
+ let bb: f32 = b.bar();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T);
+
+impl<X> Foo<X> {
+ fn new(a: X) -> Self {
+ Self(a)
+ }
+
+ fn test(self) -> X {
+ self.0
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo::new(123);
+
+ let b = a.test();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T);
+
+impl<X> Foo<X> {
+ fn new(a: X) -> Self {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ Self(a)
+ }
+
+ fn test(self) -> X {
+ self.0
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo(123);
+
+ let b = a.test();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<X, Y>(X, Y);
+
+impl<T> Foo<u32, T> {
+ fn new(a: T) -> Self {
+ Self(123, a)
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo::new(false);
+}
--- /dev/null
+struct Foo(f32, bool);
+
+struct GenericStruct<T>(T, usize);
+
+fn main() {
+ let a1;
+ a1 = Foo(1.0, false);
+
+ let b1: f32 = a1.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c1: bool = a1.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a2: GenericStruct<i8>;
+ a2 = GenericStruct::<i8>(1, 456);
+
+ let b2: i8 = a2.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c2: usize = a2.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a3;
+ a3 = GenericStruct::<i32>(123, 456);
+
+ let b3: i32 = a3.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c3: usize = a3.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a4;
+ a4 = GenericStruct(1.0, 456);
+
+ let b4: f32 = a4.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c4: usize = a4.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a5;
+ a5 = GenericStruct::<_>(true, 456);
+
+ let b5: bool = a5.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let c5: usize = a5.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl<T> Foo<T, T> {
+ fn new(a: T, b: T) -> Self {
+ Self(a, b)
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo::new(123, 456);
+}
--- /dev/null
+fn callee<T>(t: &T) -> i32 {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ 32
+}
+
+fn caller(t: i32) -> i32 {
+ callee(&t)
+}
+
+fn main() {
+ let a;
+ a = caller(123);
+}
--- /dev/null
+fn callee<T>(t: (T, bool)) -> i32 {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ 32
+}
+
+fn caller(t: i32) -> i32 {
+ callee((t, false))
+}
+
+fn main() {
+ let a;
+ a = caller(123);
+}
--- /dev/null
+struct Foo<A = f32>(A);
+
+fn main() {
+ let a: Foo;
+ a = Foo(123f32);
+}
--- /dev/null
+struct Foo<A = (isize, char)> {
+ a: A,
+}
+
+impl Foo<isize> {
+ fn bar(self) -> isize {
+ self.a
+ }
+}
+
+impl Foo<char> {
+ fn bar(self) -> char {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ self.a
+ }
+}
+
+impl Foo {
+ fn bar(self) {
+ let a: (isize, char) = self.a;
+ let b = a.0;
+ let c = a.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let aa: Foo<isize> = Foo { a: b };
+ let bb: isize = aa.bar();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ }
+}
+
+fn main() {
+ let a = Foo { a: (123, 'a') };
+ a.bar();
+}
--- /dev/null
+struct Foo<A, B = (A, A)>(A, B);
+
+fn main() {
+ let a: Foo<bool>;
+ a = Foo::<bool>(true, (false, true));
+
+ let b: (bool, bool);
+ b = a.1;
+}
--- /dev/null
+// github issue #415
+fn test<A, B>(a: A, b: B) -> (A, B) {
+ (a, b)
+}
+
+fn main() {
+ let a = test::<i32, i32>(123, 456);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b = test::<f32, f32>(123f32, 456f32);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c = test::<_, _>(123, 456f32);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let d = test(true, 1234);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let e = test((123, false), 123f32);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// github issue #415
+fn test<A>(a: &A) -> &A {
+ a
+}
+
+fn main() {
+ let a = 123;
+ let b = &a;
+ let c = test(b);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a = 123f32;
+ let b = &a;
+ let c = test(b);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl Foo<i32, f32> {
+ fn test<X>(a: X) -> X {
+ a
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo::test::<_>(123);
+
+ let b;
+ b = Foo::test::<bool>(true);
+
+ let c;
+ c = Foo::test(456f32);
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl Foo<i32, f32> {
+ fn test<X>(self, a: X) -> X {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ a
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo(123, 456f32);
+
+ let b;
+ b = a.test::<bool>(false);
+}
--- /dev/null
+fn test<T>(a: T) -> T {
+ a
+}
+
+fn main() {
+ let a;
+ a = test(123);
+ let aa: i32 = a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b;
+ b = test::<u32>(456);
+ let bb: u32 = b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl<T> Foo<T, f32> {
+ fn test<X>(self, a: X) -> X {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ a
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo(123, 456f32);
+
+ let b;
+ b = a.test::<bool>(false);
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl<T> Foo<T, f32> {
+ fn test<X>(self, a: X) -> (T, X) {
+ (self.0, a)
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo(123, 456f32);
+
+ let b;
+ b = a.test::<bool>(false);
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+impl<T> Foo<T, f32> {
+ fn test<X>(self, a: X) -> (T, X) {
+ (self.0, a)
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo(123, 456f32);
+
+ let b;
+ b = a.test(false);
+}
--- /dev/null
+struct Foo<T> {
+ a: T,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ b: bool,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn test<T>(a: T) -> Foo<T> {
+ Foo { a: a, b: true }
+}
+
+fn main() {
+ let a: Foo<i32> = test(123);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b: Foo<u32> = test(456);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test<T>(a: T) -> T {
+ a
+}
+
+fn main() {
+ let a: i32 = test(123);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b: i32 = test(456);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T);
+
+struct Bar<T> {
+ a: Foo<T>,
+ b: bool,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let a: Bar<i32> = Bar::<i32> {
+ a: Foo::<i32>(123),
+ b: true,
+ };
+ let b: i32 = a.a.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T);
+
+struct Bar {
+ a: Foo<i32>,
+ b: bool,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let a = Foo::<i32>(123);
+ let b: Bar = Bar { a: a, b: true };
+ let c: i32 = b.a.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct GenericStruct<T>(T, usize);
+
+impl<T> GenericStruct<T> {
+ fn new(a: T, b: usize) -> Self {
+ GenericStruct(a, b)
+ }
+}
+
+fn main() {
+ let a: GenericStruct<i32> = GenericStruct::<i32>::new(123, 456);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b: GenericStruct<u32> = GenericStruct::<_>::new(123, 456);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c: GenericStruct<f32> = GenericStruct::new(123f32, 456);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct GenericStruct<T>(T, usize);
+
+impl<T> GenericStruct<T> {
+ fn new(a: T, b: usize) -> Self {
+ GenericStruct(a, b)
+ }
+
+ fn get(self) -> T {
+ self.0
+ }
+}
+
+fn main() {
+ let a: GenericStruct<i32> = GenericStruct::<i32>::new(123, 456);
+ let aa: i32 = a.get();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b: GenericStruct<u32> = GenericStruct::<_>::new(123, 456);
+ let bb: u32 = b.get();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c: GenericStruct<f32> = GenericStruct::new(123f32, 456);
+ let cc: f32 = c.get();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn foo() {}
+
+
+fn main() {
+ let _a = (foo());
+}
\ No newline at end of file
--- /dev/null
+struct I();
+
+impl I {
+ fn () {
+ // { dg-error {expecting 'identifier' but '\(' found} "" { target *-*-* } .-1 }
+ // { dg-error {failed to parse inherent impl item in inherent impl} "" { target *-*-* } .-2 }
+ // { dg-error {failed to parse item in crate} "" { target *-*-* } .-3 }
+ }
+}
+
+impl I {
+ unsafe fn () {
+ // { dg-error {expecting 'identifier' but '\(' found} "" { xfail *-*-* } .-1 }
+ }
+}
+
+fn main() {
+ let _i = I();
+}
--- /dev/null
+fn foo() -> bool {
+ true
+}
+
+fn bar() {}
+
+struct Foo1 {
+ one: i32
+}
+
+
+fn main() {
+ if foo() {
+ bar();
+ let a = Foo1{one: 1};
+ a.one
+ }
+
+}
\ No newline at end of file
--- /dev/null
+fn foo() -> bool {
+ true
+}
+
+fn bar() -> bool {
+ false
+}
+
+struct Foo1 {
+ one: i32
+}
+
+
+fn main() {
+ if foo() {
+ } else if bar() {
+ let a = Foo1{one: 1};
+ a.one;
+ }
+}
\ No newline at end of file
--- /dev/null
+fn test(x: i32) -> i32 {
+ if x == 10 {
+ 123
+ } else if x < 10 {
+ 456
+ } else {
+ 789
+ }
+}
+
+fn main() {
+ let a = test(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn foo() -> bool {
+ true
+}
+
+fn bar() {}
+
+struct Foo1 {
+ one: i32
+}
+
+
+fn main() {
+ if foo() {
+ bar();
+ } else {
+ let a = Foo1{one: 1};
+ a.one;
+ }
+}
\ No newline at end of file
--- /dev/null
+extern "C"
+{
+ pub fn abort ();
+}
+
+struct B { b: bool }
+
+pub fn main ()
+{
+ let n = 1;
+ if 0 > -n { } else { unsafe { abort (); } }
+
+ let b = true;
+ if !b { unsafe { abort (); } }
+ if !!b { } else { unsafe { abort (); } }
+
+ let bb = B { b: false };
+
+ if !bb.b && !b { unsafe { abort (); } }
+
+ if (B { b: true }).b { } else { unsafe { abort (); } }
+}
--- /dev/null
+struct Foo(i32, bool);
+
+impl Foo {
+ fn new(a: i32, b: bool) -> Foo {
+ Foo(a, b)
+ }
+
+ fn test2() -> i32 {
+ test_forward_decl()
+ }
+}
+
+fn test_forward_decl() -> i32 {
+ 123
+}
+
+fn main() {
+ let a;
+ a = Foo::new(1, true);
+
+ let b;
+ b = Foo::test2();
+}
--- /dev/null
+struct Foo(i32, bool);
+
+impl Foo {
+ const number: i32 = 456;
+
+ fn new(a: i32, b: bool) -> Foo {
+ Foo(a, b)
+ }
+
+ fn test2() -> i32 {
+ test_forward_decl()
+ }
+}
+
+fn test_forward_decl() -> i32 {
+ 123
+}
+
+fn main() {
+ let a;
+ a = Foo::new(1, true);
+
+ let b;
+ b = Foo::test2();
+
+ let c;
+ c = Foo::new(Foo::number, true);
+}
--- /dev/null
+struct Point {
+ x: f64,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ y: f64,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl Point {
+ fn origin() -> Point {
+ Point { x: 0.0, y: 0.0 }
+ }
+
+ fn new(x: f64, y: f64) -> Point {
+ Point { x: x, y: y }
+ }
+}
+
+struct Rectangle {
+ p1: Point,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ p2: Point,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl Rectangle {
+ fn from(p1: Point, p2: Point) -> Self {
+ Self { p1, p2 }
+ }
+}
+
+fn main() {
+ let p1 = Point::origin();
+ let p2 = Point::new(3.0, 4.0);
+ let rect = Rectangle::from(p1, p2);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo(i32, bool);
+
+impl Foo {
+ fn new(a: i32, b: bool) -> Foo {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ Foo(a, b)
+ }
+
+ fn test2() -> i32 {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ 1
+ }
+}
+
+fn main() {
+ let _a = Foo(1, true);
+}
--- /dev/null
+fn test1() -> i32 {
+ 1
+}
+
+fn test2() -> i32 {
+ return 2;
+}
+
+fn test3(x: i32) -> i32 {
+ if x > 1 {
+ 5
+ } else {
+ 0
+ }
+}
+
+fn test4(x: i32) -> i32 {
+ if x > 1 {
+ return 1;
+ }
+ 0
+}
+
+fn test5(x: i32) -> i32 {
+ if x > 1 {
+ if x == 5 {
+ 7
+ } else {
+ 9
+ }
+ } else {
+ 0
+ }
+}
+
+fn test6(x: i32) -> i32 {
+ if x > 1 {
+ return 5;
+ } else {
+ return 0;
+ }
+}
+
+fn test7(x: i32) -> i32 {
+ if x > 1 {
+ return 5;
+ } else {
+ return 0;
+ }
+}
+
+fn test8() -> i32 {
+ return 1;
+}
+
+fn main() {
+ let call1 = test1();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call2 = test2();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call3 = test3(3);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call4 = test4(4);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call5 = test5(5);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call6 = test6(6);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call7 = test7(7);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let call8 = test8();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let array: [_; 2] = [111, 222];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+#![allow(dead_code)]
+#![allow(unused_variables)]
+pub fn main () { }
--- /dev/null
+const TEST_CONST: i32 = 10;
+
+fn main() {
+ let a;
+ a = TEST_CONST;
+}
--- /dev/null
+fn main() {
+ let a = 1u32;
+
+ let b;
+ b = a;
+}
--- /dev/null
+fn test(a: u32) -> u32 {
+ a + 1
+}
+
+fn main() {
+ let param;
+ param = 123;
+
+ let a = test(param);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let a;
+ a = 1;
+}
--- /dev/null
+const TEST_CONST: i32 = 10;
+
+fn test(x: u32) -> u32 {
+ x + 1
+}
+
+fn main() {
+ let x = TEST_CONST;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a = 1u32;
+ let b = a;
+
+ let c;
+ c = 1;
+
+ let d;
+ d = b;
+
+ let param;
+ param = 123;
+
+ let test_call = test(param);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-prune-output "warning: unused name" } as there are many of these expected.
+
+fn main() {
+ let a1: i8 = 1i8;
+ let a2: i16 = 2i16;
+ let a3: i32 = 3i32;
+ let a4: i64 = 4i64;
+ let a5: i128 = 5i128;
+
+ let b1 = 1i8;
+ let b2 = 2i16;
+ let b3 = 3i32;
+ let b4 = 4i64;
+ let b5 = 5i128;
+
+ let c1: u8 = 1u8;
+ let c2: u16 = 2u16;
+ let c3: u32 = 3u32;
+ let c4: u64 = 4u64;
+ let c5: u128 = 5u128;
+
+ let d1 = 1u8;
+ let d2 = 2u16;
+ let d3 = 3u32;
+ let d4 = 4u64;
+ let d5 = 5u128;
+}
--- /dev/null
+// { dg-additional-options -fdump-tree-original }
+
+#![feature(intrinsics)]
+
+extern "rust-intrinsic" {
+ pub fn sqrtf32(x: f32) -> f32;
+ pub fn sinf32(x: f32) -> f32;
+}
+
+fn main() {
+ unsafe fn foo() {
+ let mut f32;
+
+ f32 = sqrtf32(5f32);
+ // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sqrtf \(5\.0e\+0\);$} 1 original } }
+
+ f32 = sinf32(39f32);
+ // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sinf \(3\.9e\+1\);$} 1 original } }
+ }
+
+ unsafe { foo() };
+}
--- /dev/null
+// { dg-additional-options -fdump-tree-original }
+
+#![feature(intrinsics)]
+
+extern "rust-intrinsic" {
+ pub fn size_of<T>() -> usize;
+}
+
+fn main() -> i32 {
+ unsafe fn foo() -> usize {
+ let f: f32;
+
+ let s_f32 = size_of::<f32>();
+ let s_f64 = size_of::<f64>();
+ let s_f32_again = size_of::<f32>();
+
+ s_f32 + s_f64 + s_f32_again
+ }
+
+ // useless code, just used for function compilation caching
+ unsafe { foo() as i32 }
+}
--- /dev/null
+/* comment cr\r is allowed */
+pub fn main () { }
--- /dev/null
+// comment cr\r is allowed
+pub fn main () { }
--- /dev/null
+extern "rust-intrinsic" {
+ pub fn size_of<T>() -> usize;
+}
+
+fn test() -> usize {
+ unsafe { size_of::<i32>() }
+}
+
+fn main() {
+ let _a = test();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+extern "rust-intrinsic" {
+ #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
+ pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
+}
+
+struct FatPtr<T> {
+ data: *const T,
+ len: usize,
+}
+
+union Repr<T> {
+ rust: *const [T],
+ rust_mut: *mut [T],
+ raw: FatPtr<T>,
+}
+
+impl<T> *const [T] {
+ pub const fn len(self) -> usize {
+ // SAFETY: this is safe because `*const [T]` and `FatPtr<T>` have the same layout.
+ // Only `std` can make this guarantee.
+ unsafe { Repr { rust: self }.raw.len }
+ }
+
+ pub const fn as_ptr(self) -> *const T {
+ self as *const T
+ }
+}
+
+impl<T> *const T {
+ pub const unsafe fn offset(self, count: isize) -> *const T {
+ unsafe { offset(self, count) }
+ }
+
+ pub const unsafe fn add(self, count: usize) -> Self {
+ unsafe { self.offset(count as isize) }
+ }
+
+ pub const fn as_ptr(self) -> *const T {
+ self as *const T
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+mod intrinsics {
+ extern "rust-intrinsic" {
+ #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
+ pub fn wrapping_add<T>(a: T, b: T) -> T;
+ #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
+ pub fn rotate_left<T>(a: T, b: T) -> T;
+ #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
+ pub fn rotate_right<T>(a: T, b: T) -> T;
+ #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
+ pub fn offset<T>(ptr: *const T, count: isize) -> *const T;
+ }
+}
+
+mod mem {
+ extern "rust-intrinsic" {
+ #[rustc_const_stable(feature = "const_transmute", since = "1.46.0")]
+ fn transmute<T, U>(_: T) -> U;
+ #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
+ fn size_of<T>() -> usize;
+ }
+}
+
+macro_rules! impl_uint {
+ ($($ty:ident = $lang:literal),*) => {
+ $(
+ impl $ty {
+ pub fn wrapping_add(self, rhs: Self) -> Self {
+ // intrinsics::wrapping_add(self, rhs)
+ self + rhs
+ }
+
+ pub fn rotate_left(self, n: u32) -> Self {
+ unsafe {
+ intrinsics::rotate_left(self, n as Self)
+ }
+ }
+
+ pub fn rotate_right(self, n: u32) -> Self {
+ unsafe {
+ intrinsics::rotate_right(self, n as Self)
+ }
+ }
+
+ pub fn to_le(self) -> Self {
+ #[cfg(target_endian = "little")]
+ {
+ self
+ }
+ }
+
+ pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+ Self::from_le(Self::from_ne_bytes(bytes))
+ }
+
+ pub const fn from_le(x: Self) -> Self {
+ #[cfg(target_endian = "little")]
+ {
+ x
+ }
+ }
+
+ pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+ unsafe { mem::transmute(bytes) }
+ }
+ }
+ )*
+ }
+}
+
+impl_uint!(
+ u8 = "u8",
+ u16 = "u16",
+ u32 = "u32",
+ u64 = "u64",
+ usize = "usize"
+);
--- /dev/null
+// { dg-options "-w" }
+const BLOCK_LEN: usize = 64;
+
+const IV: [u32; 8] = [
+ 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19,
+];
+
+struct ChunkState {
+ chaining_value: [u32; 8],
+ chunk_counter: u64,
+ block: [u8; BLOCK_LEN],
+ block_len: u8,
+ blocks_compressed: u8,
+ flags: u32,
+}
+
+impl ChunkState {
+ fn new(key_words: [u32; 8], chunk_counter: u64, flags: u32) -> Self {
+ Self {
+ chaining_value: key_words,
+ chunk_counter,
+ block: [0; BLOCK_LEN],
+ block_len: 0,
+ blocks_compressed: 0,
+ flags,
+ }
+ }
+}
+
+pub struct Hasher {
+ chunk_state: ChunkState,
+ key_words: [u32; 8],
+ cv_stack: [[u32; 8]; 54], // Space for 54 subtree chaining values:
+ cv_stack_len: u8, // 2^54 * CHUNK_LEN = 2^64
+ flags: u32,
+}
+
+impl Hasher {
+ fn new_internal(key_words: [u32; 8], flags: u32) -> Self {
+ Self {
+ chunk_state: ChunkState::new(key_words, 0, flags),
+ key_words,
+ cv_stack: [[0; 8]; 54],
+ cv_stack_len: 0,
+ flags,
+ }
+ }
+
+ /// Construct a new `Hasher` for the regular hash function.
+ pub fn new() -> Self {
+ Self::new_internal(IV, 0)
+ }
+}
--- /dev/null
+struct S;
+
+fn foo<S>(s: S) -> S {
+ s
+}
+
+fn main() {
+ let _s: S = foo(S);
+}
--- /dev/null
+pub trait Foo {
+ type Target;
+
+ fn bar(&self) -> &Self::Target;
+}
+
+impl<T> Foo for &T {
+ type Target = T;
+
+ fn bar(&self) -> &T {
+ *self
+ }
+}
+
+pub fn main() {
+ let a: i32 = 123;
+ let b: &i32 = &a;
+
+ b.bar();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
+
+#[lang = "deref"]
+pub trait Deref {
+ type Target;
+
+ fn deref(&self) -> &Self::Target;
+}
+
+impl<T> Deref for &T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ unsafe {
+ let a = "imm_deref\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+
+ *self
+ }
+}
+
+impl<T> Deref for &mut T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ unsafe {
+ let a = "mut_deref\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+
+ *self
+ }
+}
+
+struct Foo<T>(T);
+impl<T> Deref for Foo<T> {
+ type Target = T;
+
+ fn deref(&self) -> &Self::Target {
+ unsafe {
+ let a = "foo_deref\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+
+ &self.0
+ }
+}
+
+struct Bar(i32);
+impl Bar {
+ fn cake(self) -> i32 {
+ self.0 + 1
+ }
+}
+
+pub fn main() {
+ let foo: Foo<Bar> = Foo(Bar(123));
+ let bar: Bar = *foo;
+
+ let cake_result: i32 = foo.cake();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+struct Foo<T>(T);
+impl<T> Foo<T> {
+ fn new<Y>(a: T, b: Y) -> Self {
+ Self(a)
+ }
+}
+
+struct Bar<T>(T);
+impl Bar<i32> {
+ fn baz(self) {}
+
+ fn test() -> i32 {
+ 123
+ }
+}
+
+struct Baz<A, B>(A, B);
+impl Baz<i32, f32> {
+ fn test<X>(a: X) -> X {
+ a
+ }
+}
+
+pub fn main() {
+ let a = Foo::<i32>::new::<f32>(123, 456f32);
+ let b = Foo::new::<f32>(123, 456f32);
+
+ let c = Bar::<i32>(123);
+ let d = Bar::baz(c);
+
+ let e = Bar::test();
+
+ let f = Baz::test::<bool>(true);
+}
--- /dev/null
+// { dg-additional-options "-w" }
+struct Foo<T>(T);
+impl<T> Foo<T> {
+ fn new<Y>(a: T, b: Y) -> Self {
+ Self(a)
+ }
+}
+
+pub fn test() {
+ let a = Foo::<i32>::new::<f32>(123, 456f32);
+}
--- /dev/null
+fn foo() -> bool {
+ return true;
+}
+
+fn bar() -> bool {
+ return false;
+}
+
+
+
+fn main() {
+ let _a = true && foo();
+ let _b = true || bar();
+}
\ No newline at end of file
--- /dev/null
+fn foo<'a>(t: &'a str) -> &'a str {
+ t
+}
+
+fn main() {
+ foo("hello world");
+}
--- /dev/null
+// { dg-prune-output "warning: unused name" } as there are many of these expected.
+
+fn main() {
+ let hex: i32 = 0xFF;
+ let binary: i32 = 0b11110000;
+ let oct: i32 = 0o70;
+
+ let hex_u8: u8 = 0xFF_u8;
+ let bin_u16: u16 = 0b1111000011110000_u16;
+ let oct: u32 = 0o70_u32;
+}
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ loop {
+ let c = a + b;
+ a = b;
+ b = c;
+ }
+}
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ // first number in Fibonacci sequence over 10:
+ loop {
+ if b > 10 {
+ break;
+ }
+ let c = a + b;
+ a = b;
+ b = c;
+ }
+}
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ // first number in Fibonacci sequence over 10:
+ loop {
+ if b > 10 {
+ return;
+ }
+ let c = a + b;
+ a = b;
+ b = c;
+ }
+}
--- /dev/null
+fn main() {
+ 'outer: loop {
+ 'inner: loop {
+ break 'outer;
+ }
+ }
+}
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ // first number in Fibonacci sequence over 10:
+ let _fib = loop {
+ if b > 10 {
+ break b;
+ }
+ let c = a + b;
+ a = b;
+ b = c;
+ };
+}
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ let mut c;
+ while b > 10 {
+ c = a + b;
+ a = b;
+ b = c;
+ }
+}
--- /dev/null
+fn main() {
+ let mut a = 1;
+ let mut b = 1;
+
+ let _fib = loop {
+ if (a % 2 == 0) {
+ continue;
+ }
+ let c = a + b;
+ a = b;
+ b = c;
+ };
+}
--- /dev/null
+macro_rules! stmt {
+ ($s:stmt) => {
+ $s
+ };
+ ($s:stmt, $($ss:stmt),*) => {
+ $s;
+ stmt!($($ss),*);
+ };
+}
+
+fn main() {
+ stmt!(
+ struct S;
+ );
+ stmt!(
+ struct A;,
+ struct B;,
+ struct C;,
+ struct D;,
+ struct E;
+ );
+}
+
--- /dev/null
+// { dg-additional-options -fdump-tree-ccp1-raw }
+
+macro_rules! stmt {
+ ($s:stmt) => {
+ $s
+ };
+ ($s:stmt, $($ss:stmt),*) => {
+ $s;
+ stmt!($($ss),*);
+ };
+}
+
+pub fn test() -> i32 {
+ stmt!(
+ let a = 1
+ // { dg-warning {unused name 'a'} {} { target *-*-* } .-1 }
+ );
+ stmt!(
+ let b = 2,
+ let c = 3,
+ let d = 4,
+ let e = 5,
+ let f = b + c + d + e
+ );
+ f
+ // { dg-final { scan-tree-dump-times {gimple_return <14>} 1 ccp1 { target __OPTIMIZE__ } } }
+}
+
+fn main() {
+ let _ = test();
+}
+
--- /dev/null
+// { dg-additional-options "-w" }
+
+macro_rules! add {
+ ($a:expr) => { $a };
+ ($a:expr, $($b:expr),+) => { $a + add!($($b),*) }
+}
+
+fn main() -> i32 {
+ if add!(add!(1, 2)) > add!(5) {
+ add!(1, add!(2, 3), add!(4))
+ } else {
+ add!(5, add!(6, 7), add!(8), 9) + 10
+ }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+enum Foo {
+ A,
+ B,
+ C(char),
+ D { x: i64, y: i64 },
+}
+
+fn inspect(f: Foo) {
+ match f {
+ Foo::A => {}
+ Foo::B => {}
+ Foo::C(x) => {}
+ Foo::D { x, y } => {}
+ }
+}
--- /dev/null
+struct Point {
+ x: f64,
+ y: f64,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl Point {
+ fn origin() -> Point {
+ Point { x: 0.0, y: 0.0 }
+ }
+
+ fn new(x: f64, y: f64) -> Point {
+ Point { x: x, y: y }
+ }
+}
+
+struct Rectangle {
+ p1: Point,
+ p2: Point,
+}
+
+impl Rectangle {
+ fn from(p1: Point, p2: Point) -> Self {
+ Self { p1, p2 }
+ }
+
+ fn sum_x(self) -> f64 {
+ let p1 = self.p1;
+ let p2 = self.p2;
+ p1.x + p2.x
+ }
+}
+
+fn main() {
+ let p1 = Point::origin();
+ let p2 = Point::new(3.0, 4.0);
+ let rect = Rectangle::from(p1, p2);
+
+ let sum = rect.sum_x();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Point {
+ x: f64,
+ y: f64,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl Point {
+ fn origin() -> Point {
+ Point { x: 0.0, y: 0.0 }
+ }
+
+ fn new(x: f64, y: f64) -> Point {
+ Point { x: x, y: y }
+ }
+}
+
+struct Rectangle {
+ p1: Point,
+ p2: Point,
+}
+
+impl Rectangle {
+ fn from(p1: Point, p2: Point) -> Self {
+ Self { p1, p2 }
+ }
+}
+
+fn main() {
+ let p1 = Point::origin();
+ let p2 = Point::new(3.0, 4.0);
+ let rect = Rectangle::from(p1, p2);
+
+ let sum = rect.sum_x();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
+
+impl Rectangle {
+ fn sum_x(self) -> f64 {
+ let p1 = self.p1;
+ let p2 = self.p2;
+ p1.x + p2.x
+ }
+}
--- /dev/null
+struct Point {
+ x: f64,
+ y: f64,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl Point {
+ fn origin() -> Point {
+ Point { x: 0.0, y: 0.0 }
+ }
+
+ fn new(x: f64, y: f64) -> Point {
+ Point { x: x, y: y }
+ }
+}
+
+struct Rectangle {
+ p1: Point,
+ p2: Point,
+}
+
+impl Rectangle {
+ fn from(p1: Point, p2: Point) -> Self {
+ Self { p1, p2 }
+ }
+
+ fn sum_x(self) -> f64 {
+ let p1 = self.p1;
+ let p2 = self.p2;
+ p1.x + p2.x
+ }
+}
+
+fn main() {
+ let p1 = Point::origin();
+ let p2 = Point::new(3.0, 4.0);
+ let rect = Rectangle::from(p1, p2);
+
+ let sum = rect.sum_x();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ // multiple MethodCallExpr were causing issue #310
+ let sum = rect.sum_x();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+mod foo {
+ struct A; // { dg-warning "struct is never constructed" }
+}
+
+fn main() {}
--- /dev/null
+// This is testing name resolution
+
+mod _foo {
+ struct _A;
+}
+
+mod _bar {
+ mod _barbis {
+ struct _B;
+ }
+}
--- /dev/null
+mod foomod {
+ pub struct Foo {}
+}
+
+impl foomod::Foo {
+ pub fn new() -> Self {
+ foomod::Foo {}
+ }
+}
+
+fn main() {
+ let _a = foomod::Foo::new();
+}
--- /dev/null
+// { dg-additional-options "-w" }
+mod A {
+ pub mod B {
+ pub mod C {
+ pub struct Foo {
+ pub f: i32,
+ }
+ impl Foo {
+ pub fn new() -> Self {
+ Foo { f: 23i32 }
+ }
+ }
+ }
+ }
+}
+
+fn main() -> i32 {
+ let a = A::B::C::Foo::new();
+ let b = A::B::C::Foo { f: -23i32 };
+
+ a.f - b.f
+}
--- /dev/null
+pub fn return_12() -> i32 {
+ 12
+}
--- /dev/null
+fn unused() {}
--- /dev/null
+#[must_use = "TEST 1"]
+fn test1() -> i32 {
+ 123
+}
+
+#[must_use = "TEST 2"]
+fn test2() -> i32 {
+ 456
+}
+
+fn main() {
+ let _a = test1();
+
+ test2();
+ // { dg-warning "ignoring return value of" "" { target *-*-* } .-1 }
+}
--- /dev/null
+trait A {
+ #[must_use]
+ fn test() -> i32;
+}
+
+struct S;
+impl A for S {
+ fn test() -> i32 {
+ 123
+ }
+}
+
+fn main() {
+ S::test();
+ // { dg-warning "ignoring return value of" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo(i32, bool);
+
+impl Foo {
+ fn new(a: i32, b: bool) -> Foo {
+ Foo(a, b)
+ }
+
+ fn test() -> i32 {
+ test()
+ }
+}
+
+fn test() -> i32 {
+ 123
+}
+
+fn main() {
+ let a;
+ a = Foo::new(1, true);
+
+ let b;
+ b = Foo::test();
+}
--- /dev/null
+fn ret1() -> i32 {
+ return 1;
+}
+
+fn main() {
+ let _a = -ret1();
+}
\ No newline at end of file
--- /dev/null
+pub fn main() {
+ let a = 123;
+
+ fn test(x: i32) -> i32 {
+ x + 456
+ }
+
+ let b;
+ b = test(a);
+}
--- /dev/null
+pub fn main() {
+ fn test<T>(x: T) -> T {
+ x
+ }
+
+ let mut a = 123;
+ a = test(a);
+
+ let mut b = 456f32;
+ b = test(b);
+}
--- /dev/null
+struct Point {
+ x: f64,
+ y: f64,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+struct Rectangle {
+ p1: Point,
+ p2: Point,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let p1 = Point { x: 0.0, y: 0.0 };
+ let p2 = Point { x: 2.0, y: 4.0 };
+ let rect = Rectangle { p1, p2 };
+
+ let a = rect.p1.x;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn foo() -> i32 {
+ let c;
+ let d;
+
+ c = if false {
+ return 1;
+ } else {
+ 0.0
+ };
+
+ d = if true {
+ 0.0
+ } else {
+ return 1;
+ };
+
+ 0
+}
+
+fn main() {
+ foo();
+}
--- /dev/null
+#!
+[allow(unused)]
+fn main () { }
--- /dev/null
+#!/*/this/is/a/comment*/[allow(unused)] fn main () { }
--- /dev/null
+#!//this/is/a/comment
+[allow(unused)]
+fn main () { }
--- /dev/null
+#!//this/is/a/comment
+
+/* Also a /* nested */
+ multiline // comment
+ with some more whitespace after, but then finally a [, so not a real #! line. */
+
+[allow(unused)] fn main () { }
--- /dev/null
+#!
+
+ [allow(unused)]
+
+ fn main () { }
+
--- /dev/null
+fn test(a: i32, b: i32) -> i32 {
+ a + b
+}
+
+fn main() {
+ let a = test(1, 4);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let a = 123;
+ let b = a + (a * 2);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+pub fn main() {
+ let mut num = 2;
+ let r1: *const i32 = #
+ let r2 = unsafe { *r1 } + unsafe { *r1 };
+ let r3 = num;
+ num = 4;
+ let r4 = num + unsafe { *r1 } * r3;
+ let _eightteen = r2 + r3 + r4;
+}
--- /dev/null
+const TRUE: bool = true;
+const FALSE: bool = !TRUE;
+
+const U8ZERO: u8 = 0;
+const U8ONE: u8 = U8ZERO + 1;
+const U16ZERO: u16 = 0;
+const U16ONE: u16 = U16ZERO + 1;
+const U32ZERO: u32 = 0;
+const U32ONE: u32 = U32ZERO + 1;
+const U64ZERO: u64 = 0;
+const U64ONE: u64 = U64ZERO + 1;
+const U128ZERO: u128 = 0;
+const U128ONE: u128 = U128ZERO + 1;
+
+const I8ZERO: i8 = 0;
+const I8ONE: i8 = I8ZERO + 1;
+const I16ZERO: i16 = 0;
+const I16ONE: i16 = I16ZERO + 1;
+const I32ZERO: i32 = 0;
+const I32ONE: i32 = I32ZERO + 1;
+const I64ZERO: i64 = 0;
+const I64ONE: i64 = I64ZERO + 1;
+const I128ZERO: i128 = 0;
+const I128ONE: i128 = I128ZERO + 1;
+
+const F32ZERO: f32 = 0.0;
+const F32ONE: f32 = F32ZERO + 1.0;
+const F64ZERO: f64 = 0.0;
+const F64ONE: f64 = F64ZERO + 1.0;
+
+const USIZEZERO: usize = 0;
+const USIZEONE: usize = USIZEZERO + 1;
+const ISIZEZERO: isize = 0;
+const ISIZEONE: isize = ISIZEZERO + 1;
+
+/* Not yet supported
+const CHARPI: char = '\u{03C0}';
+const STRHELLO: &str = "Hello World!";
+*/
+
+extern "C" { fn abort (); }
+
+pub fn main ()
+{
+ if TRUE == FALSE { unsafe { abort (); } }
+ if U8ZERO > U8ONE { unsafe { abort (); } }
+ if U16ZERO > U16ONE { unsafe { abort (); } }
+ if U32ZERO > U32ONE { unsafe { abort (); } }
+ if U64ZERO > U64ONE { unsafe { abort (); } }
+ if U128ZERO > U128ONE { unsafe { abort (); } }
+
+ if I8ONE <= I8ZERO { unsafe { abort (); } }
+ if I16ONE <= I16ZERO { unsafe { abort (); } }
+ if I32ONE <= I32ZERO { unsafe { abort (); } }
+ if I64ONE <= I64ZERO { unsafe { abort (); } }
+ if I128ONE <= I128ZERO { unsafe { abort (); } }
+
+ if F32ZERO + F32ONE != F32ONE { unsafe { abort (); } }
+ if F64ZERO + F64ONE != F64ONE { unsafe { abort (); } }
+
+ if USIZEZERO + USIZEONE - USIZEONE + USIZEZERO != USIZEZERO
+ {
+ unsafe { abort (); }
+ }
+ if ISIZEZERO + ISIZEONE - ISIZEONE + ISIZEZERO != ISIZEZERO
+ {
+ unsafe { abort (); }
+ }
+
+ // if CHARPI != '\u{03c0}' { unsafe { abort (); } }
+ // if STRHELLO != "Hello World!" { unsafe { abort (); } }
+}
--- /dev/null
+extern "C"
+{
+ fn abort ();
+}
+
+struct Prims
+{
+ b1: bool,
+ b2: bool,
+ b3: bool,
+ b4: bool,
+ c1: char,
+ c2: char,
+ u81: u8,
+ u82: u8,
+ u83: u8,
+ u84: u8,
+ i81: i8,
+ i82: i8,
+ i83: i8,
+ i84: i8,
+ u161: u16,
+ u162: u16,
+ i161: i16,
+ i162: i16,
+ u321: u32,
+ u322: u32,
+ i321: i32,
+ i322: i32,
+ u641: u64,
+ i641: i64,
+ u1281: u128,
+ i1281: i128,
+ usize1: usize,
+ isize1: isize,
+}
+
+fn prims_eq (p1: Prims, p2: Prims) -> bool
+{
+ return p1.b1 == p2.b1
+ && p1.b2 == p2.b2
+ && p1.b3 == p2.b3
+ && p1.b4 == p2.b4
+ && p1.c1 == p2.c1
+ && p1.c2 == p2.c2
+ && p1.u81 == p2.u81
+ && p1.u82 == p2.u82
+ && p1.u83 == p2.u83
+ && p1.u84 == p2.u84
+ && p1.i81 == p2.i81
+ && p1.i82 == p2.i82
+ && p1.i83 == p2.i83
+ && p1.i84 == p2.i84
+ && p1.u161 == p2.u161
+ && p1.u162 == p2.u162
+ && p1.i161 == p2.i161
+ && p1.i162 == p2.i162
+ && p1.u321 == p2.u321
+ && p1.u322 == p2.u322
+ && p1.i321 == p2.i321
+ && p1.i322 == p2.i322
+ && p1.u641 == p2.u641
+ && p1.i641 == p2.i641
+ && p1.u1281 == p2.u1281
+ && p1.i1281 == p2.i1281
+ && p1.usize1 == p2.usize1
+ && p1.isize1 == p2.isize1;
+}
+
+pub fn main ()
+{
+ let p1 = Prims { b1: true, b2: false, b3: false, b4: true,
+ c1: 'a', c2: 'b',
+ u81: 1, u82: 2, u83: 3, u84: 4,
+ i81: -1, i82: -2, i83: -3, i84: -4,
+ u161: 1, u162: 2,
+ i161: -1, i162: -2,
+ u321: 1, u322: 2,
+ i321: -1, i322: -2,
+ u641: 1,
+ i641: -1,
+ u1281: 1,
+ i1281: -1,
+ usize1: 1,
+ isize1: -1 };
+ let p2 = Prims { usize1: 1, .. p1 };
+ let p3 = Prims { u1281: 0, .. p2 };
+ let p4 = Prims { i1281: 0, .. p3 };
+ if !prims_eq (p1, p2) { unsafe { abort (); } }
+ if prims_eq (p3, p4) { unsafe { abort (); } }
+}
--- /dev/null
+// { dg-additional-options "-w" }
+#[lang = "RangeFull"]
+pub struct RangeFull;
+
+#[lang = "Range"]
+pub struct Range<Idx> {
+ pub start: Idx,
+ pub end: Idx,
+}
+
+#[lang = "RangeFrom"]
+pub struct RangeFrom<Idx> {
+ pub start: Idx,
+}
+
+#[lang = "RangeTo"]
+pub struct RangeTo<Idx> {
+ pub end: Idx,
+}
+
+#[lang = "RangeInclusive"]
+pub struct RangeInclusive<Idx> {
+ pub start: Idx,
+ pub end: Idx,
+}
+
+fn test() {
+ let a = 1..2; // range
+ let b = 1..; // range from
+ let c = ..3; // range to
+ let d = 0..=2; // range inclusive
+}
--- /dev/null
+pub fn square(num: i32) -> i32 { /* { dg-warning "used" } */
+ r#num * num
+}
\ No newline at end of file
--- /dev/null
+pub fn plus(r#break: i32, r#unsafe: i32) -> i32 { /* { dg-warning "used" } */
+ r#break + r#unsafe
+}
\ No newline at end of file
--- /dev/null
+fn gcd(x: i32, y: i32) -> i32 {
+ if y == 0 {
+ x
+ } else {
+ gcd(y, x % y)
+ }
+}
+
+fn main() {
+ let a = gcd(100, 5);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn foo() {}
+
+fn main() {
+ return foo();
+}
--- /dev/null
+fn main() {
+ let x = 1;
+ {
+ let mut x = true;
+ {
+ x = false;
+ }
+ }
+ let x = x + 1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo(i32, bool);
+
+impl Foo {
+ fn new(a: i32, b: bool) -> Self {
+ Self(a, b)
+ }
+}
+
+fn main() {
+ let a;
+ a = Foo::new(1, true);
+}
--- /dev/null
+fn main() {
+ let mut x = 5;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let mut x;
+ x = true;
+}
--- /dev/null
+fn main() {
+ let x = 1;
+ let x = x + 1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+#!/usr/bin/env cat
+
+fn main () { }
--- /dev/null
+#!/usr/bin/env cat
+#![allow(unused)]
+fn main () { }
--- /dev/null
+#!//usr/bin/env cat
+#![allow(unused)]
+fn main () { }
--- /dev/null
+fn test(x: i32) -> i32 {
+ return x + 1;
+}
+
+fn main() {
+ let call_test = test(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+static x:i32 = 3;
+
+fn main() {
+ let y = x +1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test(x: i32) -> i32 {
+ if x > 1 { 1 } else { 2 };
+ if x > 1 { 1; } else { 2; }
+
+ { 3; }
+ { 3 };
+
+ { 3 }
+}
+
+fn main() {
+ let a = test(0); // { dg-warning "unused name" }
+}
--- /dev/null
+fn main() {
+ let a;
+ a = "hello world infer";
+
+ let b: &str;
+ b = "hello world specified";
+}
--- /dev/null
+struct Foo {
+ one: i32,
+ two: i32,
+}
+
+fn main() {
+ let struct_test = Foo { one: 1, two: 2 };
+ let a = struct_test.one;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = struct_test.two;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ b: i32,
+}
+
+fn foo() -> Foo {
+ Foo { a: 42, b: 32 }
+}
+
+fn main() {
+ let _f = Foo { a: 10, ..foo() };
+}
--- /dev/null
+// { dg-additional-options "-fdump-tree-gimple -frust-crate=example" }
+
+struct Foo {
+ a: u16,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ b: u8,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let my_foo = Foo { a: 1, b: 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ // { dg-final { scan-tree-dump-times {(?n)const struct example::Foo my_foo;$} 1 gimple } }
+}
--- /dev/null
+struct Foo {
+ one: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ two: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let struct_test = Foo { one: 1, two: 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ struct foo {
+ a: i32,
+ b: f32,
+ };
+
+ let a;
+ a = foo { a: 123, b: 456f32 };
+}
--- /dev/null
+pub fn main() {
+ struct O(i32);
+ struct T(i32, i32);
+ struct M(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32);
+
+ // tuples
+ let z = ();
+ let o = (0,);
+ let f = o.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let t = (0, 1);
+ let s = t.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let m = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ let l = m.10;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ // tuple structs
+ let so = O(0);
+ let sf = so.0;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let st = T(0, 1);
+ let fs = st.1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let sm = M(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ let sl = sm.10;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ z
+}
--- /dev/null
+struct Foo(f32, f32);
+
+fn main() {
+ let a = Foo { 0: 10.0, 1: 20.0 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ b: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let a = 1;
+ let b = 2;
+ let c = Foo { a, b };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ b: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let a = Foo { a: 1, b: 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = Foo { a: 3, b: 4, ..a };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: i32,
+ b: i32,
+}
+
+fn main() {
+ let a = Foo { a: 1, b: 2 };
+ let b = Foo { ..a };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: i32,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ b: i32,
+}
+
+fn main() {
+ let a = Foo { a: 1, b: 2 };
+ let b = Foo { a: 1, ..a };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ a: i32,
+ b: f32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let c = Foo { a: 1, b: 2f32 };
+ let b = Foo { b: 4f32, ..c };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo(f32, i32);
+
+fn main() {
+ let a = Foo { 1: 1, 0: 2f32 };
+ let b = Foo { ..a };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ struct foo(i32, f32);
+
+ let a;
+ a = foo(123, 456f32);
+}
--- /dev/null
+#![crate_name = "name"]
+
+
+#[allow(dead_code)]
+fn main() {}
\ No newline at end of file
--- /dev/null
+trait Foo {
+ fn bar() -> i32;
+}
+
+struct Test(i32, f32);
+
+impl Foo for Test {
+ fn bar() -> i32 {
+ 123
+ }
+}
+
+fn main() {
+ let a: i32;
+ a = Test::bar();
+}
--- /dev/null
+trait Foo // where
+// Self: Sized,
+{
+ fn get(self) -> i32;
+
+ fn test(self) -> i32 {
+ self.get()
+ }
+}
+
+struct Bar(i32);
+impl Foo for Bar {
+ fn get(self) -> i32 {
+ self.0
+ }
+}
+
+fn main() {
+ let a;
+ a = Bar(123);
+
+ let b;
+ b = Bar::get(a);
+
+ let a;
+ a = Bar(123);
+
+ let b;
+ b = a.test();
+}
--- /dev/null
+trait Foo {
+ type A;
+
+ fn test(a: Self::A) -> Self::A {
+ a
+ }
+}
+
+struct Bar(i32);
+impl Foo for Bar {
+ type A = i32;
+}
+
+struct Baz(f32);
+impl Foo for Baz {
+ type A = f32;
+}
+
+fn main() {
+ let a;
+ a = Bar(123);
+
+ let b;
+ b = Bar::test(a.0);
+
+ let c;
+ c = Baz(123f32);
+
+ let d;
+ d = Baz::test(c.0);
+}
--- /dev/null
+trait Foo {
+ type A;
+
+ fn test(a: Self::A) -> Self::A {
+ a
+ }
+}
+
+struct Bar(i32);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+impl Foo for Bar {
+ type A = i32;
+}
+
+struct Baz(f32);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+impl Foo for Baz {
+ type A = f32;
+}
+
+fn main() {
+ let a: <Baz as Foo>::A;
+ a = 123f32;
+
+ let b;
+ b = <Baz as Foo>::test(a);
+}
--- /dev/null
+trait Trait {
+ const FOO: usize;
+ type Target;
+}
+
+struct S;
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+impl Trait for S {
+ const FOO: usize = 0;
+ type Target = usize;
+}
+
+fn main() {
+ let a: <S as Trait>::Target;
+ a = <S as Trait>::FOO;
+}
--- /dev/null
+trait Foo<T> {
+ type A;
+
+ fn test(a: T) -> T {
+ a
+ }
+}
+
+struct Bar<T>(T);
+impl<T> Foo<T> for Bar<T> {
+ type A = T;
+}
+
+pub fn main() {
+ let a;
+ a = Bar(123);
+
+ let b: <Bar<i32> as Foo<i32>>::A;
+ b = 456;
+
+ let c: <Bar<i32> as Foo<i32>>::A;
+ c = <Bar<i32> as Foo<i32>>::test(a.0);
+}
--- /dev/null
+trait Foo<T> {
+ type A;
+
+ fn test(a: T, b: Self::A) -> (T, Self::A) {
+ (a, b)
+ }
+}
+
+struct Bar<T>(T);
+impl<T> Foo<T> for Bar<T> {
+ type A = T;
+}
+
+pub fn main() {
+ let a;
+ a = Bar(123);
+
+ let b: <Bar<i32> as Foo<i32>>::A;
+ b = 456;
+
+ let c;
+ c = <Bar<i32> as Foo<i32>>::test(a.0, 123);
+}
--- /dev/null
+trait A {
+ fn a() -> i32 {
+ 123
+ }
+
+ fn b() -> i32 {
+ Self::a() + 456
+ }
+}
+
+struct S;
+impl A for S {}
+
+fn main() {
+ let a;
+ a = S::a();
+
+ let b;
+ b = S::b();
+}
--- /dev/null
+trait A {
+ fn a() -> i32 {
+ 123
+ }
+}
+
+trait B: A {
+ fn b() -> i32 {
+ Self::a() + 456
+ }
+}
+
+struct S;
+impl A for S {}
+impl B for S {}
+
+fn main() {
+ let a;
+ a = S::a();
+
+ let b;
+ b = S::b();
+}
--- /dev/null
+trait Foo<'a> {}
+
+trait Bar {
+ type Item: for<'a> Foo<'a>;
+}
--- /dev/null
+// { dg-additional-options "-w" }
+trait Get {
+ type Value;
+ fn get(&self) -> &<Self as Get>::Value;
+}
+
+struct Struct {
+ x: isize,
+}
+
+impl Get for Struct {
+ type Value = isize;
+ fn get(&self) -> &isize {
+ &self.x
+ }
+}
+
+trait Grab {
+ type U;
+ fn grab(&self) -> &<Self as Grab>::U;
+}
+
+impl<T: Get> Grab for T {
+ type U = <T as Get>::Value;
+ fn grab(&self) -> &<T as Get>::Value {
+ self.get()
+ }
+}
+
+fn main() {
+ let s = Struct { x: 100 };
+ let a = s.grab();
+}
--- /dev/null
+trait Foo {
+ fn bar() -> i32;
+}
+
+struct Test<T>(T);
+
+impl<T> Foo for Test<T> {
+ fn bar() -> i32 {
+ 123
+ }
+}
+
+fn main() {
+ let a: i32;
+ a = Test::<i32>::bar();
+}
--- /dev/null
+pub trait Foo {
+ fn Bar(self) -> i32;
+}
+
+struct Baz;
+// { dg-warning "struct is never constructed: .Baz." "" { target *-*-* } .-1 }
+
+impl Foo for Baz {
+ fn Bar(self) -> i32 {
+ // { dg-warning "unused name .self." "" { target *-*-* } .-1 }
+ 123
+ }
+}
+
+fn main() {}
--- /dev/null
+trait Foo {
+ type A;
+ type B;
+
+ fn new(a: Self::A, b: Self::B) -> Self;
+}
+
+struct Baz(i32, f32);
+
+impl Foo for Baz {
+ type A = i32;
+ type B = f32;
+
+ fn new(a: Self::A, b: Self::B) -> Self {
+ Baz(a, b)
+ }
+}
+
+fn main() {
+ Baz::new(123, 456f32);
+}
--- /dev/null
+trait Foo {
+ type A;
+ type B;
+
+ fn new(a: Self::A, b: Self::B) -> Self;
+}
+
+struct Baz(i32, f32);
+
+impl Foo for Baz {
+ type A = i32;
+ type B = f32;
+
+ fn new(a: i32, b: f32) -> Self {
+ Baz(a, b)
+ }
+}
+
+fn main() {
+ Baz::new(123, 456f32);
+}
--- /dev/null
+trait Foo {
+ type A;
+
+ fn baz(a: Self::A) -> Self::A;
+}
+
+struct Bar<T>(T);
+
+impl<T> Foo for Bar<T> {
+ type A = T;
+
+ fn baz(a: Self::A) -> T {
+ a
+ }
+}
+
+fn main() {
+ let a;
+ a = Bar::<i32>::baz(123);
+}
--- /dev/null
+trait Foo {
+ const A: i32;
+
+ fn test(self);
+}
+
+struct Bar;
+impl Foo for Bar {
+ const A: i32 = 123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ fn test(self) {}
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let a = Bar;
+ a.test();
+}
--- /dev/null
+trait Foo {
+ fn default() -> i32;
+}
+
+struct Bar(i32);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+impl Foo for Bar {
+ fn default() -> i32 {
+ 123
+ }
+}
+
+fn type_bound_test<T: Foo>() -> i32 {
+ T::default()
+}
+
+fn main() {
+ let a;
+ a = type_bound_test::<Bar>();
+}
--- /dev/null
+trait Foo {
+ fn default() -> i32;
+ fn get(self) -> i32;
+}
+
+struct Bar(i32);
+impl Foo for Bar {
+ fn default() -> i32 {
+ 123
+ }
+
+ fn get(self) -> i32 {
+ self.0
+ }
+}
+
+fn type_bound_test<T: Foo>(a: T) -> i32 {
+ T::default() + a.get()
+}
+
+fn main() {
+ let a;
+ a = Bar(456);
+
+ let b;
+ b = type_bound_test(a);
+}
--- /dev/null
+mod mem {
+ extern "rust-intrinsic" {
+ fn size_of<T>() -> usize;
+ fn transmute<U, V>(_: U) -> V; // { dg-error "cannot transmute between types of different sizes, or dependently-sized types" }
+ }
+}
+
+fn main() {
+ let a = 123;
+ let _b: [u32; mem::size_of::<i32>()] = unsafe { mem::transmute(a) };
+}
--- /dev/null
+mod mem {
+ extern "rust-intrinsic" {
+ fn size_of<T>() -> usize;
+ fn transmute<U, V>(_: U) -> V;
+ }
+}
+
+fn main() {
+ let a = 123;
+ let _b: [u8; mem::size_of::<i32>()] = unsafe { mem::transmute(a) };
+}
--- /dev/null
+fn main() {
+ let a: (i32, bool) = (123, true);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b;
+ b = (456, 5f32);
+}
--- /dev/null
+fn main() {
+ let a = 123;
+ let b = (a,);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let a = (1, true);
+
+ let b;
+ let c;
+
+ b = a.0;
+ c = a.1;
+}
--- /dev/null
+enum E {
+ T0(),
+ T1(i32),
+ T2(i32, u32),
+}
+
+/* The following doesn't parse yet...
+fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
+{
+ let e = e0;
+ let f = e1;
+ let g = e2;
+ (e,f,g,())
+}
+
+fn main()
+{
+ let e0 = E::T0();
+ let e1 = E::T1(0);
+ let e2 = E::T2(0,1);
+ f(e0, e1, e2).3
+}
+*/
--- /dev/null
+struct Foo(i32, i32);
+
+fn main() {
+ let mut a = Foo(1, 2);
+ a.0 = 22;
+}
--- /dev/null
+fn foo() -> i32 {
+ return 1;
+}
+fn main() {
+ let _a = (foo(), 2);
+}
--- /dev/null
+fn main()
+{
+ // tuples
+ let z = ();
+
+ let o = (0,);
+ let _f = o.0;
+
+ let t = (0,1);
+ let _s = t.1;
+
+ let m = (0,1,2,3,4,5,6,7,8,9,10);
+ let _l = m.10;
+
+ // tuple structs
+ struct E();
+ let _e = E();
+
+ struct O(i32);
+ let so = O(0);
+ let _sf = so.0;
+
+ struct T(i32,i32);
+ let st = T(0,1);
+ let _fs = st.1;
+
+ struct M(i32,i32,i32,i32,i32,i32,i32,i32,i32,i32,i32);
+ let sm = M(0,1,2,3,4,5,6,7,8,9,10);
+ let _sl = sm.10;
+
+ z
+}
--- /dev/null
+struct Foo(i32, i32, bool);
+
+fn main() {
+ let a = Foo(1, 2, true);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo(i32, bool);
+
+fn main() {
+ let a = Foo(1, true);
+
+ let b;
+ let c;
+
+ b = a.0;
+ c = a.1;
+}
--- /dev/null
+struct E();
+struct T(E,E,());
+
+fn main()
+{
+ let z0 = E();
+ let z1 = E();
+ let t = T(z0,z1,());
+ let z = t.2;
+ z
+}
--- /dev/null
+struct Foo(i32, i32);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+fn main() {}
--- /dev/null
+type TypeAlias = (i32, u32);
+
+fn main() {
+ let a: TypeAlias;
+ a = (123, 456);
+}
--- /dev/null
+type x = u32;
+
+fn main() {
+ let x: x = 1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let y: x = 2;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ one: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ two: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn test(x: i32) -> i32 {
+ return x + 1;
+}
+
+fn main() {
+ let logical: bool = true;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let an_integer = 5;
+ let mut default_integer = 7;
+
+ default_integer = 1 + an_integer;
+
+ let call_test = test(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let struct_test = Foo { one: 1, two: 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test(x: i32) -> i32 {
+ return x + 1;
+}
+
+fn main() {
+ let an_integer = 5;
+ let call_test = test(an_integer + 1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test(x: i32) -> i32 {
+ return x + 1;
+}
+
+fn main() {
+ let mut an_integer = 5;
+ an_integer = test(1) + 3;
+
+ let mut x;
+ x = 1;
+
+ let call_test = test(1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let xs: [i32; 5] = [1, 2, 3, 4, 5];
+ let xy = [6, 7, 8];
+
+ let a = xs[0];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = xy[2];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let mut c;
+ c = xs[0];
+}
--- /dev/null
+struct Foo {
+ a: i32,
+ b: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let a;
+ a = Foo { a: 1, b: 2 };
+
+ let b = a.a;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test(x: u32) -> u32 {
+ return x + 1;
+}
+
+fn main() {
+ let a;
+ a = 1;
+ let b = test(a);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c = 1;
+ let d = test(c + 1);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-prune-output "warning: unused name" } as there are many of these expected.
+
+fn main() {
+ let a: i32 = -1;
+ let b: i32 = 3 - -1;
+ let c: bool = !false;
+ let d: i32 = !3;
+}
--- /dev/null
+// { dg-excess-errors "...." }
+fn main() {
+ // { dg-error "unended string literal" "" { target *-*-* } .+1 }
+ let s = "123
+}
--- /dev/null
+// { dg-excess-errors "...." }
+fn main() {
+ // { dg-error "unended byte string literal" "" { target *-*-* } .+1 }
+ let s = b"123
+}
--- /dev/null
+fn main() {
+ let _unused_but_fine = 12;
+ let unused = 12; // { dg-warning "unused name" }
+}
--- /dev/null
+union U
+{
+ f1: u8
+}
+
+union V
+{
+ f1: u8,
+ f2: u16,
+ f3: i32,
+}
+
+struct S
+{
+ f1: U,
+ f2: V
+}
+
+fn main ()
+{
+ let u = U { f1: 16 };
+ let v = V { f2: 365 };
+ let s = S { f1: u, f2: v };
+ let _v125 = unsafe
+ { let mut uv: u64;
+ uv = s.f1.f1 as u64;
+ uv += s.f2.f1 as u64;
+ uv += s.f2.f2 as u64;
+ uv -= s.f2.f3 as u64;
+ uv
+ };
+}
--- /dev/null
+union union
+{
+ union: u32,
+ inion: i32,
+ u8ion: u8,
+ i64on: i64,
+ u64on: u64
+}
+
+pub fn main ()
+{
+ let union = union { union: 2 };
+ let inion = union { inion: -2 };
+ let mut mnion = union { inion: -16 };
+ let m1 = unsafe { mnion.union };
+ unsafe { mnion.union = union.union };
+ let m2 = unsafe { mnion.inion };
+ let u1 = unsafe { union.union };
+ let i1 = unsafe { union.inion };
+ let u2 = unsafe { inion.union };
+ let i2 = unsafe { inion.inion };
+ let _r1 = u2 - u1 - m1;
+ let _r2 = i1 + i2 + m2;
+ let _u8 = unsafe { union.u8ion };
+ let _i64 = unsafe { union.i64on };
+ let _u64 = unsafe { union.u64on };
+}
--- /dev/null
+fn main() {
+ let a: () = ();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b;
+ b = ();
+}
--- /dev/null
+fn test(a: ()) -> () {
+ a
+}
+
+fn main() {
+ let a;
+ a = test(());
+}
--- /dev/null
+struct S;
+
+fn main() {
+ let s = S;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct S;
+
+fn main() {
+ let _s = S {};
+}
--- /dev/null
+struct Foo;
+
+fn main() {
+ let a = Foo {};
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = Foo;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn test() -> i32 {
+ unsafe {
+ let a;
+ a = 123;
+ a
+ }
+}
+
+fn main() {
+ let a;
+ a = test();
+}
--- /dev/null
+fn main() {
+ unsafe {}
+ ()
+}
--- /dev/null
+pub fn test() -> i32 {
+ let a = unsafe { 123 };
+ a
+}
+
+pub fn main() {
+ let a = test();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct SS {
+ one: i32,
+ two: i32,
+}
+struct TS(i32, i32);
+
+fn main() {
+ unsafe {
+ let ss = SS { one: 1, two: 2 };
+ let _ts = TS(ss.one, ss.two);
+ };
+}
--- /dev/null
+// { dg-warning "function is never used: 'bar'" "" { target *-*-* } .+1 }
+fn bar() {
+ foo();
+}
+
+// { dg-warning "function is never used: 'foo'" "" { target *-*-* } .+1 }
+fn foo() {
+ bar();
+}
+
+fn f() {
+
+}
+
+fn main() {
+ f();
+}
--- /dev/null
+fn test() -> i32 {
+ 1
+}
+
+fn unused() -> i32 {
+ // { dg-warning "function is never used: 'unused'" "" { target *-*-* } .-1 }
+ 2
+}
+
+fn main() {
+ let a = 1;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b = test();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo {
+ // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+ one: i32,
+ two: i32,
+}
+
+fn main() {}
--- /dev/null
+struct Foo {
+ one: i32,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ two: i32
+}
+fn main() {
+ let _a = Foo {one: 1, two: 2};
+ let _b = _a.two;
+}
\ No newline at end of file
--- /dev/null
+fn main() {
+ let a = [1, 2, 3];
+ let b: usize = 1;
+ let c = a[b];
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-excess-errors "...." }
+// { dg-error "unended string literal" "" { target *-*-* } .+1 }
+#[doc(alias = "123
--- /dev/null
+fn foo() {}
+fn bar() -> i32 { return 10; }
+
+fn main() {
+ let mut i = 1;
+ while i < bar() {
+ foo();
+ i += 1;
+ }
+}
--- /dev/null
+trait Foo {
+ fn Bar() -> i32 {}
+ // { dg-error "expected .i32. got .()." "" { target *-*-* } .-1 }
+}
+
+struct Baz;
+
+impl Foo for Baz {
+ fn Barrr() {}
+ // { dg-error "method .Barrr. is not a member of trait .Foo." "" { target *-*-* } .-1 }
+}
+
+fn main() {}
--- /dev/null
+struct Foo(i32);
+
+trait Bar {
+ const A: i32 = 123;
+ fn B();
+ fn C(&self);
+}
+
+pub fn main() {
+ let a;
+ a = Foo(123);
+
+ let b: &dyn Bar = &a;
+ // { dg-error "trait bound is not object safe" "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo(i32);
+
+trait A {
+ const A: i32 = 123;
+ fn B();
+ fn C(&self);
+}
+
+trait B: A {
+ fn test(&self);
+}
+
+pub fn main() {
+ let a;
+ a = Foo(123);
+
+ let b: &dyn B = &a;
+ // { dg-error "trait bound is not object safe" "" { target *-*-* } .-1 }
+}
--- /dev/null
+trait A<T> {
+ type Output;
+
+ fn test(self, a: &T) -> &Self::Output;
+}
+
+struct Foo<T> {
+ start: T,
+ end: T,
+}
+
+impl<T> A for Foo<usize> {
+ // { dg-error "generic item takes at least 1 type arguments but 0 were supplied" "" { target *-*-* } .-1 }
+ // { dg-error "unconstrained type parameter" "" { target *-*-* } .-2 }
+ type Output = T;
+
+ fn test(self, a: &T) -> &Self::Output {
+ a
+ }
+}
--- /dev/null
+trait Foo {
+ fn Bar() -> i32 {}
+ // { dg-error "expected .i32. got .()." "" { target *-*-* } .-1 }
+}
+
+struct Baz;
+
+impl Foo for Baz {
+ fn Bar() {}
+ // { dg-error "expected .i32. got .()." "" { target *-*-* } .-1 }
+ // { dg-error "method .Bar. has an incompatible type for trait .Foo." "" { target *-*-* } .-2 }
+}
+
+fn main() {}
--- /dev/null
+trait Foo {
+ type A;
+
+ fn baz(a: Self::A) -> Self::A;
+}
+
+struct Bar<T>(T);
+
+impl<T> Foo for Bar<T> {
+ type A = i32;
+
+ fn baz(a: f32) -> f32 {
+ // { dg-error "method .baz. has an incompatible type for trait .Foo." "" { target *-*-* } .-1 }
+ a
+ // { dg-error "expected .i32. got .f32." "" { target *-*-* } .-1 }
+ }
+}
+
+fn main() {
+ let a;
+ a = Bar::<i32>::baz(123f32);
+}
--- /dev/null
+trait Foo {
+ const A: i32;
+
+ fn test(self);
+}
+
+struct Bar;
+impl Foo for Bar {
+ // { dg-error "missing A in implementation of trait .Foo." "" { target *-*-* } .-1 }
+ fn test(self) {}
+}
+
+fn main() {
+ let a = Bar;
+ a.test();
+}
--- /dev/null
+trait Foo {
+ const A: i32;
+
+ fn test(self);
+}
+
+struct Bar;
+impl Foo for Bar {}
+// { dg-error "missing A, test in implementation of trait .Foo." "" { target *-*-* } .-1 }
--- /dev/null
+trait Foo {
+ fn default() -> i32;
+}
+
+struct Bar(i32);
+
+fn type_bound_test<T: Foo>() -> i32 {
+ T::default()
+}
+
+fn main() {
+ let a;
+ a = type_bound_test::<Bar>();
+ // { dg-error "bounds not satisfied for Bar" "" { target *-*-* } .-1 }
+}
--- /dev/null
+trait Foo {
+ fn default() -> i32;
+}
+
+trait Bar {
+ fn not_default() -> i32;
+}
+
+struct Test(i32);
+
+impl Foo for Test {
+ fn default() -> i32 {
+ 1234
+ }
+}
+
+fn type_bound_test<T: Foo + Bar>() -> i32 {
+ T::default()
+}
+
+fn main() {
+ let a = type_bound_test::<Test>();
+ // { dg-error "bounds not satisfied for Test" "" { target *-*-* } .-1 }
+}
--- /dev/null
+trait A {
+ fn get(self) -> f64;
+}
+
+trait B {
+ fn get(self) -> u8;
+}
+
+struct Foo(u8, f64);
+
+impl A for Foo {
+ fn get(self) -> f64 {
+ self.1
+ }
+}
+
+impl B for Foo {
+ fn get(self) -> u8 {
+ self.0
+ }
+}
+
+fn main() {
+ let _a;
+ _a = Foo(123, 456f64);
+
+ let _b: f64;
+ _b = <Foo as A>::get(_a);
+
+ let _a;
+ _a = Foo(123, 456f64);
+
+ let _c: u8;
+ _c = <Foo as B>::get(_a)
+}
--- /dev/null
+struct Foo(i32);
+trait Bar {
+ fn baz(&self);
+}
+
+fn main() {
+ let a;
+ a = Foo(123);
+
+ let b: &dyn Bar = &a;
+ // { dg-error "bounds not satisfied for Foo .Bar. is not satisfied" "" { target *-*-* } .-1 }
+ // { dg-error "expected" "" { target *-*-* } .-2 }
+}
--- /dev/null
+fn main() {
+ let a: (i32, bool) = (123, 123); // { dg-error "expected .bool. got .<integer>." }
+ let b;
+ b = (456, 5f32);
+}
--- /dev/null
+struct Foo {
+ one: i32,
+ two: i32,
+}
+
+fn main() {
+ let a = Foo(1, 2); // { dg-error "expected function, tuple struct or tuple variant, found struct 'Foo'" }
+}
--- /dev/null
+struct Bar(i32, i32, bool);
+
+fn main() {
+ let a = Bar(1, 2); // { dg-error "unexpected number of arguments 2 expected 3" }
+}
--- /dev/null
+struct Foo(i32, i32, bool);
+
+fn main() {
+ let c = Foo(1, 2f32, true);
+ // { dg-error "expected .i32. got .f32." "" { target *-*-* } .-1 }
+}
--- /dev/null
+type TypeAlias = (i32, u32);
+
+fn main() {
+ let a: TypeAlias;
+ a = (123, 456f32); // { dg-error "expected .u32. got .f32." }
+}
--- /dev/null
+struct Foo<A, B>(A, B);
+
+fn main() {
+ let a;
+ a = Foo::<A = i32, B = f32>(123f32);
+ // { dg-error "associated type bindings are not allowed here" "" { target *-*-* } .-1 }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-2 }
+ // { dg-error {Failed to resolve expression of function call} "" { target *-*-* } .-3 }
+ // { duplicate _dg-error {failed to type resolve expression} "" { target *-*-* } .-4 }
+}
--- /dev/null
+fn main() {
+ let a: i32 = -1;
+ let b: i32 = 3 - -1;
+ let c: bool = !false;
+ let d: i32 = !3;
+
+ let e: f32 = -true; // // { dg-error "cannot apply unary - to bool" }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-1 }
+}
--- /dev/null
+fn main() {
+ let a: i32 = -1;
+ let b: i32 = 3 - -1;
+ let c: bool = !false;
+ let d: i32 = !3;
+
+ let e: f32 = !5f32; // { dg-error "cannot apply unary '!' to f32" }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-1 }
+}
--- /dev/null
+struct Foo<T>(T, bool);
+
+impl<X, Y> Foo<X> {
+ // { dg-error "unconstrained type parameter" "" { target *-*-* } .-1 }
+ fn test() -> Y {
+ 123
+ }
+}
+
+fn main() {
+ let a = Foo::test();
+}
--- /dev/null
+fn main ()
+{
+ // Braces are required
+ let _cbl = '\u013'; // { dg-error "unicode escape" }
+ let _sbl = "\u013"; //{ dg-error "unicode escape" }
+
+ // One to six hex digits
+ let _c0 = '\u{}'; // { dg-error "unicode escape" }
+ let _c1 = '\u{0}';
+ let _c2 = '\u{00}';
+ let _c3 = '\u{000}';
+ let _c4 = '\u{0000}';
+ let _c5 = '\u{00000}';
+ let _c6 = '\u{000000}';
+ let _c7 = '\u{0000000}'; // { dg-error "unicode escape" }
+
+ let _s0 = "\u{}"; // { dg-error "unicode escape" }
+ let _s1 = "\u{0}";
+ let _s2 = "\u{00}";
+ let _s3 = "\u{000}";
+ let _s4 = "\u{0000}";
+ let _s5 = "\u{00000}";
+ let _s6 = "\u{000000}";
+ let _s7 = "\u{0000000}"; // { dg-error "unicode escape" }
+
+ // Underscores OK except for start
+ let _c_ = '\u{00___01__0_1_}';
+ let _s_ = "\u{00___01__0_1_}";
+ let _c__ = '\u{_00__01__0_}'; // { dg-error "unicode escape" }
+ let _s__ = "\u{_00__01__0_}"; // { dg-error "unicode escape" }
+
+ // Must be hex chars
+ let _chex = '\u{hex}'; // { dg-error "unicode escape" }
+ let _shex = '\u{hex}'; // { dg-error "unicode escape" }
+
+ // Only valid from 0x0 to 0xD7FF and from 0xE000 to 0x10FFF
+ let _cd7ff = '\u{D7FF}';
+ let _sd7ff = "\u{D7FF}";
+ let _cd800 = '\u{D800}'; // { dg-error "unicode escape" }
+ let _sd800 = "\u{D800}"; // { dg-error "unicode escape" }
+
+ let _cdfff = '\u{DFFF}'; // { dg-error "unicode escape" }
+ let _sdfff = "\u{DFFF}"; // { dg-error "unicode escape" }
+ let _ce000 = '\u{E000}';
+ let _se000 = "\u{E000}";
+
+ let _clast = '\u{10FFFF}';
+ let _slast = "\u{10FFFF}";
+ let _clast1 = '\u{110000}'; // { dg-error "unicode escape" }
+ let _slast1 = "\u{110000}"; // { dg-error "unicode escape" }
+
+ let _cffffff = '\u{FFFFFF}'; // { dg-error "unicode escape" }
+ let _sffffff = "\u{FFFFFF}"; // { dg-error "unicode escape" }
+
+ // unicode escapes cannot be used in bytes or byte strings.
+ // Except in raw byte strings (where they aren't escapes).
+ let _bc = b'\u{000A}'; // { dg-error "unicode escape" }
+ let _bs = b"\u{000A}"; // { dg-error "unicode escape" }
+ let _rbs = br"\u{000A}";
+}
--- /dev/null
+fn foo(_a: &i32) {}
+fn bar(_a: i32) {}
+
+static mut a: i32 = 15;
+
+fn main() {
+ foo(&a); // { dg-error "use of mutable static" }
+ bar(a); // { dg-error "use of mutable static" }
+
+ unsafe {
+ foo(&a);
+ bar(a);
+ }
+}
--- /dev/null
+extern "rust-intrinsic" {
+ pub fn rotate_left<T>(l: T, r: T) -> T;
+}
+
+fn main() -> i32 {
+ let a = 15;
+ let b = 15;
+
+ let _ = rotate_left(a, b);
+
+ 0
+}
--- /dev/null
+fn foo(_a: &i32) {}
+fn bar(_a: i32) {}
+
+mod inner {
+ pub static mut a: i32 = 15;
+}
+
+fn main() {
+ foo(&inner::a); // { dg-error "use of mutable static" }
+ bar(inner::a); // { dg-error "use of mutable static" }
+
+ unsafe {
+ foo(&inner::a);
+ bar(inner::a);
+ }
+}
--- /dev/null
+extern "C" {
+ static VALUE: char;
+}
+
+fn main() {
+ let _ = VALUE; // { dg-error "use of extern static" }
+ unsafe {
+ let _ = VALUE;
+ }
+}
--- /dev/null
+fn foo() -> i32 {
+ let a = 15;
+ let p_a = &a as *const i32;
+
+ unsafe { *p_a }
+}
+
+unsafe fn bar() -> i32 {
+ let a = 15;
+ let p_a = &a as *const i32;
+
+ *p_a
+}
+
+fn baz() -> i32 {
+ let a = 15;
+ let p_a = &a as *const i32;
+
+ *p_a // { dg-error "dereference of raw pointer" }
+}
+
+unsafe fn qux() -> i32 {
+ let a = 15;
+ let p_a = &a as *const i32;
+
+ unsafe {}
+
+ *p_a
+}
--- /dev/null
+fn main() {
+ let b = 15;
+ let c = *(&b as *const i32); // { dg-error "dereference of raw pointer" }
+}
--- /dev/null
+unsafe fn foo() {}
+unsafe fn bar() {
+ foo();
+}
+
+fn main() {
+ foo(); // { dg-error "call to unsafe function" }
+ bar(); // { dg-error "call to unsafe function" }
+
+ unsafe {
+ foo();
+ bar();
+ }
+}
--- /dev/null
+extern "C" {
+ fn printf(fmt: *const i8, ...);
+}
+
+fn main() {
+ let s = "hey\0";
+
+ printf(s as *const str as *const i8); // { dg-error "call to extern function" }
+}
--- /dev/null
+struct S;
+
+impl S {
+ unsafe fn foo(self) {}
+}
+
+fn main() {
+ let s = S;
+ s.foo(); // { dg-error "call to unsafe method" }
+
+ unsafe {
+ s.foo();
+ }
+}
--- /dev/null
+union U {
+ a: i32,
+ b: f32,
+ c: u8,
+}
+
+fn main() {
+ let u = U { a: 14 };
+ let _ = u.a; // { dg-error "access to union" }
+}
--- /dev/null
+// { dg-error "unexpected EOF while looking for end of comment" "" { target *-*-* } .+1 }
+/* This comment needs closure :) !
--- /dev/null
+mod frob {}
+
+use foo::bar::baz; // { dg-error "cannot find simple path segment .foo." }
+use frob::ulator; // { dg-error "cannot find simple path segment .ulator." }
+
+mod sain {
+ mod doux {}
+
+ mod dron {}
+}
+
+use not_sain::*; // { dg-error "cannot find simple path segment .not_sain." }
+
+use sain::*;
+use sain::{doux, dron};
+use sain::{doux, dron, graal}; // { dg-error "cannot find simple path segment .graal." }
--- /dev/null
+fn main() {
+ let a = [1, 2, 3];
+ let b: u32 = 1;
+ let c = a[b]; // { dg-error "the type ...integer..CAPACITY.. cannot be indexed by .u32." }
+ // { dg-error {failed to type resolve expression} "" { target *-*-* } .-1 }
+}
--- /dev/null
+// { dg-excess-errors "warnings" }
+
+// { dg-error "lifetime not defined" "#359" { xfail *-*-* } .+1 }
+fn lifetime_undefined(t: &'a str) -> &'a str {
+ t
+}
+
+// { dg-error "lifetime not defined" "#359" { xfail *-*-* } .+1 }
+fn lifetime_undefined_bis<'a>(t: &'a str)-> &'b str {
+ t
+}
--- /dev/null
+// { dg-xfail-if "pub visibility not supported #432" *-*-* }
+
+mod foomod {
+ pub struct Foo {
+ pub f: i32,
+ pub g: u32,
+ }
+}
+
+fn test() -> foomod::Foo {
+ foomod::Foo{
+ f:1,
+ g:3,
+ }
+}
--- /dev/null
+# Copyright (C) 2021-2022 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Compile tests, no torture testing.
+#
+# These tests are used to keep track of known limitations :
+# 1- tests that are incorrecly build instead of being rejected
+# 2- tests that are build to an incorrect result
+# 3- tests that are rejected instead of being correctly build
+#
+# Not currently supported here:
+# - tests that are exhibiting incorrect behavior at runtime
+#
+# Here's how to annotate tests for each cases:
+#
+# 1- test is successfuly build instead of being rejected
+#
+# Expected behavior: a specific error rejecting the test
+# Observed behavior: error not present
+# Use dg-error and mark the test xfail and add reference to corresponding issue.
+# { dg-error "lifetime not defined" "#359" { xfail *-*-* } }
+#
+# 2- test is successfuly build but result is incorrect
+#
+# Expected behavior: test is correctly build and has specific property
+# Observed behavior: test is correctly build but is missing the specific property
+# Depends on the property. For example, if the property can be checked in the assembly file, use dg-final + xfail.
+# { dg-final { scan-assembler "given_string_missing_in_assembly_" "#1234" { xfail *-*-* } } }
+#
+# 3- test is rejected instead of being correctly build
+#
+# Expected behavior: test is successfully build
+# Observed behavior: the test is rejected with an error
+# Use dg-bogus + xfail to match the bogus error message, or use dg-xfail-if if it's harder to match a specific error.
+
+# Load support procs.
+load_lib rust-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+set saved-dg-do-what-default ${dg-do-what-default}
+
+set dg-do-what-default "compile"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] "" ""
+set dg-do-what-default ${saved-dg-do-what-default}
+
+# All done.
+dg-finish