about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-06-08 01:48:59 +0000
committerbors <bors@rust-lang.org>2015-06-08 01:48:59 +0000
commitdcc59c09a9efbaeb72a8de110804871dccac1854 (patch)
treea4cd6c3660fd2e4d4b5a2ced58642490c186ad7a /src/test
parent8f9f2fe97e78bd7dbdfc477b765d5e6dc930b9eb (diff)
parent93d01eb443d0f871716c9d7faa3b69dc49662663 (diff)
downloadrust-dcc59c09a9efbaeb72a8de110804871dccac1854.tar.gz
rust-dcc59c09a9efbaeb72a8de110804871dccac1854.zip
Auto merge of #26087 - fitzgen:improve-suggestion-hueristics, r=Aatch
This makes the maximum edit distance of typo suggestions a function of the typo'd name's length. FWIW, clang uses this same hueristic, and I've found their suggestions to be better than rustc's. Without something like this, you end up with suggestions that aren't related at all when there are short variable names.

See also https://github.com/rust-lang/rust/issues/20028#issuecomment-109767159
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/bad-expr-path.rs4
-rw-r--r--src/test/compile-fail/bad-expr-path2.rs8
-rw-r--r--src/test/compile-fail/typo-suggestion.rs21
3 files changed, 27 insertions, 6 deletions
diff --git a/src/test/compile-fail/bad-expr-path.rs b/src/test/compile-fail/bad-expr-path.rs
index 38ba652f53b..c35c9255ed2 100644
--- a/src/test/compile-fail/bad-expr-path.rs
+++ b/src/test/compile-fail/bad-expr-path.rs
@@ -8,8 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// error-pattern: unresolved name `m1::a`. Did you mean `args`?
+// error-pattern: unresolved name `m1::arguments`. Did you mean `arguments`?
 
 mod m1 {}
 
-fn main(args: Vec<String>) { log(debug, m1::a); }
+fn main(arguments: Vec<String>) { log(debug, m1::arguments); }
diff --git a/src/test/compile-fail/bad-expr-path2.rs b/src/test/compile-fail/bad-expr-path2.rs
index f397d0b387d..af34887dec9 100644
--- a/src/test/compile-fail/bad-expr-path2.rs
+++ b/src/test/compile-fail/bad-expr-path2.rs
@@ -8,12 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// error-pattern: unresolved name `m1::a`. Did you mean `args`?
+// error-pattern: unresolved name `m1::arguments`. Did you mean `arguments`?
 
 mod m1 {
-    pub mod a {}
+    pub mod arguments {}
 }
 
-fn main(args: Vec<String>) {
-    log(debug, m1::a);
+fn main(arguments: Vec<String>) {
+    log(debug, m1::arguments);
 }
diff --git a/src/test/compile-fail/typo-suggestion.rs b/src/test/compile-fail/typo-suggestion.rs
new file mode 100644
index 00000000000..d5cf6a294ee
--- /dev/null
+++ b/src/test/compile-fail/typo-suggestion.rs
@@ -0,0 +1,21 @@
+// 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.
+
+fn main() {
+    let foo = 1;
+
+    // `foo` shouldn't be suggested, it is too dissimilar from `bar`.
+    println!("Hello {}", bar);
+    //~^ ERROR: unresolved name `bar`
+
+    // But this is close enough.
+    println!("Hello {}", fob);
+    //~^ ERROR: unresolved name `fob`. Did you mean `foo`?
+}