diff options
| author | bors <bors@rust-lang.org> | 2013-03-27 23:10:19 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-27 23:10:19 -0700 |
| commit | d7ba0acbf5aef70cb4afd162e0c0a1fa07813db7 (patch) | |
| tree | 5a870d57ba2bd716cd9a5166d0c46ec19ee386ec | |
| parent | 84ddff3909b5920228642649b7f5cc011c0b900a (diff) | |
| parent | ab5346d119b6ac3ba9e9d67df929fdf546865d0a (diff) | |
| download | rust-d7ba0acbf5aef70cb4afd162e0c0a1fa07813db7.tar.gz rust-d7ba0acbf5aef70cb4afd162e0c0a1fa07813db7.zip | |
auto merge of #5579 : dbaupp/rust/rustc-typo-limit, r=catamorphism
Impose a limit so that the typo suggester only shows reasonable suggestions (i.e. don't suggest `args` when the error is `foobar`). A tiny bit of progress on #2281.
| -rw-r--r-- | src/librustc/middle/resolve.rs | 9 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-2281-part1.rs | 13 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 66dc1a37e51..0c9c7a73902 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -4666,7 +4666,7 @@ pub impl Resolver { } } - fn find_best_match_for_name(@mut self, name: &str) -> Option<~str> { + fn find_best_match_for_name(@mut self, name: &str, max_distance: uint) -> Option<~str> { let this = &mut *self; let mut maybes: ~[~str] = ~[]; @@ -4694,6 +4694,7 @@ pub impl Resolver { if vec::len(values) > 0 && values[smallest] != uint::max_value && values[smallest] < str::len(name) + 2 && + values[smallest] <= max_distance && maybes[smallest] != name.to_owned() { Some(vec::swap_remove(&mut maybes, smallest)) @@ -4770,8 +4771,9 @@ pub impl Resolver { wrong_name)); } else { - match self.find_best_match_for_name(wrong_name) { - + // limit search to 5 to reduce the number + // of stupid suggestions + match self.find_best_match_for_name(wrong_name, 5) { Some(m) => { self.session.span_err(expr.span, fmt!("unresolved name: `%s`. \ @@ -5292,4 +5294,3 @@ pub fn resolve_crate(session: Session, trait_map: trait_map } } - diff --git a/src/test/compile-fail/issue-2281-part1.rs b/src/test/compile-fail/issue-2281-part1.rs new file mode 100644 index 00000000000..3951eaad6d1 --- /dev/null +++ b/src/test/compile-fail/issue-2281-part1.rs @@ -0,0 +1,13 @@ +// Copyright 2012 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. + +// error-pattern: unresolved name: `foobar`. + +fn main(args: ~[str]) { debug!(foobar); } |
