_rust 10 KB

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