mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Don't suggest associated function call for associated const.
This commit is contained in:
parent
5dfb4b0afa
commit
2582e36da3
@ -9,7 +9,6 @@ use rustc_data_structures::fx::FxHashSet;
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def::Namespace;
|
|
||||||
use rustc_infer::infer::canonical::OriginalQueryValues;
|
use rustc_infer::infer::canonical::OriginalQueryValues;
|
||||||
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
@ -1881,6 +1880,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||||||
// The length of the returned iterator is nearly always 0 or 1 and this
|
// The length of the returned iterator is nearly always 0 or 1 and this
|
||||||
// method is fairly hot.
|
// method is fairly hot.
|
||||||
fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
|
fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
|
||||||
|
let relevant_kind_for_mode = |kind| match (self.mode, kind) {
|
||||||
|
(Mode::MethodCall, ty::AssocKind::Fn) => true,
|
||||||
|
(Mode::Path, ty::AssocKind::Const | ty::AssocKind::Fn) => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
if let Some(name) = self.method_name {
|
if let Some(name) = self.method_name {
|
||||||
if self.allow_similar_names {
|
if self.allow_similar_names {
|
||||||
let max_dist = max(name.as_str().len(), 3) / 3;
|
let max_dist = max(name.as_str().len(), 3) / 3;
|
||||||
@ -1888,7 +1892,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||||||
.associated_items(def_id)
|
.associated_items(def_id)
|
||||||
.in_definition_order()
|
.in_definition_order()
|
||||||
.filter(|x| {
|
.filter(|x| {
|
||||||
if x.kind.namespace() != Namespace::ValueNS {
|
if !relevant_kind_for_mode(x.kind) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
match lev_distance_with_substrings(name.as_str(), x.name.as_str(), max_dist)
|
match lev_distance_with_substrings(name.as_str(), x.name.as_str(), max_dist)
|
||||||
@ -1902,10 +1906,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||||||
} else {
|
} else {
|
||||||
self.fcx
|
self.fcx
|
||||||
.associated_value(def_id, name)
|
.associated_value(def_id, name)
|
||||||
|
.filter(|x| relevant_kind_for_mode(x.kind))
|
||||||
.map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
|
.map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.tcx.associated_items(def_id).in_definition_order().copied().collect()
|
self.tcx
|
||||||
|
.associated_items(def_id)
|
||||||
|
.in_definition_order()
|
||||||
|
.filter(|x| relevant_kind_for_mode(x.kind))
|
||||||
|
.copied()
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,7 @@ error[E0599]: no method named `MAX` found for type `u32` in the current scope
|
|||||||
--> $DIR/dont-suggest-ufcs-for-const.rs:2:11
|
--> $DIR/dont-suggest-ufcs-for-const.rs:2:11
|
||||||
|
|
|
|
||||||
LL | 1_u32.MAX();
|
LL | 1_u32.MAX();
|
||||||
| ------^^^--
|
| ^^^ method not found in `u32`
|
||||||
| | |
|
|
||||||
| | this is an associated function, not a method
|
|
||||||
| help: use associated function syntax instead: `u32::MAX()`
|
|
||||||
|
|
|
||||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
|
||||||
= note: the candidate is defined in an impl for the type `u32`
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user