mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
librustc: Limit the typo suggestions to reasonable suggests.
Impose a limit so that the typo suggester only shows reasonable suggestions (i.e. don't suggest `args` when the error is `foobar`).
This commit is contained in:
parent
2888563510
commit
ab5346d119
|
@ -4667,7 +4667,7 @@ fn resolve_item_by_identifier_in_lexical_scope(@mut self,
|
|||
}
|
||||
}
|
||||
|
||||
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] = ~[];
|
||||
|
@ -4695,6 +4695,7 @@ fn find_best_match_for_name(@mut self, name: &str) -> Option<~str> {
|
|||
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))
|
||||
|
@ -4771,8 +4772,9 @@ fn resolve_expr(@mut self, expr: @expr, visitor: ResolveVisitor) {
|
|||
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`. \
|
||||
|
@ -5293,4 +5295,3 @@ pub fn resolve_crate(session: Session,
|
|||
trait_map: trait_map
|
||||
}
|
||||
}
|
||||
|
||||
|
|
13
src/test/compile-fail/issue-2281-part1.rs
Normal file
13
src/test/compile-fail/issue-2281-part1.rs
Normal file
|
@ -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); }
|
Loading…
Reference in a new issue