Skip to content

Commit 72f4923

Browse files
committed
Auto merge of #102297 - fee1-dead-contrib:rollup-2np0cre, r=fee1-dead
Rollup of 5 pull requests Successful merges: - #102143 (Recover from struct nested in struct) - #102178 (bootstrap: the backtrace feature is stable, no need to allow it any more) - #102197 (Stabilize const `BTree{Map,Set}::new`) - #102267 (Don't set RUSTC in the bootstrap build script) - #102270 (Remove benches from `rustc_middle`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fe217c2 + 39c6bdc commit 72f4923

File tree

14 files changed

+60
-108
lines changed

14 files changed

+60
-108
lines changed

compiler/rustc_hir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
#![feature(associated_type_defaults)]
66
#![feature(closure_track_caller)]
7-
#![feature(const_btree_new)]
7+
#![feature(const_btree_len)]
88
#![cfg_attr(bootstrap, feature(let_else))]
99
#![feature(once_cell)]
1010
#![feature(min_specialization)]

compiler/rustc_middle/benches/lib.rs

-54
This file was deleted.

compiler/rustc_parse/src/parser/item.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ impl<'a> Parser<'a> {
17151715
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
17161716
let (ident, is_raw) = self.ident_or_err()?;
17171717
if !is_raw && ident.is_reserved() {
1718+
let snapshot = self.create_snapshot_for_diagnostic();
17181719
let err = if self.check_fn_front_matter(false) {
17191720
let inherited_vis = Visibility {
17201721
span: rustc_span::DUMMY_SP,
@@ -1735,6 +1736,22 @@ impl<'a> Parser<'a> {
17351736
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
17361737
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
17371738
err
1739+
} else if self.eat_keyword(kw::Struct) {
1740+
match self.parse_item_struct() {
1741+
Ok((ident, _)) => {
1742+
let mut err = self.struct_span_err(
1743+
lo.with_hi(ident.span.hi()),
1744+
&format!("structs are not allowed in {adt_ty} definitions"),
1745+
);
1746+
err.help("consider creating a new `struct` definition instead of nesting");
1747+
err
1748+
}
1749+
Err(err) => {
1750+
err.cancel();
1751+
self.restore_snapshot(snapshot);
1752+
self.expected_ident_found()
1753+
}
1754+
}
17381755
} else {
17391756
self.expected_ident_found()
17401757
};

library/alloc/src/collections/btree/map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<K, V> BTreeMap<K, V> {
580580
/// map.insert(1, "a");
581581
/// ```
582582
#[stable(feature = "rust1", since = "1.0.0")]
583-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
583+
#[rustc_const_stable(feature = "const_btree_new", since = "CURRENT_RUSTC_VERSION")]
584584
#[must_use]
585585
pub const fn new() -> BTreeMap<K, V> {
586586
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(Global), _marker: PhantomData }
@@ -2392,7 +2392,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
23922392
/// ```
23932393
#[must_use]
23942394
#[stable(feature = "rust1", since = "1.0.0")]
2395-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
2395+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
23962396
pub const fn len(&self) -> usize {
23972397
self.length
23982398
}
@@ -2413,7 +2413,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
24132413
/// ```
24142414
#[must_use]
24152415
#[stable(feature = "rust1", since = "1.0.0")]
2416-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
2416+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
24172417
pub const fn is_empty(&self) -> bool {
24182418
self.len() == 0
24192419
}

library/alloc/src/collections/btree/set.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl<T> BTreeSet<T> {
343343
/// let mut set: BTreeSet<i32> = BTreeSet::new();
344344
/// ```
345345
#[stable(feature = "rust1", since = "1.0.0")]
346-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
346+
#[rustc_const_stable(feature = "const_btree_new", since = "CURRENT_RUSTC_VERSION")]
347347
#[must_use]
348348
pub const fn new() -> BTreeSet<T> {
349349
BTreeSet { map: BTreeMap::new() }
@@ -1174,7 +1174,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
11741174
/// ```
11751175
#[must_use]
11761176
#[stable(feature = "rust1", since = "1.0.0")]
1177-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
1177+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
11781178
pub const fn len(&self) -> usize {
11791179
self.map.len()
11801180
}
@@ -1193,7 +1193,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
11931193
/// ```
11941194
#[must_use]
11951195
#[stable(feature = "rust1", since = "1.0.0")]
1196-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
1196+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
11971197
pub const fn is_empty(&self) -> bool {
11981198
self.len() == 0
11991199
}

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
#![feature(coerce_unsized)]
100100
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
101101
#![feature(const_box)]
102-
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_new))]
102+
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
103103
#![feature(const_cow_is_borrowed)]
104104
#![feature(const_convert)]
105105
#![feature(const_size_of_val)]

library/alloc/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#![feature(slice_group_by)]
3333
#![feature(slice_partition_dedup)]
3434
#![feature(string_remove_matches)]
35-
#![feature(const_btree_new)]
35+
#![feature(const_btree_len)]
3636
#![feature(const_default_impls)]
3737
#![feature(const_trait_impl)]
3838
#![feature(const_str_from_utf8)]

src/bootstrap/build.rs

-36
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
1-
use env::consts::{EXE_EXTENSION, EXE_SUFFIX};
21
use std::env;
3-
use std::ffi::OsString;
4-
use std::path::PathBuf;
5-
6-
/// Given an executable called `name`, return the filename for the
7-
/// executable for a particular target.
8-
pub fn exe(name: &PathBuf) -> PathBuf {
9-
if EXE_EXTENSION != "" && name.extension() != Some(EXE_EXTENSION.as_ref()) {
10-
let mut name: OsString = name.clone().into();
11-
name.push(EXE_SUFFIX);
12-
name.into()
13-
} else {
14-
name.clone()
15-
}
16-
}
172

183
fn main() {
194
let host = env::var("HOST").unwrap();
205
println!("cargo:rerun-if-changed=build.rs");
21-
println!("cargo:rerun-if-env-changed=RUSTC");
226
println!("cargo:rustc-env=BUILD_TRIPLE={}", host);
23-
24-
// This may not be a canonicalized path.
25-
let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
26-
27-
if rustc.is_relative() {
28-
println!("cargo:rerun-if-env-changed=PATH");
29-
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
30-
let absolute = dir.join(&exe(&rustc));
31-
if absolute.exists() {
32-
rustc = absolute;
33-
break;
34-
}
35-
}
36-
}
37-
assert!(rustc.is_absolute());
38-
39-
// FIXME: if the path is not utf-8, this is going to break. Unfortunately
40-
// Cargo doesn't have a way for us to specify non-utf-8 paths easily, so
41-
// we'll need to invent some encoding scheme if this becomes a problem.
42-
println!("cargo:rustc-env=RUSTC={}", rustc.to_str().unwrap());
437
}

src/bootstrap/builder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1557,13 +1557,12 @@ impl<'a> Builder<'a> {
15571557
match mode {
15581558
Mode::ToolBootstrap => {
15591559
// Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally.
1560-
// HACK: because anyhow does feature detection in build.rs, we need to allow the backtrace feature too.
1561-
rustflags.arg("-Zallow-features=binary-dep-depinfo,backtrace");
1560+
rustflags.arg("-Zallow-features=binary-dep-depinfo");
15621561
}
15631562
Mode::ToolStd => {
15641563
// Right now this is just compiletest and a few other tools that build on stable.
15651564
// Allow them to use `feature(test)`, but nothing else.
1566-
rustflags.arg("-Zallow-features=binary-dep-depinfo,test,backtrace,proc_macro_internals,proc_macro_diagnostic,proc_macro_span");
1565+
rustflags.arg("-Zallow-features=binary-dep-depinfo,test,proc_macro_internals,proc_macro_diagnostic,proc_macro_span");
15671566
}
15681567
Mode::Std | Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {}
15691568
}

src/test/ui/consts/issue-88071.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//
33
// regression test for #88071
44

5-
#![feature(const_btree_new)]
6-
75
use std::collections::BTreeMap;
86

97
pub struct CustomMap<K, V>(BTreeMap<K, V>);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct S1 {
2+
struct S2 {
3+
//~^ ERROR structs are not allowed in struct definitions
4+
}
5+
}
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: structs are not allowed in struct definitions
2+
--> $DIR/issue-101540.rs:2:5
3+
|
4+
LL | struct S2 {
5+
| ^^^^^^^^^
6+
|
7+
= help: consider creating a new `struct` definition instead of nesting
8+
9+
error: aborting due to previous error
10+

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,21 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bo
367367
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
368368
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
369369
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
370+
371+
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver` doesn't accept
372+
// the `-dev` version number so we have to strip it off.
373+
let short_version = since
374+
.as_str()
375+
.split('-')
376+
.next()
377+
.expect("rustc_attr::StabilityLevel::Stable::since` is empty");
378+
379+
let since = rustc_span::Symbol::intern(short_version);
380+
370381
crate::meets_msrv(
371382
msrv,
372383
RustcVersion::parse(since.as_str())
373-
.expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
384+
.unwrap_or_else(|err| panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")),
374385
)
375386
} else {
376387
// Unstable const fn with the feature enabled.

src/tools/clippy/tests/ui/crashes/ice-7126.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// This test requires a feature gated const fn and will stop working in the future.
22

3-
#![feature(const_btree_new)]
3+
#![feature(const_btree_len)]
44

55
use std::collections::BTreeMap;
66

7-
struct Foo(BTreeMap<i32, i32>);
7+
struct Foo(usize);
88
impl Foo {
99
fn new() -> Self {
10-
Self(BTreeMap::new())
10+
Self(BTreeMap::len(&BTreeMap::<u8, u8>::new()))
1111
}
1212
}
1313

0 commit comments

Comments
 (0)