"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/tools/rustfmt/src/syntux/parser.rs" between
rustc-1.45.0-src.tar.xz and rustc-1.45.2-src.tar.xz

About: Rust is a systems programming language that runs "blazingly fast, prevents nearly all segfaults, and guarantees thread safety" (developed by Mozilla).

parser.rs  (rustc-1.45.0-src.tar.xz):parser.rs  (rustc-1.45.2-src.tar.xz)
use std::panic::{catch_unwind, AssertUnwindSafe}; use std::panic::{catch_unwind, AssertUnwindSafe};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use rustc_ast::ast; use rustc_ast::ast;
use rustc_ast::token::{DelimToken, TokenKind}; use rustc_ast::token::{DelimToken, TokenKind};
use rustc_errors::{Diagnostic, PResult}; use rustc_errors::Diagnostic;
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser}; use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
use rustc_span::{symbol::kw, Span}; use rustc_span::{symbol::kw, Span};
use crate::syntux::session::ParseSess; use crate::syntux::session::ParseSess;
use crate::{Config, Input}; use crate::{Config, Input};
pub(crate) type DirectoryOwnership = rustc_expand::module::DirectoryOwnership; pub(crate) type DirectoryOwnership = rustc_expand::module::DirectoryOwnership;
pub(crate) type ModulePathSuccess = rustc_expand::module::ModulePathSuccess; pub(crate) type ModulePathSuccess = rustc_expand::module::ModulePathSuccess;
#[derive(Clone)] #[derive(Clone)]
skipping to change at line 105 skipping to change at line 105
ParserCreationError, ParserCreationError,
ParseError, ParseError,
ParsePanicError, ParsePanicError,
} }
impl<'a> Parser<'a> { impl<'a> Parser<'a> {
pub(crate) fn submod_path_from_attr(attrs: &[ast::Attribute], path: &Path) - > Option<PathBuf> { pub(crate) fn submod_path_from_attr(attrs: &[ast::Attribute], path: &Path) - > Option<PathBuf> {
rustc_expand::module::submod_path_from_attr(attrs, path) rustc_expand::module::submod_path_from_attr(attrs, path)
} }
// FIXME(topecongiro) Use the method from libsyntax[1] once it become public
.
//
// [1] https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/att
r.rs
fn parse_inner_attrs(parser: &mut RawParser<'a>) -> PResult<'a, Vec<ast::Att
ribute>> {
let mut attrs: Vec<ast::Attribute> = vec![];
loop {
match parser.token.kind {
TokenKind::Pound => {
// Don't even try to parse if it's not an inner attribute.
if !parser.look_ahead(1, |t| t == &TokenKind::Not) {
break;
}
let attr = parser.parse_attribute(true)?;
assert_eq!(attr.style, ast::AttrStyle::Inner);
attrs.push(attr);
}
TokenKind::DocComment(s) => {
// we need to get the position of this token before we bump.
let attr = rustc_ast::attr::mk_doc_comment(
rustc_ast::util::comments::doc_comment_style(&s.as_str()
),
s,
parser.token.span,
);
if attr.style == ast::AttrStyle::Inner {
attrs.push(attr);
parser.bump();
} else {
break;
}
}
_ => break,
}
}
Ok(attrs)
}
fn parse_mod_items(parser: &mut RawParser<'a>, span: Span) -> PResult<'a, as
t::Mod> {
let mut items = vec![];
while let Some(item) = parser.parse_item()? {
items.push(item);
}
// Handle extern mods that are empty files/files with only comments.
if items.is_empty() {
parser.parse_mod(&TokenKind::Eof)?;
}
let hi = if parser.token.span.is_dummy() {
span
} else {
parser.prev_token.span
};
Ok(ast::Mod {
inner: span.to(hi),
items,
inline: false,
})
}
pub(crate) fn parse_file_as_module( pub(crate) fn parse_file_as_module(
sess: &'a ParseSess, sess: &'a ParseSess,
path: &Path, path: &Path,
span: Span, span: Span,
) -> Option<ast::Mod> { ) -> Option<(ast::Mod, Vec<ast::Attribute>)> {
let result = catch_unwind(AssertUnwindSafe(|| { let result = catch_unwind(AssertUnwindSafe(|| {
let mut parser = new_parser_from_file(sess.inner(), &path, Some(span )); let mut parser = new_parser_from_file(sess.inner(), &path, Some(span ));
match parser.parse_mod(&TokenKind::Eof) {
let lo = parser.token.span; Ok(result) => Some(result),
// FIXME(topecongiro) Format inner attributes (#3606).
match Parser::parse_inner_attrs(&mut parser) {
Ok(_attrs) => (),
Err(mut e) => { Err(mut e) => {
e.cancel(); e.cancel();
sess.reset_errors(); sess.reset_errors();
return None;
}
}
match Parser::parse_mod_items(&mut parser, lo) {
Ok(m) => Some(m),
Err(mut db) => {
db.cancel();
sess.reset_errors();
None None
} }
} }
})); }));
match result { match result {
Ok(Some(m)) => Some(m), Ok(Some(m)) => Some(m),
_ => None, _ => None,
} }
} }
 End of changes. 5 change blocks. 
82 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)