Add suggestions for misspelled method names

Use the syntax::util::lev_distance module to provide suggestions when a
named method cannot be found.

Part of #30197
This commit is contained in:
Thomas Jespersen 2017-03-20 20:02:51 +01:00
parent ef227f5ffe
commit 09defbcb5b
6 changed files with 145 additions and 10 deletions

View file

@ -3,6 +3,8 @@ error[E0599]: no method named `b` found for type `&Self` in the current scope
|
13 | || self.b()
| ^
|
= help: did you mean `a`?
error[E0308]: mismatched types
--> $DIR/issue-3563.rs:13:9

View file

@ -0,0 +1,38 @@
// 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.
struct Foo;
impl Foo {
fn bar(self) {}
fn baz(&self, x: f64) {}
}
trait FooT {
fn bag(&self);
}
impl FooT for Foo {
fn bag(&self) {}
}
fn main() {
let f = Foo;
f.bat(1.0);
let s = "foo".to_string();
let _ = s.is_emtpy();
// Generates a warning, both for count_ones and count_zeros
let _ = 63u32.count_eos();
let _ = 63u32.count_o(); // Does not generate a warning
}

View file

@ -0,0 +1,34 @@
error[E0599]: no method named `bat` found for type `Foo` in the current scope
--> $DIR/suggest-methods.rs:28:7
|
28 | f.bat(1.0);
| ^^^
|
= help: did you mean `bar`?
= help: did you mean `baz`?
error[E0599]: no method named `is_emtpy` found for type `std::string::String` in the current scope
--> $DIR/suggest-methods.rs:31:15
|
31 | let _ = s.is_emtpy();
| ^^^^^^^^
|
= help: did you mean `is_empty`?
error[E0599]: no method named `count_eos` found for type `u32` in the current scope
--> $DIR/suggest-methods.rs:34:19
|
34 | let _ = 63u32.count_eos();
| ^^^^^^^^^
|
= help: did you mean `count_ones`?
= help: did you mean `count_zeros`?
error[E0599]: no method named `count_o` found for type `u32` in the current scope
--> $DIR/suggest-methods.rs:35:19
|
35 | let _ = 63u32.count_o(); // Does not generate a warning
| ^^^^^^^
error: aborting due to 4 previous errors