Rename Span::empty
to Span::shrink_to_lo
, add Span::shrink_to_hi
This commit is contained in:
parent
e5fb13897d
commit
f88162654d
@ -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)
|
||||
|
@ -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,
|
||||
),
|
||||
];
|
||||
|
@ -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",
|
||||
@ -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",
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
})
|
||||
|
@ -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,
|
||||
})
|
||||
@ -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,
|
||||
}
|
||||
|
@ -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,
|
||||
})));
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) => {
|
||||
@ -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()?;
|
||||
|
@ -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| {
|
||||
|
@ -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(),
|
||||
@ -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 {
|
||||
|
@ -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,
|
||||
})))
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user