Conversation
| let has_self_assoc_type = if let SelfSource::QPath(ty) = source | ||
| && let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind | ||
| && let Res::SelfTyAlias { alias_to: impl_def_id, .. } = path.res | ||
| && let DefKind::Impl { .. } = self.tcx.def_kind(impl_def_id) |
There was a problem hiding this comment.
While this does nicely detect the scenario in issue #142797, it's not very general. E.g., it obviously doesn't account for:
struct Struct;
trait Trait { type AssocStruct; }
impl Trait for i32 { type AssocStruct = Struct; }
fn main() { let _ = i32::AssocStruct; } //~ ERROR no associated item … found …| #![allow(dead_code, unused_variables)] | ||
|
|
There was a problem hiding this comment.
| #![allow(dead_code, unused_variables)] |
Compiletest already automatically adds -Aunused to UI tests (unless they're run-{pass,crash}) which implies dead_code and unused_variables.
| } else if rcvr_ty.is_enum() { | ||
| "variant or associated item" | ||
| } else if has_self_assoc_type { | ||
| "associated function or constant" | ||
| } else { | ||
| match (item_ident.as_str().chars().next(), rcvr_ty.is_fresh_ty()) { | ||
| (Some(name), false) if name.is_lowercase() => "function or associated item", | ||
| (Some(_), false) => "associated item", | ||
| (Some(_), true) | (None, false) => "variant or associated item", | ||
| (None, true) => "variant", | ||
| } | ||
| }; |
There was a problem hiding this comment.
I'm wondering if we should just unconditionally talk about associated function or constant instead of associated item because that's actually the truth, rustc_hir_typeck::method looks for assoc fns, assoc consts & enum variants, not assoc items in general.
Then we wouldn't need to check for the presence of assoc tys which is rather ad hoc.
variant or associated item→variant, associated function or constantfunction or associated item,associated item→associated function or constant
I know it's slightly lengthier but associated item is strictly speaking incorrect. @estebank, I'd also like to hear what you think about this proposal :)
Fix #142797
r? @fmease