Skip to content

Commit 2722751

Browse files
committed
feat: Warn that edition 2015 code is not explicitly supported
1 parent 8a899e6 commit 2722751

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

mutest-driver/src/passes/analysis.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_hash::FxHashSet;
44
use rustc_interface::{create_and_enter_global_ctxt, passes, run_compiler};
55
use rustc_interface::interface::Result as CompilerResult;
66
use rustc_span::ErrorGuaranteed;
7+
use rustc_span::edition::Edition;
78
use rustc_span::fatal_error::FatalError;
89
use mutest_emit::codegen::symbols::span_diagnostic_ord;
910

@@ -67,6 +68,12 @@ pub fn run(config: &mut Config) -> CompilerResult<Option<AnalysisPassResult>> {
6768
// relevant attribute validation is performed during macro expansion.
6869
mutest_emit::codegen::tool_attr::register(sess, &mut crate_ast);
6970

71+
if sess.edition() == Edition::Edition2015 {
72+
let mut diagnostic = sess.dcx().struct_warn("edition 2015 code is not explicitly supported");
73+
diagnostic.note("you may encounter issues with generated code from macro expansion sanitization and mutation operators");
74+
diagnostic.emit();
75+
}
76+
7077
let result = create_and_enter_global_ctxt(compiler, crate_ast.clone(), |tcx| -> Flow<AnalysisPassResult, ErrorGuaranteed> {
7178
let (mut generated_crate_ast, def_res) = {
7279
let (resolver, expanded_crate_ast) = &*tcx.resolver_for_lowering().borrow();

tests/ui/warn_on_edition_2015.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ print-mutants
2+
//@ build
3+
//@ stdout
4+
//@ stderr
5+
//@ edition: 2015
6+
7+
fn mutated_fn(a: i32, b: i32) -> i32 {
8+
a + b
9+
}
10+
11+
#[test]
12+
fn test() {
13+
assert_eq!(11, mutated_fn(5, 6));
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: edition 2015 code is not explicitly supported
2+
|
3+
= note: you may encounter issues with generated code from macro expansion sanitization and mutation operators
4+
5+
warning: 1 warning emitted
6+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
1 mutation
2+
- [arg_default_shadow] ignore `a` argument by shadowing it with `Default::default()` in mutated_fn at tests/ui/warn_on_edition_2015.rs:7:15: 7:21
3+
<-(0)- test
4+
5+
1 mutation
6+
- [arg_default_shadow] ignore `b` argument by shadowing it with `Default::default()` in mutated_fn at tests/ui/warn_on_edition_2015.rs:7:23: 7:29
7+
<-(0)- test
8+
9+
1 mutation
10+
- [math_op_add_sub_swap] swap operator `+` for `-` in mutated_fn at tests/ui/warn_on_edition_2015.rs:8:5: 8:10
11+
<-(0)- test
12+
13+
1 mutation
14+
- [math_op_add_mul_swap] swap operator `+` for `*` in mutated_fn at tests/ui/warn_on_edition_2015.rs:8:5: 8:10
15+
<-(0)- test
16+
17+
4 mutants; 4 mutations; 4 safe; 0 unsafe (0 tainted); 0 batched; 4 unbatched

0 commit comments

Comments
 (0)