Remove Spanned
from mk_name_value_item_str
and expr_to_spanned_string
This commit is contained in:
parent
1cdcea920e
commit
73d2da0894
8 changed files with 31 additions and 29 deletions
|
@ -3,7 +3,6 @@ use super::*;
|
||||||
use syntax_pos::DUMMY_SP;
|
use syntax_pos::DUMMY_SP;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::source_map::dummy_spanned;
|
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax::with_default_globals;
|
use syntax::with_default_globals;
|
||||||
|
|
||||||
|
@ -181,7 +180,8 @@ fn test_parse_ok() {
|
||||||
|
|
||||||
let mi = attr::mk_name_value_item_str(
|
let mi = attr::mk_name_value_item_str(
|
||||||
Ident::from_str("all"),
|
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")));
|
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
||||||
use syntax::ast::{self, AttrStyle, Ident};
|
use syntax::ast::{self, AttrStyle, Ident};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ext::base::MacroKind;
|
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::{Symbol, kw, sym};
|
||||||
use syntax::symbol::InternedString;
|
use syntax::symbol::InternedString;
|
||||||
use syntax_pos::{self, Pos, FileName};
|
use syntax_pos::{self, Pos, FileName};
|
||||||
|
@ -930,8 +930,8 @@ impl Attributes {
|
||||||
if attr.check_name(sym::enable) {
|
if attr.check_name(sym::enable) {
|
||||||
if let Some(feat) = attr.value_str() {
|
if let Some(feat) = attr.value_str() {
|
||||||
let meta = attr::mk_name_value_item_str(
|
let meta = attr::mk_name_value_item_str(
|
||||||
Ident::with_empty_ctxt(sym::target_feature),
|
Ident::with_empty_ctxt(sym::target_feature), feat, DUMMY_SP
|
||||||
dummy_spanned(feat));
|
);
|
||||||
if let Ok(feat_cfg) = Cfg::parse(&meta) {
|
if let Ok(feat_cfg) = Cfg::parse(&meta) {
|
||||||
cfg &= feat_cfg;
|
cfg &= feat_cfg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -939,8 +939,6 @@ pub struct Field {
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SpannedIdent = Spanned<Ident>;
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
|
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
|
||||||
pub enum BlockCheckMode {
|
pub enum BlockCheckMode {
|
||||||
Default,
|
Default,
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::ast::{AttrId, AttrStyle, Name, Ident, Path, PathSegment};
|
||||||
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
|
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
|
||||||
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
|
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
|
||||||
use crate::mut_visit::visit_clobber;
|
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::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
||||||
use crate::parse::parser::Parser;
|
use crate::parse::parser::Parser;
|
||||||
use crate::parse::{self, ParseSess, PResult};
|
use crate::parse::{self, ParseSess, PResult};
|
||||||
|
@ -328,7 +328,9 @@ impl Attribute {
|
||||||
let comment = self.value_str().unwrap();
|
let comment = self.value_str().unwrap();
|
||||||
let meta = mk_name_value_item_str(
|
let meta = mk_name_value_item_str(
|
||||||
Ident::with_empty_ctxt(sym::doc),
|
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 {
|
f(&Attribute {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
style: self.style,
|
style: self.style,
|
||||||
|
@ -345,9 +347,9 @@ impl Attribute {
|
||||||
|
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
|
||||||
pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem {
|
pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> MetaItem {
|
||||||
let lit_kind = LitKind::Str(value.node, ast::StrStyle::Cooked);
|
let lit_kind = LitKind::Str(str, ast::StrStyle::Cooked);
|
||||||
mk_name_value_item(ident, lit_kind, value.span)
|
mk_name_value_item(ident, lit_kind, str_span)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
|
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::ast::{self, Attribute, Name, PatKind};
|
use crate::ast::{self, Attribute, Name, PatKind};
|
||||||
use crate::attr::{HasAttrs, Stability, Deprecation};
|
use crate::attr::{HasAttrs, Stability, Deprecation};
|
||||||
use crate::source_map::{SourceMap, Spanned, respan};
|
use crate::source_map::SourceMap;
|
||||||
use crate::edition::Edition;
|
use crate::edition::Edition;
|
||||||
use crate::ext::expand::{self, AstFragment, Invocation};
|
use crate::ext::expand::{self, AstFragment, Invocation};
|
||||||
use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency};
|
use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency};
|
||||||
|
@ -916,7 +916,7 @@ pub fn expr_to_spanned_string<'a>(
|
||||||
cx: &'a mut ExtCtxt<'_>,
|
cx: &'a mut ExtCtxt<'_>,
|
||||||
mut expr: P<ast::Expr>,
|
mut expr: P<ast::Expr>,
|
||||||
err_msg: &str,
|
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.
|
// Update `expr.span`'s ctxt now in case expr is an `include!` macro invocation.
|
||||||
expr.span = expr.span.apply_mark(cx.current_expansion.id);
|
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 {
|
Err(match expr.node {
|
||||||
ast::ExprKind::Lit(ref l) => match l.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,
|
ast::LitKind::Err(_) => None,
|
||||||
_ => Some(cx.struct_span_err(l.span, err_msg))
|
_ => 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)
|
expr_to_spanned_string(cx, expr, err_msg)
|
||||||
.map_err(|err| err.map(|mut err| err.emit()))
|
.map_err(|err| err.map(|mut err| err.emit()))
|
||||||
.ok()
|
.ok()
|
||||||
.map(|s| s.node)
|
.map(|(symbol, style, _)| (symbol, style))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Non-fatally assert that `tts` is empty. Note that this function
|
/// Non-fatally assert that `tts` is empty. Note that this function
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path};
|
use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path};
|
||||||
use crate::ast::{MacStmtStyle, StmtKind, ItemKind};
|
use crate::ast::{MacStmtStyle, StmtKind, ItemKind};
|
||||||
use crate::attr::{self, HasAttrs};
|
use crate::attr::{self, HasAttrs};
|
||||||
use crate::source_map::{dummy_spanned, respan};
|
use crate::source_map::respan;
|
||||||
use crate::config::StripUnconfigured;
|
use crate::config::StripUnconfigured;
|
||||||
use crate::ext::base::*;
|
use crate::ext::base::*;
|
||||||
use crate::ext::proc_macro::collect_derives;
|
use crate::ext::proc_macro::collect_derives;
|
||||||
|
@ -1251,13 +1251,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||||
ast::NestedMetaItem::MetaItem(
|
ast::NestedMetaItem::MetaItem(
|
||||||
attr::mk_name_value_item_str(
|
attr::mk_name_value_item_str(
|
||||||
Ident::with_empty_ctxt(sym::file),
|
Ident::with_empty_ctxt(sym::file),
|
||||||
dummy_spanned(file),
|
file,
|
||||||
|
DUMMY_SP,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ast::NestedMetaItem::MetaItem(
|
ast::NestedMetaItem::MetaItem(
|
||||||
attr::mk_name_value_item_str(
|
attr::mk_name_value_item_str(
|
||||||
Ident::with_empty_ctxt(sym::contents),
|
Ident::with_empty_ctxt(sym::contents),
|
||||||
dummy_spanned(src_interned),
|
src_interned,
|
||||||
|
DUMMY_SP,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
|
@ -172,8 +172,8 @@ fn get_spans_of_pat_idents(src: &str) -> Vec<Span> {
|
||||||
impl<'a> crate::visit::Visitor<'a> for PatIdentVisitor {
|
impl<'a> crate::visit::Visitor<'a> for PatIdentVisitor {
|
||||||
fn visit_pat(&mut self, p: &'a ast::Pat) {
|
fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||||
match p.node {
|
match p.node {
|
||||||
PatKind::Ident(_ , ref spannedident, _) => {
|
PatKind::Ident(_ , ref ident, _) => {
|
||||||
self.spans.push(spannedident.span.clone());
|
self.spans.push(ident.span.clone());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
crate::visit::walk_pat(self, p);
|
crate::visit::walk_pat(self, p);
|
||||||
|
|
|
@ -846,9 +846,9 @@ pub fn expand_preparsed_format_args(
|
||||||
|
|
||||||
let msg = "format argument must be a string literal";
|
let msg = "format argument must be a string literal";
|
||||||
let fmt_sp = efmt.span;
|
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 => {
|
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
|
fmt
|
||||||
}
|
}
|
||||||
Ok(fmt) => fmt,
|
Ok(fmt) => fmt,
|
||||||
|
@ -875,7 +875,7 @@ pub fn expand_preparsed_format_args(
|
||||||
_ => (false, None),
|
_ => (false, None),
|
||||||
};
|
};
|
||||||
|
|
||||||
let str_style = match fmt.node.1 {
|
let str_style = match fmt_style {
|
||||||
ast::StrStyle::Cooked => None,
|
ast::StrStyle::Cooked => None,
|
||||||
ast::StrStyle::Raw(raw) => {
|
ast::StrStyle::Raw(raw) => {
|
||||||
Some(raw as usize)
|
Some(raw as usize)
|
||||||
|
@ -981,7 +981,7 @@ pub fn expand_preparsed_format_args(
|
||||||
vec![]
|
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 parser = parse::Parser::new(fmt_str, str_style, skips, append_newline);
|
||||||
|
|
||||||
let mut unverified_pieces = Vec::new();
|
let mut unverified_pieces = Vec::new();
|
||||||
|
@ -995,7 +995,7 @@ pub fn expand_preparsed_format_args(
|
||||||
|
|
||||||
if !parser.errors.is_empty() {
|
if !parser.errors.is_empty() {
|
||||||
let err = parser.errors.remove(0);
|
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: {}",
|
let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}",
|
||||||
err.description));
|
err.description));
|
||||||
e.span_label(sp, err.label + " in format string");
|
e.span_label(sp, err.label + " in format string");
|
||||||
|
@ -1003,7 +1003,7 @@ pub fn expand_preparsed_format_args(
|
||||||
e.note(¬e);
|
e.note(¬e);
|
||||||
}
|
}
|
||||||
if let Some((label, span)) = err.secondary_label {
|
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.span_label(sp, label);
|
||||||
}
|
}
|
||||||
e.emit();
|
e.emit();
|
||||||
|
@ -1011,7 +1011,7 @@ pub fn expand_preparsed_format_args(
|
||||||
}
|
}
|
||||||
|
|
||||||
let arg_spans = parser.arg_places.iter()
|
let arg_spans = parser.arg_places.iter()
|
||||||
.map(|span| fmt.span.from_inner(*span))
|
.map(|span| fmt_span.from_inner(*span))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let named_pos: FxHashSet<usize> = names.values().cloned().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()),
|
str_pieces: Vec::with_capacity(unverified_pieces.len()),
|
||||||
all_pieces_simple: true,
|
all_pieces_simple: true,
|
||||||
macsp,
|
macsp,
|
||||||
fmtsp: fmt.span,
|
fmtsp: fmt_span,
|
||||||
invalid_refs: Vec::new(),
|
invalid_refs: Vec::new(),
|
||||||
arg_spans,
|
arg_spans,
|
||||||
arg_with_formatting: Vec::new(),
|
arg_with_formatting: Vec::new(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue