diff options
author | John Hodge (bugs) <tpg@mutabah.net> | 2017-05-14 12:01:45 +0800 |
---|---|---|
committer | John Hodge (bugs) <tpg@mutabah.net> | 2017-05-14 12:01:45 +0800 |
commit | 1d2fe7681219700998c8ecbdb8ed5acab66578df (patch) | |
tree | 0d38e8ab5fd80c890d3dec67a0596abfc7a4f0cd /samples/test | |
parent | c6fca061dd134068c831aefd88d9535a30f423ed (diff) | |
parent | fde22b3f03d802231985b8ded567cba16cb5aa00 (diff) | |
download | mrust-1d2fe7681219700998c8ecbdb8ed5acab66578df.tar.gz |
Merge branch 'master' of https://github.com/thepowersgang/mrustc
# Conflicts:
# src/common.hpp
# src/hir/deserialise.cpp
# src/hir_typeck/static.cpp
# src/mir/from_hir.cpp
# src/mir/from_hir.hpp
# src/mir/from_hir_match.cpp
# src/mir/helpers.hpp
# src/mir/mir_builder.cpp
Diffstat (limited to 'samples/test')
-rw-r--r-- | samples/test/for_underscore_drop.rs | 18 | ||||
-rw-r--r-- | samples/test/scoping_rules.rs | 21 |
2 files changed, 39 insertions, 0 deletions
diff --git a/samples/test/for_underscore_drop.rs b/samples/test/for_underscore_drop.rs new file mode 100644 index 00000000..e590fee0 --- /dev/null +++ b/samples/test/for_underscore_drop.rs @@ -0,0 +1,18 @@ + +struct DropFlag<'a>(&'a mut i32); +impl<'a> ::std::ops::Drop for DropFlag<'a> +{ + fn drop(&mut self) { + *self.0 += 1; + } +} + +#[test] +fn values_in_for_loop_dropped() +{ + let mut foo = 0; + for _ in Some(DropFlag(&mut foo)) + { + } + assert_eq!(foo, 1); +} diff --git a/samples/test/scoping_rules.rs b/samples/test/scoping_rules.rs new file mode 100644 index 00000000..9878fd16 --- /dev/null +++ b/samples/test/scoping_rules.rs @@ -0,0 +1,21 @@ + +struct DropFlag<'a>(&'a ::std::cell::Cell<i32>); +impl<'a> ::std::ops::Drop for DropFlag<'a> +{ + fn drop(&mut self) { + self.0.set( self.0.get() + 1 ); + } +} + +// Any temporaries defined in the expression part of a statement (i.e. in the yeilded part of a +// block) are stored in the parent scope. +#[test] +fn temporaries_in_yielded_expr() +{ + let drop_count = ::std::cell::Cell::new(0); + let _foo = ({ DropFlag(&drop_count).0 }, assert_eq!(drop_count.get(), 0) ); + drop(_foo); + assert_eq!(drop_count.get(), 1); +} + + |