Skip to content

Commit

Permalink
Auto merge of #102297 - fee1-dead-contrib:rollup-2np0cre, r=fee1-dead
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Sep 26, 2022
2 parents fe217c2 + 39c6bdc commit 72f4923
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 108 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![feature(associated_type_defaults)]
#![feature(closure_track_caller)]
#![feature(const_btree_new)]
#![feature(const_btree_len)]
#![cfg_attr(bootstrap, feature(let_else))]
#![feature(once_cell)]
#![feature(min_specialization)]
Expand Down
54 changes: 0 additions & 54 deletions compiler/rustc_middle/benches/lib.rs

This file was deleted.

17 changes: 17 additions & 0 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,7 @@ impl<'a> Parser<'a> {
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
let (ident, is_raw) = self.ident_or_err()?;
if !is_raw && ident.is_reserved() {
let snapshot = self.create_snapshot_for_diagnostic();
let err = if self.check_fn_front_matter(false) {
let inherited_vis = Visibility {
span: rustc_span::DUMMY_SP,
Expand All @@ -1735,6 +1736,22 @@ impl<'a> Parser<'a> {
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
err
} else if self.eat_keyword(kw::Struct) {
match self.parse_item_struct() {
Ok((ident, _)) => {
let mut err = self.struct_span_err(
lo.with_hi(ident.span.hi()),
&format!("structs are not allowed in {adt_ty} definitions"),
);
err.help("consider creating a new `struct` definition instead of nesting");
err
}
Err(err) => {
err.cancel();
self.restore_snapshot(snapshot);
self.expected_ident_found()
}
}
} else {
self.expected_ident_found()
};
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl<K, V> BTreeMap<K, V> {
/// map.insert(1, "a");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
#[rustc_const_stable(feature = "const_btree_new", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub const fn new() -> BTreeMap<K, V> {
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(Global), _marker: PhantomData }
Expand Down Expand Up @@ -2392,7 +2392,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
pub const fn len(&self) -> usize {
self.length
}
Expand All @@ -2413,7 +2413,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<T> BTreeSet<T> {
/// let mut set: BTreeSet<i32> = BTreeSet::new();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
#[rustc_const_stable(feature = "const_btree_new", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub const fn new() -> BTreeSet<T> {
BTreeSet { map: BTreeMap::new() }
Expand Down Expand Up @@ -1174,7 +1174,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
pub const fn len(&self) -> usize {
self.map.len()
}
Expand All @@ -1193,7 +1193,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#![feature(coerce_unsized)]
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
#![feature(const_box)]
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_new))]
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
#![feature(const_cow_is_borrowed)]
#![feature(const_convert)]
#![feature(const_size_of_val)]
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#![feature(slice_group_by)]
#![feature(slice_partition_dedup)]
#![feature(string_remove_matches)]
#![feature(const_btree_new)]
#![feature(const_btree_len)]
#![feature(const_default_impls)]
#![feature(const_trait_impl)]
#![feature(const_str_from_utf8)]
Expand Down
36 changes: 0 additions & 36 deletions src/bootstrap/build.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,7 @@
use env::consts::{EXE_EXTENSION, EXE_SUFFIX};
use std::env;
use std::ffi::OsString;
use std::path::PathBuf;

/// Given an executable called `name`, return the filename for the
/// executable for a particular target.
pub fn exe(name: &PathBuf) -> PathBuf {
if EXE_EXTENSION != "" && name.extension() != Some(EXE_EXTENSION.as_ref()) {
let mut name: OsString = name.clone().into();
name.push(EXE_SUFFIX);
name.into()
} else {
name.clone()
}
}

fn main() {
let host = env::var("HOST").unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=RUSTC");
println!("cargo:rustc-env=BUILD_TRIPLE={}", host);

// This may not be a canonicalized path.
let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap());

if rustc.is_relative() {
println!("cargo:rerun-if-env-changed=PATH");
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
let absolute = dir.join(&exe(&rustc));
if absolute.exists() {
rustc = absolute;
break;
}
}
}
assert!(rustc.is_absolute());

// FIXME: if the path is not utf-8, this is going to break. Unfortunately
// Cargo doesn't have a way for us to specify non-utf-8 paths easily, so
// we'll need to invent some encoding scheme if this becomes a problem.
println!("cargo:rustc-env=RUSTC={}", rustc.to_str().unwrap());
}
5 changes: 2 additions & 3 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,13 +1557,12 @@ impl<'a> Builder<'a> {
match mode {
Mode::ToolBootstrap => {
// Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally.
// HACK: because anyhow does feature detection in build.rs, we need to allow the backtrace feature too.
rustflags.arg("-Zallow-features=binary-dep-depinfo,backtrace");
rustflags.arg("-Zallow-features=binary-dep-depinfo");
}
Mode::ToolStd => {
// Right now this is just compiletest and a few other tools that build on stable.
// Allow them to use `feature(test)`, but nothing else.
rustflags.arg("-Zallow-features=binary-dep-depinfo,test,backtrace,proc_macro_internals,proc_macro_diagnostic,proc_macro_span");
rustflags.arg("-Zallow-features=binary-dep-depinfo,test,proc_macro_internals,proc_macro_diagnostic,proc_macro_span");
}
Mode::Std | Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {}
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/consts/issue-88071.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// regression test for #88071

#![feature(const_btree_new)]

use std::collections::BTreeMap;

pub struct CustomMap<K, V>(BTreeMap<K, V>);
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/parser/issues/issue-101540.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct S1 {
struct S2 {
//~^ ERROR structs are not allowed in struct definitions
}
}

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/parser/issues/issue-101540.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: structs are not allowed in struct definitions
--> $DIR/issue-101540.rs:2:5
|
LL | struct S2 {
| ^^^^^^^^^
|
= help: consider creating a new `struct` definition instead of nesting

error: aborting due to previous error

13 changes: 12 additions & 1 deletion src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,21 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bo
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.

// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver` doesn't accept
// the `-dev` version number so we have to strip it off.
let short_version = since
.as_str()
.split('-')
.next()
.expect("rustc_attr::StabilityLevel::Stable::since` is empty");

let since = rustc_span::Symbol::intern(short_version);

crate::meets_msrv(
msrv,
RustcVersion::parse(since.as_str())
.expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
.unwrap_or_else(|err| panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")),
)
} else {
// Unstable const fn with the feature enabled.
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/tests/ui/crashes/ice-7126.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// This test requires a feature gated const fn and will stop working in the future.

#![feature(const_btree_new)]
#![feature(const_btree_len)]

use std::collections::BTreeMap;

struct Foo(BTreeMap<i32, i32>);
struct Foo(usize);
impl Foo {
fn new() -> Self {
Self(BTreeMap::new())
Self(BTreeMap::len(&BTreeMap::<u8, u8>::new()))
}
}

Expand Down

0 comments on commit 72f4923

Please sign in to comment.