Skip to content

Commit

Permalink
Auto merge of rust-lang#124993 - jieyouxu:rollup-u02aso7, r=jieyouxu
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#124233 (Add `-lmingwex` second time in `mingw_libs`)
 - rust-lang#124318 (ignore generics args in attribute paths)
 - rust-lang#124899 (bootstrap: add comments for the automatic dry run)
 - rust-lang#124904 (reachable computation: extend explanation of what this does, and why)
 - rust-lang#124930 (Make sure we consume a generic arg when checking mistyped turbofish)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 11, 2024
2 parents 19dacee + e7bb090 commit f9a3fd9
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 59 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,11 @@ impl<'a> Parser<'a> {
let x = self.parse_seq_to_before_end(
&token::Gt,
SeqSep::trailing_allowed(token::Comma),
|p| p.parse_generic_arg(None),
|p| match p.parse_generic_arg(None)? {
Some(arg) => Ok(arg),
// If we didn't eat a generic arg, then we should error.
None => p.unexpected_any(),
},
);
match x {
Ok((_, _, Recovered::No)) => {
Expand Down
19 changes: 12 additions & 7 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<'a> Parser<'a> {
style: PathStyle,
ty_generics: Option<&Generics>,
) -> PResult<'a, Path> {
let reject_generics_if_mod_style = |parser: &Parser<'_>, path: &Path| {
let reject_generics_if_mod_style = |parser: &Parser<'_>, path: Path| {
// Ensure generic arguments don't end up in attribute paths, such as:
//
// macro_rules! m {
Expand All @@ -178,21 +178,26 @@ impl<'a> Parser<'a> {
.map(|arg| arg.span())
.collect::<Vec<_>>();
parser.dcx().emit_err(errors::GenericsInPath { span });
// Ignore these arguments to prevent unexpected behaviors.
let segments = path
.segments
.iter()
.map(|segment| PathSegment { ident: segment.ident, id: segment.id, args: None })
.collect();
Path { segments, ..path }
} else {
path
}
};

maybe_whole!(self, NtPath, |path| {
reject_generics_if_mod_style(self, &path);
path.into_inner()
});
maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner()));

if let token::Interpolated(nt) = &self.token.kind {
if let token::NtTy(ty) = &nt.0 {
if let ast::TyKind::Path(None, path) = &ty.kind {
let path = path.clone();
self.bump();
reject_generics_if_mod_style(self, &path);
return Ok(path);
return Ok(reject_generics_if_mod_style(self, path));
}
}
}
Expand Down
32 changes: 22 additions & 10 deletions compiler/rustc_passes/src/reachable.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
//! Finds local items that are externally reachable, which means that other crates need access to
//! their compiled machine code or their MIR.
//! Finds local items that are "reachable", which means that other crates need access to their
//! compiled code or their *runtime* MIR. (Compile-time MIR is always encoded anyway, so we don't
//! worry about that here.)
//!
//! An item is "externally reachable" if it is relevant for other crates. This obviously includes
//! all public items. However, some of these items cannot be compiled to machine code (because they
//! are generic), and for some the machine code is not sufficient (because we want to cross-crate
//! inline them). These items "need cross-crate MIR". When a reachable function `f` needs
//! cross-crate MIR, then all the functions it calls also become reachable, as they will be
//! necessary to use the MIR of `f` from another crate. Furthermore, an item can become "externally
//! reachable" by having a `const`/`const fn` return a pointer to that item, so we also need to
//! recurse into reachable `const`/`const fn`.
//! An item is "reachable" if codegen that happens in downstream crates can end up referencing this
//! item. This obviously includes all public items. However, some of these items cannot be codegen'd
//! (because they are generic), and for some the compiled code is not sufficient (because we want to
//! cross-crate inline them). These items "need cross-crate MIR". When a reachable function `f`
//! needs cross-crate MIR, then its MIR may be codegen'd in a downstream crate, and hence items it
//! mentions need to be considered reachable.
//!
//! Furthermore, if a `const`/`const fn` is reachable, then it can return pointers to other items,
//! making those reachable as well. For instance, consider a `const fn` returning a pointer to an
//! otherwise entirely private function: if a downstream crate calls that `const fn` to compute the
//! initial value of a `static`, then it needs to generate a direct reference to this function --
//! i.e., the function is directly reachable from that downstream crate! Hence we have to recurse
//! into `const` and `const fn`.
//!
//! Conversely, reachability *stops* when it hits a monomorphic non-`const` function that we do not
//! want to cross-crate inline. That function will just be codegen'd in this crate, which means the
//! monomorphization collector will consider it a root and then do another graph traversal to
//! codegen everything called by this function -- but that's a very different graph from what we are
//! considering here as at that point, everything is monomorphic.

use hir::def_id::LocalDefIdSet;
use rustc_data_structures::stack::ensure_sufficient_stack;
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_target/src/spec/base/windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub fn opts() -> TargetOptions {
//
// See https://github.com/rust-lang/rust/pull/47483 for some more details.
"-lmsvcrt",
// Math functions missing in MSVCRT (they are present in UCRT) require
// this dependency cycle: `libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`.
"-lmingwex",
"-luser32",
"-lkernel32",
];
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {

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

/// When bootstrap is passed a set of paths, this controls whether this rule
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ impl Build {

if !self.config.dry_run() {
{
// We first do a dry-run. This is a sanity-check to ensure that
// steps don't do anything expensive in the dry-run.
self.config.dry_run = DryRun::SelfCheck;
let builder = builder::Builder::new(self);
builder.execute_cli();
Expand Down
16 changes: 0 additions & 16 deletions tests/crashes/123911.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/crashes/123912.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ known-bug: #97006
//@ compile-flags: -Zunpretty=hir

#![allow(unused)]
// issue#97006

macro_rules! m {
($attr_path: path) => {
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/macros/genercs-in-path-with-prettry-hir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: unexpected generic arguments in path
--> $DIR/genercs-in-path-with-prettry-hir.rs:12:10
|
LL | m!(inline<u8>);
| ^^^^

error: aborting due to 1 previous error

15 changes: 15 additions & 0 deletions tests/ui/macros/genercs-in-path-with-prettry-hir.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ compile-flags: -Zunpretty=hir

// issue#97006

macro_rules! m { ($attr_path: path) => { #[$attr_path] fn f() {} } }
#[

inline]
fn f() { }

fn main() { }
19 changes: 19 additions & 0 deletions tests/ui/macros/macro-expand-within-generics-in-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// issue#123911
// issue#123912

macro_rules! m {
($p: path) => {
#[$p]
struct S;
};
}

macro_rules! p {
() => {};
}

m!(generic<p!()>);
//~^ ERROR: unexpected generic arguments in path
//~| ERROR: cannot find attribute `generic` in this scope

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/macros/macro-expand-within-generics-in-path.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: unexpected generic arguments in path
--> $DIR/macro-expand-within-generics-in-path.rs:15:11
|
LL | m!(generic<p!()>);
| ^^^^^^

error: cannot find attribute `generic` in this scope
--> $DIR/macro-expand-within-generics-in-path.rs:15:4
|
LL | m!(generic<p!()>);
| ^^^^^^^

error: aborting due to 2 previous errors

6 changes: 6 additions & 0 deletions tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn foo() {
let x = Tr<A, A:>;
//~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,`
}

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,`
--> $DIR/turbofish-arg-with-stray-colon.rs:2:17
|
LL | let x = Tr<A, A:>;
| ^ expected one of 8 possible tokens
|
= note: type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
help: maybe write a path separator here
|
LL | let x = Tr<A, A::>;
| ~~

error: aborting due to 1 previous error

1 change: 0 additions & 1 deletion tests/ui/span/macro-ty-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ fn main() {
foo::<>!(); //~ ERROR generic arguments in macro path
m!(Default<>);
//~^ ERROR unexpected generic arguments in path
//~^^ ERROR generic arguments in macro path
}
8 changes: 1 addition & 7 deletions tests/ui/span/macro-ty-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,5 @@ error: unexpected generic arguments in path
LL | m!(Default<>);
| ^^

error: generic arguments in macro path
--> $DIR/macro-ty-params.rs:12:15
|
LL | m!(Default<>);
| ^^

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

0 comments on commit f9a3fd9

Please sign in to comment.