Skip to content

Commit

Permalink
Rename Span::empty to Span::shrink_to_lo, add Span::shrink_to_hi
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Mar 17, 2018
1 parent e5fb138 commit f881626
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ impl<'a> LoweringContext<'a> {
TyKind::Slice(ref ty) => hir::TySlice(self.lower_ty(ty, itctx)),
TyKind::Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt, itctx)),
TyKind::Rptr(ref region, ref mt) => {
let span = t.span.with_hi(t.span.lo());
let span = t.span.shrink_to_lo();
let lifetime = match *region {
Some(ref lt) => self.lower_lifetime(lt),
None => self.elided_lifetime(span)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_allocator/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
f.cx.item_extern_crate(f.span, f.alloc),
f.cx.item_use_simple(
f.span,
respan(f.span.empty(), VisibilityKind::Inherited),
respan(f.span.shrink_to_lo(), VisibilityKind::Inherited),
super_path,
),
];
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
if !cx.access_levels.is_reachable(it.id) {
let msg = "function is marked #[no_mangle], but not exported";
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg);
let insertion_span = it.span.with_hi(it.span.lo());
let insertion_span = it.span.shrink_to_lo();
if it.vis == hir::Visibility::Inherited {
err.span_suggestion(insertion_span,
"try making it public",
Expand All @@ -1107,7 +1107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
!cx.access_levels.is_reachable(it.id) {
let msg = "static is marked #[no_mangle], but not exported";
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg);
let insertion_span = it.span.with_hi(it.span.lo());
let insertion_span = it.span.shrink_to_lo();
if it.vis == hir::Visibility::Inherited {
err.span_suggestion(insertion_span,
"try making it public",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl CrateStore for cstore::CStore {
tokens: body.into(),
legacy: def.legacy,
}),
vis: codemap::respan(local_span.empty(), ast::VisibilityKind::Inherited),
vis: codemap::respan(local_span.shrink_to_lo(), ast::VisibilityKind::Inherited),
tokens: None,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
builder.args_and_body(block, &arguments, arg_scope, &body.value)
}));
// Attribute epilogue to function's closing brace
let fn_end = span.with_lo(span.hi());
let fn_end = span.shrink_to_hi();
let source_info = builder.source_info(fn_end);
let return_block = builder.return_block();
builder.cfg.terminate(block, source_info,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
// don't suggest placing a use before the prelude
// import or other generated ones
if item.span.ctxt().outer().expn_info().is_none() {
self.span = Some(item.span.with_hi(item.span.lo()));
self.span = Some(item.span.shrink_to_lo());
self.found_use = true;
return;
}
Expand All @@ -768,12 +768,12 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
if item.span.ctxt().outer().expn_info().is_none() {
// don't insert between attributes and an item
if item.attrs.is_empty() {
self.span = Some(item.span.with_hi(item.span.lo()));
self.span = Some(item.span.shrink_to_lo());
} else {
// find the first attribute on the item
for attr in &item.attrs {
if self.span.map_or(true, |span| attr.span < span) {
self.span = Some(attr.span.with_hi(attr.span.lo()));
self.span = Some(attr.span.shrink_to_lo());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {

fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {
self.process_macro_use(trait_item.span);
let vis_span = trait_item.span.empty();
let vis_span = trait_item.span.shrink_to_lo();
match trait_item.node {
ast::TraitItemKind::Const(ref ty, ref expr) => {
self.process_assoc_const(
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, '
// don't suggest placing a use before the prelude
// import or other generated ones
if item.span.ctxt().outer().expn_info().is_none() {
self.span = Some(item.span.with_hi(item.span.lo()));
self.span = Some(item.span.shrink_to_lo());
self.found_use = true;
return;
}
Expand All @@ -779,12 +779,12 @@ impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, '
if item.span.ctxt().outer().expn_info().is_none() {
// don't insert between attributes and an item
if item.attrs.is_empty() {
self.span = Some(item.span.with_hi(item.span.lo()));
self.span = Some(item.span.shrink_to_lo());
} else {
// find the first attribute on the item
for attr in &item.attrs {
if self.span.map_or(true, |span| attr.span < span) {
self.span = Some(attr.span.with_hi(attr.span.lo()));
self.span = Some(attr.span.shrink_to_lo());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if sugg_unit {
let sugg_span = sess.codemap().end_point(expr_sp);
// remove closing `)` from the span
let sugg_span = sugg_span.with_hi(sugg_span.lo());
let sugg_span = sugg_span.shrink_to_lo();
err.span_suggestion(
sugg_span,
"expected the unit value `()`; create it with empty parentheses",
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Path {
return None;
}
}
Some(PathSegment::crate_root(self.span.with_hi(self.span.lo())))
Some(PathSegment::crate_root(self.span.shrink_to_lo()))
}

pub fn is_global(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
ty,
expr,
),
vis: codemap::respan(span.empty(), ast::VisibilityKind::Public),
vis: codemap::respan(span.shrink_to_lo(), ast::VisibilityKind::Public),
span,
tokens: None,
})
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
attrs,
id: ast::DUMMY_NODE_ID,
node,
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
span,
tokens: None,
})
Expand Down Expand Up @@ -1033,7 +1033,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
span: ty.span,
ty,
ident: None,
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
node: ast::ItemKind::Mod(krate.module),
ident: keywords::Invalid.ident(),
id: ast::DUMMY_NODE_ID,
vis: respan(krate.span.empty(), ast::VisibilityKind::Public),
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
tokens: None,
})));

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ fn expand_wrapper(cx: &ExtCtxt,
let path = path.iter().map(|s| s.to_string()).collect();
let use_item = cx.item_use_glob(
sp,
respan(sp.empty(), ast::VisibilityKind::Inherited),
respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
ids_ext(path),
);
cx.stmt_item(sp, use_item)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate,
ident: keywords::Invalid.ident(),
attrs,
id: ast::DUMMY_NODE_ID,
vis: respan(span.empty(), ast::VisibilityKind::Public),
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Public),
span,
node: ast::ItemKind::Mod(module),
tokens: None,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<'a> StringReader<'a> {

// Make the range zero-length if the span is invalid.
if span.lo() > span.hi() || begin.fm.start_pos != end.fm.start_pos {
span = span.with_hi(span.lo());
span = span.shrink_to_lo();
}

let mut sr = StringReader::new_raw_internal(sess, begin.fm);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ impl<'a> Parser<'a> {
if self.eat(&token::RArrow) {
Ok(FunctionRetTy::Ty(self.parse_ty_common(allow_plus, true)?))
} else {
Ok(FunctionRetTy::Default(self.span.with_hi(self.span.lo())))
Ok(FunctionRetTy::Default(self.span.shrink_to_lo()))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ impl<'a> State<'a> {
ti.ident,
ty,
default.as_ref().map(|expr| &**expr),
&codemap::respan(ti.span.empty(), ast::VisibilityKind::Inherited),
&codemap::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
)?;
}
ast::TraitItemKind::Method(ref sig, ref body) => {
Expand All @@ -1579,7 +1579,7 @@ impl<'a> State<'a> {
ti.ident,
&ti.generics,
sig,
&codemap::respan(ti.span.empty(), ast::VisibilityKind::Inherited),
&codemap::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
)?;
if let Some(ref body) = *body {
self.nbsp()?;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/std_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<&str>
is_sugared_doc: false,
span,
}],
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
node: ast::ItemKind::Use(P(ast::UseTree {
prefix: ast::Path {
segments: [name, "prelude", "v1"].into_iter().map(|name| {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl<'a> TraitDef<'a> {
id: ast::DUMMY_NODE_ID,
span: self.span,
ident,
vis: respan(self.span.empty(), ast::VisibilityKind::Inherited),
vis: respan(self.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
attrs: Vec::new(),
generics: Generics::default(),
Expand Down Expand Up @@ -977,7 +977,7 @@ impl<'a> MethodDef<'a> {
attrs: self.attributes.clone(),
generics: fn_generics,
span: trait_.span,
vis: respan(trait_.span.empty(), ast::VisibilityKind::Inherited),
vis: respan(trait_.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
ident: method_ident,
node: ast::ImplItemKind::Method(ast::MethodSig {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
asm,
ctxt: cx.backtrace(),
})),
vis: respan(sp.empty(), ast::VisibilityKind::Inherited),
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
span: sp,
tokens: None,
})))
Expand Down
11 changes: 9 additions & 2 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,15 @@ impl Span {

/// Returns a new span representing an empty span at the beginning of this span
#[inline]
pub fn empty(self) -> Span {
self.with_hi(self.lo())
pub fn shrink_to_lo(self) -> Span {
let span = self.data();
span.with_hi(span.lo)
}
/// Returns a new span representing an empty span at the end of this span
#[inline]
pub fn shrink_to_hi(self) -> Span {
let span = self.data();
span.with_lo(span.hi)
}

/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
Expand Down

0 comments on commit f881626

Please sign in to comment.