1
Fork 0

Remove Spanned from mk_name_value_item_str and expr_to_spanned_string

This commit is contained in:
Vadim Petrochenkov 2019-08-15 01:56:44 +03:00
parent 1cdcea920e
commit 73d2da0894
8 changed files with 31 additions and 29 deletions

View file

@ -3,7 +3,6 @@ use super::*;
use syntax_pos::DUMMY_SP;
use syntax::ast::*;
use syntax::attr;
use syntax::source_map::dummy_spanned;
use syntax::symbol::Symbol;
use syntax::with_default_globals;
@ -181,7 +180,8 @@ fn test_parse_ok() {
let mi = attr::mk_name_value_item_str(
Ident::from_str("all"),
dummy_spanned(Symbol::intern("done"))
Symbol::intern("done"),
DUMMY_SP,
);
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));

View file

@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
use syntax::ast::{self, AttrStyle, Ident};
use syntax::attr;
use syntax::ext::base::MacroKind;
use syntax::source_map::{dummy_spanned, Spanned};
use syntax::source_map::{DUMMY_SP, Spanned};
use syntax::symbol::{Symbol, kw, sym};
use syntax::symbol::InternedString;
use syntax_pos::{self, Pos, FileName};
@ -930,8 +930,8 @@ impl Attributes {
if attr.check_name(sym::enable) {
if let Some(feat) = attr.value_str() {
let meta = attr::mk_name_value_item_str(
Ident::with_empty_ctxt(sym::target_feature),
dummy_spanned(feat));
Ident::with_empty_ctxt(sym::target_feature), feat, DUMMY_SP
);
if let Ok(feat_cfg) = Cfg::parse(&meta) {
cfg &= feat_cfg;
}

View file

@ -939,8 +939,6 @@ pub struct Field {
pub id: NodeId,
}
pub type SpannedIdent = Spanned<Ident>;
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
pub enum BlockCheckMode {
Default,

View file

@ -13,7 +13,7 @@ use crate::ast::{AttrId, AttrStyle, Name, Ident, Path, PathSegment};
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
use crate::mut_visit::visit_clobber;
use crate::source_map::{BytePos, Spanned, dummy_spanned};
use crate::source_map::{BytePos, Spanned, DUMMY_SP};
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
use crate::parse::parser::Parser;
use crate::parse::{self, ParseSess, PResult};
@ -328,7 +328,9 @@ impl Attribute {
let comment = self.value_str().unwrap();
let meta = mk_name_value_item_str(
Ident::with_empty_ctxt(sym::doc),
dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
Symbol::intern(&strip_doc_comment_decoration(&comment.as_str())),
DUMMY_SP,
);
f(&Attribute {
id: self.id,
style: self.style,
@ -345,9 +347,9 @@ impl Attribute {
/* Constructors */
pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem {
let lit_kind = LitKind::Str(value.node, ast::StrStyle::Cooked);
mk_name_value_item(ident, lit_kind, value.span)
pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> MetaItem {
let lit_kind = LitKind::Str(str, ast::StrStyle::Cooked);
mk_name_value_item(ident, lit_kind, str_span)
}
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {

View file

@ -1,6 +1,6 @@
use crate::ast::{self, Attribute, Name, PatKind};
use crate::attr::{HasAttrs, Stability, Deprecation};
use crate::source_map::{SourceMap, Spanned, respan};
use crate::source_map::SourceMap;
use crate::edition::Edition;
use crate::ext::expand::{self, AstFragment, Invocation};
use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency};
@ -916,7 +916,7 @@ pub fn expr_to_spanned_string<'a>(
cx: &'a mut ExtCtxt<'_>,
mut expr: P<ast::Expr>,
err_msg: &str,
) -> Result<Spanned<(Symbol, ast::StrStyle)>, Option<DiagnosticBuilder<'a>>> {
) -> Result<(Symbol, ast::StrStyle, Span), Option<DiagnosticBuilder<'a>>> {
// Update `expr.span`'s ctxt now in case expr is an `include!` macro invocation.
expr.span = expr.span.apply_mark(cx.current_expansion.id);
@ -926,7 +926,7 @@ pub fn expr_to_spanned_string<'a>(
Err(match expr.node {
ast::ExprKind::Lit(ref l) => match l.node {
ast::LitKind::Str(s, style) => return Ok(respan(expr.span, (s, style))),
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
ast::LitKind::Err(_) => None,
_ => Some(cx.struct_span_err(l.span, err_msg))
},
@ -940,7 +940,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt<'_>, expr: P<ast::Expr>, err_msg: &str)
expr_to_spanned_string(cx, expr, err_msg)
.map_err(|err| err.map(|mut err| err.emit()))
.ok()
.map(|s| s.node)
.map(|(symbol, style, _)| (symbol, style))
}
/// Non-fatally assert that `tts` is empty. Note that this function

View file

@ -1,7 +1,7 @@
use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path};
use crate::ast::{MacStmtStyle, StmtKind, ItemKind};
use crate::attr::{self, HasAttrs};
use crate::source_map::{dummy_spanned, respan};
use crate::source_map::respan;
use crate::config::StripUnconfigured;
use crate::ext::base::*;
use crate::ext::proc_macro::collect_derives;
@ -1251,13 +1251,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
ast::NestedMetaItem::MetaItem(
attr::mk_name_value_item_str(
Ident::with_empty_ctxt(sym::file),
dummy_spanned(file),
file,
DUMMY_SP,
),
),
ast::NestedMetaItem::MetaItem(
attr::mk_name_value_item_str(
Ident::with_empty_ctxt(sym::contents),
dummy_spanned(src_interned),
src_interned,
DUMMY_SP,
),
),
];

View file

@ -172,8 +172,8 @@ fn get_spans_of_pat_idents(src: &str) -> Vec<Span> {
impl<'a> crate::visit::Visitor<'a> for PatIdentVisitor {
fn visit_pat(&mut self, p: &'a ast::Pat) {
match p.node {
PatKind::Ident(_ , ref spannedident, _) => {
self.spans.push(spannedident.span.clone());
PatKind::Ident(_ , ref ident, _) => {
self.spans.push(ident.span.clone());
}
_ => {
crate::visit::walk_pat(self, p);

View file

@ -846,9 +846,9 @@ pub fn expand_preparsed_format_args(
let msg = "format argument must be a string literal";
let fmt_sp = efmt.span;
let fmt = match expr_to_spanned_string(ecx, efmt, msg) {
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) {
Ok(mut fmt) if append_newline => {
fmt.node.0 = Symbol::intern(&format!("{}\n", fmt.node.0));
fmt.0 = Symbol::intern(&format!("{}\n", fmt.0));
fmt
}
Ok(fmt) => fmt,
@ -875,7 +875,7 @@ pub fn expand_preparsed_format_args(
_ => (false, None),
};
let str_style = match fmt.node.1 {
let str_style = match fmt_style {
ast::StrStyle::Cooked => None,
ast::StrStyle::Raw(raw) => {
Some(raw as usize)
@ -981,7 +981,7 @@ pub fn expand_preparsed_format_args(
vec![]
};
let fmt_str = &*fmt.node.0.as_str(); // for the suggestions below
let fmt_str = &*fmt_str.as_str(); // for the suggestions below
let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline);
let mut unverified_pieces = Vec::new();
@ -995,7 +995,7 @@ pub fn expand_preparsed_format_args(
if !parser.errors.is_empty() {
let err = parser.errors.remove(0);
let sp = fmt.span.from_inner(err.span);
let sp = fmt_span.from_inner(err.span);
let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}",
err.description));
e.span_label(sp, err.label + " in format string");
@ -1003,7 +1003,7 @@ pub fn expand_preparsed_format_args(
e.note(&note);
}
if let Some((label, span)) = err.secondary_label {
let sp = fmt.span.from_inner(span);
let sp = fmt_span.from_inner(span);
e.span_label(sp, label);
}
e.emit();
@ -1011,7 +1011,7 @@ pub fn expand_preparsed_format_args(
}
let arg_spans = parser.arg_places.iter()
.map(|span| fmt.span.from_inner(*span))
.map(|span| fmt_span.from_inner(*span))
.collect();
let named_pos: FxHashSet<usize> = names.values().cloned().collect();
@ -1034,7 +1034,7 @@ pub fn expand_preparsed_format_args(
str_pieces: Vec::with_capacity(unverified_pieces.len()),
all_pieces_simple: true,
macsp,
fmtsp: fmt.span,
fmtsp: fmt_span,
invalid_refs: Vec::new(),
arg_spans,
arg_with_formatting: Vec::new(),