Skip to content

Commit 4da796f

Browse files
committed
Fix reborrows of &mut pointers
Fixes #28839
1 parent 3729b12 commit 4da796f

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/librustc_typeck/check/coercion.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
110110
a,
111111
b);
112112

113-
if a == b {
114-
return Ok(None);
115-
}
116-
117113
// Consider coercing the subtype to a DST
118114
let unsize = self.unpack_actual_value(a, |a| {
119115
self.coerce_unsized(a, b)

src/test/compile-fail/borrowck-loan-of-static-data-issue-27616.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn evil(mut s: &'static mut String)
2323
let alias: &'static mut String = s;
2424
let inner: &str = &alias;
2525
// free value
26-
*s = String::new(); //~ ERROR use of moved value
26+
*s = String::new(); //~ ERROR cannot assign
2727
let _spray = "0wned".to_owned();
2828
// ... and then use it
2929
println!("{}", inner);

src/test/run-pass/issue-28839.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-pretty : (#23623) problems with newlines before // comments
12+
13+
pub struct Foo;
14+
15+
pub fn get_foo2<'a>(foo: &'a mut Option<&'a mut Foo>) -> &'a mut Foo {
16+
match foo {
17+
// Ensure that this is not considered a move, but rather a reborrow.
18+
&mut Some(ref mut x) => *x,
19+
&mut None => panic!(),
20+
}
21+
}
22+
23+
fn main() {
24+
}

0 commit comments

Comments
 (0)