Skip to content

Commit

Permalink
Remove more duplicated spans
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 6, 2018
1 parent 62000c0 commit b3b5ef1
Show file tree
Hide file tree
Showing 33 changed files with 181 additions and 200 deletions.
16 changes: 9 additions & 7 deletions src/libproc_macro/lib.rs
Expand Up @@ -1099,13 +1099,15 @@ impl TokenTree {
self::TokenTree::Term(tt) => {
let ident = ast::Ident::new(tt.sym, tt.span.0);
let sym_str = tt.sym.as_str();
let token =
if sym_str.starts_with("'") { Lifetime(ident) }
else if sym_str.starts_with("r#") {
let name = Symbol::intern(&sym_str[2..]);
let ident = ast::Ident { name, ctxt: tt.span.0.ctxt() };
Ident(ident, true)
} else { Ident(ident, false) };
let token = if sym_str.starts_with("'") {
Lifetime(ident)
} else if sym_str.starts_with("r#") {
let name = Symbol::intern(&sym_str[2..]);
let ident = ast::Ident::new(name, ident.span);
Ident(ident, true)
} else {
Ident(ident, false)
};
return TokenTree::Token(tt.span.0, token).into();
}
self::TokenTree::Literal(self::Literal {
Expand Down
19 changes: 10 additions & 9 deletions src/librustc/hir/lowering.rs
Expand Up @@ -920,7 +920,7 @@ impl<'a> LoweringContext<'a> {
fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> {
label.map(|label| hir::Label {
name: label.ident.name,
span: label.span,
span: label.ident.span,
})
}

Expand Down Expand Up @@ -1810,7 +1810,7 @@ impl<'a> LoweringContext<'a> {
default: tp.default
.as_ref()
.map(|x| self.lower_ty(x, ImplTraitContext::Disallowed)),
span: tp.span,
span: tp.ident.span,
pure_wrt_drop: attr::contains_name(&tp.attrs, "may_dangle"),
synthetic: tp.attrs
.iter()
Expand All @@ -1822,21 +1822,22 @@ impl<'a> LoweringContext<'a> {
}

fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
let span = l.ident.span;
match self.lower_ident(l.ident) {
x if x == "'static" => self.new_named_lifetime(l.id, l.span, hir::LifetimeName::Static),
x if x == "'static" => self.new_named_lifetime(l.id, span, hir::LifetimeName::Static),
x if x == "'_" => match self.anonymous_lifetime_mode {
AnonymousLifetimeMode::CreateParameter => {
let fresh_name = self.collect_fresh_in_band_lifetime(l.span);
self.new_named_lifetime(l.id, l.span, fresh_name)
let fresh_name = self.collect_fresh_in_band_lifetime(span);
self.new_named_lifetime(l.id, span, fresh_name)
}

AnonymousLifetimeMode::PassThrough => {
self.new_named_lifetime(l.id, l.span, hir::LifetimeName::Underscore)
self.new_named_lifetime(l.id, span, hir::LifetimeName::Underscore)
}
},
name => {
self.maybe_collect_in_band_lifetime(l.span, name);
self.new_named_lifetime(l.id, l.span, hir::LifetimeName::Name(name))
self.maybe_collect_in_band_lifetime(span, name);
self.new_named_lifetime(l.id, span, hir::LifetimeName::Name(name))
}
}
}
Expand Down Expand Up @@ -2936,7 +2937,7 @@ impl<'a> LoweringContext<'a> {
ImplTraitContext::Disallowed,
);
let args = args.iter().map(|x| self.lower_expr(x)).collect();
hir::ExprMethodCall(hir_seg, seg.span, args)
hir::ExprMethodCall(hir_seg, seg.ident.span, args)
}
ExprKind::Binary(binop, ref lhs, ref rhs) => {
let binop = self.lower_binop(binop);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/def_collector.rs
Expand Up @@ -202,15 +202,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
lifetime_def.lifetime.id,
DefPathData::LifetimeDef(lifetime_def.lifetime.ident.name.as_str()),
REGULAR_SPACE,
lifetime_def.lifetime.span
lifetime_def.lifetime.ident.span
);
}
GenericParam::Type(ref ty_param) => {
self.create_def(
ty_param.id,
DefPathData::TypeParam(ty_param.ident.name.as_str()),
REGULAR_SPACE,
ty_param.span
ty_param.ident.span
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_syntax.rs
Expand Up @@ -162,7 +162,7 @@ impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 });
impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal });
impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst });
impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, span, ident });
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Expand Up @@ -952,8 +952,8 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> {
ast_visit::walk_ty(self, t);
}

fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
run_lints!(self, check_ident, early_passes, sp, id);
fn visit_ident(&mut self, ident: ast::Ident) {
run_lints!(self, check_ident, early_passes, ident);
}

fn visit_mod(&mut self, m: &'a ast::Mod, s: Span, _a: &[ast::Attribute], n: ast::NodeId) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Expand Up @@ -236,7 +236,7 @@ pub trait LateLintPass<'a, 'tcx>: LintPass {
}

pub trait EarlyLintPass: LintPass {
fn check_ident(&mut self, _: &EarlyContext, _: Span, _: ast::Ident) { }
fn check_ident(&mut self, _: &EarlyContext, _: ast::Ident) { }
fn check_crate(&mut self, _: &EarlyContext, _: &ast::Crate) { }
fn check_crate_post(&mut self, _: &EarlyContext, _: &ast::Crate) { }
fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
Expand Down
35 changes: 18 additions & 17 deletions src/librustc_passes/ast_validation.rs
Expand Up @@ -36,19 +36,20 @@ impl<'a> AstValidator<'a> {
&self.session.parse_sess.span_diagnostic
}

fn check_lifetime(&self, lifetime: &Lifetime) {
fn check_lifetime(&self, ident: Ident) {
let valid_names = [keywords::UnderscoreLifetime.name(),
keywords::StaticLifetime.name(),
keywords::Invalid.name()];
if !valid_names.contains(&lifetime.ident.name) &&
token::is_reserved_ident(lifetime.ident.without_first_quote()) {
self.err_handler().span_err(lifetime.span, "lifetimes cannot use keyword names");
if !valid_names.contains(&ident.name) &&
token::is_reserved_ident(ident.without_first_quote()) {
self.err_handler().span_err(ident.span, "lifetimes cannot use keyword names");
}
}

fn check_label(&self, label: Ident, span: Span) {
if token::is_reserved_ident(label.without_first_quote()) {
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
fn check_label(&self, ident: Ident) {
if token::is_reserved_ident(ident.without_first_quote()) {
self.err_handler()
.span_err(ident.span, &format!("invalid label name `{}`", ident.name));
}
}

Expand Down Expand Up @@ -144,7 +145,7 @@ impl<'a> AstValidator<'a> {
let non_lifetime_param_spans : Vec<_> = params.iter()
.filter_map(|param| match *param {
GenericParam::Lifetime(_) => None,
GenericParam::Type(ref t) => Some(t.span),
GenericParam::Type(ref t) => Some(t.ident.span),
}).collect();
if !non_lifetime_param_spans.is_empty() {
self.err_handler().span_err(non_lifetime_param_spans,
Expand All @@ -156,7 +157,7 @@ impl<'a> AstValidator<'a> {
match *param {
GenericParam::Lifetime(ref l) => {
if !l.bounds.is_empty() {
let spans : Vec<_> = l.bounds.iter().map(|b| b.span).collect();
let spans: Vec<_> = l.bounds.iter().map(|b| b.ident.span).collect();
self.err_handler().span_err(spans,
"lifetime bounds cannot be used in this context");
}
Expand Down Expand Up @@ -193,7 +194,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
for bound in bounds {
if let RegionTyParamBound(ref lifetime) = *bound {
if any_lifetime_bounds {
span_err!(self.session, lifetime.span, E0226,
span_err!(self.session, lifetime.ident.span, E0226,
"only a single explicit lifetime bound is permitted");
break;
}
Expand Down Expand Up @@ -234,12 +235,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

fn visit_label(&mut self, label: &'a Label) {
self.check_label(label.ident, label.span);
self.check_label(label.ident);
visit::walk_label(self, label);
}

fn visit_lifetime(&mut self, lifetime: &'a Lifetime) {
self.check_lifetime(lifetime);
self.check_lifetime(lifetime.ident);
visit::walk_lifetime(self, lifetime);
}

Expand Down Expand Up @@ -328,19 +329,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
ItemKind::TraitAlias(Generics { ref params, .. }, ..) => {
for param in params {
if let GenericParam::Type(TyParam {
ident,
ref bounds,
ref default,
span,
..
}) = *param
{
if !bounds.is_empty() {
self.err_handler().span_err(span,
self.err_handler().span_err(ident.span,
"type parameters on the left side of a \
trait alias cannot be bounded");
}
if !default.is_none() {
self.err_handler().span_err(span,
self.err_handler().span_err(ident.span,
"type parameters on the left side of a \
trait alias cannot have defaults");
}
Expand Down Expand Up @@ -408,7 +409,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
match (param, seen_non_lifetime_param) {
(&GenericParam::Lifetime(ref ld), true) => {
self.err_handler()
.span_err(ld.lifetime.span, "lifetime parameters must be leading");
.span_err(ld.lifetime.ident.span, "lifetime parameters must be leading");
},
(&GenericParam::Lifetime(_), false) => {}
_ => {
Expand All @@ -417,7 +418,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

if let GenericParam::Type(ref ty_param @ TyParam { default: Some(_), .. }) = *param {
seen_default = Some(ty_param.span);
seen_default = Some(ty_param.ident.span);
} else if let Some(span) = seen_default {
self.err_handler()
.span_err(span, "type parameters with a default must be trailing");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -195,7 +195,7 @@ impl<'a> Resolver<'a> {
ast::UseTreeKind::Nested(ref items) => {
let prefix = ast::Path {
segments: module_path.into_iter()
.map(|ident| ast::PathSegment::from_ident(ident, ident.span))
.map(|ident| ast::PathSegment::from_ident(ident))
.collect(),
span: path.span,
};
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_resolve/lib.rs
Expand Up @@ -2281,9 +2281,9 @@ impl<'a> Resolver<'a> {
ident.name,
span,
);
resolve_error(self, type_parameter.span, err);
resolve_error(self, type_parameter.ident.span, err);
}
seen_bindings.entry(ident).or_insert(type_parameter.span);
seen_bindings.entry(ident).or_insert(type_parameter.ident.span);

// plain insert (no renaming)
let def_id = self.definitions.local_def_id(type_parameter.id);
Expand Down Expand Up @@ -3634,7 +3634,7 @@ impl<'a> Resolver<'a> {
});
self.record_def(expr.id, err_path_resolution());
resolve_error(self,
label.span,
label.ident.span,
ResolutionError::UndeclaredLabel(&label.ident.name.as_str(),
close_match));
}
Expand Down Expand Up @@ -3865,7 +3865,7 @@ impl<'a> Resolver<'a> {
if filter_fn(name_binding.def()) {
// create the path
let mut segms = path_segments.clone();
segms.push(ast::PathSegment::from_ident(ident, name_binding.span));
segms.push(ast::PathSegment::from_ident(ident));
let path = Path {
span: name_binding.span,
segments: segms,
Expand All @@ -3887,7 +3887,7 @@ impl<'a> Resolver<'a> {
if let Some(module) = name_binding.module() {
// form the path
let mut path_segments = path_segments.clone();
path_segments.push(ast::PathSegment::from_ident(ident, name_binding.span));
path_segments.push(ast::PathSegment::from_ident(ident));

if !in_module_is_extern || name_binding.vis == ty::Visibility::Public {
// add the module to the lookup
Expand Down Expand Up @@ -3926,7 +3926,7 @@ impl<'a> Resolver<'a> {
if let Some(module) = name_binding.module() {
// form the path
let mut path_segments = path_segments.clone();
path_segments.push(ast::PathSegment::from_ident(ident, name_binding.span));
path_segments.push(ast::PathSegment::from_ident(ident));
if module.def() == Some(module_def) {
let path = Path {
span: name_binding.span,
Expand Down Expand Up @@ -3958,7 +3958,7 @@ impl<'a> Resolver<'a> {
enum_module.for_each_child_stable(|ident, _, name_binding| {
if let Def::Variant(..) = name_binding.def() {
let mut segms = enum_import_suggestion.path.segments.clone();
segms.push(ast::PathSegment::from_ident(ident, name_binding.span));
segms.push(ast::PathSegment::from_ident(ident));
variants.push(Path {
span: name_binding.span,
segments: segms,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/macros.rs
Expand Up @@ -141,10 +141,10 @@ impl<'a> base::Resolver for Resolver<'a> {
path.segments[0].ident.name = keywords::CrateRoot.name();
let module = self.0.resolve_crate_root(ident.span.ctxt(), true);
if !module.is_local() {
let span = path.segments[0].span;
let span = path.segments[0].ident.span;
path.segments.insert(1, match module.kind {
ModuleKind::Def(_, name) => ast::PathSegment::from_ident(
ast::Ident::with_empty_ctxt(name), span
ast::Ident::with_empty_ctxt(name).with_span_pos(span)
),
_ => unreachable!(),
})
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<'a> base::Resolver for Resolver<'a> {
}).into();
}
return Some(ast::Attribute {
path: ast::Path::from_ident(span, Ident::with_empty_ctxt(legacy_name)),
path: ast::Path::from_ident(Ident::new(legacy_name, span)),
tokens: TokenStream::empty(),
id: attr::mk_attr_id(),
style: ast::AttrStyle::Outer,
Expand Down

0 comments on commit b3b5ef1

Please sign in to comment.