Skip to content

Commit e36e4bd

Browse files
committed
Auto merge of rust-lang#76231 - tmandry:rollup-ilvs9fq, r=tmandry
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
2 parents 130359c + 4dd75f8 commit e36e4bd

File tree

47 files changed

+1064
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1064
-99
lines changed

compiler/rustc_ast/src/ast.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -922,9 +922,13 @@ impl Stmt {
922922
pub fn add_trailing_semicolon(mut self) -> Self {
923923
self.kind = match self.kind {
924924
StmtKind::Expr(expr) => StmtKind::Semi(expr),
925-
StmtKind::MacCall(mac) => StmtKind::MacCall(
926-
mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)),
927-
),
925+
StmtKind::MacCall(mac) => {
926+
StmtKind::MacCall(mac.map(|MacCallStmt { mac, style: _, attrs }| MacCallStmt {
927+
mac,
928+
style: MacStmtStyle::Semicolon,
929+
attrs,
930+
}))
931+
}
928932
kind => kind,
929933
};
930934
self
@@ -958,7 +962,14 @@ pub enum StmtKind {
958962
/// Just a trailing semi-colon.
959963
Empty,
960964
/// Macro.
961-
MacCall(P<(MacCall, MacStmtStyle, AttrVec)>),
965+
MacCall(P<MacCallStmt>),
966+
}
967+
968+
#[derive(Clone, Encodable, Decodable, Debug)]
969+
pub struct MacCallStmt {
970+
pub mac: MacCall,
971+
pub style: MacStmtStyle,
972+
pub attrs: AttrVec,
962973
}
963974

964975
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]

compiler/rustc_ast/src/attr/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_span::symbol::{sym, Ident, Symbol};
1616
use rustc_span::Span;
1717

1818
use std::iter;
19-
use std::ops::DerefMut;
2019

2120
pub struct MarkedAttrs(GrowableBitSet<AttrId>);
2221

@@ -634,10 +633,7 @@ impl HasAttrs for StmtKind {
634633
StmtKind::Local(ref local) => local.attrs(),
635634
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
636635
StmtKind::Empty | StmtKind::Item(..) => &[],
637-
StmtKind::MacCall(ref mac) => {
638-
let (_, _, ref attrs) = **mac;
639-
attrs.attrs()
640-
}
636+
StmtKind::MacCall(ref mac) => mac.attrs.attrs(),
641637
}
642638
}
643639

@@ -647,8 +643,7 @@ impl HasAttrs for StmtKind {
647643
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
648644
StmtKind::Empty | StmtKind::Item(..) => {}
649645
StmtKind::MacCall(mac) => {
650-
let (_mac, _style, attrs) = mac.deref_mut();
651-
attrs.visit_attrs(f);
646+
mac.attrs.visit_attrs(f);
652647
}
653648
}
654649
}

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
13051305
StmtKind::Semi(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Semi).collect(),
13061306
StmtKind::Empty => smallvec![StmtKind::Empty],
13071307
StmtKind::MacCall(mut mac) => {
1308-
let (mac_, _semi, attrs) = mac.deref_mut();
1308+
let MacCallStmt { mac: mac_, style: _, attrs } = mac.deref_mut();
13091309
vis.visit_mac(mac_);
13101310
visit_thin_attrs(attrs, vis);
13111311
smallvec![StmtKind::MacCall(mac)]

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
692692
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr),
693693
StmtKind::Empty => {}
694694
StmtKind::MacCall(ref mac) => {
695-
let (ref mac, _, ref attrs) = **mac;
695+
let MacCallStmt { ref mac, style: _, ref attrs } = **mac;
696696
visitor.visit_mac(mac);
697697
for attr in attrs.iter() {
698698
visitor.visit_attribute(attr);

compiler/rustc_ast_pretty/src/pprust.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1507,11 +1507,10 @@ impl<'a> State<'a> {
15071507
self.s.word(";");
15081508
}
15091509
ast::StmtKind::MacCall(ref mac) => {
1510-
let (ref mac, style, ref attrs) = **mac;
15111510
self.space_if_not_bol();
1512-
self.print_outer_attributes(attrs);
1513-
self.print_mac(mac);
1514-
if style == ast::MacStmtStyle::Semicolon {
1511+
self.print_outer_attributes(&mac.attrs);
1512+
self.print_mac(&mac.mac);
1513+
if mac.style == ast::MacStmtStyle::Semicolon {
15151514
self.s.word(";");
15161515
}
15171516
}

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
10841084

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

@@ -1499,7 +1499,7 @@ fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'
14991499
/// Add sysroot and other globally set directories to the directory search list.
15001500
fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
15011501
// Prefer system mingw-w64 libs, see get_crt_libs_path comment for more details.
1502-
if sess.opts.debugging_opts.link_self_contained.is_none()
1502+
if sess.opts.cg.link_self_contained.is_none()
15031503
&& cfg!(windows)
15041504
&& sess.target.target.llvm_target.contains("windows-gnu")
15051505
{

compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ E0768: include_str!("./error_codes/E0768.md"),
454454
E0769: include_str!("./error_codes/E0769.md"),
455455
E0770: include_str!("./error_codes/E0770.md"),
456456
E0771: include_str!("./error_codes/E0771.md"),
457+
E0773: include_str!("./error_codes/E0773.md"),
457458
;
458459
// E0006, // merged with E0005
459460
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
A builtin-macro was defined more than once.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0773
6+
#![feature(decl_macro)]
7+
#![feature(rustc_attrs)]
8+
9+
#[rustc_builtin_macro]
10+
pub macro test($item:item) {
11+
/* compiler built-in */
12+
}
13+
14+
mod inner {
15+
#[rustc_builtin_macro]
16+
pub macro test($item:item) {
17+
/* compiler built-in */
18+
}
19+
}
20+
```
21+
22+
To fix the issue, remove the duplicate declaration:
23+
24+
```
25+
#![feature(decl_macro)]
26+
#![feature(rustc_attrs)]
27+
28+
#[rustc_builtin_macro]
29+
pub macro test($item:item) {
30+
/* compiler built-in */
31+
}
32+
```
33+
34+
In very rare edge cases, this may happen when loading `core` or `std` twice,
35+
once with `check` metadata and once with `build` metadata.
36+
For more information, see [#75176].
37+
38+
[#75176]: https://github.com/rust-lang/rust/pull/75176#issuecomment-683234468

compiler/rustc_expand/src/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::token;
1313
use rustc_ast::tokenstream::TokenStream;
1414
use rustc_ast::visit::{self, AssocCtxt, Visitor};
1515
use rustc_ast::{self as ast, AttrItem, Block, LitKind, NodeId, PatKind, Path};
16-
use rustc_ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
16+
use rustc_ast::{ItemKind, MacArgs, MacCallStmt, MacStmtStyle, StmtKind};
1717
use rustc_ast_pretty::pprust;
1818
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
1919
use rustc_data_structures::map_in_place::MapInPlace;
@@ -1363,7 +1363,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13631363
}
13641364

13651365
if let StmtKind::MacCall(mac) = stmt.kind {
1366-
let (mac, style, attrs) = mac.into_inner();
1366+
let MacCallStmt { mac, style, attrs } = mac.into_inner();
13671367
self.check_attributes(&attrs);
13681368
let mut placeholder =
13691369
self.collect_bang(mac, stmt.span, AstFragmentKind::Stmts).make_stmts();

compiler/rustc_expand/src/placeholders.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ pub fn placeholder(
9292
AstFragment::Ty(P(ast::Ty { id, span, kind: ast::TyKind::MacCall(mac_placeholder()) }))
9393
}
9494
AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{
95-
let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ast::AttrVec::new()));
95+
let mac = P(ast::MacCallStmt {
96+
mac: mac_placeholder(),
97+
style: ast::MacStmtStyle::Braces,
98+
attrs: ast::AttrVec::new(),
99+
});
96100
ast::Stmt { id, span, kind: ast::StmtKind::MacCall(mac) }
97101
}]),
98102
AstFragmentKind::Arms => AstFragment::Arms(smallvec![ast::Arm {
@@ -293,7 +297,7 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
293297

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

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ fn test_codegen_options_tracking_hash() {
402402
// `link_arg` is omitted because it just forwards to `link_args`.
403403
untracked!(link_args, vec![String::from("abc"), String::from("def")]);
404404
untracked!(link_dead_code, Some(true));
405+
untracked!(link_self_contained, Some(true));
405406
untracked!(linker, Some(PathBuf::from("linker")));
406407
untracked!(linker_flavor, Some(LinkerFlavor::Gcc));
407408
untracked!(no_stack_check, true);

compiler/rustc_lexer/src/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,16 @@ pub fn strip_shebang(input: &str) -> Option<usize> {
191191
// For simplicity we consider any line starting with `#!` a shebang,
192192
// regardless of restrictions put on shebangs by specific platforms.
193193
if let Some(input_tail) = input.strip_prefix("#!") {
194-
// Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
195-
// a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
194+
// Ok, this is a shebang but if the next non-whitespace token is `[`,
196195
// then it may be valid Rust code, so consider it Rust code.
197-
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok|
198-
!matches!(tok, TokenKind::Whitespace | TokenKind::LineComment { .. } | TokenKind::BlockComment { .. })
199-
);
196+
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok| {
197+
!matches!(
198+
tok,
199+
TokenKind::Whitespace
200+
| TokenKind::LineComment { doc_style: None }
201+
| TokenKind::BlockComment { doc_style: None, .. }
202+
)
203+
});
200204
if next_non_whitespace_token != Some(TokenKind::OpenBracket) {
201205
// No other choice than to consider this a shebang.
202206
return Some(2 + input_tail.lines().next().unwrap_or_default().len());

compiler/rustc_mir/src/util/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod alignment;
99
pub mod collect_writes;
1010
mod graphviz;
1111
pub(crate) mod pretty;
12+
pub(crate) mod spanview;
1213

1314
pub use self::aggregate::expand_aggregate;
1415
pub use self::alignment::is_disaligned;

compiler/rustc_mir/src/util/pretty.rs

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::{self, Write};
66
use std::path::{Path, PathBuf};
77

88
use super::graphviz::write_mir_fn_graphviz;
9+
use super::spanview::write_mir_fn_spanview;
910
use crate::transform::MirSource;
1011
use either::Either;
1112
use rustc_data_structures::fx::FxHashMap;
@@ -147,6 +148,16 @@ fn dump_matched_mir_node<'tcx, F>(
147148
write_mir_fn_graphviz(tcx, source.def_id(), body, false, &mut file)?;
148149
};
149150
}
151+
152+
if let Some(spanview) = tcx.sess.opts.debugging_opts.dump_mir_spanview {
153+
let _: io::Result<()> = try {
154+
let mut file =
155+
create_dump_file(tcx, "html", pass_num, pass_name, disambiguator, source)?;
156+
if source.def_id().is_local() {
157+
write_mir_fn_spanview(tcx, source.def_id(), body, spanview, &mut file)?;
158+
}
159+
};
160+
}
150161
}
151162

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

0 commit comments

Comments
 (0)