Skip to content

Rollup of 7 pull requests #121383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6150991
make "custom attribute panicked" translatable
tshepang Feb 19, 2024
f68682f
make "proc-macro derive panicked" translatable
tshepang Feb 20, 2024
e54ef0a
Make --verbose imply -Z write-long-types-to-disk=no
ffmancera Feb 20, 2024
ad14a22
Update panic message for missing `//@ run-rustfix` ui test suite when…
jieyouxu Feb 20, 2024
4d386d9
Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeInco…
jieyouxu Feb 20, 2024
0195f21
diagnostic items for legacy numeric modules
pitaj Feb 20, 2024
e35481f
Suggest using --verbose when writing type to a file
ffmancera Feb 20, 2024
010f394
Convert `delayed_bug`s to `bug`s.
nnethercote Feb 16, 2024
2903bbb
Convert `bug`s back to `delayed_bug`s.
nnethercote Feb 19, 2024
3da200d
print proper relative path for descriptive name check
chenyukang Feb 21, 2024
62e7414
Docs for extension proc-macro
compiler-errors Feb 19, 2024
d5206c6
Rollup merge of #121208 - nnethercote:delayed_bug-to-bug, r=lcnr
Dylan-DPC Feb 21, 2024
4840785
Rollup merge of #121288 - tshepang:make-expand-translatable, r=michae…
Dylan-DPC Feb 21, 2024
94e459f
Rollup merge of #121304 - compiler-errors:ext, r=nnethercote
Dylan-DPC Feb 21, 2024
4a205bb
Rollup merge of #121328 - ffmancera:ff/verbose_long_type, r=compiler-…
Dylan-DPC Feb 21, 2024
e10b3b8
Rollup merge of #121338 - jieyouxu:ambiguous_wide_pointer_comparisons…
Dylan-DPC Feb 21, 2024
860ad7c
Rollup merge of #121361 - pitaj:diag_items-legacy_numeric_constants, …
Dylan-DPC Feb 21, 2024
229108a
Rollup merge of #121375 - chenyukang:yukang-fix-tidy, r=albertlarsan68
Dylan-DPC Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,9 +1636,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if let Some(old_def_id) = self.orig_opt_local_def_id(param) {
old_def_id
} else {
self.dcx()
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
continue;
self.dcx().span_bug(lifetime.ident.span, "no def-id for fresh lifetime");
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
| GenericArgKind::Const(_),
_,
) => {
// HIR lowering sometimes doesn't catch this in erroneous
// programs, so we need to use span_delayed_bug here. See #82126.
self.dcx().span_delayed_bug(
// This was previously a `span_delayed_bug` and could be
// reached by the test for #82126, but no longer.
self.dcx().span_bug(
hir_arg.span(),
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
.and(type_op::normalize::Normalize::new(ty))
.fully_perform(self.infcx, span)
else {
// Note: this path is currently not reached in any test, so
// any example that triggers this would be worth minimizing
// and converting into a test.
tcx.dcx().span_delayed_bug(span, format!("failed to normalize {ty:?}"));
continue;
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if argument_index + 1 >= body.local_decls.len() {
self.tcx()
.dcx()
.span_delayed_bug(body.span, "found more normalized_input_ty than local_decls");
break;
.span_bug(body.span, "found more normalized_input_ty than local_decls");
}

// In MIR, argument N is stored in local N+1.
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,13 @@ pub(crate) fn type_check<'mir, 'tcx>(
"opaque_type_map",
),
);
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
let hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
if hidden_type.has_non_region_infer() {
let reported = infcx.dcx().span_delayed_bug(
infcx.dcx().span_bug(
decl.hidden_type.span,
format!("could not resolve {:#?}", hidden_type.ty.kind()),
);
hidden_type.ty = Ty::new_error(infcx.tcx, reported);
}

(opaque_type_key, hidden_type)
Expand Down Expand Up @@ -1089,10 +1088,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);

if result.is_err() {
self.infcx.dcx().span_delayed_bug(
self.body.span,
"failed re-defining predefined opaques in mir typeck",
);
self.infcx
.dcx()
.span_bug(self.body.span, "failed re-defining predefined opaques in mir typeck");
}
}

Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
if ecx.tcx.is_ctfe_mir_available(def) {
Ok(ecx.tcx.mir_for_ctfe(def))
} else if ecx.tcx.def_kind(def) == DefKind::AssocConst {
let guar = ecx
.tcx
.dcx()
.delayed_bug("This is likely a const item that is missing from its impl");
throw_inval!(AlreadyReported(guar.into()));
ecx.tcx.dcx().bug("This is likely a const item that is missing from its impl");
} else {
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
// so this should be unreachable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {

fn check_static(&mut self, def_id: DefId, span: Span) {
if self.tcx.is_thread_local_static(def_id) {
self.tcx
.dcx()
.span_delayed_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
self.tcx.dcx().span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
}
self.check_op_spanned(ops::StaticAccess, span)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {

fn visit_source_scope(&mut self, scope: SourceScope) {
if self.body.source_scopes.get(scope).is_none() {
self.tcx.dcx().span_delayed_bug(
self.tcx.dcx().span_bug(
self.body.span,
format!(
"broken MIR in {:?} ({}):\ninvalid source scope {:?}",
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ expand_collapse_debuginfo_illegal =
expand_count_repetition_misplaced =
`count` can not be placed inside the inner-most repetition

expand_custom_attribute_panicked =
custom attribute panicked
.help = message: {$message}

expand_duplicate_matcher_binding = duplicate matcher binding
.label = duplicate binding
.label2 = previous binding
Expand Down Expand Up @@ -115,6 +119,10 @@ expand_only_one_argument =
expand_only_one_word =
must only be one word

expand_proc_macro_derive_panicked =
proc-macro derive panicked
.help = message: {$message}

expand_proc_macro_derive_tokens =
proc-macro derive produced unparsable tokens

Expand Down
30 changes: 30 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,36 @@ pub(crate) struct ProcMacroPanickedHelp {
pub message: String,
}

#[derive(Diagnostic)]
#[diag(expand_proc_macro_derive_panicked)]
pub(crate) struct ProcMacroDerivePanicked {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub message: Option<ProcMacroDerivePanickedHelp>,
}

#[derive(Subdiagnostic)]
#[help(expand_help)]
pub(crate) struct ProcMacroDerivePanickedHelp {
pub message: String,
}

#[derive(Diagnostic)]
#[diag(expand_custom_attribute_panicked)]
pub(crate) struct CustomAttributePanicked {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub message: Option<CustomAttributePanickedHelp>,
}

#[derive(Subdiagnostic)]
#[help(expand_help)]
pub(crate) struct CustomAttributePanickedHelp {
pub message: String,
}

#[derive(Diagnostic)]
#[diag(expand_proc_macro_derive_tokens)]
pub struct ProcMacroDeriveTokens {
Expand Down
24 changes: 14 additions & 10 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ impl base::AttrProcMacro for AttrProcMacro {
let server = proc_macro_server::Rustc::new(ecx);
self.client.run(&strategy, server, annotation, annotated, proc_macro_backtrace).map_err(
|e| {
let mut err = ecx.dcx().struct_span_err(span, "custom attribute panicked");
if let Some(s) = e.as_str() {
err.help(format!("message: {s}"));
}
err.emit()
ecx.dcx().emit_err(errors::CustomAttributePanicked {
span,
message: e.as_str().map(|message| errors::CustomAttributePanickedHelp {
message: message.into(),
}),
})
},
)
}
Expand Down Expand Up @@ -146,11 +147,14 @@ impl MultiItemModifier for DeriveProcMacro {
match self.client.run(&strategy, server, input, proc_macro_backtrace) {
Ok(stream) => stream,
Err(e) => {
let mut err = ecx.dcx().struct_span_err(span, "proc-macro derive panicked");
if let Some(s) = e.as_str() {
err.help(format!("message: {s}"));
}
err.emit();
ecx.dcx().emit_err({
errors::ProcMacroDerivePanicked {
span,
message: e.as_str().map(|message| {
errors::ProcMacroDerivePanickedHelp { message: message.into() }
}),
}
});
return ExpandResult::Ready(vec![]);
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// trait reference.
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
// A cycle error occurred, most likely.
let guar = tcx.dcx().span_delayed_bug(span, "expected cycle error");
return Err(guar);
tcx.dcx().span_bug(span, "expected cycle error");
};

self.one_bound_for_assoc_item(
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
fn check_opaque(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let item = tcx.hir().expect_item(def_id);
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
tcx.dcx().span_delayed_bug(item.span, "expected opaque item");
return;
tcx.dcx().span_bug(item.span, "expected opaque item");
};

// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
Expand Down Expand Up @@ -382,10 +381,10 @@ fn check_opaque_meets_bounds<'tcx>(
Ok(()) => {}
Err(ty_err) => {
let ty_err = ty_err.to_string(tcx);
return Err(tcx.dcx().span_delayed_bug(
tcx.dcx().span_bug(
span,
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
));
);
}
}

Expand Down
26 changes: 17 additions & 9 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,12 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
}
Err(err) => {
let reported = tcx.dcx().span_delayed_bug(
return_span,
format!("could not fully resolve: {ty} => {err:?}"),
);
remapped_types.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
// This code path is not reached in any tests, but may be
// reachable. If this is triggered, it should be converted to
// `span_delayed_bug` and the triggering case turned into a
// test.
tcx.dcx()
.span_bug(return_span, format!("could not fully resolve: {ty} => {err:?}"));
}
}
}
Expand Down Expand Up @@ -917,7 +918,13 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
.with_note(format!("hidden type inferred to be `{}`", self.ty))
.emit()
}
_ => self.tcx.dcx().delayed_bug("should've been able to remap region"),
_ => {
// This code path is not reached in any tests, but may be
// reachable. If this is triggered, it should be converted
// to `delayed_bug` and the triggering case turned into a
// test.
self.tcx.dcx().bug("should've been able to remap region");
}
};
return Err(guar);
};
Expand Down Expand Up @@ -1276,9 +1283,10 @@ fn compare_number_of_generics<'tcx>(
// inheriting the generics from will also have mismatched arguments, and
// we'll report an error for that instead. Delay a bug for safety, though.
if trait_.is_impl_trait_in_trait() {
return Err(tcx.dcx().delayed_bug(
"errors comparing numbers of generics of trait/impl functions were not emitted",
));
// FIXME: no tests trigger this. If you find example code that does
// trigger this, please add it to the test suite.
tcx.dcx()
.bug("errors comparing numbers of generics of trait/impl functions were not emitted");
}

let matchings = [
Expand Down
18 changes: 12 additions & 6 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,28 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
trait_m_sig.inputs_and_output,
));
if !ocx.select_all_or_error().is_empty() {
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
return;
// This code path is not reached in any tests, but may be reachable. If
// this is triggered, it should be converted to `delayed_bug` and the
// triggering case turned into a test.
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
}
let outlives_env = OutlivesEnvironment::with_bounds(
param_env,
infcx.implied_bounds_tys(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
);
let errors = infcx.resolve_regions(&outlives_env);
if !errors.is_empty() {
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
return;
// This code path is not reached in any tests, but may be reachable. If
// this is triggered, it should be converted to `delayed_bug` and the
// triggering case turned into a test.
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
}
// Resolve any lifetime variables that may have been introduced during normalization.
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
return;
// This code path is not reached in any tests, but may be reachable. If
// this is triggered, it should be converted to `delayed_bug` and the
// triggering case turned into a test.
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
};

// For quicker lookup, use an `IndexSet` (we don't use one earlier because
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,14 +1087,8 @@ fn check_type_defn<'tcx>(
packed && {
let ty = tcx.type_of(variant.tail().did).instantiate_identity();
let ty = tcx.erase_regions(ty);
if ty.has_infer() {
tcx.dcx()
.span_delayed_bug(item.span, format!("inference variables in {ty:?}"));
// Just treat unresolved type expression as if it needs drop.
true
} else {
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
}
assert!(!ty.has_infer());
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
}
};
// All fields (except for possibly the last) should be sized.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {

if is_host_effect {
if let Some(idx) = host_effect_index {
tcx.dcx().span_delayed_bug(
tcx.dcx().span_bug(
param.span,
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"),
);
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
}
}

self.tcx.dcx().span_delayed_bug(
self.tcx.dcx().span_bug(
lifetime_ref.ident.span,
format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
);
Expand Down Expand Up @@ -1465,10 +1465,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
}
}

self.tcx.dcx().span_delayed_bug(
self.tcx.hir().span(hir_id),
format!("could not resolve {param_def_id:?}"),
);
self.tcx
.dcx()
.span_bug(self.tcx.hir().span(hir_id), format!("could not resolve {param_def_id:?}"));
}

#[instrument(level = "debug", skip(self))]
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::Never
| ty::Dynamic(_, _, ty::DynStar)
| ty::Error(_) => {
let guar = self
.dcx()
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
return Err(guar);
self.dcx().span_bug(span, format!("`{t:?}` should be sized but is not?"));
}
})
}
Expand Down
Loading