Skip to content

Commit 1d447a9

Browse files
committed
Auto merge of #121383 - Dylan-DPC:rollup-735p4u4, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #121208 (Convert `delayed_bug`s to `bug`s.) - #121288 (make rustc_expand translatable) - #121304 (Add docs for extension proc-macro) - #121328 (Make --verbose imply -Z write-long-types-to-disk=no) - #121338 (Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect) - #121361 (diagnostic items for legacy numeric modules) - #121375 (Print proper relative path for descriptive name check) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bb8b11e + 229108a commit 1d447a9

File tree

55 files changed

+292
-174
lines changed

Some content is hidden

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

55 files changed

+292
-174
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1636,9 +1636,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16361636
if let Some(old_def_id) = self.orig_opt_local_def_id(param) {
16371637
old_def_id
16381638
} else {
1639-
self.dcx()
1640-
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1641-
continue;
1639+
self.dcx().span_bug(lifetime.ident.span, "no def-id for fresh lifetime");
16421640
}
16431641
}
16441642

Diff for: compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
626626
| GenericArgKind::Const(_),
627627
_,
628628
) => {
629-
// HIR lowering sometimes doesn't catch this in erroneous
630-
// programs, so we need to use span_delayed_bug here. See #82126.
631-
self.dcx().span_delayed_bug(
629+
// This was previously a `span_delayed_bug` and could be
630+
// reached by the test for #82126, but no longer.
631+
self.dcx().span_bug(
632632
hir_arg.span(),
633633
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
634634
);

Diff for: compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+3
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
316316
.and(type_op::normalize::Normalize::new(ty))
317317
.fully_perform(self.infcx, span)
318318
else {
319+
// Note: this path is currently not reached in any test, so
320+
// any example that triggers this would be worth minimizing
321+
// and converting into a test.
319322
tcx.dcx().span_delayed_bug(span, format!("failed to normalize {ty:?}"));
320323
continue;
321324
};

Diff for: compiler/rustc_borrowck/src/type_check/input_output.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
154154
if argument_index + 1 >= body.local_decls.len() {
155155
self.tcx()
156156
.dcx()
157-
.span_delayed_bug(body.span, "found more normalized_input_ty than local_decls");
158-
break;
157+
.span_bug(body.span, "found more normalized_input_ty than local_decls");
159158
}
160159

161160
// In MIR, argument N is stored in local N+1.

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,13 @@ pub(crate) fn type_check<'mir, 'tcx>(
220220
"opaque_type_map",
221221
),
222222
);
223-
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
223+
let hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
224224
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
225225
if hidden_type.has_non_region_infer() {
226-
let reported = infcx.dcx().span_delayed_bug(
226+
infcx.dcx().span_bug(
227227
decl.hidden_type.span,
228228
format!("could not resolve {:#?}", hidden_type.ty.kind()),
229229
);
230-
hidden_type.ty = Ty::new_error(infcx.tcx, reported);
231230
}
232231

233232
(opaque_type_key, hidden_type)
@@ -1089,10 +1088,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10891088
);
10901089

10911090
if result.is_err() {
1092-
self.infcx.dcx().span_delayed_bug(
1093-
self.body.span,
1094-
"failed re-defining predefined opaques in mir typeck",
1095-
);
1091+
self.infcx
1092+
.dcx()
1093+
.span_bug(self.body.span, "failed re-defining predefined opaques in mir typeck");
10961094
}
10971095
}
10981096

Diff for: compiler/rustc_const_eval/src/const_eval/machine.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
393393
if ecx.tcx.is_ctfe_mir_available(def) {
394394
Ok(ecx.tcx.mir_for_ctfe(def))
395395
} else if ecx.tcx.def_kind(def) == DefKind::AssocConst {
396-
let guar = ecx
397-
.tcx
398-
.dcx()
399-
.delayed_bug("This is likely a const item that is missing from its impl");
400-
throw_inval!(AlreadyReported(guar.into()));
396+
ecx.tcx.dcx().bug("This is likely a const item that is missing from its impl");
401397
} else {
402398
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
403399
// so this should be unreachable.

Diff for: compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
329329

330330
fn check_static(&mut self, def_id: DefId, span: Span) {
331331
if self.tcx.is_thread_local_static(def_id) {
332-
self.tcx
333-
.dcx()
334-
.span_delayed_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
332+
self.tcx.dcx().span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
335333
}
336334
self.check_op_spanned(ops::StaticAccess, span)
337335
}

Diff for: compiler/rustc_const_eval/src/transform/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
517517

518518
fn visit_source_scope(&mut self, scope: SourceScope) {
519519
if self.body.source_scopes.get(scope).is_none() {
520-
self.tcx.dcx().span_delayed_bug(
520+
self.tcx.dcx().span_bug(
521521
self.body.span,
522522
format!(
523523
"broken MIR in {:?} ({}):\ninvalid source scope {:?}",

Diff for: compiler/rustc_expand/messages.ftl

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ expand_collapse_debuginfo_illegal =
2222
expand_count_repetition_misplaced =
2323
`count` can not be placed inside the inner-most repetition
2424
25+
expand_custom_attribute_panicked =
26+
custom attribute panicked
27+
.help = message: {$message}
28+
2529
expand_duplicate_matcher_binding = duplicate matcher binding
2630
.label = duplicate binding
2731
.label2 = previous binding
@@ -115,6 +119,10 @@ expand_only_one_argument =
115119
expand_only_one_word =
116120
must only be one word
117121
122+
expand_proc_macro_derive_panicked =
123+
proc-macro derive panicked
124+
.help = message: {$message}
125+
118126
expand_proc_macro_derive_tokens =
119127
proc-macro derive produced unparsable tokens
120128

Diff for: compiler/rustc_expand/src/errors.rs

+30
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,36 @@ pub(crate) struct ProcMacroPanickedHelp {
392392
pub message: String,
393393
}
394394

395+
#[derive(Diagnostic)]
396+
#[diag(expand_proc_macro_derive_panicked)]
397+
pub(crate) struct ProcMacroDerivePanicked {
398+
#[primary_span]
399+
pub span: Span,
400+
#[subdiagnostic]
401+
pub message: Option<ProcMacroDerivePanickedHelp>,
402+
}
403+
404+
#[derive(Subdiagnostic)]
405+
#[help(expand_help)]
406+
pub(crate) struct ProcMacroDerivePanickedHelp {
407+
pub message: String,
408+
}
409+
410+
#[derive(Diagnostic)]
411+
#[diag(expand_custom_attribute_panicked)]
412+
pub(crate) struct CustomAttributePanicked {
413+
#[primary_span]
414+
pub span: Span,
415+
#[subdiagnostic]
416+
pub message: Option<CustomAttributePanickedHelp>,
417+
}
418+
419+
#[derive(Subdiagnostic)]
420+
#[help(expand_help)]
421+
pub(crate) struct CustomAttributePanickedHelp {
422+
pub message: String,
423+
}
424+
395425
#[derive(Diagnostic)]
396426
#[diag(expand_proc_macro_derive_tokens)]
397427
pub struct ProcMacroDeriveTokens {

Diff for: compiler/rustc_expand/src/proc_macro.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ impl base::AttrProcMacro for AttrProcMacro {
9393
let server = proc_macro_server::Rustc::new(ecx);
9494
self.client.run(&strategy, server, annotation, annotated, proc_macro_backtrace).map_err(
9595
|e| {
96-
let mut err = ecx.dcx().struct_span_err(span, "custom attribute panicked");
97-
if let Some(s) = e.as_str() {
98-
err.help(format!("message: {s}"));
99-
}
100-
err.emit()
96+
ecx.dcx().emit_err(errors::CustomAttributePanicked {
97+
span,
98+
message: e.as_str().map(|message| errors::CustomAttributePanickedHelp {
99+
message: message.into(),
100+
}),
101+
})
101102
},
102103
)
103104
}
@@ -146,11 +147,14 @@ impl MultiItemModifier for DeriveProcMacro {
146147
match self.client.run(&strategy, server, input, proc_macro_backtrace) {
147148
Ok(stream) => stream,
148149
Err(e) => {
149-
let mut err = ecx.dcx().struct_span_err(span, "proc-macro derive panicked");
150-
if let Some(s) = e.as_str() {
151-
err.help(format!("message: {s}"));
152-
}
153-
err.emit();
150+
ecx.dcx().emit_err({
151+
errors::ProcMacroDerivePanicked {
152+
span,
153+
message: e.as_str().map(|message| {
154+
errors::ProcMacroDerivePanickedHelp { message: message.into() }
155+
}),
156+
}
157+
});
154158
return ExpandResult::Ready(vec![]);
155159
}
156160
}

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12371237
// trait reference.
12381238
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
12391239
// A cycle error occurred, most likely.
1240-
let guar = tcx.dcx().span_delayed_bug(span, "expected cycle error");
1241-
return Err(guar);
1240+
tcx.dcx().span_bug(span, "expected cycle error");
12421241
};
12431242

12441243
self.one_bound_for_assoc_item(

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
257257
fn check_opaque(tcx: TyCtxt<'_>, def_id: LocalDefId) {
258258
let item = tcx.hir().expect_item(def_id);
259259
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
260-
tcx.dcx().span_delayed_bug(item.span, "expected opaque item");
261-
return;
260+
tcx.dcx().span_bug(item.span, "expected opaque item");
262261
};
263262

264263
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
@@ -382,10 +381,10 @@ fn check_opaque_meets_bounds<'tcx>(
382381
Ok(()) => {}
383382
Err(ty_err) => {
384383
let ty_err = ty_err.to_string(tcx);
385-
return Err(tcx.dcx().span_delayed_bug(
384+
tcx.dcx().span_bug(
386385
span,
387386
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
388-
));
387+
);
389388
}
390389
}
391390

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,12 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
734734
remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
735735
}
736736
Err(err) => {
737-
let reported = tcx.dcx().span_delayed_bug(
738-
return_span,
739-
format!("could not fully resolve: {ty} => {err:?}"),
740-
);
741-
remapped_types.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
737+
// This code path is not reached in any tests, but may be
738+
// reachable. If this is triggered, it should be converted to
739+
// `span_delayed_bug` and the triggering case turned into a
740+
// test.
741+
tcx.dcx()
742+
.span_bug(return_span, format!("could not fully resolve: {ty} => {err:?}"));
742743
}
743744
}
744745
}
@@ -917,7 +918,13 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
917918
.with_note(format!("hidden type inferred to be `{}`", self.ty))
918919
.emit()
919920
}
920-
_ => self.tcx.dcx().delayed_bug("should've been able to remap region"),
921+
_ => {
922+
// This code path is not reached in any tests, but may be
923+
// reachable. If this is triggered, it should be converted
924+
// to `delayed_bug` and the triggering case turned into a
925+
// test.
926+
self.tcx.dcx().bug("should've been able to remap region");
927+
}
921928
};
922929
return Err(guar);
923930
};
@@ -1276,9 +1283,10 @@ fn compare_number_of_generics<'tcx>(
12761283
// inheriting the generics from will also have mismatched arguments, and
12771284
// we'll report an error for that instead. Delay a bug for safety, though.
12781285
if trait_.is_impl_trait_in_trait() {
1279-
return Err(tcx.dcx().delayed_bug(
1280-
"errors comparing numbers of generics of trait/impl functions were not emitted",
1281-
));
1286+
// FIXME: no tests trigger this. If you find example code that does
1287+
// trigger this, please add it to the test suite.
1288+
tcx.dcx()
1289+
.bug("errors comparing numbers of generics of trait/impl functions were not emitted");
12821290
}
12831291

12841292
let matchings = [

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,28 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
154154
trait_m_sig.inputs_and_output,
155155
));
156156
if !ocx.select_all_or_error().is_empty() {
157-
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
158-
return;
157+
// This code path is not reached in any tests, but may be reachable. If
158+
// this is triggered, it should be converted to `delayed_bug` and the
159+
// triggering case turned into a test.
160+
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
159161
}
160162
let outlives_env = OutlivesEnvironment::with_bounds(
161163
param_env,
162164
infcx.implied_bounds_tys(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
163165
);
164166
let errors = infcx.resolve_regions(&outlives_env);
165167
if !errors.is_empty() {
166-
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
167-
return;
168+
// This code path is not reached in any tests, but may be reachable. If
169+
// this is triggered, it should be converted to `delayed_bug` and the
170+
// triggering case turned into a test.
171+
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
168172
}
169173
// Resolve any lifetime variables that may have been introduced during normalization.
170174
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
171-
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
172-
return;
175+
// This code path is not reached in any tests, but may be reachable. If
176+
// this is triggered, it should be converted to `delayed_bug` and the
177+
// triggering case turned into a test.
178+
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
173179
};
174180

175181
// For quicker lookup, use an `IndexSet` (we don't use one earlier because

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1087,14 +1087,8 @@ fn check_type_defn<'tcx>(
10871087
packed && {
10881088
let ty = tcx.type_of(variant.tail().did).instantiate_identity();
10891089
let ty = tcx.erase_regions(ty);
1090-
if ty.has_infer() {
1091-
tcx.dcx()
1092-
.span_delayed_bug(item.span, format!("inference variables in {ty:?}"));
1093-
// Just treat unresolved type expression as if it needs drop.
1094-
true
1095-
} else {
1096-
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
1097-
}
1090+
assert!(!ty.has_infer());
1091+
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
10981092
}
10991093
};
11001094
// All fields (except for possibly the last) should be sized.

Diff for: compiler/rustc_hir_analysis/src/collect/generics_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
315315

316316
if is_host_effect {
317317
if let Some(idx) = host_effect_index {
318-
tcx.dcx().span_delayed_bug(
318+
tcx.dcx().span_bug(
319319
param.span,
320320
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"),
321321
);

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13311331
}
13321332
}
13331333

1334-
self.tcx.dcx().span_delayed_bug(
1334+
self.tcx.dcx().span_bug(
13351335
lifetime_ref.ident.span,
13361336
format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
13371337
);
@@ -1465,10 +1465,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14651465
}
14661466
}
14671467

1468-
self.tcx.dcx().span_delayed_bug(
1469-
self.tcx.hir().span(hir_id),
1470-
format!("could not resolve {param_def_id:?}"),
1471-
);
1468+
self.tcx
1469+
.dcx()
1470+
.span_bug(self.tcx.hir().span(hir_id), format!("could not resolve {param_def_id:?}"));
14721471
}
14731472

14741473
#[instrument(level = "debug", skip(self))]

Diff for: compiler/rustc_hir_typeck/src/cast.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139139
| ty::Never
140140
| ty::Dynamic(_, _, ty::DynStar)
141141
| ty::Error(_) => {
142-
let guar = self
143-
.dcx()
144-
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
145-
return Err(guar);
142+
self.dcx().span_bug(span, format!("`{t:?}` should be sized but is not?"));
146143
}
147144
})
148145
}

0 commit comments

Comments
 (0)