Skip to content

Commit 378c4ab

Browse files
committed
Make public API, docs algorithm-agnostic
1 parent c2f2a3c commit 378c4ab

File tree

16 files changed

+81
-73
lines changed

16 files changed

+81
-73
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
1313
use rustc_hir::PredicateOrigin;
1414
use rustc_index::vec::{Idx, IndexVec};
1515
use rustc_middle::ty::{DefIdTree, ResolverAstLowering, TyCtxt};
16-
use rustc_span::lev_distance::find_best_match_for_name;
16+
use rustc_span::edit_distance::find_best_match_for_name;
1717
use rustc_span::source_map::DesugaringKind;
1818
use rustc_span::symbol::{kw, sym, Ident};
1919
use rustc_span::{Span, Symbol};

compiler/rustc_hir_analysis/src/astconv/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir as hir;
66
use rustc_hir::def_id::DefId;
77
use rustc_middle::ty;
88
use rustc_session::parse::feature_err;
9-
use rustc_span::lev_distance::find_best_match_for_name;
9+
use rustc_span::edit_distance::find_best_match_for_name;
1010
use rustc_span::symbol::{sym, Ident};
1111
use rustc_span::{Span, Symbol, DUMMY_SP};
1212

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use rustc_middle::ty::DynKind;
3434
use rustc_middle::ty::GenericParamDefKind;
3535
use rustc_middle::ty::{self, Const, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeVisitable};
3636
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS};
37+
use rustc_span::edit_distance::find_best_match_for_name;
3738
use rustc_span::edition::Edition;
38-
use rustc_span::lev_distance::find_best_match_for_name;
3939
use rustc_span::symbol::{kw, Ident, Symbol};
4040
use rustc_span::{sym, Span, DUMMY_SP};
4141
use rustc_target::spec::abi;

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use rustc_middle::ty::subst::SubstsRef;
4545
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitable};
4646
use rustc_session::errors::ExprParenthesesNeeded;
4747
use rustc_session::parse::feature_err;
48+
use rustc_span::edit_distance::find_best_match_for_name;
4849
use rustc_span::hygiene::DesugaringKind;
49-
use rustc_span::lev_distance::find_best_match_for_name;
5050
use rustc_span::source_map::{Span, Spanned};
5151
use rustc_span::symbol::{kw, sym, Ident, Symbol};
5252
use rustc_target::spec::abi::Abi::RustIntrinsic;

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use rustc_middle::ty::{InternalSubsts, SubstsRef};
2525
use rustc_session::lint;
2626
use rustc_span::def_id::DefId;
2727
use rustc_span::def_id::LocalDefId;
28-
use rustc_span::lev_distance::{
29-
find_best_match_for_name_with_substrings, lev_distance_with_substrings,
28+
use rustc_span::edit_distance::{
29+
edit_distance_with_substrings, find_best_match_for_name_with_substrings,
3030
};
3131
use rustc_span::symbol::sym;
3232
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
@@ -70,7 +70,7 @@ struct ProbeContext<'a, 'tcx> {
7070
impl_dups: FxHashSet<DefId>,
7171

7272
/// When probing for names, include names that are close to the
73-
/// requested name (by Levenshtein distance)
73+
/// requested name (by edit distance)
7474
allow_similar_names: bool,
7575

7676
/// Some(candidate) if there is a private candidate
@@ -1794,7 +1794,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17941794

17951795
/// Similarly to `probe_for_return_type`, this method attempts to find the best matching
17961796
/// candidate method where the method name may have been misspelled. Similarly to other
1797-
/// Levenshtein based suggestions, we provide at most one such suggestion.
1797+
/// edit distance based suggestions, we provide at most one such suggestion.
17981798
fn probe_for_similar_candidate(&mut self) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
17991799
debug!("probing for method names similar to {:?}", self.method_name);
18001800

@@ -2052,8 +2052,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
20522052
if self.matches_by_doc_alias(x.def_id) {
20532053
return true;
20542054
}
2055-
match lev_distance_with_substrings(name.as_str(), x.name.as_str(), max_dist)
2056-
{
2055+
match edit_distance_with_substrings(
2056+
name.as_str(),
2057+
x.name.as_str(),
2058+
max_dist,
2059+
) {
20572060
Some(d) => d > 0,
20582061
None => false,
20592062
}

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_middle::ty::{self, DefIdTree, GenericArgKind, Ty, TyCtxt, TypeVisitabl
3131
use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef};
3232
use rustc_span::symbol::{kw, sym, Ident};
3333
use rustc_span::Symbol;
34-
use rustc_span::{lev_distance, source_map, ExpnKind, FileName, MacroKind, Span};
34+
use rustc_span::{edit_distance, source_map, ExpnKind, FileName, MacroKind, Span};
3535
use rustc_trait_selection::traits::error_reporting::on_unimplemented::OnUnimplementedNote;
3636
use rustc_trait_selection::traits::error_reporting::on_unimplemented::TypeErrCtxtExt as _;
3737
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
@@ -1014,7 +1014,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10141014
// that had unsatisfied trait bounds
10151015
if unsatisfied_predicates.is_empty() && rcvr_ty.is_enum() {
10161016
let adt_def = rcvr_ty.ty_adt_def().expect("enum is not an ADT");
1017-
if let Some(suggestion) = lev_distance::find_best_match_for_name(
1017+
if let Some(suggestion) = edit_distance::find_best_match_for_name(
10181018
&adt_def.variants().iter().map(|s| s.name).collect::<Vec<_>>(),
10191019
item_name.name,
10201020
None,

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
1414
use rustc_middle::middle::stability::EvalResult;
1515
use rustc_middle::ty::{self, Adt, BindingMode, Ty, TypeVisitable};
1616
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
17+
use rustc_span::edit_distance::find_best_match_for_name;
1718
use rustc_span::hygiene::DesugaringKind;
18-
use rustc_span::lev_distance::find_best_match_for_name;
1919
use rustc_span::source_map::{Span, Spanned};
2020
use rustc_span::symbol::{kw, sym, Ident};
2121
use rustc_span::{BytePos, DUMMY_SP};

compiler/rustc_interface/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc_session::filesearch::sysroot_candidates;
1414
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
1515
use rustc_session::parse::CrateConfig;
1616
use rustc_session::{early_error, filesearch, output, Session};
17+
use rustc_span::edit_distance::find_best_match_for_name;
1718
use rustc_span::edition::Edition;
18-
use rustc_span::lev_distance::find_best_match_for_name;
1919
use rustc_span::source_map::FileLoader;
2020
use rustc_span::symbol::{sym, Symbol};
2121
use session::CompilerIO;

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_middle::ty::{self, print::Printer, subst::GenericArg, RegisteredTools,
3939
use rustc_session::lint::{BuiltinLintDiagnostics, LintExpectationId};
4040
use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId};
4141
use rustc_session::Session;
42-
use rustc_span::lev_distance::find_best_match_for_name;
42+
use rustc_span::edit_distance::find_best_match_for_name;
4343
use rustc_span::symbol::{sym, Ident, Symbol};
4444
use rustc_span::{BytePos, Span};
4545
use rustc_target::abi;

compiler/rustc_parse/src/parser/item.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use rustc_errors::{
1919
struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, PResult,
2020
StashKey,
2121
};
22+
use rustc_span::edit_distance::edit_distance;
2223
use rustc_span::edition::Edition;
23-
use rustc_span::lev_distance::lev_distance;
2424
use rustc_span::source_map::{self, Span};
2525
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2626
use rustc_span::DUMMY_SP;
@@ -459,7 +459,8 @@ impl<'a> Parser<'a> {
459459
// Maybe the user misspelled `macro_rules` (issue #91227)
460460
if self.token.is_ident()
461461
&& path.segments.len() == 1
462-
&& lev_distance("macro_rules", &path.segments[0].ident.to_string(), 3).is_some()
462+
&& edit_distance("macro_rules", &path.segments[0].ident.to_string(), 3)
463+
.is_some()
463464
{
464465
err.span_suggestion(
465466
path.span,

0 commit comments

Comments
 (0)