Skip to content

Commit

Permalink
auto merge of #5579 : dbaupp/rust/rustc-typo-limit, r=catamorphism
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Mar 28, 2013
2 parents 84ddff3 + ab5346d commit d7ba0ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = ~[];
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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`. \
Expand Down Expand Up @@ -5292,4 +5294,3 @@ pub fn resolve_crate(session: Session,
trait_map: trait_map
}
}

13 changes: 13 additions & 0 deletions src/test/compile-fail/issue-2281-part1.rs
Original file line number Diff line number Diff line change
@@ -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); }

0 comments on commit d7ba0ac

Please sign in to comment.