Skip to content

Commit 092e4f4

Browse files
committed
Auto merge of rust-lang#113890 - matthiaskrgr:rollup-k1w2vii, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#110765 (rustdoc: fix position of `default` in method rendering) - rust-lang#113529 (Permit pre-evaluated constants in simd_shuffle) - rust-lang#113800 (Avoid another gha group nesting) - rust-lang#113827 (Add Foreign, Never, FnDef, Closure and Generator tys to SMIR) - rust-lang#113835 (new solver: don't consider blanket impls multiple times) - rust-lang#113883 (Remove outdated Firefox-specific CSS for search's crate selector appearance) - rust-lang#113884 (Don't translate compiler-internal bug messages) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 06a53dd + 464e02a commit 092e4f4

File tree

27 files changed

+619
-286
lines changed

27 files changed

+619
-286
lines changed

compiler/rustc_codegen_ssa/src/mir/constant.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6565
&self,
6666
constant: &mir::Constant<'tcx>,
6767
) -> Result<Option<ty::ValTree<'tcx>>, ErrorHandled> {
68-
let uv = match constant.literal {
68+
let uv = match self.monomorphize(constant.literal) {
6969
mir::ConstantKind::Unevaluated(uv, _) => uv.shrink(),
70+
mir::ConstantKind::Ty(c) => match c.kind() {
71+
// A constant that came from a const generic but was then used as an argument to old-style
72+
// simd_shuffle (passing as argument instead of as a generic param).
73+
rustc_type_ir::ConstKind::Value(valtree) => return Ok(Some(valtree)),
74+
other => span_bug!(constant.span, "{other:#?}"),
75+
},
76+
// We should never encounter `ConstantKind::Val` unless MIR opts (like const prop) evaluate
77+
// a constant and write that value back into `Operand`s. This could happen, but is unlikely.
78+
// Also: all users of `simd_shuffle` are on unstable and already need to take a lot of care
79+
// around intrinsics. For an issue to happen here, it would require a macro expanding to a
80+
// `simd_shuffle` call without wrapping the constant argument in a `const {}` block, but
81+
// the user pass through arbitrary expressions.
82+
// FIXME(oli-obk): replace the magic const generic argument of `simd_shuffle` with a real
83+
// const generic.
7084
other => span_bug!(constant.span, "{other:#?}"),
7185
};
7286
let uv = self.monomorphize(uv);

compiler/rustc_errors/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ impl Handler {
10031003
self.emit_diag_at_span(Diagnostic::new_with_code(Warning(None), Some(code), msg), span);
10041004
}
10051005

1006-
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
1006+
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<String>) -> ! {
10071007
self.inner.borrow_mut().span_bug(span, msg)
10081008
}
10091009

@@ -1012,7 +1012,7 @@ impl Handler {
10121012
pub fn delay_span_bug(
10131013
&self,
10141014
span: impl Into<MultiSpan>,
1015-
msg: impl Into<DiagnosticMessage>,
1015+
msg: impl Into<String>,
10161016
) -> ErrorGuaranteed {
10171017
self.inner.borrow_mut().delay_span_bug(span, msg)
10181018
}
@@ -1596,8 +1596,8 @@ impl HandlerInner {
15961596
}
15971597

15981598
#[track_caller]
1599-
fn span_bug(&mut self, sp: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
1600-
self.emit_diag_at_span(Diagnostic::new(Bug, msg), sp);
1599+
fn span_bug(&mut self, sp: impl Into<MultiSpan>, msg: impl Into<String>) -> ! {
1600+
self.emit_diag_at_span(Diagnostic::new(Bug, msg.into()), sp);
16011601
panic::panic_any(ExplicitBug);
16021602
}
16031603

@@ -1610,7 +1610,7 @@ impl HandlerInner {
16101610
fn delay_span_bug(
16111611
&mut self,
16121612
sp: impl Into<MultiSpan>,
1613-
msg: impl Into<DiagnosticMessage>,
1613+
msg: impl Into<String>,
16141614
) -> ErrorGuaranteed {
16151615
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
16161616
// incrementing `err_count` by one, so we need to +1 the comparing.
@@ -1619,9 +1619,9 @@ impl HandlerInner {
16191619
self.err_count() + self.lint_err_count + self.delayed_bug_count() + 1 >= c.get()
16201620
}) {
16211621
// FIXME: don't abort here if report_delayed_bugs is off
1622-
self.span_bug(sp, msg);
1622+
self.span_bug(sp, msg.into());
16231623
}
1624-
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
1624+
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg.into());
16251625
diagnostic.set_span(sp.into());
16261626
self.emit_diagnostic(&mut diagnostic).unwrap()
16271627
}

compiler/rustc_expand/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ impl<'a> ExtCtxt<'a> {
11471147
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
11481148
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
11491149
}
1150-
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! {
1150+
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<String>) -> ! {
11511151
self.sess.parse_sess.span_diagnostic.span_bug(sp, msg);
11521152
}
11531153
pub fn trace_macros_diag(&mut self) {

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,10 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
568568

569569
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for DisableAutoTraitVisitor<'tcx> {
570570
type BreakTy = ();
571-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
571+
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
572572
let tcx = self.tcx;
573-
if t != self.self_ty_root {
574-
for impl_def_id in tcx.non_blanket_impls_for_ty(self.trait_def_id, t) {
573+
if ty != self.self_ty_root {
574+
for impl_def_id in tcx.non_blanket_impls_for_ty(self.trait_def_id, ty) {
575575
match tcx.impl_polarity(impl_def_id) {
576576
ImplPolarity::Negative => return ControlFlow::Break(()),
577577
ImplPolarity::Reservation => {}
@@ -584,7 +584,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
584584
}
585585
}
586586

587-
match t.kind() {
587+
match ty.kind() {
588588
ty::Adt(def, args) if def.is_phantom_data() => args.visit_with(self),
589589
ty::Adt(def, args) => {
590590
// @lcnr: This is the only place where cycles can happen. We avoid this
@@ -599,7 +599,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
599599

600600
ControlFlow::Continue(())
601601
}
602-
_ => t.super_visit_with(self),
602+
_ => ty.super_visit_with(self),
603603
}
604604
}
605605
}

compiler/rustc_middle/src/ty/fast_reject.rs

+60-55
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,33 @@ use std::fmt::Debug;
66
use std::hash::Hash;
77
use std::iter;
88

9-
use self::SimplifiedType::*;
10-
119
/// See `simplify_type`.
1210
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
1311
pub enum SimplifiedType {
14-
BoolSimplifiedType,
15-
CharSimplifiedType,
16-
IntSimplifiedType(ty::IntTy),
17-
UintSimplifiedType(ty::UintTy),
18-
FloatSimplifiedType(ty::FloatTy),
19-
AdtSimplifiedType(DefId),
20-
ForeignSimplifiedType(DefId),
21-
StrSimplifiedType,
22-
ArraySimplifiedType,
23-
SliceSimplifiedType,
24-
RefSimplifiedType(Mutability),
25-
PtrSimplifiedType(Mutability),
26-
NeverSimplifiedType,
27-
TupleSimplifiedType(usize),
12+
Bool,
13+
Char,
14+
Int(ty::IntTy),
15+
Uint(ty::UintTy),
16+
Float(ty::FloatTy),
17+
Adt(DefId),
18+
Foreign(DefId),
19+
Str,
20+
Array,
21+
Slice,
22+
Ref(Mutability),
23+
Ptr(Mutability),
24+
Never,
25+
Tuple(usize),
2826
/// A trait object, all of whose components are markers
2927
/// (e.g., `dyn Send + Sync`).
30-
MarkerTraitObjectSimplifiedType,
31-
TraitSimplifiedType(DefId),
32-
ClosureSimplifiedType(DefId),
33-
GeneratorSimplifiedType(DefId),
34-
GeneratorWitnessSimplifiedType(usize),
35-
GeneratorWitnessMIRSimplifiedType(DefId),
36-
FunctionSimplifiedType(usize),
37-
PlaceholderSimplifiedType,
28+
MarkerTraitObject,
29+
Trait(DefId),
30+
Closure(DefId),
31+
Generator(DefId),
32+
GeneratorWitness(usize),
33+
GeneratorWitnessMIR(DefId),
34+
Function(usize),
35+
Placeholder,
3836
}
3937

4038
/// Generic parameters are pretty much just bound variables, e.g.
@@ -64,6 +62,9 @@ pub enum TreatParams {
6462
/// correct mode for *lookup*, as during candidate selection.
6563
///
6664
/// N.B. during deep rejection, this acts identically to `ForLookup`.
65+
///
66+
/// FIXME(-Ztrait-solver=next): Remove this variant and cleanup
67+
/// the code.
6768
NextSolverLookup,
6869
}
6970

@@ -110,34 +111,36 @@ pub fn simplify_type<'tcx>(
110111
treat_params: TreatParams,
111112
) -> Option<SimplifiedType> {
112113
match *ty.kind() {
113-
ty::Bool => Some(BoolSimplifiedType),
114-
ty::Char => Some(CharSimplifiedType),
115-
ty::Int(int_type) => Some(IntSimplifiedType(int_type)),
116-
ty::Uint(uint_type) => Some(UintSimplifiedType(uint_type)),
117-
ty::Float(float_type) => Some(FloatSimplifiedType(float_type)),
118-
ty::Adt(def, _) => Some(AdtSimplifiedType(def.did())),
119-
ty::Str => Some(StrSimplifiedType),
120-
ty::Array(..) => Some(ArraySimplifiedType),
121-
ty::Slice(..) => Some(SliceSimplifiedType),
122-
ty::RawPtr(ptr) => Some(PtrSimplifiedType(ptr.mutbl)),
114+
ty::Bool => Some(SimplifiedType::Bool),
115+
ty::Char => Some(SimplifiedType::Char),
116+
ty::Int(int_type) => Some(SimplifiedType::Int(int_type)),
117+
ty::Uint(uint_type) => Some(SimplifiedType::Uint(uint_type)),
118+
ty::Float(float_type) => Some(SimplifiedType::Float(float_type)),
119+
ty::Adt(def, _) => Some(SimplifiedType::Adt(def.did())),
120+
ty::Str => Some(SimplifiedType::Str),
121+
ty::Array(..) => Some(SimplifiedType::Array),
122+
ty::Slice(..) => Some(SimplifiedType::Slice),
123+
ty::RawPtr(ptr) => Some(SimplifiedType::Ptr(ptr.mutbl)),
123124
ty::Dynamic(trait_info, ..) => match trait_info.principal_def_id() {
124125
Some(principal_def_id) if !tcx.trait_is_auto(principal_def_id) => {
125-
Some(TraitSimplifiedType(principal_def_id))
126+
Some(SimplifiedType::Trait(principal_def_id))
126127
}
127-
_ => Some(MarkerTraitObjectSimplifiedType),
128+
_ => Some(SimplifiedType::MarkerTraitObject),
128129
},
129-
ty::Ref(_, _, mutbl) => Some(RefSimplifiedType(mutbl)),
130-
ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(ClosureSimplifiedType(def_id)),
131-
ty::Generator(def_id, _, _) => Some(GeneratorSimplifiedType(def_id)),
132-
ty::GeneratorWitness(tys) => Some(GeneratorWitnessSimplifiedType(tys.skip_binder().len())),
133-
ty::GeneratorWitnessMIR(def_id, _) => Some(GeneratorWitnessMIRSimplifiedType(def_id)),
134-
ty::Never => Some(NeverSimplifiedType),
135-
ty::Tuple(tys) => Some(TupleSimplifiedType(tys.len())),
136-
ty::FnPtr(f) => Some(FunctionSimplifiedType(f.skip_binder().inputs().len())),
137-
ty::Placeholder(..) => Some(PlaceholderSimplifiedType),
130+
ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)),
131+
ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id)),
132+
ty::Generator(def_id, _, _) => Some(SimplifiedType::Generator(def_id)),
133+
ty::GeneratorWitness(tys) => {
134+
Some(SimplifiedType::GeneratorWitness(tys.skip_binder().len()))
135+
}
136+
ty::GeneratorWitnessMIR(def_id, _) => Some(SimplifiedType::GeneratorWitnessMIR(def_id)),
137+
ty::Never => Some(SimplifiedType::Never),
138+
ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())),
139+
ty::FnPtr(f) => Some(SimplifiedType::Function(f.skip_binder().inputs().len())),
140+
ty::Placeholder(..) => Some(SimplifiedType::Placeholder),
138141
ty::Param(_) => match treat_params {
139142
TreatParams::ForLookup | TreatParams::NextSolverLookup => {
140-
Some(PlaceholderSimplifiedType)
143+
Some(SimplifiedType::Placeholder)
141144
}
142145
TreatParams::AsCandidateKey => None,
143146
},
@@ -147,24 +150,26 @@ pub fn simplify_type<'tcx>(
147150
//
148151
// We will have to be careful with lazy normalization here.
149152
// FIXME(lazy_normalization): This is probably not right...
150-
TreatParams::ForLookup if !ty.has_non_region_infer() => Some(PlaceholderSimplifiedType),
151-
TreatParams::NextSolverLookup => Some(PlaceholderSimplifiedType),
153+
TreatParams::ForLookup if !ty.has_non_region_infer() => {
154+
Some(SimplifiedType::Placeholder)
155+
}
156+
TreatParams::NextSolverLookup => Some(SimplifiedType::Placeholder),
152157
TreatParams::ForLookup | TreatParams::AsCandidateKey => None,
153158
},
154-
ty::Foreign(def_id) => Some(ForeignSimplifiedType(def_id)),
159+
ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)),
155160
ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
156161
}
157162
}
158163

159164
impl SimplifiedType {
160165
pub fn def(self) -> Option<DefId> {
161166
match self {
162-
AdtSimplifiedType(d)
163-
| ForeignSimplifiedType(d)
164-
| TraitSimplifiedType(d)
165-
| ClosureSimplifiedType(d)
166-
| GeneratorSimplifiedType(d)
167-
| GeneratorWitnessMIRSimplifiedType(d) => Some(d),
167+
SimplifiedType::Adt(d)
168+
| SimplifiedType::Foreign(d)
169+
| SimplifiedType::Trait(d)
170+
| SimplifiedType::Closure(d)
171+
| SimplifiedType::Generator(d)
172+
| SimplifiedType::GeneratorWitnessMIR(d) => Some(d),
168173
_ => None,
169174
}
170175
}

compiler/rustc_middle/src/ty/sty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use hir::def::DefKind;
1515
use polonius_engine::Atom;
1616
use rustc_data_structures::captures::Captures;
1717
use rustc_data_structures::intern::Interned;
18-
use rustc_error_messages::DiagnosticMessage;
1918
use rustc_errors::{DiagnosticArgValue, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan};
2019
use rustc_hir as hir;
2120
use rustc_hir::def_id::DefId;
@@ -1991,7 +1990,7 @@ impl<'tcx> Ty<'tcx> {
19911990
pub fn new_error_with_message<S: Into<MultiSpan>>(
19921991
tcx: TyCtxt<'tcx>,
19931992
span: S,
1994-
msg: impl Into<DiagnosticMessage>,
1993+
msg: impl Into<String>,
19951994
) -> Ty<'tcx> {
19961995
let reported = tcx.sess.delay_span_bug(span, msg);
19971996
Ty::new(tcx, Error(reported))

compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
247247
self.sess.span_diagnostic.struct_span_err(sp, m)
248248
}
249249

250-
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: impl Into<DiagnosticMessage>) -> ! {
250+
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: impl Into<String>) -> ! {
251251
self.sess.span_diagnostic.span_bug(sp, m)
252252
}
253253

compiler/rustc_parse/src/parser/pat.rs

+16-33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::errors::{
88
TrailingVertNotAllowed, UnexpectedLifetimeInPattern, UnexpectedVertVertBeforeFunctionParam,
99
UnexpectedVertVertInPattern,
1010
};
11-
use crate::fluent_generated as fluent;
1211
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
1312
use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
1413
use rustc_ast::ptr::P;
@@ -214,41 +213,25 @@ impl<'a> Parser<'a> {
214213

215214
if let PatKind::Or(pats) = &pat.kind {
216215
let span = pat.span;
217-
218-
if trailing_vert {
219-
// We already emitted an error and suggestion to remove the trailing vert. Don't
220-
// emit again.
221-
222-
// FIXME(#100717): pass `TopLevelOrPatternNotAllowed::* { sub: None }` to
223-
// `delay_span_bug()` instead of fluent message
224-
self.sess.span_diagnostic.delay_span_bug(
225-
span,
226-
match syntax_loc {
227-
PatternLocation::LetBinding => {
228-
fluent::parse_or_pattern_not_allowed_in_let_binding
229-
}
230-
PatternLocation::FunctionParameter => {
231-
fluent::parse_or_pattern_not_allowed_in_fn_parameters
232-
}
233-
},
234-
);
216+
let pat = pprust::pat_to_string(&pat);
217+
let sub = if pats.len() == 1 {
218+
Some(TopLevelOrPatternNotAllowedSugg::RemoveLeadingVert { span, pat })
235219
} else {
236-
let pat = pprust::pat_to_string(&pat);
237-
let sub = if pats.len() == 1 {
238-
Some(TopLevelOrPatternNotAllowedSugg::RemoveLeadingVert { span, pat })
239-
} else {
240-
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens { span, pat })
241-
};
220+
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens { span, pat })
221+
};
242222

243-
self.sess.emit_err(match syntax_loc {
244-
PatternLocation::LetBinding => {
245-
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
246-
}
247-
PatternLocation::FunctionParameter => {
248-
TopLevelOrPatternNotAllowed::FunctionParameter { span, sub }
249-
}
250-
});
223+
let mut err = self.sess.create_err(match syntax_loc {
224+
PatternLocation::LetBinding => {
225+
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
226+
}
227+
PatternLocation::FunctionParameter => {
228+
TopLevelOrPatternNotAllowed::FunctionParameter { span, sub }
229+
}
230+
});
231+
if trailing_vert {
232+
err.delay_as_bug();
251233
}
234+
err.emit();
252235
}
253236

254237
Ok((pat, colon))

compiler/rustc_session/src/session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ impl Session {
677677
pub fn delay_span_bug<S: Into<MultiSpan>>(
678678
&self,
679679
sp: S,
680-
msg: impl Into<DiagnosticMessage>,
680+
msg: impl Into<String>,
681681
) -> ErrorGuaranteed {
682682
self.diagnostic().delay_span_bug(sp, msg)
683683
}

0 commit comments

Comments
 (0)