Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};

// Diagnostic: undeclared-label
pub(crate) fn undeclared_label(
    ctx: &DiagnosticsContext<'_>,
    d: &hir::UndeclaredLabel,
) -> Diagnostic {
    let name = &d.name;
    Diagnostic::new_with_syntax_node_ptr(
        ctx,
        DiagnosticCode::RustcHardError("undeclared-label"),
        format!("use of undeclared label `{}`", name.display(ctx.sema.db)),
        d.node.clone().map(|it| it.into()),
    )
}

#[cfg(test)]
mod tests {
    use crate::tests::check_diagnostics;

    #[test]
    fn smoke_test() {
        check_diagnostics(
            r#"
fn foo() {
    break 'a;
  //^^^^^^^^ error: break outside of loop
        //^^ error: use of undeclared label `'a`
    continue 'a;
  //^^^^^^^^^^^ error: continue outside of loop
           //^^ error: use of undeclared label `'a`
}
"#,
        );
    }

    #[test]
    fn while_let_loop_with_label_in_condition() {
        check_diagnostics(
            r#"
fn foo() {
    let mut optional = Some(0);

    'my_label: while let Some(a) = match optional {
        None => break 'my_label,
        Some(val) => Some(val),
    } {
        optional = None;
        continue 'my_label;
    }
}
"#,
        );
    }

    #[test]
    fn for_loop() {
        check_diagnostics(
            r#"
//- minicore: iterator
fn foo() {
    'xxx: for _ in unknown {
        'yyy: for _ in unknown {
            break 'xxx;
            continue 'yyy;
            break 'zzz;
                //^^^^ error: use of undeclared label `'zzz`
        }
        continue 'xxx;
        continue 'yyy;
               //^^^^ error: use of undeclared label `'yyy`
        break 'xxx;
        break 'yyy;
            //^^^^ error: use of undeclared label `'yyy`
    }
}
"#,
        );
    }

    #[test]
    fn try_operator_desugar_works() {
        check_diagnostics(
            r#"
//- minicore: option, try
fn foo() {
    None?;
}
"#,
        );
        check_diagnostics(
            r#"
//- minicore: option, try, future
async fn foo() {
    None?;
}
"#,
        );
        check_diagnostics(
            r#"
//- minicore: option, try, future, fn
async fn foo() {
    || None?;
}
"#,
        );
    }
}
vatar/33b4cff6a0b66c779a28144db06833d68afb98e95cd2b006e44c9fa97f476c3a?s=32"> bendn inline
62201c0 · 2023-10-03 22Commits
.gitignore
-rw-r--r--
19
Cargo.toml
-rw-r--r--
225
LICENSE
-rw-r--r--
1062
src
d---------
README.md

umath: ffast-math, for rust.

MSRV DOCS

Want to make your math faster? *t&c apply

Want to order a float?

You can do all of that, with umath!

use umath::FFloat;
// wrap a non NAN and non INF f32/f64 (we will also *never* make this number nan).
let mut f = unsafe { FFloat::new(4.0f32) };
f *= 3; // multiply by 3
// this check will be removed by the optimizer!
assert!(!f.is_nan());
# use std::collections::BinaryHeap;
// use a ORD type! this is allowed, as FFloat is not allowed to be NAN | INF.
let mut b = BinaryHeap::new();
b.push(unsafe { FFloat::new(2.0) });
b.push(unsafe { FFloat::new(1.0) });
b.push(unsafe { FFloat::new(3.0) });
b.push(f);
assert_eq!(b.pop(), Some(unsafe { FFloat::new(24.0) }));

A note on safety

When you make your first FFLoat, you must promise that you will never create a NAN | INF FFLoat. Hence, *f = NAN is (delayed) UB.

Nightlyness

umath is nightly because it makes use of core intrinsics, like fadd_fast(), which require the core_intrinsics feature to use.