Skip to content

Commit 73d2da0

Browse files
committed
Remove Spanned from mk_name_value_item_str and expr_to_spanned_string
1 parent 1cdcea9 commit 73d2da0

File tree

8 files changed

+31
-29
lines changed

8 files changed

+31
-29
lines changed

src/librustdoc/clean/cfg/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::*;
33
use syntax_pos::DUMMY_SP;
44
use syntax::ast::*;
55
use syntax::attr;
6-
use syntax::source_map::dummy_spanned;
76
use syntax::symbol::Symbol;
87
use syntax::with_default_globals;
98

@@ -181,7 +180,8 @@ fn test_parse_ok() {
181180

182181
let mi = attr::mk_name_value_item_str(
183182
Ident::from_str("all"),
184-
dummy_spanned(Symbol::intern("done"))
183+
Symbol::intern("done"),
184+
DUMMY_SP,
185185
);
186186
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
187187

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
2929
use syntax::ast::{self, AttrStyle, Ident};
3030
use syntax::attr;
3131
use syntax::ext::base::MacroKind;
32-
use syntax::source_map::{dummy_spanned, Spanned};
32+
use syntax::source_map::{DUMMY_SP, Spanned};
3333
use syntax::symbol::{Symbol, kw, sym};
3434
use syntax::symbol::InternedString;
3535
use syntax_pos::{self, Pos, FileName};
@@ -930,8 +930,8 @@ impl Attributes {
930930
if attr.check_name(sym::enable) {
931931
if let Some(feat) = attr.value_str() {
932932
let meta = attr::mk_name_value_item_str(
933-
Ident::with_empty_ctxt(sym::target_feature),
934-
dummy_spanned(feat));
933+
Ident::with_empty_ctxt(sym::target_feature), feat, DUMMY_SP
934+
);
935935
if let Ok(feat_cfg) = Cfg::parse(&meta) {
936936
cfg &= feat_cfg;
937937
}

src/libsyntax/ast.rs

-2
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,6 @@ pub struct Field {
939939
pub id: NodeId,
940940
}
941941

942-
pub type SpannedIdent = Spanned<Ident>;
943-
944942
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
945943
pub enum BlockCheckMode {
946944
Default,

src/libsyntax/attr/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::ast::{AttrId, AttrStyle, Name, Ident, Path, PathSegment};
1313
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
1414
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
1515
use crate::mut_visit::visit_clobber;
16-
use crate::source_map::{BytePos, Spanned, dummy_spanned};
16+
use crate::source_map::{BytePos, Spanned, DUMMY_SP};
1717
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
1818
use crate::parse::parser::Parser;
1919
use crate::parse::{self, ParseSess, PResult};
@@ -328,7 +328,9 @@ impl Attribute {
328328
let comment = self.value_str().unwrap();
329329
let meta = mk_name_value_item_str(
330330
Ident::with_empty_ctxt(sym::doc),
331-
dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
331+
Symbol::intern(&strip_doc_comment_decoration(&comment.as_str())),
332+
DUMMY_SP,
333+
);
332334
f(&Attribute {
333335
id: self.id,
334336
style: self.style,
@@ -345,9 +347,9 @@ impl Attribute {
345347

346348
/* Constructors */
347349

348-
pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem {
349-
let lit_kind = LitKind::Str(value.node, ast::StrStyle::Cooked);
350-
mk_name_value_item(ident, lit_kind, value.span)
350+
pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> MetaItem {
351+
let lit_kind = LitKind::Str(str, ast::StrStyle::Cooked);
352+
mk_name_value_item(ident, lit_kind, str_span)
351353
}
352354

353355
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {

src/libsyntax/ext/base.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ast::{self, Attribute, Name, PatKind};
22
use crate::attr::{HasAttrs, Stability, Deprecation};
3-
use crate::source_map::{SourceMap, Spanned, respan};
3+
use crate::source_map::SourceMap;
44
use crate::edition::Edition;
55
use crate::ext::expand::{self, AstFragment, Invocation};
66
use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency};
@@ -916,7 +916,7 @@ pub fn expr_to_spanned_string<'a>(
916916
cx: &'a mut ExtCtxt<'_>,
917917
mut expr: P<ast::Expr>,
918918
err_msg: &str,
919-
) -> Result<Spanned<(Symbol, ast::StrStyle)>, Option<DiagnosticBuilder<'a>>> {
919+
) -> Result<(Symbol, ast::StrStyle, Span), Option<DiagnosticBuilder<'a>>> {
920920
// Update `expr.span`'s ctxt now in case expr is an `include!` macro invocation.
921921
expr.span = expr.span.apply_mark(cx.current_expansion.id);
922922

@@ -926,7 +926,7 @@ pub fn expr_to_spanned_string<'a>(
926926

927927
Err(match expr.node {
928928
ast::ExprKind::Lit(ref l) => match l.node {
929-
ast::LitKind::Str(s, style) => return Ok(respan(expr.span, (s, style))),
929+
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
930930
ast::LitKind::Err(_) => None,
931931
_ => Some(cx.struct_span_err(l.span, err_msg))
932932
},
@@ -940,7 +940,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt<'_>, expr: P<ast::Expr>, err_msg: &str)
940940
expr_to_spanned_string(cx, expr, err_msg)
941941
.map_err(|err| err.map(|mut err| err.emit()))
942942
.ok()
943-
.map(|s| s.node)
943+
.map(|(symbol, style, _)| (symbol, style))
944944
}
945945

946946
/// Non-fatally assert that `tts` is empty. Note that this function

src/libsyntax/ext/expand.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path};
22
use crate::ast::{MacStmtStyle, StmtKind, ItemKind};
33
use crate::attr::{self, HasAttrs};
4-
use crate::source_map::{dummy_spanned, respan};
4+
use crate::source_map::respan;
55
use crate::config::StripUnconfigured;
66
use crate::ext::base::*;
77
use crate::ext::proc_macro::collect_derives;
@@ -1251,13 +1251,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12511251
ast::NestedMetaItem::MetaItem(
12521252
attr::mk_name_value_item_str(
12531253
Ident::with_empty_ctxt(sym::file),
1254-
dummy_spanned(file),
1254+
file,
1255+
DUMMY_SP,
12551256
),
12561257
),
12571258
ast::NestedMetaItem::MetaItem(
12581259
attr::mk_name_value_item_str(
12591260
Ident::with_empty_ctxt(sym::contents),
1260-
dummy_spanned(src_interned),
1261+
src_interned,
1262+
DUMMY_SP,
12611263
),
12621264
),
12631265
];

src/libsyntax/parse/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ fn get_spans_of_pat_idents(src: &str) -> Vec<Span> {
172172
impl<'a> crate::visit::Visitor<'a> for PatIdentVisitor {
173173
fn visit_pat(&mut self, p: &'a ast::Pat) {
174174
match p.node {
175-
PatKind::Ident(_ , ref spannedident, _) => {
176-
self.spans.push(spannedident.span.clone());
175+
PatKind::Ident(_ , ref ident, _) => {
176+
self.spans.push(ident.span.clone());
177177
}
178178
_ => {
179179
crate::visit::walk_pat(self, p);

src/libsyntax_ext/format.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,9 @@ pub fn expand_preparsed_format_args(
846846

847847
let msg = "format argument must be a string literal";
848848
let fmt_sp = efmt.span;
849-
let fmt = match expr_to_spanned_string(ecx, efmt, msg) {
849+
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) {
850850
Ok(mut fmt) if append_newline => {
851-
fmt.node.0 = Symbol::intern(&format!("{}\n", fmt.node.0));
851+
fmt.0 = Symbol::intern(&format!("{}\n", fmt.0));
852852
fmt
853853
}
854854
Ok(fmt) => fmt,
@@ -875,7 +875,7 @@ pub fn expand_preparsed_format_args(
875875
_ => (false, None),
876876
};
877877

878-
let str_style = match fmt.node.1 {
878+
let str_style = match fmt_style {
879879
ast::StrStyle::Cooked => None,
880880
ast::StrStyle::Raw(raw) => {
881881
Some(raw as usize)
@@ -981,7 +981,7 @@ pub fn expand_preparsed_format_args(
981981
vec![]
982982
};
983983

984-
let fmt_str = &*fmt.node.0.as_str(); // for the suggestions below
984+
let fmt_str = &*fmt_str.as_str(); // for the suggestions below
985985
let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline);
986986

987987
let mut unverified_pieces = Vec::new();
@@ -995,23 +995,23 @@ pub fn expand_preparsed_format_args(
995995

996996
if !parser.errors.is_empty() {
997997
let err = parser.errors.remove(0);
998-
let sp = fmt.span.from_inner(err.span);
998+
let sp = fmt_span.from_inner(err.span);
999999
let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}",
10001000
err.description));
10011001
e.span_label(sp, err.label + " in format string");
10021002
if let Some(note) = err.note {
10031003
e.note(&note);
10041004
}
10051005
if let Some((label, span)) = err.secondary_label {
1006-
let sp = fmt.span.from_inner(span);
1006+
let sp = fmt_span.from_inner(span);
10071007
e.span_label(sp, label);
10081008
}
10091009
e.emit();
10101010
return DummyResult::raw_expr(sp, true);
10111011
}
10121012

10131013
let arg_spans = parser.arg_places.iter()
1014-
.map(|span| fmt.span.from_inner(*span))
1014+
.map(|span| fmt_span.from_inner(*span))
10151015
.collect();
10161016

10171017
let named_pos: FxHashSet<usize> = names.values().cloned().collect();
@@ -1034,7 +1034,7 @@ pub fn expand_preparsed_format_args(
10341034
str_pieces: Vec::with_capacity(unverified_pieces.len()),
10351035
all_pieces_simple: true,
10361036
macsp,
1037-
fmtsp: fmt.span,
1037+
fmtsp: fmt_span,
10381038
invalid_refs: Vec::new(),
10391039
arg_spans,
10401040
arg_with_formatting: Vec::new(),

0 commit comments

Comments
 (0)