forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial fix for rust-lang#2687---impl method must only be subtype of …
…trait method, not exact match.
- Loading branch information
1 parent
2ab614f
commit 2093952
Showing
3 changed files
with
66 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
trait Mumbo { | ||
pure fn jumbo(&self, x: @uint) -> uint; | ||
fn jambo(&self, x: @const uint) -> uint; | ||
fn jbmbo(&self) -> @uint; | ||
} | ||
|
||
impl uint: Mumbo { | ||
// Cannot have a larger effect than the trait: | ||
fn jumbo(&self, x: @uint) { *self + *x; } | ||
//~^ ERROR expected pure fn but found impure fn | ||
|
||
// Cannot accept a narrower range of parameters: | ||
fn jambo(&self, x: @uint) { *self + *x; } | ||
//~^ ERROR values differ in mutability | ||
|
||
// Cannot return a wider range of values: | ||
fn jbmbo(&self) -> @const uint { @const 0 } | ||
//~^ ERROR values differ in mutability | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
trait Mumbo { | ||
fn jumbo(&self, x: @uint) -> uint; | ||
} | ||
|
||
impl uint: Mumbo { | ||
// Note: this method def is ok, it is more accepting and | ||
// less effecting than the trait method: | ||
pure fn jumbo(&self, x: @const uint) -> uint { *self + *x } | ||
} | ||
|
||
fn main() { | ||
let a = 3u; | ||
let b = a.jumbo(@mut 6); | ||
|
||
let x = @a as @Mumbo; | ||
let y = x.jumbo(@mut 6); //~ ERROR values differ in mutability | ||
let z = x.jumbo(@6); | ||
} | ||
|
||
|
||
|