Skip to content

Commit b3b5ef1

Browse files
committed
Remove more duplicated spans
1 parent 62000c0 commit b3b5ef1

File tree

33 files changed

+181
-200
lines changed

33 files changed

+181
-200
lines changed

src/libproc_macro/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,13 +1099,15 @@ impl TokenTree {
10991099
self::TokenTree::Term(tt) => {
11001100
let ident = ast::Ident::new(tt.sym, tt.span.0);
11011101
let sym_str = tt.sym.as_str();
1102-
let token =
1103-
if sym_str.starts_with("'") { Lifetime(ident) }
1104-
else if sym_str.starts_with("r#") {
1105-
let name = Symbol::intern(&sym_str[2..]);
1106-
let ident = ast::Ident { name, ctxt: tt.span.0.ctxt() };
1107-
Ident(ident, true)
1108-
} else { Ident(ident, false) };
1102+
let token = if sym_str.starts_with("'") {
1103+
Lifetime(ident)
1104+
} else if sym_str.starts_with("r#") {
1105+
let name = Symbol::intern(&sym_str[2..]);
1106+
let ident = ast::Ident::new(name, ident.span);
1107+
Ident(ident, true)
1108+
} else {
1109+
Ident(ident, false)
1110+
};
11091111
return TokenTree::Token(tt.span.0, token).into();
11101112
}
11111113
self::TokenTree::Literal(self::Literal {

src/librustc/hir/lowering.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ impl<'a> LoweringContext<'a> {
920920
fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> {
921921
label.map(|label| hir::Label {
922922
name: label.ident.name,
923-
span: label.span,
923+
span: label.ident.span,
924924
})
925925
}
926926

@@ -1810,7 +1810,7 @@ impl<'a> LoweringContext<'a> {
18101810
default: tp.default
18111811
.as_ref()
18121812
.map(|x| self.lower_ty(x, ImplTraitContext::Disallowed)),
1813-
span: tp.span,
1813+
span: tp.ident.span,
18141814
pure_wrt_drop: attr::contains_name(&tp.attrs, "may_dangle"),
18151815
synthetic: tp.attrs
18161816
.iter()
@@ -1822,21 +1822,22 @@ impl<'a> LoweringContext<'a> {
18221822
}
18231823

18241824
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
1825+
let span = l.ident.span;
18251826
match self.lower_ident(l.ident) {
1826-
x if x == "'static" => self.new_named_lifetime(l.id, l.span, hir::LifetimeName::Static),
1827+
x if x == "'static" => self.new_named_lifetime(l.id, span, hir::LifetimeName::Static),
18271828
x if x == "'_" => match self.anonymous_lifetime_mode {
18281829
AnonymousLifetimeMode::CreateParameter => {
1829-
let fresh_name = self.collect_fresh_in_band_lifetime(l.span);
1830-
self.new_named_lifetime(l.id, l.span, fresh_name)
1830+
let fresh_name = self.collect_fresh_in_band_lifetime(span);
1831+
self.new_named_lifetime(l.id, span, fresh_name)
18311832
}
18321833

18331834
AnonymousLifetimeMode::PassThrough => {
1834-
self.new_named_lifetime(l.id, l.span, hir::LifetimeName::Underscore)
1835+
self.new_named_lifetime(l.id, span, hir::LifetimeName::Underscore)
18351836
}
18361837
},
18371838
name => {
1838-
self.maybe_collect_in_band_lifetime(l.span, name);
1839-
self.new_named_lifetime(l.id, l.span, hir::LifetimeName::Name(name))
1839+
self.maybe_collect_in_band_lifetime(span, name);
1840+
self.new_named_lifetime(l.id, span, hir::LifetimeName::Name(name))
18401841
}
18411842
}
18421843
}
@@ -2936,7 +2937,7 @@ impl<'a> LoweringContext<'a> {
29362937
ImplTraitContext::Disallowed,
29372938
);
29382939
let args = args.iter().map(|x| self.lower_expr(x)).collect();
2939-
hir::ExprMethodCall(hir_seg, seg.span, args)
2940+
hir::ExprMethodCall(hir_seg, seg.ident.span, args)
29402941
}
29412942
ExprKind::Binary(binop, ref lhs, ref rhs) => {
29422943
let binop = self.lower_binop(binop);

src/librustc/hir/map/def_collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
202202
lifetime_def.lifetime.id,
203203
DefPathData::LifetimeDef(lifetime_def.lifetime.ident.name.as_str()),
204204
REGULAR_SPACE,
205-
lifetime_def.lifetime.span
205+
lifetime_def.lifetime.ident.span
206206
);
207207
}
208208
GenericParam::Type(ref ty_param) => {
209209
self.create_def(
210210
ty_param.id,
211211
DefPathData::TypeParam(ty_param.ident.name.as_str()),
212212
REGULAR_SPACE,
213-
ty_param.span
213+
ty_param.ident.span
214214
);
215215
}
216216
}

src/librustc/ich/impls_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 });
162162
impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal });
163163
impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst });
164164
impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });
165-
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, span, ident });
165+
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
166166
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
167167
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });
168168

src/librustc/lint/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,8 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> {
952952
ast_visit::walk_ty(self, t);
953953
}
954954

955-
fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
956-
run_lints!(self, check_ident, early_passes, sp, id);
955+
fn visit_ident(&mut self, ident: ast::Ident) {
956+
run_lints!(self, check_ident, early_passes, ident);
957957
}
958958

959959
fn visit_mod(&mut self, m: &'a ast::Mod, s: Span, _a: &[ast::Attribute], n: ast::NodeId) {

src/librustc/lint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ pub trait LateLintPass<'a, 'tcx>: LintPass {
236236
}
237237

238238
pub trait EarlyLintPass: LintPass {
239-
fn check_ident(&mut self, _: &EarlyContext, _: Span, _: ast::Ident) { }
239+
fn check_ident(&mut self, _: &EarlyContext, _: ast::Ident) { }
240240
fn check_crate(&mut self, _: &EarlyContext, _: &ast::Crate) { }
241241
fn check_crate_post(&mut self, _: &EarlyContext, _: &ast::Crate) { }
242242
fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }

src/librustc_passes/ast_validation.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ impl<'a> AstValidator<'a> {
3636
&self.session.parse_sess.span_diagnostic
3737
}
3838

39-
fn check_lifetime(&self, lifetime: &Lifetime) {
39+
fn check_lifetime(&self, ident: Ident) {
4040
let valid_names = [keywords::UnderscoreLifetime.name(),
4141
keywords::StaticLifetime.name(),
4242
keywords::Invalid.name()];
43-
if !valid_names.contains(&lifetime.ident.name) &&
44-
token::is_reserved_ident(lifetime.ident.without_first_quote()) {
45-
self.err_handler().span_err(lifetime.span, "lifetimes cannot use keyword names");
43+
if !valid_names.contains(&ident.name) &&
44+
token::is_reserved_ident(ident.without_first_quote()) {
45+
self.err_handler().span_err(ident.span, "lifetimes cannot use keyword names");
4646
}
4747
}
4848

49-
fn check_label(&self, label: Ident, span: Span) {
50-
if token::is_reserved_ident(label.without_first_quote()) {
51-
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
49+
fn check_label(&self, ident: Ident) {
50+
if token::is_reserved_ident(ident.without_first_quote()) {
51+
self.err_handler()
52+
.span_err(ident.span, &format!("invalid label name `{}`", ident.name));
5253
}
5354
}
5455

@@ -144,7 +145,7 @@ impl<'a> AstValidator<'a> {
144145
let non_lifetime_param_spans : Vec<_> = params.iter()
145146
.filter_map(|param| match *param {
146147
GenericParam::Lifetime(_) => None,
147-
GenericParam::Type(ref t) => Some(t.span),
148+
GenericParam::Type(ref t) => Some(t.ident.span),
148149
}).collect();
149150
if !non_lifetime_param_spans.is_empty() {
150151
self.err_handler().span_err(non_lifetime_param_spans,
@@ -156,7 +157,7 @@ impl<'a> AstValidator<'a> {
156157
match *param {
157158
GenericParam::Lifetime(ref l) => {
158159
if !l.bounds.is_empty() {
159-
let spans : Vec<_> = l.bounds.iter().map(|b| b.span).collect();
160+
let spans: Vec<_> = l.bounds.iter().map(|b| b.ident.span).collect();
160161
self.err_handler().span_err(spans,
161162
"lifetime bounds cannot be used in this context");
162163
}
@@ -193,7 +194,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
193194
for bound in bounds {
194195
if let RegionTyParamBound(ref lifetime) = *bound {
195196
if any_lifetime_bounds {
196-
span_err!(self.session, lifetime.span, E0226,
197+
span_err!(self.session, lifetime.ident.span, E0226,
197198
"only a single explicit lifetime bound is permitted");
198199
break;
199200
}
@@ -234,12 +235,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
234235
}
235236

236237
fn visit_label(&mut self, label: &'a Label) {
237-
self.check_label(label.ident, label.span);
238+
self.check_label(label.ident);
238239
visit::walk_label(self, label);
239240
}
240241

241242
fn visit_lifetime(&mut self, lifetime: &'a Lifetime) {
242-
self.check_lifetime(lifetime);
243+
self.check_lifetime(lifetime.ident);
243244
visit::walk_lifetime(self, lifetime);
244245
}
245246

@@ -328,19 +329,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
328329
ItemKind::TraitAlias(Generics { ref params, .. }, ..) => {
329330
for param in params {
330331
if let GenericParam::Type(TyParam {
332+
ident,
331333
ref bounds,
332334
ref default,
333-
span,
334335
..
335336
}) = *param
336337
{
337338
if !bounds.is_empty() {
338-
self.err_handler().span_err(span,
339+
self.err_handler().span_err(ident.span,
339340
"type parameters on the left side of a \
340341
trait alias cannot be bounded");
341342
}
342343
if !default.is_none() {
343-
self.err_handler().span_err(span,
344+
self.err_handler().span_err(ident.span,
344345
"type parameters on the left side of a \
345346
trait alias cannot have defaults");
346347
}
@@ -408,7 +409,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
408409
match (param, seen_non_lifetime_param) {
409410
(&GenericParam::Lifetime(ref ld), true) => {
410411
self.err_handler()
411-
.span_err(ld.lifetime.span, "lifetime parameters must be leading");
412+
.span_err(ld.lifetime.ident.span, "lifetime parameters must be leading");
412413
},
413414
(&GenericParam::Lifetime(_), false) => {}
414415
_ => {
@@ -417,7 +418,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
417418
}
418419

419420
if let GenericParam::Type(ref ty_param @ TyParam { default: Some(_), .. }) = *param {
420-
seen_default = Some(ty_param.span);
421+
seen_default = Some(ty_param.ident.span);
421422
} else if let Some(span) = seen_default {
422423
self.err_handler()
423424
.span_err(span, "type parameters with a default must be trailing");

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'a> Resolver<'a> {
195195
ast::UseTreeKind::Nested(ref items) => {
196196
let prefix = ast::Path {
197197
segments: module_path.into_iter()
198-
.map(|ident| ast::PathSegment::from_ident(ident, ident.span))
198+
.map(|ident| ast::PathSegment::from_ident(ident))
199199
.collect(),
200200
span: path.span,
201201
};

src/librustc_resolve/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,9 +2281,9 @@ impl<'a> Resolver<'a> {
22812281
ident.name,
22822282
span,
22832283
);
2284-
resolve_error(self, type_parameter.span, err);
2284+
resolve_error(self, type_parameter.ident.span, err);
22852285
}
2286-
seen_bindings.entry(ident).or_insert(type_parameter.span);
2286+
seen_bindings.entry(ident).or_insert(type_parameter.ident.span);
22872287

22882288
// plain insert (no renaming)
22892289
let def_id = self.definitions.local_def_id(type_parameter.id);
@@ -3634,7 +3634,7 @@ impl<'a> Resolver<'a> {
36343634
});
36353635
self.record_def(expr.id, err_path_resolution());
36363636
resolve_error(self,
3637-
label.span,
3637+
label.ident.span,
36383638
ResolutionError::UndeclaredLabel(&label.ident.name.as_str(),
36393639
close_match));
36403640
}
@@ -3865,7 +3865,7 @@ impl<'a> Resolver<'a> {
38653865
if filter_fn(name_binding.def()) {
38663866
// create the path
38673867
let mut segms = path_segments.clone();
3868-
segms.push(ast::PathSegment::from_ident(ident, name_binding.span));
3868+
segms.push(ast::PathSegment::from_ident(ident));
38693869
let path = Path {
38703870
span: name_binding.span,
38713871
segments: segms,
@@ -3887,7 +3887,7 @@ impl<'a> Resolver<'a> {
38873887
if let Some(module) = name_binding.module() {
38883888
// form the path
38893889
let mut path_segments = path_segments.clone();
3890-
path_segments.push(ast::PathSegment::from_ident(ident, name_binding.span));
3890+
path_segments.push(ast::PathSegment::from_ident(ident));
38913891

38923892
if !in_module_is_extern || name_binding.vis == ty::Visibility::Public {
38933893
// add the module to the lookup
@@ -3926,7 +3926,7 @@ impl<'a> Resolver<'a> {
39263926
if let Some(module) = name_binding.module() {
39273927
// form the path
39283928
let mut path_segments = path_segments.clone();
3929-
path_segments.push(ast::PathSegment::from_ident(ident, name_binding.span));
3929+
path_segments.push(ast::PathSegment::from_ident(ident));
39303930
if module.def() == Some(module_def) {
39313931
let path = Path {
39323932
span: name_binding.span,
@@ -3958,7 +3958,7 @@ impl<'a> Resolver<'a> {
39583958
enum_module.for_each_child_stable(|ident, _, name_binding| {
39593959
if let Def::Variant(..) = name_binding.def() {
39603960
let mut segms = enum_import_suggestion.path.segments.clone();
3961-
segms.push(ast::PathSegment::from_ident(ident, name_binding.span));
3961+
segms.push(ast::PathSegment::from_ident(ident));
39623962
variants.push(Path {
39633963
span: name_binding.span,
39643964
segments: segms,

src/librustc_resolve/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ impl<'a> base::Resolver for Resolver<'a> {
141141
path.segments[0].ident.name = keywords::CrateRoot.name();
142142
let module = self.0.resolve_crate_root(ident.span.ctxt(), true);
143143
if !module.is_local() {
144-
let span = path.segments[0].span;
144+
let span = path.segments[0].ident.span;
145145
path.segments.insert(1, match module.kind {
146146
ModuleKind::Def(_, name) => ast::PathSegment::from_ident(
147-
ast::Ident::with_empty_ctxt(name), span
147+
ast::Ident::with_empty_ctxt(name).with_span_pos(span)
148148
),
149149
_ => unreachable!(),
150150
})
@@ -277,7 +277,7 @@ impl<'a> base::Resolver for Resolver<'a> {
277277
}).into();
278278
}
279279
return Some(ast::Attribute {
280-
path: ast::Path::from_ident(span, Ident::with_empty_ctxt(legacy_name)),
280+
path: ast::Path::from_ident(Ident::new(legacy_name, span)),
281281
tokens: TokenStream::empty(),
282282
id: attr::mk_attr_id(),
283283
style: ast::AttrStyle::Outer,

0 commit comments

Comments
 (0)