File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1212#![ deny( unused_assignments) ]
1313#![ allow( dead_code, non_camel_case_types, trivial_numeric_casts) ]
1414
15+ use std:: ops:: AddAssign ;
16+
1517fn f1 ( x : isize ) {
1618 //~^ ERROR unused variable: `x`
1719}
@@ -100,5 +102,30 @@ fn f5c() {
100102 }
101103}
102104
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+
103130fn main ( ) {
104131}
You can’t perform that action at this time.
0 commit comments