about summary refs log tree commit diff
path: root/tests/ui/lint/negative_literals.rs
blob: 5964bbb559a1e2965617b017469c17120a9f40c4 (plain)
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
//@ check-fail

#![deny(ambiguous_negative_literals)]

fn main() {
    let _ = -1i32.abs();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1f32.abs();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1f64.asin();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1f64.asinh();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1f64.tan();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1f64.tanh();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1.0_f64.cos().cos();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1.0_f64.cos().sin();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1.0_f64.sin().cos();
    //~^ ERROR `-` has lower precedence than method calls
    let _ = -1f64.sin().sin();
    //~^ ERROR `-` has lower precedence than method calls

    dbg!( -1.0_f32.cos() );
    //~^ ERROR `-` has lower precedence than method calls

    // should not warn
    let _ = (-1i32).abs();
    let _ = (-1f32).abs();
    let _ = -(1i32).abs();
    let _ = -(1f32).abs();
    let _ = -(1i32.abs());
    let _ = -(1f32.abs());
}