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

Rollup of 7 pull requests #85831

Closed
wants to merge 16 commits into from
Closed
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
2 changes: 2 additions & 0 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ pub fn compile_declarative_macro(
&sess.parse_sess,
def.id,
features,
edition,
)
.pop()
.unwrap();
Expand All @@ -492,6 +493,7 @@ pub fn compile_declarative_macro(
&sess.parse_sess,
def.id,
features,
edition,
)
.pop()
.unwrap();
Expand Down
27 changes: 22 additions & 5 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use rustc_feature::Features;
use rustc_session::parse::ParseSess;
use rustc_span::symbol::{kw, Ident};

use rustc_span::Span;
use rustc_span::edition::Edition;
use rustc_span::{Span, SyntaxContext};

use rustc_data_structures::sync::Lrc;

Expand All @@ -32,6 +33,7 @@ const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
/// - `sess`: the parsing session. Any errors will be emitted to this session.
/// - `node_id`: the NodeId of the macro we are parsing.
/// - `features`: language features so we can do feature gating.
/// - `edition`: the edition of the crate defining the macro
///
/// # Returns
///
Expand All @@ -42,6 +44,7 @@ pub(super) fn parse(
sess: &ParseSess,
node_id: NodeId,
features: &Features,
edition: Edition,
) -> Vec<TokenTree> {
// Will contain the final collection of `self::TokenTree`
let mut result = Vec::new();
Expand All @@ -52,7 +55,7 @@ pub(super) fn parse(
while let Some(tree) = trees.next() {
// Given the parsed tree, if there is a metavar and we are expecting matchers, actually
// parse out the matcher (i.e., in `$id:ident` this would parse the `:` and `ident`).
let tree = parse_tree(tree, &mut trees, expect_matchers, sess, node_id, features);
let tree = parse_tree(tree, &mut trees, expect_matchers, sess, node_id, features, edition);
match tree {
TokenTree::MetaVar(start_sp, ident) if expect_matchers => {
let span = match trees.next() {
Expand All @@ -64,7 +67,19 @@ pub(super) fn parse(

let kind =
token::NonterminalKind::from_symbol(frag.name, || {
span.edition()
// FIXME(#85708) - once we properly decode a foreign
// crate's `SyntaxContext::root`, then we can replace
// this with just `span.edition()`. A
// `SyntaxContext::root()` from the current crate will
// have the edition of the current crate, and a
// `SyntaxxContext::root()` from a foreign crate will
// have the edition of that crate (which we manually
// retrieve via the `edition` parameter).
if span.ctxt() == SyntaxContext::root() {
edition
} else {
span.edition()
}
})
.unwrap_or_else(
|| {
Expand Down Expand Up @@ -117,13 +132,15 @@ pub(super) fn parse(
/// - `expect_matchers`: same as for `parse` (see above).
/// - `sess`: the parsing session. Any errors will be emitted to this session.
/// - `features`: language features so we can do feature gating.
/// - `edition` - the edition of the crate defining the macro
fn parse_tree(
tree: tokenstream::TokenTree,
outer_trees: &mut impl Iterator<Item = tokenstream::TokenTree>,
expect_matchers: bool,
sess: &ParseSess,
node_id: NodeId,
features: &Features,
edition: Edition,
) -> TokenTree {
// Depending on what `tree` is, we could be parsing different parts of a macro
match tree {
Expand Down Expand Up @@ -151,7 +168,7 @@ fn parse_tree(
sess.span_diagnostic.span_err(span.entire(), &msg);
}
// Parse the contents of the sequence itself
let sequence = parse(tts, expect_matchers, sess, node_id, features);
let sequence = parse(tts, expect_matchers, sess, node_id, features, edition);
// Get the Kleene operator and optional separator
let (separator, kleene) =
parse_sep_and_kleene_op(&mut trees, span.entire(), sess);
Expand Down Expand Up @@ -204,7 +221,7 @@ fn parse_tree(
span,
Lrc::new(Delimited {
delim,
tts: parse(tts, expect_matchers, sess, node_id, features),
tts: parse(tts, expect_matchers, sess, node_id, features, edition),
}),
),
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,10 @@ impl<'a> Parser<'a> {
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
} else {
let err = if self.check_fn_front_matter(false) {
let _ = self.parse_fn(&mut Vec::new(), |_| true, lo);
// We use `parse_fn` to get a span for the function
if let Err(mut db) = self.parse_fn(&mut Vec::new(), |_| true, lo) {
db.delay_as_bug();
}
let mut err = self.struct_span_err(
lo.to(self.prev_token.span),
&format!("functions are not allowed in {} definitions", adt_ty),
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_session/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ pub fn filename_for_metadata(
crate_name: &str,
outputs: &OutputFilenames,
) -> PathBuf {
// If the command-line specified the path, use that directly.
if let Some(Some(out_filename)) = sess.opts.output_types.get(&OutputType::Metadata) {
return out_filename.clone();
}

let libname = format!("{}{}", crate_name, sess.opts.cg.extra_filename);

let out_filename = outputs
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/vec/is_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
// `Option<num::NonZeroU32>` and similar have a representation guarantee that
// they're the same size as the corresponding `u32` type, as well as a guarantee
// that transmuting between `NonZeroU32` and `Option<num::NonZeroU32>` works.
// While the documentation officially makes in UB to transmute from `None`,
// While the documentation officially makes it UB to transmute from `None`,
// we're the standard library so we can make extra inferences, and we know that
// the only niche available to represent `None` is the one that's all zeros.

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Step for Llvm {
.define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap())
.define("LLVM_DEFAULT_TARGET_TRIPLE", target_native);

if target != "aarch64-apple-darwin" {
if target != "aarch64-apple-darwin" && !target.contains("windows") {
cfg.define("LLVM_ENABLE_ZLIB", "ON");
} else {
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [JSON Output](json.md)
- [Tests](tests/index.md)
- [Platform Support](platform-support.md)
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
- [Target Tier Policy](target-tier-policy.md)
- [Targets](targets/index.md)
- [Built-in Targets](targets/built-in.md)
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ host tools.
target | std | host | notes
-------|:---:|:----:|-------
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
`aarch64-apple-ios-sim` | ? | | Apple iOS Simulator on ARM64
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | | | Apple iOS Simulator on ARM64
`aarch64-apple-tvos` | * | | ARM64 tvOS
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
`aarch64-unknown-hermit` | ? | |
Expand Down
56 changes: 56 additions & 0 deletions src/doc/rustc/src/platform-support/aarch64-apple-ios-sim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# aarch64-apple-ios-sim

**Tier: 3**

Apple iOS Simulator on ARM64.

## Designated Developers

* [@badboy](https://github.com/badboy)
* [@deg4uss3r](https://github.com/deg4uss3r)

## Requirements

This target is cross-compiled.
To build this target Xcode 12 or higher on macOS is required.

## Building

The target can be built by enabling it for a `rustc` build:

```toml
[build]
build-stage = 1
target = ["aarch64-apple-ios-sim"]
```

## Cross-compilation

This target can be cross-compiled from `x86_64` or `aarch64` macOS hosts.

Other hosts are not supported for cross-compilation, but might work when also providing the required Xcode SDK.

## Testing

Currently there is no support to run the rustc test suite for this target.


## Building Rust programs

*Note: Building for this target requires the corresponding iOS SDK, as provided by Xcode 12+.*

If `rustc` has support for that target and the library artifacts are available,
then Rust programs can be built for that target:

```text
rustc --target aarch64-apple-ios-sim your-code.rs
```

On Rust Nightly it is possible to build without the target artifacts available:

```text
cargo build -Z build-std --target aarch64-apple-ios-sim
```

There is no easy way to run simple programs in the iOS simulator.
Static library builds can be embedded into iOS applications.
7 changes: 0 additions & 7 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,6 @@ impl Options {
return Err(0);
}

if matches.opt_strs("print").iter().any(|opt| opt == "unversioned-files") {
for file in crate::html::render::FILES_UNVERSIONED.keys() {
println!("{}", file);
}
return Err(0);
}

let color = config::parse_color(&matches);
let config::JsonConfig { json_rendered, json_unused_externs, .. } =
config::parse_json(&matches);
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ mod print_item;
mod write_shared;

crate use context::*;
crate use write_shared::FILES_UNVERSIONED;

use std::collections::VecDeque;
use std::default::Default;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::docfs::PathError;
use crate::error::Error;
use crate::html::{layout, static_files};

crate static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
map! {
"FiraSans-Regular.woff2" => static_files::fira_sans::REGULAR2,
"FiraSans-Medium.woff2" => static_files::fira_sans::MEDIUM2,
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,6 @@ fn opts() -> Vec<RustcOptGroup> {
"Generate JSON file at the top level instead of generating HTML redirection files",
)
}),
unstable("print", |o| {
o.optmulti("", "print", "Rustdoc information to print on stdout", "[unversioned-files]")
}),
unstable("emit", |o| {
o.optmulti(
"",
Expand Down
4 changes: 0 additions & 4 deletions src/test/run-make-fulldeps/print-unversioned-files/Makefile

This file was deleted.

This file was deleted.

33 changes: 33 additions & 0 deletions src/test/run-make/emit-named-files/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-include ../../run-make-fulldeps/tools.mk

OUT=$(TMPDIR)/emit

all: asm llvm-bc llvm-ir obj metadata link dep-info mir

asm: $(OUT)
$(RUSTC) --emit asm=$(OUT)/libfoo.s foo.rs
test -f $(OUT)/libfoo.s
llvm-bc: $(OUT)
$(RUSTC) --emit llvm-bc=$(OUT)/libfoo.bc foo.rs
test -f $(OUT)/libfoo.bc
llvm-ir: $(OUT)
$(RUSTC) --emit llvm-ir=$(OUT)/libfoo.ll foo.rs
test -f $(OUT)/libfoo.ll
obj: $(OUT)
$(RUSTC) --emit obj=$(OUT)/libfoo.o foo.rs
test -f $(OUT)/libfoo.o
metadata: $(OUT)
$(RUSTC) --emit metadata=$(OUT)/libfoo.rmeta foo.rs
test -f $(OUT)/libfoo.rmeta
link: $(OUT)
$(RUSTC) --emit link=$(OUT)/libfoo.rlib foo.rs
test -f $(OUT)/libfoo.rlib
dep-info: $(OUT)
$(RUSTC) --emit dep-info=$(OUT)/libfoo.d foo.rs
test -f $(OUT)/libfoo.d
mir: $(OUT)
$(RUSTC) --emit mir=$(OUT)/libfoo.mir foo.rs
test -f $(OUT)/libfoo.mir

$(OUT):
mkdir -p $(OUT)
1 change: 1 addition & 0 deletions src/test/run-make/emit-named-files/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#![crate_type = "rlib"]
11 changes: 11 additions & 0 deletions src/test/ui/macros/auxiliary/foreign-crate-macro-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// edition:2018

#[macro_export]
macro_rules! custom_matches {
($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => {
match $expression {
$( $pattern )|+ $( if $guard )? => true,
_ => false
}
}
}
12 changes: 12 additions & 0 deletions src/test/ui/macros/cross-crate-pat-span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// edition:2021
// check-pass
// aux-build: foreign-crate-macro-pat.rs
//
// Tests that the edition of the foreign crate is used
// when determining the behavior of the `:pat` matcher.

extern crate foreign_crate_macro_pat;

fn main() {
let _b = foreign_crate_macro_pat::custom_matches!(b'3', b'0' ..= b'9');
}
9 changes: 9 additions & 0 deletions src/test/ui/macros/issue-84429-matches-edition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// edition:2021
// check-pass
//
// Regression test for issue #84429
// Tests that we can properly invoke `matches!` from a 2021-edition crate.

fn main() {
let _b = matches!(b'3', b'0' ..= b'9');
}
10 changes: 10 additions & 0 deletions src/test/ui/parser/fn-field-parse-error-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression test for #85794

struct Baz {
inner : dyn fn ()
//~^ ERROR expected `,`, or `}`, found keyword `fn`
//~| ERROR functions are not allowed in struct definitions
//~| ERROR cannot find type `dyn` in this scope
}

fn main() {}
24 changes: 24 additions & 0 deletions src/test/ui/parser/fn-field-parse-error-ice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error: expected `,`, or `}`, found keyword `fn`
--> $DIR/fn-field-parse-error-ice.rs:4:16
|
LL | inner : dyn fn ()
| ^ help: try adding a comma: `,`

error: functions are not allowed in struct definitions
--> $DIR/fn-field-parse-error-ice.rs:4:17
|
LL | inner : dyn fn ()
| ^^
|
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information

error[E0412]: cannot find type `dyn` in this scope
--> $DIR/fn-field-parse-error-ice.rs:4:13
|
LL | inner : dyn fn ()
| ^^^ not found in this scope

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0412`.
Loading