diff --git a/src/intrinsic.rs b/src/intrinsic.rs index b7c5d8d07c25..09df91b3ab38 100644 --- a/src/intrinsic.rs +++ b/src/intrinsic.rs @@ -245,7 +245,13 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a, this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?; }, - "likely" | "unlikely" | "forget" => {} + "forget" => {} + + "likely" | "unlikely" => { + // These just return their argument + let b = this.read_immediate(args[0])?; + this.write_immediate(*b, dest)?; + } "init" => { // Check fast path: we don't want to force an allocation in case the destination is a simple value, diff --git a/tests/run-pass/iter.rs b/tests/run-pass/iter.rs new file mode 100644 index 000000000000..1bef21d83bda --- /dev/null +++ b/tests/run-pass/iter.rs @@ -0,0 +1,40 @@ +fn iter_empty_and_zst() { + for _ in Vec::::new().iter() { // this iterates over a Unique::empty() + panic!("We should never be here."); + } + + // Iterate over a ZST (uses arith_offset internally) + let mut count = 0; + for _ in &[(), (), ()] { + count += 1; + } + assert_eq!(count, 3); +} + +fn test_iterator_step_by_nth() { + let mut it = (0..16).step_by(5); + assert_eq!(it.nth(0), Some(0)); + assert_eq!(it.nth(0), Some(5)); + assert_eq!(it.nth(0), Some(10)); + assert_eq!(it.nth(0), Some(15)); + assert_eq!(it.nth(0), None); +} + +fn iter_any() { + let f = |x: &u8| { 10u8 == *x }; + f(&1u8); + + let g = |(), x: &u8| { 10u8 == *x }; + g((), &1u8); + + let h = |(), (), x: &u8| { 10u8 == *x }; + h((), (), &1u8); + + [1, 2, 3u8].into_iter().any(|elt| 10 == *elt); +} + +fn main() { + test_iterator_step_by_nth(); + iter_any(); + iter_empty_and_zst(); +} diff --git a/tests/run-pass/iter_any.rs b/tests/run-pass/iter_any.rs deleted file mode 100644 index b14eb074488b..000000000000 --- a/tests/run-pass/iter_any.rs +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() { - let f = |x: &u8| { 10u8 == *x }; - f(&1u8); - - let g = |(), x: &u8| { 10u8 == *x }; - g((), &1u8); - - let h = |(), (), x: &u8| { 10u8 == *x }; - h((), (), &1u8); - - [1, 2, 3u8].into_iter().any(|elt| 10 == *elt); -} diff --git a/tests/run-pass/iter_slice.rs b/tests/run-pass/iter_slice.rs deleted file mode 100644 index fd7229c3455e..000000000000 --- a/tests/run-pass/iter_slice.rs +++ /dev/null @@ -1,12 +0,0 @@ -fn main() { - for _ in Vec::::new().iter() { // this iterates over a Unique::empty() - panic!("We should never be here."); - } - - // Iterate over a ZST (uses arith_offset internally) - let mut count = 0; - for _ in &[(), (), ()] { - count += 1; - } - assert_eq!(count, 3); -}