Skip to content

Commit cd6e566

Browse files
committed
Auto merge of rust-lang#136658 - matthiaskrgr:rollup-tg1vmex, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#133925 (disallow `repr()` on invalid items) - rust-lang#136069 (Simplify slice indexing in next trait solver) - rust-lang#136152 (Stabilize `map_many_mut` feature) - rust-lang#136219 (Misc. `rustc_hir` cleanups 🧹) - rust-lang#136580 (Couple of changes to run rustc in miri) - rust-lang#136636 (Couple of minor cleanups to the diagnostic infrastructure) - rust-lang#136645 (Clippy subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 942db67 + b1be2d5 commit cd6e566

File tree

127 files changed

+2883
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+2883
-721
lines changed

compiler/rustc_data_structures/src/memmap.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::io;
33
use std::ops::{Deref, DerefMut};
44

55
/// A trivial wrapper for [`memmap2::Mmap`] (or `Vec<u8>` on WASM).
6-
#[cfg(not(target_arch = "wasm32"))]
6+
#[cfg(not(any(miri, target_arch = "wasm32")))]
77
pub struct Mmap(memmap2::Mmap);
88

9-
#[cfg(target_arch = "wasm32")]
9+
#[cfg(any(miri, target_arch = "wasm32"))]
1010
pub struct Mmap(Vec<u8>);
1111

12-
#[cfg(not(target_arch = "wasm32"))]
12+
#[cfg(not(any(miri, target_arch = "wasm32")))]
1313
impl Mmap {
1414
/// # Safety
1515
///
@@ -29,7 +29,7 @@ impl Mmap {
2929
}
3030
}
3131

32-
#[cfg(target_arch = "wasm32")]
32+
#[cfg(any(miri, target_arch = "wasm32"))]
3333
impl Mmap {
3434
#[inline]
3535
pub unsafe fn map(mut file: File) -> io::Result<Self> {
@@ -56,13 +56,13 @@ impl AsRef<[u8]> for Mmap {
5656
}
5757
}
5858

59-
#[cfg(not(target_arch = "wasm32"))]
59+
#[cfg(not(any(miri, target_arch = "wasm32")))]
6060
pub struct MmapMut(memmap2::MmapMut);
6161

62-
#[cfg(target_arch = "wasm32")]
62+
#[cfg(any(miri, target_arch = "wasm32"))]
6363
pub struct MmapMut(Vec<u8>);
6464

65-
#[cfg(not(target_arch = "wasm32"))]
65+
#[cfg(not(any(miri, target_arch = "wasm32")))]
6666
impl MmapMut {
6767
#[inline]
6868
pub fn map_anon(len: usize) -> io::Result<Self> {
@@ -82,7 +82,7 @@ impl MmapMut {
8282
}
8383
}
8484

85-
#[cfg(target_arch = "wasm32")]
85+
#[cfg(any(miri, target_arch = "wasm32"))]
8686
impl MmapMut {
8787
#[inline]
8888
pub fn map_anon(len: usize) -> io::Result<Self> {

compiler/rustc_data_structures/src/stack.rs

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ const STACK_PER_RECURSION: usize = 16 * 1024 * 1024; // 16MB
1717
///
1818
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
1919
#[inline]
20+
#[cfg(not(miri))]
2021
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
2122
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
2223
}
24+
25+
/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations
26+
/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit
27+
/// from this.
28+
///
29+
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
30+
#[cfg(miri)]
31+
#[inline]
32+
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
33+
f()
34+
}

compiler/rustc_driver_impl/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ pub mod pretty;
8989
#[macro_use]
9090
mod print;
9191
mod session_diagnostics;
92-
#[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))]
92+
#[cfg(all(not(miri), unix, any(target_env = "gnu", target_os = "macos")))]
9393
mod signal_handler;
9494

95-
#[cfg(not(all(unix, any(target_env = "gnu", target_os = "macos"))))]
95+
#[cfg(not(all(not(miri), unix, any(target_env = "gnu", target_os = "macos"))))]
9696
mod signal_handler {
9797
/// On platforms which don't support our signal handler's requirements,
9898
/// simply use the default signal handler provided by std.
@@ -1024,7 +1024,7 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
10241024
let wall = matches.opt_strs("W");
10251025
if wall.iter().any(|x| *x == "all") {
10261026
print_wall_help();
1027-
rustc_errors::FatalError.raise();
1027+
return true;
10281028
}
10291029

10301030
// Don't handle -W help here, because we might first load additional lints.
@@ -1474,7 +1474,7 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
14741474
/// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
14751475
/// Making this handler optional lets tools can install a different handler, if they wish.
14761476
pub fn install_ctrlc_handler() {
1477-
#[cfg(not(target_family = "wasm"))]
1477+
#[cfg(all(not(miri), not(target_family = "wasm")))]
14781478
ctrlc::set_handler(move || {
14791479
// Indicate that we have been signaled to stop, then give the rest of the compiler a bit of
14801480
// time to check CTRL_C_RECEIVED and run its own shutdown logic, but after a short amount

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ impl HumanEmitter {
17651765

17661766
let column_width = if let Some(width) = self.diagnostic_width {
17671767
width.saturating_sub(code_offset)
1768-
} else if self.ui_testing {
1768+
} else if self.ui_testing || cfg!(miri) {
17691769
DEFAULT_COLUMN_WIDTH
17701770
} else {
17711771
termize::dimensions()

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ impl<'a> DiagCtxtHandle<'a> {
10481048
/// bad results, such as spurious/uninteresting additional errors -- when
10491049
/// returning an error `Result` is difficult.
10501050
pub fn abort_if_errors(&self) {
1051-
if self.has_errors().is_some() {
1052-
FatalError.raise();
1051+
if let Some(guar) = self.has_errors() {
1052+
guar.raise_fatal();
10531053
}
10541054
}
10551055

compiler/rustc_hir/src/hir.rs

+36-56
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub type UsePath<'hir> = Path<'hir, SmallVec<[Res; 3]>>;
206206

207207
impl Path<'_> {
208208
pub fn is_global(&self) -> bool {
209-
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
209+
self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
210210
}
211211
}
212212

@@ -1061,10 +1061,7 @@ impl Attribute {
10611061

10621062
pub fn value_lit(&self) -> Option<&MetaItemLit> {
10631063
match &self.kind {
1064-
AttrKind::Normal(n) => match n.as_ref() {
1065-
AttrItem { args: AttrArgs::Eq { expr, .. }, .. } => Some(expr),
1066-
_ => None,
1067-
},
1064+
AttrKind::Normal(box AttrItem { args: AttrArgs::Eq { expr, .. }, .. }) => Some(expr),
10681065
_ => None,
10691066
}
10701067
}
@@ -1077,12 +1074,9 @@ impl AttributeExt for Attribute {
10771074

10781075
fn meta_item_list(&self) -> Option<ThinVec<ast::MetaItemInner>> {
10791076
match &self.kind {
1080-
AttrKind::Normal(n) => match n.as_ref() {
1081-
AttrItem { args: AttrArgs::Delimited(d), .. } => {
1082-
ast::MetaItemKind::list_from_tokens(d.tokens.clone())
1083-
}
1084-
_ => None,
1085-
},
1077+
AttrKind::Normal(box AttrItem { args: AttrArgs::Delimited(d), .. }) => {
1078+
ast::MetaItemKind::list_from_tokens(d.tokens.clone())
1079+
}
10861080
_ => None,
10871081
}
10881082
}
@@ -1098,23 +1092,16 @@ impl AttributeExt for Attribute {
10981092
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
10991093
fn ident(&self) -> Option<Ident> {
11001094
match &self.kind {
1101-
AttrKind::Normal(n) => {
1102-
if let [ident] = n.path.segments.as_ref() {
1103-
Some(*ident)
1104-
} else {
1105-
None
1106-
}
1107-
}
1108-
AttrKind::DocComment(..) => None,
1095+
AttrKind::Normal(box AttrItem {
1096+
path: AttrPath { segments: box [ident], .. }, ..
1097+
}) => Some(*ident),
1098+
_ => None,
11091099
}
11101100
}
11111101

11121102
fn path_matches(&self, name: &[Symbol]) -> bool {
11131103
match &self.kind {
1114-
AttrKind::Normal(n) => {
1115-
n.path.segments.len() == name.len()
1116-
&& n.path.segments.iter().zip(name).all(|(s, n)| s.name == *n)
1117-
}
1104+
AttrKind::Normal(n) => n.path.segments.iter().map(|segment| &segment.name).eq(name),
11181105
AttrKind::DocComment(..) => false,
11191106
}
11201107
}
@@ -1128,12 +1115,7 @@ impl AttributeExt for Attribute {
11281115
}
11291116

11301117
fn is_word(&self) -> bool {
1131-
match &self.kind {
1132-
AttrKind::Normal(n) => {
1133-
matches!(n.args, AttrArgs::Empty)
1134-
}
1135-
AttrKind::DocComment(..) => false,
1136-
}
1118+
matches!(self.kind, AttrKind::Normal(box AttrItem { args: AttrArgs::Empty, .. }))
11371119
}
11381120

11391121
fn ident_path(&self) -> Option<SmallVec<[Ident; 1]>> {
@@ -1990,7 +1972,7 @@ impl fmt::Display for ConstContext {
19901972
}
19911973

19921974
// NOTE: `IntoDiagArg` impl for `ConstContext` lives in `rustc_errors`
1993-
// due to a cyclical dependency between hir that crate.
1975+
// due to a cyclical dependency between hir and that crate.
19941976

19951977
/// A literal.
19961978
pub type Lit = Spanned<LitKind>;
@@ -3604,10 +3586,10 @@ impl<'hir> FnRetTy<'hir> {
36043586
}
36053587

36063588
pub fn is_suggestable_infer_ty(&self) -> Option<&'hir Ty<'hir>> {
3607-
if let Self::Return(ty) = self {
3608-
if ty.is_suggestable_infer_ty() {
3609-
return Some(*ty);
3610-
}
3589+
if let Self::Return(ty) = self
3590+
&& ty.is_suggestable_infer_ty()
3591+
{
3592+
return Some(*ty);
36113593
}
36123594
None
36133595
}
@@ -3976,11 +3958,11 @@ pub struct FnHeader {
39763958

39773959
impl FnHeader {
39783960
pub fn is_async(&self) -> bool {
3979-
matches!(&self.asyncness, IsAsync::Async(_))
3961+
matches!(self.asyncness, IsAsync::Async(_))
39803962
}
39813963

39823964
pub fn is_const(&self) -> bool {
3983-
matches!(&self.constness, Constness::Const)
3965+
matches!(self.constness, Constness::Const)
39843966
}
39853967

39863968
pub fn is_unsafe(&self) -> bool {
@@ -4076,16 +4058,16 @@ pub struct Impl<'hir> {
40764058

40774059
impl ItemKind<'_> {
40784060
pub fn generics(&self) -> Option<&Generics<'_>> {
4079-
Some(match *self {
4080-
ItemKind::Fn { ref generics, .. }
4081-
| ItemKind::TyAlias(_, ref generics)
4082-
| ItemKind::Const(_, ref generics, _)
4083-
| ItemKind::Enum(_, ref generics)
4084-
| ItemKind::Struct(_, ref generics)
4085-
| ItemKind::Union(_, ref generics)
4086-
| ItemKind::Trait(_, _, ref generics, _, _)
4087-
| ItemKind::TraitAlias(ref generics, _)
4088-
| ItemKind::Impl(Impl { ref generics, .. }) => generics,
4061+
Some(match self {
4062+
ItemKind::Fn { generics, .. }
4063+
| ItemKind::TyAlias(_, generics)
4064+
| ItemKind::Const(_, generics, _)
4065+
| ItemKind::Enum(_, generics)
4066+
| ItemKind::Struct(_, generics)
4067+
| ItemKind::Union(_, generics)
4068+
| ItemKind::Trait(_, _, generics, _, _)
4069+
| ItemKind::TraitAlias(generics, _)
4070+
| ItemKind::Impl(Impl { generics, .. }) => generics,
40894071
_ => return None,
40904072
})
40914073
}
@@ -4484,16 +4466,14 @@ impl<'hir> Node<'hir> {
44844466

44854467
/// Get a `hir::Impl` if the node is an impl block for the given `trait_def_id`.
44864468
pub fn impl_block_of_trait(self, trait_def_id: DefId) -> Option<&'hir Impl<'hir>> {
4487-
match self {
4488-
Node::Item(Item { kind: ItemKind::Impl(impl_block), .. })
4489-
if impl_block
4490-
.of_trait
4491-
.and_then(|trait_ref| trait_ref.trait_def_id())
4492-
.is_some_and(|trait_id| trait_id == trait_def_id) =>
4493-
{
4494-
Some(impl_block)
4495-
}
4496-
_ => None,
4469+
if let Node::Item(Item { kind: ItemKind::Impl(impl_block), .. }) = self
4470+
&& let Some(trait_ref) = impl_block.of_trait
4471+
&& let Some(trait_id) = trait_ref.trait_def_id()
4472+
&& trait_id == trait_def_id
4473+
{
4474+
Some(impl_block)
4475+
} else {
4476+
None
44974477
}
44984478
}
44994479

compiler/rustc_hir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// tidy-alphabetical-start
66
#![allow(internal_features)]
77
#![feature(associated_type_defaults)]
8+
#![feature(box_patterns)]
89
#![feature(closure_track_caller)]
910
#![feature(debug_closure_helpers)]
1011
#![feature(exhaustive_patterns)]

compiler/rustc_interface/src/interface.rs

-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
442442
locale_resources.push(codegen_backend.locale_resource());
443443

444444
let mut sess = rustc_session::build_session(
445-
early_dcx,
446445
config.opts,
447446
CompilerIO {
448447
input: config.input,

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ where
6565
static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
6666

6767
let sess = build_session(
68-
early_dcx,
6968
sessopts,
7069
io,
7170
None,

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,11 @@ where
453453
{
454454
// In case any fresh inference variables have been created between `state`
455455
// and the previous instantiation, extend `orig_values` for it.
456-
assert!(orig_values.len() <= state.value.var_values.len());
457-
for &arg in &state.value.var_values.var_values.as_slice()
458-
[orig_values.len()..state.value.var_values.len()]
459-
{
460-
let unconstrained = delegate.fresh_var_for_kind_with_span(arg, span);
461-
orig_values.push(unconstrained);
462-
}
456+
orig_values.extend(
457+
state.value.var_values.var_values.as_slice()[orig_values.len()..]
458+
.iter()
459+
.map(|&arg| delegate.fresh_var_for_kind_with_span(arg, span)),
460+
);
463461

464462
let instantiation =
465463
EvalCtxt::compute_query_response_instantiation_values(delegate, orig_values, &state, span);

compiler/rustc_parse/src/parser/tests.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::parser::{ForceCollect, Parser};
2626
use crate::{new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
2727

2828
fn psess() -> ParseSess {
29-
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, crate::DEFAULT_LOCALE_RESOURCE])
29+
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE])
3030
}
3131

3232
/// Map string to parser (via tts).
@@ -41,10 +41,8 @@ fn string_to_parser(psess: &ParseSess, source_str: String) -> Parser<'_> {
4141
fn create_test_handler(theme: OutputTheme) -> (DiagCtxt, Arc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
4242
let output = Arc::new(Mutex::new(Vec::new()));
4343
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
44-
let fallback_bundle = rustc_errors::fallback_fluent_bundle(
45-
vec![crate::DEFAULT_LOCALE_RESOURCE, crate::DEFAULT_LOCALE_RESOURCE],
46-
false,
47-
);
44+
let fallback_bundle =
45+
rustc_errors::fallback_fluent_bundle(vec![crate::DEFAULT_LOCALE_RESOURCE], false);
4846
let mut emitter = HumanEmitter::new(Box::new(Shared { data: output.clone() }), fallback_bundle)
4947
.sm(Some(source_map.clone()))
5048
.diagnostic_width(Some(140));

0 commit comments

Comments
 (0)