Skip to content

Commit c1e8f3a

Browse files
committed
Auto merge of #85838 - GuillaumeGomez:rollup-rk2rh7m, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - #85285 (Add eslint checks to CI) - #85709 (Use correct edition when parsing `:pat` matchers) - #85762 (Do not try to build LLVM with Zlib on Windows) - #85770 (Remove `--print unversioned-files` from rustdoc ) - #85781 (Add documentation for aarch64-apple-ios-sim target) - #85801 (Add `String::extend_from_within`) - #85817 (Fix a typo) - #85818 (Don't drop `PResult` without handling the error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 758c00e + 71a7f8f commit c1e8f3a

File tree

24 files changed

+197
-45
lines changed

24 files changed

+197
-45
lines changed

compiler/rustc_expand/src/mbe/macro_rules.rs

+2
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ pub fn compile_declarative_macro(
467467
&sess.parse_sess,
468468
def.id,
469469
features,
470+
edition,
470471
)
471472
.pop()
472473
.unwrap();
@@ -492,6 +493,7 @@ pub fn compile_declarative_macro(
492493
&sess.parse_sess,
493494
def.id,
494495
features,
496+
edition,
495497
)
496498
.pop()
497499
.unwrap();

compiler/rustc_expand/src/mbe/quoted.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use rustc_feature::Features;
99
use rustc_session::parse::ParseSess;
1010
use rustc_span::symbol::{kw, Ident};
1111

12-
use rustc_span::Span;
12+
use rustc_span::edition::Edition;
13+
use rustc_span::{Span, SyntaxContext};
1314

1415
use rustc_data_structures::sync::Lrc;
1516

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

6568
let kind =
6669
token::NonterminalKind::from_symbol(frag.name, || {
67-
span.edition()
70+
// FIXME(#85708) - once we properly decode a foreign
71+
// crate's `SyntaxContext::root`, then we can replace
72+
// this with just `span.edition()`. A
73+
// `SyntaxContext::root()` from the current crate will
74+
// have the edition of the current crate, and a
75+
// `SyntaxxContext::root()` from a foreign crate will
76+
// have the edition of that crate (which we manually
77+
// retrieve via the `edition` parameter).
78+
if span.ctxt() == SyntaxContext::root() {
79+
edition
80+
} else {
81+
span.edition()
82+
}
6883
})
6984
.unwrap_or_else(
7085
|| {
@@ -117,13 +132,15 @@ pub(super) fn parse(
117132
/// - `expect_matchers`: same as for `parse` (see above).
118133
/// - `sess`: the parsing session. Any errors will be emitted to this session.
119134
/// - `features`: language features so we can do feature gating.
135+
/// - `edition` - the edition of the crate defining the macro
120136
fn parse_tree(
121137
tree: tokenstream::TokenTree,
122138
outer_trees: &mut impl Iterator<Item = tokenstream::TokenTree>,
123139
expect_matchers: bool,
124140
sess: &ParseSess,
125141
node_id: NodeId,
126142
features: &Features,
143+
edition: Edition,
127144
) -> TokenTree {
128145
// Depending on what `tree` is, we could be parsing different parts of a macro
129146
match tree {
@@ -151,7 +168,7 @@ fn parse_tree(
151168
sess.span_diagnostic.span_err(span.entire(), &msg);
152169
}
153170
// Parse the contents of the sequence itself
154-
let sequence = parse(tts, expect_matchers, sess, node_id, features);
171+
let sequence = parse(tts, expect_matchers, sess, node_id, features, edition);
155172
// Get the Kleene operator and optional separator
156173
let (separator, kleene) =
157174
parse_sep_and_kleene_op(&mut trees, span.entire(), sess);
@@ -204,7 +221,7 @@ fn parse_tree(
204221
span,
205222
Lrc::new(Delimited {
206223
delim,
207-
tts: parse(tts, expect_matchers, sess, node_id, features),
224+
tts: parse(tts, expect_matchers, sess, node_id, features, edition),
208225
}),
209226
),
210227
}

compiler/rustc_parse/src/parser/item.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,10 @@ impl<'a> Parser<'a> {
14741474
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
14751475
} else {
14761476
let err = if self.check_fn_front_matter(false) {
1477-
let _ = self.parse_fn(&mut Vec::new(), |_| true, lo);
1477+
// We use `parse_fn` to get a span for the function
1478+
if let Err(mut db) = self.parse_fn(&mut Vec::new(), |_| true, lo) {
1479+
db.delay_as_bug();
1480+
}
14781481
let mut err = self.struct_span_err(
14791482
lo.to(self.prev_token.span),
14801483
&format!("functions are not allowed in {} definitions", adt_ty),

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
#![feature(associated_type_bounds)]
145145
#![feature(slice_group_by)]
146146
#![feature(decl_macro)]
147+
#![feature(bindings_after_at)]
147148
// Allow testing this library
148149

149150
#[cfg(test)]

library/alloc/src/string.rs

+36
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,42 @@ impl String {
843843
self.vec.extend_from_slice(string.as_bytes())
844844
}
845845

846+
/// Copies elements from `src` range to the end of the string.
847+
///
848+
/// ## Panics
849+
///
850+
/// Panics if the starting point or end point do not lie on a [`char`]
851+
/// boundary, or if they're out of bounds.
852+
///
853+
/// ## Examples
854+
///
855+
/// ```
856+
/// #![feature(string_extend_from_within)]
857+
/// let mut string = String::from("abcde");
858+
///
859+
/// string.extend_from_within(2..);
860+
/// assert_eq!(string, "abcdecde");
861+
///
862+
/// string.extend_from_within(..2);
863+
/// assert_eq!(string, "abcdecdeab");
864+
///
865+
/// string.extend_from_within(4..8);
866+
/// assert_eq!(string, "abcdecdeabecde");
867+
/// ```
868+
#[cfg(not(no_global_oom_handling))]
869+
#[unstable(feature = "string_extend_from_within", issue = "none")]
870+
pub fn extend_from_within<R>(&mut self, src: R)
871+
where
872+
R: RangeBounds<usize>,
873+
{
874+
let src @ Range { start, end } = slice::range(src, ..self.len());
875+
876+
assert!(self.is_char_boundary(start));
877+
assert!(self.is_char_boundary(end));
878+
879+
self.vec.extend_from_within(src);
880+
}
881+
846882
/// Returns this `String`'s capacity, in bytes.
847883
///
848884
/// # Examples

library/alloc/src/vec/is_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
7373
// `Option<num::NonZeroU32>` and similar have a representation guarantee that
7474
// they're the same size as the corresponding `u32` type, as well as a guarantee
7575
// that transmuting between `NonZeroU32` and `Option<num::NonZeroU32>` works.
76-
// While the documentation officially makes in UB to transmute from `None`,
76+
// While the documentation officially makes it UB to transmute from `None`,
7777
// we're the standard library so we can make extra inferences, and we know that
7878
// the only niche available to represent `None` is the one that's all zeros.
7979

src/bootstrap/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl Step for Llvm {
181181
.define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap())
182182
.define("LLVM_DEFAULT_TARGET_TRIPLE", target_native);
183183

184-
if target != "aarch64-apple-darwin" {
184+
if target != "aarch64-apple-darwin" && !target.contains("windows") {
185185
cfg.define("LLVM_ENABLE_ZLIB", "ON");
186186
} else {
187187
cfg.define("LLVM_ENABLE_ZLIB", "OFF");

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
2222
# Install es-check
2323
# Pin its version to prevent unrelated CI failures due to future es-check versions.
2424
RUN npm install [email protected] -g
25+
RUN npm install [email protected] -g
2526

2627
COPY scripts/sccache.sh /scripts/
2728
RUN sh /scripts/sccache.sh
@@ -37,4 +38,5 @@ ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \
3738
python3 ../x.py doc --stage 0 library/test && \
3839
/scripts/validate-toolstate.sh && \
3940
# Runs checks to ensure that there are no ES5 issues in our JS code.
40-
es-check es5 ../src/librustdoc/html/static/*.js
41+
es-check es5 ../src/librustdoc/html/static/*.js && \
42+
eslint ../src/librustdoc/html/static/*.js

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [JSON Output](json.md)
1414
- [Tests](tests/index.md)
1515
- [Platform Support](platform-support.md)
16+
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
1617
- [Target Tier Policy](target-tier-policy.md)
1718
- [Targets](targets/index.md)
1819
- [Built-in Targets](targets/built-in.md)

src/doc/rustc/src/platform-support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ host tools.
196196
target | std | host | notes
197197
-------|:---:|:----:|-------
198198
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
199-
`aarch64-apple-ios-sim` | ? | | Apple iOS Simulator on ARM64
199+
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | | | Apple iOS Simulator on ARM64
200200
`aarch64-apple-tvos` | * | | ARM64 tvOS
201201
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
202202
`aarch64-unknown-hermit` | ? | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# aarch64-apple-ios-sim
2+
3+
**Tier: 3**
4+
5+
Apple iOS Simulator on ARM64.
6+
7+
## Designated Developers
8+
9+
* [@badboy](https://github.com/badboy)
10+
* [@deg4uss3r](https://github.com/deg4uss3r)
11+
12+
## Requirements
13+
14+
This target is cross-compiled.
15+
To build this target Xcode 12 or higher on macOS is required.
16+
17+
## Building
18+
19+
The target can be built by enabling it for a `rustc` build:
20+
21+
```toml
22+
[build]
23+
build-stage = 1
24+
target = ["aarch64-apple-ios-sim"]
25+
```
26+
27+
## Cross-compilation
28+
29+
This target can be cross-compiled from `x86_64` or `aarch64` macOS hosts.
30+
31+
Other hosts are not supported for cross-compilation, but might work when also providing the required Xcode SDK.
32+
33+
## Testing
34+
35+
Currently there is no support to run the rustc test suite for this target.
36+
37+
38+
## Building Rust programs
39+
40+
*Note: Building for this target requires the corresponding iOS SDK, as provided by Xcode 12+.*
41+
42+
If `rustc` has support for that target and the library artifacts are available,
43+
then Rust programs can be built for that target:
44+
45+
```text
46+
rustc --target aarch64-apple-ios-sim your-code.rs
47+
```
48+
49+
On Rust Nightly it is possible to build without the target artifacts available:
50+
51+
```text
52+
cargo build -Z build-std --target aarch64-apple-ios-sim
53+
```
54+
55+
There is no easy way to run simple programs in the iOS simulator.
56+
Static library builds can be embedded into iOS applications.

src/librustdoc/config.rs

-7
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,6 @@ impl Options {
349349
return Err(0);
350350
}
351351

352-
if matches.opt_strs("print").iter().any(|opt| opt == "unversioned-files") {
353-
for file in crate::html::render::FILES_UNVERSIONED.keys() {
354-
println!("{}", file);
355-
}
356-
return Err(0);
357-
}
358-
359352
let color = config::parse_color(&matches);
360353
let config::JsonConfig { json_rendered, json_unused_externs, .. } =
361354
config::parse_json(&matches);

src/librustdoc/html/render/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ mod print_item;
3333
mod write_shared;
3434

3535
crate use context::*;
36-
crate use write_shared::FILES_UNVERSIONED;
3736

3837
use std::collections::VecDeque;
3938
use std::default::Default;

src/librustdoc/html/render/write_shared.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::docfs::PathError;
1818
use crate::error::Error;
1919
use crate::html::{layout, static_files};
2020

21-
crate static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
21+
static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
2222
map! {
2323
"FiraSans-Regular.woff2" => static_files::fira_sans::REGULAR2,
2424
"FiraSans-Medium.woff2" => static_files::fira_sans::MEDIUM2,
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/* global initSidebarItems */
12
initSidebarItems({});

src/librustdoc/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,6 @@ fn opts() -> Vec<RustcOptGroup> {
581581
"Generate JSON file at the top level instead of generating HTML redirection files",
582582
)
583583
}),
584-
unstable("print", |o| {
585-
o.optmulti("", "print", "Rustdoc information to print on stdout", "[unversioned-files]")
586-
}),
587584
unstable("emit", |o| {
588585
o.optmulti(
589586
"",

src/test/run-make-fulldeps/print-unversioned-files/Makefile

-4
This file was deleted.

src/test/run-make-fulldeps/print-unversioned-files/unversioned-files.txt

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition:2018
2+
3+
#[macro_export]
4+
macro_rules! custom_matches {
5+
($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => {
6+
match $expression {
7+
$( $pattern )|+ $( if $guard )? => true,
8+
_ => false
9+
}
10+
}
11+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2021
2+
// check-pass
3+
// aux-build: foreign-crate-macro-pat.rs
4+
//
5+
// Tests that the edition of the foreign crate is used
6+
// when determining the behavior of the `:pat` matcher.
7+
8+
extern crate foreign_crate_macro_pat;
9+
10+
fn main() {
11+
let _b = foreign_crate_macro_pat::custom_matches!(b'3', b'0' ..= b'9');
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// edition:2021
2+
// check-pass
3+
//
4+
// Regression test for issue #84429
5+
// Tests that we can properly invoke `matches!` from a 2021-edition crate.
6+
7+
fn main() {
8+
let _b = matches!(b'3', b'0' ..= b'9');
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for #85794
2+
3+
struct Baz {
4+
inner : dyn fn ()
5+
//~^ ERROR expected `,`, or `}`, found keyword `fn`
6+
//~| ERROR functions are not allowed in struct definitions
7+
//~| ERROR cannot find type `dyn` in this scope
8+
}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)