File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 12
12
#![ deny( unused_assignments) ]
13
13
#![ allow( dead_code, non_camel_case_types, trivial_numeric_casts) ]
14
14
15
+ use std:: ops:: AddAssign ;
16
+
15
17
fn f1 ( x : isize ) {
16
18
//~^ ERROR unused variable: `x`
17
19
}
@@ -100,5 +102,30 @@ fn f5c() {
100
102
}
101
103
}
102
104
105
+ struct View < ' a > ( & ' a mut [ i32 ] ) ;
106
+
107
+ impl < ' a > AddAssign < i32 > for View < ' a > {
108
+ fn add_assign ( & mut self , rhs : i32 ) {
109
+ for lhs in self . 0 . iter_mut ( ) {
110
+ * lhs += rhs;
111
+ }
112
+ }
113
+ }
114
+
115
+ fn f6 ( ) {
116
+ let mut array = [ 1 , 2 , 3 ] ;
117
+ let mut v = View ( & mut array) ;
118
+
119
+ // ensure an error shows up for x even if lhs of an overloaded add assign
120
+
121
+ let x;
122
+ //~^ ERROR variable `x` is assigned to, but never used
123
+
124
+ * ( {
125
+ x = 0 ; //~ ERROR value assigned to `x` is never read
126
+ & mut v
127
+ } ) += 1 ;
128
+ }
129
+
103
130
fn main ( ) {
104
131
}
You can’t perform that action at this time.
0 commit comments