Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Update code for finding #[test] functions. #1239

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 109 additions & 87 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ You'll need to install MIRAI as described
Then use `cargo mirai` to run MIRAI over your current package. This works much like `cargo check` but uses MIRAI rather
than rustc to analyze the targets of your current package.

`cargo mirai` does a top-down full-program path sensitive analysis of the
[entry points](https://github.com/facebookexperimental/MIRAI/blob/main/documentation/Overview.md#entry-points) of your
package. To analyze test functions instead, use `cargo mirai --tests`.

This will likely produce some warnings. Some of these will be real issues (true positives) that you'll fix by changing
the offending code. Other warnings will be due to limitations of MIRAI and you can silence them by adding annotations
declared in this [crate](https://crates.io/crates/mirai-annotations).
Expand Down
Binary file modified binaries/summary_store.tar
Binary file not shown.
14 changes: 4 additions & 10 deletions checker/src/crate_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use mirai_annotations::*;
use rustc_errors::{Diagnostic, DiagnosticBuilder};
use rustc_hir::def_id::{DefId, DefIndex};
use rustc_middle::mir;
use rustc_middle::ty::{GenericArgsRef, TyCtxt, UnevaluatedConst};
use rustc_middle::ty::{GenericArgsRef, TyCtxt};
use rustc_session::Session;

use crate::body_visitor::BodyVisitor;
Expand Down Expand Up @@ -224,20 +224,14 @@ impl<'compilation, 'tcx> CrateVisitor<'compilation, 'tcx> {
for b in body.basic_blocks.iter() {
for s in &b.statements {
// The statement we are looking for has the form
// `Assign(_, Rvalue(Constant(UnevaluatedConst(def_id)))))`
// `Assign(_, Rvalue(Operand::Constant(ConstantKind::Unevaluated({def, ..}, _))))`
if let mir::StatementKind::Assign(box (
_,
mir::Rvalue::Use(mir::Operand::Constant(box ref con)),
)) = s.kind
{
if let mir::ConstantKind::Ty(c) = con.literal {
if let rustc_middle::ty::ConstKind::Unevaluated(UnevaluatedConst {
def,
..
}) = c.kind()
{
result.push(utils::def_id_display_name(self.tcx, def));
}
if let mir::ConstantKind::Unevaluated(c, _) = con.literal {
result.push(utils::def_id_display_name(self.tcx, c.def));
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions checker/tests/run-pass/generic_trait_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ impl Tr<i32> for Foo {
pub fn t1() {
let foo = Foo { bar: 1 };
verify!(foo.actual() == 1);
// todo: fix this
verify!(foo.actual() == 2); // ~ provably false verification condition
verify!(foo.actual() == 2); //~ provably false verification condition
}

pub fn main() {}
3 changes: 1 addition & 2 deletions checker/tests/run-pass/test_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ fn some_test() {

#[test]
fn another_test() {
// todo: fix this
verify!(2 == 1); // ~ provably false verification condition
verify!(2 == 1); //~ provably false verification condition
}

pub fn main() {
Expand Down
3 changes: 1 addition & 2 deletions checker/tests/run-pass/trait_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ pub fn test() {
let mut a = MyAdder(3);
a.decrement();
checked_verify!(a.current() < 3);
// todo: fix this
verify!(a.current() == 1); // ~ provably false verification condition
verify!(a.current() == 1); //~ provably false verification condition
}

pub fn main() {}
3 changes: 1 addition & 2 deletions checker/tests/run-pass/trait_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ impl Tr for Foo {
pub fn t1() {
let foo = Foo { bar: 1 };
verify!(foo.actual() == 1);
// todo: fix this
verify!(foo.actual() == 2); // ~ provably false verification condition
verify!(foo.actual() == 2); //~ provably false verification condition
}

pub fn main() {}