File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ //! Regression test for <https://github.com/rust-lang/rust/issues/128381>.
2+
3+ struct Struct {
4+ field : u32 ,
5+ }
6+
7+ fn main ( ) {
8+ let mut some_struct = Some ( Struct { field : 42 } ) ;
9+ some_struct. as_mut ( ) . inspect ( |some_struct| {
10+ some_struct. field *= 10 ; //~ ERROR cannot assign to `some_struct.field`, which is behind a `&` reference
11+ // Users can't change type of `some_struct` param, so above error must not suggest it.
12+ } ) ;
13+
14+ // Same check as above but using `hir::ExprKind::Call` instead of `hir::ExprKind::MethodCall`.
15+ Option :: inspect ( some_struct. as_mut ( ) , |some_struct| {
16+ some_struct. field *= 20 ; //~ ERROR cannot assign to `some_struct.field`, which is behind a `&` reference
17+ } ) ;
18+ }
Original file line number Diff line number Diff line change 1+ error[E0594]: cannot assign to `some_struct.field`, which is behind a `&` reference
2+ --> $DIR/option-inspect-mutation.rs:10:9
3+ |
4+ LL | some_struct.as_mut().inspect(|some_struct| {
5+ | ----------- consider changing this binding's type to be: `&mut &mut Struct`
6+ LL | some_struct.field *= 10;
7+ | ^^^^^^^^^^^^^^^^^^^^^^^ `some_struct` is a `&` reference, so it cannot be written to
8+
9+ error[E0594]: cannot assign to `some_struct.field`, which is behind a `&` reference
10+ --> $DIR/option-inspect-mutation.rs:16:9
11+ |
12+ LL | Option::inspect(some_struct.as_mut(), |some_struct| {
13+ | ----------- consider changing this binding's type to be: `&mut &mut Struct`
14+ LL | some_struct.field *= 20;
15+ | ^^^^^^^^^^^^^^^^^^^^^^^ `some_struct` is a `&` reference, so it cannot be written to
16+
17+ error: aborting due to 2 previous errors
18+
19+ For more information about this error, try `rustc --explain E0594`.
You can’t perform that action at this time.
0 commit comments