Strings between fields in struct: Why a valid code

julia> begin
       "why this"
        struct X
         "why that"
         y::Int
        end
       end
X

help?> X.y
  why that

help?> X
search: X xor exp Expr exp2 exit axes expm1 exp10 export extrema extrema! exponent Exception expanduser

  why this

julia> Meta.@lower begin
       "why this"
        struct X
         "why that"
         y::Int
        end
       end
...omitted the lowered struct code...
10 ┄ %37 = (Base.Docs.Binding)(Main, :X)
│    %38 = (Core.svec)("why this")
│    %39 = (Pair{Symbol, Any})(:y, "why that")
│    %40 = (Dict{Symbol, Any})(%39)
│    %41 = (Pair)(:fields, %40)
│    %42 = (Dict{Symbol, Any})(:path => "REPL[24]", :linenumber => 2, :module => Main, %41)
│    %43 = (Base.Docs.docstr)(%38, %42)
│    %44 = Core.apply_type(Union)
│    %45 = (Base.Docs.doc!)(Main, %37, %43, %44)
└───       return %45
))))

As implied, the lowered Base.Docs code vanishes if you don’t start with a string over the struct, even if there are strings over the fields:

julia> begin
        struct Y
         "why that"
         z::Int
        end
       end

help?> Y.z
  Y has fields z.

help?> Y
search: Y yield yieldto Sys Type hypot typeof Symbol TypeVar typemin typemax symlink symdiff typejoin symdiff! TypeError

  No documentation found.
...

Reasonably, ArgumentParser has an overall docstring:

"Command-line argument parser with key-value stores and attributes."
mutable struct ArgumentParser
2 Likes