diff --git a/src/static_rts/visitor.rs b/src/static_rts/visitor.rs index d6c52c20..2cd03205 100644 --- a/src/static_rts/visitor.rs +++ b/src/static_rts/visitor.rs @@ -765,6 +765,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { let ty = self.monomorphize(ty); // 2. function -> contained closure visit_fn_use(tcx, ty, false, source, self.output, EdgeType::Contained); + visit_drop_use(tcx, ty, false, source, self.output); } if let TyKind::Ref(_region, ty, _mtblt) = *ty.kind() { // Also account for closures behind references @@ -1123,18 +1124,18 @@ fn collect_used_items<'tcx>( instance: Instance<'tcx>, output: &mut MonoItems<'tcx>, ) { - let body = tcx.instance_mir(instance.def); + let body = tcx.instance_mir(instance.def); - // Here we rely on the visitor also visiting `required_consts`, so that we evaluate them - // and abort compilation if any of them errors. - MirUsedCollector { - tcx, - body, - output, - instance, - visiting_call_terminator: false, - } - .visit_body(body); + // Here we rely on the visitor also visiting `required_consts`, so that we evaluate them + // and abort compilation if any of them errors. + MirUsedCollector { + tcx, + body, + output, + instance, + visiting_call_terminator: false, + } + .visit_body(body); } fn collect_const_value<'tcx>( diff --git a/test-data/blackbox/adt/Cargo.toml b/test-data/blackbox/adt/Cargo.toml index c801a9a2..c5470974 100644 --- a/test-data/blackbox/adt/Cargo.toml +++ b/test-data/blackbox/adt/Cargo.toml @@ -8,6 +8,5 @@ edition = "2021" [features] changes_display = [] changes_debug = [] -changes_drop = [] [dependencies] diff --git a/test-data/blackbox/adt/src/lib.rs b/test-data/blackbox/adt/src/lib.rs index 3fff689f..642b62b0 100644 --- a/test-data/blackbox/adt/src/lib.rs +++ b/test-data/blackbox/adt/src/lib.rs @@ -29,18 +29,6 @@ impl Debug for Foo { } } -static mut DROPPED: bool = false; - -impl Drop for Foo { - #[cfg(not(feature = "changes_drop"))] - fn drop(&mut self) { - unsafe { DROPPED = true }; - } - - #[cfg(feature = "changes_drop")] - fn drop(&mut self) {} -} - fn generic_display(s: &S, buf: &mut impl Write) { buf.write_fmt(format_args!("{}", s)).unwrap(); } @@ -84,7 +72,6 @@ pub mod test { let instance: Foo = Foo { data: 1 }; assert_eq!(format!("{}", instance), "Foo: 1"); } - assert!(unsafe { DROPPED }); } #[test] diff --git a/test-data/blackbox/drop/Cargo.toml b/test-data/blackbox/drop/Cargo.toml new file mode 100644 index 00000000..78c89a6f --- /dev/null +++ b/test-data/blackbox/drop/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "drop" +version = "0.1.0" +edition = "2021" + +[features] +changes_drop = [] +drop_inner = [] +drop_outer = [] +drop_direct = [] +drop_delegate = [] +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/test-data/blackbox/drop/src/lib.rs b/test-data/blackbox/drop/src/lib.rs new file mode 100644 index 00000000..14e90969 --- /dev/null +++ b/test-data/blackbox/drop/src/lib.rs @@ -0,0 +1,57 @@ +static mut DROPPED: bool = false; + +struct Foo { + data: i32, +} +struct Bar { + data: i32, + foo: Foo, +} + +#[cfg(feature = "drop_inner")] +impl Drop for Foo { + fn drop(&mut self) { + println!("Data {}", self.data); + #[cfg(not(feature = "changes_drop"))] + unsafe { + DROPPED = true; + } + } +} + +#[cfg(feature = "drop_outer")] +impl Drop for Bar { + fn drop(&mut self) { + println!("Data {}", self.data); + println!("Foo {}", self.foo.data); + #[cfg(not(feature = "changes_drop"))] + unsafe { + DROPPED = true; + } + } +} + +#[cfg(feature = "drop_delegate")] +fn delegate(t: T) {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_drop() { + { + let bar = Bar { + data: 1, + foo: Foo { data: 2 }, + }; + + #[cfg(feature = "drop_direct")] + drop(bar); + + #[cfg(feature = "drop_delegate")] + delegate(bar); + } + assert!(unsafe { DROPPED }) + } +} diff --git a/test-data/manual/allocator/Cargo.toml b/test-data/manual/allocator/Cargo.toml new file mode 100644 index 00000000..e4d6f9ac --- /dev/null +++ b/test-data/manual/allocator/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "allocator" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +jemallocator = "0.1" diff --git a/test-data/manual/allocator/src/main.rs b/test-data/manual/allocator/src/main.rs new file mode 100644 index 00000000..05592310 --- /dev/null +++ b/test-data/manual/allocator/src/main.rs @@ -0,0 +1,16 @@ +extern crate jemallocator; + +fn main() { + println!("Hello, world!"); +} + +#[global_allocator] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; + + +#[test] +fn test() { + let mut foo = String::new(); + foo.push_str("Foo"); + assert_eq!(foo, "Foo"); +} diff --git a/tests/blackbox.rs b/tests/blackbox.rs index da6f46ee..be39ce2a 100644 --- a/tests/blackbox.rs +++ b/tests/blackbox.rs @@ -87,8 +87,18 @@ fn check_same_crate_id(mode: Mode) { #[test_case(Mode::Static, "adt", "", "changes_display")] #[test_case(Mode::Dynamic, "adt", "", "changes_debug")] #[test_case(Mode::Static, "adt", "", "changes_debug")] -#[test_case(Mode::Dynamic, "adt", "", "changes_drop")] -#[test_case(Mode::Static, "adt", "", "changes_drop")] +#[test_case(Mode::Dynamic, "drop", "drop_inner", "drop_inner,changes_drop")] +#[test_case(Mode::Static, "drop", "drop_inner", "drop_inner,changes_drop")] +#[test_case(Mode::Dynamic, "drop", "drop_outer", "drop_outer,changes_drop")] +#[test_case(Mode::Static, "drop", "drop_outer", "drop_outer,changes_drop")] +#[test_case(Mode::Dynamic, "drop", "drop_inner,drop_direct", "drop_inner,drop_direct,changes_drop")] +#[test_case(Mode::Static, "drop", "drop_inner,drop_direct", "drop_inner,drop_direct,changes_drop")] +#[test_case(Mode::Dynamic, "drop", "drop_outer,drop_direct", "drop_outer,drop_direct,changes_drop")] +#[test_case(Mode::Static, "drop", "drop_outer,drop_direct", "drop_outer,drop_direct,changes_drop")] +#[test_case(Mode::Dynamic, "drop", "drop_inner,drop_delegate", "drop_inner,drop_delegate,changes_drop")] +#[test_case(Mode::Static, "drop", "drop_inner,drop_delegate", "drop_inner,drop_delegate,changes_drop")] +#[test_case(Mode::Dynamic, "drop", "drop_outer,drop_delegate", "drop_outer,drop_delegate,changes_drop")] +#[test_case(Mode::Static, "drop", "drop_outer,drop_delegate", "drop_outer,drop_delegate,changes_drop")] #[test_case(Mode::Dynamic, "command", "", "changes_return")] #[test_case(Mode::Dynamic, "dynamic", "", "changes_direct")] #[test_case(Mode::Static, "dynamic", "", "changes_direct")]