diff options
| author | bors <bors@rust-lang.org> | 2014-05-14 12:06:29 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-14 12:06:29 -0700 |
| commit | 2a7a39191a83fc2a63df6cb47acd344ae669d9c7 (patch) | |
| tree | e431c9df5c8e14fe8e4f66e258366b4c35b077e6 /src/test | |
| parent | 1a1645d3b1986b494087a3d3ab608e029432de20 (diff) | |
| parent | 595e2910d8132170dab30fd31fc09800609188a8 (diff) | |
| download | rust-2a7a39191a83fc2a63df6cb47acd344ae669d9c7.tar.gz rust-2a7a39191a83fc2a63df6cb47acd344ae669d9c7.zip | |
auto merge of #14086 : Ryman/rust/resolve_error_suggestions, r=alexcrichton
Provides better help for the resolve failures inside an `impl` if the name matches: - a field on the self type - a method on the self type - a method on the current trait ref (in a trait impl) Not handling trait method suggestions if in a regular `impl` (as you can see on line 69 of the test), I believe it is possible though. Also, provides a better message when `self` fails to resolve due to being a static method. It's using some unsafe pointers to skip copying the larger structures (which are only used in error conditions); it's likely possible to get it working with lifetimes (all the useful refs should outlive the visitor calls) but I haven't really figured that out for this case. (can switch to copying code if wanted) Closes #2356.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/issue-2356.rs | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/src/test/compile-fail/issue-2356.rs b/src/test/compile-fail/issue-2356.rs index 22676d0b8c5..4d9e56a21f8 100644 --- a/src/test/compile-fail/issue-2356.rs +++ b/src/test/compile-fail/issue-2356.rs @@ -8,12 +8,83 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-test Resolve code for classes knew how to do this, impls don't +trait Groom { + fn shave(); +} + +pub struct cat { + whiskers: int, +} + +pub enum MaybeDog { + Dog, + NoDog +} + +impl MaybeDog { + fn bark() { + // If this provides a suggestion, it's a bug as MaybeDog doesn't impl Groom + shave(); + //~^ ERROR: unresolved name `shave`. + } +} + +impl Groom for cat { + fn shave(&self, other: uint) { + whiskers -= other; + //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`? + shave(4); + //~^ ERROR: unresolved name `shave`. Did you mean to call `Groom::shave`? + purr(); + //~^ ERROR: unresolved name `purr`. Did you mean to call `self.purr`? + } +} + +impl cat { + fn static_method() {} -struct cat { - tail: int, + fn purr_louder() { + static_method(); + //~^ ERROR: unresolved name `static_method`. Did you mean to call `cat::static_method` + purr(); + //~^ ERROR: unresolved name `purr`. Did you mean to call `self.purr`? + purr(); + //~^ ERROR: unresolved name `purr`. Did you mean to call `self.purr`? + purr(); + //~^ ERROR: unresolved name `purr`. Did you mean to call `self.purr`? + } } impl cat { - pub fn meow() { tail += 1; } //~ ERROR: Did you mean: `self.tail` + fn meow() { + if self.whiskers > 3 { + //~^ ERROR: `self` is not available in a static method. Maybe a `self` argument is missing? + println!("MEOW"); + } + } + + fn purr(&self) { + grow_older(); + //~^ ERROR: unresolved name `grow_older`. Did you mean to call `cat::grow_older` + shave(); + //~^ ERROR: unresolved name `shave`. + } + + fn burn_whiskers(&mut self) { + whiskers = 0; + //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`? + } + + pub fn grow_older(other:uint) { + whiskers = 4; + //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`? + purr_louder(); + //~^ ERROR: unresolved name `purr_louder`. Did you mean to call `cat::purr_louder` + } +} + +fn main() { + self += 1; + //~^ ERROR: unresolved name `self`. + // it's a bug if this suggests a missing `self` as we're not in a method } |
