Merge pull request #390 from dtolnay/rawaddr
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add support for raw addr syntax
authored by David Tolnay · committed by GitHub · parents 6c52daa, fcf2ef8 · Browse files · 2 files·+27 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+27 added−0 removed
- tests:+11 added−0 removed
- other:+16 added−0 removed
Provenance
- Commit
a16252b- Tree
5313154- Author
David Tolnay <dtolnay@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
6c52daa- Parent 2
fcf2ef8
2 files changed+27 added−0 removed
modified:src/ensure.rs+16 added
153 unmodified lines154 (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $mut:tt $($dup:tt)*) &mut $($rest:tt)*) => {155 $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $mut) $($parse)*} ($($rest)*) $($rest)*)156 };157 158+ (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $raw:tt $mut:tt $($dup:tt)*) &raw mut $($rest:tt)*) => {159+ $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $raw $mut) $($parse)*} ($($rest)*) $($rest)*)160+ };161+162+ (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $raw:tt $const:tt $($dup:tt)*) &raw const $($rest:tt)*) => {163+ $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $raw $const) $($parse)*} ($($rest)*) $($rest)*)164+ };165+166 (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) & $($rest:tt)*) => {167 $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*)168 };169 170 (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $mut:tt $($dup:tt)*) &&mut $($rest:tt)*) => {171 $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $mut) $($parse)*} ($($rest)*) $($rest)*)172 };173 174+ (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $raw:tt $mut:tt $($dup:tt)*) &&raw mut $($rest:tt)*) => {175+ $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $raw $mut) $($parse)*} ($($rest)*) $($rest)*)176+ };177+178+ (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $raw:tt $const:tt $($dup:tt)*) &&raw const $($rest:tt)*) => {179+ $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $raw $const) $($parse)*} ($($rest)*) $($rest)*)180+ };181+182 (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $($dup:tt)*) && $($rest:tt)*) => {183 $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand) $($parse)*} ($($rest)*) $($rest)*)184 };185 750 unmodified linesmodified:tests/test_ensure.rs+11 added
184 unmodified lines185 let test = || Ok(ensure!(&mut x == *&&mut &2));186 assert_err(test, "Condition failed: `&mut x == *&&mut &2` (1 vs 2)");187 }188 189+#[rustversion::since(1.82)]190 #[test]191+fn test_raw_addr() {192+ let mut x = 1;193+ let test = || Ok(ensure!(S + &raw const x != S + &raw mut x));194+ assert_err(195+ test,196+ "Condition failed: `S + &raw const x != S + &raw mut x` (false vs false)",197+ );198+}199+200+#[test]201 fn test_if() {202 #[rustfmt::skip]203 let test = || Ok(ensure!(if false {}.t(1) == 2));204 assert_err(test, "Condition failed: `if false {}.t(1) == 2` (1 vs 2)");548 unmodified lines