1use std::collections::BTreeMap;
4use std::collections::btree_map::{
5 Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter,
6};
7use std::path::Path;
8
9use rustc_data_structures::stable_hash::StableOrd;
10use rustc_errors::ColorConfig;
11use rustc_errors::emitter::HumanReadableErrorType;
12use rustc_macros::{Decodable, Encodable, StableHash};
13use rustc_span::{Span, Symbol};
14use rustc_structures::CrateType;
15
16use crate::Session;
17use crate::config::{OutFileName, OutputFilenames};
18use crate::diagnostics::{
19 CrateNameEmpty, FileIsNotWriteable, InvalidCharacterInCrateName,
20 InvalidCharacterInCrateNameSuggestion,
21};
22
23pub fn out_filename(
24 sess: &Session,
25 crate_type: CrateType,
26 outputs: &OutputFilenames,
27 crate_name: Symbol,
28) -> OutFileName {
29 let default_filename = filename_for_input(sess, crate_type, crate_name, outputs);
30 let out_filename = outputs
31 .outputs
32 .get(&OutputType::Exe)
33 .and_then(|s| s.to_owned())
34 .or_else(|| outputs.single_output_file.clone())
35 .unwrap_or(default_filename);
36
37 if let OutFileName::Real(ref path) = out_filename {
38 check_file_is_writeable(path, sess);
39 }
40
41 out_filename
42}
43
44pub fn check_file_is_writeable(file: &Path, sess: &Session) {
48 if !is_writeable(file) {
49 sess.dcx().emit_fatal(FileIsNotWriteable { file });
50 }
51}
52
53fn is_writeable(p: &Path) -> bool {
54 match p.metadata() {
55 Err(..) => true,
56 Ok(m) => !m.permissions().readonly(),
57 }
58}
59
60pub fn validate_crate_name(sess: &Session, crate_name: Symbol, span: Option<Span>) {
69 let mut guar = None;
70
71 if crate_name.is_empty() {
72 guar = Some(sess.dcx().emit_err(CrateNameEmpty { span }));
73 }
74
75 for c in crate_name.as_str().chars() {
76 if c.is_alphanumeric() || c == '_' {
77 continue;
78 }
79 guar = Some(sess.dcx().emit_err(InvalidCharacterInCrateName {
80 span,
81 character: c,
82 crate_name,
83 suggestion: span.is_none().then(|| InvalidCharacterInCrateNameSuggestion {
84 suggested_name:
85 crate_name.as_str().replace(|c: char| c != '_' && !c.is_alphanumeric(), "_"),
86 }),
87 }));
88 }
89
90 if let Some(guar) = guar {
91 guar.raise_fatal();
92 }
93}
94
95pub fn filename_for_metadata(sess: &Session, outputs: &OutputFilenames) -> OutFileName {
96 let out_filename = outputs.path(OutputType::Metadata);
97 if let OutFileName::Real(ref path) = out_filename {
98 check_file_is_writeable(path, sess);
99 }
100 out_filename
101}
102
103pub fn filename_for_input(
104 sess: &Session,
105 crate_type: CrateType,
106 crate_name: Symbol,
107 outputs: &OutputFilenames,
108) -> OutFileName {
109 let libname = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}", crate_name,
sess.opts.cg.extra_filename))
})format!("{}{}", crate_name, sess.opts.cg.extra_filename);
110
111 match crate_type {
112 CrateType::Rlib => {
113 OutFileName::Real(outputs.out_directory.join(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("lib{0}.rlib", libname))
})format!("lib{libname}.rlib")))
114 }
115 CrateType::Cdylib | CrateType::ProcMacro | CrateType::Dylib | CrateType::Sdylib => {
116 let (prefix, suffix) = (&sess.target.dll_prefix, &sess.target.dll_suffix);
117 OutFileName::Real(outputs.out_directory.join(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}{2}", prefix, libname,
suffix))
})format!("{prefix}{libname}{suffix}")))
118 }
119 CrateType::StaticLib => {
120 let (prefix, suffix) = sess.staticlib_components(false);
121 OutFileName::Real(outputs.out_directory.join(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}{2}", prefix, libname,
suffix))
})format!("{prefix}{libname}{suffix}")))
122 }
123 CrateType::Executable => {
124 let suffix = &sess.target.exe_suffix;
125 let out_filename = outputs.path(OutputType::Exe);
126 if let OutFileName::Real(ref path) = out_filename {
127 if suffix.is_empty() {
128 out_filename
129 } else {
130 OutFileName::Real(path.with_extension(&suffix[1..]))
131 }
132 } else {
133 out_filename
134 }
135 }
136 }
137}
138
139pub fn invalid_output_for_target(sess: &Session, crate_type: CrateType) -> bool {
141 if let CrateType::Cdylib | CrateType::Dylib | CrateType::ProcMacro = crate_type {
142 if !sess.target.dynamic_linking {
143 return true;
144 }
145 if sess.crt_static(Some(crate_type)) && !sess.target.crt_static_allows_dylibs {
146 return true;
147 }
148 }
149 if crate_type == CrateType::ProcMacro {
150 if sess.opts.target_triple == sess.wasm_proc_macro_tuple
151 && sess.opts.unstable_opts.wasm_proc_macros
152 {
153 return false;
154 }
155 }
156 if let CrateType::ProcMacro | CrateType::Dylib = crate_type
157 && sess.target.only_cdylib
158 {
159 return true;
160 }
161 if let CrateType::Executable = crate_type
162 && !sess.target.executables
163 {
164 return true;
165 }
166
167 false
168}
169
170macro_rules! define_output_types {
171 (
172 $(
173 $(#[doc = $doc:expr])*
174 $Variant:ident => {
175 shorthand: $shorthand:expr,
176 extension: $extension:expr,
177 description: $description:expr,
178 default_filename: $default_filename:expr,
179 is_text: $is_text:expr,
180 compatible_with_cgus_and_single_output: $compatible:expr
181 }
182 ),* $(,)?
183 ) => {
184 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, StableHash)]
185 #[derive(Encodable, Decodable)]
186 pub enum OutputType {
187 $(
188 $(#[doc = $doc])*
189 $Variant,
190 )*
191 }
192
193 impl StableOrd for OutputType {
194 const CAN_USE_UNSTABLE_SORT: bool = true;
195
196 const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
198 }
199
200 impl OutputType {
201 pub fn iter_all() -> impl Iterator<Item = OutputType> {
202 static ALL_VARIANTS: &[OutputType] = &[
203 $(
204 OutputType::$Variant,
205 )*
206 ];
207 ALL_VARIANTS.iter().copied()
208 }
209
210 pub(crate) fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
211 match *self {
212 $(
213 OutputType::$Variant => $compatible,
214 )*
215 }
216 }
217
218 pub fn shorthand(&self) -> &'static str {
219 match *self {
220 $(
221 OutputType::$Variant => $shorthand,
222 )*
223 }
224 }
225
226 pub(crate) fn from_shorthand(shorthand: &str) -> Option<Self> {
227 match shorthand {
228 $(
229 s if s == $shorthand => Some(OutputType::$Variant),
230 )*
231 _ => None,
232 }
233 }
234
235 pub(crate) fn shorthands_display() -> String {
236 let shorthands = vec![
237 $(
238 format!("`{}`", $shorthand),
239 )*
240 ];
241 shorthands.join(", ")
242 }
243
244 pub fn extension(&self) -> &'static str {
245 match *self {
246 $(
247 OutputType::$Variant => $extension,
248 )*
249 }
250 }
251
252 pub fn is_text_output(&self) -> bool {
253 match *self {
254 $(
255 OutputType::$Variant => $is_text,
256 )*
257 }
258 }
259
260 pub fn description(&self) -> &'static str {
261 match *self {
262 $(
263 OutputType::$Variant => $description,
264 )*
265 }
266 }
267
268 pub fn default_filename(&self) -> &'static str {
269 match *self {
270 $(
271 OutputType::$Variant => $default_filename,
272 )*
273 }
274 }
275
276
277 }
278 }
279}
280
281pub enum OutputType {
Assembly,
#[doc =
"This is the optimized bitcode, which could be either pre-LTO or non-LTO bitcode,"]
#[doc = "depending on the specific request type."]
Bitcode,
DepInfo,
Exe,
LlvmAssembly,
Metadata,
Mir,
Object,
#[doc = "This is the summary or index data part of the ThinLTO bitcode."]
ThinLinkBitcode,
}
const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for OutputType {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
OutputType::Assembly => { 0usize }
OutputType::Bitcode => { 1usize }
OutputType::DepInfo => { 2usize }
OutputType::Exe => { 3usize }
OutputType::LlvmAssembly => { 4usize }
OutputType::Metadata => { 5usize }
OutputType::Mir => { 6usize }
OutputType::Object => { 7usize }
OutputType::ThinLinkBitcode => { 8usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
}
}
};
const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for OutputType {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { OutputType::Assembly }
1usize => { OutputType::Bitcode }
2usize => { OutputType::DepInfo }
3usize => { OutputType::Exe }
4usize => { OutputType::LlvmAssembly }
5usize => { OutputType::Metadata }
6usize => { OutputType::Mir }
7usize => { OutputType::Object }
8usize => { OutputType::ThinLinkBitcode }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `OutputType`, expected 0..9, actual {0}",
n));
}
}
}
}
};
#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for OutputType {
}
#[automatically_derived]impl ::core::clone::Clone for OutputType {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}
#[automatically_derived]impl ::core::marker::Copy for OutputType { }
#[automatically_derived]impl ::core::marker::StructuralPartialEq for
OutputType {
}
#[automatically_derived]impl ::core::cmp::PartialEq for OutputType {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}
#[automatically_derived]impl ::core::cmp::Eq for OutputType { }
#[automatically_derived]impl ::core::hash::Hash for OutputType {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}
#[automatically_derived]impl ::core::fmt::Debug for OutputType {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"Assembly Bitcode DepInfo Exe LlvmAssembly Metadata Mir Object ThinLinkBitcode",
match self {
OutputType::Assembly => 0usize,
OutputType::Bitcode => 9usize,
OutputType::DepInfo => 17usize,
OutputType::Exe => 25usize,
OutputType::LlvmAssembly => 29usize,
OutputType::Metadata => 42usize,
OutputType::Mir => 51usize,
OutputType::Object => 55usize,
OutputType::ThinLinkBitcode => 62usize,
})
}
}
#[automatically_derived]impl ::core::cmp::PartialOrd for OutputType {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}
#[automatically_derived]impl ::core::cmp::Ord for OutputType {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other))
}
}
const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for OutputType {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
OutputType::Assembly => 0u8.stable_hash(__hcx, __hasher),
OutputType::Bitcode => 1u8.stable_hash(__hcx, __hasher),
OutputType::DepInfo => 2u8.stable_hash(__hcx, __hasher),
OutputType::Exe => 3u8.stable_hash(__hcx, __hasher),
OutputType::LlvmAssembly =>
4u8.stable_hash(__hcx, __hasher),
OutputType::Metadata => 5u8.stable_hash(__hcx, __hasher),
OutputType::Mir => 6u8.stable_hash(__hcx, __hasher),
OutputType::Object => 7u8.stable_hash(__hcx, __hasher),
OutputType::ThinLinkBitcode =>
8u8.stable_hash(__hcx, __hasher),
}
match *self {
OutputType::Assembly => {}
OutputType::Bitcode => {}
OutputType::DepInfo => {}
OutputType::Exe => {}
OutputType::LlvmAssembly => {}
OutputType::Metadata => {}
OutputType::Mir => {}
OutputType::Object => {}
OutputType::ThinLinkBitcode => {}
}
}
}
};
impl StableOrd for OutputType {
const CAN_USE_UNSTABLE_SORT: bool = true;
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl OutputType {
pub fn iter_all() -> impl Iterator<Item = OutputType> {
static ALL_VARIANTS: &[OutputType] =
&[OutputType::Assembly, OutputType::Bitcode, OutputType::DepInfo,
OutputType::Exe, OutputType::LlvmAssembly,
OutputType::Metadata, OutputType::Mir, OutputType::Object,
OutputType::ThinLinkBitcode];
ALL_VARIANTS.iter().copied()
}
pub(crate) fn is_compatible_with_codegen_units_and_single_output_file(&self)
-> bool {
match *self {
OutputType::Assembly => false,
OutputType::Bitcode => false,
OutputType::DepInfo => true,
OutputType::Exe => true,
OutputType::LlvmAssembly => false,
OutputType::Metadata => true,
OutputType::Mir => false,
OutputType::Object => false,
OutputType::ThinLinkBitcode => false,
}
}
pub fn shorthand(&self) -> &'static str {
match *self {
OutputType::Assembly => "asm",
OutputType::Bitcode => "llvm-bc",
OutputType::DepInfo => "dep-info",
OutputType::Exe => "link",
OutputType::LlvmAssembly => "llvm-ir",
OutputType::Metadata => "metadata",
OutputType::Mir => "mir",
OutputType::Object => "obj",
OutputType::ThinLinkBitcode => "thin-link-bitcode",
}
}
pub(crate) fn from_shorthand(shorthand: &str) -> Option<Self> {
match shorthand {
s if s == "asm" => Some(OutputType::Assembly),
s if s == "llvm-bc" => Some(OutputType::Bitcode),
s if s == "dep-info" => Some(OutputType::DepInfo),
s if s == "link" => Some(OutputType::Exe),
s if s == "llvm-ir" => Some(OutputType::LlvmAssembly),
s if s == "metadata" => Some(OutputType::Metadata),
s if s == "mir" => Some(OutputType::Mir),
s if s == "obj" => Some(OutputType::Object),
s if s == "thin-link-bitcode" =>
Some(OutputType::ThinLinkBitcode),
_ => None,
}
}
pub(crate) fn shorthands_display() -> String {
let shorthands =
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "asm"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "llvm-bc"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "dep-info"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "link"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "llvm-ir"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "metadata"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "mir"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", "obj"))
}),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`",
"thin-link-bitcode"))
})]));
shorthands.join(", ")
}
pub fn extension(&self) -> &'static str {
match *self {
OutputType::Assembly => "s",
OutputType::Bitcode => "bc",
OutputType::DepInfo => "d",
OutputType::Exe => "",
OutputType::LlvmAssembly => "ll",
OutputType::Metadata => "rmeta",
OutputType::Mir => "mir",
OutputType::Object => "o",
OutputType::ThinLinkBitcode => "indexing.o",
}
}
pub fn is_text_output(&self) -> bool {
match *self {
OutputType::Assembly => true,
OutputType::Bitcode => false,
OutputType::DepInfo => true,
OutputType::Exe => false,
OutputType::LlvmAssembly => true,
OutputType::Metadata => false,
OutputType::Mir => true,
OutputType::Object => false,
OutputType::ThinLinkBitcode => false,
}
}
pub fn description(&self) -> &'static str {
match *self {
OutputType::Assembly =>
"Generates a file with the crate's assembly code",
OutputType::Bitcode =>
"Generates a binary file containing the LLVM bitcode",
OutputType::DepInfo =>
"Generates a file with Makefile syntax that indicates all the source files that were loaded to generate the crate",
OutputType::Exe =>
"Generates the crates specified by --crate-type. This is the default if --emit is not specified",
OutputType::LlvmAssembly => "Generates a file containing LLVM IR",
OutputType::Metadata =>
"Generates a file containing metadata about the crate",
OutputType::Mir =>
"Generates a file containing rustc's mid-level intermediate representation",
OutputType::Object => "Generates a native object file",
OutputType::ThinLinkBitcode =>
"Generates the ThinLTO summary as bitcode",
}
}
pub fn default_filename(&self) -> &'static str {
match *self {
OutputType::Assembly => "CRATE_NAME.s",
OutputType::Bitcode => "CRATE_NAME.bc",
OutputType::DepInfo => "CRATE_NAME.d",
OutputType::Exe => "(platform and crate-type dependent)",
OutputType::LlvmAssembly => "CRATE_NAME.ll",
OutputType::Metadata => "libCRATE_NAME.rmeta",
OutputType::Mir => "CRATE_NAME.mir",
OutputType::Object => "CRATE_NAME.o",
OutputType::ThinLinkBitcode => "CRATE_NAME.indexing.o",
}
}
}define_output_types! {
282 Assembly => {
283 shorthand: "asm",
284 extension: "s",
285 description: "Generates a file with the crate's assembly code",
286 default_filename: "CRATE_NAME.s",
287 is_text: true,
288 compatible_with_cgus_and_single_output: false
289 },
290 #[doc = "This is the optimized bitcode, which could be either pre-LTO or non-LTO bitcode,"]
291 #[doc = "depending on the specific request type."]
292 Bitcode => {
293 shorthand: "llvm-bc",
294 extension: "bc",
295 description: "Generates a binary file containing the LLVM bitcode",
296 default_filename: "CRATE_NAME.bc",
297 is_text: false,
298 compatible_with_cgus_and_single_output: false
299 },
300 DepInfo => {
301 shorthand: "dep-info",
302 extension: "d",
303 description: "Generates a file with Makefile syntax that indicates all the source files that were loaded to generate the crate",
304 default_filename: "CRATE_NAME.d",
305 is_text: true,
306 compatible_with_cgus_and_single_output: true
307 },
308 Exe => {
309 shorthand: "link",
310 extension: "",
311 description: "Generates the crates specified by --crate-type. This is the default if --emit is not specified",
312 default_filename: "(platform and crate-type dependent)",
313 is_text: false,
314 compatible_with_cgus_and_single_output: true
315 },
316 LlvmAssembly => {
317 shorthand: "llvm-ir",
318 extension: "ll",
319 description: "Generates a file containing LLVM IR",
320 default_filename: "CRATE_NAME.ll",
321 is_text: true,
322 compatible_with_cgus_and_single_output: false
323 },
324 Metadata => {
325 shorthand: "metadata",
326 extension: "rmeta",
327 description: "Generates a file containing metadata about the crate",
328 default_filename: "libCRATE_NAME.rmeta",
329 is_text: false,
330 compatible_with_cgus_and_single_output: true
331 },
332 Mir => {
333 shorthand: "mir",
334 extension: "mir",
335 description: "Generates a file containing rustc's mid-level intermediate representation",
336 default_filename: "CRATE_NAME.mir",
337 is_text: true,
338 compatible_with_cgus_and_single_output: false
339 },
340 Object => {
341 shorthand: "obj",
342 extension: "o",
343 description: "Generates a native object file",
344 default_filename: "CRATE_NAME.o",
345 is_text: false,
346 compatible_with_cgus_and_single_output: false
347 },
348 #[doc = "This is the summary or index data part of the ThinLTO bitcode."]
349 ThinLinkBitcode => {
350 shorthand: "thin-link-bitcode",
351 extension: "indexing.o",
352 description: "Generates the ThinLTO summary as bitcode",
353 default_filename: "CRATE_NAME.indexing.o",
354 is_text: false,
355 compatible_with_cgus_and_single_output: false
356 },
357}
358
359#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ErrorOutputType {
}
#[automatically_derived]impl ::core::clone::Clone for ErrorOutputType {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<HumanReadableErrorType>;
let _: ::core::clone::AssertParamIsClone<ColorConfig>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for ErrorOutputType { }Copy, #[automatically_derived]impl ::core::fmt::Debug for ErrorOutputType {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::HumanReadable { kind: __self_0, color_config: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"HumanReadable kind color_config", __self_0, &__self_1),
Self::Json {
pretty: __self_0,
json_rendered: __self_1,
color_config: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Json pretty json_rendered color_config", __self_0,
__self_1, &__self_2),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ErrorOutputType {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ErrorOutputType {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::HumanReadable { kind: __self_0, color_config: __self_1
}, Self::HumanReadable {
kind: __arg1_0, color_config: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::Json {
pretty: __self_0,
json_rendered: __self_1,
color_config: __self_2 }, Self::Json {
pretty: __arg1_0,
json_rendered: __arg1_1,
color_config: __arg1_2 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1 &&
__self_2 == __arg1_2,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ErrorOutputType {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<HumanReadableErrorType>;
let _: ::core::cmp::AssertParamIsEq<ColorConfig>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]impl ::core::default::Default for ErrorOutputType {
#[inline]
fn default() -> Self {
Self::HumanReadable {
kind: const HumanReadableErrorType {
no_graphics: false,
short: false,
unicode: false,
},
color_config: const ColorConfig::Auto,
}
}
}Default)]
361pub enum ErrorOutputType {
362 #[default]
364 HumanReadable {
365 kind: HumanReadableErrorType = HumanReadableErrorType { no_graphics: false, short: false, unicode: false },
366 color_config: ColorConfig = ColorConfig::Auto,
367 },
368 Json {
370 pretty: bool,
372 json_rendered: HumanReadableErrorType,
375 color_config: ColorConfig,
376 },
377}
378
379#[derive(#[automatically_derived]impl ::core::clone::Clone for ResolveDocLinks {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::None => ResolveDocLinks::None,
Self::ExportedMetadata => ResolveDocLinks::ExportedMetadata,
Self::Exported => ResolveDocLinks::Exported,
Self::All => ResolveDocLinks::All,
}
}
}Clone, #[automatically_derived]impl ::core::hash::Hash for ResolveDocLinks {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, #[automatically_derived]impl ::core::fmt::Debug for ResolveDocLinks {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ResolveDocLinks::None => "None",
ResolveDocLinks::ExportedMetadata => "ExportedMetadata",
ResolveDocLinks::Exported => "Exported",
ResolveDocLinks::All => "All",
})
}
}Debug)]
380pub enum ResolveDocLinks {
381 None,
383 ExportedMetadata,
385 Exported,
387 All,
389}
390
391#[derive(#[automatically_derived]impl ::core::clone::Clone for OutputTypes {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
OutputTypes(::core::clone::Clone::clone(&self.0))
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for OutputTypes {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "OutputTypes",
&&self.0)
}
}Debug, #[automatically_derived]impl ::core::hash::Hash for OutputTypes {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for OutputTypes
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
OutputTypes(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for OutputTypes {
fn encode(&self, __encoder: &mut __E) {
let OutputTypes(ref __binding_0) = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for OutputTypes {
fn decode(__decoder: &mut __D) -> Self {
OutputTypes(::rustc_serialize::Decodable::decode(__decoder))
}
}
};Decodable)]
396pub struct OutputTypes(pub(crate) BTreeMap<OutputType, Option<OutFileName>>);
397
398impl OutputTypes {
399 pub fn new(entries: &[(OutputType, Option<OutFileName>)]) -> OutputTypes {
400 OutputTypes(BTreeMap::from_iter(entries.iter().map(|&(k, ref v)| (k, v.clone()))))
401 }
402
403 pub(crate) fn get(&self, key: &OutputType) -> Option<&Option<OutFileName>> {
404 self.0.get(key)
405 }
406
407 pub fn contains_key(&self, key: &OutputType) -> bool {
408 self.0.contains_key(key)
409 }
410
411 pub fn contains_explicit_name(&self, key: &OutputType) -> bool {
413 #[allow(non_exhaustive_omitted_patterns)] match self.0.get(key) {
Some(Some(..)) => true,
_ => false,
}matches!(self.0.get(key), Some(Some(..)))
414 }
415
416 pub fn iter(&self) -> BTreeMapIter<'_, OutputType, Option<OutFileName>> {
417 self.0.iter()
418 }
419
420 pub fn keys(&self) -> BTreeMapKeysIter<'_, OutputType, Option<OutFileName>> {
421 self.0.keys()
422 }
423
424 pub fn values(&self) -> BTreeMapValuesIter<'_, OutputType, Option<OutFileName>> {
425 self.0.values()
426 }
427
428 pub fn len(&self) -> usize {
429 self.0.len()
430 }
431
432 pub fn should_codegen(&self) -> bool {
434 self.0.keys().any(|k| match *k {
435 OutputType::Bitcode
436 | OutputType::ThinLinkBitcode
437 | OutputType::Assembly
438 | OutputType::LlvmAssembly
439 | OutputType::Mir
440 | OutputType::Object
441 | OutputType::Exe => true,
442 OutputType::Metadata | OutputType::DepInfo => false,
443 })
444 }
445
446 pub fn should_link(&self) -> bool {
448 self.0.keys().any(|k| match *k {
449 OutputType::Bitcode
450 | OutputType::ThinLinkBitcode
451 | OutputType::Assembly
452 | OutputType::LlvmAssembly
453 | OutputType::Mir
454 | OutputType::Metadata
455 | OutputType::Object
456 | OutputType::DepInfo => false,
457 OutputType::Exe => true,
458 })
459 }
460}