]> git.lizzy.rs Git - rust.git/blob - tests/ui/neg_multiply.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[rust.git] / tests / ui / neg_multiply.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::neg_multiply)]
11 #![allow(clippy::no_effect, clippy::unnecessary_operation)]
12
13 use std::ops::Mul;
14
15 struct X;
16
17 impl Mul<isize> for X {
18     type Output = X;
19
20     fn mul(self, _r: isize) -> Self {
21         self
22     }
23 }
24
25 impl Mul<X> for isize {
26     type Output = X;
27
28     fn mul(self, _r: X) -> X {
29         X
30     }
31 }
32
33 fn main() {
34     let x = 0;
35
36     x * -1;
37
38     -1 * x;
39
40     -1 * -1; // should be ok
41
42     X * -1; // should be ok
43     -1 * X; // should also be ok
44 }