_rustc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #compdef rustc
  2. local -a _rustc_opts_switches _rustc_opts_lint _rustc_opts_debug
  3. typeset -A opt_args
  4. _rustc_debuginfo_levels=(
  5. "0[no debug info]"
  6. "1[line-tables only (for stacktraces and breakpoints)]"
  7. "2[full debug info with variable and type information (same as -g)]"
  8. )
  9. _rustc_crate_types=(
  10. 'bin'
  11. 'lib'
  12. 'rlib'
  13. 'dylib'
  14. 'cdylib'
  15. 'staticlib'
  16. 'proc-macro'
  17. )
  18. _rustc_emit_types=(
  19. 'asm'
  20. 'llvm-bc'
  21. 'llvm-ir'
  22. 'obj'
  23. 'metadata'
  24. 'link'
  25. 'dep-info'
  26. 'mir'
  27. )
  28. _rustc_print_types=(
  29. 'crate-name'
  30. 'file-names'
  31. 'sysroot'
  32. 'cfg'
  33. 'target-list'
  34. 'target-cpus'
  35. 'target-features'
  36. 'relocation-models'
  37. 'code-models'
  38. 'target-spec-json'
  39. 'native-static-libs'
  40. )
  41. _rustc_pretty_types=(
  42. 'normal[un-annotated source]'
  43. 'expanded[crates expanded]'
  44. 'expanded,identified[fully parenthesized, AST nodes with IDs]'
  45. )
  46. _rustc_unpretty_types=(
  47. 'normal[un-annotated source]'
  48. 'expanded[crates expanded]'
  49. 'expanded,identified[fully parenthesized, AST nodes with IDs]'
  50. 'flowgraph=[graphviz formatted flowgraph for node]:NODEID:'
  51. 'everybody_loops[all function bodies replaced with `loop {}`]'
  52. 'hir[the HIR]'
  53. 'hir,identified'
  54. 'hir,typed[HIR with types for each node]'
  55. )
  56. _rustc_color_types=(
  57. 'auto[colorize, if output goes to a tty (default)]'
  58. 'always[always colorize output]'
  59. 'never[never colorize output]'
  60. )
  61. _rustc_error_format=(
  62. 'human'
  63. 'json'
  64. )
  65. _rustc_opts_vals=(
  66. --cfg='[Configure the compilation environment]:SPEC:'
  67. -L'[Add a directory to the library search path]:DIR:_files -/'
  68. --crate-name='[Specify the name of the crate being built]'
  69. --crate-type='[Comma separated list of types of crates for the compiler to emit]:TYPES:_values -s "," "Crate types" "$_rustc_crate_types[@]"'
  70. --emit='[Comma separated list of types of output for the compiler to emit]:TYPES:_values -s "," "Emit Targets" "$_rustc_emit_types[@]"'
  71. --print='[Comma separated list of compiler information to print on stdout]:TYPES:_values -s "," "Printable info" "$_rustc_print_types[@]"'
  72. -o'[Write output to <filename>. Ignored if more than one --emit is specified.]:FILENAME:_files'
  73. --out-dir='[Write output to compiler-chosen filename in <dir>. Ignored if -o is specified. (default the current directory)]:DIR:_files -/'
  74. --explain='[Provide a detailed explanation of an error message]:OPT:'
  75. --target='[Target triple cpu-manufacturer-kernel\[-os\] to compile]:TRIPLE:'
  76. --extern'[Specify where an external rust library is located]:ARG:'
  77. --sysroot='[Override the system root]:PATH:_files -/'
  78. --error-format='[How errors and other messages are produced]:TYPES:_values "$_rustc_error_format"'
  79. --debuginfo='[Emit DWARF debug info to the objects created]:LEVEL:_values "Debug Levels" "$_rustc_debuginfo_levels[@]"'
  80. --dep-info='[Output dependency info to <filename> after compiling]::FILE:_files -/'
  81. --opt-level='[Optimize with possible levels 0-3]:LEVEL:(0 1 2 3)'
  82. --pretty='[Pretty-print the input instead of compiling]::TYPE:_values "TYPES" "$_rustc_pretty_types[@]"'
  83. --unpretty='[Present the input source, unstable (and less-pretty)]::TYPE:_values "TYPES" "$_rustc_unpretty_types[@]"'
  84. --color='[Configure coloring of output]:CONF:_values "COLORS" "$_rustc_color_types[@]"'
  85. )
  86. _rustc_opts_switches=(
  87. -g'[Equivalent to --debuginfo=2]'
  88. -O'[Equivalent to --opt-level=2]'
  89. --test'[Build a test harness]'
  90. {-v,--verbose}'[Use verbose output]'
  91. {-V,--version}'[Print version info and exit]'
  92. {-h,--help}'[Display this message]'
  93. --no-analysis'[Parse and expand the output, but run no analysis or produce output]'
  94. --no-trans'[Run all passes except translation; no output]'
  95. --parse-only'[Parse only; do not compile, assemble, or link]'
  96. --print-crate-name'[Output the crate name and exit]'
  97. --print-file-name'[Output the file(s) that would be written if compilation continued and exit]'
  98. )
  99. _rustc_opts_codegen=(
  100. 'ar=[Path to the archive utility to use when assembling archives.]:BIN:_path_files'
  101. 'linker=[Path to the linker utility to use when linking libraries, executables, and objects.]:BIN:_path_files'
  102. 'link-args=[A space-separated list of extra arguments to pass to the linker when the linker is invoked.]:ARGS:'
  103. 'target-cpu=[Selects a target processor. If the value is "help", then a list of available CPUs is printed.]:CPU:'
  104. 'target-feature=[A space-separated list of features to enable or disable for the target. A preceding "+" enables a feature while a preceding "-" disables it. Available features can be discovered through target-cpu=help.]:FEATURE:'
  105. 'passes=[A space-separated list of extra LLVM passes to run. A value of "list" will cause rustc to print all known passes and exit. The passes specified are appended at the end of the normal pass manager.]:LIST:'
  106. 'llvm-args=[A space-separated list of arguments to pass through to LLVM.]:ARGS:'
  107. 'save-temps[If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated throughout compilation in the output directory.]'
  108. 'rpath[If specified, then the rpath value for dynamic libraries will be set in either dynamic library or executable outputs.]'
  109. 'no-prepopulate-passes[Suppresses pre-population of the LLVM pass manager that is run over the module.]'
  110. 'no-vectorize-loops[Suppresses running the loop vectorization LLVM pass, regardless of optimization level.]'
  111. 'no-vectorize-slp[Suppresses running the LLVM SLP vectorization pass, regardless of optimization level.]'
  112. 'soft-float[Generates software floating point library calls instead of hardware instructions.]'
  113. 'prefer-dynamic[Prefers dynamic linking to static linking.]'
  114. "no-integrated-as[Force usage of an external assembler rather than LLVM's integrated one.]"
  115. 'no-redzone[disable the use of the redzone]'
  116. 'relocation-model=[The relocation model to use. (default: pic)]:MODEL:(pic static dynamic-no-pic)'
  117. 'code-model=[choose the code model to use (llc -code-model for details)]:MODEL:'
  118. 'metadata=[metadata to mangle symbol names with]:VAL:'
  119. 'extra-filenames=[extra data to put in each output filename]:VAL:'
  120. 'codegen-units=[divide crate into N units to optimize in parallel]:N:'
  121. 'help[Show all codegen options]'
  122. )
  123. _rustc_opts_lint=(
  124. 'help[Show a list of all lints]'
  125. 'experimental[detects use of #\[experimental\] items]'
  126. 'heap-memory[use of any (Box type or @ type) heap memory]'
  127. 'managed-heap-memory[use of managed (@ type) heap memory]'
  128. 'missing-doc[detects missing documentation for public members]'
  129. 'non-uppercase-statics[static constants should have uppercase identifiers]'
  130. 'owned-heap-memory[use of owned (~ type) heap memory]'
  131. 'unnecessary-qualification[detects unnecessarily qualified names]'
  132. 'unsafe-block[usage of an `unsafe` block]'
  133. 'unstable[detects use of #\[unstable\] items (incl. items with no stability attribute)]'
  134. 'unused-result[unused result of an expression in a statement]'
  135. 'variant-size-difference[detects enums with widely varying variant sizes]'
  136. 'ctypes[proper use of libc types in foreign modules]'
  137. 'dead-assignment[detect assignments that will never be read]'
  138. 'dead-code[detect piece of code that will never be used]'
  139. 'deprecated[detects use of #\[deprecated\] items]'
  140. 'non-camel-case-types[types, variants and traits should have camel case names]'
  141. 'non-snake-case[methods, functions, lifetime parameters and modules should have snake case names]'
  142. 'path-statement[path statements with no effect]'
  143. 'raw-pointer-deriving[uses of #\[deriving\] with raw pointers are rarely correct]'
  144. 'type-limits[comparisons made useless by limits of the types involved]'
  145. 'type-overflow[literal out of range for its type]'
  146. 'unnecessary-allocation[detects unnecessary allocations that can be eliminated]'
  147. 'unnecessary-parens[`if`, `match`, `while` and `return` do not need parentheses]'
  148. 'unreachable-code[detects unreachable code]'
  149. 'unrecognized-lint[unrecognized lint attribute]'
  150. 'unsigned-negate[using an unary minus operator on unsigned type]'
  151. 'unused-attribute[detects attributes that were not used by the compiler]'
  152. 'unused-imports[imports that are never used]'
  153. 'unused-must-use[unused result of a type flagged as #\[must_use\]]'
  154. "unused-mut[detect mut variables which don't need to be mutable]"
  155. 'unused-unsafe[unnecessary use of an `unsafe` block]'
  156. 'unused-variable[detect variables which are not used in any way]'
  157. 'visible-private-types[detect use of private types in exported type signatures]'
  158. 'warnings[mass-change the level for lints which produce warnings]'
  159. 'while-true[suggest using `loop { }` instead of `while true { }`]'
  160. 'unknown-crate-type[unknown crate type found in #\[crate_type\] directive]'
  161. 'unknown-features[unknown features found in crate-level #\[feature\] directives]'
  162. 'bad-style[group of non_camel_case_types, non_snake_case, non_uppercase_statics]'
  163. 'unused[group of unused_imports, unused_variable, dead_assignment, dead_code, unused_mut, unreachable_code]'
  164. )
  165. _rustc_opts_debug=(
  166. 'verbose[in general, enable more debug printouts]'
  167. 'span-free-formats[when debug-printing compiler state, do not include spans]'
  168. "identify-regions[make unnamed regions display as '# (where # is some non-ident unique id)]"
  169. 'emit-end-regions[emit EndRegion as part of MIR; enable transforms that solely process EndRegion]'
  170. 'time-passes[measure time of each rustc pass]'
  171. 'count-llvm-insns[count where LLVM instrs originate]'
  172. 'time-llvm-passes[measure time of each LLVM pass]'
  173. 'trans-stats[gather trans statistics]'
  174. 'asm-comments[generate comments into the assembly (may change behavior)]'
  175. 'no-verify[skip LLVM verification]'
  176. 'borrowck-stats[gather borrowck statistics]'
  177. 'no-landing-pads[omit landing pads for unwinding]'
  178. 'debug-llvm[enable debug output from LLVM]'
  179. 'show-span[show spans for compiler debugging]'
  180. 'count-type-sizes[count the sizes of aggregate types]'
  181. 'meta-stats[gather metadata statistics]'
  182. 'no-opt[do not optimize, even if -O is passed]'
  183. 'print-link-args[Print the arguments passed to the linker]'
  184. 'gc[Garbage collect shared data (experimental)]'
  185. 'print-llvm-passes[Prints the llvm optimization passes being run]'
  186. 'lto[Perform LLVM link-time optimizations]'
  187. 'ast-json[Print the AST as JSON and halt]'
  188. 'ast-json-noexpand[Print the pre-expansion AST as JSON and halt]'
  189. 'ls[List the symbols defined by a library crate]'
  190. 'save-analysis[Write syntax and type analysis information in addition to normal output]'
  191. 'flowgraph-print-loans[Include loan analysis data in --pretty flowgraph output]'
  192. 'flowgraph-print-moves[Include move analysis data in --pretty flowgraph output]'
  193. 'flowgraph-print-assigns[Include assignment analysis data in --pretty flowgraph output]'
  194. 'flowgraph-print-all[Include all dataflow analysis data in --pretty flowgraph output]'
  195. )
  196. _rustc_opts_fun_lint(){
  197. _values -s , 'options' \
  198. "$_rustc_opts_lint[@]"
  199. }
  200. _rustc_opts_fun_debug(){
  201. _values 'options' "$_rustc_opts_debug[@]"
  202. }
  203. _rustc_opts_fun_codegen(){
  204. _values 'options' "$_rustc_opts_codegen[@]"
  205. }
  206. _arguments -s : \
  207. '(-W --warn)'{-W,--warn=}'[Set lint warnings]:lint options:_rustc_opts_fun_lint' \
  208. '(-A --allow)'{-A,--allow=}'[Set lint allowed]:lint options:_rustc_opts_fun_lint' \
  209. '(-D --deny)'{-D,--deny=}'[Set lint denied]:lint options:_rustc_opts_fun_lint' \
  210. '(-F --forbid)'{-F,--forbid=}'[Set lint forbidden]:lint options:_rustc_opts_fun_lint' \
  211. '*-Z[Set internal debugging options]:debug options:_rustc_opts_fun_debug' \
  212. '*-C[Set internal Codegen options]:codegen options:_rustc_opts_fun_codegen' \
  213. "$_rustc_opts_switches[@]" \
  214. "$_rustc_opts_vals[@]" \
  215. '::files:_files -g "*.rs"'