Skip to content

Commit 0cf9613

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

File tree

26 files changed

+126
-145
lines changed

26 files changed

+126
-145
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
@@ -258,7 +258,7 @@ impl<'a> LintLevelsBuilder<'a> {
258258
let meta_item = match li.meta_item() {
259259
Some(meta_item) if meta_item.is_word() => meta_item,
260260
_ => {
261-
let mut err = bad_attr(li.span);
261+
let mut err = bad_attr(li.span());
262262
if let Some(item) = li.meta_item() {
263263
if let ast::MetaItemKind::NameValue(_) = item.node {
264264
if item.path == "reason" {
@@ -290,7 +290,7 @@ impl<'a> LintLevelsBuilder<'a> {
290290
let name = meta_item.path.segments.last().expect("empty lint name").ident.name;
291291
match store.check_lint_name(&name.as_str(), tool_name) {
292292
CheckLintNameResult::Ok(ids) => {
293-
let src = LintSource::Node(name, li.span, reason);
293+
let src = LintSource::Node(name, li.span(), reason);
294294
for id in ids {
295295
specs.insert(*id, (level, src));
296296
}
@@ -301,7 +301,7 @@ impl<'a> LintLevelsBuilder<'a> {
301301
Ok(ids) => {
302302
let complete_name = &format!("{}::{}", tool_name.unwrap(), name);
303303
let src = LintSource::Node(
304-
Symbol::intern(complete_name), li.span, reason
304+
Symbol::intern(complete_name), li.span(), reason
305305
);
306306
for id in ids {
307307
specs.insert(*id, (level, src));
@@ -323,18 +323,18 @@ impl<'a> LintLevelsBuilder<'a> {
323323
lint,
324324
lvl,
325325
src,
326-
Some(li.span.into()),
326+
Some(li.span().into()),
327327
&msg,
328328
);
329329
err.span_suggestion(
330-
li.span,
330+
li.span(),
331331
"change it to",
332332
new_lint_name.to_string(),
333333
Applicability::MachineApplicable,
334334
).emit();
335335

336336
let src = LintSource::Node(
337-
Symbol::intern(&new_lint_name), li.span, reason
337+
Symbol::intern(&new_lint_name), li.span(), reason
338338
);
339339
for id in ids {
340340
specs.insert(*id, (level, src));
@@ -361,11 +361,11 @@ impl<'a> LintLevelsBuilder<'a> {
361361
lint,
362362
level,
363363
src,
364-
Some(li.span.into()),
364+
Some(li.span().into()),
365365
&msg);
366366
if let Some(new_name) = renamed {
367367
err.span_suggestion(
368-
li.span,
368+
li.span(),
369369
"use the new name",
370370
new_name,
371371
Applicability::MachineApplicable
@@ -384,12 +384,12 @@ impl<'a> LintLevelsBuilder<'a> {
384384
lint,
385385
level,
386386
src,
387-
Some(li.span.into()),
387+
Some(li.span().into()),
388388
&msg);
389389

390390
if let Some(suggestion) = suggestion {
391391
db.span_suggestion(
392-
li.span,
392+
li.span(),
393393
"did you mean",
394394
suggestion.to_string(),
395395
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
@@ -813,12 +813,12 @@ impl<'a> Resolver<'a> {
813813
MetaItemKind::List(nested_metas) => for nested_meta in nested_metas {
814814
match nested_meta.ident() {
815815
Some(ident) if nested_meta.is_word() => single_imports.push(ident),
816-
_ => ill_formed(nested_meta.span),
816+
_ => ill_formed(nested_meta.span()),
817817
}
818818
}
819819
MetaItemKind::NameValue(..) => ill_formed(meta.span),
820820
}
821-
None => ill_formed(attr.span()),
821+
None => ill_formed(attr.span),
822822
}
823823
}
824824
}

src/librustc_typeck/collect.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,7 @@ fn from_target_feature(
23262326
if !item.check_name("enable") {
23272327
let msg = "#[target_feature(..)] only accepts sub-keys of `enable` \
23282328
currently";
2329-
tcx.sess.span_err(item.span, &msg);
2329+
tcx.sess.span_err(item.span(), &msg);
23302330
continue;
23312331
}
23322332

@@ -2336,7 +2336,7 @@ fn from_target_feature(
23362336
None => {
23372337
let msg = "#[target_feature] attribute must be of the form \
23382338
#[target_feature(enable = \"..\")]";
2339-
tcx.sess.span_err(item.span, &msg);
2339+
tcx.sess.span_err(item.span(), &msg);
23402340
continue;
23412341
}
23422342
};
@@ -2352,7 +2352,7 @@ fn from_target_feature(
23522352
this target",
23532353
feature
23542354
);
2355-
let mut err = tcx.sess.struct_span_err(item.span, &msg);
2355+
let mut err = tcx.sess.struct_span_err(item.span(), &msg);
23562356

23572357
if feature.starts_with("+") {
23582358
let valid = whitelist.contains_key(&feature[1..]);
@@ -2387,7 +2387,7 @@ fn from_target_feature(
23872387
feature_gate::emit_feature_err(
23882388
&tcx.sess.parse_sess,
23892389
feature_gate.as_ref().unwrap(),
2390-
item.span,
2390+
item.span(),
23912391
feature_gate::GateIssue::Language,
23922392
&format!("the target feature `{}` is currently unstable", feature),
23932393
);
@@ -2549,7 +2549,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
25492549
} else {
25502550
span_err!(
25512551
tcx.sess.diagnostic(),
2552-
items[0].span,
2552+
items[0].span(),
25532553
E0535,
25542554
"invalid argument"
25552555
);
@@ -2583,7 +2583,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
25832583
} else if list_contains_name(&items[..], "speed") {
25842584
OptimizeAttr::Speed
25852585
} else {
2586-
err(items[0].span, "invalid argument");
2586+
err(items[0].span(), "invalid argument");
25872587
OptimizeAttr::None
25882588
}
25892589
}

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
@@ -777,15 +777,15 @@ pub struct Attributes {
777777
impl Attributes {
778778
/// Extracts the content from an attribute `#[doc(cfg(content))]`.
779779
fn extract_cfg(mi: &ast::MetaItem) -> Option<&ast::MetaItem> {
780-
use syntax::ast::NestedMetaItemKind::MetaItem;
780+
use syntax::ast::NestedMetaItem::MetaItem;
781781

782782
if let ast::MetaItemKind::List(ref nmis) = mi.node {
783783
if nmis.len() == 1 {
784-
if let MetaItem(ref cfg_mi) = nmis[0].node {
784+
if let MetaItem(ref cfg_mi) = nmis[0] {
785785
if cfg_mi.check_name("cfg") {
786786
if let ast::MetaItemKind::List(ref cfg_nmis) = cfg_mi.node {
787787
if cfg_nmis.len() == 1 {
788-
if let MetaItem(ref content_mi) = cfg_nmis[0].node {
788+
if let MetaItem(ref content_mi) = cfg_nmis[0] {
789789
return Some(content_mi);
790790
}
791791
}

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)