Skip to content

Commit f922e0d

Browse files
committed
Refactor away NestedMetaItemKind
Remove methods `Attribute::span` and `MetaItem::span` duplicating public fields
1 parent 0dd5ff1 commit f922e0d

File tree

26 files changed

+125
-144
lines changed

26 files changed

+125
-144
lines changed

src/librustc/hir/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
233233
_ => continue,
234234
};
235235
self.emit_repr_error(
236-
hint.span,
236+
hint.span(),
237237
item.span,
238238
&format!("attribute should be applied to {}", allowed_targets),
239239
&format!("not {} {}", article, allowed_targets),
@@ -242,7 +242,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
242242

243243
// Just point at all repr hints if there are any incompatibilities.
244244
// This is not ideal, but tracking precisely which ones are at fault is a huge hassle.
245-
let hint_spans = hints.iter().map(|hint| hint.span);
245+
let hint_spans = hints.iter().map(|hint| hint.span());
246246

247247
// Error on repr(transparent, <anything else>).
248248
if is_transparent && hints.len() > 1 {

src/librustc/ich/impls_syntax.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ fn hash_token<'a, 'gcx, W: StableHasherResult>(
360360
}
361361
}
362362

363-
impl_stable_hash_for_spanned!(::syntax::ast::NestedMetaItemKind);
364-
365-
impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItemKind {
363+
impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItem {
366364
MetaItem(meta_item),
367365
Literal(lit)
368366
});

src/librustc/lint/levels.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a> LintLevelsBuilder<'a> {
257257
let meta_item = match li.meta_item() {
258258
Some(meta_item) if meta_item.is_word() => meta_item,
259259
_ => {
260-
let mut err = bad_attr(li.span);
260+
let mut err = bad_attr(li.span());
261261
if let Some(item) = li.meta_item() {
262262
if let ast::MetaItemKind::NameValue(_) = item.node {
263263
if item.path == "reason" {
@@ -289,7 +289,7 @@ impl<'a> LintLevelsBuilder<'a> {
289289
let name = meta_item.path.segments.last().expect("empty lint name").ident.name;
290290
match store.check_lint_name(&name.as_str(), tool_name) {
291291
CheckLintNameResult::Ok(ids) => {
292-
let src = LintSource::Node(name, li.span, reason);
292+
let src = LintSource::Node(name, li.span(), reason);
293293
for id in ids {
294294
specs.insert(*id, (level, src));
295295
}
@@ -300,7 +300,7 @@ impl<'a> LintLevelsBuilder<'a> {
300300
Ok(ids) => {
301301
let complete_name = &format!("{}::{}", tool_name.unwrap(), name);
302302
let src = LintSource::Node(
303-
Symbol::intern(complete_name), li.span, reason
303+
Symbol::intern(complete_name), li.span(), reason
304304
);
305305
for id in ids {
306306
specs.insert(*id, (level, src));
@@ -322,18 +322,18 @@ impl<'a> LintLevelsBuilder<'a> {
322322
lint,
323323
lvl,
324324
src,
325-
Some(li.span.into()),
325+
Some(li.span().into()),
326326
&msg,
327327
);
328328
err.span_suggestion(
329-
li.span,
329+
li.span(),
330330
"change it to",
331331
new_lint_name.to_string(),
332332
Applicability::MachineApplicable,
333333
).emit();
334334

335335
let src = LintSource::Node(
336-
Symbol::intern(&new_lint_name), li.span, reason
336+
Symbol::intern(&new_lint_name), li.span(), reason
337337
);
338338
for id in ids {
339339
specs.insert(*id, (level, src));
@@ -360,11 +360,11 @@ impl<'a> LintLevelsBuilder<'a> {
360360
lint,
361361
level,
362362
src,
363-
Some(li.span.into()),
363+
Some(li.span().into()),
364364
&msg);
365365
if let Some(new_name) = renamed {
366366
err.span_suggestion(
367-
li.span,
367+
li.span(),
368368
"use the new name",
369369
new_name,
370370
Applicability::MachineApplicable
@@ -383,12 +383,12 @@ impl<'a> LintLevelsBuilder<'a> {
383383
lint,
384384
level,
385385
src,
386-
Some(li.span.into()),
386+
Some(li.span().into()),
387387
&msg);
388388

389389
if let Some(suggestion) = suggestion {
390390
db.span_suggestion(
391-
li.span,
391+
li.span(),
392392
"did you mean",
393393
suggestion.to_string(),
394394
Applicability::MachineApplicable,

src/librustc/traits/on_unimplemented.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
107107
{
108108
if let Some(items) = item.meta_item_list() {
109109
if let Ok(subcommand) =
110-
Self::parse(tcx, trait_def_id, &items, item.span, false)
110+
Self::parse(tcx, trait_def_id, &items, item.span(), false)
111111
{
112112
subcommands.push(subcommand);
113113
} else {
@@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
118118
}
119119

120120
// nothing found
121-
parse_error(tcx, item.span,
121+
parse_error(tcx, item.span(),
122122
"this attribute must have a valid value",
123123
"expected value here",
124124
Some(r#"eg `#[rustc_on_unimplemented(message="foo")]`"#));

src/librustc_incremental/assert_dep_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
104104
value = Some(ident.name),
105105
_ =>
106106
// FIXME better-encapsulate meta_item (don't directly access `node`)
107-
span_bug!(list_item.span(), "unexpected meta-item {:?}", list_item.node),
107+
span_bug!(list_item.span(), "unexpected meta-item {:?}", list_item),
108108
}
109109
}
110110
value

src/librustc_incremental/assert_module_sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> {
153153
return value;
154154
} else {
155155
self.tcx.sess.span_fatal(
156-
item.span,
156+
item.span(),
157157
&format!("associated value expected for `{}`", name));
158158
}
159159
}

src/librustc_incremental/persist/dirty_clean.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
430430
if DepNode::has_label_string(label) {
431431
if out.contains(label) {
432432
self.tcx.sess.span_fatal(
433-
item.span,
433+
item.span(),
434434
&format!("dep-node label `{}` is repeated", label));
435435
}
436436
out.insert(label.to_string());
437437
} else {
438438
self.tcx.sess.span_fatal(
439-
item.span,
439+
item.span(),
440440
&format!("dep-node label `{}` not recognized", label));
441441
}
442442
}
@@ -582,7 +582,7 @@ fn expect_associated_value(tcx: TyCtxt<'_, '_, '_>, item: &NestedMetaItem) -> as
582582
"expected an associated value".to_string()
583583
};
584584

585-
tcx.sess.span_fatal(item.span, &msg);
585+
tcx.sess.span_fatal(item.span(), &msg);
586586
}
587587
}
588588

src/librustc_metadata/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for Collector<'a, 'tcx> {
7676
k => {
7777
struct_span_err!(self.tcx.sess, m.span, E0458,
7878
"unknown kind: `{}`", k)
79-
.span_label(item.span, "unknown kind").emit();
79+
.span_label(item.span(), "unknown kind").emit();
8080
cstore::NativeUnknown
8181
}
8282
};

src/librustc_passes/layout_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> VarianceTest<'a, 'tcx> {
8686

8787
_ => {
8888
self.tcx.sess.span_err(
89-
meta_item.span,
89+
meta_item.span(),
9090
&format!("unrecognized field name `{}`", name),
9191
);
9292
}

src/librustc_plugin/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn load_plugins(sess: &Session,
5959
match plugin.ident_str() {
6060
Some(name) if !plugin.is_value_str() => {
6161
let args = plugin.meta_item_list().map(ToOwned::to_owned);
62-
loader.load_plugin(plugin.span, name, args.unwrap_or_default());
62+
loader.load_plugin(plugin.span(), name, args.unwrap_or_default());
6363
},
6464
_ => call_malformed_plugin_attribute(sess, attr.span),
6565
}

src/librustc_resolve/build_reduced_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,12 @@ impl<'a> Resolver<'a> {
816816
MetaItemKind::List(nested_metas) => for nested_meta in nested_metas {
817817
match nested_meta.ident() {
818818
Some(ident) if nested_meta.is_word() => single_imports.push(ident),
819-
_ => ill_formed(nested_meta.span),
819+
_ => ill_formed(nested_meta.span()),
820820
}
821821
}
822822
MetaItemKind::NameValue(..) => ill_formed(meta.span),
823823
}
824-
None => ill_formed(attr.span()),
824+
None => ill_formed(attr.span),
825825
}
826826
}
827827
}

src/librustc_typeck/collect.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ fn from_target_feature(
22692269
if !item.check_name("enable") {
22702270
let msg = "#[target_feature(..)] only accepts sub-keys of `enable` \
22712271
currently";
2272-
tcx.sess.span_err(item.span, &msg);
2272+
tcx.sess.span_err(item.span(), &msg);
22732273
continue;
22742274
}
22752275

@@ -2279,7 +2279,7 @@ fn from_target_feature(
22792279
None => {
22802280
let msg = "#[target_feature] attribute must be of the form \
22812281
#[target_feature(enable = \"..\")]";
2282-
tcx.sess.span_err(item.span, &msg);
2282+
tcx.sess.span_err(item.span(), &msg);
22832283
continue;
22842284
}
22852285
};
@@ -2295,7 +2295,7 @@ fn from_target_feature(
22952295
this target",
22962296
feature
22972297
);
2298-
let mut err = tcx.sess.struct_span_err(item.span, &msg);
2298+
let mut err = tcx.sess.struct_span_err(item.span(), &msg);
22992299

23002300
if feature.starts_with("+") {
23012301
let valid = whitelist.contains_key(&feature[1..]);
@@ -2330,7 +2330,7 @@ fn from_target_feature(
23302330
feature_gate::emit_feature_err(
23312331
&tcx.sess.parse_sess,
23322332
feature_gate.as_ref().unwrap(),
2333-
item.span,
2333+
item.span(),
23342334
feature_gate::GateIssue::Language,
23352335
&format!("the target feature `{}` is currently unstable", feature),
23362336
);
@@ -2492,7 +2492,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
24922492
} else {
24932493
span_err!(
24942494
tcx.sess.diagnostic(),
2495-
items[0].span,
2495+
items[0].span(),
24962496
E0535,
24972497
"invalid argument"
24982498
);
@@ -2526,7 +2526,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
25262526
} else if list_contains_name(&items[..], "speed") {
25272527
OptimizeAttr::Speed
25282528
} else {
2529-
err(items[0].span, "invalid argument");
2529+
err(items[0].span(), "invalid argument");
25302530
OptimizeAttr::None
25312531
}
25322532
}

src/librustdoc/clean/cfg.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fmt::{self, Write};
88
use std::ops;
99

1010
use syntax::symbol::Symbol;
11-
use syntax::ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, LitKind};
11+
use syntax::ast::{MetaItem, MetaItemKind, NestedMetaItem, LitKind};
1212
use syntax::parse::ParseSess;
1313
use syntax::feature_gate::Features;
1414

@@ -41,9 +41,9 @@ pub struct InvalidCfgError {
4141
impl Cfg {
4242
/// Parses a `NestedMetaItem` into a `Cfg`.
4343
fn parse_nested(nested_cfg: &NestedMetaItem) -> Result<Cfg, InvalidCfgError> {
44-
match nested_cfg.node {
45-
NestedMetaItemKind::MetaItem(ref cfg) => Cfg::parse(cfg),
46-
NestedMetaItemKind::Literal(ref lit) => Err(InvalidCfgError {
44+
match nested_cfg {
45+
NestedMetaItem::MetaItem(ref cfg) => Cfg::parse(cfg),
46+
NestedMetaItem::Literal(ref lit) => Err(InvalidCfgError {
4747
msg: "unexpected literal",
4848
span: lit.span,
4949
}),
@@ -442,9 +442,9 @@ mod test {
442442
path: Path::from_ident(Ident::from_str(stringify!($name))),
443443
node: MetaItemKind::List(vec![
444444
$(
445-
dummy_spanned(NestedMetaItemKind::MetaItem(
445+
NestedMetaItem::MetaItem(
446446
dummy_meta_item_word(stringify!($list)),
447-
)),
447+
),
448448
)*
449449
]),
450450
span: DUMMY_SP,
@@ -456,7 +456,7 @@ mod test {
456456
path: Path::from_ident(Ident::from_str(stringify!($name))),
457457
node: MetaItemKind::List(vec![
458458
$(
459-
dummy_spanned(NestedMetaItemKind::MetaItem($list)),
459+
NestedMetaItem::MetaItem($list),
460460
)*
461461
]),
462462
span: DUMMY_SP,

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -776,15 +776,15 @@ pub struct Attributes {
776776
impl Attributes {
777777
/// Extracts the content from an attribute `#[doc(cfg(content))]`.
778778
fn extract_cfg(mi: &ast::MetaItem) -> Option<&ast::MetaItem> {
779-
use syntax::ast::NestedMetaItemKind::MetaItem;
779+
use syntax::ast::NestedMetaItem::MetaItem;
780780

781781
if let ast::MetaItemKind::List(ref nmis) = mi.node {
782782
if nmis.len() == 1 {
783-
if let MetaItem(ref cfg_mi) = nmis[0].node {
783+
if let MetaItem(ref cfg_mi) = nmis[0] {
784784
if cfg_mi.check_name("cfg") {
785785
if let ast::MetaItemKind::List(ref cfg_nmis) = cfg_mi.node {
786786
if cfg_nmis.len() == 1 {
787-
if let MetaItem(ref content_mi) = cfg_nmis[0].node {
787+
if let MetaItem(ref content_mi) = cfg_nmis[0] {
788788
return Some(content_mi);
789789
}
790790
}

src/libsyntax/ast.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,11 @@ pub struct Crate {
443443
pub span: Span,
444444
}
445445

446-
/// A spanned compile-time attribute list item.
447-
pub type NestedMetaItem = Spanned<NestedMetaItemKind>;
448-
449446
/// Possible values inside of compile-time attribute lists.
450447
///
451448
/// E.g., the '..' in `#[name(..)]`.
452449
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
453-
pub enum NestedMetaItemKind {
450+
pub enum NestedMetaItem {
454451
/// A full MetaItem, for recursive meta items.
455452
MetaItem(MetaItem),
456453
/// A literal.
@@ -2207,7 +2204,7 @@ pub struct Item {
22072204
impl Item {
22082205
/// Return the span that encompasses the attributes.
22092206
pub fn span_with_attributes(&self) -> Span {
2210-
self.attrs.iter().fold(self.span, |acc, attr| acc.to(attr.span()))
2207+
self.attrs.iter().fold(self.span, |acc, attr| acc.to(attr.span))
22112208
}
22122209
}
22132210

0 commit comments

Comments
 (0)