11#![ feature( test) ] // compiletest_rs requires this attribute
22#![ feature( once_cell) ]
3+ #![ feature( is_sorted) ]
34#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
45#![ warn( rust_2018_idioms, unused_lifetimes) ]
56
@@ -162,8 +163,8 @@ fn base_config(test_dir: &str) -> compiletest::Config {
162163}
163164
164165fn run_ui ( ) {
165- let config = base_config ( "ui" ) ;
166- // use tests/clippy.toml
166+ let mut config = base_config ( "ui" ) ;
167+ config . rustfix_coverage = true ;
167168 let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , fs:: canonicalize ( "tests" ) . unwrap ( ) ) ;
168169 let _threads = VarGuard :: set (
169170 "RUST_TEST_THREADS" ,
@@ -175,6 +176,7 @@ fn run_ui() {
175176 } ) ,
176177 ) ;
177178 compiletest:: run_tests ( & config) ;
179+ check_rustfix_coverage ( ) ;
178180}
179181
180182fn run_internal_tests ( ) {
@@ -337,6 +339,82 @@ fn compile_test() {
337339 run_internal_tests ( ) ;
338340}
339341
342+ const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS : & [ & str ] = & [
343+ "assign_ops2.rs" ,
344+ "cast_size_32bit.rs" ,
345+ "char_lit_as_u8.rs" ,
346+ "cmp_owned/without_suggestion.rs" ,
347+ "crashes/ice-6250.rs" ,
348+ "crashes/ice-6251.rs" ,
349+ "dbg_macro.rs" ,
350+ "deref_addrof_double_trigger.rs" ,
351+ "doc/unbalanced_ticks.rs" ,
352+ "eprint_with_newline.rs" ,
353+ "explicit_counter_loop.rs" ,
354+ "iter_skip_next_unfixable.rs" ,
355+ "let_and_return.rs" ,
356+ "literals.rs" ,
357+ "map_flatten.rs" ,
358+ "map_unwrap_or.rs" ,
359+ "match_bool.rs" ,
360+ "mem_replace_macro.rs" ,
361+ "needless_arbitrary_self_type_unfixable.rs" ,
362+ "needless_borrow_pat.rs" ,
363+ "needless_for_each_unfixable.rs" ,
364+ "nonminimal_bool.rs" ,
365+ "print_literal.rs" ,
366+ "print_with_newline.rs" ,
367+ "redundant_static_lifetimes_multiple.rs" ,
368+ "ref_binding_to_reference.rs" ,
369+ "repl_uninit.rs" ,
370+ "result_map_unit_fn_unfixable.rs" ,
371+ "search_is_some.rs" ,
372+ "single_component_path_imports_nested_first.rs" ,
373+ "string_add.rs" ,
374+ "toplevel_ref_arg_non_rustfix.rs" ,
375+ "unit_arg.rs" ,
376+ "unnecessary_clone.rs" ,
377+ "unnecessary_lazy_eval_unfixable.rs" ,
378+ "write_literal.rs" ,
379+ "write_literal_2.rs" ,
380+ "write_with_newline.rs" ,
381+ ] ;
382+
383+ fn check_rustfix_coverage ( ) {
384+ let missing_coverage_path = Path :: new ( "target/debug/test/ui/rustfix_missing_coverage.txt" ) ;
385+
386+ if let Ok ( missing_coverage_contents) = std:: fs:: read_to_string ( missing_coverage_path) {
387+ assert ! ( RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS . is_sorted( ) ) ;
388+
389+ for rs_path in missing_coverage_contents. lines ( ) {
390+ let filename = rs_path. strip_prefix ( "tests/ui/" ) . unwrap ( ) ;
391+ assert ! (
392+ RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS . binary_search( & filename) . is_ok( ) ,
393+ "`{}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation" ,
394+ rs_path,
395+ ) ;
396+ }
397+ }
398+ }
399+
400+ #[ test]
401+ fn rustfix_coverage_known_exceptions_accuracy ( ) {
402+ for filename in RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS {
403+ let rs_path = Path :: new ( "tests/ui" ) . join ( filename) ;
404+ assert ! (
405+ rs_path. exists( ) ,
406+ "`{}` does not exists" ,
407+ rs_path. strip_prefix( env!( "CARGO_MANIFEST_DIR" ) ) . unwrap( ) . display( )
408+ ) ;
409+ let fixed_path = rs_path. with_extension ( "fixed" ) ;
410+ assert ! (
411+ !fixed_path. exists( ) ,
412+ "`{}` exists" ,
413+ fixed_path. strip_prefix( env!( "CARGO_MANIFEST_DIR" ) ) . unwrap( ) . display( )
414+ ) ;
415+ }
416+ }
417+
340418/// Restores an env var on drop
341419#[ must_use]
342420struct VarGuard {
0 commit comments