Skip to content

Commit e5038e2

Browse files
committed
Auto merge of #91455 - matthiaskrgr:rollup-gix2hy6, r=matthiaskrgr
Rollup of 4 iffy pull requests Successful merges: - #89234 (Disallow non-c-like but "fieldless" ADTs from being casted to integer if they use arbitrary enum discriminant) - #91045 (Issue 90702 fix: Stop treating some crate loading failures as fatal errors) - #91394 (Bump stage0 compiler) - #91411 (Enable svh tests on msvc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 18bb8c6 + 822a058 commit e5038e2

File tree

69 files changed

+713
-599
lines changed

Some content is hidden

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

69 files changed

+713
-599
lines changed

compiler/rustc_attr/src/builtin.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,10 @@ pub fn eval_condition(
519519
[NestedMetaItem::Literal(Lit { kind: LitKind::Str(sym, ..), span, .. })] => {
520520
(sym, span)
521521
}
522-
[NestedMetaItem::Literal(Lit { span, .. })
523-
| NestedMetaItem::MetaItem(MetaItem { span, .. })] => {
522+
[
523+
NestedMetaItem::Literal(Lit { span, .. })
524+
| NestedMetaItem::MetaItem(MetaItem { span, .. }),
525+
] => {
524526
sess.span_diagnostic
525527
.struct_span_err(*span, "expected a version literal")
526528
.emit();

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
977977
Some(ref name),
978978
BorrowExplanation::MustBeValidFor {
979979
category:
980-
category
981-
@
982-
(ConstraintCategory::Return(_)
980+
category @ (ConstraintCategory::Return(_)
983981
| ConstraintCategory::CallArgument
984982
| ConstraintCategory::OpaqueType),
985983
from_closure: false,

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
165165
PlaceRef {
166166
local: _,
167167
projection:
168-
[.., ProjectionElem::Index(_)
169-
| ProjectionElem::ConstantIndex { .. }
170-
| ProjectionElem::Subslice { .. }
171-
| ProjectionElem::Downcast(..)],
168+
[
169+
..,
170+
ProjectionElem::Index(_)
171+
| ProjectionElem::ConstantIndex { .. }
172+
| ProjectionElem::Subslice { .. }
173+
| ProjectionElem::Downcast(..),
174+
],
172175
} => bug!("Unexpected immutable place."),
173176
}
174177

@@ -217,7 +220,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
217220
PlaceRef {
218221
local,
219222
projection:
220-
[proj_base @ .., ProjectionElem::Deref, ProjectionElem::Field(field, _), ProjectionElem::Deref],
223+
[
224+
proj_base @ ..,
225+
ProjectionElem::Deref,
226+
ProjectionElem::Field(field, _),
227+
ProjectionElem::Deref,
228+
],
221229
} => {
222230
err.span_label(span, format!("cannot {ACT}", ACT = act));
223231

@@ -763,11 +771,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
763771
kind:
764772
Call(
765773
_,
766-
[Expr {
767-
kind: MethodCall(path_segment, ..),
768-
hir_id,
769-
..
770-
}, ..],
774+
[
775+
Expr {
776+
kind: MethodCall(path_segment, ..),
777+
hir_id,
778+
..
779+
},
780+
..,
781+
],
771782
),
772783
..
773784
},

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -769,20 +769,24 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
769769
let opaque_ty = hir.item(id);
770770
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
771771
bounds:
772-
[hir::GenericBound::LangItemTrait(
773-
hir::LangItem::Future,
774-
_,
775-
_,
776-
hir::GenericArgs {
777-
bindings:
778-
[hir::TypeBinding {
779-
ident: Ident { name: sym::Output, .. },
780-
kind: hir::TypeBindingKind::Equality { ty },
781-
..
782-
}],
783-
..
784-
},
785-
)],
772+
[
773+
hir::GenericBound::LangItemTrait(
774+
hir::LangItem::Future,
775+
_,
776+
_,
777+
hir::GenericArgs {
778+
bindings:
779+
[
780+
hir::TypeBinding {
781+
ident: Ident { name: sym::Output, .. },
782+
kind: hir::TypeBindingKind::Equality { ty },
783+
..
784+
},
785+
],
786+
..
787+
},
788+
),
789+
],
786790
..
787791
}) = opaque_ty.kind
788792
{

compiler/rustc_borrowck/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![feature(bool_to_option)]
44
#![feature(box_patterns)]
55
#![feature(crate_visibility_modifier)]
6-
#![cfg_attr(bootstrap, feature(format_args_capture))]
76
#![feature(in_band_lifetimes)]
87
#![feature(iter_zip)]
98
#![feature(let_else)]

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1525,14 +1525,12 @@ fn generator_layout_and_saved_local_names(
15251525
// Deref of the `Pin<&mut Self>` state argument.
15261526
mir::ProjectionElem::Field(..),
15271527
mir::ProjectionElem::Deref,
1528-
15291528
// Field of a variant of the state.
15301529
mir::ProjectionElem::Downcast(_, variant),
15311530
mir::ProjectionElem::Field(field, _),
15321531
] => {
1533-
let name = &mut generator_saved_local_names[
1534-
generator_layout.variant_fields[variant][field]
1535-
];
1532+
let name = &mut generator_saved_local_names
1533+
[generator_layout.variant_fields[variant][field]];
15361534
if name.is_none() {
15371535
name.replace(var.name);
15381536
}

compiler/rustc_errors/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(crate_visibility_modifier)]
77
#![feature(backtrace)]
88
#![feature(if_let_guard)]
9-
#![cfg_attr(bootstrap, feature(format_args_capture))]
109
#![feature(iter_zip)]
1110
#![feature(let_else)]
1211
#![feature(nll)]

compiler/rustc_expand/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(crate_visibility_modifier)]
22
#![feature(decl_macro)]
33
#![feature(destructuring_assignment)]
4-
#![cfg_attr(bootstrap, feature(format_args_capture))]
54
#![feature(if_let_guard)]
65
#![feature(iter_zip)]
76
#![feature(let_else)]

compiler/rustc_expand/src/mbe/macro_parser.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,7 @@ fn inner_parse_loop<'root, 'tt>(
584584
//
585585
// At the beginning of the loop, if we reach the end of the delimited submatcher,
586586
// we pop the stack to backtrack out of the descent.
587-
seq
588-
@
589-
(TokenTree::Delimited(..)
587+
seq @ (TokenTree::Delimited(..)
590588
| TokenTree::Token(Token { kind: DocComment(..), .. })) => {
591589
let lower_elts = mem::replace(&mut item.top_elts, Tt(seq));
592590
let idx = item.idx;

compiler/rustc_expand/src/parse/tests.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,33 @@ fn string_to_tts_macro() {
6565
let tts: &[TokenTree] = &tts[..];
6666

6767
match tts {
68-
[TokenTree::Token(Token { kind: token::Ident(name_macro_rules, false), .. }), TokenTree::Token(Token { kind: token::Not, .. }), TokenTree::Token(Token { kind: token::Ident(name_zip, false), .. }), TokenTree::Delimited(_, macro_delim, macro_tts)]
69-
if name_macro_rules == &kw::MacroRules && name_zip.as_str() == "zip" =>
70-
{
68+
[
69+
TokenTree::Token(Token { kind: token::Ident(name_macro_rules, false), .. }),
70+
TokenTree::Token(Token { kind: token::Not, .. }),
71+
TokenTree::Token(Token { kind: token::Ident(name_zip, false), .. }),
72+
TokenTree::Delimited(_, macro_delim, macro_tts),
73+
] if name_macro_rules == &kw::MacroRules && name_zip.as_str() == "zip" => {
7174
let tts = &macro_tts.trees().collect::<Vec<_>>();
7275
match &tts[..] {
73-
[TokenTree::Delimited(_, first_delim, first_tts), TokenTree::Token(Token { kind: token::FatArrow, .. }), TokenTree::Delimited(_, second_delim, second_tts)]
74-
if macro_delim == &token::Paren =>
75-
{
76+
[
77+
TokenTree::Delimited(_, first_delim, first_tts),
78+
TokenTree::Token(Token { kind: token::FatArrow, .. }),
79+
TokenTree::Delimited(_, second_delim, second_tts),
80+
] if macro_delim == &token::Paren => {
7681
let tts = &first_tts.trees().collect::<Vec<_>>();
7782
match &tts[..] {
78-
[TokenTree::Token(Token { kind: token::Dollar, .. }), TokenTree::Token(Token { kind: token::Ident(name, false), .. })]
79-
if first_delim == &token::Paren && name.as_str() == "a" => {}
83+
[
84+
TokenTree::Token(Token { kind: token::Dollar, .. }),
85+
TokenTree::Token(Token { kind: token::Ident(name, false), .. }),
86+
] if first_delim == &token::Paren && name.as_str() == "a" => {}
8087
_ => panic!("value 3: {:?} {:?}", first_delim, first_tts),
8188
}
8289
let tts = &second_tts.trees().collect::<Vec<_>>();
8390
match &tts[..] {
84-
[TokenTree::Token(Token { kind: token::Dollar, .. }), TokenTree::Token(Token { kind: token::Ident(name, false), .. })]
85-
if second_delim == &token::Paren && name.as_str() == "a" => {}
91+
[
92+
TokenTree::Token(Token { kind: token::Dollar, .. }),
93+
TokenTree::Token(Token { kind: token::Ident(name, false), .. }),
94+
] if second_delim == &token::Paren && name.as_str() == "a" => {}
8695
_ => panic!("value 4: {:?} {:?}", second_delim, second_tts),
8796
}
8897
}

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#![feature(bool_to_option)]
3131
#![feature(box_patterns)]
3232
#![feature(crate_visibility_modifier)]
33-
#![cfg_attr(bootstrap, feature(format_args_capture))]
3433
#![feature(iter_order_by)]
3534
#![feature(iter_zip)]
3635
#![feature(let_else)]

compiler/rustc_metadata/src/creader.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,17 @@ impl<'a> CrateLoader<'a> {
512512
name: Symbol,
513513
span: Span,
514514
dep_kind: CrateDepKind,
515-
) -> CrateNum {
515+
) -> Option<CrateNum> {
516516
self.used_extern_options.insert(name);
517-
self.maybe_resolve_crate(name, dep_kind, None).unwrap_or_else(|err| {
518-
let missing_core =
519-
self.maybe_resolve_crate(sym::core, CrateDepKind::Explicit, None).is_err();
520-
err.report(&self.sess, span, missing_core)
521-
})
517+
match self.maybe_resolve_crate(name, dep_kind, None) {
518+
Ok(cnum) => Some(cnum),
519+
Err(err) => {
520+
let missing_core =
521+
self.maybe_resolve_crate(sym::core, CrateDepKind::Explicit, None).is_err();
522+
err.report(&self.sess, span, missing_core);
523+
None
524+
}
525+
}
522526
}
523527

524528
fn maybe_resolve_crate<'b>(
@@ -751,7 +755,7 @@ impl<'a> CrateLoader<'a> {
751755
};
752756
info!("panic runtime not found -- loading {}", name);
753757

754-
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit);
758+
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
755759
let data = self.cstore.get_crate_data(cnum);
756760

757761
// Sanity check the loaded crate to ensure it is indeed a panic runtime
@@ -791,7 +795,7 @@ impl<'a> CrateLoader<'a> {
791795
);
792796
}
793797

794-
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit);
798+
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
795799
let data = self.cstore.get_crate_data(cnum);
796800

797801
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
@@ -991,7 +995,7 @@ impl<'a> CrateLoader<'a> {
991995
item: &ast::Item,
992996
definitions: &Definitions,
993997
def_id: LocalDefId,
994-
) -> CrateNum {
998+
) -> Option<CrateNum> {
995999
match item.kind {
9961000
ast::ItemKind::ExternCrate(orig_name) => {
9971001
debug!(
@@ -1011,7 +1015,7 @@ impl<'a> CrateLoader<'a> {
10111015
CrateDepKind::Explicit
10121016
};
10131017

1014-
let cnum = self.resolve_crate(name, item.span, dep_kind);
1018+
let cnum = self.resolve_crate(name, item.span, dep_kind)?;
10151019

10161020
let path_len = definitions.def_path(def_id).data.len();
10171021
self.update_extern_crate(
@@ -1023,14 +1027,14 @@ impl<'a> CrateLoader<'a> {
10231027
dependency_of: LOCAL_CRATE,
10241028
},
10251029
);
1026-
cnum
1030+
Some(cnum)
10271031
}
10281032
_ => bug!(),
10291033
}
10301034
}
10311035

1032-
pub fn process_path_extern(&mut self, name: Symbol, span: Span) -> CrateNum {
1033-
let cnum = self.resolve_crate(name, span, CrateDepKind::Explicit);
1036+
pub fn process_path_extern(&mut self, name: Symbol, span: Span) -> Option<CrateNum> {
1037+
let cnum = self.resolve_crate(name, span, CrateDepKind::Explicit)?;
10341038

10351039
self.update_extern_crate(
10361040
cnum,
@@ -1043,7 +1047,7 @@ impl<'a> CrateLoader<'a> {
10431047
},
10441048
);
10451049

1046-
cnum
1050+
Some(cnum)
10471051
}
10481052

10491053
pub fn maybe_process_path_extern(&mut self, name: Symbol) -> Option<CrateNum> {

compiler/rustc_metadata/src/locator.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ use rustc_data_structures::memmap::Mmap;
220220
use rustc_data_structures::owning_ref::OwningRef;
221221
use rustc_data_structures::svh::Svh;
222222
use rustc_data_structures::sync::MetadataRef;
223-
use rustc_errors::struct_span_err;
223+
use rustc_errors::{struct_span_err, FatalError};
224224
use rustc_session::config::{self, CrateType};
225225
use rustc_session::cstore::{CrateSource, MetadataLoader};
226226
use rustc_session::filesearch::{FileDoesntMatch, FileMatches, FileSearch};
@@ -814,11 +814,11 @@ pub fn find_plugin_registrar(
814814
span: Span,
815815
name: Symbol,
816816
) -> PathBuf {
817-
match find_plugin_registrar_impl(sess, metadata_loader, name) {
818-
Ok(res) => res,
817+
find_plugin_registrar_impl(sess, metadata_loader, name).unwrap_or_else(|err| {
819818
// `core` is always available if we got as far as loading plugins.
820-
Err(err) => err.report(sess, span, false),
821-
}
819+
err.report(sess, span, false);
820+
FatalError.raise()
821+
})
822822
}
823823

824824
fn find_plugin_registrar_impl<'a>(
@@ -931,8 +931,8 @@ impl fmt::Display for MetadataError<'_> {
931931
}
932932

933933
impl CrateError {
934-
crate fn report(self, sess: &Session, span: Span, missing_core: bool) -> ! {
935-
let mut err = match self {
934+
crate fn report(self, sess: &Session, span: Span, missing_core: bool) {
935+
let mut diag = match self {
936936
CrateError::NonAsciiName(crate_name) => sess.struct_span_err(
937937
span,
938938
&format!("cannot load a crate with a non-ascii name `{}`", crate_name),
@@ -1210,8 +1210,6 @@ impl CrateError {
12101210
),
12111211
};
12121212

1213-
err.emit();
1214-
sess.abort_if_errors();
1215-
unreachable!();
1213+
diag.emit();
12161214
}
12171215
}

compiler/rustc_middle/src/ty/adt.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
88
use rustc_errors::ErrorReported;
99
use rustc_hir as hir;
10-
use rustc_hir::def::{DefKind, Res};
10+
use rustc_hir::def::{CtorKind, DefKind, Res};
1111
use rustc_hir::def_id::DefId;
1212
use rustc_index::vec::{Idx, IndexVec};
1313
use rustc_query_system::ich::StableHashingContext;
@@ -314,6 +314,22 @@ impl<'tcx> AdtDef {
314314
/// Whether the ADT lacks fields. Note that this includes uninhabited enums,
315315
/// e.g., `enum Void {}` is considered payload free as well.
316316
pub fn is_payloadfree(&self) -> bool {
317+
// Treat the ADT as not payload-free if arbitrary_enum_discriminant is used (#88621).
318+
// This would disallow the following kind of enum from being casted into integer.
319+
// ```
320+
// enum Enum {
321+
// Foo() = 1,
322+
// Bar{} = 2,
323+
// Baz = 3,
324+
// }
325+
// ```
326+
if self
327+
.variants
328+
.iter()
329+
.any(|v| matches!(v.discr, VariantDiscr::Explicit(_)) && v.ctor_kind != CtorKind::Const)
330+
{
331+
return false;
332+
}
317333
self.variants.iter().all(|v| v.fields.is_empty())
318334
}
319335

compiler/rustc_middle/src/ty/context.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,11 @@ impl<'tcx> TyCtxt<'tcx> {
11111111
};
11121112
debug!("layout_scalar_valid_range: attr={:?}", attr);
11131113
if let Some(
1114-
&[ast::NestedMetaItem::Literal(ast::Lit { kind: ast::LitKind::Int(a, _), .. })],
1114+
&[
1115+
ast::NestedMetaItem::Literal(ast::Lit {
1116+
kind: ast::LitKind::Int(a, _), ..
1117+
}),
1118+
],
11151119
) = attr.meta_item_list().as_deref()
11161120
{
11171121
Bound::Included(a)

0 commit comments

Comments
 (0)