1#![allow(internal_features)]
20#![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))]
21#![feature(core_io_borrowed_buf)]
22#![feature(decl_macro)]
23#![feature(diagnostic_on_unknown)]
24#![feature(map_try_insert)]
25#![feature(negative_impls)]
26#![feature(read_buf)]
27#![feature(rustc_attrs)]
28extern crate self as rustc_span;
34
35use rustc_data_structures::stable_hash::StableHashCtxt;
36use rustc_data_structures::{AtomicRef, outline};
37use rustc_macros::{Decodable, Encodable, StableHash};
38use rustc_serialize::opaque::mem_encoder::MemEncoder;
39use rustc_serialize::opaque::{FileEncoder, MemDecoder};
40use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
41use tracing::debug;
42pub use unicode_width::UNICODE_VERSION;
43
44mod caching_source_map_view;
45pub mod source_map;
46use source_map::{SourceMap, SourceMapInputs};
47
48pub use self::caching_source_map_view::CachingSourceMapView;
49use crate::fatal_error::FatalError;
50
51pub mod edition;
52use edition::Edition;
53pub mod hygiene;
54use hygiene::Transparency;
55pub use hygiene::{
56 DesugaringKind, ExpnData, ExpnHash, ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext,
57};
58pub mod def_id;
59use def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId, StableCrateId};
60pub mod edit_distance;
61mod span_encoding;
62pub use span_encoding::{DUMMY_SP, OrdSpan, Span};
63
64pub mod symbol;
65pub use symbol::{
66 ByteSymbol, Ident, MacroRulesNormalizedIdent, STDLIB_STABLE_CRATES, Symbol, kw, sym,
67};
68
69mod analyze_source_file;
70pub mod fatal_error;
71
72pub mod profiling;
73
74pub mod macros;
75use std::borrow::Cow;
76use std::fmt::Display;
77use std::hash::Hash;
78use std::io::{self, Read};
79use std::ops::{Add, Range, Sub};
80use std::path::{Path, PathBuf};
81use std::str::FromStr;
82use std::sync::Arc;
83use std::{cmp, fmt, iter};
84
85pub use macros::{bug, span_bug};
86use md5::{Digest, Md5};
87use rustc_data_structures::stable_hash::{StableHash, StableHasher};
88use rustc_data_structures::sync::{FreezeLock, FreezeWriteGuard, Lock};
89use rustc_data_structures::unord::UnordMap;
90use rustc_hashes::{Hash64, Hash128};
91use sha1::Sha1;
92use sha2::Sha256;
93
94#[cfg(test)]
95mod tests;
96
97#[derive(#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Spanned<T> {
#[inline]
fn clone(&self) -> Self {
Spanned {
node: ::core::clone::Clone::clone(&self.node),
span: ::core::clone::Clone::clone(&self.span),
}
}
}Clone, const _: () =
{
impl<T, __E: ::rustc_span::SpanEncoder>
::rustc_serialize::Encodable<__E> for Spanned<T> where
T: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let Spanned { node: ref __binding_0, span: ref __binding_1 } =
*self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable, const _: () =
{
impl<T, __D: ::rustc_span::SpanDecoder>
::rustc_serialize::Decodable<__D> for Spanned<T> where
T: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
Spanned {
node: ::rustc_serialize::Decodable::decode(__decoder),
span: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable, #[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for Spanned<T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "Spanned",
"node", &self.node, "span", &&self.span)
}
}Debug, #[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Spanned<T> { }Copy, #[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::marker::StructuralPartialEq for
Spanned<T> {
}
#[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for Spanned<T> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.node == other.node && self.span == other.span
}
}PartialEq, #[automatically_derived]
impl<T: ::core::hash::Hash> ::core::hash::Hash for Spanned<T> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.node, state);
::core::hash::Hash::hash(&self.span, state)
}
}Hash, const _: () =
{
impl<T> ::rustc_data_structures::stable_hash::StableHash for
Spanned<T> where
T: ::rustc_data_structures::stable_hash::StableHash {
#[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 {
Spanned { node: ref __binding_0, span: ref __binding_1 } =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
98pub struct Spanned<T> {
99 pub node: T,
100 pub span: Span,
101}
102
103pub fn respan<T>(sp: Span, t: T) -> Spanned<T> {
104 Spanned { node: t, span: sp }
105}
106
107pub fn dummy_spanned<T>(t: T) -> Spanned<T> {
108 respan(DUMMY_SP, t)
109}
110
111pub struct SessionGlobals {
116 symbol_interner: symbol::Interner,
117 span_interner: Lock<span_encoding::SpanInterner>,
118 metavar_spans: MetavarSpansMap,
121 hygiene_data: Lock<hygiene::HygieneData>,
122
123 source_map: Option<Arc<SourceMap>>,
127}
128
129impl SessionGlobals {
130 pub fn new(
131 edition: Edition,
132 extra_symbols: &[&'static str],
133 sm_inputs: Option<SourceMapInputs>,
134 ) -> SessionGlobals {
135 SessionGlobals {
136 symbol_interner: symbol::Interner::with_extra_symbols(extra_symbols),
137 span_interner: Lock::new(span_encoding::SpanInterner::default()),
138 metavar_spans: Default::default(),
139 hygiene_data: Lock::new(hygiene::HygieneData::new(edition)),
140 source_map: sm_inputs.map(|inputs| Arc::new(SourceMap::with_inputs(inputs))),
141 }
142 }
143}
144
145pub fn create_session_globals_then<R>(
146 edition: Edition,
147 extra_symbols: &[&'static str],
148 sm_inputs: Option<SourceMapInputs>,
149 f: impl FnOnce() -> R,
150) -> R {
151 if !!SESSION_GLOBALS.is_set() {
{
::core::panicking::panic_fmt(format_args!("SESSION_GLOBALS should never be overwritten! Use another thread if you need another SessionGlobals"));
}
};assert!(
152 !SESSION_GLOBALS.is_set(),
153 "SESSION_GLOBALS should never be overwritten! \
154 Use another thread if you need another SessionGlobals"
155 );
156 let session_globals = SessionGlobals::new(edition, extra_symbols, sm_inputs);
157 SESSION_GLOBALS.set(&session_globals, f)
158}
159
160pub fn set_session_globals_then<R>(session_globals: &SessionGlobals, f: impl FnOnce() -> R) -> R {
161 if !!SESSION_GLOBALS.is_set() {
{
::core::panicking::panic_fmt(format_args!("SESSION_GLOBALS should never be overwritten! Use another thread if you need another SessionGlobals"));
}
};assert!(
162 !SESSION_GLOBALS.is_set(),
163 "SESSION_GLOBALS should never be overwritten! \
164 Use another thread if you need another SessionGlobals"
165 );
166 SESSION_GLOBALS.set(session_globals, f)
167}
168
169pub fn create_session_if_not_set_then<R, F>(edition: Edition, f: F) -> R
171where
172 F: FnOnce(&SessionGlobals) -> R,
173{
174 if !SESSION_GLOBALS.is_set() {
175 let session_globals = SessionGlobals::new(edition, &[], None);
176 SESSION_GLOBALS.set(&session_globals, || SESSION_GLOBALS.with(f))
177 } else {
178 SESSION_GLOBALS.with(f)
179 }
180}
181
182#[inline]
183pub fn with_session_globals<R, F>(f: F) -> R
184where
185 F: FnOnce(&SessionGlobals) -> R,
186{
187 SESSION_GLOBALS.with(f)
188}
189
190pub fn create_default_session_globals_then<R>(f: impl FnOnce() -> R) -> R {
192 create_session_globals_then(edition::DEFAULT_EDITION, &[], None, f)
193}
194
195static SESSION_GLOBALS: ::scoped_tls::ScopedKey<SessionGlobals> =
::scoped_tls::ScopedKey {
inner: {
const FOO: ::std::thread::LocalKey<::std::cell::Cell<*const ()>> =
{
const __RUST_STD_INTERNAL_INIT: ::std::cell::Cell<*const ()>
=
{ ::std::cell::Cell::new(::std::ptr::null()) };
unsafe {
::std::thread::LocalKey::new(const {
if ::std::mem::needs_drop::<::std::cell::Cell<*const ()>>()
{
|__rust_std_internal_init|
{
#[thread_local]
static __RUST_STD_INTERNAL_VAL:
::std::thread::local_impl::EagerStorage<::std::cell::Cell<*const ()>>
=
::std::thread::local_impl::EagerStorage::new(__RUST_STD_INTERNAL_INIT);
__RUST_STD_INTERNAL_VAL.get()
}
} else {
|__rust_std_internal_init|
{
#[thread_local]
static __RUST_STD_INTERNAL_VAL: ::std::cell::Cell<*const ()>
=
__RUST_STD_INTERNAL_INIT;
&__RUST_STD_INTERNAL_VAL
}
}
})
}
};
&FOO
},
_marker: ::std::marker::PhantomData,
};scoped_tls::scoped_thread_local!(static SESSION_GLOBALS: SessionGlobals);
199
200#[derive(#[automatically_derived]
impl ::core::default::Default for MetavarSpansMap {
#[inline]
fn default() -> Self {
MetavarSpansMap(::core::default::Default::default())
}
}Default)]
201pub struct MetavarSpansMap(FreezeLock<UnordMap<Span, (Span, bool)>>);
202
203impl MetavarSpansMap {
204 pub fn insert(&self, span: Span, var_span: Span) -> bool {
205 match self.0.write().try_insert(span, (var_span, false)) {
206 Ok(_) => true,
207 Err(entry) => entry.entry.get().0 == var_span,
208 }
209 }
210
211 pub fn get(&self, span: Span) -> Option<Span> {
213 if let Some(mut mspans) = self.0.try_write() {
214 if let Some((var_span, read)) = mspans.get_mut(&span) {
215 *read = true;
216 Some(*var_span)
217 } else {
218 None
219 }
220 } else {
221 if let Some((span, true)) = self.0.read().get(&span) { Some(*span) } else { None }
222 }
223 }
224
225 pub fn freeze_and_get_read_spans(&self) -> UnordMap<Span, Span> {
229 self.0.freeze().items().filter(|(_, (_, b))| *b).map(|(s1, (s2, _))| (*s1, *s2)).collect()
230 }
231}
232
233#[inline]
234pub fn with_metavar_spans<R>(f: impl FnOnce(&MetavarSpansMap) -> R) -> R {
235 with_session_globals(|session_globals| f(&session_globals.metavar_spans))
236}
237
238#[doc =
r" Scopes used to determined if it need to apply to `--remap-path-prefix`"]
pub struct RemapPathScopeComponents(<RemapPathScopeComponents as
::bitflags::__private::PublicFlags>::Internal);
#[automatically_derived]
impl ::core::fmt::Debug for RemapPathScopeComponents {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"RemapPathScopeComponents", &&self.0)
}
}
#[automatically_derived]
impl ::core::cmp::Eq for RemapPathScopeComponents {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _:
::core::cmp::AssertParamIsEq<<RemapPathScopeComponents as
::bitflags::__private::PublicFlags>::Internal>;
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for RemapPathScopeComponents { }
#[automatically_derived]
impl ::core::cmp::PartialEq for RemapPathScopeComponents {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for RemapPathScopeComponents { }
#[automatically_derived]
impl ::core::clone::Clone for RemapPathScopeComponents {
#[inline]
fn clone(&self) -> Self {
let _:
::core::clone::AssertParamIsClone<<RemapPathScopeComponents as
::bitflags::__private::PublicFlags>::Internal>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for RemapPathScopeComponents { }
#[automatically_derived]
impl ::core::cmp::Ord for RemapPathScopeComponents {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for RemapPathScopeComponents {
#[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::hash::Hash for RemapPathScopeComponents {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
impl RemapPathScopeComponents {
#[doc = r" Apply remappings to the expansion of `std::file!()` macro"]
#[allow(deprecated, non_upper_case_globals,)]
pub const MACRO: Self = Self::from_bits_retain(1 << 0);
#[doc = r" Apply remappings to printed compiler diagnostics"]
#[allow(deprecated, non_upper_case_globals,)]
pub const DIAGNOSTICS: Self = Self::from_bits_retain(1 << 1);
#[doc = r" Apply remappings to debug information"]
#[allow(deprecated, non_upper_case_globals,)]
pub const DEBUGINFO: Self = Self::from_bits_retain(1 << 3);
#[doc = r" Apply remappings to coverage information"]
#[allow(deprecated, non_upper_case_globals,)]
pub const COVERAGE: Self = Self::from_bits_retain(1 << 4);
#[doc = r" Apply remappings to documentation information"]
#[allow(deprecated, non_upper_case_globals,)]
pub const DOCUMENTATION: Self = Self::from_bits_retain(1 << 5);
#[doc =
r" An alias for `macro`, `debuginfo` and `coverage`. This ensures all paths in compiled"]
#[doc =
r" executables, libraries and objects are remapped but not elsewhere."]
#[allow(deprecated, non_upper_case_globals,)]
pub const OBJECT: Self =
Self::from_bits_retain(Self::MACRO.bits() | Self::DEBUGINFO.bits() |
Self::COVERAGE.bits());
}
impl ::bitflags::Flags for RemapPathScopeComponents {
const FLAGS: &'static [::bitflags::Flag<RemapPathScopeComponents>] =
&[{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("MACRO",
RemapPathScopeComponents::MACRO)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("DIAGNOSTICS",
RemapPathScopeComponents::DIAGNOSTICS)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("DEBUGINFO",
RemapPathScopeComponents::DEBUGINFO)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("COVERAGE",
RemapPathScopeComponents::COVERAGE)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("DOCUMENTATION",
RemapPathScopeComponents::DOCUMENTATION)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("OBJECT",
RemapPathScopeComponents::OBJECT)
}];
type Bits = u8;
fn bits(&self) -> u8 { RemapPathScopeComponents::bits(self) }
fn from_bits_retain(bits: u8) -> RemapPathScopeComponents {
RemapPathScopeComponents::from_bits_retain(bits)
}
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: indexing_slicing, clippy :: same_name_method,
clippy :: iter_without_into_iter,)]
const _: () =
{
#[repr(transparent)]
pub struct InternalBitFlags(u8);
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for InternalBitFlags { }
#[automatically_derived]
impl ::core::clone::Clone for InternalBitFlags {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for InternalBitFlags { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for InternalBitFlags { }
#[automatically_derived]
impl ::core::cmp::PartialEq for InternalBitFlags {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for InternalBitFlags {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for InternalBitFlags {
#[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 InternalBitFlags {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::hash::Hash for InternalBitFlags {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
impl ::bitflags::__private::PublicFlags for RemapPathScopeComponents {
type Primitive = u8;
type Internal = InternalBitFlags;
}
impl ::bitflags::__private::core::default::Default for
InternalBitFlags {
#[inline]
fn default() -> Self { InternalBitFlags::empty() }
}
impl ::bitflags::__private::core::fmt::Debug for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
if self.is_empty() {
f.write_fmt(format_args!("{0:#x}",
<u8 as ::bitflags::Bits>::EMPTY))
} else {
::bitflags::__private::core::fmt::Display::fmt(self, f)
}
}
}
impl ::bitflags::__private::core::fmt::Display for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
::bitflags::parser::to_writer(&RemapPathScopeComponents(*self),
f)
}
}
impl ::bitflags::__private::core::str::FromStr for InternalBitFlags {
type Err = ::bitflags::parser::ParseError;
fn from_str(s: &str)
->
::bitflags::__private::core::result::Result<Self,
Self::Err> {
::bitflags::parser::from_str::<RemapPathScopeComponents>(s).map(|flags|
flags.0)
}
}
impl ::bitflags::__private::core::convert::AsRef<u8> for
InternalBitFlags {
fn as_ref(&self) -> &u8 { &self.0 }
}
impl ::bitflags::__private::core::convert::From<u8> for
InternalBitFlags {
fn from(bits: u8) -> Self { Self::from_bits_retain(bits) }
}
#[allow(dead_code, deprecated, unused_attributes)]
impl InternalBitFlags {
#[inline]
pub const fn empty() -> Self {
Self(<u8 as ::bitflags::Bits>::EMPTY)
}
#[inline]
pub const fn all() -> Self {
let mut truncated = <u8 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
<RemapPathScopeComponents as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<RemapPathScopeComponents as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<RemapPathScopeComponents as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<RemapPathScopeComponents as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<RemapPathScopeComponents as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<RemapPathScopeComponents as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
let _ = i;
Self(truncated)
}
#[inline]
pub const fn bits(&self) -> u8 { self.0 }
#[inline]
pub const fn from_bits(bits: u8)
-> ::bitflags::__private::core::option::Option<Self> {
let truncated = Self::from_bits_truncate(bits).0;
if truncated == bits {
::bitflags::__private::core::option::Option::Some(Self(bits))
} else { ::bitflags::__private::core::option::Option::None }
}
#[inline]
pub const fn from_bits_truncate(bits: u8) -> Self {
Self(bits & Self::all().0)
}
#[inline]
pub const fn from_bits_retain(bits: u8) -> Self { Self(bits) }
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
{
if name == "MACRO" {
return ::bitflags::__private::core::option::Option::Some(Self(RemapPathScopeComponents::MACRO.bits()));
}
};
;
{
if name == "DIAGNOSTICS" {
return ::bitflags::__private::core::option::Option::Some(Self(RemapPathScopeComponents::DIAGNOSTICS.bits()));
}
};
;
{
if name == "DEBUGINFO" {
return ::bitflags::__private::core::option::Option::Some(Self(RemapPathScopeComponents::DEBUGINFO.bits()));
}
};
;
{
if name == "COVERAGE" {
return ::bitflags::__private::core::option::Option::Some(Self(RemapPathScopeComponents::COVERAGE.bits()));
}
};
;
{
if name == "DOCUMENTATION" {
return ::bitflags::__private::core::option::Option::Some(Self(RemapPathScopeComponents::DOCUMENTATION.bits()));
}
};
;
{
if name == "OBJECT" {
return ::bitflags::__private::core::option::Option::Some(Self(RemapPathScopeComponents::OBJECT.bits()));
}
};
;
let _ = name;
::bitflags::__private::core::option::Option::None
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.0 == <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn is_all(&self) -> bool {
Self::all().0 | self.0 == self.0
}
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0 & other.0 != <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0 & other.0 == other.0
}
#[inline]
pub fn insert(&mut self, other: Self) {
*self = Self(self.0).union(other);
}
#[inline]
pub fn remove(&mut self, other: Self) {
*self = Self(self.0).difference(other);
}
#[inline]
pub fn toggle(&mut self, other: Self) {
*self = Self(self.0).symmetric_difference(other);
}
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0 ^ other.0)
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self::from_bits_truncate(!self.0)
}
}
impl ::bitflags::__private::core::fmt::Binary for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for InternalBitFlags {
type Output = Self;
#[inline]
fn bitor(self, other: InternalBitFlags) -> Self {
self.union(other)
}
}
impl ::bitflags::__private::core::ops::BitOrAssign for
InternalBitFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for InternalBitFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for
InternalBitFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for InternalBitFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for
InternalBitFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for InternalBitFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for InternalBitFlags
{
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for InternalBitFlags {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<InternalBitFlags> for
InternalBitFlags {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<InternalBitFlags>
for InternalBitFlags {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl InternalBitFlags {
#[inline]
pub const fn iter(&self)
-> ::bitflags::iter::Iter<RemapPathScopeComponents> {
::bitflags::iter::Iter::__private_const_new(<RemapPathScopeComponents
as ::bitflags::Flags>::FLAGS,
RemapPathScopeComponents::from_bits_retain(self.bits()),
RemapPathScopeComponents::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<RemapPathScopeComponents> {
::bitflags::iter::IterNames::__private_const_new(<RemapPathScopeComponents
as ::bitflags::Flags>::FLAGS,
RemapPathScopeComponents::from_bits_retain(self.bits()),
RemapPathScopeComponents::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for
InternalBitFlags {
type Item = RemapPathScopeComponents;
type IntoIter = ::bitflags::iter::Iter<RemapPathScopeComponents>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
impl InternalBitFlags {
#[inline]
pub fn bits_mut(&mut self) -> &mut u8 { &mut self.0 }
}
#[allow(dead_code, deprecated, unused_attributes)]
impl RemapPathScopeComponents {
#[inline]
pub const fn empty() -> Self { Self(InternalBitFlags::empty()) }
#[inline]
pub const fn all() -> Self { Self(InternalBitFlags::all()) }
#[inline]
pub const fn bits(&self) -> u8 { self.0.bits() }
#[inline]
pub const fn from_bits(bits: u8)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_bits(bits) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
#[inline]
pub const fn from_bits_truncate(bits: u8) -> Self {
Self(InternalBitFlags::from_bits_truncate(bits))
}
#[inline]
pub const fn from_bits_retain(bits: u8) -> Self {
Self(InternalBitFlags::from_bits_retain(bits))
}
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_name(name) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
#[inline]
pub const fn is_empty(&self) -> bool { self.0.is_empty() }
#[inline]
pub const fn is_all(&self) -> bool { self.0.is_all() }
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0.intersects(other.0)
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0.contains(other.0)
}
#[inline]
pub fn insert(&mut self, other: Self) { self.0.insert(other.0) }
#[inline]
pub fn remove(&mut self, other: Self) { self.0.remove(other.0) }
#[inline]
pub fn toggle(&mut self, other: Self) { self.0.toggle(other.0) }
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
self.0.set(other.0, value)
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0.intersection(other.0))
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0.union(other.0))
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0.difference(other.0))
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0.symmetric_difference(other.0))
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self(self.0.complement())
}
}
impl ::bitflags::__private::core::fmt::Binary for
RemapPathScopeComponents {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for
RemapPathScopeComponents {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for
RemapPathScopeComponents {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for
RemapPathScopeComponents {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for
RemapPathScopeComponents {
type Output = Self;
#[inline]
fn bitor(self, other: RemapPathScopeComponents) -> Self {
self.union(other)
}
}
impl ::bitflags::__private::core::ops::BitOrAssign for
RemapPathScopeComponents {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for
RemapPathScopeComponents {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for
RemapPathScopeComponents {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for
RemapPathScopeComponents {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for
RemapPathScopeComponents {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for
RemapPathScopeComponents {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for
RemapPathScopeComponents {
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for
RemapPathScopeComponents {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<RemapPathScopeComponents>
for RemapPathScopeComponents {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<RemapPathScopeComponents>
for RemapPathScopeComponents {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl RemapPathScopeComponents {
#[inline]
pub const fn iter(&self)
-> ::bitflags::iter::Iter<RemapPathScopeComponents> {
::bitflags::iter::Iter::__private_const_new(<RemapPathScopeComponents
as ::bitflags::Flags>::FLAGS,
RemapPathScopeComponents::from_bits_retain(self.bits()),
RemapPathScopeComponents::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<RemapPathScopeComponents> {
::bitflags::iter::IterNames::__private_const_new(<RemapPathScopeComponents
as ::bitflags::Flags>::FLAGS,
RemapPathScopeComponents::from_bits_retain(self.bits()),
RemapPathScopeComponents::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for
RemapPathScopeComponents {
type Item = RemapPathScopeComponents;
type IntoIter = ::bitflags::iter::Iter<RemapPathScopeComponents>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
};bitflags::bitflags! {
239 #[derive(Debug, Eq, PartialEq, Clone, Copy, Ord, PartialOrd, Hash)]
241 pub struct RemapPathScopeComponents: u8 {
242 const MACRO = 1 << 0;
244 const DIAGNOSTICS = 1 << 1;
246 const DEBUGINFO = 1 << 3;
248 const COVERAGE = 1 << 4;
250 const DOCUMENTATION = 1 << 5;
252
253 const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits() | Self::COVERAGE.bits();
256 }
257}
258
259impl<E: Encoder> Encodable<E> for RemapPathScopeComponents {
260 #[inline]
261 fn encode(&self, s: &mut E) {
262 s.emit_u8(self.bits());
263 }
264}
265
266impl<D: Decoder> Decodable<D> for RemapPathScopeComponents {
267 #[inline]
268 fn decode(s: &mut D) -> RemapPathScopeComponents {
269 RemapPathScopeComponents::from_bits(s.read_u8())
270 .expect("invalid bits for RemapPathScopeComponents")
271 }
272}
273
274#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RealFileName {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "RealFileName",
"local", &self.local, "maybe_remapped", &self.maybe_remapped,
"scopes", &&self.scopes)
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for RealFileName {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Option<InnerRealFileName>>;
let _: ::core::cmp::AssertParamIsEq<InnerRealFileName>;
let _: ::core::cmp::AssertParamIsEq<RemapPathScopeComponents>;
}
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for RealFileName { }
#[automatically_derived]
impl ::core::cmp::PartialEq for RealFileName {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.local == other.local &&
self.maybe_remapped == other.maybe_remapped &&
self.scopes == other.scopes
}
}PartialEq, #[automatically_derived]
impl ::core::clone::Clone for RealFileName {
#[inline]
fn clone(&self) -> Self {
RealFileName {
local: ::core::clone::Clone::clone(&self.local),
maybe_remapped: ::core::clone::Clone::clone(&self.maybe_remapped),
scopes: ::core::clone::Clone::clone(&self.scopes),
}
}
}Clone, #[automatically_derived]
impl ::core::cmp::Ord for RealFileName {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.local, &other.local) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(&self.maybe_remapped,
&other.maybe_remapped) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.scopes, &other.scopes),
cmp => cmp,
},
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::cmp::PartialOrd for RealFileName {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for RealFileName {
fn decode(__decoder: &mut __D) -> Self {
RealFileName {
local: ::rustc_serialize::Decodable::decode(__decoder),
maybe_remapped: ::rustc_serialize::Decodable::decode(__decoder),
scopes: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for RealFileName {
fn encode(&self, __encoder: &mut __E) {
let RealFileName {
local: ref __binding_0,
maybe_remapped: ref __binding_1,
scopes: ref __binding_2 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
};Encodable)]
306pub struct RealFileName {
307 local: Option<InnerRealFileName>,
309 maybe_remapped: InnerRealFileName,
311 scopes: RemapPathScopeComponents,
313}
314
315#[derive(#[automatically_derived]
impl ::core::fmt::Debug for InnerRealFileName {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"InnerRealFileName", "name", &self.name, "working_directory",
&self.working_directory, "embeddable_name",
&&self.embeddable_name)
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for InnerRealFileName {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<PathBuf>;
}
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for InnerRealFileName { }
#[automatically_derived]
impl ::core::cmp::PartialEq for InnerRealFileName {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.name == other.name &&
self.working_directory == other.working_directory &&
self.embeddable_name == other.embeddable_name
}
}PartialEq, #[automatically_derived]
impl ::core::clone::Clone for InnerRealFileName {
#[inline]
fn clone(&self) -> Self {
InnerRealFileName {
name: ::core::clone::Clone::clone(&self.name),
working_directory: ::core::clone::Clone::clone(&self.working_directory),
embeddable_name: ::core::clone::Clone::clone(&self.embeddable_name),
}
}
}Clone, #[automatically_derived]
impl ::core::cmp::Ord for InnerRealFileName {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.name, &other.name) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(&self.working_directory,
&other.working_directory) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.embeddable_name,
&other.embeddable_name),
cmp => cmp,
},
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::cmp::PartialOrd for InnerRealFileName {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for InnerRealFileName {
fn decode(__decoder: &mut __D) -> Self {
InnerRealFileName {
name: ::rustc_serialize::Decodable::decode(__decoder),
working_directory: ::rustc_serialize::Decodable::decode(__decoder),
embeddable_name: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for InnerRealFileName {
fn encode(&self, __encoder: &mut __E) {
let InnerRealFileName {
name: ref __binding_0,
working_directory: ref __binding_1,
embeddable_name: ref __binding_2 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
};Encodable, #[automatically_derived]
impl ::core::hash::Hash for InnerRealFileName {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.name, state);
::core::hash::Hash::hash(&self.working_directory, state);
::core::hash::Hash::hash(&self.embeddable_name, state)
}
}Hash)]
319struct InnerRealFileName {
320 name: PathBuf,
322 working_directory: PathBuf,
324 embeddable_name: PathBuf,
326}
327
328impl Hash for RealFileName {
329 #[inline]
330 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
331 if !self.was_fully_remapped() {
336 self.local.hash(state);
337 }
338 self.maybe_remapped.hash(state);
339 self.scopes.bits().hash(state);
340 }
341}
342
343impl RealFileName {
344 #[inline]
350 pub fn path(&self, scope: RemapPathScopeComponents) -> &Path {
351 if !(scope.bits().count_ones() == 1) {
{
::core::panicking::panic_fmt(format_args!("one and only one scope should be passed to `RealFileName::path`: {0:?}",
scope));
}
};assert!(
352 scope.bits().count_ones() == 1,
353 "one and only one scope should be passed to `RealFileName::path`: {scope:?}"
354 );
355 if !self.scopes.contains(scope)
356 && let Some(local_name) = &self.local
357 {
358 local_name.name.as_path()
359 } else {
360 self.maybe_remapped.name.as_path()
361 }
362 }
363
364 #[inline]
375 pub fn embeddable_name(&self, scope: RemapPathScopeComponents) -> (&Path, &Path) {
376 if !(scope.bits().count_ones() == 1) {
{
::core::panicking::panic_fmt(format_args!("one and only one scope should be passed to `RealFileName::embeddable_path`: {0:?}",
scope));
}
};assert!(
377 scope.bits().count_ones() == 1,
378 "one and only one scope should be passed to `RealFileName::embeddable_path`: {scope:?}"
379 );
380 if !self.scopes.contains(scope)
381 && let Some(local_name) = &self.local
382 {
383 (&local_name.working_directory, &local_name.embeddable_name)
384 } else {
385 (&self.maybe_remapped.working_directory, &self.maybe_remapped.embeddable_name)
386 }
387 }
388
389 #[inline]
396 pub fn local_path(&self) -> Option<&Path> {
397 if self.was_not_remapped() {
398 Some(&self.maybe_remapped.name)
399 } else if let Some(local) = &self.local {
400 Some(&local.name)
401 } else {
402 None
403 }
404 }
405
406 #[inline]
413 pub fn into_local_path(self) -> Option<PathBuf> {
414 if self.was_not_remapped() {
415 Some(self.maybe_remapped.name)
416 } else if let Some(local) = self.local {
417 Some(local.name)
418 } else {
419 None
420 }
421 }
422
423 #[inline]
425 pub(crate) fn was_remapped(&self) -> bool {
426 !self.scopes.is_empty()
427 }
428
429 #[inline]
431 fn was_fully_remapped(&self) -> bool {
432 self.scopes.is_all()
433 }
434
435 #[inline]
437 fn was_not_remapped(&self) -> bool {
438 self.scopes.is_empty()
439 }
440
441 #[inline]
445 pub fn empty() -> RealFileName {
446 RealFileName {
447 local: Some(InnerRealFileName {
448 name: PathBuf::new(),
449 working_directory: PathBuf::new(),
450 embeddable_name: PathBuf::new(),
451 }),
452 maybe_remapped: InnerRealFileName {
453 name: PathBuf::new(),
454 working_directory: PathBuf::new(),
455 embeddable_name: PathBuf::new(),
456 },
457 scopes: RemapPathScopeComponents::empty(),
458 }
459 }
460
461 pub fn from_virtual_path(path: &Path) -> RealFileName {
465 let name = InnerRealFileName {
466 name: path.to_owned(),
467 embeddable_name: path.to_owned(),
468 working_directory: PathBuf::new(),
469 };
470 RealFileName { local: None, maybe_remapped: name, scopes: RemapPathScopeComponents::all() }
471 }
472
473 #[inline]
478 pub fn update_for_crate_metadata(&mut self) {
479 if self.was_fully_remapped() || self.was_not_remapped() {
480 self.local = None;
485 }
486 }
487
488 fn to_string_lossy<'a>(&'a self, display_pref: FileNameDisplayPreference) -> Cow<'a, str> {
492 match display_pref {
493 FileNameDisplayPreference::Remapped => self.maybe_remapped.name.to_string_lossy(),
494 FileNameDisplayPreference::Local => {
495 self.local.as_ref().unwrap_or(&self.maybe_remapped).name.to_string_lossy()
496 }
497 FileNameDisplayPreference::Short => self
498 .maybe_remapped
499 .name
500 .file_name()
501 .map_or_else(|| "".into(), |f| f.to_string_lossy()),
502 FileNameDisplayPreference::Scope(scope) => self.path(scope).to_string_lossy(),
503 }
504 }
505}
506
507#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FileName {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Real(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Real",
&__self_0),
Self::CfgSpec(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"CfgSpec", &__self_0),
Self::Anon(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Anon",
&__self_0),
Self::MacroExpansion(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"MacroExpansion", &__self_0),
Self::ProcMacroSourceCode(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ProcMacroSourceCode", &__self_0),
Self::CliCrateAttr(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"CliCrateAttr", &__self_0),
Self::Custom(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Custom",
&__self_0),
Self::DocTest(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DocTest", __self_0, &__self_1),
Self::InlineAsm(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InlineAsm", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for FileName {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<RealFileName>;
let _: ::core::cmp::AssertParamIsEq<Hash64>;
let _: ::core::cmp::AssertParamIsEq<String>;
let _: ::core::cmp::AssertParamIsEq<isize>;
}
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for FileName { }
#[automatically_derived]
impl ::core::cmp::PartialEq for FileName {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Real(__self_0), Self::Real(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::CfgSpec(__self_0), Self::CfgSpec(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Anon(__self_0), Self::Anon(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::MacroExpansion(__self_0),
Self::MacroExpansion(__arg1_0)) => __self_0 == __arg1_0,
(Self::ProcMacroSourceCode(__self_0),
Self::ProcMacroSourceCode(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::CliCrateAttr(__self_0), Self::CliCrateAttr(__arg1_0))
=> __self_0 == __arg1_0,
(Self::Custom(__self_0), Self::Custom(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::DocTest(__self_0, __self_1),
Self::DocTest(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::InlineAsm(__self_0), Self::InlineAsm(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::clone::Clone for FileName {
#[inline]
fn clone(&self) -> Self {
match self {
Self::Real(__self_0) =>
FileName::Real(::core::clone::Clone::clone(__self_0)),
Self::CfgSpec(__self_0) =>
FileName::CfgSpec(::core::clone::Clone::clone(__self_0)),
Self::Anon(__self_0) =>
FileName::Anon(::core::clone::Clone::clone(__self_0)),
Self::MacroExpansion(__self_0) =>
FileName::MacroExpansion(::core::clone::Clone::clone(__self_0)),
Self::ProcMacroSourceCode(__self_0) =>
FileName::ProcMacroSourceCode(::core::clone::Clone::clone(__self_0)),
Self::CliCrateAttr(__self_0) =>
FileName::CliCrateAttr(::core::clone::Clone::clone(__self_0)),
Self::Custom(__self_0) =>
FileName::Custom(::core::clone::Clone::clone(__self_0)),
Self::DocTest(__self_0, __self_1) =>
FileName::DocTest(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1)),
Self::InlineAsm(__self_0) =>
FileName::InlineAsm(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]
impl ::core::cmp::Ord for FileName {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match (self, other) {
(Self::Real(__self_0), Self::Real(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::CfgSpec(__self_0), Self::CfgSpec(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::Anon(__self_0), Self::Anon(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::MacroExpansion(__self_0), Self::MacroExpansion(__arg1_0))
=> ::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::ProcMacroSourceCode(__self_0),
Self::ProcMacroSourceCode(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::CliCrateAttr(__self_0), Self::CliCrateAttr(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::Custom(__self_0), Self::Custom(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::DocTest(__self_0, __self_1),
Self::DocTest(__arg1_0, __arg1_1)) =>
match ::core::cmp::Ord::cmp(__self_0, __arg1_0) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(__self_1, __arg1_1),
cmp => cmp,
},
(Self::InlineAsm(__self_0), Self::InlineAsm(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ =>
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other)),
}
}
}Ord, #[automatically_derived]
impl ::core::cmp::PartialOrd for FileName {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::hash::Hash for FileName {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Real(__self_0) => ::core::hash::Hash::hash(__self_0, state),
Self::CfgSpec(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Anon(__self_0) => ::core::hash::Hash::hash(__self_0, state),
Self::MacroExpansion(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::ProcMacroSourceCode(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::CliCrateAttr(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Custom(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::DocTest(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::InlineAsm(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for FileName {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
FileName::Real(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
FileName::CfgSpec(::rustc_serialize::Decodable::decode(__decoder))
}
2usize => {
FileName::Anon(::rustc_serialize::Decodable::decode(__decoder))
}
3usize => {
FileName::MacroExpansion(::rustc_serialize::Decodable::decode(__decoder))
}
4usize => {
FileName::ProcMacroSourceCode(::rustc_serialize::Decodable::decode(__decoder))
}
5usize => {
FileName::CliCrateAttr(::rustc_serialize::Decodable::decode(__decoder))
}
6usize => {
FileName::Custom(::rustc_serialize::Decodable::decode(__decoder))
}
7usize => {
FileName::DocTest(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
8usize => {
FileName::InlineAsm(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `FileName`, expected 0..9, actual {0}",
n));
}
}
}
}
};Decodable, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for FileName {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
FileName::Real(ref __binding_0) => { 0usize }
FileName::CfgSpec(ref __binding_0) => { 1usize }
FileName::Anon(ref __binding_0) => { 2usize }
FileName::MacroExpansion(ref __binding_0) => { 3usize }
FileName::ProcMacroSourceCode(ref __binding_0) => { 4usize }
FileName::CliCrateAttr(ref __binding_0) => { 5usize }
FileName::Custom(ref __binding_0) => { 6usize }
FileName::DocTest(ref __binding_0, ref __binding_1) => {
7usize
}
FileName::InlineAsm(ref __binding_0) => { 8usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
FileName::Real(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
FileName::CfgSpec(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
FileName::Anon(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
FileName::MacroExpansion(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
FileName::ProcMacroSourceCode(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
FileName::CliCrateAttr(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
FileName::Custom(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
FileName::DocTest(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
FileName::InlineAsm(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable)]
509pub enum FileName {
510 Real(RealFileName),
511 CfgSpec(Hash64),
513 Anon(Hash64),
515 MacroExpansion(Hash64),
518 ProcMacroSourceCode(Hash64),
519 CliCrateAttr(Hash64),
521 Custom(String),
523 DocTest(RealFileName, isize),
525 InlineAsm(Hash64),
527}
528
529pub struct FileNameDisplay<'a> {
530 inner: &'a FileName,
531 display_pref: FileNameDisplayPreference,
532}
533
534#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for FileNameDisplayPreference { }
#[automatically_derived]
impl ::core::clone::Clone for FileNameDisplayPreference {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<RemapPathScopeComponents>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for FileNameDisplayPreference { }Copy)]
536enum FileNameDisplayPreference {
537 Remapped,
538 Local,
539 Short,
540 Scope(RemapPathScopeComponents),
541}
542
543impl fmt::Display for FileNameDisplay<'_> {
544 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
545 use FileName::*;
546 match *self.inner {
547 Real(ref name) | DocTest(ref name, _) => {
548 fmt.write_fmt(format_args!("{0}", name.to_string_lossy(self.display_pref)))write!(fmt, "{}", name.to_string_lossy(self.display_pref))
549 }
550 CfgSpec(_) => fmt.write_fmt(format_args!("<cfgspec>"))write!(fmt, "<cfgspec>"),
551 MacroExpansion(_) => fmt.write_fmt(format_args!("<macro expansion>"))write!(fmt, "<macro expansion>"),
552 Anon(_) => fmt.write_fmt(format_args!("<anon>"))write!(fmt, "<anon>"),
553 ProcMacroSourceCode(_) => fmt.write_fmt(format_args!("<proc-macro source code>"))write!(fmt, "<proc-macro source code>"),
554 CliCrateAttr(_) => fmt.write_fmt(format_args!("<crate attribute>"))write!(fmt, "<crate attribute>"),
555 Custom(ref s) => fmt.write_fmt(format_args!("<{0}>", s))write!(fmt, "<{s}>"),
556 InlineAsm(_) => fmt.write_fmt(format_args!("<inline asm>"))write!(fmt, "<inline asm>"),
557 }
558 }
559}
560
561impl<'a> FileNameDisplay<'a> {
562 pub fn to_string_lossy(&self) -> Cow<'a, str> {
563 match self.inner {
564 FileName::Real(inner) => inner.to_string_lossy(self.display_pref),
565 _ => Cow::from(self.to_string()),
566 }
567 }
568}
569
570impl FileName {
571 pub fn is_real(&self) -> bool {
572 use FileName::*;
573 match *self {
574 Real(_) => true,
575 Anon(_)
576 | MacroExpansion(_)
577 | ProcMacroSourceCode(_)
578 | CliCrateAttr(_)
579 | Custom(_)
580 | CfgSpec(_)
581 | DocTest(_, _)
582 | InlineAsm(_) => false,
583 }
584 }
585
586 #[inline]
591 pub fn prefer_remapped_unconditionally(&self) -> FileNameDisplay<'_> {
592 FileNameDisplay { inner: self, display_pref: FileNameDisplayPreference::Remapped }
593 }
594
595 #[inline]
600 pub fn prefer_local_unconditionally(&self) -> FileNameDisplay<'_> {
601 FileNameDisplay { inner: self, display_pref: FileNameDisplayPreference::Local }
602 }
603
604 #[inline]
606 pub fn short(&self) -> FileNameDisplay<'_> {
607 FileNameDisplay { inner: self, display_pref: FileNameDisplayPreference::Short }
608 }
609
610 #[inline]
612 pub fn display(&self, scope: RemapPathScopeComponents) -> FileNameDisplay<'_> {
613 FileNameDisplay { inner: self, display_pref: FileNameDisplayPreference::Scope(scope) }
614 }
615
616 pub fn macro_expansion_source_code(src: &str) -> FileName {
617 let mut hasher = StableHasher::new();
618 src.hash(&mut hasher);
619 FileName::MacroExpansion(hasher.finish())
620 }
621
622 pub fn anon_source_code(src: &str) -> FileName {
623 let mut hasher = StableHasher::new();
624 src.hash(&mut hasher);
625 FileName::Anon(hasher.finish())
626 }
627
628 pub fn proc_macro_source_code(src: &str) -> FileName {
629 let mut hasher = StableHasher::new();
630 src.hash(&mut hasher);
631 FileName::ProcMacroSourceCode(hasher.finish())
632 }
633
634 pub fn cfg_spec_source_code(src: &str) -> FileName {
635 let mut hasher = StableHasher::new();
636 src.hash(&mut hasher);
637 FileName::CfgSpec(hasher.finish())
638 }
639
640 pub fn cli_crate_attr_source_code(src: &str) -> FileName {
641 let mut hasher = StableHasher::new();
642 src.hash(&mut hasher);
643 FileName::CliCrateAttr(hasher.finish())
644 }
645
646 pub fn doc_test_source_code(path: RealFileName, line: isize) -> FileName {
647 FileName::DocTest(path, line)
648 }
649
650 pub fn inline_asm_source_code(src: &str) -> FileName {
651 let mut hasher = StableHasher::new();
652 src.hash(&mut hasher);
653 FileName::InlineAsm(hasher.finish())
654 }
655
656 pub fn into_local_path(self) -> Option<PathBuf> {
661 match self {
662 FileName::Real(path) => path.into_local_path(),
663 FileName::DocTest(path, _) => path.into_local_path(),
664 _ => None,
665 }
666 }
667}
668
669#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for SpanData { }
#[automatically_derived]
impl ::core::clone::Clone for SpanData {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<BytePos>;
let _: ::core::clone::AssertParamIsClone<SyntaxContext>;
let _: ::core::clone::AssertParamIsClone<Option<LocalDefId>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for SpanData { }Copy, #[automatically_derived]
impl ::core::hash::Hash for SpanData {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.lo, state);
::core::hash::Hash::hash(&self.hi, state);
::core::hash::Hash::hash(&self.ctxt, state);
::core::hash::Hash::hash(&self.parent, state)
}
}Hash, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for SpanData { }
#[automatically_derived]
impl ::core::cmp::PartialEq for SpanData {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.lo == other.lo && self.hi == other.hi && self.ctxt == other.ctxt
&& self.parent == other.parent
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for SpanData {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<BytePos>;
let _: ::core::cmp::AssertParamIsEq<SyntaxContext>;
let _: ::core::cmp::AssertParamIsEq<Option<LocalDefId>>;
}
}Eq)]
685pub struct SpanData {
686 pub lo: BytePos,
687 pub hi: BytePos,
688 pub ctxt: SyntaxContext,
691 pub parent: Option<LocalDefId>,
692}
693
694impl !PartialOrd for SpanData {}
697impl !Ord for SpanData {}
698
699impl SpanData {
700 #[inline]
701 pub fn span(&self) -> Span {
702 Span::new(self.lo, self.hi, self.ctxt, self.parent)
703 }
704 #[inline]
705 pub fn with_lo(&self, lo: BytePos) -> Span {
706 Span::new(lo, self.hi, self.ctxt, self.parent)
707 }
708 #[inline]
709 pub fn with_hi(&self, hi: BytePos) -> Span {
710 Span::new(self.lo, hi, self.ctxt, self.parent)
711 }
712 #[inline]
714 fn with_ctxt(&self, ctxt: SyntaxContext) -> Span {
715 Span::new(self.lo, self.hi, ctxt, self.parent)
716 }
717 #[inline]
719 fn with_parent(&self, parent: Option<LocalDefId>) -> Span {
720 Span::new(self.lo, self.hi, self.ctxt, parent)
721 }
722 #[inline]
724 pub fn is_dummy(self) -> bool {
725 self.lo.0 == 0 && self.hi.0 == 0
726 }
727 pub fn contains(self, other: Self) -> bool {
729 self.lo <= other.lo && other.hi <= self.hi
730 }
731}
732
733impl Default for SpanData {
734 fn default() -> Self {
735 Self { lo: BytePos(0), hi: BytePos(0), ctxt: SyntaxContext::root(), parent: None }
736 }
737}
738
739impl Span {
740 #[inline]
741 pub fn lo(self) -> BytePos {
742 self.data().lo
743 }
744 #[inline]
745 pub fn with_lo(self, lo: BytePos) -> Span {
746 self.data().with_lo(lo)
747 }
748 #[inline]
749 pub fn hi(self) -> BytePos {
750 self.data().hi
751 }
752 #[inline]
753 pub fn with_hi(self, hi: BytePos) -> Span {
754 self.data().with_hi(hi)
755 }
756 #[inline]
757 pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span {
758 self.map_ctxt(|_| ctxt)
759 }
760
761 #[inline]
766 pub fn lo_hi(self) -> (BytePos, BytePos) {
767 let data = self.data();
768 (data.lo, data.hi)
769 }
770
771 #[inline]
772 pub fn is_visible(self, sm: &SourceMap) -> bool {
773 !self.is_dummy() && sm.is_span_accessible(self)
774 }
775
776 #[inline]
781 pub fn in_external_macro(self, sm: &SourceMap) -> bool {
782 self.ctxt().in_external_macro(sm)
783 }
784
785 pub fn in_derive_expansion(self) -> bool {
787 #[allow(non_exhaustive_omitted_patterns)] match self.ctxt().outer_expn_data().kind
{
ExpnKind::Macro(MacroKind::Derive, _) => true,
_ => false,
}matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
788 }
789
790 pub fn is_from_async_await(self) -> bool {
792 #[allow(non_exhaustive_omitted_patterns)] match self.ctxt().outer_expn_data().kind
{
ExpnKind::Desugaring(DesugaringKind::Async | DesugaringKind::Await) =>
true,
_ => false,
}matches!(
793 self.ctxt().outer_expn_data().kind,
794 ExpnKind::Desugaring(DesugaringKind::Async | DesugaringKind::Await),
795 )
796 }
797
798 pub fn can_be_used_for_suggestions(self) -> bool {
800 !self.from_expansion()
801 || (self.in_derive_expansion()
805 && self.parent_callsite().map(|p| (p.lo(), p.hi())) != Some((self.lo(), self.hi())))
806 }
807
808 #[inline]
809 pub fn with_root_ctxt(lo: BytePos, hi: BytePos) -> Span {
810 Span::new(lo, hi, SyntaxContext::root(), None)
811 }
812
813 #[inline]
815 pub fn shrink_to_lo(self) -> Span {
816 let span = self.data_untracked();
817 span.with_hi(span.lo)
818 }
819 #[inline]
821 pub fn shrink_to_hi(self) -> Span {
822 let span = self.data_untracked();
823 span.with_lo(span.hi)
824 }
825
826 #[inline]
827 pub fn is_empty(self) -> bool {
829 let span = self.data_untracked();
830 span.hi == span.lo
831 }
832
833 pub fn substitute_dummy(self, other: Span) -> Span {
835 if self.is_dummy() { other } else { self }
836 }
837
838 pub fn contains(self, other: Span) -> bool {
840 let span = self.data();
841 let other = other.data();
842 span.contains(other)
843 }
844
845 pub fn overlaps(self, other: Span) -> bool {
847 let span = self.data();
848 let other = other.data();
849 span.lo < other.hi && other.lo < span.hi
850 }
851
852 pub fn overlaps_or_adjacent(self, other: Span) -> bool {
854 let span = self.data();
855 let other = other.data();
856 span.lo <= other.hi && other.lo <= span.hi
857 }
858
859 pub fn trim_start(self, other: Span) -> Option<Span> {
861 let span = self.data();
862 let other = other.data();
863 if span.hi > other.hi { Some(span.with_lo(cmp::max(span.lo, other.hi))) } else { None }
864 }
865
866 pub fn trim_end(self, other: Span) -> Option<Span> {
868 let span = self.data();
869 let other = other.data();
870 if span.lo < other.lo { Some(span.with_hi(cmp::min(span.hi, other.lo))) } else { None }
871 }
872
873 pub fn source_callsite(self) -> Span {
876 let ctxt = self.ctxt();
877 if !ctxt.is_root() { ctxt.outer_expn_data().call_site.source_callsite() } else { self }
878 }
879
880 pub fn parent_callsite(self) -> Option<Span> {
883 let ctxt = self.ctxt();
884 (!ctxt.is_root()).then(|| ctxt.outer_expn_data().call_site)
885 }
886
887 pub fn find_ancestor_inside(mut self, outer: Span) -> Option<Span> {
900 while !outer.contains(self) {
901 self = self.parent_callsite()?;
902 }
903 Some(self)
904 }
905
906 pub fn find_ancestor_in_same_ctxt(mut self, other: Span) -> Option<Span> {
919 while !self.eq_ctxt(other) {
920 self = self.parent_callsite()?;
921 }
922 Some(self)
923 }
924
925 pub fn find_ancestor_inside_same_ctxt(mut self, outer: Span) -> Option<Span> {
938 while !outer.contains(self) || !self.eq_ctxt(outer) {
939 self = self.parent_callsite()?;
940 }
941 Some(self)
942 }
943
944 pub fn find_ancestor_not_from_extern_macro(mut self, sm: &SourceMap) -> Option<Span> {
958 while self.in_external_macro(sm) {
959 self = self.parent_callsite()?;
960 }
961 Some(self)
962 }
963
964 pub fn find_ancestor_not_from_macro(mut self) -> Option<Span> {
977 while self.from_expansion() {
978 self = self.parent_callsite()?;
979 }
980 Some(self)
981 }
982
983 pub fn edition(self) -> edition::Edition {
985 self.ctxt().edition()
986 }
987
988 #[inline]
990 pub fn is_rust_2015(self) -> bool {
991 self.edition().is_rust_2015()
992 }
993
994 #[inline]
996 pub fn at_least_rust_2018(self) -> bool {
997 self.edition().at_least_rust_2018()
998 }
999
1000 #[inline]
1002 pub fn at_least_rust_2021(self) -> bool {
1003 self.edition().at_least_rust_2021()
1004 }
1005
1006 #[inline]
1008 pub fn at_least_rust_2024(self) -> bool {
1009 self.edition().at_least_rust_2024()
1010 }
1011
1012 pub fn source_callee(self) -> Option<ExpnData> {
1018 let mut ctxt = self.ctxt();
1019 let mut opt_expn_data = None;
1020 while !ctxt.is_root() {
1021 let expn_data = ctxt.outer_expn_data();
1022 ctxt = expn_data.call_site.ctxt();
1023 opt_expn_data = Some(expn_data);
1024 }
1025 opt_expn_data
1026 }
1027
1028 pub fn allows_unstable(self, feature: Symbol) -> bool {
1032 self.ctxt()
1033 .outer_expn_data()
1034 .allow_internal_unstable
1035 .is_some_and(|features| features.contains(&feature))
1036 }
1037
1038 pub fn is_desugaring(self, kind: DesugaringKind) -> bool {
1040 match self.ctxt().outer_expn_data().kind {
1041 ExpnKind::Desugaring(k) => k == kind,
1042 _ => false,
1043 }
1044 }
1045
1046 pub fn desugaring_kind(self) -> Option<DesugaringKind> {
1049 match self.ctxt().outer_expn_data().kind {
1050 ExpnKind::Desugaring(k) => Some(k),
1051 _ => None,
1052 }
1053 }
1054
1055 pub fn allows_unsafe(self) -> bool {
1059 self.ctxt().outer_expn_data().allow_internal_unsafe
1060 }
1061
1062 pub fn macro_backtrace(mut self) -> impl Iterator<Item = ExpnData> {
1063 let mut prev_span = DUMMY_SP;
1064 iter::from_fn(move || {
1065 loop {
1066 let ctxt = self.ctxt();
1067 if ctxt.is_root() {
1068 return None;
1069 }
1070
1071 let expn_data = ctxt.outer_expn_data();
1072 let is_recursive = expn_data.call_site.lo_hi() == prev_span.lo_hi();
1073
1074 prev_span = self;
1075 self = expn_data.call_site;
1076
1077 if !is_recursive {
1079 return Some(expn_data);
1080 }
1081 }
1082 })
1083 }
1084
1085 pub fn split_at(self, pos: u32) -> (Span, Span) {
1087 let len = self.hi().0 - self.lo().0;
1088 if true {
if !(pos <= len) {
::core::panicking::panic("assertion failed: pos <= len")
};
};debug_assert!(pos <= len);
1089
1090 let split_pos = BytePos(self.lo().0 + pos);
1091 (
1092 Span::new(self.lo(), split_pos, self.ctxt(), self.parent()),
1093 Span::new(split_pos, self.hi(), self.ctxt(), self.parent()),
1094 )
1095 }
1096
1097 fn try_metavars(a: SpanData, b: SpanData, a_orig: Span, b_orig: Span) -> (SpanData, SpanData) {
1099 match with_metavar_spans(|mspans| (mspans.get(a_orig), mspans.get(b_orig))) {
1100 (None, None) => {}
1101 (Some(meta_a), None) => {
1102 let meta_a = meta_a.data();
1103 if meta_a.ctxt == b.ctxt {
1104 return (meta_a, b);
1105 }
1106 }
1107 (None, Some(meta_b)) => {
1108 let meta_b = meta_b.data();
1109 if a.ctxt == meta_b.ctxt {
1110 return (a, meta_b);
1111 }
1112 }
1113 (Some(meta_a), Some(meta_b)) => {
1114 let meta_b = meta_b.data();
1115 if a.ctxt == meta_b.ctxt {
1116 return (a, meta_b);
1117 }
1118 let meta_a = meta_a.data();
1119 if meta_a.ctxt == b.ctxt {
1120 return (meta_a, b);
1121 } else if meta_a.ctxt == meta_b.ctxt {
1122 return (meta_a, meta_b);
1123 }
1124 }
1125 }
1126
1127 (a, b)
1128 }
1129
1130 fn prepare_to_combine(
1132 a_orig: Span,
1133 b_orig: Span,
1134 ) -> Result<(SpanData, SpanData, Option<LocalDefId>), Span> {
1135 let (a, b) = (a_orig.data(), b_orig.data());
1136 if a.ctxt == b.ctxt {
1137 return Ok((a, b, if a.parent == b.parent { a.parent } else { None }));
1138 }
1139
1140 let (a, b) = Span::try_metavars(a, b, a_orig, b_orig);
1141 if a.ctxt == b.ctxt {
1142 return Ok((a, b, if a.parent == b.parent { a.parent } else { None }));
1143 }
1144
1145 let a_is_callsite = a.ctxt.is_root() || a.ctxt == b.span().source_callsite().ctxt();
1153 Err(if a_is_callsite { b_orig } else { a_orig })
1154 }
1155
1156 pub fn with_neighbor(self, neighbor: Span) -> Span {
1158 match Span::prepare_to_combine(self, neighbor) {
1159 Ok((this, ..)) => this.span(),
1160 Err(_) => self,
1161 }
1162 }
1163
1164 pub fn to(self, end: Span) -> Span {
1175 match Span::prepare_to_combine(self, end) {
1176 Ok((from, to, parent)) => {
1177 Span::new(cmp::min(from.lo, to.lo), cmp::max(from.hi, to.hi), from.ctxt, parent)
1178 }
1179 Err(fallback) => fallback,
1180 }
1181 }
1182
1183 pub fn between(self, end: Span) -> Span {
1191 match Span::prepare_to_combine(self, end) {
1192 Ok((from, to, parent)) => {
1193 Span::new(cmp::min(from.hi, to.hi), cmp::max(from.lo, to.lo), from.ctxt, parent)
1194 }
1195 Err(fallback) => fallback,
1196 }
1197 }
1198
1199 pub fn until(self, end: Span) -> Span {
1207 match Span::prepare_to_combine(self, end) {
1208 Ok((from, to, parent)) => {
1209 Span::new(cmp::min(from.lo, to.lo), cmp::max(from.lo, to.lo), from.ctxt, parent)
1210 }
1211 Err(fallback) => fallback,
1212 }
1213 }
1214
1215 pub fn within_macro(self, within: Span, sm: &SourceMap) -> Option<Span> {
1230 let (self_, _, parent) = Span::prepare_to_combine(self, within).ok()?;
1231
1232 if self.data().contains(self_) || sm.is_imported(within) {
1239 return None;
1240 }
1241
1242 if within.data().ctxt.outer_expn_data().diagnostic_opaque {
1245 return None;
1246 }
1247
1248 Some(Span::new(self_.lo, self_.hi, self_.ctxt, parent))
1249 }
1250
1251 pub fn from_inner(self, inner: InnerSpan) -> Span {
1252 let span = self.data();
1253 Span::new(
1254 span.lo + BytePos::from_usize(inner.start),
1255 span.lo + BytePos::from_usize(inner.end),
1256 span.ctxt,
1257 span.parent,
1258 )
1259 }
1260
1261 pub fn with_def_site_ctxt(self, expn_id: ExpnId) -> Span {
1264 self.with_ctxt_from_mark(expn_id, Transparency::Opaque)
1265 }
1266
1267 pub fn with_call_site_ctxt(self, expn_id: ExpnId) -> Span {
1270 self.with_ctxt_from_mark(expn_id, Transparency::Transparent)
1271 }
1272
1273 pub fn with_mixed_site_ctxt(self, expn_id: ExpnId) -> Span {
1276 self.with_ctxt_from_mark(expn_id, Transparency::SemiOpaque)
1277 }
1278
1279 fn with_ctxt_from_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
1283 self.with_ctxt(SyntaxContext::root().apply_mark(expn_id, transparency))
1284 }
1285
1286 #[inline]
1287 pub fn apply_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
1288 self.map_ctxt(|ctxt| ctxt.apply_mark(expn_id, transparency))
1289 }
1290
1291 #[inline]
1292 pub fn remove_mark(&mut self) -> ExpnId {
1293 let mut mark = ExpnId::root();
1294 *self = self.map_ctxt(|mut ctxt| {
1295 mark = ctxt.remove_mark();
1296 ctxt
1297 });
1298 mark
1299 }
1300
1301 #[inline]
1302 pub fn adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
1303 let mut mark = None;
1304 *self = self.map_ctxt(|mut ctxt| {
1305 mark = ctxt.adjust(expn_id);
1306 ctxt
1307 });
1308 mark
1309 }
1310
1311 #[inline]
1312 pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
1313 let mut mark = None;
1314 *self = self.map_ctxt(|mut ctxt| {
1315 mark = ctxt.normalize_to_macros_2_0_and_adjust(expn_id);
1316 ctxt
1317 });
1318 mark
1319 }
1320
1321 #[inline]
1322 pub fn normalize_to_macros_2_0(self) -> Span {
1323 self.map_ctxt(|ctxt| ctxt.normalize_to_macros_2_0())
1324 }
1325
1326 #[inline]
1327 pub fn normalize_to_macro_rules(self) -> Span {
1328 self.map_ctxt(|ctxt| ctxt.normalize_to_macro_rules())
1329 }
1330}
1331
1332impl Default for Span {
1333 fn default() -> Self {
1334 DUMMY_SP
1335 }
1336}
1337
1338#[automatically_derived]
impl ::core::marker::Copy for AttrId { }
impl AttrId {
#[doc = r" Maximum value the index can take, as a `u32`."]
pub const MAX_AS_U32: u32 = 0xFFFF_FF00;
#[doc = r" Maximum value the index can take."]
pub const MAX: Self = Self::from_u32(0xFFFF_FF00);
#[doc = r" Zero value of the index."]
pub const ZERO: Self = Self::from_u32(0);
#[doc = r" Creates a new index from a given `usize`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub const fn from_usize(value: usize) -> Self {
if !(value <= (0xFFFF_FF00 as usize)) {
::core::panicking::panic("assertion failed: value <= (0xFFFF_FF00 as usize)")
};
unsafe { Self::from_u32_unchecked(value as u32) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub const fn from_u32(value: u32) -> Self {
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u16`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub const fn from_u16(value: u16) -> Self {
let value = value as u32;
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Safety"]
#[doc = r""]
#[doc =
r" The provided value must be less than or equal to the maximum value for the newtype."]
#[doc =
r" Providing a value outside this range is undefined due to layout restrictions."]
#[doc = r""]
#[doc = r" Prefer using `from_u32`."]
#[inline]
pub const unsafe fn from_u32_unchecked(value: u32) -> Self {
Self {
private_use_as_methods_instead: unsafe {
std::mem::transmute(value)
},
}
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
pub const fn index(self) -> usize { self.as_usize() }
#[doc = r" Extracts the value of this index as a `u32`."]
#[inline]
pub const fn as_u32(self) -> u32 {
unsafe { std::mem::transmute(self.private_use_as_methods_instead) }
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
pub const fn as_usize(self) -> usize { self.as_u32() as usize }
}
impl std::ops::Add<usize> for AttrId {
type Output = Self;
#[inline]
fn add(self, other: usize) -> Self {
Self::from_usize(self.index() + other)
}
}
impl std::ops::AddAssign<usize> for AttrId {
#[inline]
fn add_assign(&mut self, other: usize) { *self = *self + other; }
}
impl rustc_index::Idx for AttrId {
#[inline]
fn new(value: usize) -> Self { Self::from_usize(value) }
#[inline]
fn index(self) -> usize { self.as_usize() }
}
impl ::std::iter::Step for AttrId {
#[inline]
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
<usize as
::std::iter::Step>::steps_between(&Self::index(*start),
&Self::index(*end))
}
#[inline]
fn forward_checked(start: Self, u: usize) -> Option<Self> {
Self::index(start).checked_add(u).map(Self::from_usize)
}
#[inline]
fn backward_checked(start: Self, u: usize) -> Option<Self> {
Self::index(start).checked_sub(u).map(Self::from_usize)
}
#[inline]
fn forward_overflowing(start: Self, u: usize) -> (Self, bool) {
let (s, o) = Self::index(start).overflowing_add(u);
(Self::from_usize(s), o)
}
#[inline]
fn backward_overflowing(start: Self, u: usize) -> (Self, bool) {
let (s, o) = Self::index(start).overflowing_sub(u);
(Self::from_usize(s), o)
}
}
impl ::std::cmp::Ord for AttrId {
#[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.as_u32().cmp(&other.as_u32())
}
}
impl ::std::cmp::PartialOrd for AttrId {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl From<AttrId> for u32 {
#[inline]
fn from(v: AttrId) -> u32 { v.as_u32() }
}
impl From<AttrId> for usize {
#[inline]
fn from(v: AttrId) -> usize { v.as_usize() }
}
impl From<usize> for AttrId {
#[inline]
fn from(value: usize) -> Self { Self::from_usize(value) }
}
impl From<u32> for AttrId {
#[inline]
fn from(value: u32) -> Self { Self::from_u32(value) }
}
impl ::std::cmp::Eq for AttrId {}
impl ::std::cmp::PartialEq for AttrId {
fn eq(&self, other: &Self) -> bool { self.as_u32().eq(&other.as_u32()) }
}
impl ::std::marker::StructuralPartialEq for AttrId {}
impl ::std::hash::Hash for AttrId {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.as_u32().hash(state)
}
}
impl ::std::fmt::Debug for AttrId {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_fmt(format_args!("AttrId({0})", self.as_u32()))
}
}rustc_index::newtype_index! {
1339 #[orderable]
1340 #[debug_format = "AttrId({})"]
1341 pub struct AttrId {}
1342}
1343
1344pub trait SpanEncoder: Encoder {
1347 fn encode_span(&mut self, span: Span);
1348 fn encode_symbol(&mut self, sym: Symbol);
1349 fn encode_byte_symbol(&mut self, byte_sym: ByteSymbol);
1350 fn encode_expn_id(&mut self, expn_id: ExpnId);
1351 fn encode_syntax_context(&mut self, syntax_context: SyntaxContext);
1352 fn encode_crate_num(&mut self, crate_num: CrateNum);
1355 fn encode_def_index(&mut self, def_index: DefIndex);
1356 fn encode_def_id(&mut self, def_id: DefId);
1357
1358 fn encode_local_def_id(&mut self, def_id: LocalDefId) {
1359 self.encode_def_id(def_id.to_def_id());
1360 }
1361
1362 fn encode_def_key(&mut self, parent: Option<DefIndex>, disambiguated_data: impl Encodable<Self>)
1365 where
1366 Self: Sized,
1367 {
1368 parent.encode(self);
1369 disambiguated_data.encode(self);
1370 }
1371}
1372
1373impl SpanEncoder for FileEncoder<'_> {
1374 fn encode_span(&mut self, span: Span) {
1375 let span = span.data();
1376 span.lo.encode(self);
1377 span.hi.encode(self);
1378 }
1379
1380 fn encode_symbol(&mut self, sym: Symbol) {
1381 self.emit_str(sym.as_str());
1382 }
1383
1384 fn encode_byte_symbol(&mut self, byte_sym: ByteSymbol) {
1385 self.emit_byte_str(byte_sym.as_byte_str());
1386 }
1387
1388 fn encode_expn_id(&mut self, _expn_id: ExpnId) {
1389 {
::core::panicking::panic_fmt(format_args!("cannot encode `ExpnId` with `FileEncoder`"));
};panic!("cannot encode `ExpnId` with `FileEncoder`");
1390 }
1391
1392 fn encode_syntax_context(&mut self, _syntax_context: SyntaxContext) {
1393 {
::core::panicking::panic_fmt(format_args!("cannot encode `SyntaxContext` with `FileEncoder`"));
};panic!("cannot encode `SyntaxContext` with `FileEncoder`");
1394 }
1395
1396 fn encode_crate_num(&mut self, crate_num: CrateNum) {
1397 self.emit_u32(crate_num.as_u32());
1398 }
1399
1400 fn encode_def_index(&mut self, _def_index: DefIndex) {
1401 {
::core::panicking::panic_fmt(format_args!("cannot encode `DefIndex` with `FileEncoder`"));
};panic!("cannot encode `DefIndex` with `FileEncoder`");
1402 }
1403
1404 fn encode_def_id(&mut self, def_id: DefId) {
1405 def_id.krate.encode(self);
1406 def_id.index.encode(self);
1407 }
1408}
1409
1410impl SpanEncoder for MemEncoder {
1411 fn encode_span(&mut self, span: Span) {
1412 let span = span.data();
1413 span.lo.encode(self);
1414 span.hi.encode(self);
1415 }
1416
1417 fn encode_symbol(&mut self, sym: Symbol) {
1418 self.emit_str(sym.as_str());
1419 }
1420
1421 fn encode_byte_symbol(&mut self, byte_sym: ByteSymbol) {
1422 self.emit_byte_str(byte_sym.as_byte_str());
1423 }
1424
1425 fn encode_expn_id(&mut self, _expn_id: ExpnId) {
1426 {
::core::panicking::panic_fmt(format_args!("cannot encode `ExpnId` with `MemEncoder`"));
};panic!("cannot encode `ExpnId` with `MemEncoder`");
1427 }
1428
1429 fn encode_syntax_context(&mut self, _syntax_context: SyntaxContext) {
1430 {
::core::panicking::panic_fmt(format_args!("cannot encode `SyntaxContext` with `MemEncoder`"));
};panic!("cannot encode `SyntaxContext` with `MemEncoder`");
1431 }
1432
1433 fn encode_crate_num(&mut self, crate_num: CrateNum) {
1434 self.emit_u32(crate_num.as_u32());
1435 }
1436
1437 fn encode_def_index(&mut self, _def_index: DefIndex) {
1438 {
::core::panicking::panic_fmt(format_args!("cannot encode `DefIndex` with `MemEncoder`"));
};panic!("cannot encode `DefIndex` with `MemEncoder`");
1439 }
1440
1441 fn encode_def_id(&mut self, def_id: DefId) {
1442 def_id.krate.encode(self);
1443 def_id.index.encode(self);
1444 }
1445}
1446
1447impl<E: SpanEncoder> Encodable<E> for Span {
1448 fn encode(&self, s: &mut E) {
1449 s.encode_span(*self);
1450 }
1451}
1452
1453impl<E: SpanEncoder> Encodable<E> for Symbol {
1454 fn encode(&self, s: &mut E) {
1455 s.encode_symbol(*self);
1456 }
1457}
1458
1459impl<E: SpanEncoder> Encodable<E> for ByteSymbol {
1460 fn encode(&self, s: &mut E) {
1461 s.encode_byte_symbol(*self);
1462 }
1463}
1464
1465impl<E: SpanEncoder> Encodable<E> for ExpnId {
1466 fn encode(&self, s: &mut E) {
1467 s.encode_expn_id(*self)
1468 }
1469}
1470
1471impl<E: SpanEncoder> Encodable<E> for SyntaxContext {
1472 fn encode(&self, s: &mut E) {
1473 s.encode_syntax_context(*self)
1474 }
1475}
1476
1477impl<E: SpanEncoder> Encodable<E> for CrateNum {
1478 fn encode(&self, s: &mut E) {
1479 s.encode_crate_num(*self)
1480 }
1481}
1482
1483impl<E: SpanEncoder> Encodable<E> for DefIndex {
1484 fn encode(&self, s: &mut E) {
1485 s.encode_def_index(*self)
1486 }
1487}
1488
1489impl<E: SpanEncoder> Encodable<E> for DefId {
1490 fn encode(&self, s: &mut E) {
1491 s.encode_def_id(*self)
1492 }
1493}
1494
1495impl<E: SpanEncoder> Encodable<E> for AttrId {
1496 fn encode(&self, _s: &mut E) {
1497 }
1499}
1500
1501pub trait BlobDecoder: Decoder {
1502 fn decode_symbol(&mut self) -> Symbol;
1503 fn decode_byte_symbol(&mut self) -> ByteSymbol;
1504 fn decode_def_index(&mut self) -> DefIndex;
1505
1506 fn decode_local_def_id(&mut self) -> LocalDefId;
1511}
1512
1513pub trait SpanDecoder: BlobDecoder {
1530 fn decode_span(&mut self) -> Span;
1531 fn decode_expn_id(&mut self) -> ExpnId;
1532 fn decode_syntax_context(&mut self) -> SyntaxContext;
1533 fn decode_crate_num(&mut self) -> CrateNum;
1534 fn decode_def_id(&mut self) -> DefId;
1535 fn decode_attr_id(&mut self) -> AttrId;
1536}
1537
1538impl BlobDecoder for MemDecoder<'_> {
1539 fn decode_symbol(&mut self) -> Symbol {
1540 Symbol::intern(self.read_str())
1541 }
1542
1543 fn decode_byte_symbol(&mut self) -> ByteSymbol {
1544 ByteSymbol::intern(self.read_byte_str())
1545 }
1546
1547 fn decode_def_index(&mut self) -> DefIndex {
1548 {
::core::panicking::panic_fmt(format_args!("cannot decode `DefIndex` with `MemDecoder`"));
};panic!("cannot decode `DefIndex` with `MemDecoder`");
1549 }
1550
1551 fn decode_local_def_id(&mut self) -> LocalDefId {
1552 self.decode_def_id().expect_local()
1553 }
1554}
1555
1556impl SpanDecoder for MemDecoder<'_> {
1557 fn decode_span(&mut self) -> Span {
1558 let lo = Decodable::decode(self);
1559 let hi = Decodable::decode(self);
1560
1561 Span::new(lo, hi, SyntaxContext::root(), None)
1562 }
1563
1564 fn decode_expn_id(&mut self) -> ExpnId {
1565 {
::core::panicking::panic_fmt(format_args!("cannot decode `ExpnId` with `MemDecoder`"));
};panic!("cannot decode `ExpnId` with `MemDecoder`");
1566 }
1567
1568 fn decode_syntax_context(&mut self) -> SyntaxContext {
1569 {
::core::panicking::panic_fmt(format_args!("cannot decode `SyntaxContext` with `MemDecoder`"));
};panic!("cannot decode `SyntaxContext` with `MemDecoder`");
1570 }
1571
1572 fn decode_crate_num(&mut self) -> CrateNum {
1573 CrateNum::from_u32(self.read_u32())
1574 }
1575
1576 fn decode_def_id(&mut self) -> DefId {
1577 DefId { krate: Decodable::decode(self), index: Decodable::decode(self) }
1578 }
1579
1580 fn decode_attr_id(&mut self) -> AttrId {
1581 {
::core::panicking::panic_fmt(format_args!("cannot decode `AttrId` with `MemDecoder`"));
};panic!("cannot decode `AttrId` with `MemDecoder`");
1582 }
1583}
1584
1585impl<D: SpanDecoder> Decodable<D> for Span {
1586 fn decode(s: &mut D) -> Span {
1587 s.decode_span()
1588 }
1589}
1590
1591impl<D: BlobDecoder> Decodable<D> for Symbol {
1592 fn decode(s: &mut D) -> Symbol {
1593 s.decode_symbol()
1594 }
1595}
1596
1597impl<D: BlobDecoder> Decodable<D> for ByteSymbol {
1598 fn decode(s: &mut D) -> ByteSymbol {
1599 s.decode_byte_symbol()
1600 }
1601}
1602
1603impl<D: SpanDecoder> Decodable<D> for ExpnId {
1604 fn decode(s: &mut D) -> ExpnId {
1605 s.decode_expn_id()
1606 }
1607}
1608
1609impl<D: SpanDecoder> Decodable<D> for SyntaxContext {
1610 fn decode(s: &mut D) -> SyntaxContext {
1611 s.decode_syntax_context()
1612 }
1613}
1614
1615impl<D: SpanDecoder> Decodable<D> for CrateNum {
1616 fn decode(s: &mut D) -> CrateNum {
1617 s.decode_crate_num()
1618 }
1619}
1620
1621impl<D: BlobDecoder> Decodable<D> for DefIndex {
1622 fn decode(s: &mut D) -> DefIndex {
1623 s.decode_def_index()
1624 }
1625}
1626
1627impl<D: SpanDecoder> Decodable<D> for DefId {
1628 fn decode(s: &mut D) -> DefId {
1629 s.decode_def_id()
1630 }
1631}
1632
1633impl<D: SpanDecoder> Decodable<D> for AttrId {
1634 fn decode(s: &mut D) -> AttrId {
1635 s.decode_attr_id()
1636 }
1637}
1638
1639impl fmt::Debug for Span {
1640 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1641 fn fallback(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1645 f.debug_struct("Span")
1646 .field("lo", &span.lo())
1647 .field("hi", &span.hi())
1648 .field("ctxt", &span.ctxt())
1649 .finish()
1650 }
1651
1652 if SESSION_GLOBALS.is_set() {
1653 with_session_globals(|session_globals| {
1654 if let Some(source_map) = &session_globals.source_map {
1655 f.write_fmt(format_args!("{0} ({1:?})",
source_map.span_to_diagnostic_string(*self), self.ctxt()))write!(f, "{} ({:?})", source_map.span_to_diagnostic_string(*self), self.ctxt())
1656 } else {
1657 fallback(*self, f)
1658 }
1659 })
1660 } else {
1661 fallback(*self, f)
1662 }
1663 }
1664}
1665
1666impl fmt::Debug for SpanData {
1667 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1668 fmt::Debug::fmt(&self.span(), f)
1669 }
1670}
1671
1672#[derive(#[automatically_derived]
impl ::core::marker::Copy for MultiByteChar { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for MultiByteChar { }
#[automatically_derived]
impl ::core::clone::Clone for MultiByteChar {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<RelativeBytePos>;
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}Clone, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for MultiByteChar {
fn encode(&self, __encoder: &mut __E) {
let MultiByteChar {
pos: ref __binding_0, bytes: ref __binding_1 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for MultiByteChar {
fn decode(__decoder: &mut __D) -> Self {
MultiByteChar {
pos: ::rustc_serialize::Decodable::decode(__decoder),
bytes: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable, #[automatically_derived]
impl ::core::cmp::Eq for MultiByteChar {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<RelativeBytePos>;
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for MultiByteChar { }
#[automatically_derived]
impl ::core::cmp::PartialEq for MultiByteChar {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.bytes == other.bytes && self.pos == other.pos
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for MultiByteChar {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "MultiByteChar",
"pos", &self.pos, "bytes", &&self.bytes)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
MultiByteChar {
#[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 {
MultiByteChar { pos: ref __binding_0, bytes: ref __binding_1
} => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
1674pub struct MultiByteChar {
1675 pub pos: RelativeBytePos,
1677 pub bytes: u8,
1679}
1680
1681#[derive(#[automatically_derived]
impl ::core::marker::Copy for NormalizedPos { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for NormalizedPos { }
#[automatically_derived]
impl ::core::clone::Clone for NormalizedPos {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<RelativeBytePos>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for NormalizedPos {
fn encode(&self, __encoder: &mut __E) {
let NormalizedPos {
pos: ref __binding_0, diff: ref __binding_1 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for NormalizedPos {
fn decode(__decoder: &mut __D) -> Self {
NormalizedPos {
pos: ::rustc_serialize::Decodable::decode(__decoder),
diff: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable, #[automatically_derived]
impl ::core::cmp::Eq for NormalizedPos {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<RelativeBytePos>;
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for NormalizedPos { }
#[automatically_derived]
impl ::core::cmp::PartialEq for NormalizedPos {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.diff == other.diff && self.pos == other.pos
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for NormalizedPos {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "NormalizedPos",
"pos", &self.pos, "diff", &&self.diff)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
NormalizedPos {
#[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 {
NormalizedPos { pos: ref __binding_0, diff: ref __binding_1
} => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
1683pub struct NormalizedPos {
1684 pub pos: RelativeBytePos,
1686 pub diff: u32,
1688}
1689
1690#[derive(#[automatically_derived]
impl ::core::marker::StructuralPartialEq for ExternalSource { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ExternalSource {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Foreign { kind: __self_0, metadata_index: __self_1 },
Self::Foreign { kind: __arg1_0, metadata_index: __arg1_1 })
=> __self_1 == __arg1_1 && __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ExternalSource {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ExternalSourceKind>;
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}Eq, #[automatically_derived]
impl ::core::clone::Clone for ExternalSource {
#[inline]
fn clone(&self) -> Self {
match self {
Self::Unneeded => ExternalSource::Unneeded,
Self::Foreign { kind: __self_0, metadata_index: __self_1 } =>
ExternalSource::Foreign {
kind: ::core::clone::Clone::clone(__self_0),
metadata_index: ::core::clone::Clone::clone(__self_1),
},
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ExternalSource {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Unneeded =>
::core::fmt::Formatter::write_str(f, "Unneeded"),
Self::Foreign { kind: __self_0, metadata_index: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Foreign", "kind", __self_0, "metadata_index", &__self_1),
}
}
}Debug)]
1691pub enum ExternalSource {
1692 Unneeded,
1694 Foreign {
1695 kind: ExternalSourceKind,
1696 metadata_index: u32,
1698 },
1699}
1700
1701#[derive(#[automatically_derived]
impl ::core::marker::StructuralPartialEq for ExternalSourceKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ExternalSourceKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Present(__self_0), Self::Present(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ExternalSourceKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Arc<String>>;
}
}Eq, #[automatically_derived]
impl ::core::clone::Clone for ExternalSourceKind {
#[inline]
fn clone(&self) -> Self {
match self {
Self::Present(__self_0) =>
ExternalSourceKind::Present(::core::clone::Clone::clone(__self_0)),
Self::AbsentOk => ExternalSourceKind::AbsentOk,
Self::AbsentErr => ExternalSourceKind::AbsentErr,
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ExternalSourceKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Present(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Present", &__self_0),
Self::AbsentOk =>
::core::fmt::Formatter::write_str(f, "AbsentOk"),
Self::AbsentErr =>
::core::fmt::Formatter::write_str(f, "AbsentErr"),
}
}
}Debug)]
1703pub enum ExternalSourceKind {
1704 Present(Arc<String>),
1706 AbsentOk,
1708 AbsentErr,
1710}
1711
1712impl ExternalSource {
1713 pub fn get_source(&self) -> Option<&str> {
1714 match self {
1715 ExternalSource::Foreign { kind: ExternalSourceKind::Present(src), .. } => Some(src),
1716 _ => None,
1717 }
1718 }
1719}
1720
1721#[derive(#[automatically_derived]
impl ::core::fmt::Debug for OffsetOverflowError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "OffsetOverflowError")
}
}Debug)]
1722pub struct OffsetOverflowError;
1723
1724#[derive(#[automatically_derived]
impl ::core::marker::Copy for SourceFileHashAlgorithm { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for SourceFileHashAlgorithm { }
#[automatically_derived]
impl ::core::clone::Clone for SourceFileHashAlgorithm {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for SourceFileHashAlgorithm {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
SourceFileHashAlgorithm::Md5 => "Md5",
SourceFileHashAlgorithm::Sha1 => "Sha1",
SourceFileHashAlgorithm::Sha256 => "Sha256",
SourceFileHashAlgorithm::Blake3 => "Blake3",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for SourceFileHashAlgorithm { }
#[automatically_derived]
impl ::core::cmp::PartialEq for SourceFileHashAlgorithm {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for SourceFileHashAlgorithm { }Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for SourceFileHashAlgorithm {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for SourceFileHashAlgorithm {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other))
}
}Ord, #[automatically_derived]
impl ::core::hash::Hash for SourceFileHashAlgorithm {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for SourceFileHashAlgorithm {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
SourceFileHashAlgorithm::Md5 => { 0usize }
SourceFileHashAlgorithm::Sha1 => { 1usize }
SourceFileHashAlgorithm::Sha256 => { 2usize }
SourceFileHashAlgorithm::Blake3 => { 3usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for SourceFileHashAlgorithm {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { SourceFileHashAlgorithm::Md5 }
1usize => { SourceFileHashAlgorithm::Sha1 }
2usize => { SourceFileHashAlgorithm::Sha256 }
3usize => { SourceFileHashAlgorithm::Blake3 }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `SourceFileHashAlgorithm`, expected 0..4, actual {0}",
n));
}
}
}
}
};Decodable)]
1725#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
SourceFileHashAlgorithm {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
SourceFileHashAlgorithm::Md5 => {}
SourceFileHashAlgorithm::Sha1 => {}
SourceFileHashAlgorithm::Sha256 => {}
SourceFileHashAlgorithm::Blake3 => {}
}
}
}
};StableHash)]
1726pub enum SourceFileHashAlgorithm {
1727 Md5,
1728 Sha1,
1729 Sha256,
1730 Blake3,
1731}
1732
1733impl Display for SourceFileHashAlgorithm {
1734 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1735 f.write_str(match self {
1736 Self::Md5 => "md5",
1737 Self::Sha1 => "sha1",
1738 Self::Sha256 => "sha256",
1739 Self::Blake3 => "blake3",
1740 })
1741 }
1742}
1743
1744impl FromStr for SourceFileHashAlgorithm {
1745 type Err = ();
1746
1747 fn from_str(s: &str) -> Result<SourceFileHashAlgorithm, ()> {
1748 match s {
1749 "md5" => Ok(SourceFileHashAlgorithm::Md5),
1750 "sha1" => Ok(SourceFileHashAlgorithm::Sha1),
1751 "sha256" => Ok(SourceFileHashAlgorithm::Sha256),
1752 "blake3" => Ok(SourceFileHashAlgorithm::Blake3),
1753 _ => Err(()),
1754 }
1755 }
1756}
1757
1758#[derive(#[automatically_derived]
impl ::core::marker::Copy for SourceFileHash { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for SourceFileHash { }
#[automatically_derived]
impl ::core::clone::Clone for SourceFileHash {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<SourceFileHashAlgorithm>;
let _: ::core::clone::AssertParamIsClone<[u8; 32]>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for SourceFileHash { }
#[automatically_derived]
impl ::core::cmp::PartialEq for SourceFileHash {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.kind == other.kind && self.value == other.value
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for SourceFileHash {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<SourceFileHashAlgorithm>;
let _: ::core::cmp::AssertParamIsEq<[u8; 32]>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for SourceFileHash {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"SourceFileHash", "kind", &self.kind, "value", &&self.value)
}
}Debug, #[automatically_derived]
impl ::core::hash::Hash for SourceFileHash {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.kind, state);
::core::hash::Hash::hash(&self.value, state)
}
}Hash)]
1760#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
SourceFileHash {
#[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 {
SourceFileHash {
kind: ref __binding_0, value: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for SourceFileHash {
fn encode(&self, __encoder: &mut __E) {
let SourceFileHash {
kind: ref __binding_0, value: ref __binding_1 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for SourceFileHash {
fn decode(__decoder: &mut __D) -> Self {
SourceFileHash {
kind: ::rustc_serialize::Decodable::decode(__decoder),
value: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
1761pub struct SourceFileHash {
1762 pub kind: SourceFileHashAlgorithm,
1763 value: [u8; 32],
1764}
1765
1766impl Display for SourceFileHash {
1767 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1768 f.write_fmt(format_args!("{0}=", self.kind))write!(f, "{}=", self.kind)?;
1769 for byte in self.value[0..self.hash_len()].into_iter() {
1770 f.write_fmt(format_args!("{0:02x}", byte))write!(f, "{byte:02x}")?;
1771 }
1772 Ok(())
1773 }
1774}
1775
1776impl SourceFileHash {
1777 pub fn new_in_memory(kind: SourceFileHashAlgorithm, src: impl AsRef<[u8]>) -> SourceFileHash {
1778 let mut hash = SourceFileHash { kind, value: Default::default() };
1779 let len = hash.hash_len();
1780 let value = &mut hash.value[..len];
1781 let data = src.as_ref();
1782 match kind {
1783 SourceFileHashAlgorithm::Md5 => {
1784 value.copy_from_slice(&Md5::digest(data));
1785 }
1786 SourceFileHashAlgorithm::Sha1 => {
1787 value.copy_from_slice(&Sha1::digest(data));
1788 }
1789 SourceFileHashAlgorithm::Sha256 => {
1790 value.copy_from_slice(&Sha256::digest(data));
1791 }
1792 SourceFileHashAlgorithm::Blake3 => value.copy_from_slice(blake3::hash(data).as_bytes()),
1793 };
1794 hash
1795 }
1796
1797 pub fn new(kind: SourceFileHashAlgorithm, src: impl Read) -> Result<SourceFileHash, io::Error> {
1798 let mut hash = SourceFileHash { kind, value: Default::default() };
1799 let len = hash.hash_len();
1800 let value = &mut hash.value[..len];
1801 let mut buf = ::alloc::vec::from_elem(0, 16 * 1024)vec![0; 16 * 1024];
1804
1805 fn digest<T>(
1806 mut hasher: T,
1807 mut update: impl FnMut(&mut T, &[u8]),
1808 finish: impl FnOnce(T, &mut [u8]),
1809 mut src: impl Read,
1810 buf: &mut [u8],
1811 value: &mut [u8],
1812 ) -> Result<(), io::Error> {
1813 loop {
1814 let bytes_read = src.read(buf)?;
1815 if bytes_read == 0 {
1816 break;
1817 }
1818 update(&mut hasher, &buf[0..bytes_read]);
1819 }
1820 finish(hasher, value);
1821 Ok(())
1822 }
1823
1824 match kind {
1825 SourceFileHashAlgorithm::Sha256 => {
1826 digest(
1827 Sha256::new(),
1828 |h, b| {
1829 h.update(b);
1830 },
1831 |h, out| out.copy_from_slice(&h.finalize()),
1832 src,
1833 &mut buf,
1834 value,
1835 )?;
1836 }
1837 SourceFileHashAlgorithm::Sha1 => {
1838 digest(
1839 Sha1::new(),
1840 |h, b| {
1841 h.update(b);
1842 },
1843 |h, out| out.copy_from_slice(&h.finalize()),
1844 src,
1845 &mut buf,
1846 value,
1847 )?;
1848 }
1849 SourceFileHashAlgorithm::Md5 => {
1850 digest(
1851 Md5::new(),
1852 |h, b| {
1853 h.update(b);
1854 },
1855 |h, out| out.copy_from_slice(&h.finalize()),
1856 src,
1857 &mut buf,
1858 value,
1859 )?;
1860 }
1861 SourceFileHashAlgorithm::Blake3 => {
1862 digest(
1863 blake3::Hasher::new(),
1864 |h, b| {
1865 h.update(b);
1866 },
1867 |h, out| out.copy_from_slice(h.finalize().as_bytes()),
1868 src,
1869 &mut buf,
1870 value,
1871 )?;
1872 }
1873 }
1874 Ok(hash)
1875 }
1876
1877 pub fn matches(&self, src: &str) -> bool {
1879 Self::new_in_memory(self.kind, src.as_bytes()) == *self
1880 }
1881
1882 pub fn hash_bytes(&self) -> &[u8] {
1884 let len = self.hash_len();
1885 &self.value[..len]
1886 }
1887
1888 fn hash_len(&self) -> usize {
1889 match self.kind {
1890 SourceFileHashAlgorithm::Md5 => 16,
1891 SourceFileHashAlgorithm::Sha1 => 20,
1892 SourceFileHashAlgorithm::Sha256 | SourceFileHashAlgorithm::Blake3 => 32,
1893 }
1894 }
1895}
1896
1897#[derive(#[automatically_derived]
impl ::core::clone::Clone for SourceFileLines {
#[inline]
fn clone(&self) -> Self {
match self {
Self::Lines(__self_0) =>
SourceFileLines::Lines(::core::clone::Clone::clone(__self_0)),
Self::Diffs(__self_0) =>
SourceFileLines::Diffs(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
1898pub enum SourceFileLines {
1899 Lines(Vec<RelativeBytePos>),
1901
1902 Diffs(SourceFileDiffs),
1904}
1905
1906impl SourceFileLines {
1907 pub fn is_lines(&self) -> bool {
1908 #[allow(non_exhaustive_omitted_patterns)] match self {
SourceFileLines::Lines(_) => true,
_ => false,
}matches!(self, SourceFileLines::Lines(_))
1909 }
1910}
1911
1912#[derive(#[automatically_derived]
impl ::core::clone::Clone for SourceFileDiffs {
#[inline]
fn clone(&self) -> Self {
SourceFileDiffs {
bytes_per_diff: ::core::clone::Clone::clone(&self.bytes_per_diff),
num_diffs: ::core::clone::Clone::clone(&self.num_diffs),
raw_diffs: ::core::clone::Clone::clone(&self.raw_diffs),
}
}
}Clone)]
1920pub struct SourceFileDiffs {
1921 bytes_per_diff: usize,
1925
1926 num_diffs: usize,
1929
1930 raw_diffs: Vec<u8>,
1936}
1937
1938pub struct SourceFile {
1940 pub name: FileName,
1944 pub src: Option<Arc<String>>,
1946 pub src_hash: SourceFileHash,
1948 pub checksum_hash: Option<SourceFileHash>,
1952 pub external_src: FreezeLock<ExternalSource>,
1955 pub start_pos: BytePos,
1957 pub normalized_source_len: RelativeBytePos,
1959 pub unnormalized_source_len: u32,
1961 pub lines: FreezeLock<SourceFileLines>,
1963 pub multibyte_chars: Vec<MultiByteChar>,
1965 pub normalized_pos: Vec<NormalizedPos>,
1967 pub stable_id: StableSourceFileId,
1971 pub cnum: CrateNum,
1973}
1974
1975impl Clone for SourceFile {
1976 fn clone(&self) -> Self {
1977 Self {
1978 name: self.name.clone(),
1979 src: self.src.clone(),
1980 src_hash: self.src_hash,
1981 checksum_hash: self.checksum_hash,
1982 external_src: self.external_src.clone(),
1983 start_pos: self.start_pos,
1984 normalized_source_len: self.normalized_source_len,
1985 unnormalized_source_len: self.unnormalized_source_len,
1986 lines: self.lines.clone(),
1987 multibyte_chars: self.multibyte_chars.clone(),
1988 normalized_pos: self.normalized_pos.clone(),
1989 stable_id: self.stable_id,
1990 cnum: self.cnum,
1991 }
1992 }
1993}
1994
1995impl<S: SpanEncoder> Encodable<S> for SourceFile {
1996 fn encode(&self, s: &mut S) {
1997 self.name.encode(s);
1998 self.src_hash.encode(s);
1999 self.checksum_hash.encode(s);
2000 self.normalized_source_len.encode(s);
2002 self.unnormalized_source_len.encode(s);
2003
2004 if !self.lines.read().is_lines() {
::core::panicking::panic("assertion failed: self.lines.read().is_lines()")
};assert!(self.lines.read().is_lines());
2006 let lines = self.lines();
2007 s.emit_u32(lines.len() as u32);
2009
2010 if lines.len() != 0 {
2012 let max_line_length = if lines.len() == 1 {
2013 0
2014 } else {
2015 lines
2016 .array_windows()
2017 .map(|&[fst, snd]| snd - fst)
2018 .map(|bp| bp.to_usize())
2019 .max()
2020 .unwrap()
2021 };
2022
2023 let bytes_per_diff: usize = match max_line_length {
2024 0..=0xFF => 1,
2025 0x100..=0xFFFF => 2,
2026 _ => 4,
2027 };
2028
2029 s.emit_u8(bytes_per_diff as u8);
2031
2032 {
match (&lines[0], &RelativeBytePos(0)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(lines[0], RelativeBytePos(0));
2034
2035 let diff_iter = lines.array_windows().map(|&[fst, snd]| snd - fst);
2037 let num_diffs = lines.len() - 1;
2038 let mut raw_diffs;
2039 match bytes_per_diff {
2040 1 => {
2041 raw_diffs = Vec::with_capacity(num_diffs);
2042 for diff in diff_iter {
2043 raw_diffs.push(diff.0 as u8);
2044 }
2045 }
2046 2 => {
2047 raw_diffs = Vec::with_capacity(bytes_per_diff * num_diffs);
2048 for diff in diff_iter {
2049 raw_diffs.extend_from_slice(&(diff.0 as u16).to_le_bytes());
2050 }
2051 }
2052 4 => {
2053 raw_diffs = Vec::with_capacity(bytes_per_diff * num_diffs);
2054 for diff in diff_iter {
2055 raw_diffs.extend_from_slice(&(diff.0).to_le_bytes());
2056 }
2057 }
2058 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
2059 }
2060 s.emit_raw_bytes(&raw_diffs);
2061 }
2062
2063 self.multibyte_chars.encode(s);
2064 self.stable_id.encode(s);
2065 self.normalized_pos.encode(s);
2066 self.cnum.encode(s);
2067 }
2068}
2069
2070impl<D: SpanDecoder> Decodable<D> for SourceFile {
2071 fn decode(d: &mut D) -> SourceFile {
2072 let name: FileName = Decodable::decode(d);
2073 let src_hash: SourceFileHash = Decodable::decode(d);
2074 let checksum_hash: Option<SourceFileHash> = Decodable::decode(d);
2075 let normalized_source_len: RelativeBytePos = Decodable::decode(d);
2076 let unnormalized_source_len = Decodable::decode(d);
2077 let lines = {
2078 let num_lines: u32 = Decodable::decode(d);
2079 if num_lines > 0 {
2080 let bytes_per_diff = d.read_u8() as usize;
2082
2083 let num_diffs = num_lines as usize - 1;
2085 let raw_diffs = d.read_raw_bytes(bytes_per_diff * num_diffs).to_vec();
2086 SourceFileLines::Diffs(SourceFileDiffs { bytes_per_diff, num_diffs, raw_diffs })
2087 } else {
2088 SourceFileLines::Lines(::alloc::vec::Vec::new()vec![])
2089 }
2090 };
2091 let multibyte_chars: Vec<MultiByteChar> = Decodable::decode(d);
2092 let stable_id = Decodable::decode(d);
2093 let normalized_pos: Vec<NormalizedPos> = Decodable::decode(d);
2094 let cnum: CrateNum = Decodable::decode(d);
2095 SourceFile {
2096 name,
2097 start_pos: BytePos::from_u32(0),
2098 normalized_source_len,
2099 unnormalized_source_len,
2100 src: None,
2101 src_hash,
2102 checksum_hash,
2103 external_src: FreezeLock::frozen(ExternalSource::Unneeded),
2106 lines: FreezeLock::new(lines),
2107 multibyte_chars,
2108 normalized_pos,
2109 stable_id,
2110 cnum,
2111 }
2112 }
2113}
2114
2115impl fmt::Debug for SourceFile {
2116 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2117 fmt.write_fmt(format_args!("SourceFile({0:?})", self.name))write!(fmt, "SourceFile({:?})", self.name)
2118 }
2119}
2120
2121#[derive(#[automatically_derived]
impl ::core::fmt::Debug for StableSourceFileId {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"StableSourceFileId", &&self.0)
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for StableSourceFileId { }
#[automatically_derived]
impl ::core::clone::Clone for StableSourceFileId {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Hash128>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for StableSourceFileId { }Copy, #[automatically_derived]
impl ::core::hash::Hash for StableSourceFileId {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for StableSourceFileId { }
#[automatically_derived]
impl ::core::cmp::PartialEq for StableSourceFileId {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for StableSourceFileId {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Hash128>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for StableSourceFileId {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::default::Default for StableSourceFileId {
#[inline]
fn default() -> Self {
StableSourceFileId(::core::default::Default::default())
}
}Default, #[automatically_derived]
impl ::core::cmp::Ord for StableSourceFileId {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord)]
2143#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
StableSourceFileId {
#[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 {
StableSourceFileId(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for StableSourceFileId {
fn encode(&self, __encoder: &mut __E) {
let StableSourceFileId(ref __binding_0) = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for StableSourceFileId {
fn decode(__decoder: &mut __D) -> Self {
StableSourceFileId(::rustc_serialize::Decodable::decode(__decoder))
}
}
};Decodable)]
2144pub struct StableSourceFileId(Hash128);
2145
2146impl StableSourceFileId {
2147 fn from_filename_in_current_crate(filename: &FileName) -> Self {
2148 Self::from_filename_and_stable_crate_id(filename, None)
2149 }
2150
2151 pub fn from_filename_for_export(
2152 filename: &FileName,
2153 local_crate_stable_crate_id: StableCrateId,
2154 ) -> Self {
2155 Self::from_filename_and_stable_crate_id(filename, Some(local_crate_stable_crate_id))
2156 }
2157
2158 fn from_filename_and_stable_crate_id(
2159 filename: &FileName,
2160 stable_crate_id: Option<StableCrateId>,
2161 ) -> Self {
2162 let mut hasher = StableHasher::new();
2163 filename.hash(&mut hasher);
2164 stable_crate_id.hash(&mut hasher);
2165 StableSourceFileId(hasher.finish())
2166 }
2167}
2168
2169impl SourceFile {
2170 const MAX_FILE_SIZE: u32 = u32::MAX - 1;
2171
2172 pub fn new(
2173 name: FileName,
2174 mut src: String,
2175 hash_kind: SourceFileHashAlgorithm,
2176 checksum_hash_kind: Option<SourceFileHashAlgorithm>,
2177 ) -> Result<Self, OffsetOverflowError> {
2178 let src_hash = SourceFileHash::new_in_memory(hash_kind, src.as_bytes());
2180 let checksum_hash = checksum_hash_kind.map(|checksum_hash_kind| {
2181 if checksum_hash_kind == hash_kind {
2182 src_hash
2183 } else {
2184 SourceFileHash::new_in_memory(checksum_hash_kind, src.as_bytes())
2185 }
2186 });
2187 let unnormalized_source_len = u32::try_from(src.len()).map_err(|_| OffsetOverflowError)?;
2189 if unnormalized_source_len > Self::MAX_FILE_SIZE {
2190 return Err(OffsetOverflowError);
2191 }
2192
2193 let normalized_pos = normalize_src(&mut src);
2194
2195 let stable_id = StableSourceFileId::from_filename_in_current_crate(&name);
2196 let normalized_source_len = u32::try_from(src.len()).map_err(|_| OffsetOverflowError)?;
2197 if normalized_source_len > Self::MAX_FILE_SIZE {
2198 return Err(OffsetOverflowError);
2199 }
2200
2201 let (lines, multibyte_chars) = analyze_source_file::analyze_source_file(&src);
2202
2203 Ok(SourceFile {
2204 name,
2205 src: Some(Arc::new(src)),
2206 src_hash,
2207 checksum_hash,
2208 external_src: FreezeLock::frozen(ExternalSource::Unneeded),
2209 start_pos: BytePos::from_u32(0),
2210 normalized_source_len: RelativeBytePos::from_u32(normalized_source_len),
2211 unnormalized_source_len,
2212 lines: FreezeLock::frozen(SourceFileLines::Lines(lines)),
2213 multibyte_chars,
2214 normalized_pos,
2215 stable_id,
2216 cnum: LOCAL_CRATE,
2217 })
2218 }
2219
2220 fn convert_diffs_to_lines_frozen(&self) {
2223 let mut guard = if let Some(guard) = self.lines.try_write() { guard } else { return };
2224
2225 let SourceFileDiffs { bytes_per_diff, num_diffs, raw_diffs } = match &*guard {
2226 SourceFileLines::Diffs(diffs) => diffs,
2227 SourceFileLines::Lines(..) => {
2228 FreezeWriteGuard::freeze(guard);
2229 return;
2230 }
2231 };
2232
2233 let num_lines = num_diffs + 1;
2235 let mut lines = Vec::with_capacity(num_lines);
2236 let mut line_start = RelativeBytePos(0);
2237 lines.push(line_start);
2238
2239 {
match (&*num_diffs, &(raw_diffs.len() / bytes_per_diff)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(*num_diffs, raw_diffs.len() / bytes_per_diff);
2240 match bytes_per_diff {
2241 1 => {
2242 lines.extend(raw_diffs.into_iter().map(|&diff| {
2243 line_start = line_start + RelativeBytePos(diff as u32);
2244 line_start
2245 }));
2246 }
2247 2 => {
2248 lines.extend((0..*num_diffs).map(|i| {
2249 let pos = bytes_per_diff * i;
2250 let bytes = [raw_diffs[pos], raw_diffs[pos + 1]];
2251 let diff = u16::from_le_bytes(bytes);
2252 line_start = line_start + RelativeBytePos(diff as u32);
2253 line_start
2254 }));
2255 }
2256 4 => {
2257 lines.extend((0..*num_diffs).map(|i| {
2258 let pos = bytes_per_diff * i;
2259 let bytes = [
2260 raw_diffs[pos],
2261 raw_diffs[pos + 1],
2262 raw_diffs[pos + 2],
2263 raw_diffs[pos + 3],
2264 ];
2265 let diff = u32::from_le_bytes(bytes);
2266 line_start = line_start + RelativeBytePos(diff);
2267 line_start
2268 }));
2269 }
2270 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
2271 }
2272
2273 *guard = SourceFileLines::Lines(lines);
2274
2275 FreezeWriteGuard::freeze(guard);
2276 }
2277
2278 pub fn lines(&self) -> &[RelativeBytePos] {
2279 if let Some(SourceFileLines::Lines(lines)) = self.lines.get() {
2280 return &lines[..];
2281 }
2282
2283 outline(|| {
2284 self.convert_diffs_to_lines_frozen();
2285 if let Some(SourceFileLines::Lines(lines)) = self.lines.get() {
2286 return &lines[..];
2287 }
2288 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
2289 })
2290 }
2291
2292 pub fn line_begin_pos(&self, pos: BytePos) -> BytePos {
2294 let pos = self.relative_position(pos);
2295 let line_index = self.lookup_line(pos).unwrap();
2296 let line_start_pos = self.lines()[line_index];
2297 self.absolute_position(line_start_pos)
2298 }
2299
2300 pub fn add_external_src<F>(&self, get_src: F) -> bool
2305 where
2306 F: FnOnce() -> Option<String>,
2307 {
2308 if !self.external_src.is_frozen() {
2309 let src = get_src();
2310 let src = src.and_then(|mut src| {
2311 self.src_hash.matches(&src).then(|| {
2313 normalize_src(&mut src);
2314 src
2315 })
2316 });
2317
2318 self.external_src.try_write().map(|mut external_src| {
2319 if let ExternalSource::Foreign {
2320 kind: src_kind @ ExternalSourceKind::AbsentOk,
2321 ..
2322 } = &mut *external_src
2323 {
2324 *src_kind = if let Some(src) = src {
2325 ExternalSourceKind::Present(Arc::new(src))
2326 } else {
2327 ExternalSourceKind::AbsentErr
2328 };
2329 } else {
2330 {
::core::panicking::panic_fmt(format_args!("unexpected state {0:?}",
*external_src));
}panic!("unexpected state {:?}", *external_src)
2331 }
2332
2333 FreezeWriteGuard::freeze(external_src)
2335 });
2336 }
2337
2338 self.src.is_some() || self.external_src.read().get_source().is_some()
2339 }
2340
2341 pub fn get_line(&self, line_number: usize) -> Option<Cow<'_, str>> {
2344 fn get_until_newline(src: &str, begin: usize) -> &str {
2345 let slice = &src[begin..];
2349 match slice.find('\n') {
2350 Some(e) => &slice[..e],
2351 None => slice,
2352 }
2353 }
2354
2355 let begin = {
2356 let line = self.lines().get(line_number).copied()?;
2357 line.to_usize()
2358 };
2359
2360 if let Some(ref src) = self.src {
2361 Some(Cow::from(get_until_newline(src, begin)))
2362 } else {
2363 self.external_src
2364 .borrow()
2365 .get_source()
2366 .map(|src| Cow::Owned(String::from(get_until_newline(src, begin))))
2367 }
2368 }
2369
2370 pub fn is_real_file(&self) -> bool {
2371 self.name.is_real()
2372 }
2373
2374 #[inline]
2375 pub fn is_imported(&self) -> bool {
2376 self.src.is_none()
2377 }
2378
2379 pub fn count_lines(&self) -> usize {
2380 self.lines().len()
2381 }
2382
2383 #[inline]
2384 pub fn absolute_position(&self, pos: RelativeBytePos) -> BytePos {
2385 BytePos::from_u32(pos.to_u32() + self.start_pos.to_u32())
2386 }
2387
2388 #[inline]
2389 pub fn relative_position(&self, pos: BytePos) -> RelativeBytePos {
2390 RelativeBytePos::from_u32(pos.to_u32() - self.start_pos.to_u32())
2391 }
2392
2393 #[inline]
2394 pub fn end_position(&self) -> BytePos {
2395 self.absolute_position(self.normalized_source_len)
2396 }
2397
2398 pub fn lookup_line(&self, pos: RelativeBytePos) -> Option<usize> {
2403 self.lines().partition_point(|x| x <= &pos).checked_sub(1)
2404 }
2405
2406 pub fn line_bounds(&self, line_index: usize) -> Range<BytePos> {
2407 if self.is_empty() {
2408 return self.start_pos..self.start_pos;
2409 }
2410
2411 let lines = self.lines();
2412 if !(line_index < lines.len()) {
::core::panicking::panic("assertion failed: line_index < lines.len()")
};assert!(line_index < lines.len());
2413 if line_index == (lines.len() - 1) {
2414 self.absolute_position(lines[line_index])..self.end_position()
2415 } else {
2416 self.absolute_position(lines[line_index])..self.absolute_position(lines[line_index + 1])
2417 }
2418 }
2419
2420 #[inline]
2425 pub fn contains(&self, byte_pos: BytePos) -> bool {
2426 byte_pos >= self.start_pos && byte_pos <= self.end_position()
2427 }
2428
2429 #[inline]
2430 pub fn is_empty(&self) -> bool {
2431 self.normalized_source_len.to_u32() == 0
2432 }
2433
2434 pub fn original_relative_byte_pos(&self, pos: BytePos) -> RelativeBytePos {
2437 let pos = self.relative_position(pos);
2438
2439 let diff = match self.normalized_pos.binary_search_by(|np| np.pos.cmp(&pos)) {
2443 Ok(i) => self.normalized_pos[i].diff,
2444 Err(0) => 0,
2445 Err(i) => self.normalized_pos[i - 1].diff,
2446 };
2447
2448 RelativeBytePos::from_u32(pos.0 + diff)
2449 }
2450
2451 pub fn normalized_byte_pos(&self, offset: u32) -> BytePos {
2461 let diff =
2462 match self.normalized_pos.binary_search_by(|np| (np.pos.0 + np.diff).cmp(&offset)) {
2463 Ok(i) => self.normalized_pos[i].diff,
2464 Err(0) => 0,
2465 Err(i) => self.normalized_pos[i - 1].diff,
2466 };
2467
2468 BytePos::from_u32(self.start_pos.0 + offset - diff)
2469 }
2470
2471 fn bytepos_to_file_charpos(&self, bpos: RelativeBytePos) -> CharPos {
2473 let mut total_extra_bytes = 0;
2475
2476 for mbc in self.multibyte_chars.iter() {
2477 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs:2477",
"rustc_span", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2477u32),
::tracing_core::__macro_support::Option::Some("rustc_span"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0}-byte char at {1:?}",
mbc.bytes, mbc.pos) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("{}-byte char at {:?}", mbc.bytes, mbc.pos);
2478 if mbc.pos < bpos {
2479 total_extra_bytes += mbc.bytes as u32 - 1;
2482 if !(bpos.to_u32() >= mbc.pos.to_u32() + mbc.bytes as u32) {
::core::panicking::panic("assertion failed: bpos.to_u32() >= mbc.pos.to_u32() + mbc.bytes as u32")
};assert!(bpos.to_u32() >= mbc.pos.to_u32() + mbc.bytes as u32);
2485 } else {
2486 break;
2487 }
2488 }
2489
2490 if !(total_extra_bytes <= bpos.to_u32()) {
::core::panicking::panic("assertion failed: total_extra_bytes <= bpos.to_u32()")
};assert!(total_extra_bytes <= bpos.to_u32());
2491 CharPos(bpos.to_usize() - total_extra_bytes as usize)
2492 }
2493
2494 fn lookup_file_pos(&self, pos: RelativeBytePos) -> (usize, CharPos) {
2497 let chpos = self.bytepos_to_file_charpos(pos);
2498 match self.lookup_line(pos) {
2499 Some(a) => {
2500 let line = a + 1; let linebpos = self.lines()[a];
2502 let linechpos = self.bytepos_to_file_charpos(linebpos);
2503 let col = chpos - linechpos;
2504 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs:2504",
"rustc_span", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2504u32),
::tracing_core::__macro_support::Option::Some("rustc_span"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("byte pos {0:?} is on the line at byte pos {1:?}",
pos, linebpos) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("byte pos {:?} is on the line at byte pos {:?}", pos, linebpos);
2505 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs:2505",
"rustc_span", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2505u32),
::tracing_core::__macro_support::Option::Some("rustc_span"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("char pos {0:?} is on the line at char pos {1:?}",
chpos, linechpos) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("char pos {:?} is on the line at char pos {:?}", chpos, linechpos);
2506 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs:2506",
"rustc_span", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2506u32),
::tracing_core::__macro_support::Option::Some("rustc_span"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("byte is on line: {0}",
line) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("byte is on line: {}", line);
2507 if !(chpos >= linechpos) {
::core::panicking::panic("assertion failed: chpos >= linechpos")
};assert!(chpos >= linechpos);
2508 (line, col)
2509 }
2510 None => (0, chpos),
2511 }
2512 }
2513
2514 pub fn lookup_file_pos_with_col_display(&self, pos: BytePos) -> (usize, CharPos, usize) {
2517 let pos = self.relative_position(pos);
2518 let (line, col_or_chpos) = self.lookup_file_pos(pos);
2519 if line > 0 {
2520 let Some(code) = self.get_line(line - 1) else {
2521 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs:2528",
"rustc_span", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/7df81381d027710708209f36b98d11b1c88f8d2e/compiler/rustc_span/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2528u32),
::tracing_core::__macro_support::Option::Some("rustc_span"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("couldn\'t find line {1} {0:?}",
self.name, line) as &dyn ::tracing::field::Value))])
});
} else { ; }
};tracing::info!("couldn't find line {line} {:?}", self.name);
2529 return (line, col_or_chpos, col_or_chpos.0);
2530 };
2531 let display_col = code.chars().take(col_or_chpos.0).map(|ch| char_width(ch)).sum();
2532 (line, col_or_chpos, display_col)
2533 } else {
2534 (0, col_or_chpos, col_or_chpos.0)
2536 }
2537 }
2538}
2539
2540pub fn char_width(ch: char) -> usize {
2541 match ch {
2544 '\t' => 4,
2545 '\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}'
2549 | '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}'
2550 | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}'
2551 | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}'
2552 | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}'
2553 | '\u{007F}' | '\u{202A}' | '\u{202B}' | '\u{202D}' | '\u{202E}' | '\u{2066}'
2554 | '\u{2067}' | '\u{2068}' | '\u{202C}' | '\u{2069}' => 1,
2555 _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1),
2556 }
2557}
2558
2559pub fn str_width(s: &str) -> usize {
2560 s.chars().map(char_width).sum()
2561}
2562
2563fn normalize_src(src: &mut String) -> Vec<NormalizedPos> {
2565 let mut normalized_pos = ::alloc::vec::Vec::new()vec![];
2566 remove_bom(src, &mut normalized_pos);
2567 normalize_newlines(src, &mut normalized_pos);
2568 normalized_pos
2569}
2570
2571fn remove_bom(src: &mut String, normalized_pos: &mut Vec<NormalizedPos>) {
2573 if src.starts_with('\u{feff}') {
2574 src.drain(..3);
2575 normalized_pos.push(NormalizedPos { pos: RelativeBytePos(0), diff: 3 });
2576 }
2577}
2578
2579fn normalize_newlines(src: &mut String, normalized_pos: &mut Vec<NormalizedPos>) {
2583 if !src.as_bytes().contains(&b'\r') {
2584 return;
2585 }
2586
2587 let mut buf = std::mem::take(src).into_bytes();
2593 let mut gap_len = 0;
2594 let mut tail = buf.as_mut_slice();
2595 let mut cursor = 0;
2596 let original_gap = normalized_pos.last().map_or(0, |l| l.diff);
2597 loop {
2598 let idx = match find_crlf(&tail[gap_len..]) {
2599 None => tail.len(),
2600 Some(idx) => idx + gap_len,
2601 };
2602 tail.copy_within(gap_len..idx, 0);
2603 tail = &mut tail[idx - gap_len..];
2604 if tail.len() == gap_len {
2605 break;
2606 }
2607 cursor += idx - gap_len;
2608 gap_len += 1;
2609 normalized_pos.push(NormalizedPos {
2610 pos: RelativeBytePos::from_usize(cursor + 1),
2611 diff: original_gap + gap_len as u32,
2612 });
2613 }
2614
2615 let new_len = buf.len() - gap_len;
2618 unsafe {
2619 buf.set_len(new_len);
2620 *src = String::from_utf8_unchecked(buf);
2621 }
2622
2623 fn find_crlf(src: &[u8]) -> Option<usize> {
2624 let mut search_idx = 0;
2625 while let Some(idx) = find_cr(&src[search_idx..]) {
2626 if src[search_idx..].get(idx + 1) != Some(&b'\n') {
2627 search_idx += idx + 1;
2628 continue;
2629 }
2630 return Some(search_idx + idx);
2631 }
2632 None
2633 }
2634
2635 fn find_cr(src: &[u8]) -> Option<usize> {
2636 src.iter().position(|&b| b == b'\r')
2637 }
2638}
2639
2640pub trait Pos {
2645 fn from_usize(n: usize) -> Self;
2646 fn to_usize(&self) -> usize;
2647 fn from_u32(n: u32) -> Self;
2648 fn to_u32(&self) -> u32;
2649}
2650
2651macro_rules! impl_pos {
2652 (
2653 $(
2654 $(#[$attr:meta])*
2655 $vis:vis struct $ident:ident($inner_vis:vis $inner_ty:ty);
2656 )*
2657 ) => {
2658 $(
2659 $(#[$attr])*
2660 $vis struct $ident($inner_vis $inner_ty);
2661
2662 impl Pos for $ident {
2663 #[inline(always)]
2664 fn from_usize(n: usize) -> $ident {
2665 $ident(n as $inner_ty)
2666 }
2667
2668 #[inline(always)]
2669 fn to_usize(&self) -> usize {
2670 self.0 as usize
2671 }
2672
2673 #[inline(always)]
2674 fn from_u32(n: u32) -> $ident {
2675 $ident(n as $inner_ty)
2676 }
2677
2678 #[inline(always)]
2679 fn to_u32(&self) -> u32 {
2680 self.0 as u32
2681 }
2682 }
2683
2684 impl Add for $ident {
2685 type Output = $ident;
2686
2687 #[inline(always)]
2688 fn add(self, rhs: $ident) -> $ident {
2689 $ident(self.0 + rhs.0)
2690 }
2691 }
2692
2693 impl Sub for $ident {
2694 type Output = $ident;
2695
2696 #[inline(always)]
2697 fn sub(self, rhs: $ident) -> $ident {
2698 $ident(self.0 - rhs.0)
2699 }
2700 }
2701 )*
2702 };
2703}
2704
2705#[doc = r" A byte offset."]
#[doc = r""]
#[doc =
r" Keep this small (currently 32-bits), as AST contains a lot of them."]
pub struct BytePos(pub u32);
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for BytePos { }
#[automatically_derived]
impl ::core::clone::Clone for BytePos {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for BytePos { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for BytePos { }
#[automatically_derived]
impl ::core::cmp::PartialEq for BytePos {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for BytePos {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}
#[automatically_derived]
impl ::core::hash::Hash for BytePos {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for BytePos {
#[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 BytePos {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::fmt::Debug for BytePos {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "BytePos",
&&self.0)
}
}
impl Pos for BytePos {
#[inline(always)]
fn from_usize(n: usize) -> BytePos { BytePos(n as u32) }
#[inline(always)]
fn to_usize(&self) -> usize { self.0 as usize }
#[inline(always)]
fn from_u32(n: u32) -> BytePos { BytePos(n as u32) }
#[inline(always)]
fn to_u32(&self) -> u32 { self.0 as u32 }
}
impl Add for BytePos {
type Output = BytePos;
#[inline(always)]
fn add(self, rhs: BytePos) -> BytePos { BytePos(self.0 + rhs.0) }
}
impl Sub for BytePos {
type Output = BytePos;
#[inline(always)]
fn sub(self, rhs: BytePos) -> BytePos { BytePos(self.0 - rhs.0) }
}
#[doc = r" A byte offset relative to file beginning."]
pub struct RelativeBytePos(pub u32);
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for RelativeBytePos { }
#[automatically_derived]
impl ::core::clone::Clone for RelativeBytePos {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for RelativeBytePos { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for RelativeBytePos { }
#[automatically_derived]
impl ::core::cmp::PartialEq for RelativeBytePos {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for RelativeBytePos {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}
#[automatically_derived]
impl ::core::hash::Hash for RelativeBytePos {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for RelativeBytePos {
#[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 RelativeBytePos {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::fmt::Debug for RelativeBytePos {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"RelativeBytePos", &&self.0)
}
}
const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
RelativeBytePos {
#[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 {
RelativeBytePos(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};
impl Pos for RelativeBytePos {
#[inline(always)]
fn from_usize(n: usize) -> RelativeBytePos { RelativeBytePos(n as u32) }
#[inline(always)]
fn to_usize(&self) -> usize { self.0 as usize }
#[inline(always)]
fn from_u32(n: u32) -> RelativeBytePos { RelativeBytePos(n as u32) }
#[inline(always)]
fn to_u32(&self) -> u32 { self.0 as u32 }
}
impl Add for RelativeBytePos {
type Output = RelativeBytePos;
#[inline(always)]
fn add(self, rhs: RelativeBytePos) -> RelativeBytePos {
RelativeBytePos(self.0 + rhs.0)
}
}
impl Sub for RelativeBytePos {
type Output = RelativeBytePos;
#[inline(always)]
fn sub(self, rhs: RelativeBytePos) -> RelativeBytePos {
RelativeBytePos(self.0 - rhs.0)
}
}
#[doc = r" A character offset."]
#[doc = r""]
#[doc = r" Because of multibyte UTF-8 characters, a byte offset"]
#[doc =
r" is not equivalent to a character offset. The [`SourceMap`] will convert [`BytePos`]"]
#[doc = r" values to `CharPos` values as necessary."]
pub struct CharPos(pub usize);
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for CharPos { }
#[automatically_derived]
impl ::core::clone::Clone for CharPos {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for CharPos { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for CharPos { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CharPos {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for CharPos {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<usize>;
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for CharPos {
#[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 CharPos {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::fmt::Debug for CharPos {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "CharPos",
&&self.0)
}
}
impl Pos for CharPos {
#[inline(always)]
fn from_usize(n: usize) -> CharPos { CharPos(n as usize) }
#[inline(always)]
fn to_usize(&self) -> usize { self.0 as usize }
#[inline(always)]
fn from_u32(n: u32) -> CharPos { CharPos(n as usize) }
#[inline(always)]
fn to_u32(&self) -> u32 { self.0 as u32 }
}
impl Add for CharPos {
type Output = CharPos;
#[inline(always)]
fn add(self, rhs: CharPos) -> CharPos { CharPos(self.0 + rhs.0) }
}
impl Sub for CharPos {
type Output = CharPos;
#[inline(always)]
fn sub(self, rhs: CharPos) -> CharPos { CharPos(self.0 - rhs.0) }
}impl_pos! {
2706 #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
2710 pub struct BytePos(pub u32);
2711
2712 #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, StableHash)]
2714 pub struct RelativeBytePos(pub u32);
2715
2716 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
2722 pub struct CharPos(pub usize);
2723}
2724
2725impl<S: Encoder> Encodable<S> for BytePos {
2726 fn encode(&self, s: &mut S) {
2727 s.emit_u32(self.0);
2728 }
2729}
2730
2731impl<D: Decoder> Decodable<D> for BytePos {
2732 fn decode(d: &mut D) -> BytePos {
2733 BytePos(d.read_u32())
2734 }
2735}
2736
2737impl<S: Encoder> Encodable<S> for RelativeBytePos {
2738 fn encode(&self, s: &mut S) {
2739 s.emit_u32(self.0);
2740 }
2741}
2742
2743impl<D: Decoder> Decodable<D> for RelativeBytePos {
2744 fn decode(d: &mut D) -> RelativeBytePos {
2745 RelativeBytePos(d.read_u32())
2746 }
2747}
2748
2749#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Loc {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "Loc", "file",
&self.file, "line", &self.line, "col", &self.col, "col_display",
&&self.col_display)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Loc {
#[inline]
fn clone(&self) -> Self {
Loc {
file: ::core::clone::Clone::clone(&self.file),
line: ::core::clone::Clone::clone(&self.line),
col: ::core::clone::Clone::clone(&self.col),
col_display: ::core::clone::Clone::clone(&self.col_display),
}
}
}Clone)]
2755pub struct Loc {
2756 pub file: Arc<SourceFile>,
2758 pub line: usize,
2760 pub col: CharPos,
2762 pub col_display: usize,
2764}
2765
2766#[derive(#[automatically_derived]
impl ::core::fmt::Debug for SourceFileAndLine {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"SourceFileAndLine", "sf", &self.sf, "line", &&self.line)
}
}Debug)]
2768pub struct SourceFileAndLine {
2769 pub sf: Arc<SourceFile>,
2770 pub line: usize,
2772}
2773#[derive(#[automatically_derived]
impl ::core::fmt::Debug for SourceFileAndBytePos {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"SourceFileAndBytePos", "sf", &self.sf, "pos", &&self.pos)
}
}Debug)]
2774pub struct SourceFileAndBytePos {
2775 pub sf: Arc<SourceFile>,
2776 pub pos: BytePos,
2777}
2778
2779#[derive(#[automatically_derived]
impl ::core::marker::Copy for LineInfo { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LineInfo { }
#[automatically_derived]
impl ::core::clone::Clone for LineInfo {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<usize>;
let _: ::core::clone::AssertParamIsClone<CharPos>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for LineInfo {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "LineInfo",
"line_index", &self.line_index, "start_col", &self.start_col,
"end_col", &&self.end_col)
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for LineInfo { }
#[automatically_derived]
impl ::core::cmp::PartialEq for LineInfo {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.line_index == other.line_index &&
self.start_col == other.start_col &&
self.end_col == other.end_col
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for LineInfo {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<usize>;
let _: ::core::cmp::AssertParamIsEq<CharPos>;
}
}Eq)]
2780pub struct LineInfo {
2781 pub line_index: usize,
2783
2784 pub start_col: CharPos,
2786
2787 pub end_col: CharPos,
2789}
2790
2791pub struct FileLines {
2792 pub file: Arc<SourceFile>,
2793 pub lines: Vec<LineInfo>,
2794}
2795
2796pub static SPAN_TRACK: AtomicRef<fn(LocalDefId)> = AtomicRef::new(&((|_| {}) as fn(_)));
2797
2798pub type FileLinesResult = Result<FileLines, SpanLinesError>;
2803
2804#[derive(#[automatically_derived]
impl ::core::clone::Clone for SpanLinesError {
#[inline]
fn clone(&self) -> Self {
match self {
Self::DistinctSources(__self_0) =>
SpanLinesError::DistinctSources(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for SpanLinesError { }
#[automatically_derived]
impl ::core::cmp::PartialEq for SpanLinesError {
#[inline]
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::DistinctSources(__self_0), Self::DistinctSources(__arg1_0))
=> __self_0 == __arg1_0,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for SpanLinesError {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Box<DistinctSources>>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for SpanLinesError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::DistinctSources(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"DistinctSources", &__self_0),
}
}
}Debug)]
2805pub enum SpanLinesError {
2806 DistinctSources(Box<DistinctSources>),
2807}
2808
2809#[derive(#[automatically_derived]
impl ::core::clone::Clone for SpanSnippetError {
#[inline]
fn clone(&self) -> Self {
match self {
Self::IllFormedSpan(__self_0) =>
SpanSnippetError::IllFormedSpan(::core::clone::Clone::clone(__self_0)),
Self::DistinctSources(__self_0) =>
SpanSnippetError::DistinctSources(::core::clone::Clone::clone(__self_0)),
Self::MalformedForSourcemap(__self_0) =>
SpanSnippetError::MalformedForSourcemap(::core::clone::Clone::clone(__self_0)),
Self::SourceNotAvailable { filename: __self_0 } =>
SpanSnippetError::SourceNotAvailable {
filename: ::core::clone::Clone::clone(__self_0),
},
}
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for SpanSnippetError { }
#[automatically_derived]
impl ::core::cmp::PartialEq for SpanSnippetError {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::IllFormedSpan(__self_0), Self::IllFormedSpan(__arg1_0))
=> __self_0 == __arg1_0,
(Self::DistinctSources(__self_0),
Self::DistinctSources(__arg1_0)) => __self_0 == __arg1_0,
(Self::MalformedForSourcemap(__self_0),
Self::MalformedForSourcemap(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::SourceNotAvailable { filename: __self_0 },
Self::SourceNotAvailable { filename: __arg1_0 }) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for SpanSnippetError {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Span>;
let _: ::core::cmp::AssertParamIsEq<Box<DistinctSources>>;
let _: ::core::cmp::AssertParamIsEq<MalformedSourceMapPositions>;
let _: ::core::cmp::AssertParamIsEq<FileName>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for SpanSnippetError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::IllFormedSpan(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"IllFormedSpan", &__self_0),
Self::DistinctSources(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"DistinctSources", &__self_0),
Self::MalformedForSourcemap(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"MalformedForSourcemap", &__self_0),
Self::SourceNotAvailable { filename: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"SourceNotAvailable", "filename", &__self_0),
}
}
}Debug)]
2810pub enum SpanSnippetError {
2811 IllFormedSpan(Span),
2812 DistinctSources(Box<DistinctSources>),
2813 MalformedForSourcemap(MalformedSourceMapPositions),
2814 SourceNotAvailable { filename: FileName },
2815}
2816
2817#[derive(#[automatically_derived]
impl ::core::clone::Clone for DistinctSources {
#[inline]
fn clone(&self) -> Self {
DistinctSources {
begin: ::core::clone::Clone::clone(&self.begin),
end: ::core::clone::Clone::clone(&self.end),
}
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for DistinctSources { }
#[automatically_derived]
impl ::core::cmp::PartialEq for DistinctSources {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.begin == other.begin && self.end == other.end
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DistinctSources {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<(FileName, BytePos)>;
let _: ::core::cmp::AssertParamIsEq<(FileName, BytePos)>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for DistinctSources {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DistinctSources", "begin", &self.begin, "end", &&self.end)
}
}Debug)]
2818pub struct DistinctSources {
2819 pub begin: (FileName, BytePos),
2820 pub end: (FileName, BytePos),
2821}
2822
2823#[derive(#[automatically_derived]
impl ::core::clone::Clone for MalformedSourceMapPositions {
#[inline]
fn clone(&self) -> Self {
MalformedSourceMapPositions {
name: ::core::clone::Clone::clone(&self.name),
source_len: ::core::clone::Clone::clone(&self.source_len),
begin_pos: ::core::clone::Clone::clone(&self.begin_pos),
end_pos: ::core::clone::Clone::clone(&self.end_pos),
}
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for MalformedSourceMapPositions { }
#[automatically_derived]
impl ::core::cmp::PartialEq for MalformedSourceMapPositions {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.name == other.name && self.source_len == other.source_len &&
self.begin_pos == other.begin_pos &&
self.end_pos == other.end_pos
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for MalformedSourceMapPositions {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<FileName>;
let _: ::core::cmp::AssertParamIsEq<usize>;
let _: ::core::cmp::AssertParamIsEq<BytePos>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for MalformedSourceMapPositions {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"MalformedSourceMapPositions", "name", &self.name, "source_len",
&self.source_len, "begin_pos", &self.begin_pos, "end_pos",
&&self.end_pos)
}
}Debug)]
2824pub struct MalformedSourceMapPositions {
2825 pub name: FileName,
2826 pub source_len: usize,
2827 pub begin_pos: BytePos,
2828 pub end_pos: BytePos,
2829}
2830
2831#[derive(#[automatically_derived]
impl ::core::marker::Copy for InnerSpan { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for InnerSpan { }
#[automatically_derived]
impl ::core::clone::Clone for InnerSpan {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for InnerSpan { }
#[automatically_derived]
impl ::core::cmp::PartialEq for InnerSpan {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.start == other.start && self.end == other.end
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for InnerSpan {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<usize>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for InnerSpan {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "InnerSpan",
"start", &self.start, "end", &&self.end)
}
}Debug)]
2833pub struct InnerSpan {
2834 pub start: usize,
2835 pub end: usize,
2836}
2837
2838impl InnerSpan {
2839 pub fn new(start: usize, end: usize) -> InnerSpan {
2840 InnerSpan { start, end }
2841 }
2842}
2843
2844impl StableHash for Span {
2845 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
2846 hcx.stable_hash_span(self.to_raw_span(), hasher)
2848 }
2849}
2850
2851#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ErrorGuaranteed { }
#[automatically_derived]
impl ::core::clone::Clone for ErrorGuaranteed {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<()>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ErrorGuaranteed { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for ErrorGuaranteed {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ErrorGuaranteed", &&self.0)
}
}Debug, #[automatically_derived]
impl ::core::hash::Hash for ErrorGuaranteed {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ErrorGuaranteed { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ErrorGuaranteed {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ErrorGuaranteed {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<()>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for ErrorGuaranteed {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for ErrorGuaranteed {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord)]
2857#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
ErrorGuaranteed {
#[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 {
ErrorGuaranteed(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
2858pub struct ErrorGuaranteed(());
2859
2860impl ErrorGuaranteed {
2861 #[deprecated = "should only be used in `DiagCtxtInner::emit_diagnostic`"]
2863 pub fn unchecked_error_guaranteed() -> Self {
2864 ErrorGuaranteed(())
2865 }
2866
2867 pub fn raise_fatal(self) -> ! {
2868 FatalError.raise()
2869 }
2870}
2871
2872impl<E: rustc_serialize::Encoder> Encodable<E> for ErrorGuaranteed {
2873 #[inline]
2874 fn encode(&self, _e: &mut E) {
2875 {
::core::panicking::panic_fmt(format_args!("should never serialize an `ErrorGuaranteed`, as we do not write metadata or incremental caches in case errors occurred"));
}panic!(
2876 "should never serialize an `ErrorGuaranteed`, as we do not write metadata or \
2877 incremental caches in case errors occurred"
2878 )
2879 }
2880}
2881impl<D: rustc_serialize::Decoder> Decodable<D> for ErrorGuaranteed {
2882 #[inline]
2883 fn decode(_d: &mut D) -> ErrorGuaranteed {
2884 {
::core::panicking::panic_fmt(format_args!("`ErrorGuaranteed` should never have been serialized to metadata or incremental caches"));
}panic!(
2885 "`ErrorGuaranteed` should never have been serialized to metadata or incremental caches"
2886 )
2887 }
2888}