rust/src/test/ui/did_you_mean/issue-39544.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub enum X {
Y
}
pub struct Z {
x: X
}
2017-03-26 17:35:50 -05:00
fn main() {
let z = Z { x: X::Y };
2017-11-20 06:13:27 -06:00
let _ = &mut z.x; //~ ERROR cannot borrow
}
2017-03-26 17:35:50 -05:00
impl Z {
fn foo<'z>(&'z self) {
2017-11-20 06:13:27 -06:00
let _ = &mut self.x; //~ ERROR cannot borrow
2017-03-26 17:35:50 -05:00
}
fn foo1(&self, other: &Z) {
2017-11-20 06:13:27 -06:00
let _ = &mut self.x; //~ ERROR cannot borrow
let _ = &mut other.x; //~ ERROR cannot borrow
2017-03-26 17:35:50 -05:00
}
fn foo2<'a>(&'a self, other: &Z) {
2017-11-20 06:13:27 -06:00
let _ = &mut self.x; //~ ERROR cannot borrow
let _ = &mut other.x; //~ ERROR cannot borrow
2017-03-26 17:35:50 -05:00
}
fn foo3<'a>(self: &'a Self, other: &Z) {
2017-11-20 06:13:27 -06:00
let _ = &mut self.x; //~ ERROR cannot borrow
let _ = &mut other.x; //~ ERROR cannot borrow
2017-03-26 17:35:50 -05:00
}
fn foo4(other: &Z) {
2017-11-20 06:13:27 -06:00
let _ = &mut other.x; //~ ERROR cannot borrow
2017-03-26 17:35:50 -05:00
}
}
pub fn with_arg(z: Z, w: &Z) {
2017-11-20 06:13:27 -06:00
let _ = &mut z.x; //~ ERROR cannot borrow
let _ = &mut w.x; //~ ERROR cannot borrow
}
pub fn with_tuple() {
let mut y = 0;
let x = (&y,);
2017-11-20 06:13:27 -06:00
*x.0 = 1; //~ ERROR cannot assign to immutable borrowed content
}