Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.x: Bump rustc-ap to v679 #4434

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 103 additions & 67 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,36 @@ rustc-workspace-hack = "1.0.0"

[dependencies.rustc_ast]
package = "rustc-ap-rustc_ast"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_ast_pretty]
package = "rustc-ap-rustc_ast_pretty"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_attr]
package = "rustc-ap-rustc_attr"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_data_structures]
package = "rustc-ap-rustc_data_structures"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_errors]
package = "rustc-ap-rustc_errors"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_expand]
package = "rustc-ap-rustc_expand"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_parse]
package = "rustc-ap-rustc_parse"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_session]
package = "rustc-ap-rustc_session"
version = "677.0.0"
version = "679.0.0"

[dependencies.rustc_span]
package = "rustc-ap-rustc_span"
version = "677.0.0"
version = "679.0.0"
5 changes: 1 addition & 4 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
ast::StmtKind::Local(ref local) => local.span,
ast::StmtKind::Item(ref item) => item.span,
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span,
ast::StmtKind::MacCall(ref mac) => {
let (ref mac, _, _) = **mac;
mac.span()
}
ast::StmtKind::MacCall(ref mac_stmt) => mac_stmt.mac.span(),
ast::StmtKind::Empty => stmt.span,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ fn rewrite_closure_with_block(
id: ast::NodeId::root(),
kind: ast::StmtKind::Expr(ptr::P(body.clone())),
span: body.span,
tokens: None,
}],
id: ast::NodeId::root(),
rules: ast::BlockCheckMode::Default,
span: body.span,
tokens: None,
};
let block = crate::expr::rewrite_block_with_visitor(
context,
Expand Down
9 changes: 4 additions & 5 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::fmt;

use rustc_ast::ast::{self, UseTreeKind};
use rustc_span::{
source_map,
symbol::{self, sym},
BytePos, Span, DUMMY_SP,
};
Expand Down Expand Up @@ -509,16 +508,16 @@ impl UseTree {
fn same_visibility(&self, other: &UseTree) -> bool {
match (&self.visibility, &other.visibility) {
(
Some(source_map::Spanned {
node: ast::VisibilityKind::Inherited,
Some(ast::Visibility {
kind: ast::VisibilityKind::Inherited,
..
}),
None,
)
| (
None,
Some(source_map::Spanned {
node: ast::VisibilityKind::Inherited,
Some(ast::Visibility {
kind: ast::VisibilityKind::Inherited,
..
}),
)
Expand Down
14 changes: 8 additions & 6 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::cmp::{max, min, Ordering};
use regex::Regex;
use rustc_ast::visit;
use rustc_ast::{ast, ptr};
use rustc_span::{source_map, symbol, BytePos, Span, DUMMY_SP};
use rustc_span::{symbol, BytePos, Span, DUMMY_SP};

use crate::attr::filter_inline_attrs;
use crate::comment::{
Expand All @@ -31,9 +31,10 @@ use crate::utils::*;
use crate::vertical::rewrite_with_alignment;
use crate::visitor::FmtVisitor;

const DEFAULT_VISIBILITY: ast::Visibility = source_map::Spanned {
node: ast::VisibilityKind::Inherited,
const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
kind: ast::VisibilityKind::Inherited,
span: DUMMY_SP,
tokens: None,
};

fn type_annotation_separator(config: &Config) -> &str {
Expand Down Expand Up @@ -125,7 +126,7 @@ impl Rewrite for ast::Local {
// FIXME format modules in this style
#[allow(dead_code)]
struct Item<'a> {
keyword: &'static str,
unsafety: ast::Unsafe,
abi: Cow<'static, str>,
vis: Option<&'a ast::Visibility>,
body: Vec<BodyElement<'a>>,
Expand All @@ -135,7 +136,7 @@ struct Item<'a> {
impl<'a> Item<'a> {
fn from_foreign_mod(fm: &'a ast::ForeignMod, span: Span, config: &Config) -> Item<'a> {
Item {
keyword: "",
unsafety: fm.unsafety,
abi: format_extern(
ast::Extern::from_abi(fm.abi),
config.force_explicit_abi(),
Expand Down Expand Up @@ -254,6 +255,7 @@ impl<'a> FnSig<'a> {

impl<'a> FmtVisitor<'a> {
fn format_item(&mut self, item: &Item<'_>) {
self.buffer.push_str(format_unsafety(item.unsafety));
self.buffer.push_str(&item.abi);

let snippet = self.snippet(item.span);
Expand Down Expand Up @@ -1367,7 +1369,7 @@ pub(crate) fn format_struct_struct(
}

fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
match vis.node {
match vis.kind {
ast::VisibilityKind::Crate(..) | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
_ => default_span.lo(),
}
Expand Down
5 changes: 2 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,7 @@ fn next_space(tok: &TokenKind) -> SpaceState {
| TokenKind::Pound
| TokenKind::Dollar
| TokenKind::OpenDelim(_)
| TokenKind::CloseDelim(_)
| TokenKind::Whitespace => SpaceState::Never,
| TokenKind::CloseDelim(_) => SpaceState::Never,

TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(_) => SpaceState::Ident,

Expand Down Expand Up @@ -1275,8 +1274,8 @@ impl MacroParser {
span,
})) = self.toks.look_ahead(0)
{
self.toks.next();
hi = span.hi();
self.toks.next();
}
Some(MacroBranch {
span: mk_sp(lo, hi),
Expand Down
7 changes: 3 additions & 4 deletions src/spanned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ impl Spanned for ast::Stmt {
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => {
mk_sp(expr.span().lo(), self.span.hi())
}
ast::StmtKind::MacCall(ref mac) => {
let (_, _, ref attrs) = **mac;
if attrs.is_empty() {
ast::StmtKind::MacCall(ref mac_stmt) => {
if mac_stmt.attrs.is_empty() {
self.span
} else {
mk_sp(attrs[0].span.lo(), self.span.hi())
mk_sp(mac_stmt.attrs[0].span.lo(), self.span.hi())
}
}
ast::StmtKind::Empty => self.span,
Expand Down
2 changes: 1 addition & 1 deletion src/syntux/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a> Parser<'a> {
) -> Result<(ast::Mod, Vec<ast::Attribute>), ParserError> {
let result = catch_unwind(AssertUnwindSafe(|| {
let mut parser = new_parser_from_file(sess.inner(), &path, Some(span));
match parser.parse_mod(&TokenKind::Eof) {
match parser.parse_mod(&TokenKind::Eof, ast::Unsafe::No) {
Ok(result) => Some(result),
Err(mut e) => {
e.cancel();
Expand Down
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ pub(crate) fn extra_offset(text: &str, shape: Shape) -> usize {
}

pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
match (&a.node, &b.node) {
match (&a.kind, &b.kind) {
(
VisibilityKind::Restricted { path: p, .. },
VisibilityKind::Restricted { path: q, .. },
) => pprust::path_to_string(p) == pprust::path_to_string(q),
) => pprust::path_to_string(&p) == pprust::path_to_string(&q),
(VisibilityKind::Public, VisibilityKind::Public)
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
| (
Expand All @@ -62,7 +62,7 @@ pub(crate) fn format_visibility(
context: &RewriteContext<'_>,
vis: &Visibility,
) -> Cow<'static, str> {
match vis.node {
match vis.kind {
VisibilityKind::Public => Cow::from("pub "),
VisibilityKind::Inherited => Cow::from(""),
VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
Expand Down
22 changes: 13 additions & 9 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cell::{Cell, RefCell};
use std::rc::Rc;

use rustc_ast::{ast, attr::HasAttrs, token::DelimToken, visit};
use rustc_span::{symbol, BytePos, Pos, Span};
use rustc_span::{symbol, BytePos, Pos, Span, DUMMY_SP};

use crate::attr::*;
use crate::comment::{rewrite_comment, CodeCharKind, CommentCodeSlices};
Expand All @@ -25,8 +25,8 @@ use crate::spanned::Spanned;
use crate::stmt::Stmt;
use crate::syntux::session::ParseSess;
use crate::utils::{
self, contains_skip, count_newlines, depr_skip_annotation, inner_attributes, last_line_width,
mk_sp, ptr_vec_to_ref_vec, rewrite_ident, stmt_expr,
self, contains_skip, count_newlines, depr_skip_annotation, format_unsafety, inner_attributes,
last_line_width, mk_sp, ptr_vec_to_ref_vec, rewrite_ident, stmt_expr,
};
use crate::{ErrorKind, FormatReport, FormattingError};

Expand Down Expand Up @@ -146,16 +146,15 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
self.push_rewrite(stmt.span(), rewrite)
}
}
ast::StmtKind::MacCall(ref mac) => {
let (ref mac, _macro_style, ref attrs) = **mac;
if self.visit_attrs(attrs, ast::AttrStyle::Outer) {
ast::StmtKind::MacCall(ref mac_stmt) => {
if self.visit_attrs(&mac_stmt.attrs, ast::AttrStyle::Outer) {
self.push_skipped_with_span(
attrs,
&mac_stmt.attrs,
stmt.span(),
get_span_without_attrs(stmt.as_ast_node()),
);
} else {
self.visit_mac(mac, None, MacroPosition::Statement);
self.visit_mac(&mac_stmt.mac, None, MacroPosition::Statement);
}
self.format_missing(stmt.span().hi());
}
Expand Down Expand Up @@ -604,7 +603,11 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
}
ast::AssocItemKind::Fn(defaultness, ref sig, ref generics, Some(ref body)) => {
let inner_attrs = inner_attributes(&ti.attrs);
let vis = rustc_span::source_map::dummy_spanned(ast::VisibilityKind::Inherited);
let vis = ast::Visibility {
kind: ast::VisibilityKind::Inherited,
span: DUMMY_SP,
tokens: None,
};
let fn_ctxt = visit::FnCtxt::Assoc(visit::AssocCtxt::Trait);
self.visit_fn(
visit::FnKind::Fn(fn_ctxt, ti.ident, sig, &vis, Some(body)),
Expand Down Expand Up @@ -903,6 +906,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
) {
let vis_str = utils::format_visibility(&self.get_context(), vis);
self.push_str(&*vis_str);
self.push_str(format_unsafety(m.unsafety));
self.push_str("mod ");
// Calling `to_owned()` to work around borrow checker.
let ident_str = rewrite_ident(&self.get_context(), ident).to_owned();
Expand Down
7 changes: 7 additions & 0 deletions tests/source/unsafe-mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// These are supported by rustc syntactically but not semantically.

#[cfg(any())]
unsafe mod m { }

#[cfg(any())]
unsafe extern "C++" { }
7 changes: 7 additions & 0 deletions tests/target/unsafe-mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// These are supported by rustc syntactically but not semantically.

#[cfg(any())]
unsafe mod m {}

#[cfg(any())]
unsafe extern "C++" {}