Skip to content

Commit

Permalink
Auto merge of rust-lang#76231 - tmandry:rollup-ilvs9fq, r=tmandry
Browse files Browse the repository at this point in the history
Rollup of 14 pull requests

Successful merges:

 - rust-lang#74880 (Add trailing comma support to matches macro)
 - rust-lang#76074 (Add new `-Z dump-mir-spanview` option)
 - rust-lang#76088 (Add more examples to lexicographic cmp on Iterators.)
 - rust-lang#76099 (Add info about `!` and `impl Trait`)
 - rust-lang#76126 (Use "Fira Sans" for crate list font)
 - rust-lang#76132 (Factor out StmtKind::MacCall fields into `MacCallStmt` struct)
 - rust-lang#76143 (Give a better error message for duplicate built-in macros)
 - rust-lang#76158 (Stabilise link-self-contained option)
 - rust-lang#76201 (Move to intra-doc links for library/core/src/panic.rs)
 - rust-lang#76206 (Make all methods of `std::net::Ipv6Addr` const)
 - rust-lang#76207 (# Move to intra-doc links for library/core/src/clone.rs)
 - rust-lang#76212 (Document lint missing_doc_code_examples is nightly-only)
 - rust-lang#76218 (lexer: Tiny improvement to shebang detection)
 - rust-lang#76221 (Clean up header in `iter` docs for `for` loops)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Sep 2, 2020
2 parents 130359c + 4dd75f8 commit e36e4bd
Show file tree
Hide file tree
Showing 47 changed files with 1,064 additions and 99 deletions.
19 changes: 15 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,9 +922,13 @@ impl Stmt {
pub fn add_trailing_semicolon(mut self) -> Self {
self.kind = match self.kind {
StmtKind::Expr(expr) => StmtKind::Semi(expr),
StmtKind::MacCall(mac) => StmtKind::MacCall(
mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)),
),
StmtKind::MacCall(mac) => {
StmtKind::MacCall(mac.map(|MacCallStmt { mac, style: _, attrs }| MacCallStmt {
mac,
style: MacStmtStyle::Semicolon,
attrs,
}))
}
kind => kind,
};
self
Expand Down Expand Up @@ -958,7 +962,14 @@ pub enum StmtKind {
/// Just a trailing semi-colon.
Empty,
/// Macro.
MacCall(P<(MacCall, MacStmtStyle, AttrVec)>),
MacCall(P<MacCallStmt>),
}

#[derive(Clone, Encodable, Decodable, Debug)]
pub struct MacCallStmt {
pub mac: MacCall,
pub style: MacStmtStyle,
pub attrs: AttrVec,
}

#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span;

use std::iter;
use std::ops::DerefMut;

pub struct MarkedAttrs(GrowableBitSet<AttrId>);

Expand Down Expand Up @@ -634,10 +633,7 @@ impl HasAttrs for StmtKind {
StmtKind::Local(ref local) => local.attrs(),
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
StmtKind::Empty | StmtKind::Item(..) => &[],
StmtKind::MacCall(ref mac) => {
let (_, _, ref attrs) = **mac;
attrs.attrs()
}
StmtKind::MacCall(ref mac) => mac.attrs.attrs(),
}
}

Expand All @@ -647,8 +643,7 @@ impl HasAttrs for StmtKind {
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
StmtKind::Empty | StmtKind::Item(..) => {}
StmtKind::MacCall(mac) => {
let (_mac, _style, attrs) = mac.deref_mut();
attrs.visit_attrs(f);
mac.attrs.visit_attrs(f);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
StmtKind::Semi(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Semi).collect(),
StmtKind::Empty => smallvec![StmtKind::Empty],
StmtKind::MacCall(mut mac) => {
let (mac_, _semi, attrs) = mac.deref_mut();
let MacCallStmt { mac: mac_, style: _, attrs } = mac.deref_mut();
vis.visit_mac(mac_);
visit_thin_attrs(attrs, vis);
smallvec![StmtKind::MacCall(mac)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr),
StmtKind::Empty => {}
StmtKind::MacCall(ref mac) => {
let (ref mac, _, ref attrs) = **mac;
let MacCallStmt { ref mac, style: _, ref attrs } = **mac;
visitor.visit_mac(mac);
for attr in attrs.iter() {
visitor.visit_attribute(attr);
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_ast_pretty/src/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,11 +1507,10 @@ impl<'a> State<'a> {
self.s.word(";");
}
ast::StmtKind::MacCall(ref mac) => {
let (ref mac, style, ref attrs) = **mac;
self.space_if_not_bol();
self.print_outer_attributes(attrs);
self.print_mac(mac);
if style == ast::MacStmtStyle::Semicolon {
self.print_outer_attributes(&mac.attrs);
self.print_mac(&mac.mac);
if mac.style == ast::MacStmtStyle::Semicolon {
self.s.word(";");
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {

fn get_object_file_path(sess: &Session, name: &str, self_contained: bool) -> PathBuf {
// prefer system {,dll}crt2.o libs, see get_crt_libs_path comment for more details
if sess.opts.debugging_opts.link_self_contained.is_none()
if sess.opts.cg.link_self_contained.is_none()
&& sess.target.target.llvm_target.contains("windows-gnu")
{
if let Some(compiler_libs_path) = get_crt_libs_path(sess) {
Expand Down Expand Up @@ -1289,7 +1289,7 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
/// Whether we link to our own CRT objects instead of relying on gcc to pull them.
/// We only provide such support for a very limited number of targets.
fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
if let Some(self_contained) = sess.opts.debugging_opts.link_self_contained {
if let Some(self_contained) = sess.opts.cg.link_self_contained {
return self_contained;
}

Expand Down Expand Up @@ -1499,7 +1499,7 @@ fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'
/// Add sysroot and other globally set directories to the directory search list.
fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
// Prefer system mingw-w64 libs, see get_crt_libs_path comment for more details.
if sess.opts.debugging_opts.link_self_contained.is_none()
if sess.opts.cg.link_self_contained.is_none()
&& cfg!(windows)
&& sess.target.target.llvm_target.contains("windows-gnu")
{
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ E0768: include_str!("./error_codes/E0768.md"),
E0769: include_str!("./error_codes/E0769.md"),
E0770: include_str!("./error_codes/E0770.md"),
E0771: include_str!("./error_codes/E0771.md"),
E0773: include_str!("./error_codes/E0773.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
38 changes: 38 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0773.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
A builtin-macro was defined more than once.

Erroneous code example:

```compile_fail,E0773
#![feature(decl_macro)]
#![feature(rustc_attrs)]
#[rustc_builtin_macro]
pub macro test($item:item) {
/* compiler built-in */
}
mod inner {
#[rustc_builtin_macro]
pub macro test($item:item) {
/* compiler built-in */
}
}
```

To fix the issue, remove the duplicate declaration:

```
#![feature(decl_macro)]
#![feature(rustc_attrs)]
#[rustc_builtin_macro]
pub macro test($item:item) {
/* compiler built-in */
}
```

In very rare edge cases, this may happen when loading `core` or `std` twice,
once with `check` metadata and once with `build` metadata.
For more information, see [#75176].

[#75176]: https://github.com/rust-lang/rust/pull/75176#issuecomment-683234468
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::visit::{self, AssocCtxt, Visitor};
use rustc_ast::{self as ast, AttrItem, Block, LitKind, NodeId, PatKind, Path};
use rustc_ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
use rustc_ast::{ItemKind, MacArgs, MacCallStmt, MacStmtStyle, StmtKind};
use rustc_ast_pretty::pprust;
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
use rustc_data_structures::map_in_place::MapInPlace;
Expand Down Expand Up @@ -1363,7 +1363,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}

if let StmtKind::MacCall(mac) = stmt.kind {
let (mac, style, attrs) = mac.into_inner();
let MacCallStmt { mac, style, attrs } = mac.into_inner();
self.check_attributes(&attrs);
let mut placeholder =
self.collect_bang(mac, stmt.span, AstFragmentKind::Stmts).make_stmts();
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_expand/src/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ pub fn placeholder(
AstFragment::Ty(P(ast::Ty { id, span, kind: ast::TyKind::MacCall(mac_placeholder()) }))
}
AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{
let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ast::AttrVec::new()));
let mac = P(ast::MacCallStmt {
mac: mac_placeholder(),
style: ast::MacStmtStyle::Braces,
attrs: ast::AttrVec::new(),
});
ast::Stmt { id, span, kind: ast::StmtKind::MacCall(mac) }
}]),
AstFragmentKind::Arms => AstFragment::Arms(smallvec![ast::Arm {
Expand Down Expand Up @@ -293,7 +297,7 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {

fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
let (style, mut stmts) = match stmt.kind {
ast::StmtKind::MacCall(mac) => (mac.1, self.remove(stmt.id).make_stmts()),
ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()),
_ => return noop_flat_map_stmt(stmt, self),
};

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ fn test_codegen_options_tracking_hash() {
// `link_arg` is omitted because it just forwards to `link_args`.
untracked!(link_args, vec![String::from("abc"), String::from("def")]);
untracked!(link_dead_code, Some(true));
untracked!(link_self_contained, Some(true));
untracked!(linker, Some(PathBuf::from("linker")));
untracked!(linker_flavor, Some(LinkerFlavor::Gcc));
untracked!(no_stack_check, true);
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,16 @@ pub fn strip_shebang(input: &str) -> Option<usize> {
// For simplicity we consider any line starting with `#!` a shebang,
// regardless of restrictions put on shebangs by specific platforms.
if let Some(input_tail) = input.strip_prefix("#!") {
// Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
// a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
// Ok, this is a shebang but if the next non-whitespace token is `[`,
// then it may be valid Rust code, so consider it Rust code.
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok|
!matches!(tok, TokenKind::Whitespace | TokenKind::LineComment { .. } | TokenKind::BlockComment { .. })
);
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok| {
!matches!(
tok,
TokenKind::Whitespace
| TokenKind::LineComment { doc_style: None }
| TokenKind::BlockComment { doc_style: None, .. }
)
});
if next_non_whitespace_token != Some(TokenKind::OpenBracket) {
// No other choice than to consider this a shebang.
return Some(2 + input_tail.lines().next().unwrap_or_default().len());
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod alignment;
pub mod collect_writes;
mod graphviz;
pub(crate) mod pretty;
pub(crate) mod spanview;

pub use self::aggregate::expand_aggregate;
pub use self::alignment::is_disaligned;
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_mir/src/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};

use super::graphviz::write_mir_fn_graphviz;
use super::spanview::write_mir_fn_spanview;
use crate::transform::MirSource;
use either::Either;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -147,6 +148,16 @@ fn dump_matched_mir_node<'tcx, F>(
write_mir_fn_graphviz(tcx, source.def_id(), body, false, &mut file)?;
};
}

if let Some(spanview) = tcx.sess.opts.debugging_opts.dump_mir_spanview {
let _: io::Result<()> = try {
let mut file =
create_dump_file(tcx, "html", pass_num, pass_name, disambiguator, source)?;
if source.def_id().is_local() {
write_mir_fn_spanview(tcx, source.def_id(), body, spanview, &mut file)?;
}
};
}
}

/// Returns the path to the filename where we should dump a given MIR.
Expand Down

0 comments on commit e36e4bd

Please sign in to comment.