mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Small cleanups
- Use a tuple struct instead of a single field - Enforce calling `source_callsite()` by making the inner span private - Rename `empty` to `dummy`
This commit is contained in:
parent
0e574fb39a
commit
9684557c8f
@ -118,7 +118,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||
};
|
||||
|
||||
Some(Item {
|
||||
source: Span::empty(),
|
||||
source: Span::dummy(),
|
||||
name: None,
|
||||
attrs: Default::default(),
|
||||
visibility: Inherited,
|
||||
|
@ -479,7 +479,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
|
||||
items.push(clean::Item {
|
||||
name: None,
|
||||
attrs: clean::Attributes::default(),
|
||||
source: clean::Span::empty(),
|
||||
source: clean::Span::dummy(),
|
||||
def_id: DefId::local(CRATE_DEF_INDEX),
|
||||
visibility: clean::Public,
|
||||
stability: None,
|
||||
|
@ -1882,10 +1882,7 @@ impl Clean<VariantKind> for hir::VariantData<'_> {
|
||||
|
||||
impl Clean<Span> for rustc_span::Span {
|
||||
fn clean(&self, _cx: &DocContext<'_>) -> Span {
|
||||
// Get the macro invocation instead of the definition,
|
||||
// in case the span is result of a macro expansion.
|
||||
// (See rust-lang/rust#39726)
|
||||
Span { original: self.source_callsite() }
|
||||
Span::from_rustc_span(*self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1610,31 +1610,36 @@ crate enum VariantKind {
|
||||
Struct(VariantStruct),
|
||||
}
|
||||
|
||||
/// Small wrapper around `rustc_span::Span` that adds helper methods.
|
||||
/// Small wrapper around `rustc_span::Span` that adds helper methods and enforces calling `source_callsite`.
|
||||
#[derive(Clone, Debug)]
|
||||
crate struct Span {
|
||||
crate original: rustc_span::Span,
|
||||
}
|
||||
crate struct Span(rustc_span::Span);
|
||||
|
||||
impl Span {
|
||||
crate fn empty() -> Self {
|
||||
Self { original: rustc_span::DUMMY_SP }
|
||||
crate fn from_rustc_span(sp: rustc_span::Span) -> Self {
|
||||
// Get the macro invocation instead of the definition,
|
||||
// in case the span is result of a macro expansion.
|
||||
// (See rust-lang/rust#39726)
|
||||
Self(sp.source_callsite())
|
||||
}
|
||||
|
||||
crate fn dummy() -> Self {
|
||||
Self(rustc_span::DUMMY_SP)
|
||||
}
|
||||
|
||||
crate fn span(&self) -> rustc_span::Span {
|
||||
self.original
|
||||
self.0
|
||||
}
|
||||
|
||||
crate fn filename(&self, sess: &Session) -> FileName {
|
||||
sess.source_map().span_to_filename(self.original)
|
||||
sess.source_map().span_to_filename(self.0)
|
||||
}
|
||||
|
||||
crate fn lo(&self, sess: &Session) -> Loc {
|
||||
sess.source_map().lookup_char_pos(self.original.lo())
|
||||
sess.source_map().lookup_char_pos(self.0.lo())
|
||||
}
|
||||
|
||||
crate fn hi(&self, sess: &Session) -> Loc {
|
||||
sess.source_map().lookup_char_pos(self.original.hi())
|
||||
sess.source_map().lookup_char_pos(self.0.hi())
|
||||
}
|
||||
|
||||
crate fn cnum(&self, sess: &Session) -> CrateNum {
|
||||
|
Loading…
Reference in New Issue
Block a user