mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Pass HirId of expr in question instead of function body
This commit is contained in:
parent
a421cfed74
commit
120e5bdac0
@ -83,6 +83,8 @@ struct ProbeContext<'a, 'tcx> {
|
||||
unsatisfied_predicates: Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>)>,
|
||||
|
||||
is_suggestion: IsSuggestion,
|
||||
|
||||
scope_expr_id: hir::HirId,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
|
||||
@ -285,7 +287,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self_ty,
|
||||
scope_expr_id,
|
||||
ProbeScope::AllTraits,
|
||||
|probe_cx| probe_cx.pick(),
|
||||
|probe_cx| probe_cx.pick(scope_expr_id),
|
||||
)
|
||||
.ok()
|
||||
.map(|pick| pick.item)
|
||||
@ -317,7 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self_ty,
|
||||
scope_expr_id,
|
||||
scope,
|
||||
|probe_cx| probe_cx.pick(),
|
||||
|probe_cx| probe_cx.pick(scope_expr_id),
|
||||
)
|
||||
}
|
||||
|
||||
@ -448,6 +450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
orig_values,
|
||||
steps.steps,
|
||||
is_suggestion,
|
||||
scope_expr_id,
|
||||
);
|
||||
|
||||
probe_cx.assemble_inherent_candidates();
|
||||
@ -547,6 +550,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
orig_steps_var_values: OriginalQueryValues<'tcx>,
|
||||
steps: Lrc<Vec<CandidateStep<'tcx>>>,
|
||||
is_suggestion: IsSuggestion,
|
||||
scope_expr_id: hir::HirId,
|
||||
) -> ProbeContext<'a, 'tcx> {
|
||||
ProbeContext {
|
||||
fcx,
|
||||
@ -564,6 +568,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
private_candidate: None,
|
||||
unsatisfied_predicates: Vec::new(),
|
||||
is_suggestion,
|
||||
scope_expr_id,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1031,7 +1036,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// THE ACTUAL SEARCH
|
||||
|
||||
fn pick(mut self) -> PickResult<'tcx> {
|
||||
fn pick(mut self, scope_expr_id: hir::HirId) -> PickResult<'tcx> {
|
||||
assert!(self.method_name.is_some());
|
||||
|
||||
if let Some(r) = self.pick_core() {
|
||||
@ -1077,7 +1082,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
if let Some((kind, def_id)) = private_candidate {
|
||||
return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
|
||||
}
|
||||
let lev_candidate = self.probe_for_lev_candidate()?;
|
||||
let lev_candidate = self.probe_for_lev_candidate(scope_expr_id)?;
|
||||
|
||||
Err(MethodError::NoMatch(NoMatchData::new(
|
||||
static_candidates,
|
||||
@ -1312,7 +1317,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
) {
|
||||
self.tcx.struct_span_lint_hir(
|
||||
lint::builtin::UNSTABLE_NAME_COLLISIONS,
|
||||
self.fcx.body_id,
|
||||
self.scope_expr_id,
|
||||
self.span,
|
||||
|lint| {
|
||||
let def_kind = stable_pick.item.kind.as_def_kind();
|
||||
@ -1580,7 +1585,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
/// Similarly to `probe_for_return_type`, this method attempts to find the best matching
|
||||
/// candidate method where the method name may have been misspelt. Similarly to other
|
||||
/// Levenshtein based suggestions, we provide at most one such suggestion.
|
||||
fn probe_for_lev_candidate(&mut self) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
|
||||
fn probe_for_lev_candidate(
|
||||
&mut self,
|
||||
scope_expr_id: hir::HirId,
|
||||
) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
|
||||
debug!("probing for method names similar to {:?}", self.method_name);
|
||||
|
||||
let steps = self.steps.clone();
|
||||
@ -1594,6 +1602,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
self.orig_steps_var_values.clone(),
|
||||
steps,
|
||||
IsSuggestion(true),
|
||||
scope_expr_id,
|
||||
);
|
||||
pcx.allow_similar_names = true;
|
||||
pcx.assemble_inherent_candidates();
|
||||
|
Loading…
Reference in New Issue
Block a user