mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
libsyntax => 2018
This commit is contained in:
parent
2596bc1368
commit
7bb082d27f
@ -2,6 +2,7 @@
|
|||||||
authors = ["The Rust Project Developers"]
|
authors = ["The Rust Project Developers"]
|
||||||
name = "syntax"
|
name = "syntax"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "syntax"
|
name = "syntax"
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
// The Rust abstract syntax tree.
|
// The Rust abstract syntax tree.
|
||||||
|
|
||||||
pub use self::GenericArgs::*;
|
pub use GenericArgs::*;
|
||||||
pub use self::UnsafeSource::*;
|
pub use UnsafeSource::*;
|
||||||
pub use symbol::{Ident, Symbol as Name};
|
pub use crate::symbol::{Ident, Symbol as Name};
|
||||||
pub use util::parser::ExprPrecedence;
|
pub use crate::util::parser::ExprPrecedence;
|
||||||
|
|
||||||
|
use crate::ext::hygiene::{Mark, SyntaxContext};
|
||||||
|
use crate::print::pprust;
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||||
|
use crate::symbol::{keywords, Symbol};
|
||||||
|
use crate::tokenstream::TokenStream;
|
||||||
|
use crate::ThinVec;
|
||||||
|
|
||||||
use ext::hygiene::{Mark, SyntaxContext};
|
|
||||||
use print::pprust;
|
|
||||||
use ptr::P;
|
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use rustc_data_structures::static_assert;
|
use rustc_data_structures::static_assert;
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use source_map::{dummy_spanned, respan, Spanned};
|
|
||||||
use symbol::{keywords, Symbol};
|
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
use tokenstream::TokenStream;
|
|
||||||
use ThinVec;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
@ -31,7 +32,7 @@ pub struct Label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Label {
|
impl fmt::Debug for Label {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "label({:?})", self.ident)
|
write!(f, "label({:?})", self.ident)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,7 +44,7 @@ pub struct Lifetime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Lifetime {
|
impl fmt::Debug for Lifetime {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"lifetime({}: {})",
|
"lifetime({}: {})",
|
||||||
@ -74,13 +75,13 @@ impl<'a> PartialEq<&'a str> for Path {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Path {
|
impl fmt::Debug for Path {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "path({})", pprust::path_to_string(self))
|
write!(f, "path({})", pprust::path_to_string(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Path {
|
impl fmt::Display for Path {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", pprust::path_to_string(self))
|
write!(f, "{}", pprust::path_to_string(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,6 +220,7 @@ impl ParenthesizedArgs {
|
|||||||
// hack to ensure that we don't try to access the private parts of `NodeId` in this module
|
// hack to ensure that we don't try to access the private parts of `NodeId` in this module
|
||||||
mod node_id_inner {
|
mod node_id_inner {
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
|
use rustc_data_structures::newtype_index;
|
||||||
newtype_index! {
|
newtype_index! {
|
||||||
pub struct NodeId {
|
pub struct NodeId {
|
||||||
ENCODABLE = custom
|
ENCODABLE = custom
|
||||||
@ -227,7 +229,7 @@ mod node_id_inner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use self::node_id_inner::NodeId;
|
pub use node_id_inner::NodeId;
|
||||||
|
|
||||||
impl NodeId {
|
impl NodeId {
|
||||||
pub fn placeholder_from_mark(mark: Mark) -> Self {
|
pub fn placeholder_from_mark(mark: Mark) -> Self {
|
||||||
@ -240,7 +242,7 @@ impl NodeId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NodeId {
|
impl fmt::Display for NodeId {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(&self.as_u32(), f)
|
fmt::Display::fmt(&self.as_u32(), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,7 +480,7 @@ pub struct Pat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Pat {
|
impl fmt::Debug for Pat {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "pat({}: {})", self.id, pprust::pat_to_string(self))
|
write!(f, "pat({}: {})", self.id, pprust::pat_to_string(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -676,7 +678,7 @@ pub enum BinOpKind {
|
|||||||
|
|
||||||
impl BinOpKind {
|
impl BinOpKind {
|
||||||
pub fn to_string(&self) -> &'static str {
|
pub fn to_string(&self) -> &'static str {
|
||||||
use self::BinOpKind::*;
|
use BinOpKind::*;
|
||||||
match *self {
|
match *self {
|
||||||
Add => "+",
|
Add => "+",
|
||||||
Sub => "-",
|
Sub => "-",
|
||||||
@ -713,7 +715,7 @@ impl BinOpKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_comparison(&self) -> bool {
|
pub fn is_comparison(&self) -> bool {
|
||||||
use self::BinOpKind::*;
|
use BinOpKind::*;
|
||||||
match *self {
|
match *self {
|
||||||
Eq | Lt | Le | Ne | Gt | Ge => true,
|
Eq | Lt | Le | Ne | Gt | Ge => true,
|
||||||
And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
|
And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
|
||||||
@ -792,7 +794,7 @@ impl Stmt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Stmt {
|
impl fmt::Debug for Stmt {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"stmt({}: {})",
|
"stmt({}: {})",
|
||||||
@ -1030,7 +1032,7 @@ impl Expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Expr {
|
impl fmt::Debug for Expr {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "expr({}: {})", self.id, pprust::expr_to_string(self))
|
write!(f, "expr({}: {})", self.id, pprust::expr_to_string(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1438,13 +1440,13 @@ pub enum IntTy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for IntTy {
|
impl fmt::Debug for IntTy {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(self, f)
|
fmt::Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for IntTy {
|
impl fmt::Display for IntTy {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", self.ty_to_string())
|
write!(f, "{}", self.ty_to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1519,13 +1521,13 @@ impl UintTy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for UintTy {
|
impl fmt::Debug for UintTy {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(self, f)
|
fmt::Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for UintTy {
|
impl fmt::Display for UintTy {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", self.ty_to_string())
|
write!(f, "{}", self.ty_to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1547,7 +1549,7 @@ pub struct Ty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Ty {
|
impl fmt::Debug for Ty {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "type({})", pprust::ty_to_string(self))
|
write!(f, "type({})", pprust::ty_to_string(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1832,7 +1834,7 @@ pub enum Defaultness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Unsafety {
|
impl fmt::Display for Unsafety {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(
|
fmt::Display::fmt(
|
||||||
match *self {
|
match *self {
|
||||||
Unsafety::Normal => "normal",
|
Unsafety::Normal => "normal",
|
||||||
@ -1852,7 +1854,7 @@ pub enum ImplPolarity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ImplPolarity {
|
impl fmt::Debug for ImplPolarity {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
ImplPolarity::Positive => "positive".fmt(f),
|
ImplPolarity::Positive => "positive".fmt(f),
|
||||||
ImplPolarity::Negative => "negative".fmt(f),
|
ImplPolarity::Negative => "negative".fmt(f),
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
//! Parsing and validation of builtin attributes
|
//! Parsing and validation of builtin attributes
|
||||||
|
|
||||||
use ast::{self, Attribute, MetaItem, Name, NestedMetaItemKind};
|
use crate::ast::{self, Attribute, MetaItem, Name, NestedMetaItemKind};
|
||||||
use errors::{Applicability, Handler};
|
use crate::errors::{Applicability, Handler};
|
||||||
use feature_gate::{Features, GatedCfg};
|
use crate::feature_gate::{Features, GatedCfg};
|
||||||
use parse::ParseSess;
|
use crate::parse::ParseSess;
|
||||||
|
|
||||||
use syntax_pos::{symbol::Symbol, Span};
|
use syntax_pos::{symbol::Symbol, Span};
|
||||||
|
|
||||||
use super::{list_contains_name, mark_used, MetaItemKind};
|
use super::{list_contains_name, mark_used, MetaItemKind};
|
||||||
@ -188,7 +189,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
|
|||||||
-> Option<Stability>
|
-> Option<Stability>
|
||||||
where I: Iterator<Item = &'a Attribute>
|
where I: Iterator<Item = &'a Attribute>
|
||||||
{
|
{
|
||||||
use self::StabilityLevel::*;
|
use StabilityLevel::*;
|
||||||
|
|
||||||
let mut stab: Option<Stability> = None;
|
let mut stab: Option<Stability> = None;
|
||||||
let mut rustc_depr: Option<RustcDeprecation> = None;
|
let mut rustc_depr: Option<RustcDeprecation> = None;
|
||||||
@ -694,7 +695,7 @@ pub enum IntType {
|
|||||||
impl IntType {
|
impl IntType {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_signed(self) -> bool {
|
pub fn is_signed(self) -> bool {
|
||||||
use self::IntType::*;
|
use IntType::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
SignedInt(..) => true,
|
SignedInt(..) => true,
|
||||||
@ -711,7 +712,7 @@ impl IntType {
|
|||||||
/// structure layout, `packed` to remove padding, and `transparent` to elegate representation
|
/// structure layout, `packed` to remove padding, and `transparent` to elegate representation
|
||||||
/// concerns to the only non-ZST field.
|
/// concerns to the only non-ZST field.
|
||||||
pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
|
pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
|
||||||
use self::ReprAttr::*;
|
use ReprAttr::*;
|
||||||
|
|
||||||
let mut acc = Vec::new();
|
let mut acc = Vec::new();
|
||||||
let diagnostic = &sess.span_diagnostic;
|
let diagnostic = &sess.span_diagnostic;
|
||||||
@ -831,7 +832,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn int_type_of_word(s: &str) -> Option<IntType> {
|
fn int_type_of_word(s: &str) -> Option<IntType> {
|
||||||
use self::IntType::*;
|
use IntType::*;
|
||||||
|
|
||||||
match s {
|
match s {
|
||||||
"i8" => Some(SignedInt(ast::IntTy::I8)),
|
"i8" => Some(SignedInt(ast::IntTy::I8)),
|
||||||
|
@ -2,31 +2,33 @@
|
|||||||
|
|
||||||
mod builtin;
|
mod builtin;
|
||||||
|
|
||||||
pub use self::builtin::{
|
pub use builtin::{
|
||||||
cfg_matches, contains_feature_attr, eval_condition, find_crate_name, find_deprecation,
|
cfg_matches, contains_feature_attr, eval_condition, find_crate_name, find_deprecation,
|
||||||
find_repr_attrs, find_stability, find_unwind_attr, Deprecation, InlineAttr, OptimizeAttr,
|
find_repr_attrs, find_stability, find_unwind_attr, Deprecation, InlineAttr, OptimizeAttr,
|
||||||
IntType, ReprAttr, RustcDeprecation, Stability, StabilityLevel, UnwindAttr,
|
IntType, ReprAttr, RustcDeprecation, Stability, StabilityLevel, UnwindAttr,
|
||||||
};
|
};
|
||||||
pub use self::IntType::*;
|
pub use IntType::*;
|
||||||
pub use self::ReprAttr::*;
|
pub use ReprAttr::*;
|
||||||
pub use self::StabilityLevel::*;
|
pub use StabilityLevel::*;
|
||||||
|
|
||||||
use ast;
|
use crate::ast;
|
||||||
use ast::{AttrId, Attribute, AttrStyle, Name, Ident, Path, PathSegment};
|
use crate::ast::{AttrId, Attribute, AttrStyle, Name, Ident, Path, PathSegment};
|
||||||
use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
|
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
|
||||||
use ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind, GenericParam};
|
use crate::ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind, GenericParam};
|
||||||
use mut_visit::visit_clobber;
|
use crate::mut_visit::visit_clobber;
|
||||||
use source_map::{BytePos, Spanned, respan, dummy_spanned};
|
use crate::source_map::{BytePos, Spanned, respan, dummy_spanned};
|
||||||
|
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
||||||
|
use crate::parse::parser::Parser;
|
||||||
|
use crate::parse::{self, ParseSess, PResult};
|
||||||
|
use crate::parse::token::{self, Token};
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::symbol::Symbol;
|
||||||
|
use crate::ThinVec;
|
||||||
|
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
|
||||||
|
use crate::GLOBALS;
|
||||||
|
|
||||||
|
use log::debug;
|
||||||
use syntax_pos::{FileName, Span};
|
use syntax_pos::{FileName, Span};
|
||||||
use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
|
||||||
use parse::parser::Parser;
|
|
||||||
use parse::{self, ParseSess, PResult};
|
|
||||||
use parse::token::{self, Token};
|
|
||||||
use ptr::P;
|
|
||||||
use symbol::Symbol;
|
|
||||||
use ThinVec;
|
|
||||||
use tokenstream::{TokenStream, TokenTree, DelimSpan};
|
|
||||||
use GLOBALS;
|
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
use attr::HasAttrs;
|
use crate::attr::HasAttrs;
|
||||||
use feature_gate::{
|
use crate::feature_gate::{
|
||||||
feature_err,
|
feature_err,
|
||||||
EXPLAIN_STMT_ATTR_SYNTAX,
|
EXPLAIN_STMT_ATTR_SYNTAX,
|
||||||
Features,
|
Features,
|
||||||
get_features,
|
get_features,
|
||||||
GateIssue,
|
GateIssue,
|
||||||
};
|
};
|
||||||
use attr;
|
use crate::attr;
|
||||||
use ast;
|
use crate::ast;
|
||||||
use edition::Edition;
|
use crate::edition::Edition;
|
||||||
use errors::Applicability;
|
use crate::errors::Applicability;
|
||||||
use mut_visit::*;
|
use crate::mut_visit::*;
|
||||||
use parse::{token, ParseSess};
|
use crate::parse::{token, ParseSess};
|
||||||
use ptr::P;
|
use crate::ptr::P;
|
||||||
|
use crate::util::map_in_place::MapInPlace;
|
||||||
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use util::map_in_place::MapInPlace;
|
|
||||||
|
|
||||||
/// A folder that strips out items that do not belong in the current configuration.
|
/// A folder that strips out items that do not belong in the current configuration.
|
||||||
pub struct StripUnconfigured<'a> {
|
pub struct StripUnconfigured<'a> {
|
||||||
|
@ -12,8 +12,9 @@ use std::error::Error;
|
|||||||
use rustc_serialize::json::as_json;
|
use rustc_serialize::json::as_json;
|
||||||
|
|
||||||
use syntax_pos::{Span, FileName};
|
use syntax_pos::{Span, FileName};
|
||||||
use ext::base::ExtCtxt;
|
|
||||||
use diagnostics::plugin::{ErrorMap, ErrorInfo};
|
use crate::ext::base::ExtCtxt;
|
||||||
|
use crate::diagnostics::plugin::{ErrorMap, ErrorInfo};
|
||||||
|
|
||||||
/// JSON encodable/decodable version of `ErrorInfo`.
|
/// JSON encodable/decodable version of `ErrorInfo`.
|
||||||
#[derive(PartialEq, RustcDecodable, RustcEncodable)]
|
#[derive(PartialEq, RustcDecodable, RustcEncodable)]
|
||||||
@ -34,7 +35,7 @@ pub struct ErrorLocation {
|
|||||||
|
|
||||||
impl ErrorLocation {
|
impl ErrorLocation {
|
||||||
/// Create an error location from a span.
|
/// Create an error location from a span.
|
||||||
pub fn from_span(ecx: &ExtCtxt, sp: Span) -> ErrorLocation {
|
pub fn from_span(ecx: &ExtCtxt<'_>, sp: Span) -> ErrorLocation {
|
||||||
let loc = ecx.source_map().lookup_char_pos_adj(sp.lo());
|
let loc = ecx.source_map().lookup_char_pos_adj(sp.lo());
|
||||||
ErrorLocation {
|
ErrorLocation {
|
||||||
filename: loc.filename,
|
filename: loc.filename,
|
||||||
@ -62,7 +63,7 @@ fn get_metadata_path(directory: PathBuf, name: &str) -> PathBuf {
|
|||||||
///
|
///
|
||||||
/// For our current purposes the prefix is the target architecture and the name is a crate name.
|
/// For our current purposes the prefix is the target architecture and the name is a crate name.
|
||||||
/// If an error occurs steps will be taken to ensure that no file is created.
|
/// If an error occurs steps will be taken to ensure that no file is created.
|
||||||
pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorMap)
|
pub fn output_metadata(ecx: &ExtCtxt<'_>, prefix: &str, name: &str, err_map: &ErrorMap)
|
||||||
-> Result<(), Box<dyn Error>>
|
-> Result<(), Box<dyn Error>>
|
||||||
{
|
{
|
||||||
// Create the directory to place the file in.
|
// Create the directory to place the file in.
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use ast;
|
use crate::ast::{self, Ident, Name};
|
||||||
use ast::{Ident, Name};
|
use crate::source_map;
|
||||||
use source_map;
|
use crate::ext::base::{ExtCtxt, MacEager, MacResult};
|
||||||
|
use crate::ext::build::AstBuilder;
|
||||||
|
use crate::parse::token;
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::symbol::{keywords, Symbol};
|
||||||
|
use crate::tokenstream::{TokenTree};
|
||||||
|
|
||||||
|
use smallvec::smallvec;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use ext::base::{ExtCtxt, MacEager, MacResult};
|
|
||||||
use ext::build::AstBuilder;
|
|
||||||
use parse::token;
|
|
||||||
use ptr::P;
|
|
||||||
use symbol::{keywords, Symbol};
|
|
||||||
use tokenstream::{TokenTree};
|
|
||||||
|
|
||||||
use diagnostics::metadata::output_metadata;
|
use crate::diagnostics::metadata::output_metadata;
|
||||||
|
|
||||||
pub use errors::*;
|
pub use crate::errors::*;
|
||||||
|
|
||||||
// Maximum width of any line in an extended error description (inclusive).
|
// Maximum width of any line in an extended error description (inclusive).
|
||||||
const MAX_DESCRIPTION_WIDTH: usize = 80;
|
const MAX_DESCRIPTION_WIDTH: usize = 80;
|
||||||
@ -28,7 +29,7 @@ pub struct ErrorInfo {
|
|||||||
/// Mapping from error codes to metadata.
|
/// Mapping from error codes to metadata.
|
||||||
pub type ErrorMap = BTreeMap<Name, ErrorInfo>;
|
pub type ErrorMap = BTreeMap<Name, ErrorInfo>;
|
||||||
|
|
||||||
pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
|
pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
token_tree: &[TokenTree])
|
token_tree: &[TokenTree])
|
||||||
-> Box<dyn MacResult+'cx> {
|
-> Box<dyn MacResult+'cx> {
|
||||||
@ -61,7 +62,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
|
|||||||
MacEager::expr(ecx.expr_tuple(span, Vec::new()))
|
MacEager::expr(ecx.expr_tuple(span, Vec::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
|
pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
token_tree: &[TokenTree])
|
token_tree: &[TokenTree])
|
||||||
-> Box<dyn MacResult+'cx> {
|
-> Box<dyn MacResult+'cx> {
|
||||||
@ -134,7 +135,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
|
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
token_tree: &[TokenTree])
|
token_tree: &[TokenTree])
|
||||||
-> Box<dyn MacResult+'cx> {
|
-> Box<dyn MacResult+'cx> {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
//! Since we cannot have a dependency on `librustc`, we implement some types here that are somewhat
|
//! Since we cannot have a dependency on `librustc`, we implement some types here that are somewhat
|
||||||
//! redundant. Later, these types can be converted to types for use by the rest of the compiler.
|
//! redundant. Later, these types can be converted to types for use by the rest of the compiler.
|
||||||
|
|
||||||
use syntax::ast::NodeId;
|
use crate::syntax::ast::NodeId;
|
||||||
use syntax_pos::MultiSpan;
|
use syntax_pos::MultiSpan;
|
||||||
|
|
||||||
/// Since we cannot import `LintId`s from `rustc::lint`, we define some Ids here which can later be
|
/// Since we cannot import `LintId`s from `rustc::lint`, we define some Ids here which can later be
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use attr;
|
use crate::attr;
|
||||||
use ast::{Item, ItemKind};
|
use crate::ast::{Item, ItemKind};
|
||||||
|
|
||||||
pub enum EntryPointType {
|
pub enum EntryPointType {
|
||||||
None,
|
None,
|
||||||
|
@ -1,28 +1,29 @@
|
|||||||
pub use self::SyntaxExtension::*;
|
pub use SyntaxExtension::*;
|
||||||
|
|
||||||
use ast::{self, Attribute, Name, PatKind, MetaItem};
|
use crate::ast::{self, Attribute, Name, PatKind, MetaItem};
|
||||||
use attr::HasAttrs;
|
use crate::attr::HasAttrs;
|
||||||
use source_map::{SourceMap, Spanned, respan};
|
use crate::source_map::{SourceMap, Spanned, respan};
|
||||||
|
use crate::edition::Edition;
|
||||||
|
use crate::errors::{DiagnosticBuilder, DiagnosticId};
|
||||||
|
use crate::ext::expand::{self, AstFragment, Invocation};
|
||||||
|
use crate::ext::hygiene::{self, Mark, SyntaxContext, Transparency};
|
||||||
|
use crate::mut_visit::{self, MutVisitor};
|
||||||
|
use crate::parse::{self, parser, DirectoryOwnership};
|
||||||
|
use crate::parse::token;
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::symbol::{keywords, Ident, Symbol};
|
||||||
|
use crate::ThinVec;
|
||||||
|
use crate::tokenstream::{self, TokenStream};
|
||||||
|
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
|
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
|
||||||
use edition::Edition;
|
|
||||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
|
||||||
use ext::expand::{self, AstFragment, Invocation};
|
|
||||||
use ext::hygiene::{self, Mark, SyntaxContext, Transparency};
|
|
||||||
use mut_visit::{self, MutVisitor};
|
|
||||||
use parse::{self, parser, DirectoryOwnership};
|
|
||||||
use parse::token;
|
|
||||||
use ptr::P;
|
|
||||||
use smallvec::SmallVec;
|
|
||||||
use symbol::{keywords, Ident, Symbol};
|
|
||||||
use ThinVec;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
use rustc_data_structures::sync::{self, Lrc};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use rustc_data_structures::sync::{self, Lrc};
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use tokenstream::{self, TokenStream};
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug,Clone)]
|
||||||
@ -139,7 +140,7 @@ impl Annotatable {
|
|||||||
// A more flexible ItemDecorator.
|
// A more flexible ItemDecorator.
|
||||||
pub trait MultiItemDecorator {
|
pub trait MultiItemDecorator {
|
||||||
fn expand(&self,
|
fn expand(&self,
|
||||||
ecx: &mut ExtCtxt,
|
ecx: &mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
meta_item: &ast::MetaItem,
|
meta_item: &ast::MetaItem,
|
||||||
item: &Annotatable,
|
item: &Annotatable,
|
||||||
@ -147,10 +148,10 @@ pub trait MultiItemDecorator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F> MultiItemDecorator for F
|
impl<F> MultiItemDecorator for F
|
||||||
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable, &mut dyn FnMut(Annotatable))
|
where F : Fn(&mut ExtCtxt<'_>, Span, &ast::MetaItem, &Annotatable, &mut dyn FnMut(Annotatable))
|
||||||
{
|
{
|
||||||
fn expand(&self,
|
fn expand(&self,
|
||||||
ecx: &mut ExtCtxt,
|
ecx: &mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
meta_item: &ast::MetaItem,
|
meta_item: &ast::MetaItem,
|
||||||
item: &Annotatable,
|
item: &Annotatable,
|
||||||
@ -163,7 +164,7 @@ impl<F> MultiItemDecorator for F
|
|||||||
// FIXME Decorators should follow the same pattern too.
|
// FIXME Decorators should follow the same pattern too.
|
||||||
pub trait MultiItemModifier {
|
pub trait MultiItemModifier {
|
||||||
fn expand(&self,
|
fn expand(&self,
|
||||||
ecx: &mut ExtCtxt,
|
ecx: &mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
meta_item: &ast::MetaItem,
|
meta_item: &ast::MetaItem,
|
||||||
item: Annotatable)
|
item: Annotatable)
|
||||||
@ -171,11 +172,11 @@ pub trait MultiItemModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F, T> MultiItemModifier for F
|
impl<F, T> MultiItemModifier for F
|
||||||
where F: Fn(&mut ExtCtxt, Span, &ast::MetaItem, Annotatable) -> T,
|
where F: Fn(&mut ExtCtxt<'_>, Span, &ast::MetaItem, Annotatable) -> T,
|
||||||
T: Into<Vec<Annotatable>>,
|
T: Into<Vec<Annotatable>>,
|
||||||
{
|
{
|
||||||
fn expand(&self,
|
fn expand(&self,
|
||||||
ecx: &mut ExtCtxt,
|
ecx: &mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
meta_item: &ast::MetaItem,
|
meta_item: &ast::MetaItem,
|
||||||
item: Annotatable)
|
item: Annotatable)
|
||||||
@ -192,7 +193,7 @@ impl Into<Vec<Annotatable>> for Annotatable {
|
|||||||
|
|
||||||
pub trait ProcMacro {
|
pub trait ProcMacro {
|
||||||
fn expand<'cx>(&self,
|
fn expand<'cx>(&self,
|
||||||
ecx: &'cx mut ExtCtxt,
|
ecx: &'cx mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
ts: TokenStream)
|
ts: TokenStream)
|
||||||
-> TokenStream;
|
-> TokenStream;
|
||||||
@ -202,7 +203,7 @@ impl<F> ProcMacro for F
|
|||||||
where F: Fn(TokenStream) -> TokenStream
|
where F: Fn(TokenStream) -> TokenStream
|
||||||
{
|
{
|
||||||
fn expand<'cx>(&self,
|
fn expand<'cx>(&self,
|
||||||
_ecx: &'cx mut ExtCtxt,
|
_ecx: &'cx mut ExtCtxt<'_>,
|
||||||
_span: Span,
|
_span: Span,
|
||||||
ts: TokenStream)
|
ts: TokenStream)
|
||||||
-> TokenStream {
|
-> TokenStream {
|
||||||
@ -213,7 +214,7 @@ impl<F> ProcMacro for F
|
|||||||
|
|
||||||
pub trait AttrProcMacro {
|
pub trait AttrProcMacro {
|
||||||
fn expand<'cx>(&self,
|
fn expand<'cx>(&self,
|
||||||
ecx: &'cx mut ExtCtxt,
|
ecx: &'cx mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
annotation: TokenStream,
|
annotation: TokenStream,
|
||||||
annotated: TokenStream)
|
annotated: TokenStream)
|
||||||
@ -224,7 +225,7 @@ impl<F> AttrProcMacro for F
|
|||||||
where F: Fn(TokenStream, TokenStream) -> TokenStream
|
where F: Fn(TokenStream, TokenStream) -> TokenStream
|
||||||
{
|
{
|
||||||
fn expand<'cx>(&self,
|
fn expand<'cx>(&self,
|
||||||
_ecx: &'cx mut ExtCtxt,
|
_ecx: &'cx mut ExtCtxt<'_>,
|
||||||
_span: Span,
|
_span: Span,
|
||||||
annotation: TokenStream,
|
annotation: TokenStream,
|
||||||
annotated: TokenStream)
|
annotated: TokenStream)
|
||||||
@ -238,7 +239,7 @@ impl<F> AttrProcMacro for F
|
|||||||
pub trait TTMacroExpander {
|
pub trait TTMacroExpander {
|
||||||
fn expand<'cx>(
|
fn expand<'cx>(
|
||||||
&self,
|
&self,
|
||||||
ecx: &'cx mut ExtCtxt,
|
ecx: &'cx mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
input: TokenStream,
|
input: TokenStream,
|
||||||
def_span: Option<Span>,
|
def_span: Option<Span>,
|
||||||
@ -246,16 +247,16 @@ pub trait TTMacroExpander {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type MacroExpanderFn =
|
pub type MacroExpanderFn =
|
||||||
for<'cx> fn(&'cx mut ExtCtxt, Span, &[tokenstream::TokenTree])
|
for<'cx> fn(&'cx mut ExtCtxt<'_>, Span, &[tokenstream::TokenTree])
|
||||||
-> Box<dyn MacResult+'cx>;
|
-> Box<dyn MacResult+'cx>;
|
||||||
|
|
||||||
impl<F> TTMacroExpander for F
|
impl<F> TTMacroExpander for F
|
||||||
where F: for<'cx> Fn(&'cx mut ExtCtxt, Span, &[tokenstream::TokenTree])
|
where F: for<'cx> Fn(&'cx mut ExtCtxt<'_>, Span, &[tokenstream::TokenTree])
|
||||||
-> Box<dyn MacResult+'cx>
|
-> Box<dyn MacResult+'cx>
|
||||||
{
|
{
|
||||||
fn expand<'cx>(
|
fn expand<'cx>(
|
||||||
&self,
|
&self,
|
||||||
ecx: &'cx mut ExtCtxt,
|
ecx: &'cx mut ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
input: TokenStream,
|
input: TokenStream,
|
||||||
_def_span: Option<Span>,
|
_def_span: Option<Span>,
|
||||||
@ -286,7 +287,7 @@ impl<F> TTMacroExpander for F
|
|||||||
|
|
||||||
pub trait IdentMacroExpander {
|
pub trait IdentMacroExpander {
|
||||||
fn expand<'cx>(&self,
|
fn expand<'cx>(&self,
|
||||||
cx: &'cx mut ExtCtxt,
|
cx: &'cx mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
ident: ast::Ident,
|
ident: ast::Ident,
|
||||||
token_tree: Vec<tokenstream::TokenTree>)
|
token_tree: Vec<tokenstream::TokenTree>)
|
||||||
@ -294,15 +295,15 @@ pub trait IdentMacroExpander {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type IdentMacroExpanderFn =
|
pub type IdentMacroExpanderFn =
|
||||||
for<'cx> fn(&'cx mut ExtCtxt, Span, ast::Ident, Vec<tokenstream::TokenTree>)
|
for<'cx> fn(&'cx mut ExtCtxt<'_>, Span, ast::Ident, Vec<tokenstream::TokenTree>)
|
||||||
-> Box<dyn MacResult+'cx>;
|
-> Box<dyn MacResult+'cx>;
|
||||||
|
|
||||||
impl<F> IdentMacroExpander for F
|
impl<F> IdentMacroExpander for F
|
||||||
where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, ast::Ident,
|
where F : for<'cx> Fn(&'cx mut ExtCtxt<'_>, Span, ast::Ident,
|
||||||
Vec<tokenstream::TokenTree>) -> Box<dyn MacResult+'cx>
|
Vec<tokenstream::TokenTree>) -> Box<dyn MacResult+'cx>
|
||||||
{
|
{
|
||||||
fn expand<'cx>(&self,
|
fn expand<'cx>(&self,
|
||||||
cx: &'cx mut ExtCtxt,
|
cx: &'cx mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
ident: ast::Ident,
|
ident: ast::Ident,
|
||||||
token_tree: Vec<tokenstream::TokenTree>)
|
token_tree: Vec<tokenstream::TokenTree>)
|
||||||
@ -567,7 +568,7 @@ impl MacResult for DummyResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type BuiltinDeriveFn =
|
pub type BuiltinDeriveFn =
|
||||||
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut dyn FnMut(Annotatable));
|
for<'cx> fn(&'cx mut ExtCtxt<'_>, Span, &MetaItem, &Annotatable, &mut dyn FnMut(Annotatable));
|
||||||
|
|
||||||
/// Represents different kinds of macro invocations that can be resolved.
|
/// Represents different kinds of macro invocations that can be resolved.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
@ -979,7 +980,7 @@ impl<'a> ExtCtxt<'a> {
|
|||||||
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
|
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
|
||||||
/// compilation on error, merely emits a non-fatal error and returns None.
|
/// compilation on error, merely emits a non-fatal error and returns None.
|
||||||
pub fn expr_to_spanned_string<'a>(
|
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<Spanned<(Symbol, ast::StrStyle)>, Option<DiagnosticBuilder<'a>>> {
|
||||||
@ -998,7 +999,7 @@ pub fn expr_to_spanned_string<'a>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str)
|
pub fn expr_to_string(cx: &mut ExtCtxt<'_>, expr: P<ast::Expr>, err_msg: &str)
|
||||||
-> Option<(Symbol, ast::StrStyle)> {
|
-> Option<(Symbol, ast::StrStyle)> {
|
||||||
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()))
|
||||||
@ -1011,7 +1012,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str)
|
|||||||
/// compilation should call
|
/// compilation should call
|
||||||
/// `cx.parse_sess.span_diagnostic.abort_if_errors()` (this should be
|
/// `cx.parse_sess.span_diagnostic.abort_if_errors()` (this should be
|
||||||
/// done as rarely as possible).
|
/// done as rarely as possible).
|
||||||
pub fn check_zero_tts(cx: &ExtCtxt,
|
pub fn check_zero_tts(cx: &ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[tokenstream::TokenTree],
|
tts: &[tokenstream::TokenTree],
|
||||||
name: &str) {
|
name: &str) {
|
||||||
@ -1022,7 +1023,7 @@ pub fn check_zero_tts(cx: &ExtCtxt,
|
|||||||
|
|
||||||
/// Interpreting `tts` as a comma-separated sequence of expressions,
|
/// Interpreting `tts` as a comma-separated sequence of expressions,
|
||||||
/// expect exactly one string literal, or emit an error and return None.
|
/// expect exactly one string literal, or emit an error and return None.
|
||||||
pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
|
pub fn get_single_str_from_tts(cx: &mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[tokenstream::TokenTree],
|
tts: &[tokenstream::TokenTree],
|
||||||
name: &str)
|
name: &str)
|
||||||
@ -1045,7 +1046,7 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
|
|||||||
|
|
||||||
/// Extract comma-separated expressions from `tts`. If there is a
|
/// Extract comma-separated expressions from `tts`. If there is a
|
||||||
/// parsing error, emit a non-fatal error and return None.
|
/// parsing error, emit a non-fatal error and return None.
|
||||||
pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
|
pub fn get_exprs_from_tts(cx: &mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[tokenstream::TokenTree]) -> Option<Vec<P<ast::Expr>>> {
|
tts: &[tokenstream::TokenTree]) -> Option<Vec<P<ast::Expr>>> {
|
||||||
let mut p = cx.new_parser_from_tts(tts);
|
let mut p = cx.new_parser_from_tts(tts);
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
|
use crate::ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind};
|
||||||
|
use crate::attr;
|
||||||
|
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||||
|
use crate::ext::base::ExtCtxt;
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::symbol::{Symbol, keywords};
|
||||||
|
use crate::ThinVec;
|
||||||
|
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind};
|
|
||||||
use attr;
|
|
||||||
use syntax_pos::{Pos, Span, DUMMY_SP};
|
use syntax_pos::{Pos, Span, DUMMY_SP};
|
||||||
use source_map::{dummy_spanned, respan, Spanned};
|
|
||||||
use ext::base::ExtCtxt;
|
|
||||||
use ptr::P;
|
|
||||||
use symbol::{Symbol, keywords};
|
|
||||||
use ThinVec;
|
|
||||||
|
|
||||||
// Transitional re-exports so qquote can find the paths it is looking for
|
// Transitional re-exports so qquote can find the paths it is looking for
|
||||||
mod syntax {
|
mod syntax {
|
||||||
pub use ext;
|
pub use crate::ext;
|
||||||
pub use parse;
|
pub use crate::parse;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AstBuilder {
|
pub trait AstBuilder {
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
use attr::HasAttrs;
|
use crate::attr::HasAttrs;
|
||||||
use ast;
|
use crate::ast;
|
||||||
use source_map::{hygiene, ExpnInfo, ExpnFormat};
|
use crate::source_map::{hygiene, ExpnInfo, ExpnFormat};
|
||||||
use ext::base::ExtCtxt;
|
use crate::ext::base::ExtCtxt;
|
||||||
use ext::build::AstBuilder;
|
use crate::ext::build::AstBuilder;
|
||||||
use parse::parser::PathStyle;
|
use crate::parse::parser::PathStyle;
|
||||||
use symbol::Symbol;
|
use crate::symbol::Symbol;
|
||||||
|
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
|
|
||||||
pub fn collect_derives(cx: &mut ExtCtxt, attrs: &mut Vec<ast::Attribute>) -> Vec<ast::Path> {
|
pub fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>) -> Vec<ast::Path> {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
attrs.retain(|attr| {
|
attrs.retain(|attr| {
|
||||||
if attr.path != "derive" {
|
if attr.path != "derive" {
|
||||||
@ -40,7 +41,7 @@ pub fn collect_derives(cx: &mut ExtCtxt, attrs: &mut Vec<ast::Attribute>) -> Vec
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_derived_markers<T>(cx: &mut ExtCtxt, span: Span, traits: &[ast::Path], item: &mut T)
|
pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::Path], item: &mut T)
|
||||||
where T: HasAttrs,
|
where T: HasAttrs,
|
||||||
{
|
{
|
||||||
let (mut names, mut pretty_name) = (FxHashSet::default(), "derive(".to_owned());
|
let (mut names, mut pretty_name) = (FxHashSet::default(), "derive(".to_owned());
|
||||||
|
@ -1,27 +1,28 @@
|
|||||||
use ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path};
|
use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path};
|
||||||
use ast::{MacStmtStyle, StmtKind, ItemKind};
|
use crate::ast::{MacStmtStyle, StmtKind, ItemKind};
|
||||||
use attr::{self, HasAttrs};
|
use crate::attr::{self, HasAttrs};
|
||||||
use source_map::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan};
|
use crate::source_map::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan};
|
||||||
use config::StripUnconfigured;
|
use crate::config::StripUnconfigured;
|
||||||
use errors::{Applicability, FatalError};
|
use crate::errors::{Applicability, FatalError};
|
||||||
use ext::base::*;
|
use crate::ext::base::*;
|
||||||
use ext::derive::{add_derived_markers, collect_derives};
|
use crate::ext::derive::{add_derived_markers, collect_derives};
|
||||||
use ext::hygiene::{self, Mark, SyntaxContext};
|
use crate::ext::hygiene::{self, Mark, SyntaxContext};
|
||||||
use ext::placeholders::{placeholder, PlaceholderExpander};
|
use crate::ext::placeholders::{placeholder, PlaceholderExpander};
|
||||||
use feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
|
use crate::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
|
||||||
use mut_visit::*;
|
use crate::mut_visit::*;
|
||||||
use parse::{DirectoryOwnership, PResult, ParseSess};
|
use crate::parse::{DirectoryOwnership, PResult, ParseSess};
|
||||||
use parse::token::{self, Token};
|
use crate::parse::token::{self, Token};
|
||||||
use parse::parser::Parser;
|
use crate::parse::parser::Parser;
|
||||||
use ptr::P;
|
use crate::ptr::P;
|
||||||
use smallvec::SmallVec;
|
use crate::symbol::Symbol;
|
||||||
use symbol::Symbol;
|
use crate::symbol::keywords;
|
||||||
use symbol::keywords;
|
use crate::tokenstream::{TokenStream, TokenTree};
|
||||||
|
use crate::visit::{self, Visitor};
|
||||||
|
use crate::util::map_in_place::MapInPlace;
|
||||||
|
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::{Span, DUMMY_SP, FileName};
|
use syntax_pos::{Span, DUMMY_SP, FileName};
|
||||||
use syntax_pos::hygiene::ExpnFormat;
|
use syntax_pos::hygiene::ExpnFormat;
|
||||||
use tokenstream::{TokenStream, TokenTree};
|
|
||||||
use visit::{self, Visitor};
|
|
||||||
use util::map_in_place::MapInPlace;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@ -129,8 +130,8 @@ macro_rules! ast_fragments {
|
|||||||
})*)*
|
})*)*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MacResult for ::ext::tt::macro_rules::ParserAnyMacro<'a> {
|
impl<'a> MacResult for crate::ext::tt::macro_rules::ParserAnyMacro<'a> {
|
||||||
$(fn $make_ast(self: Box<::ext::tt::macro_rules::ParserAnyMacro<'a>>)
|
$(fn $make_ast(self: Box<crate::ext::tt::macro_rules::ParserAnyMacro<'a>>)
|
||||||
-> Option<$AstTy> {
|
-> Option<$AstTy> {
|
||||||
Some(self.make(AstFragmentKind::$Kind).$make_ast())
|
Some(self.make(AstFragmentKind::$Kind).$make_ast())
|
||||||
})*
|
})*
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use ast::{self, NodeId};
|
use crate::ast::{self, NodeId};
|
||||||
use source_map::{DUMMY_SP, dummy_spanned};
|
use crate::source_map::{DUMMY_SP, dummy_spanned};
|
||||||
use ext::base::ExtCtxt;
|
use crate::ext::base::ExtCtxt;
|
||||||
use ext::expand::{AstFragment, AstFragmentKind};
|
use crate::ext::expand::{AstFragment, AstFragmentKind};
|
||||||
use ext::hygiene::Mark;
|
use crate::ext::hygiene::Mark;
|
||||||
use tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
use mut_visit::*;
|
use crate::mut_visit::*;
|
||||||
use ptr::P;
|
use crate::ptr::P;
|
||||||
use smallvec::SmallVec;
|
use crate::symbol::keywords;
|
||||||
use symbol::keywords;
|
use crate::ThinVec;
|
||||||
use ThinVec;
|
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
use ast;
|
use crate::ast;
|
||||||
use syntax_pos::{self, Pos, Span, FileName};
|
use crate::ext::base::{self, *};
|
||||||
use ext::base::*;
|
use crate::ext::build::AstBuilder;
|
||||||
use ext::base;
|
use crate::parse::{self, token, DirectoryOwnership};
|
||||||
use ext::build::AstBuilder;
|
use crate::print::pprust;
|
||||||
use parse::{token, DirectoryOwnership};
|
use crate::ptr::P;
|
||||||
use parse;
|
use crate::symbol::Symbol;
|
||||||
use print::pprust;
|
use crate::tokenstream;
|
||||||
use ptr::P;
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use symbol::Symbol;
|
use syntax_pos::{self, Pos, Span, FileName};
|
||||||
use tokenstream;
|
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
@ -21,7 +20,7 @@ use rustc_data_structures::sync::Lrc;
|
|||||||
// a given file into the current one.
|
// a given file into the current one.
|
||||||
|
|
||||||
/// line!(): expands to the current line number
|
/// line!(): expands to the current line number
|
||||||
pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_line(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
base::check_zero_tts(cx, sp, tts, "line!");
|
base::check_zero_tts(cx, sp, tts, "line!");
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* column!(): expands to the current column number */
|
/* column!(): expands to the current column number */
|
||||||
pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
base::check_zero_tts(cx, sp, tts, "column!");
|
base::check_zero_tts(cx, sp, tts, "column!");
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* __rust_unstable_column!(): expands to the current column number */
|
/* __rust_unstable_column!(): expands to the current column number */
|
||||||
pub fn expand_column_gated(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_column_gated(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
if sp.allows_unstable() {
|
if sp.allows_unstable() {
|
||||||
expand_column(cx, sp, tts)
|
expand_column(cx, sp, tts)
|
||||||
@ -55,7 +54,7 @@ pub fn expand_column_gated(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Token
|
|||||||
/// file!(): expands to the current filename */
|
/// file!(): expands to the current filename */
|
||||||
/// The source_file (`loc.file`) contains a bunch more information we could spit
|
/// The source_file (`loc.file`) contains a bunch more information we could spit
|
||||||
/// out if we wanted.
|
/// out if we wanted.
|
||||||
pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_file(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
base::check_zero_tts(cx, sp, tts, "file!");
|
base::check_zero_tts(cx, sp, tts, "file!");
|
||||||
|
|
||||||
@ -64,13 +63,13 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
|||||||
base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name.to_string())))
|
base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name.to_string())))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_stringify(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
let s = pprust::tts_to_string(tts);
|
let s = pprust::tts_to_string(tts);
|
||||||
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s)))
|
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_mod(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
base::check_zero_tts(cx, sp, tts, "module_path!");
|
base::check_zero_tts(cx, sp, tts, "module_path!");
|
||||||
let mod_path = &cx.current_expansion.module.mod_path;
|
let mod_path = &cx.current_expansion.module.mod_path;
|
||||||
@ -82,7 +81,7 @@ pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
|||||||
/// include! : parse the given file as an expr
|
/// include! : parse the given file as an expr
|
||||||
/// This is generally a bad idea because it's going to behave
|
/// This is generally a bad idea because it's going to behave
|
||||||
/// unhygienically.
|
/// unhygienically.
|
||||||
pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'cx> {
|
-> Box<dyn base::MacResult+'cx> {
|
||||||
let file = match get_single_str_from_tts(cx, sp, tts, "include!") {
|
let file = match get_single_str_from_tts(cx, sp, tts, "include!") {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
@ -120,7 +119,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T
|
|||||||
}
|
}
|
||||||
|
|
||||||
// include_str! : read the given file, insert it as a literal string expr
|
// include_str! : read the given file, insert it as a literal string expr
|
||||||
pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") {
|
let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
@ -148,7 +147,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
-> Box<dyn base::MacResult+'static> {
|
-> Box<dyn base::MacResult+'static> {
|
||||||
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
|
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
@ -178,7 +177,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke
|
|||||||
|
|
||||||
// resolve a file-system path to an absolute file-system path (if it
|
// resolve a file-system path to an absolute file-system path (if it
|
||||||
// isn't already)
|
// isn't already)
|
||||||
fn res_rel_file(cx: &mut ExtCtxt, sp: syntax_pos::Span, arg: String) -> PathBuf {
|
fn res_rel_file(cx: &mut ExtCtxt<'_>, sp: syntax_pos::Span, arg: String) -> PathBuf {
|
||||||
let arg = PathBuf::from(arg);
|
let arg = PathBuf::from(arg);
|
||||||
// Relative paths are resolved relative to the file in which they are found
|
// Relative paths are resolved relative to the file in which they are found
|
||||||
// after macro expansion (that is, they are unhygienic).
|
// after macro expansion (that is, they are unhygienic).
|
||||||
|
@ -70,21 +70,22 @@
|
|||||||
//! eof: [a $( a )* a b ·]
|
//! eof: [a $( a )* a b ·]
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
pub use self::NamedMatch::*;
|
pub use NamedMatch::*;
|
||||||
pub use self::ParseResult::*;
|
pub use ParseResult::*;
|
||||||
use self::TokenTreeOrTokenTreeSlice::*;
|
use TokenTreeOrTokenTreeSlice::*;
|
||||||
|
|
||||||
use ast::Ident;
|
use crate::ast::Ident;
|
||||||
|
use crate::errors::FatalError;
|
||||||
|
use crate::ext::tt::quoted::{self, TokenTree};
|
||||||
|
use crate::parse::{Directory, ParseSess};
|
||||||
|
use crate::parse::parser::{Parser, PathStyle};
|
||||||
|
use crate::parse::token::{self, DocComment, Nonterminal, Token};
|
||||||
|
use crate::print::pprust;
|
||||||
|
use crate::symbol::keywords;
|
||||||
|
use crate::tokenstream::{DelimSpan, TokenStream};
|
||||||
|
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::{self, Span};
|
use syntax_pos::{self, Span};
|
||||||
use errors::FatalError;
|
|
||||||
use ext::tt::quoted::{self, TokenTree};
|
|
||||||
use parse::{Directory, ParseSess};
|
|
||||||
use parse::parser::{Parser, PathStyle};
|
|
||||||
use parse::token::{self, DocComment, Nonterminal, Token};
|
|
||||||
use print::pprust;
|
|
||||||
use smallvec::SmallVec;
|
|
||||||
use symbol::keywords;
|
|
||||||
use tokenstream::{DelimSpan, TokenStream};
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
@ -649,7 +650,7 @@ pub fn parse(
|
|||||||
sess: &ParseSess,
|
sess: &ParseSess,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
ms: &[TokenTree],
|
ms: &[TokenTree],
|
||||||
directory: Option<Directory>,
|
directory: Option<Directory<'_>>,
|
||||||
recurse_into_modules: bool,
|
recurse_into_modules: bool,
|
||||||
) -> NamedParseResult {
|
) -> NamedParseResult {
|
||||||
// Create a parser that can be used for the "black box" parts.
|
// Create a parser that can be used for the "black box" parts.
|
||||||
|
@ -1,29 +1,31 @@
|
|||||||
use {ast, attr};
|
use crate::{ast, attr};
|
||||||
|
use crate::edition::Edition;
|
||||||
|
use crate::errors::FatalError;
|
||||||
|
use crate::ext::base::{DummyResult, ExtCtxt, MacResult, SyntaxExtension};
|
||||||
|
use crate::ext::base::{NormalTT, TTMacroExpander};
|
||||||
|
use crate::ext::expand::{AstFragment, AstFragmentKind};
|
||||||
|
use crate::ext::tt::macro_parser::{Success, Error, Failure};
|
||||||
|
use crate::ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal};
|
||||||
|
use crate::ext::tt::macro_parser::{parse, parse_failure_msg};
|
||||||
|
use crate::ext::tt::quoted;
|
||||||
|
use crate::ext::tt::transcribe::transcribe;
|
||||||
|
use crate::feature_gate::Features;
|
||||||
|
use crate::parse::{Directory, ParseSess};
|
||||||
|
use crate::parse::parser::Parser;
|
||||||
|
use crate::parse::token::{self, NtTT};
|
||||||
|
use crate::parse::token::Token::*;
|
||||||
|
use crate::symbol::Symbol;
|
||||||
|
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
|
||||||
|
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
use edition::Edition;
|
use log::debug;
|
||||||
use errors::FatalError;
|
|
||||||
use ext::base::{DummyResult, ExtCtxt, MacResult, SyntaxExtension};
|
|
||||||
use ext::base::{NormalTT, TTMacroExpander};
|
|
||||||
use ext::expand::{AstFragment, AstFragmentKind};
|
|
||||||
use ext::tt::macro_parser::{Success, Error, Failure};
|
|
||||||
use ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal};
|
|
||||||
use ext::tt::macro_parser::{parse, parse_failure_msg};
|
|
||||||
use ext::tt::quoted;
|
|
||||||
use ext::tt::transcribe::transcribe;
|
|
||||||
use feature_gate::Features;
|
|
||||||
use parse::{Directory, ParseSess};
|
|
||||||
use parse::parser::Parser;
|
|
||||||
use parse::token::{self, NtTT};
|
|
||||||
use parse::token::Token::*;
|
|
||||||
use symbol::Symbol;
|
|
||||||
use tokenstream::{DelimSpan, TokenStream, TokenTree};
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use errors::Applicability;
|
use crate::errors::Applicability;
|
||||||
|
|
||||||
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
|
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
|
||||||
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, \
|
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, \
|
||||||
@ -91,7 +93,7 @@ struct MacroRulesMacroExpander {
|
|||||||
impl TTMacroExpander for MacroRulesMacroExpander {
|
impl TTMacroExpander for MacroRulesMacroExpander {
|
||||||
fn expand<'cx>(
|
fn expand<'cx>(
|
||||||
&self,
|
&self,
|
||||||
cx: &'cx mut ExtCtxt,
|
cx: &'cx mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
input: TokenStream,
|
input: TokenStream,
|
||||||
def_span: Option<Span>,
|
def_span: Option<Span>,
|
||||||
@ -109,13 +111,13 @@ impl TTMacroExpander for MacroRulesMacroExpander {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) {
|
fn trace_macros_note(cx: &mut ExtCtxt<'_>, sp: Span, message: String) {
|
||||||
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
|
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
|
||||||
cx.expansions.entry(sp).or_default().push(message);
|
cx.expansions.entry(sp).or_default().push(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given `lhses` and `rhses`, this is the new macro we create
|
/// Given `lhses` and `rhses`, this is the new macro we create
|
||||||
fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
fn generic_extension<'cx>(cx: &'cx mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
def_span: Option<Span>,
|
def_span: Option<Span>,
|
||||||
name: ast::Ident,
|
name: ast::Ident,
|
||||||
@ -423,7 +425,7 @@ fn check_lhs_nt_follows(sess: &ParseSess,
|
|||||||
/// Check that the lhs contains no repetition which could match an empty token
|
/// Check that the lhs contains no repetition which could match an empty token
|
||||||
/// tree, because then the matcher would hang indefinitely.
|
/// tree, because then the matcher would hang indefinitely.
|
||||||
fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[quoted::TokenTree]) -> bool {
|
fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[quoted::TokenTree]) -> bool {
|
||||||
use self::quoted::TokenTree;
|
use quoted::TokenTree;
|
||||||
for tt in tts {
|
for tt in tts {
|
||||||
match *tt {
|
match *tt {
|
||||||
TokenTree::Token(..) | TokenTree::MetaVar(..) | TokenTree::MetaVarDecl(..) => (),
|
TokenTree::Token(..) | TokenTree::MetaVar(..) | TokenTree::MetaVarDecl(..) => (),
|
||||||
@ -497,7 +499,7 @@ struct FirstSets {
|
|||||||
|
|
||||||
impl FirstSets {
|
impl FirstSets {
|
||||||
fn new(tts: &[quoted::TokenTree]) -> FirstSets {
|
fn new(tts: &[quoted::TokenTree]) -> FirstSets {
|
||||||
use self::quoted::TokenTree;
|
use quoted::TokenTree;
|
||||||
|
|
||||||
let mut sets = FirstSets { first: FxHashMap::default() };
|
let mut sets = FirstSets { first: FxHashMap::default() };
|
||||||
build_recur(&mut sets, tts);
|
build_recur(&mut sets, tts);
|
||||||
@ -567,7 +569,7 @@ impl FirstSets {
|
|||||||
// walks forward over `tts` until all potential FIRST tokens are
|
// walks forward over `tts` until all potential FIRST tokens are
|
||||||
// identified.
|
// identified.
|
||||||
fn first(&self, tts: &[quoted::TokenTree]) -> TokenSet {
|
fn first(&self, tts: &[quoted::TokenTree]) -> TokenSet {
|
||||||
use self::quoted::TokenTree;
|
use quoted::TokenTree;
|
||||||
|
|
||||||
let mut first = TokenSet::empty();
|
let mut first = TokenSet::empty();
|
||||||
for tt in tts.iter() {
|
for tt in tts.iter() {
|
||||||
@ -721,7 +723,7 @@ fn check_matcher_core(sess: &ParseSess,
|
|||||||
first_sets: &FirstSets,
|
first_sets: &FirstSets,
|
||||||
matcher: &[quoted::TokenTree],
|
matcher: &[quoted::TokenTree],
|
||||||
follow: &TokenSet) -> TokenSet {
|
follow: &TokenSet) -> TokenSet {
|
||||||
use self::quoted::TokenTree;
|
use quoted::TokenTree;
|
||||||
|
|
||||||
let mut last = TokenSet::empty();
|
let mut last = TokenSet::empty();
|
||||||
|
|
||||||
@ -940,7 +942,7 @@ enum IsInFollow {
|
|||||||
/// separator.
|
/// separator.
|
||||||
// when changing this do not forget to update doc/book/macros.md!
|
// when changing this do not forget to update doc/book/macros.md!
|
||||||
fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow {
|
fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow {
|
||||||
use self::quoted::TokenTree;
|
use quoted::TokenTree;
|
||||||
|
|
||||||
if let TokenTree::Token(_, token::CloseDelim(_)) = *tok {
|
if let TokenTree::Token(_, token::CloseDelim(_)) = *tok {
|
||||||
// closing a token tree can never be matched by any fragment;
|
// closing a token tree can never be matched by any fragment;
|
||||||
@ -1072,7 +1074,7 @@ fn is_legal_fragment_specifier(_sess: &ParseSess,
|
|||||||
|
|
||||||
fn quoted_tt_to_string(tt: "ed::TokenTree) -> String {
|
fn quoted_tt_to_string(tt: "ed::TokenTree) -> String {
|
||||||
match *tt {
|
match *tt {
|
||||||
quoted::TokenTree::Token(_, ref tok) => ::print::pprust::token_to_string(tok),
|
quoted::TokenTree::Token(_, ref tok) => crate::print::pprust::token_to_string(tok),
|
||||||
quoted::TokenTree::MetaVar(_, name) => format!("${}", name),
|
quoted::TokenTree::MetaVar(_, name) => format!("${}", name),
|
||||||
quoted::TokenTree::MetaVarDecl(_, name, kind) => format!("${}:{}", name, kind),
|
quoted::TokenTree::MetaVarDecl(_, name, kind) => format!("${}:{}", name, kind),
|
||||||
_ => panic!("unexpected quoted::TokenTree::{{Sequence or Delimited}} \
|
_ => panic!("unexpected quoted::TokenTree::{{Sequence or Delimited}} \
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
use ast::NodeId;
|
use crate::ast::NodeId;
|
||||||
use early_buffered_lints::BufferedEarlyLintId;
|
use crate::early_buffered_lints::BufferedEarlyLintId;
|
||||||
use ext::tt::macro_parser;
|
use crate::ext::tt::macro_parser;
|
||||||
use feature_gate::Features;
|
use crate::feature_gate::Features;
|
||||||
use parse::{token, ParseSess};
|
use crate::parse::{token, ParseSess};
|
||||||
use print::pprust;
|
use crate::print::pprust;
|
||||||
use symbol::keywords;
|
use crate::tokenstream::{self, DelimSpan};
|
||||||
|
use crate::ast;
|
||||||
|
use crate::symbol::keywords;
|
||||||
|
|
||||||
use syntax_pos::{edition::Edition, BytePos, Span};
|
use syntax_pos::{edition::Edition, BytePos, Span};
|
||||||
use tokenstream::{self, DelimSpan};
|
|
||||||
use ast;
|
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
use ast::Ident;
|
use crate::ast::Ident;
|
||||||
use ext::base::ExtCtxt;
|
use crate::ext::base::ExtCtxt;
|
||||||
use ext::expand::Marker;
|
use crate::ext::expand::Marker;
|
||||||
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
|
use crate::ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
|
||||||
use ext::tt::quoted;
|
use crate::ext::tt::quoted;
|
||||||
use mut_visit::noop_visit_tt;
|
use crate::mut_visit::noop_visit_tt;
|
||||||
use parse::token::{self, Token, NtTT};
|
use crate::parse::token::{self, Token, NtTT};
|
||||||
use smallvec::SmallVec;
|
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
|
||||||
|
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::DUMMY_SP;
|
use syntax_pos::DUMMY_SP;
|
||||||
use tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
@ -56,7 +57,7 @@ impl Iterator for Frame {
|
|||||||
/// This can do Macro-By-Example transcription. On the other hand, if
|
/// This can do Macro-By-Example transcription. On the other hand, if
|
||||||
/// `src` contains no `TokenTree::{Sequence, MetaVar, MetaVarDecl}`s, `interp` can
|
/// `src` contains no `TokenTree::{Sequence, MetaVar, MetaVarDecl}`s, `interp` can
|
||||||
/// (and should) be None.
|
/// (and should) be None.
|
||||||
pub fn transcribe(cx: &ExtCtxt,
|
pub fn transcribe(cx: &ExtCtxt<'_>,
|
||||||
interp: Option<FxHashMap<Ident, Rc<NamedMatch>>>,
|
interp: Option<FxHashMap<Ident, Rc<NamedMatch>>>,
|
||||||
src: Vec<quoted::TokenTree>)
|
src: Vec<quoted::TokenTree>)
|
||||||
-> TokenStream {
|
-> TokenStream {
|
||||||
@ -230,7 +231,7 @@ fn lockstep_iter_size(tree: "ed::TokenTree,
|
|||||||
interpolations: &FxHashMap<Ident, Rc<NamedMatch>>,
|
interpolations: &FxHashMap<Ident, Rc<NamedMatch>>,
|
||||||
repeats: &[(usize, usize)])
|
repeats: &[(usize, usize)])
|
||||||
-> LockstepIterSize {
|
-> LockstepIterSize {
|
||||||
use self::quoted::TokenTree;
|
use quoted::TokenTree;
|
||||||
match *tree {
|
match *tree {
|
||||||
TokenTree::Delimited(_, ref delimed) => {
|
TokenTree::Delimited(_, ref delimed) => {
|
||||||
delimed.tts.iter().fold(LockstepIterSize::Unconstrained, |size, tt| {
|
delimed.tts.iter().fold(LockstepIterSize::Unconstrained, |size, tt| {
|
||||||
|
@ -12,21 +12,23 @@
|
|||||||
//! gate usage is added, *do not remove it again* even once the feature
|
//! gate usage is added, *do not remove it again* even once the feature
|
||||||
//! becomes stable.
|
//! becomes stable.
|
||||||
|
|
||||||
use self::AttributeType::*;
|
use AttributeType::*;
|
||||||
use self::AttributeGate::*;
|
use AttributeGate::*;
|
||||||
|
|
||||||
|
use crate::ast::{self, NodeId, PatKind, RangeEnd};
|
||||||
|
use crate::attr;
|
||||||
|
use crate::early_buffered_lints::BufferedEarlyLintId;
|
||||||
|
use crate::source_map::Spanned;
|
||||||
|
use crate::edition::{ALL_EDITIONS, Edition};
|
||||||
|
use crate::errors::{DiagnosticBuilder, Handler};
|
||||||
|
use crate::visit::{self, FnKind, Visitor};
|
||||||
|
use crate::parse::ParseSess;
|
||||||
|
use crate::symbol::Symbol;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use ast::{self, NodeId, PatKind, RangeEnd};
|
|
||||||
use attr;
|
|
||||||
use early_buffered_lints::BufferedEarlyLintId;
|
|
||||||
use source_map::Spanned;
|
|
||||||
use edition::{ALL_EDITIONS, Edition};
|
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
use errors::{DiagnosticBuilder, Handler};
|
use log::debug;
|
||||||
use visit::{self, FnKind, Visitor};
|
|
||||||
use parse::ParseSess;
|
|
||||||
use symbol::Symbol;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
@ -778,8 +780,8 @@ pub enum Stability {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fn() is not Debug
|
// fn() is not Debug
|
||||||
impl ::std::fmt::Debug for AttributeGate {
|
impl std::fmt::Debug for AttributeGate {
|
||||||
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Gated(ref stab, name, expl, _) =>
|
Gated(ref stab, name, expl, _) =>
|
||||||
write!(fmt, "Gated({:?}, {}, {})", stab, name, expl),
|
write!(fmt, "Gated({:?}, {}, {})", stab, name, expl),
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
// FIXME: spec the JSON output properly.
|
// FIXME: spec the JSON output properly.
|
||||||
|
|
||||||
use source_map::{SourceMap, FilePathMapping};
|
use crate::source_map::{SourceMap, FilePathMapping};
|
||||||
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
|
use crate::errors::registry::Registry;
|
||||||
use errors::registry::Registry;
|
use crate::errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, SourceMapper};
|
||||||
use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, SourceMapper};
|
use crate::errors::{DiagnosticId, Applicability};
|
||||||
use errors::{DiagnosticId, Applicability};
|
use crate::errors::emitter::{Emitter, EmitterWriter};
|
||||||
use errors::emitter::{Emitter, EmitterWriter};
|
|
||||||
|
|
||||||
|
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
|
||||||
use rustc_data_structures::sync::{self, Lrc};
|
use rustc_data_structures::sync::{self, Lrc};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
@ -69,7 +69,7 @@ impl JsonEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for JsonEmitter {
|
impl Emitter for JsonEmitter {
|
||||||
fn emit(&mut self, db: &DiagnosticBuilder) {
|
fn emit(&mut self, db: &DiagnosticBuilder<'_>) {
|
||||||
let data = Diagnostic::from_diagnostic_builder(db, self);
|
let data = Diagnostic::from_diagnostic_builder(db, self);
|
||||||
let result = if self.pretty {
|
let result = if self.pretty {
|
||||||
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
||||||
@ -159,7 +159,7 @@ struct DiagnosticCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic {
|
impl Diagnostic {
|
||||||
fn from_diagnostic_builder(db: &DiagnosticBuilder,
|
fn from_diagnostic_builder(db: &DiagnosticBuilder<'_>,
|
||||||
je: &JsonEmitter)
|
je: &JsonEmitter)
|
||||||
-> Diagnostic {
|
-> Diagnostic {
|
||||||
let sugg = db.suggestions.iter().map(|sugg| {
|
let sugg = db.suggestions.iter().map(|sugg| {
|
||||||
|
@ -9,9 +9,10 @@
|
|||||||
html_root_url = "https://doc.rust-lang.org/nightly/",
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
||||||
test(attr(deny(warnings))))]
|
test(attr(deny(warnings))))]
|
||||||
|
|
||||||
|
#![deny(rust_2018_idioms)]
|
||||||
|
|
||||||
#![feature(crate_visibility_modifier)]
|
#![feature(crate_visibility_modifier)]
|
||||||
#![feature(label_break_value)]
|
#![feature(label_break_value)]
|
||||||
#![feature(nll)]
|
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![feature(rustc_diagnostic_macros)]
|
#![feature(rustc_diagnostic_macros)]
|
||||||
#![feature(slice_sort_by_cached_key)]
|
#![feature(slice_sort_by_cached_key)]
|
||||||
@ -22,20 +23,10 @@
|
|||||||
|
|
||||||
#![recursion_limit="256"]
|
#![recursion_limit="256"]
|
||||||
|
|
||||||
#[macro_use] extern crate bitflags;
|
#[allow(unused_extern_crates)]
|
||||||
extern crate core;
|
|
||||||
extern crate serialize;
|
|
||||||
#[macro_use] extern crate log;
|
|
||||||
pub extern crate rustc_errors as errors;
|
|
||||||
extern crate syntax_pos;
|
|
||||||
#[macro_use] extern crate rustc_data_structures;
|
|
||||||
extern crate rustc_target;
|
|
||||||
#[macro_use] extern crate scoped_tls;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate smallvec;
|
|
||||||
|
|
||||||
extern crate serialize as rustc_serialize; // used by deriving
|
extern crate serialize as rustc_serialize; // used by deriving
|
||||||
|
|
||||||
|
pub use rustc_errors as errors;
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use rustc_data_structures::bit_set::GrowableBitSet;
|
use rustc_data_structures::bit_set::GrowableBitSet;
|
||||||
pub use rustc_data_structures::thin_vec::ThinVec;
|
pub use rustc_data_structures::thin_vec::ThinVec;
|
||||||
@ -48,7 +39,7 @@ use ast::AttrId;
|
|||||||
macro_rules! panictry {
|
macro_rules! panictry {
|
||||||
($e:expr) => ({
|
($e:expr) => ({
|
||||||
use std::result::Result::{Ok, Err};
|
use std::result::Result::{Ok, Err};
|
||||||
use errors::FatalError;
|
use crate::errors::FatalError;
|
||||||
match $e {
|
match $e {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(mut e) => {
|
Err(mut e) => {
|
||||||
@ -63,7 +54,7 @@ macro_rules! panictry {
|
|||||||
macro_rules! panictry_buffer {
|
macro_rules! panictry_buffer {
|
||||||
($handler:expr, $e:expr) => ({
|
($handler:expr, $e:expr) => ({
|
||||||
use std::result::Result::{Ok, Err};
|
use std::result::Result::{Ok, Err};
|
||||||
use errors::{FatalError, DiagnosticBuilder};
|
use crate::errors::{FatalError, DiagnosticBuilder};
|
||||||
match $e {
|
match $e {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(errs) => {
|
Err(errs) => {
|
||||||
@ -113,7 +104,7 @@ pub fn with_globals<F, R>(f: F) -> R
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_thread_local!(pub static GLOBALS: Globals);
|
scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod diagnostics {
|
pub mod diagnostics {
|
||||||
@ -139,9 +130,9 @@ pub mod util {
|
|||||||
pub mod json;
|
pub mod json;
|
||||||
|
|
||||||
pub mod syntax {
|
pub mod syntax {
|
||||||
pub use ext;
|
pub use crate::ext;
|
||||||
pub use parse;
|
pub use crate::parse;
|
||||||
pub use ast;
|
pub use crate::ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
|
@ -7,19 +7,20 @@
|
|||||||
//! a MutVisitor renaming item names in a module will miss all of those
|
//! a MutVisitor renaming item names in a module will miss all of those
|
||||||
//! that are created by the expansion of a macro.
|
//! that are created by the expansion of a macro.
|
||||||
|
|
||||||
use ast::*;
|
use crate::ast::*;
|
||||||
|
use crate::source_map::{Spanned, respan};
|
||||||
|
use crate::parse::token::{self, Token};
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::symbol::keywords;
|
||||||
|
use crate::ThinVec;
|
||||||
|
use crate::tokenstream::*;
|
||||||
|
use crate::util::map_in_place::MapInPlace;
|
||||||
|
|
||||||
|
use smallvec::{smallvec, Array, SmallVec};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use source_map::{Spanned, respan};
|
|
||||||
use parse::token::{self, Token};
|
|
||||||
use ptr::P;
|
|
||||||
use smallvec::{Array, SmallVec};
|
|
||||||
use std::ops::DerefMut;
|
|
||||||
use symbol::keywords;
|
|
||||||
use ThinVec;
|
|
||||||
use tokenstream::*;
|
|
||||||
use util::map_in_place::MapInPlace;
|
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
pub trait ExpectOne<A: Array> {
|
pub trait ExpectOne<A: Array> {
|
||||||
fn expect_one(self, err: &'static str) -> A::Item;
|
fn expect_one(self, err: &'static str) -> A::Item;
|
||||||
@ -1256,15 +1257,15 @@ pub fn noop_visit_vis<T: MutVisitor>(Spanned { node, span }: &mut Visibility, vi
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::io;
|
use std::io;
|
||||||
use ast::{self, Ident};
|
use crate::ast::{self, Ident};
|
||||||
use util::parser_testing::{string_to_crate, matches_codepattern};
|
use crate::util::parser_testing::{string_to_crate, matches_codepattern};
|
||||||
use print::pprust;
|
use crate::print::pprust;
|
||||||
use mut_visit;
|
use crate::mut_visit;
|
||||||
use with_globals;
|
use crate::with_globals;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// this version doesn't care about getting comments or docstrings in.
|
// this version doesn't care about getting comments or docstrings in.
|
||||||
fn fake_print_crate(s: &mut pprust::State,
|
fn fake_print_crate(s: &mut pprust::State<'_>,
|
||||||
krate: &ast::Crate) -> io::Result<()> {
|
krate: &ast::Crate) -> io::Result<()> {
|
||||||
s.print_mod(&krate.module, &krate.attrs)
|
s.print_mod(&krate.module, &krate.attrs)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
use attr;
|
use crate::attr;
|
||||||
use ast;
|
use crate::ast;
|
||||||
use source_map::respan;
|
use crate::source_map::respan;
|
||||||
use parse::{SeqSep, PResult};
|
use crate::parse::{SeqSep, PResult};
|
||||||
use parse::token::{self, Nonterminal, DelimToken};
|
use crate::parse::token::{self, Nonterminal, DelimToken};
|
||||||
use parse::parser::{Parser, TokenType, PathStyle};
|
use crate::parse::parser::{Parser, TokenType, PathStyle};
|
||||||
use tokenstream::{TokenStream, TokenTree};
|
use crate::tokenstream::{TokenStream, TokenTree};
|
||||||
|
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum InnerAttributeParsePolicy<'a> {
|
enum InnerAttributeParsePolicy<'a> {
|
||||||
@ -74,7 +76,7 @@ impl<'a> Parser<'a> {
|
|||||||
/// The same as `parse_attribute`, except it takes in an `InnerAttributeParsePolicy`
|
/// The same as `parse_attribute`, except it takes in an `InnerAttributeParsePolicy`
|
||||||
/// that prescribes how to handle inner attributes.
|
/// that prescribes how to handle inner attributes.
|
||||||
fn parse_attribute_with_inner_parse_policy(&mut self,
|
fn parse_attribute_with_inner_parse_policy(&mut self,
|
||||||
inner_parse_policy: InnerAttributeParsePolicy)
|
inner_parse_policy: InnerAttributeParsePolicy<'_>)
|
||||||
-> PResult<'a, ast::Attribute> {
|
-> PResult<'a, ast::Attribute> {
|
||||||
debug!("parse_attribute_with_inner_parse_policy: inner_parse_policy={:?} self.token={:?}",
|
debug!("parse_attribute_with_inner_parse_policy: inner_parse_policy={:?} self.token={:?}",
|
||||||
inner_parse_policy,
|
inner_parse_policy,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// Predicates on exprs and stmts that the pretty-printer and parser use
|
// Predicates on exprs and stmts that the pretty-printer and parser use
|
||||||
|
|
||||||
use ast;
|
use crate::ast;
|
||||||
|
|
||||||
/// Does this expression require a semicolon to be treated
|
/// Does this expression require a semicolon to be treated
|
||||||
/// as a statement? The negation of this: 'can this expression
|
/// as a statement? The negation of this: 'can this expression
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
pub use self::CommentStyle::*;
|
pub use CommentStyle::*;
|
||||||
|
|
||||||
|
use crate::ast;
|
||||||
|
use crate::source_map::SourceMap;
|
||||||
|
use crate::parse::lexer::{is_block_doc_comment, is_pattern_whitespace};
|
||||||
|
use crate::parse::lexer::{self, ParseSess, StringReader, TokenAndSpan};
|
||||||
|
use crate::print::pprust;
|
||||||
|
|
||||||
use ast;
|
|
||||||
use source_map::SourceMap;
|
|
||||||
use syntax_pos::{BytePos, CharPos, Pos, FileName};
|
use syntax_pos::{BytePos, CharPos, Pos, FileName};
|
||||||
use parse::lexer::{is_block_doc_comment, is_pattern_whitespace};
|
use log::debug;
|
||||||
use parse::lexer::{self, ParseSess, StringReader, TokenAndSpan};
|
|
||||||
use print::pprust;
|
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::usize;
|
use std::usize;
|
||||||
@ -135,7 +137,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
|
|||||||
panic!("not a doc-comment: {}", comment);
|
panic!("not a doc-comment: {}", comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_blank_line_comment(rdr: &StringReader, comments: &mut Vec<Comment>) {
|
fn push_blank_line_comment(rdr: &StringReader<'_>, comments: &mut Vec<Comment>) {
|
||||||
debug!(">>> blank-line comment");
|
debug!(">>> blank-line comment");
|
||||||
comments.push(Comment {
|
comments.push(Comment {
|
||||||
style: BlankLine,
|
style: BlankLine,
|
||||||
@ -144,7 +146,10 @@ fn push_blank_line_comment(rdr: &StringReader, comments: &mut Vec<Comment>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader, comments: &mut Vec<Comment>) {
|
fn consume_whitespace_counting_blank_lines(
|
||||||
|
rdr: &mut StringReader<'_>,
|
||||||
|
comments: &mut Vec<Comment>
|
||||||
|
) {
|
||||||
while is_pattern_whitespace(rdr.ch) && !rdr.is_eof() {
|
while is_pattern_whitespace(rdr.ch) && !rdr.is_eof() {
|
||||||
if rdr.ch_is('\n') {
|
if rdr.ch_is('\n') {
|
||||||
push_blank_line_comment(rdr, &mut *comments);
|
push_blank_line_comment(rdr, &mut *comments);
|
||||||
@ -153,7 +158,7 @@ fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader, comments: &mu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_shebang_comment(rdr: &mut StringReader,
|
fn read_shebang_comment(rdr: &mut StringReader<'_>,
|
||||||
code_to_the_left: bool,
|
code_to_the_left: bool,
|
||||||
comments: &mut Vec<Comment>) {
|
comments: &mut Vec<Comment>) {
|
||||||
debug!(">>> shebang comment");
|
debug!(">>> shebang comment");
|
||||||
@ -166,7 +171,7 @@ fn read_shebang_comment(rdr: &mut StringReader,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_line_comments(rdr: &mut StringReader,
|
fn read_line_comments(rdr: &mut StringReader<'_>,
|
||||||
code_to_the_left: bool,
|
code_to_the_left: bool,
|
||||||
comments: &mut Vec<Comment>) {
|
comments: &mut Vec<Comment>) {
|
||||||
debug!(">>> line comments");
|
debug!(">>> line comments");
|
||||||
@ -222,7 +227,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<String>, s: String, col:
|
|||||||
lines.push(s1);
|
lines.push(s1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_block_comment(rdr: &mut StringReader,
|
fn read_block_comment(rdr: &mut StringReader<'_>,
|
||||||
code_to_the_left: bool,
|
code_to_the_left: bool,
|
||||||
comments: &mut Vec<Comment>) {
|
comments: &mut Vec<Comment>) {
|
||||||
debug!(">>> block comment");
|
debug!(">>> block comment");
|
||||||
@ -312,7 +317,7 @@ fn read_block_comment(rdr: &mut StringReader,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn consume_comment(rdr: &mut StringReader,
|
fn consume_comment(rdr: &mut StringReader<'_>,
|
||||||
comments: &mut Vec<Comment>,
|
comments: &mut Vec<Comment>,
|
||||||
code_to_the_left: &mut bool,
|
code_to_the_left: &mut bool,
|
||||||
anything_to_the_left: &mut bool) {
|
anything_to_the_left: &mut bool) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use ast::{self, Ident};
|
use crate::ast::{self, Ident};
|
||||||
|
use crate::source_map::{SourceMap, FilePathMapping};
|
||||||
|
use crate::errors::{Applicability, FatalError, Diagnostic, DiagnosticBuilder};
|
||||||
|
use crate::parse::{token, ParseSess};
|
||||||
|
use crate::symbol::{Symbol, keywords};
|
||||||
|
|
||||||
use syntax_pos::{self, BytePos, CharPos, Pos, Span, NO_EXPANSION};
|
use syntax_pos::{self, BytePos, CharPos, Pos, Span, NO_EXPANSION};
|
||||||
use source_map::{SourceMap, FilePathMapping};
|
|
||||||
use errors::{Applicability, FatalError, Diagnostic, DiagnosticBuilder};
|
|
||||||
use parse::{token, ParseSess};
|
|
||||||
use symbol::{Symbol, keywords};
|
|
||||||
use core::unicode::property::Pattern_White_Space;
|
use core::unicode::property::Pattern_White_Space;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -11,6 +12,7 @@ use std::char;
|
|||||||
use std::iter;
|
use std::iter;
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
pub mod comments;
|
pub mod comments;
|
||||||
mod tokentrees;
|
mod tokentrees;
|
||||||
@ -449,7 +451,7 @@ impl<'a> StringReader<'a> {
|
|||||||
}
|
}
|
||||||
return s.into();
|
return s.into();
|
||||||
|
|
||||||
fn translate_crlf_(rdr: &StringReader,
|
fn translate_crlf_(rdr: &StringReader<'_>,
|
||||||
start: BytePos,
|
start: BytePos,
|
||||||
s: &str,
|
s: &str,
|
||||||
mut j: usize,
|
mut j: usize,
|
||||||
@ -1866,19 +1868,20 @@ fn char_at(s: &str, byte: usize) -> char {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use ast::{Ident, CrateConfig};
|
use crate::ast::{Ident, CrateConfig};
|
||||||
use symbol::Symbol;
|
use crate::symbol::Symbol;
|
||||||
use syntax_pos::{BytePos, Span, NO_EXPANSION};
|
use crate::source_map::SourceMap;
|
||||||
use source_map::SourceMap;
|
use crate::errors;
|
||||||
use errors;
|
use crate::feature_gate::UnstableFeatures;
|
||||||
use feature_gate::UnstableFeatures;
|
use crate::parse::token;
|
||||||
use parse::token;
|
use crate::diagnostics::plugin::ErrorMap;
|
||||||
|
use crate::with_globals;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use diagnostics::plugin::ErrorMap;
|
use syntax_pos::{BytePos, Span, NO_EXPANSION};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use with_globals;
|
|
||||||
fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
|
fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
|
||||||
let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()),
|
let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()),
|
||||||
Some(sm.clone()),
|
Some(sm.clone()),
|
||||||
@ -1943,7 +1946,7 @@ mod tests {
|
|||||||
|
|
||||||
// check that the given reader produces the desired stream
|
// check that the given reader produces the desired stream
|
||||||
// of tokens (stop checking after exhausting the expected vec)
|
// of tokens (stop checking after exhausting the expected vec)
|
||||||
fn check_tokenization(mut string_reader: StringReader, expected: Vec<token::Token>) {
|
fn check_tokenization(mut string_reader: StringReader<'_>, expected: Vec<token::Token>) {
|
||||||
for expected_tok in &expected {
|
for expected_tok in &expected {
|
||||||
assert_eq!(&string_reader.next_token().tok, expected_tok);
|
assert_eq!(&string_reader.next_token().tok, expected_tok);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use print::pprust::token_to_string;
|
use crate::print::pprust::token_to_string;
|
||||||
use parse::lexer::StringReader;
|
use crate::parse::lexer::StringReader;
|
||||||
use parse::{token, PResult};
|
use crate::parse::{token, PResult};
|
||||||
use tokenstream::{DelimSpan, IsJoint::*, TokenStream, TokenTree, TreeAndJoint};
|
use crate::tokenstream::{DelimSpan, IsJoint::*, TokenStream, TokenTree, TreeAndJoint};
|
||||||
|
|
||||||
impl<'a> StringReader<'a> {
|
impl<'a> StringReader<'a> {
|
||||||
// Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`.
|
// Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// http://www.unicode.org/Public/security/10.0.0/confusables.txt
|
// http://www.unicode.org/Public/security/10.0.0/confusables.txt
|
||||||
|
|
||||||
use syntax_pos::{Span, NO_EXPANSION};
|
use syntax_pos::{Span, NO_EXPANSION};
|
||||||
use errors::{Applicability, DiagnosticBuilder};
|
use crate::errors::{Applicability, DiagnosticBuilder};
|
||||||
use super::StringReader;
|
use super::StringReader;
|
||||||
|
|
||||||
const UNICODE_ARRAY: &[(char, &str, char)] = &[
|
const UNICODE_ARRAY: &[(char, &str, char)] = &[
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
//! The main parser interface
|
//! The main parser interface
|
||||||
|
|
||||||
|
use crate::ast::{self, CrateConfig, NodeId};
|
||||||
|
use crate::early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId};
|
||||||
|
use crate::source_map::{SourceMap, FilePathMapping};
|
||||||
|
use crate::errors::{FatalError, Level, Handler, ColorConfig, Diagnostic, DiagnosticBuilder};
|
||||||
|
use crate::feature_gate::UnstableFeatures;
|
||||||
|
use crate::parse::parser::Parser;
|
||||||
|
use crate::symbol::Symbol;
|
||||||
|
use crate::tokenstream::{TokenStream, TokenTree};
|
||||||
|
use crate::diagnostics::plugin::ErrorMap;
|
||||||
|
|
||||||
use rustc_data_structures::sync::{Lrc, Lock};
|
use rustc_data_structures::sync::{Lrc, Lock};
|
||||||
use ast::{self, CrateConfig, NodeId};
|
|
||||||
use early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId};
|
|
||||||
use source_map::{SourceMap, FilePathMapping};
|
|
||||||
use syntax_pos::{Span, SourceFile, FileName, MultiSpan};
|
use syntax_pos::{Span, SourceFile, FileName, MultiSpan};
|
||||||
use errors::{FatalError, Level, Handler, ColorConfig, Diagnostic, DiagnosticBuilder};
|
use log::debug;
|
||||||
use feature_gate::UnstableFeatures;
|
|
||||||
use parse::parser::Parser;
|
|
||||||
use symbol::Symbol;
|
|
||||||
use tokenstream::{TokenStream, TokenTree};
|
|
||||||
use diagnostics::plugin::ErrorMap;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -125,12 +127,12 @@ pub fn parse_crate_attrs_from_file<'a>(input: &Path, sess: &'a ParseSess)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_crate_from_source_str(name: FileName, source: String, sess: &ParseSess)
|
pub fn parse_crate_from_source_str(name: FileName, source: String, sess: &ParseSess)
|
||||||
-> PResult<ast::Crate> {
|
-> PResult<'_, ast::Crate> {
|
||||||
new_parser_from_source_str(sess, name, source).parse_crate_mod()
|
new_parser_from_source_str(sess, name, source).parse_crate_mod()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_crate_attrs_from_source_str(name: FileName, source: String, sess: &ParseSess)
|
pub fn parse_crate_attrs_from_source_str(name: FileName, source: String, sess: &ParseSess)
|
||||||
-> PResult<Vec<ast::Attribute>> {
|
-> PResult<'_, Vec<ast::Attribute>> {
|
||||||
new_parser_from_source_str(sess, name, source).parse_inner_attributes()
|
new_parser_from_source_str(sess, name, source).parse_inner_attributes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,14 +144,14 @@ pub fn parse_stream_from_source_str(name: FileName, source: String, sess: &Parse
|
|||||||
|
|
||||||
/// Create a new parser from a source string
|
/// Create a new parser from a source string
|
||||||
pub fn new_parser_from_source_str(sess: &ParseSess, name: FileName, source: String)
|
pub fn new_parser_from_source_str(sess: &ParseSess, name: FileName, source: String)
|
||||||
-> Parser {
|
-> Parser<'_> {
|
||||||
panictry_buffer!(&sess.span_diagnostic, maybe_new_parser_from_source_str(sess, name, source))
|
panictry_buffer!(&sess.span_diagnostic, maybe_new_parser_from_source_str(sess, name, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new parser from a source string. Returns any buffered errors from lexing the initial
|
/// Create a new parser from a source string. Returns any buffered errors from lexing the initial
|
||||||
/// token stream.
|
/// token stream.
|
||||||
pub fn maybe_new_parser_from_source_str(sess: &ParseSess, name: FileName, source: String)
|
pub fn maybe_new_parser_from_source_str(sess: &ParseSess, name: FileName, source: String)
|
||||||
-> Result<Parser, Vec<Diagnostic>>
|
-> Result<Parser<'_>, Vec<Diagnostic>>
|
||||||
{
|
{
|
||||||
let mut parser = maybe_source_file_to_parser(sess,
|
let mut parser = maybe_source_file_to_parser(sess,
|
||||||
sess.source_map().new_source_file(name, source))?;
|
sess.source_map().new_source_file(name, source))?;
|
||||||
@ -186,7 +188,7 @@ crate fn new_sub_parser_from_file<'a>(sess: &'a ParseSess,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Given a source_file and config, return a parser
|
/// Given a source_file and config, return a parser
|
||||||
fn source_file_to_parser(sess: & ParseSess, source_file: Lrc<SourceFile>) -> Parser {
|
fn source_file_to_parser(sess: &ParseSess, source_file: Lrc<SourceFile>) -> Parser<'_> {
|
||||||
panictry_buffer!(&sess.span_diagnostic,
|
panictry_buffer!(&sess.span_diagnostic,
|
||||||
maybe_source_file_to_parser(sess, source_file))
|
maybe_source_file_to_parser(sess, source_file))
|
||||||
}
|
}
|
||||||
@ -194,7 +196,7 @@ fn source_file_to_parser(sess: & ParseSess, source_file: Lrc<SourceFile>) -> Par
|
|||||||
/// Given a source_file and config, return a parser. Returns any buffered errors from lexing the
|
/// Given a source_file and config, return a parser. Returns any buffered errors from lexing the
|
||||||
/// initial token stream.
|
/// initial token stream.
|
||||||
fn maybe_source_file_to_parser(sess: &ParseSess, source_file: Lrc<SourceFile>)
|
fn maybe_source_file_to_parser(sess: &ParseSess, source_file: Lrc<SourceFile>)
|
||||||
-> Result<Parser, Vec<Diagnostic>>
|
-> Result<Parser<'_>, Vec<Diagnostic>>
|
||||||
{
|
{
|
||||||
let end_pos = source_file.end_pos;
|
let end_pos = source_file.end_pos;
|
||||||
let mut parser = stream_to_parser(sess, maybe_file_to_stream(sess, source_file, None)?);
|
let mut parser = stream_to_parser(sess, maybe_file_to_stream(sess, source_file, None)?);
|
||||||
@ -208,7 +210,7 @@ fn maybe_source_file_to_parser(sess: &ParseSess, source_file: Lrc<SourceFile>)
|
|||||||
|
|
||||||
// must preserve old name for now, because quote! from the *existing*
|
// must preserve old name for now, because quote! from the *existing*
|
||||||
// compiler expands into it
|
// compiler expands into it
|
||||||
pub fn new_parser_from_tts(sess: &ParseSess, tts: Vec<TokenTree>) -> Parser {
|
pub fn new_parser_from_tts(sess: &ParseSess, tts: Vec<TokenTree>) -> Parser<'_> {
|
||||||
stream_to_parser(sess, tts.into_iter().collect())
|
stream_to_parser(sess, tts.into_iter().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +272,7 @@ pub fn maybe_file_to_stream(sess: &ParseSess,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Given stream and the `ParseSess`, produce a parser
|
/// Given stream and the `ParseSess`, produce a parser
|
||||||
pub fn stream_to_parser(sess: &ParseSess, stream: TokenStream) -> Parser {
|
pub fn stream_to_parser(sess: &ParseSess, stream: TokenStream) -> Parser<'_> {
|
||||||
Parser::new(sess, stream, None, true, false)
|
Parser::new(sess, stream, None, true, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -758,22 +760,22 @@ impl SeqSep {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::ast::{self, Ident, PatKind};
|
||||||
|
use crate::attr::first_attr_value_str_by_name;
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::print::pprust::item_to_string;
|
||||||
|
use crate::tokenstream::{DelimSpan, TokenTree};
|
||||||
|
use crate::util::parser_testing::string_to_stream;
|
||||||
|
use crate::util::parser_testing::{string_to_expr, string_to_item};
|
||||||
|
use crate::with_globals;
|
||||||
use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION};
|
use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION};
|
||||||
use ast::{self, Ident, PatKind};
|
|
||||||
use attr::first_attr_value_str_by_name;
|
|
||||||
use ptr::P;
|
|
||||||
use print::pprust::item_to_string;
|
|
||||||
use tokenstream::{DelimSpan, TokenTree};
|
|
||||||
use util::parser_testing::string_to_stream;
|
|
||||||
use util::parser_testing::{string_to_expr, string_to_item};
|
|
||||||
use with_globals;
|
|
||||||
|
|
||||||
/// Parses an item.
|
/// Parses an item.
|
||||||
///
|
///
|
||||||
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and `Err`
|
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and `Err`
|
||||||
/// when a syntax error occurred.
|
/// when a syntax error occurred.
|
||||||
fn parse_item_from_source_str(name: FileName, source: String, sess: &ParseSess)
|
fn parse_item_from_source_str(name: FileName, source: String, sess: &ParseSess)
|
||||||
-> PResult<Option<P<ast::Item>>> {
|
-> PResult<'_, Option<P<ast::Item>>> {
|
||||||
new_parser_from_source_str(sess, name, source).parse_item()
|
new_parser_from_source_str(sess, name, source).parse_item()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -913,20 +915,20 @@ mod tests {
|
|||||||
struct PatIdentVisitor {
|
struct PatIdentVisitor {
|
||||||
spans: Vec<Span>
|
spans: Vec<Span>
|
||||||
}
|
}
|
||||||
impl<'a> ::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 spannedident, _) => {
|
||||||
self.spans.push(spannedident.span.clone());
|
self.spans.push(spannedident.span.clone());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
::visit::walk_pat(self, p);
|
crate::visit::walk_pat(self, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut v = PatIdentVisitor { spans: Vec::new() };
|
let mut v = PatIdentVisitor { spans: Vec::new() };
|
||||||
::visit::walk_item(&mut v, &item);
|
crate::visit::walk_item(&mut v, &item);
|
||||||
return v.spans;
|
return v.spans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1007,7 +1009,7 @@ mod tests {
|
|||||||
fn ttdelim_span() {
|
fn ttdelim_span() {
|
||||||
fn parse_expr_from_source_str(
|
fn parse_expr_from_source_str(
|
||||||
name: FileName, source: String, sess: &ParseSess
|
name: FileName, source: String, sess: &ParseSess
|
||||||
) -> PResult<P<ast::Expr>> {
|
) -> PResult<'_, P<ast::Expr>> {
|
||||||
new_parser_from_source_str(sess, name, source).parse_expr()
|
new_parser_from_source_str(sess, name, source).parse_expr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,53 +1,55 @@
|
|||||||
|
use crate::ast::{AngleBracketedArgs, ParenthesizedArgs, AttrStyle, BareFnTy};
|
||||||
|
use crate::ast::{GenericBound, TraitBoundModifier};
|
||||||
|
use crate::ast::Unsafety;
|
||||||
|
use crate::ast::{Mod, AnonConst, Arg, Arm, Guard, Attribute, BindingMode, TraitItemKind};
|
||||||
|
use crate::ast::Block;
|
||||||
|
use crate::ast::{BlockCheckMode, CaptureBy, Movability};
|
||||||
|
use crate::ast::{Constness, Crate};
|
||||||
|
use crate::ast::Defaultness;
|
||||||
|
use crate::ast::EnumDef;
|
||||||
|
use crate::ast::{Expr, ExprKind, RangeLimits};
|
||||||
|
use crate::ast::{Field, FnDecl, FnHeader};
|
||||||
|
use crate::ast::{ForeignItem, ForeignItemKind, FunctionRetTy};
|
||||||
|
use crate::ast::{GenericParam, GenericParamKind};
|
||||||
|
use crate::ast::GenericArg;
|
||||||
|
use crate::ast::{Ident, ImplItem, IsAsync, IsAuto, Item, ItemKind};
|
||||||
|
use crate::ast::{Label, Lifetime, Lit, LitKind};
|
||||||
|
use crate::ast::Local;
|
||||||
|
use crate::ast::MacStmtStyle;
|
||||||
|
use crate::ast::{Mac, Mac_, MacDelimiter};
|
||||||
|
use crate::ast::{MutTy, Mutability};
|
||||||
|
use crate::ast::{Pat, PatKind, PathSegment};
|
||||||
|
use crate::ast::{PolyTraitRef, QSelf};
|
||||||
|
use crate::ast::{Stmt, StmtKind};
|
||||||
|
use crate::ast::{VariantData, StructField};
|
||||||
|
use crate::ast::StrStyle;
|
||||||
|
use crate::ast::SelfKind;
|
||||||
|
use crate::ast::{TraitItem, TraitRef, TraitObjectSyntax};
|
||||||
|
use crate::ast::{Ty, TyKind, TypeBinding, GenericBounds};
|
||||||
|
use crate::ast::{Visibility, VisibilityKind, WhereClause, CrateSugar};
|
||||||
|
use crate::ast::{UseTree, UseTreeKind};
|
||||||
|
use crate::ast::{BinOpKind, UnOp};
|
||||||
|
use crate::ast::{RangeEnd, RangeSyntax};
|
||||||
|
use crate::{ast, attr};
|
||||||
|
use crate::ext::base::DummyResult;
|
||||||
|
use crate::source_map::{self, SourceMap, Spanned, respan};
|
||||||
|
use crate::errors::{self, Applicability, DiagnosticBuilder, DiagnosticId};
|
||||||
|
use crate::parse::{self, SeqSep, classify, token};
|
||||||
|
use crate::parse::lexer::TokenAndSpan;
|
||||||
|
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
||||||
|
use crate::parse::token::DelimToken;
|
||||||
|
use crate::parse::{new_sub_parser_from_file, ParseSess, Directory, DirectoryOwnership};
|
||||||
|
use crate::util::parser::{AssocOp, Fixity};
|
||||||
|
use crate::print::pprust;
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::parse::PResult;
|
||||||
|
use crate::ThinVec;
|
||||||
|
use crate::tokenstream::{self, DelimSpan, TokenTree, TokenStream, TreeAndJoint};
|
||||||
|
use crate::symbol::{Symbol, keywords};
|
||||||
|
|
||||||
use rustc_target::spec::abi::{self, Abi};
|
use rustc_target::spec::abi::{self, Abi};
|
||||||
use ast::{AngleBracketedArgs, ParenthesizedArgs, AttrStyle, BareFnTy};
|
|
||||||
use ast::{GenericBound, TraitBoundModifier};
|
|
||||||
use ast::Unsafety;
|
|
||||||
use ast::{Mod, AnonConst, Arg, Arm, Guard, Attribute, BindingMode, TraitItemKind};
|
|
||||||
use ast::Block;
|
|
||||||
use ast::{BlockCheckMode, CaptureBy, Movability};
|
|
||||||
use ast::{Constness, Crate};
|
|
||||||
use ast::Defaultness;
|
|
||||||
use ast::EnumDef;
|
|
||||||
use ast::{Expr, ExprKind, RangeLimits};
|
|
||||||
use ast::{Field, FnDecl, FnHeader};
|
|
||||||
use ast::{ForeignItem, ForeignItemKind, FunctionRetTy};
|
|
||||||
use ast::{GenericParam, GenericParamKind};
|
|
||||||
use ast::GenericArg;
|
|
||||||
use ast::{Ident, ImplItem, IsAsync, IsAuto, Item, ItemKind};
|
|
||||||
use ast::{Label, Lifetime, Lit, LitKind};
|
|
||||||
use ast::Local;
|
|
||||||
use ast::MacStmtStyle;
|
|
||||||
use ast::{Mac, Mac_, MacDelimiter};
|
|
||||||
use ast::{MutTy, Mutability};
|
|
||||||
use ast::{Pat, PatKind, PathSegment};
|
|
||||||
use ast::{PolyTraitRef, QSelf};
|
|
||||||
use ast::{Stmt, StmtKind};
|
|
||||||
use ast::{VariantData, StructField};
|
|
||||||
use ast::StrStyle;
|
|
||||||
use ast::SelfKind;
|
|
||||||
use ast::{TraitItem, TraitRef, TraitObjectSyntax};
|
|
||||||
use ast::{Ty, TyKind, TypeBinding, GenericBounds};
|
|
||||||
use ast::{Visibility, VisibilityKind, WhereClause, CrateSugar};
|
|
||||||
use ast::{UseTree, UseTreeKind};
|
|
||||||
use ast::{BinOpKind, UnOp};
|
|
||||||
use ast::{RangeEnd, RangeSyntax};
|
|
||||||
use {ast, attr};
|
|
||||||
use ext::base::DummyResult;
|
|
||||||
use source_map::{self, SourceMap, Spanned, respan};
|
|
||||||
use syntax_pos::{self, Span, MultiSpan, BytePos, FileName};
|
use syntax_pos::{self, Span, MultiSpan, BytePos, FileName};
|
||||||
use errors::{self, Applicability, DiagnosticBuilder, DiagnosticId};
|
use log::{debug, trace};
|
||||||
use parse::{self, SeqSep, classify, token};
|
|
||||||
use parse::lexer::TokenAndSpan;
|
|
||||||
use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
|
||||||
use parse::token::DelimToken;
|
|
||||||
use parse::{new_sub_parser_from_file, ParseSess, Directory, DirectoryOwnership};
|
|
||||||
use util::parser::{AssocOp, Fixity};
|
|
||||||
use print::pprust;
|
|
||||||
use ptr::P;
|
|
||||||
use parse::PResult;
|
|
||||||
use ThinVec;
|
|
||||||
use tokenstream::{self, DelimSpan, TokenTree, TokenStream, TreeAndJoint};
|
|
||||||
use symbol::{Symbol, keywords};
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
@ -64,7 +66,7 @@ pub enum AliasKind {
|
|||||||
Existential(GenericBounds),
|
Existential(GenericBounds),
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags::bitflags! {
|
||||||
struct Restrictions: u8 {
|
struct Restrictions: u8 {
|
||||||
const STMT_EXPR = 1 << 0;
|
const STMT_EXPR = 1 << 0;
|
||||||
const NO_STRUCT_LITERAL = 1 << 1;
|
const NO_STRUCT_LITERAL = 1 << 1;
|
||||||
@ -453,7 +455,7 @@ pub enum Error {
|
|||||||
impl Error {
|
impl Error {
|
||||||
fn span_err<S: Into<MultiSpan>>(self,
|
fn span_err<S: Into<MultiSpan>>(self,
|
||||||
sp: S,
|
sp: S,
|
||||||
handler: &errors::Handler) -> DiagnosticBuilder {
|
handler: &errors::Handler) -> DiagnosticBuilder<'_> {
|
||||||
match self {
|
match self {
|
||||||
Error::FileNotFoundForModule { ref mod_name,
|
Error::FileNotFoundForModule { ref mod_name,
|
||||||
ref default_path,
|
ref default_path,
|
||||||
@ -1313,7 +1315,7 @@ impl<'a> Parser<'a> {
|
|||||||
self.sess.span_diagnostic.span_bug(sp, m)
|
self.sess.span_diagnostic.span_bug(sp, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancel(&self, err: &mut DiagnosticBuilder) {
|
fn cancel(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||||
self.sess.span_diagnostic.cancel(err)
|
self.sess.span_diagnostic.cancel(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1721,7 +1723,7 @@ impl<'a> Parser<'a> {
|
|||||||
match ty.node {
|
match ty.node {
|
||||||
TyKind::Rptr(ref lifetime, ref mut_ty) => {
|
TyKind::Rptr(ref lifetime, ref mut_ty) => {
|
||||||
let sum_with_parens = pprust::to_string(|s| {
|
let sum_with_parens = pprust::to_string(|s| {
|
||||||
use print::pprust::PrintState;
|
use crate::print::pprust::PrintState;
|
||||||
|
|
||||||
s.s.word("&")?;
|
s.s.word("&")?;
|
||||||
s.print_opt_lifetime(lifetime)?;
|
s.print_opt_lifetime(lifetime)?;
|
||||||
@ -3063,7 +3065,7 @@ impl<'a> Parser<'a> {
|
|||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
let sugg = pprust::to_string(|s| {
|
let sugg = pprust::to_string(|s| {
|
||||||
use print::pprust::PrintState;
|
use crate::print::pprust::PrintState;
|
||||||
s.popen()?;
|
s.popen()?;
|
||||||
s.print_expr(&e)?;
|
s.print_expr(&e)?;
|
||||||
s.s.word( ".")?;
|
s.s.word( ".")?;
|
||||||
@ -5220,7 +5222,7 @@ impl<'a> Parser<'a> {
|
|||||||
stmt_span = stmt_span.with_hi(self.prev_span.hi());
|
stmt_span = stmt_span.with_hi(self.prev_span.hi());
|
||||||
}
|
}
|
||||||
let sugg = pprust::to_string(|s| {
|
let sugg = pprust::to_string(|s| {
|
||||||
use print::pprust::{PrintState, INDENT_UNIT};
|
use crate::print::pprust::{PrintState, INDENT_UNIT};
|
||||||
s.ibox(INDENT_UNIT)?;
|
s.ibox(INDENT_UNIT)?;
|
||||||
s.bopen()?;
|
s.bopen()?;
|
||||||
s.print_stmt(&stmt)?;
|
s.print_stmt(&stmt)?;
|
||||||
@ -7050,7 +7052,7 @@ impl<'a> Parser<'a> {
|
|||||||
/// Parse a `mod <foo> { ... }` or `mod <foo>;` item
|
/// Parse a `mod <foo> { ... }` or `mod <foo>;` item
|
||||||
fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> {
|
fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> {
|
||||||
let (in_cfg, outer_attrs) = {
|
let (in_cfg, outer_attrs) = {
|
||||||
let mut strip_unconfigured = ::config::StripUnconfigured {
|
let mut strip_unconfigured = crate::config::StripUnconfigured {
|
||||||
sess: self.sess,
|
sess: self.sess,
|
||||||
features: None, // don't perform gated feature checking
|
features: None, // don't perform gated feature checking
|
||||||
};
|
};
|
||||||
|
@ -1,22 +1,26 @@
|
|||||||
pub use self::BinOpToken::*;
|
pub use BinOpToken::*;
|
||||||
pub use self::Nonterminal::*;
|
pub use Nonterminal::*;
|
||||||
pub use self::DelimToken::*;
|
pub use DelimToken::*;
|
||||||
pub use self::Lit::*;
|
pub use Lit::*;
|
||||||
pub use self::Token::*;
|
pub use Token::*;
|
||||||
|
|
||||||
|
use crate::ast::{self};
|
||||||
|
use crate::parse::ParseSess;
|
||||||
|
use crate::print::pprust;
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::symbol::keywords;
|
||||||
|
use crate::syntax::parse::parse_stream_from_source_str;
|
||||||
|
use crate::tokenstream::{self, DelimSpan, TokenStream, TokenTree};
|
||||||
|
|
||||||
use ast::{self};
|
|
||||||
use parse::ParseSess;
|
|
||||||
use print::pprust;
|
|
||||||
use ptr::P;
|
|
||||||
use serialize::{Decodable, Decoder, Encodable, Encoder};
|
use serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||||
use symbol::keywords;
|
|
||||||
use syntax::parse::parse_stream_from_source_str;
|
|
||||||
use syntax_pos::{self, Span, FileName};
|
|
||||||
use syntax_pos::symbol::{self, Symbol};
|
use syntax_pos::symbol::{self, Symbol};
|
||||||
use tokenstream::{self, DelimSpan, TokenStream, TokenTree};
|
use syntax_pos::{self, Span, FileName};
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use std::{cmp, fmt};
|
use std::{cmp, fmt};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
use rustc_data_structures::static_assert;
|
||||||
use rustc_data_structures::sync::{Lrc, Lock};
|
use rustc_data_structures::sync::{Lrc, Lock};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||||
@ -683,7 +687,7 @@ impl PartialEq for Nonterminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Nonterminal {
|
impl fmt::Debug for Nonterminal {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
NtItem(..) => f.pad("NtItem(..)"),
|
NtItem(..) => f.pad("NtItem(..)"),
|
||||||
NtBlock(..) => f.pad("NtBlock(..)"),
|
NtBlock(..) => f.pad("NtBlock(..)"),
|
||||||
@ -729,7 +733,7 @@ impl PartialEq for LazyTokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for LazyTokenStream {
|
impl fmt::Debug for LazyTokenStream {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Debug::fmt(&self.clone().0.into_inner(), f)
|
fmt::Debug::fmt(&self.clone().0.into_inner(), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,7 @@ use std::collections::VecDeque;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
/// How to break. Described in more detail in the module docs.
|
/// How to break. Described in more detail in the module docs.
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
@ -192,7 +193,7 @@ impl Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Token {
|
impl fmt::Display for Token {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Token::String(ref s, len) => write!(f, "STR({},{})", s, len),
|
Token::String(ref s, len) => write!(f, "STR({},{})", s, len),
|
||||||
Token::Break(_) => f.write_str("BREAK"),
|
Token::Break(_) => f.write_str("BREAK"),
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
|
use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
|
||||||
|
use crate::ast::{SelfKind, GenericBound, TraitBoundModifier};
|
||||||
|
use crate::ast::{Attribute, MacDelimiter, GenericArg};
|
||||||
|
use crate::util::parser::{self, AssocOp, Fixity};
|
||||||
|
use crate::attr;
|
||||||
|
use crate::source_map::{self, SourceMap, Spanned};
|
||||||
|
use crate::parse::token::{self, BinOpToken, Token};
|
||||||
|
use crate::parse::lexer::comments;
|
||||||
|
use crate::parse::{self, ParseSess};
|
||||||
|
use crate::print::pp::{self, Breaks};
|
||||||
|
use crate::print::pp::Breaks::{Consistent, Inconsistent};
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::std_inject;
|
||||||
|
use crate::symbol::keywords;
|
||||||
|
use crate::tokenstream::{self, TokenStream, TokenTree};
|
||||||
|
|
||||||
use rustc_target::spec::abi::{self, Abi};
|
use rustc_target::spec::abi::{self, Abi};
|
||||||
use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
|
|
||||||
use ast::{SelfKind, GenericBound, TraitBoundModifier};
|
|
||||||
use ast::{Attribute, MacDelimiter, GenericArg};
|
|
||||||
use util::parser::{self, AssocOp, Fixity};
|
|
||||||
use attr;
|
|
||||||
use source_map::{self, SourceMap, Spanned};
|
|
||||||
use syntax_pos::{self, BytePos};
|
use syntax_pos::{self, BytePos};
|
||||||
use parse::token::{self, BinOpToken, Token};
|
|
||||||
use parse::lexer::comments;
|
|
||||||
use parse::{self, ParseSess};
|
|
||||||
use print::pp::{self, Breaks};
|
|
||||||
use print::pp::Breaks::{Consistent, Inconsistent};
|
|
||||||
use ptr::P;
|
|
||||||
use std_inject;
|
|
||||||
use symbol::keywords;
|
|
||||||
use syntax_pos::{DUMMY_SP, FileName};
|
use syntax_pos::{DUMMY_SP, FileName};
|
||||||
use tokenstream::{self, TokenStream, TokenTree};
|
|
||||||
|
|
||||||
use std::ascii;
|
use std::ascii;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -34,8 +35,8 @@ pub enum AnnNode<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait PpAnn {
|
pub trait PpAnn {
|
||||||
fn pre(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> { Ok(()) }
|
fn pre(&self, _state: &mut State<'_>, _node: AnnNode<'_>) -> io::Result<()> { Ok(()) }
|
||||||
fn post(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> { Ok(()) }
|
fn post(&self, _state: &mut State<'_>, _node: AnnNode<'_>) -> io::Result<()> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -150,7 +151,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string<F>(f: F) -> String where
|
pub fn to_string<F>(f: F) -> String where
|
||||||
F: FnOnce(&mut State) -> io::Result<()>,
|
F: FnOnce(&mut State<'_>) -> io::Result<()>,
|
||||||
{
|
{
|
||||||
let mut wr = Vec::new();
|
let mut wr = Vec::new();
|
||||||
{
|
{
|
||||||
@ -969,7 +970,7 @@ impl<'a> State<'a> {
|
|||||||
elts: &[T],
|
elts: &[T],
|
||||||
mut op: F,
|
mut op: F,
|
||||||
mut get_span: G) -> io::Result<()> where
|
mut get_span: G) -> io::Result<()> where
|
||||||
F: FnMut(&mut State, &T) -> io::Result<()>,
|
F: FnMut(&mut State<'_>, &T) -> io::Result<()>,
|
||||||
G: FnMut(&T) -> syntax_pos::Span,
|
G: FnMut(&T) -> syntax_pos::Span,
|
||||||
{
|
{
|
||||||
self.rbox(0, b)?;
|
self.rbox(0, b)?;
|
||||||
@ -3210,10 +3211,10 @@ impl<'a> State<'a> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use ast;
|
use crate::ast;
|
||||||
use source_map;
|
use crate::source_map;
|
||||||
|
use crate::with_globals;
|
||||||
use syntax_pos;
|
use syntax_pos;
|
||||||
use with_globals;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fun_to_string() {
|
fn test_fun_to_string() {
|
||||||
|
@ -129,19 +129,19 @@ impl<T: 'static + Clone> Clone for P<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized + Debug> Debug for P<T> {
|
impl<T: ?Sized + Debug> Debug for P<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
Debug::fmt(&self.ptr, f)
|
Debug::fmt(&self.ptr, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Display> Display for P<T> {
|
impl<T: Display> Display for P<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
Display::fmt(&**self, f)
|
Display::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> fmt::Pointer for P<T> {
|
impl<T> fmt::Pointer for P<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Pointer::fmt(&self.ptr, f)
|
fmt::Pointer::fmt(&self.ptr, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use ast;
|
use crate::ast;
|
||||||
use errors;
|
use crate::errors;
|
||||||
use visit;
|
use crate::visit;
|
||||||
use visit::Visitor;
|
use crate::visit::Visitor;
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
Expression,
|
Expression,
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
pub use syntax_pos::*;
|
pub use syntax_pos::*;
|
||||||
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo};
|
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo};
|
||||||
pub use self::ExpnFormat::*;
|
pub use ExpnFormat::*;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
@ -22,7 +22,9 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use errors::SourceMapper;
|
use log::debug;
|
||||||
|
|
||||||
|
use crate::errors::SourceMapper;
|
||||||
|
|
||||||
/// Return the span itself if it doesn't come from a macro expansion,
|
/// Return the span itself if it doesn't come from a macro expansion,
|
||||||
/// otherwise return the call site span up to the `enclosing_sp` by
|
/// otherwise return the call site span up to the `enclosing_sp` by
|
||||||
@ -167,7 +169,7 @@ impl SourceMap {
|
|||||||
Ok(self.new_source_file(filename, src))
|
Ok(self.new_source_file(filename, src))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn files(&self) -> MappedLockGuard<Vec<Lrc<SourceFile>>> {
|
pub fn files(&self) -> MappedLockGuard<'_, Vec<Lrc<SourceFile>>> {
|
||||||
LockGuard::map(self.files.borrow(), |files| &mut files.source_files)
|
LockGuard::map(self.files.borrow(), |files| &mut files.source_files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use ast;
|
use crate::ast;
|
||||||
use attr;
|
use crate::attr;
|
||||||
|
use crate::edition::Edition;
|
||||||
|
use crate::ext::hygiene::{Mark, SyntaxContext};
|
||||||
|
use crate::symbol::{Symbol, keywords};
|
||||||
|
use crate::source_map::{ExpnInfo, MacroAttribute, dummy_spanned, hygiene, respan};
|
||||||
|
use crate::ptr::P;
|
||||||
|
use crate::tokenstream::TokenStream;
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use edition::Edition;
|
|
||||||
use ext::hygiene::{Mark, SyntaxContext};
|
|
||||||
use symbol::{Symbol, keywords};
|
|
||||||
use syntax_pos::{DUMMY_SP, Span};
|
use syntax_pos::{DUMMY_SP, Span};
|
||||||
use source_map::{ExpnInfo, MacroAttribute, dummy_spanned, hygiene, respan};
|
|
||||||
use ptr::P;
|
|
||||||
use tokenstream::TokenStream;
|
|
||||||
|
|
||||||
/// Craft a span that will be ignored by the stability lint's
|
/// Craft a span that will be ignored by the stability lint's
|
||||||
/// call to source_map's `is_internal` check.
|
/// call to source_map's `is_internal` check.
|
||||||
|
@ -3,33 +3,35 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
use self::HasTestSignature::*;
|
use HasTestSignature::*;
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use attr::{self, HasAttrs};
|
|
||||||
|
use log::debug;
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, SourceFile, BytePos};
|
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, SourceFile, BytePos};
|
||||||
|
|
||||||
use source_map::{self, SourceMap, ExpnInfo, MacroAttribute, dummy_spanned, respan};
|
use crate::attr::{self, HasAttrs};
|
||||||
use errors;
|
use crate::source_map::{self, SourceMap, ExpnInfo, MacroAttribute, dummy_spanned, respan};
|
||||||
use config;
|
use crate::errors;
|
||||||
use entry::{self, EntryPointType};
|
use crate::config;
|
||||||
use ext::base::{ExtCtxt, Resolver};
|
use crate::entry::{self, EntryPointType};
|
||||||
use ext::build::AstBuilder;
|
use crate::ext::base::{ExtCtxt, Resolver};
|
||||||
use ext::expand::ExpansionConfig;
|
use crate::ext::build::AstBuilder;
|
||||||
use ext::hygiene::{self, Mark, SyntaxContext};
|
use crate::ext::expand::ExpansionConfig;
|
||||||
use mut_visit::{*, ExpectOne};
|
use crate::ext::hygiene::{self, Mark, SyntaxContext};
|
||||||
use feature_gate::Features;
|
use crate::mut_visit::{*, ExpectOne};
|
||||||
use util::map_in_place::MapInPlace;
|
use crate::feature_gate::Features;
|
||||||
use parse::{token, ParseSess};
|
use crate::util::map_in_place::MapInPlace;
|
||||||
use print::pprust;
|
use crate::parse::{token, ParseSess};
|
||||||
use ast::{self, Ident};
|
use crate::print::pprust;
|
||||||
use ptr::P;
|
use crate::ast::{self, Ident};
|
||||||
use smallvec::SmallVec;
|
use crate::ptr::P;
|
||||||
use symbol::{self, Symbol, keywords};
|
use crate::symbol::{self, Symbol, keywords};
|
||||||
use ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
struct Test {
|
struct Test {
|
||||||
span: Span,
|
span: Span,
|
||||||
@ -210,7 +212,7 @@ impl MutVisitor for EntryPointCleaner {
|
|||||||
/// Each tested submodule will contain a similar reexport module that we will export
|
/// Each tested submodule will contain a similar reexport module that we will export
|
||||||
/// under the name of the original module. That is, `submod::__test_reexports` is
|
/// under the name of the original module. That is, `submod::__test_reexports` is
|
||||||
/// reexported like so `pub use submod::__test_reexports as submod`.
|
/// reexported like so `pub use submod::__test_reexports as submod`.
|
||||||
fn mk_reexport_mod(cx: &mut TestCtxt,
|
fn mk_reexport_mod(cx: &mut TestCtxt<'_>,
|
||||||
parent: ast::NodeId,
|
parent: ast::NodeId,
|
||||||
tests: Vec<Ident>,
|
tests: Vec<Ident>,
|
||||||
tested_submods: Vec<(Ident, Ident)>)
|
tested_submods: Vec<(Ident, Ident)>)
|
||||||
@ -299,7 +301,7 @@ fn generate_test_harness(sess: &ParseSess,
|
|||||||
/// Craft a span that will be ignored by the stability lint's
|
/// Craft a span that will be ignored by the stability lint's
|
||||||
/// call to source_map's `is_internal` check.
|
/// call to source_map's `is_internal` check.
|
||||||
/// The expanded code calls some unstable functions in the test crate.
|
/// The expanded code calls some unstable functions in the test crate.
|
||||||
fn ignored_span(cx: &TestCtxt, sp: Span) -> Span {
|
fn ignored_span(cx: &TestCtxt<'_>, sp: Span) -> Span {
|
||||||
sp.with_ctxt(cx.ctxt)
|
sp.with_ctxt(cx.ctxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +320,7 @@ enum BadTestSignature {
|
|||||||
|
|
||||||
/// Creates a function item for use as the main function of a test build.
|
/// Creates a function item for use as the main function of a test build.
|
||||||
/// This function will call the `test_runner` as specified by the crate attribute
|
/// This function will call the `test_runner` as specified by the crate attribute
|
||||||
fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
|
fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
||||||
// Writing this out by hand with 'ignored_span':
|
// Writing this out by hand with 'ignored_span':
|
||||||
// pub fn main() {
|
// pub fn main() {
|
||||||
// #![main]
|
// #![main]
|
||||||
@ -398,7 +400,7 @@ fn path_name_i(idents: &[Ident]) -> String {
|
|||||||
|
|
||||||
/// Creates a slice containing every test like so:
|
/// Creates a slice containing every test like so:
|
||||||
/// &[path::to::test1, path::to::test2]
|
/// &[path::to::test1, path::to::test2]
|
||||||
fn mk_tests_slice(cx: &TestCtxt) -> P<ast::Expr> {
|
fn mk_tests_slice(cx: &TestCtxt<'_>) -> P<ast::Expr> {
|
||||||
debug!("building test vector from {} tests", cx.test_cases.len());
|
debug!("building test vector from {} tests", cx.test_cases.len());
|
||||||
let ref ecx = cx.ext_cx;
|
let ref ecx = cx.ext_cx;
|
||||||
|
|
||||||
@ -410,7 +412,7 @@ fn mk_tests_slice(cx: &TestCtxt) -> P<ast::Expr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a path from the top-level __test module to the test via __test_reexports
|
/// Creates a path from the top-level __test module to the test via __test_reexports
|
||||||
fn visible_path(cx: &TestCtxt, path: &[Ident]) -> Vec<Ident>{
|
fn visible_path(cx: &TestCtxt<'_>, path: &[Ident]) -> Vec<Ident>{
|
||||||
let mut visible_path = vec![];
|
let mut visible_path = vec![];
|
||||||
match cx.toplevel_reexport {
|
match cx.toplevel_reexport {
|
||||||
Some(id) => visible_path.push(id),
|
Some(id) => visible_path.push(id),
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use source_map::{SourceMap, FilePathMapping};
|
use crate::source_map::{SourceMap, FilePathMapping};
|
||||||
use errors::Handler;
|
use crate::errors::Handler;
|
||||||
use errors::emitter::EmitterWriter;
|
use crate::errors::emitter::EmitterWriter;
|
||||||
|
use crate::with_globals;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
@ -8,7 +10,6 @@ use std::str;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use syntax_pos::{BytePos, NO_EXPANSION, Span, MultiSpan};
|
use syntax_pos::{BytePos, NO_EXPANSION, Span, MultiSpan};
|
||||||
use with_globals;
|
|
||||||
|
|
||||||
/// Identify a position in the text by the Nth occurrence of a string.
|
/// Identify a position in the text by the Nth occurrence of a string.
|
||||||
struct Position {
|
struct Position {
|
||||||
|
@ -12,12 +12,15 @@
|
|||||||
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
|
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
|
||||||
//! ownership of the original.
|
//! ownership of the original.
|
||||||
|
|
||||||
|
use crate::ext::base;
|
||||||
|
use crate::ext::tt::{macro_parser, quoted};
|
||||||
|
use crate::parse::Directory;
|
||||||
|
use crate::parse::token::{self, DelimToken, Token};
|
||||||
|
use crate::print::pprust;
|
||||||
|
|
||||||
use syntax_pos::{BytePos, Mark, Span, DUMMY_SP};
|
use syntax_pos::{BytePos, Mark, Span, DUMMY_SP};
|
||||||
use ext::base;
|
#[cfg(target_arch = "x86_64")]
|
||||||
use ext::tt::{macro_parser, quoted};
|
use rustc_data_structures::static_assert;
|
||||||
use parse::Directory;
|
|
||||||
use parse::token::{self, DelimToken, Token};
|
|
||||||
use print::pprust;
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use serialize::{Decoder, Decodable, Encoder, Encodable};
|
use serialize::{Decoder, Decodable, Encoder, Encodable};
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ pub enum TokenTree {
|
|||||||
|
|
||||||
impl TokenTree {
|
impl TokenTree {
|
||||||
/// Use this token tree as a matcher to parse given tts.
|
/// Use this token tree as a matcher to parse given tts.
|
||||||
pub fn parse(cx: &base::ExtCtxt, mtch: &[quoted::TokenTree], tts: TokenStream)
|
pub fn parse(cx: &base::ExtCtxt<'_>, mtch: &[quoted::TokenTree], tts: TokenStream)
|
||||||
-> macro_parser::NamedParseResult {
|
-> macro_parser::NamedParseResult {
|
||||||
// `None` is because we're not interpolating
|
// `None` is because we're not interpolating
|
||||||
let directory = Directory {
|
let directory = Directory {
|
||||||
@ -161,7 +164,7 @@ pub enum IsJoint {
|
|||||||
NonJoint
|
NonJoint
|
||||||
}
|
}
|
||||||
|
|
||||||
use self::IsJoint::*;
|
use IsJoint::*;
|
||||||
|
|
||||||
impl TokenStream {
|
impl TokenStream {
|
||||||
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
|
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
|
||||||
@ -492,7 +495,7 @@ impl Cursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for TokenStream {
|
impl fmt::Display for TokenStream {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.write_str(&pprust::tokens_to_string(self.clone()))
|
f.write_str(&pprust::tokens_to_string(self.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -546,11 +549,11 @@ impl DelimSpan {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use syntax::ast::Ident;
|
use crate::syntax::ast::Ident;
|
||||||
use with_globals;
|
use crate::with_globals;
|
||||||
|
use crate::parse::token::Token;
|
||||||
|
use crate::util::parser_testing::string_to_stream;
|
||||||
use syntax_pos::{Span, BytePos, NO_EXPANSION};
|
use syntax_pos::{Span, BytePos, NO_EXPANSION};
|
||||||
use parse::token::Token;
|
|
||||||
use util::parser_testing::string_to_stream;
|
|
||||||
|
|
||||||
fn string_to_ts(string: &str) -> TokenStream {
|
fn string_to_ts(string: &str) -> TokenStream {
|
||||||
string_to_stream(string.to_owned())
|
string_to_stream(string.to_owned())
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
use symbol::Symbol;
|
use crate::symbol::Symbol;
|
||||||
|
|
||||||
/// Find the Levenshtein distance between two strings
|
/// Find the Levenshtein distance between two strings
|
||||||
pub fn lev_distance(a: &str, b: &str) -> usize {
|
pub fn lev_distance(a: &str, b: &str) -> usize {
|
||||||
@ -101,7 +101,7 @@ fn test_lev_distance() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_best_match_for_name() {
|
fn test_find_best_match_for_name() {
|
||||||
use with_globals;
|
use crate::with_globals;
|
||||||
with_globals(|| {
|
with_globals(|| {
|
||||||
let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")];
|
let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Simply gives a rought count of the number of nodes in an AST.
|
// Simply gives a rought count of the number of nodes in an AST.
|
||||||
|
|
||||||
use visit::*;
|
use crate::visit::*;
|
||||||
use ast::*;
|
use crate::ast::*;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
pub struct NodeCounter {
|
pub struct NodeCounter {
|
||||||
@ -69,7 +69,7 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
|||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_generics(self, g)
|
walk_generics(self, g)
|
||||||
}
|
}
|
||||||
fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, s: Span, _: NodeId) {
|
fn visit_fn(&mut self, fk: FnKind<'_>, fd: &FnDecl, s: Span, _: NodeId) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_fn(self, fk, fd, s)
|
walk_fn(self, fk, fd, s)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use parse::token::{Token, BinOpToken};
|
use crate::parse::token::{Token, BinOpToken};
|
||||||
use symbol::keywords;
|
use crate::symbol::keywords;
|
||||||
use ast::{self, BinOpKind};
|
use crate::ast::{self, BinOpKind};
|
||||||
|
|
||||||
/// Associative operator with precedence.
|
/// Associative operator with precedence.
|
||||||
///
|
///
|
||||||
@ -72,7 +72,7 @@ pub enum Fixity {
|
|||||||
impl AssocOp {
|
impl AssocOp {
|
||||||
/// Create a new AssocOP from a token
|
/// Create a new AssocOP from a token
|
||||||
pub fn from_token(t: &Token) -> Option<AssocOp> {
|
pub fn from_token(t: &Token) -> Option<AssocOp> {
|
||||||
use self::AssocOp::*;
|
use AssocOp::*;
|
||||||
match *t {
|
match *t {
|
||||||
Token::BinOpEq(k) => Some(AssignOp(k)),
|
Token::BinOpEq(k) => Some(AssignOp(k)),
|
||||||
Token::LArrow => Some(ObsoleteInPlace),
|
Token::LArrow => Some(ObsoleteInPlace),
|
||||||
@ -107,7 +107,7 @@ impl AssocOp {
|
|||||||
|
|
||||||
/// Create a new AssocOp from ast::BinOpKind.
|
/// Create a new AssocOp from ast::BinOpKind.
|
||||||
pub fn from_ast_binop(op: BinOpKind) -> Self {
|
pub fn from_ast_binop(op: BinOpKind) -> Self {
|
||||||
use self::AssocOp::*;
|
use AssocOp::*;
|
||||||
match op {
|
match op {
|
||||||
BinOpKind::Lt => Less,
|
BinOpKind::Lt => Less,
|
||||||
BinOpKind::Gt => Greater,
|
BinOpKind::Gt => Greater,
|
||||||
@ -132,7 +132,7 @@ impl AssocOp {
|
|||||||
|
|
||||||
/// Gets the precedence of this operator
|
/// Gets the precedence of this operator
|
||||||
pub fn precedence(&self) -> usize {
|
pub fn precedence(&self) -> usize {
|
||||||
use self::AssocOp::*;
|
use AssocOp::*;
|
||||||
match *self {
|
match *self {
|
||||||
As | Colon => 14,
|
As | Colon => 14,
|
||||||
Multiply | Divide | Modulus => 13,
|
Multiply | Divide | Modulus => 13,
|
||||||
@ -152,7 +152,7 @@ impl AssocOp {
|
|||||||
|
|
||||||
/// Gets the fixity of this operator
|
/// Gets the fixity of this operator
|
||||||
pub fn fixity(&self) -> Fixity {
|
pub fn fixity(&self) -> Fixity {
|
||||||
use self::AssocOp::*;
|
use AssocOp::*;
|
||||||
// NOTE: it is a bug to have an operators that has same precedence but different fixities!
|
// NOTE: it is a bug to have an operators that has same precedence but different fixities!
|
||||||
match *self {
|
match *self {
|
||||||
ObsoleteInPlace | Assign | AssignOp(_) => Fixity::Right,
|
ObsoleteInPlace | Assign | AssignOp(_) => Fixity::Right,
|
||||||
@ -164,7 +164,7 @@ impl AssocOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_comparison(&self) -> bool {
|
pub fn is_comparison(&self) -> bool {
|
||||||
use self::AssocOp::*;
|
use AssocOp::*;
|
||||||
match *self {
|
match *self {
|
||||||
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true,
|
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true,
|
||||||
ObsoleteInPlace | Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add |
|
ObsoleteInPlace | Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add |
|
||||||
@ -174,7 +174,7 @@ impl AssocOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_assign_like(&self) -> bool {
|
pub fn is_assign_like(&self) -> bool {
|
||||||
use self::AssocOp::*;
|
use AssocOp::*;
|
||||||
match *self {
|
match *self {
|
||||||
Assign | AssignOp(_) | ObsoleteInPlace => true,
|
Assign | AssignOp(_) | ObsoleteInPlace => true,
|
||||||
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide |
|
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide |
|
||||||
@ -184,7 +184,7 @@ impl AssocOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ast_binop(&self) -> Option<BinOpKind> {
|
pub fn to_ast_binop(&self) -> Option<BinOpKind> {
|
||||||
use self::AssocOp::*;
|
use AssocOp::*;
|
||||||
match *self {
|
match *self {
|
||||||
Less => Some(BinOpKind::Lt),
|
Less => Some(BinOpKind::Lt),
|
||||||
Greater => Some(BinOpKind::Gt),
|
Greater => Some(BinOpKind::Gt),
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use ast::{self, Ident};
|
use crate::ast::{self, Ident};
|
||||||
use source_map::FilePathMapping;
|
use crate::source_map::FilePathMapping;
|
||||||
use parse::{ParseSess, PResult, source_file_to_stream};
|
use crate::parse::{ParseSess, PResult, source_file_to_stream};
|
||||||
use parse::{lexer, new_parser_from_source_str};
|
use crate::parse::{lexer, new_parser_from_source_str};
|
||||||
use parse::parser::Parser;
|
use crate::parse::parser::Parser;
|
||||||
use ptr::P;
|
use crate::ptr::P;
|
||||||
use tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
|
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -13,10 +13,11 @@
|
|||||||
//! instance, a walker looking for item names in a module will miss all of
|
//! instance, a walker looking for item names in a module will miss all of
|
||||||
//! those that are created by the expansion of a macro.
|
//! those that are created by the expansion of a macro.
|
||||||
|
|
||||||
use ast::*;
|
use crate::ast::*;
|
||||||
|
use crate::parse::token::Token;
|
||||||
|
use crate::tokenstream::{TokenTree, TokenStream};
|
||||||
|
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use parse::token::Token;
|
|
||||||
use tokenstream::{TokenTree, TokenStream};
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum FnKind<'a> {
|
pub enum FnKind<'a> {
|
||||||
|
Loading…
Reference in New Issue
Block a user