Skip to content

Commit 09104ad

Browse files
committed
Explain why struct fields are handled by assoc. item code
1 parent 636d6a3 commit 09104ad

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+12
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,18 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
688688
// FIXME: this doesn't really belong in `associated_item` (maybe `variant_field` is better?)
689689
// NOTE: it's different from variant_field because it only resolves struct fields,
690690
// not variant fields (2 path segments, not 3).
691+
//
692+
// We need to handle struct (and union) fields in this code because
693+
// syntactically their paths are identical to associated item paths:
694+
// `module::Type::field` and `module::Type::Assoc`.
695+
//
696+
// On the other hand, variant fields can't be mistaken for associated
697+
// items because they look like this: `module::Type::Variant::field`.
698+
//
699+
// Variants themselves don't need to be handled here, even though
700+
// they also look like associated items (`module::Type::Variant`),
701+
// because they are real Rust syntax (unlike the intra-doc links
702+
// field syntax) and are handled by the compiler's resolver.
691703
let def = match tcx.type_of(did).kind() {
692704
ty::Adt(def, _) if !def.is_enum() => def,
693705
_ => return None,

0 commit comments

Comments
 (0)