mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Add regression tests for op_ref
This commit is contained in:
parent
7aa42073f2
commit
96b25cdaf2
@ -2,7 +2,7 @@
|
||||
#![plugin(clippy)]
|
||||
|
||||
#[deny(eq_op)]
|
||||
#[allow(identity_op, double_parens)]
|
||||
#[allow(identity_op, double_parens, many_single_char_names)]
|
||||
#[allow(no_effect, unused_variables, unnecessary_operation, short_circuit_statement)]
|
||||
#[deny(nonminimal_bool)]
|
||||
fn main() {
|
||||
@ -59,4 +59,40 @@ fn main() {
|
||||
a == a;
|
||||
2*a.len() == 2*a.len(); // ok, functions
|
||||
a.pop() == a.pop(); // ok, functions
|
||||
|
||||
use std::ops::BitAnd;
|
||||
struct X(i32);
|
||||
impl BitAnd for X {
|
||||
type Output = X;
|
||||
fn bitand(self, rhs: X) -> X {
|
||||
X(self.0 & rhs.0)
|
||||
}
|
||||
}
|
||||
impl<'a> BitAnd<&'a X> for X {
|
||||
type Output = X;
|
||||
fn bitand(self, rhs: &'a X) -> X {
|
||||
X(self.0 & rhs.0)
|
||||
}
|
||||
}
|
||||
let x = X(1);
|
||||
let y = X(2);
|
||||
let z = x & &y;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Y(i32);
|
||||
impl BitAnd for Y {
|
||||
type Output = Y;
|
||||
fn bitand(self, rhs: Y) -> Y {
|
||||
Y(self.0 & rhs.0)
|
||||
}
|
||||
}
|
||||
impl<'a> BitAnd<&'a Y> for Y {
|
||||
type Output = Y;
|
||||
fn bitand(self, rhs: &'a Y) -> Y {
|
||||
Y(self.0 & rhs.0)
|
||||
}
|
||||
}
|
||||
let x = Y(1);
|
||||
let y = Y(2);
|
||||
let z = x & &y;
|
||||
}
|
||||
|
@ -219,5 +219,15 @@ error: equal expressions as operands to `==`
|
||||
59 | a == a;
|
||||
| ^^^^^^
|
||||
|
||||
warning: taken reference of right operand
|
||||
--> $DIR/eq_op.rs:97:13
|
||||
|
|
||||
97 | let z = x & &y;
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: #[warn(op_ref)] on by default
|
||||
help: use the right value directly
|
||||
| let z = y & &y;
|
||||
|
||||
error: aborting due to 32 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user