Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
librustc: Fix up mutability in method autoderefs if incorrect, and
prefer `Deref` over `DerefMut` in all other circumstances. Closes #12825.
- Loading branch information
Showing
8 changed files
with
154 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2014 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. | ||
|
||
// Generic unique/owned smaht pointer. | ||
struct Own<T> { | ||
value: *mut T | ||
} | ||
|
||
impl<T> Deref<T> for Own<T> { | ||
fn deref<'a>(&'a self) -> &'a T { | ||
unsafe { &*self.value } | ||
} | ||
} | ||
|
||
impl<T> DerefMut<T> for Own<T> { | ||
fn deref_mut<'a>(&'a mut self) -> &'a mut T { | ||
unsafe { &mut *self.value } | ||
} | ||
} | ||
|
||
struct Point { | ||
x: int, | ||
y: int | ||
} | ||
|
||
impl Point { | ||
fn get(&mut self) -> (int, int) { | ||
(self.x, self.y) | ||
} | ||
} | ||
|
||
fn test0(mut x: Own<Point>) { | ||
let _ = x.get(); | ||
} | ||
|
||
fn test1(mut x: Own<Own<Own<Point>>>) { | ||
let _ = x.get(); | ||
} | ||
|
||
fn test2(mut x: Own<Own<Own<Point>>>) { | ||
let _ = (**x).get(); | ||
} | ||
|
||
fn main() {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from nikomatsakis
at pcwalton@496cc4c
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging pcwalton/rust/improve-method-lookup-autoderef = 496cc4c into auto
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pcwalton/rust/improve-method-lookup-autoderef = 496cc4c merged ok, testing candidate = 942b055c
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
exception: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/1250
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from nikomatsakis
at pcwalton@496cc4c
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging pcwalton/rust/improve-method-lookup-autoderef = 496cc4c into auto
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pcwalton/rust/improve-method-lookup-autoderef = 496cc4c merged ok, testing candidate = 60e7317
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/1605
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/1602
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1596
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1602
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/1599
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1598
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1598
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/1602
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1596
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1595
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/1598
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/1253
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/1251
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/1255
success: http://buildbot.rust-lang.org/builders/auto-win-64-opt/builds/88
success: http://buildbot.rust-lang.org/builders/auto-win-64-nopt-t/builds/86
success: http://buildbot.rust-lang.org/builders/auto-win-64-nopt-c/builds/86
496cc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 60e7317