Skip to content

Commit f881626

Browse files
committed
Rename Span::empty to Span::shrink_to_lo, add Span::shrink_to_hi
1 parent e5fb138 commit f881626

File tree

22 files changed

+38
-31
lines changed

22 files changed

+38
-31
lines changed

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ impl<'a> LoweringContext<'a> {
879879
TyKind::Slice(ref ty) => hir::TySlice(self.lower_ty(ty, itctx)),
880880
TyKind::Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt, itctx)),
881881
TyKind::Rptr(ref region, ref mt) => {
882-
let span = t.span.with_hi(t.span.lo());
882+
let span = t.span.shrink_to_lo();
883883
let lifetime = match *region {
884884
Some(ref lt) => self.lower_lifetime(lt),
885885
None => self.elided_lifetime(span)

src/librustc_allocator/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
9999
f.cx.item_extern_crate(f.span, f.alloc),
100100
f.cx.item_use_simple(
101101
f.span,
102-
respan(f.span.empty(), VisibilityKind::Inherited),
102+
respan(f.span.shrink_to_lo(), VisibilityKind::Inherited),
103103
super_path,
104104
),
105105
];

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
10821082
if !cx.access_levels.is_reachable(it.id) {
10831083
let msg = "function is marked #[no_mangle], but not exported";
10841084
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg);
1085-
let insertion_span = it.span.with_hi(it.span.lo());
1085+
let insertion_span = it.span.shrink_to_lo();
10861086
if it.vis == hir::Visibility::Inherited {
10871087
err.span_suggestion(insertion_span,
10881088
"try making it public",
@@ -1107,7 +1107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
11071107
!cx.access_levels.is_reachable(it.id) {
11081108
let msg = "static is marked #[no_mangle], but not exported";
11091109
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg);
1110-
let insertion_span = it.span.with_hi(it.span.lo());
1110+
let insertion_span = it.span.shrink_to_lo();
11111111
if it.vis == hir::Visibility::Inherited {
11121112
err.span_suggestion(insertion_span,
11131113
"try making it public",

src/librustc_metadata/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl CrateStore for cstore::CStore {
523523
tokens: body.into(),
524524
legacy: def.legacy,
525525
}),
526-
vis: codemap::respan(local_span.empty(), ast::VisibilityKind::Inherited),
526+
vis: codemap::respan(local_span.shrink_to_lo(), ast::VisibilityKind::Inherited),
527527
tokens: None,
528528
})
529529
}

src/librustc_mir/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
422422
builder.args_and_body(block, &arguments, arg_scope, &body.value)
423423
}));
424424
// Attribute epilogue to function's closing brace
425-
let fn_end = span.with_lo(span.hi());
425+
let fn_end = span.shrink_to_hi();
426426
let source_info = builder.source_info(fn_end);
427427
let return_block = builder.return_block();
428428
builder.cfg.terminate(block, source_info,

src/librustc_resolve/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
756756
// don't suggest placing a use before the prelude
757757
// import or other generated ones
758758
if item.span.ctxt().outer().expn_info().is_none() {
759-
self.span = Some(item.span.with_hi(item.span.lo()));
759+
self.span = Some(item.span.shrink_to_lo());
760760
self.found_use = true;
761761
return;
762762
}
@@ -768,12 +768,12 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
768768
if item.span.ctxt().outer().expn_info().is_none() {
769769
// don't insert between attributes and an item
770770
if item.attrs.is_empty() {
771-
self.span = Some(item.span.with_hi(item.span.lo()));
771+
self.span = Some(item.span.shrink_to_lo());
772772
} else {
773773
// find the first attribute on the item
774774
for attr in &item.attrs {
775775
if self.span.map_or(true, |span| attr.span < span) {
776-
self.span = Some(attr.span.with_hi(attr.span.lo()));
776+
self.span = Some(attr.span.shrink_to_lo());
777777
}
778778
}
779779
}

src/librustc_save_analysis/dump_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12091209

12101210
fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {
12111211
self.process_macro_use(trait_item.span);
1212-
let vis_span = trait_item.span.empty();
1212+
let vis_span = trait_item.span.shrink_to_lo();
12131213
match trait_item.node {
12141214
ast::TraitItemKind::Const(ref ty, ref expr) => {
12151215
self.process_assoc_const(

src/librustc_typeck/check/method/suggest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, '
767767
// don't suggest placing a use before the prelude
768768
// import or other generated ones
769769
if item.span.ctxt().outer().expn_info().is_none() {
770-
self.span = Some(item.span.with_hi(item.span.lo()));
770+
self.span = Some(item.span.shrink_to_lo());
771771
self.found_use = true;
772772
return;
773773
}
@@ -779,12 +779,12 @@ impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, '
779779
if item.span.ctxt().outer().expn_info().is_none() {
780780
// don't insert between attributes and an item
781781
if item.attrs.is_empty() {
782-
self.span = Some(item.span.with_hi(item.span.lo()));
782+
self.span = Some(item.span.shrink_to_lo());
783783
} else {
784784
// find the first attribute on the item
785785
for attr in &item.attrs {
786786
if self.span.map_or(true, |span| attr.span < span) {
787-
self.span = Some(attr.span.with_hi(attr.span.lo()));
787+
self.span = Some(attr.span.shrink_to_lo());
788788
}
789789
}
790790
}

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25202520
if sugg_unit {
25212521
let sugg_span = sess.codemap().end_point(expr_sp);
25222522
// remove closing `)` from the span
2523-
let sugg_span = sugg_span.with_hi(sugg_span.lo());
2523+
let sugg_span = sugg_span.shrink_to_lo();
25242524
err.span_suggestion(
25252525
sugg_span,
25262526
"expected the unit value `()`; create it with empty parentheses",

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Path {
117117
return None;
118118
}
119119
}
120-
Some(PathSegment::crate_root(self.span.with_hi(self.span.lo())))
120+
Some(PathSegment::crate_root(self.span.shrink_to_lo()))
121121
}
122122

123123
pub fn is_global(&self) -> bool {

src/libsyntax/diagnostics/plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
220220
ty,
221221
expr,
222222
),
223-
vis: codemap::respan(span.empty(), ast::VisibilityKind::Public),
223+
vis: codemap::respan(span.shrink_to_lo(), ast::VisibilityKind::Public),
224224
span,
225225
tokens: None,
226226
})

src/libsyntax/ext/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
987987
attrs,
988988
id: ast::DUMMY_NODE_ID,
989989
node,
990-
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
990+
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
991991
span,
992992
tokens: None,
993993
})
@@ -1033,7 +1033,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
10331033
span: ty.span,
10341034
ty,
10351035
ident: None,
1036-
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
1036+
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
10371037
attrs: Vec::new(),
10381038
id: ast::DUMMY_NODE_ID,
10391039
}

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
239239
node: ast::ItemKind::Mod(krate.module),
240240
ident: keywords::Invalid.ident(),
241241
id: ast::DUMMY_NODE_ID,
242-
vis: respan(krate.span.empty(), ast::VisibilityKind::Public),
242+
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
243243
tokens: None,
244244
})));
245245

src/libsyntax/ext/quote.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ fn expand_wrapper(cx: &ExtCtxt,
858858
let path = path.iter().map(|s| s.to_string()).collect();
859859
let use_item = cx.item_use_glob(
860860
sp,
861-
respan(sp.empty(), ast::VisibilityKind::Inherited),
861+
respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
862862
ids_ext(path),
863863
);
864864
cx.stmt_item(sp, use_item)

src/libsyntax/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate,
10191019
ident: keywords::Invalid.ident(),
10201020
attrs,
10211021
id: ast::DUMMY_NODE_ID,
1022-
vis: respan(span.empty(), ast::VisibilityKind::Public),
1022+
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Public),
10231023
span,
10241024
node: ast::ItemKind::Mod(module),
10251025
tokens: None,

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'a> StringReader<'a> {
214214

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

220220
let mut sr = StringReader::new_raw_internal(sess, begin.fm);

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ impl<'a> Parser<'a> {
15121512
if self.eat(&token::RArrow) {
15131513
Ok(FunctionRetTy::Ty(self.parse_ty_common(allow_plus, true)?))
15141514
} else {
1515-
Ok(FunctionRetTy::Default(self.span.with_hi(self.span.lo())))
1515+
Ok(FunctionRetTy::Default(self.span.shrink_to_lo()))
15161516
}
15171517
}
15181518

src/libsyntax/print/pprust.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ impl<'a> State<'a> {
15681568
ti.ident,
15691569
ty,
15701570
default.as_ref().map(|expr| &**expr),
1571-
&codemap::respan(ti.span.empty(), ast::VisibilityKind::Inherited),
1571+
&codemap::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
15721572
)?;
15731573
}
15741574
ast::TraitItemKind::Method(ref sig, ref body) => {
@@ -1579,7 +1579,7 @@ impl<'a> State<'a> {
15791579
ti.ident,
15801580
&ti.generics,
15811581
sig,
1582-
&codemap::respan(ti.span.empty(), ast::VisibilityKind::Inherited),
1582+
&codemap::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
15831583
)?;
15841584
if let Some(ref body) = *body {
15851585
self.nbsp()?;

src/libsyntax/std_inject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<&str>
7676
is_sugared_doc: false,
7777
span,
7878
}],
79-
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
79+
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
8080
node: ast::ItemKind::Use(P(ast::UseTree {
8181
prefix: ast::Path {
8282
segments: [name, "prelude", "v1"].into_iter().map(|name| {

src/libsyntax_ext/deriving/generic/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'a> TraitDef<'a> {
530530
id: ast::DUMMY_NODE_ID,
531531
span: self.span,
532532
ident,
533-
vis: respan(self.span.empty(), ast::VisibilityKind::Inherited),
533+
vis: respan(self.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
534534
defaultness: ast::Defaultness::Final,
535535
attrs: Vec::new(),
536536
generics: Generics::default(),
@@ -977,7 +977,7 @@ impl<'a> MethodDef<'a> {
977977
attrs: self.attributes.clone(),
978978
generics: fn_generics,
979979
span: trait_.span,
980-
vis: respan(trait_.span.empty(), ast::VisibilityKind::Inherited),
980+
vis: respan(trait_.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
981981
defaultness: ast::Defaultness::Final,
982982
ident: method_ident,
983983
node: ast::ImplItemKind::Method(ast::MethodSig {

src/libsyntax_ext/global_asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
6060
asm,
6161
ctxt: cx.backtrace(),
6262
})),
63-
vis: respan(sp.empty(), ast::VisibilityKind::Inherited),
63+
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
6464
span: sp,
6565
tokens: None,
6666
})))

src/libsyntax_pos/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,15 @@ impl Span {
239239

240240
/// Returns a new span representing an empty span at the beginning of this span
241241
#[inline]
242-
pub fn empty(self) -> Span {
243-
self.with_hi(self.lo())
242+
pub fn shrink_to_lo(self) -> Span {
243+
let span = self.data();
244+
span.with_hi(span.lo)
245+
}
246+
/// Returns a new span representing an empty span at the end of this span
247+
#[inline]
248+
pub fn shrink_to_hi(self) -> Span {
249+
let span = self.data();
250+
span.with_lo(span.hi)
244251
}
245252

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

0 commit comments

Comments
 (0)