Skip to content

Commit f9a3fd9

Browse files
committed
Auto merge of #124993 - jieyouxu:rollup-u02aso7, r=jieyouxu
Rollup of 5 pull requests Successful merges: - #124233 (Add `-lmingwex` second time in `mingw_libs`) - #124318 (ignore generics args in attribute paths) - #124899 (bootstrap: add comments for the automatic dry run) - #124904 (reachable computation: extend explanation of what this does, and why) - #124930 (Make sure we consume a generic arg when checking mistyped turbofish) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 19dacee + e7bb090 commit f9a3fd9

17 files changed

+125
-59
lines changed

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,11 @@ impl<'a> Parser<'a> {
12231223
let x = self.parse_seq_to_before_end(
12241224
&token::Gt,
12251225
SeqSep::trailing_allowed(token::Comma),
1226-
|p| p.parse_generic_arg(None),
1226+
|p| match p.parse_generic_arg(None)? {
1227+
Some(arg) => Ok(arg),
1228+
// If we didn't eat a generic arg, then we should error.
1229+
None => p.unexpected_any(),
1230+
},
12271231
);
12281232
match x {
12291233
Ok((_, _, Recovered::No)) => {

Diff for: compiler/rustc_parse/src/parser/path.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'a> Parser<'a> {
160160
style: PathStyle,
161161
ty_generics: Option<&Generics>,
162162
) -> PResult<'a, Path> {
163-
let reject_generics_if_mod_style = |parser: &Parser<'_>, path: &Path| {
163+
let reject_generics_if_mod_style = |parser: &Parser<'_>, path: Path| {
164164
// Ensure generic arguments don't end up in attribute paths, such as:
165165
//
166166
// macro_rules! m {
@@ -178,21 +178,26 @@ impl<'a> Parser<'a> {
178178
.map(|arg| arg.span())
179179
.collect::<Vec<_>>();
180180
parser.dcx().emit_err(errors::GenericsInPath { span });
181+
// Ignore these arguments to prevent unexpected behaviors.
182+
let segments = path
183+
.segments
184+
.iter()
185+
.map(|segment| PathSegment { ident: segment.ident, id: segment.id, args: None })
186+
.collect();
187+
Path { segments, ..path }
188+
} else {
189+
path
181190
}
182191
};
183192

184-
maybe_whole!(self, NtPath, |path| {
185-
reject_generics_if_mod_style(self, &path);
186-
path.into_inner()
187-
});
193+
maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner()));
188194

189195
if let token::Interpolated(nt) = &self.token.kind {
190196
if let token::NtTy(ty) = &nt.0 {
191197
if let ast::TyKind::Path(None, path) = &ty.kind {
192198
let path = path.clone();
193199
self.bump();
194-
reject_generics_if_mod_style(self, &path);
195-
return Ok(path);
200+
return Ok(reject_generics_if_mod_style(self, path));
196201
}
197202
}
198203
}

Diff for: compiler/rustc_passes/src/reachable.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
//! Finds local items that are externally reachable, which means that other crates need access to
2-
//! their compiled machine code or their MIR.
1+
//! Finds local items that are "reachable", which means that other crates need access to their
2+
//! compiled code or their *runtime* MIR. (Compile-time MIR is always encoded anyway, so we don't
3+
//! worry about that here.)
34
//!
4-
//! An item is "externally reachable" if it is relevant for other crates. This obviously includes
5-
//! all public items. However, some of these items cannot be compiled to machine code (because they
6-
//! are generic), and for some the machine code is not sufficient (because we want to cross-crate
7-
//! inline them). These items "need cross-crate MIR". When a reachable function `f` needs
8-
//! cross-crate MIR, then all the functions it calls also become reachable, as they will be
9-
//! necessary to use the MIR of `f` from another crate. Furthermore, an item can become "externally
10-
//! reachable" by having a `const`/`const fn` return a pointer to that item, so we also need to
11-
//! recurse into reachable `const`/`const fn`.
5+
//! An item is "reachable" if codegen that happens in downstream crates can end up referencing this
6+
//! item. This obviously includes all public items. However, some of these items cannot be codegen'd
7+
//! (because they are generic), and for some the compiled code is not sufficient (because we want to
8+
//! cross-crate inline them). These items "need cross-crate MIR". When a reachable function `f`
9+
//! needs cross-crate MIR, then its MIR may be codegen'd in a downstream crate, and hence items it
10+
//! mentions need to be considered reachable.
11+
//!
12+
//! Furthermore, if a `const`/`const fn` is reachable, then it can return pointers to other items,
13+
//! making those reachable as well. For instance, consider a `const fn` returning a pointer to an
14+
//! otherwise entirely private function: if a downstream crate calls that `const fn` to compute the
15+
//! initial value of a `static`, then it needs to generate a direct reference to this function --
16+
//! i.e., the function is directly reachable from that downstream crate! Hence we have to recurse
17+
//! into `const` and `const fn`.
18+
//!
19+
//! Conversely, reachability *stops* when it hits a monomorphic non-`const` function that we do not
20+
//! want to cross-crate inline. That function will just be codegen'd in this crate, which means the
21+
//! monomorphization collector will consider it a root and then do another graph traversal to
22+
//! codegen everything called by this function -- but that's a very different graph from what we are
23+
//! considering here as at that point, everything is monomorphic.
1224
1325
use hir::def_id::LocalDefIdSet;
1426
use rustc_data_structures::stack::ensure_sufficient_stack;

Diff for: compiler/rustc_target/src/spec/base/windows_gnu.rs

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ pub fn opts() -> TargetOptions {
4040
//
4141
// See https://github.com/rust-lang/rust/pull/47483 for some more details.
4242
"-lmsvcrt",
43+
// Math functions missing in MSVCRT (they are present in UCRT) require
44+
// this dependency cycle: `libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`.
45+
"-lmingwex",
4346
"-luser32",
4447
"-lkernel32",
4548
];

Diff for: src/bootstrap/src/core/builder.rs

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
8888

8989
/// Primary function to execute this rule. Can call `builder.ensure()`
9090
/// with other steps to run those.
91+
///
92+
/// This gets called twice during a normal `./x.py` execution: first
93+
/// with `dry_run() == true`, and then for real.
9194
fn run(self, builder: &Builder<'_>) -> Self::Output;
9295

9396
/// When bootstrap is passed a set of paths, this controls whether this rule

Diff for: src/bootstrap/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ impl Build {
683683

684684
if !self.config.dry_run() {
685685
{
686+
// We first do a dry-run. This is a sanity-check to ensure that
687+
// steps don't do anything expensive in the dry-run.
686688
self.config.dry_run = DryRun::SelfCheck;
687689
let builder = builder::Builder::new(self);
688690
builder.execute_cli();

Diff for: tests/crashes/123911.rs

-16
This file was deleted.

Diff for: tests/crashes/123912.rs

-15
This file was deleted.

Diff for: tests/crashes/97006.rs renamed to tests/ui/macros/genercs-in-path-with-prettry-hir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//@ known-bug: #97006
21
//@ compile-flags: -Zunpretty=hir
32

4-
#![allow(unused)]
3+
// issue#97006
54

65
macro_rules! m {
76
($attr_path: path) => {
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unexpected generic arguments in path
2+
--> $DIR/genercs-in-path-with-prettry-hir.rs:12:10
3+
|
4+
LL | m!(inline<u8>);
5+
| ^^^^
6+
7+
error: aborting due to 1 previous error
8+
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#[prelude_import]
2+
use ::std::prelude::rust_2015::*;
3+
#[macro_use]
4+
extern crate std;
5+
//@ compile-flags: -Zunpretty=hir
6+
7+
// issue#97006
8+
9+
macro_rules! m { ($attr_path: path) => { #[$attr_path] fn f() {} } }
10+
#[
11+
12+
inline]
13+
fn f() { }
14+
15+
fn main() { }
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// issue#123911
2+
// issue#123912
3+
4+
macro_rules! m {
5+
($p: path) => {
6+
#[$p]
7+
struct S;
8+
};
9+
}
10+
11+
macro_rules! p {
12+
() => {};
13+
}
14+
15+
m!(generic<p!()>);
16+
//~^ ERROR: unexpected generic arguments in path
17+
//~| ERROR: cannot find attribute `generic` in this scope
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unexpected generic arguments in path
2+
--> $DIR/macro-expand-within-generics-in-path.rs:15:11
3+
|
4+
LL | m!(generic<p!()>);
5+
| ^^^^^^
6+
7+
error: cannot find attribute `generic` in this scope
8+
--> $DIR/macro-expand-within-generics-in-path.rs:15:4
9+
|
10+
LL | m!(generic<p!()>);
11+
| ^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo() {
2+
let x = Tr<A, A:>;
3+
//~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,`
4+
}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,`
2+
--> $DIR/turbofish-arg-with-stray-colon.rs:2:17
3+
|
4+
LL | let x = Tr<A, A:>;
5+
| ^ expected one of 8 possible tokens
6+
|
7+
= note: type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
8+
help: maybe write a path separator here
9+
|
10+
LL | let x = Tr<A, A::>;
11+
| ~~
12+
13+
error: aborting due to 1 previous error
14+

Diff for: tests/ui/span/macro-ty-params.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ fn main() {
1111
foo::<>!(); //~ ERROR generic arguments in macro path
1212
m!(Default<>);
1313
//~^ ERROR unexpected generic arguments in path
14-
//~^^ ERROR generic arguments in macro path
1514
}

Diff for: tests/ui/span/macro-ty-params.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,5 @@ error: unexpected generic arguments in path
1616
LL | m!(Default<>);
1717
| ^^
1818

19-
error: generic arguments in macro path
20-
--> $DIR/macro-ty-params.rs:12:15
21-
|
22-
LL | m!(Default<>);
23-
| ^^
24-
25-
error: aborting due to 4 previous errors
19+
error: aborting due to 3 previous errors
2620

0 commit comments

Comments
 (0)