From 61509914a3debdf6ff809c35af15cc5cabcc32a0 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 19 Feb 2024 06:02:14 +0200 Subject: [PATCH 01/11] make "custom attribute panicked" translatable --- compiler/rustc_expand/messages.ftl | 4 ++++ compiler/rustc_expand/src/errors.rs | 15 +++++++++++++++ compiler/rustc_expand/src/proc_macro.rs | 11 ++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl index 3e3b481430043..cae4df6cd4b47 100644 --- a/compiler/rustc_expand/messages.ftl +++ b/compiler/rustc_expand/messages.ftl @@ -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 diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index 2584ff62e98e6..5bbf4411bc35d 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -392,6 +392,21 @@ pub(crate) struct ProcMacroPanickedHelp { pub message: String, } +#[derive(Diagnostic)] +#[diag(expand_custom_attribute_panicked)] +pub(crate) struct CustomAttributePanicked { + #[primary_span] + pub span: Span, + #[subdiagnostic] + pub message: Option, +} + +#[derive(Subdiagnostic)] +#[help(expand_help)] +pub(crate) struct CustomAttributePanickedHelp { + pub message: String, +} + #[derive(Diagnostic)] #[diag(expand_proc_macro_derive_tokens)] pub struct ProcMacroDeriveTokens { diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 2233cad2e63a8..170857e62ff0a 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -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(), + }), + }) }, ) } From f68682fd484fc219192aa7ccf7bb1d809288df5e Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 20 Feb 2024 08:31:13 +0200 Subject: [PATCH 02/11] make "proc-macro derive panicked" translatable --- compiler/rustc_expand/messages.ftl | 4 ++++ compiler/rustc_expand/src/errors.rs | 15 +++++++++++++++ compiler/rustc_expand/src/proc_macro.rs | 13 ++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl index cae4df6cd4b47..c82a0242c5b8f 100644 --- a/compiler/rustc_expand/messages.ftl +++ b/compiler/rustc_expand/messages.ftl @@ -114,6 +114,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 diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index 5bbf4411bc35d..299ba8a1fdf4f 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -392,6 +392,21 @@ 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, +} + +#[derive(Subdiagnostic)] +#[help(expand_help)] +pub(crate) struct ProcMacroDerivePanickedHelp { + pub message: String, +} + #[derive(Diagnostic)] #[diag(expand_custom_attribute_panicked)] pub(crate) struct CustomAttributePanicked { diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 170857e62ff0a..23caf2f193aad 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -147,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![]); } } From e54ef0a7ab42f6af8804632b1b5858c606fe1c3c Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Tue, 20 Feb 2024 01:20:00 +0100 Subject: [PATCH 03/11] Make --verbose imply -Z write-long-types-to-disk=no When shortening the type it is necessary to take into account the `--verbose` flag, if it is activated, we must always show the entire type and not write it in a file. Fixes: https://github.com/rust-lang/rust/issues/119130 --- compiler/rustc_middle/src/ty/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 80b763d1469e4..e15f03788464e 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -351,7 +351,7 @@ impl<'tcx> TyCtxt<'tcx> { }) .expect("could not write to `String`"); - if !self.sess.opts.unstable_opts.write_long_types_to_disk { + if !self.sess.opts.unstable_opts.write_long_types_to_disk || self.sess.opts.verbose { return regular; } From ad14a226c04c4b15a229bb1fba771ba8fd2f5b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Tue, 20 Feb 2024 11:33:29 +0000 Subject: [PATCH 04/11] Update panic message for missing `//@ run-rustfix` ui test suite when a .fixed file exists --- src/tools/compiletest/src/runtest.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f3a0e87d43a83..ed120ee877a53 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3938,10 +3938,15 @@ impl<'test> TestCx<'test> { self.props.compare_output_lines_by_subset, ); } else if !expected_fixed.is_empty() { - panic!( - "the `// run-rustfix` directive wasn't found but a `*.fixed` \ - file was found" - ); + if self.config.suite == "ui" { + panic!( + "the `//@ run-rustfix` directive wasn't found but a `*.fixed` file was found" + ); + } else { + panic!( + "the `// run-rustfix` directive wasn't found but a `*.fixed` file was found" + ); + } } if errors > 0 { From 4d386d9f049da498b5f072b6c358a6fbbe0baf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Tue, 20 Feb 2024 11:35:13 +0000 Subject: [PATCH 05/11] Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect It is possible to have more than one valid suggestion, which when applied together via rustfix causes the code to no longer compile. This is a temporary workaround; the real long term solution to these issues is to solve . --- compiler/rustc_lint/src/lints.rs | 9 ++++++--- ..._wide_pointer_comparisons_suggestions.fixed | 13 +++++++++++++ ...ous_wide_pointer_comparisons_suggestions.rs | 13 +++++++++++++ ...wide_pointer_comparisons_suggestions.stderr | 18 ++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed create mode 100644 tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs create mode 100644 tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index c204c67fc1f7c..71107be206b07 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1543,7 +1543,8 @@ pub enum AmbiguousWidePointerComparisons<'a> { #[multipart_suggestion( lint_addr_metadata_suggestion, style = "verbose", - applicability = "machine-applicable" + // FIXME(#53934): make machine-applicable again + applicability = "maybe-incorrect" )] pub struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> { pub ne: &'a str, @@ -1562,7 +1563,8 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> { #[multipart_suggestion( lint_addr_suggestion, style = "verbose", - applicability = "machine-applicable" + // FIXME(#53934): make machine-applicable again + applicability = "maybe-incorrect" )] AddrEq { ne: &'a str, @@ -1578,7 +1580,8 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> { #[multipart_suggestion( lint_addr_suggestion, style = "verbose", - applicability = "machine-applicable" + // FIXME(#53934): make machine-applicable again + applicability = "maybe-incorrect" )] Cast { deref_left: &'a str, diff --git a/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed new file mode 100644 index 0000000000000..6ce68ff9640c8 --- /dev/null +++ b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed @@ -0,0 +1,13 @@ +//@ run-rustfix +//@ rustfix-only-machine-applicable +//@ check-pass + +// See . + +fn cmp(a: *mut T, b: *mut T) -> bool { + let _ = a == b; + //~^ WARN ambiguous wide pointer comparison + panic!(); +} + +fn main() {} diff --git a/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs new file mode 100644 index 0000000000000..6ce68ff9640c8 --- /dev/null +++ b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs @@ -0,0 +1,13 @@ +//@ run-rustfix +//@ rustfix-only-machine-applicable +//@ check-pass + +// See . + +fn cmp(a: *mut T, b: *mut T) -> bool { + let _ = a == b; + //~^ WARN ambiguous wide pointer comparison + panic!(); +} + +fn main() {} diff --git a/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr new file mode 100644 index 0000000000000..d9190dbb81340 --- /dev/null +++ b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr @@ -0,0 +1,18 @@ +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/ambiguous_wide_pointer_comparisons_suggestions.rs:8:13 + | +LL | let _ = a == b; + | ^^^^^^ + | + = note: `#[warn(ambiguous_wide_pointer_comparisons)]` on by default +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = std::ptr::addr_eq(a, b); + | ++++++++++++++++++ ~ + +help: use explicit `std::ptr::eq` method to compare metadata and addresses + | +LL | let _ = std::ptr::eq(a, b); + | +++++++++++++ ~ + + +warning: 1 warning emitted + From 0195f21f728d80606712dc2a33ec82004aedb02e Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Tue, 20 Feb 2024 13:34:07 -0700 Subject: [PATCH 06/11] diagnostic items for legacy numeric modules --- library/core/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index b54680a61b4d8..456d88122af64 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -309,29 +309,41 @@ mod internal_macros; #[macro_use] mod int_macros; +#[rustc_diagnostic_item = "i128_legacy_mod"] #[path = "num/shells/i128.rs"] pub mod i128; +#[rustc_diagnostic_item = "i16_legacy_mod"] #[path = "num/shells/i16.rs"] pub mod i16; +#[rustc_diagnostic_item = "i32_legacy_mod"] #[path = "num/shells/i32.rs"] pub mod i32; +#[rustc_diagnostic_item = "i64_legacy_mod"] #[path = "num/shells/i64.rs"] pub mod i64; +#[rustc_diagnostic_item = "i8_legacy_mod"] #[path = "num/shells/i8.rs"] pub mod i8; +#[rustc_diagnostic_item = "isize_legacy_mod"] #[path = "num/shells/isize.rs"] pub mod isize; +#[rustc_diagnostic_item = "u128_legacy_mod"] #[path = "num/shells/u128.rs"] pub mod u128; +#[rustc_diagnostic_item = "u16_legacy_mod"] #[path = "num/shells/u16.rs"] pub mod u16; +#[rustc_diagnostic_item = "u32_legacy_mod"] #[path = "num/shells/u32.rs"] pub mod u32; +#[rustc_diagnostic_item = "u64_legacy_mod"] #[path = "num/shells/u64.rs"] pub mod u64; +#[rustc_diagnostic_item = "u8_legacy_mod"] #[path = "num/shells/u8.rs"] pub mod u8; +#[rustc_diagnostic_item = "usize_legacy_mod"] #[path = "num/shells/usize.rs"] pub mod usize; From e35481f90bcd7e4a646aabab1183a33bebae8c94 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Tue, 20 Feb 2024 09:31:01 +0100 Subject: [PATCH 07/11] Suggest using --verbose when writing type to a file --- compiler/rustc_hir_typeck/src/method/suggest.rs | 6 ++++++ .../rustc_infer/src/infer/error_reporting/mod.rs | 1 + .../src/traits/error_reporting/suggestions.rs | 12 ++++++++++++ tests/ui/diagnostic-width/long-E0308.stderr | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index f39b496154b46..5a3b0e6b10153 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -369,6 +369,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; if let Some(file) = file { err.note(format!("the full type name has been written to '{}'", file.display())); + err.note(format!( + "consider using `--verbose` to print the full type name to the console" + )); } err @@ -493,6 +496,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(file) = ty_file { err.note(format!("the full type name has been written to '{}'", file.display(),)); + err.note(format!( + "consider using `--verbose` to print the full type name to the console" + )); } if rcvr_ty.references_error() { err.downgrade_to_delayed_bug(); diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 104bf4a5be873..b72d804ce3c13 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1931,6 +1931,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { "the full type name has been written to '{}'", path.display(), )); + diag.note(format!("consider using `--verbose` to print the full type name to the console")); } } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 335e6ff28226e..8f64065daddb2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1554,6 +1554,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { "the full type name has been written to '{}'", file.display() )); + err.note(format!( + "consider using `--verbose` to print full type name to the console" + )); } if imm_ref_self_ty_satisfies_pred && mut_ref_self_ty_satisfies_pred { @@ -3133,6 +3136,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { "the full name for the type has been written to '{}'", file.display(), )); + err.note(format!( + "consider using `--verbose` to print the full type name to the console" + )); } } ObligationCauseCode::RepeatElementCopy { @@ -3600,6 +3606,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { "the full type name has been written to '{}'", file.display(), )); + err.note(format!( + "consider using `--verbose` to print the full type name to the console" + )); } let mut parent_predicate = parent_trait_pred; let mut data = &data.derived; @@ -3653,6 +3662,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { "the full type name has been written to '{}'", file.display(), )); + err.note(format!( + "consider using `--verbose` to print the full type name to the console" + )); } } // #74711: avoid a stack overflow diff --git a/tests/ui/diagnostic-width/long-E0308.stderr b/tests/ui/diagnostic-width/long-E0308.stderr index 1e5966a1c5dd4..eb37da037e9d7 100644 --- a/tests/ui/diagnostic-width/long-E0308.stderr +++ b/tests/ui/diagnostic-width/long-E0308.stderr @@ -21,6 +21,7 @@ LL | | )))))))))))))))))))))))))))))); = note: expected struct `Atype, ...>` found enum `Result, ...>` = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' + = note: consider using `--verbose` to print the full type name to the console error[E0308]: mismatched types --> $DIR/long-E0308.rs:57:26 @@ -36,6 +37,7 @@ LL | | )))))))))))))))))))))))); = note: expected enum `Option>` found enum `Result, ...>` = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' + = note: consider using `--verbose` to print the full type name to the console error[E0308]: mismatched types --> $DIR/long-E0308.rs:88:9 @@ -55,6 +57,7 @@ LL | | > = (); = note: expected struct `Atype, ...>` found unit type `()` = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' + = note: consider using `--verbose` to print the full type name to the console error[E0308]: mismatched types --> $DIR/long-E0308.rs:91:17 @@ -72,6 +75,7 @@ LL | | )))))))))))))))))))))))); = note: expected unit type `()` found enum `Result, ...>` = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' + = note: consider using `--verbose` to print the full type name to the console error: aborting due to 4 previous errors From 010f3944e0f0baac8d738da49772fd06acd3701b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 17 Feb 2024 01:23:40 +1100 Subject: [PATCH 08/11] Convert `delayed_bug`s to `bug`s. I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. The next commit will convert some more back, based on human judgment. --- compiler/rustc_ast_lowering/src/lib.rs | 4 +-- .../src/diagnostics/region_name.rs | 2 +- .../src/type_check/free_region_relations.rs | 3 +- .../src/type_check/input_output.rs | 3 +- compiler/rustc_borrowck/src/type_check/mod.rs | 12 ++++---- .../src/const_eval/machine.rs | 8 ++--- .../src/transform/check_consts/check.rs | 4 +-- .../src/transform/validate.rs | 2 +- .../rustc_hir_analysis/src/astconv/mod.rs | 3 +- .../rustc_hir_analysis/src/check/check.rs | 7 ++--- .../src/check/compare_impl_item.rs | 14 ++++----- .../src/check/compare_impl_item/refine.rs | 9 ++---- .../rustc_hir_analysis/src/check/dropck.rs | 3 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 6 ++-- .../src/collect/generics_of.rs | 2 +- .../src/collect/resolve_bound_vars.rs | 9 +++--- compiler/rustc_hir_typeck/src/cast.rs | 5 +--- compiler/rustc_hir_typeck/src/expr.rs | 15 +++------- compiler/rustc_hir_typeck/src/intrinsicck.rs | 3 +- .../src/mem_categorization.rs | 6 ++-- compiler/rustc_hir_typeck/src/method/probe.rs | 3 +- .../rustc_hir_typeck/src/method/suggest.rs | 2 +- compiler/rustc_hir_typeck/src/pat.rs | 5 +--- .../src/infer/outlives/obligations.rs | 2 +- .../rustc_infer/src/infer/outlives/verify.rs | 6 +--- compiler/rustc_infer/src/infer/relate/nll.rs | 8 ++--- .../rustc_middle/src/ty/typeck_results.rs | 3 +- compiler/rustc_middle/src/ty/util.rs | 4 +-- compiler/rustc_middle/src/util/bug.rs | 2 +- .../src/build/expr/as_constant.rs | 15 ++++------ compiler/rustc_mir_build/src/thir/constant.rs | 29 +++++++------------ .../rustc_mir_build/src/thir/pattern/mod.rs | 2 +- compiler/rustc_mir_transform/src/coroutine.rs | 6 +--- .../src/elaborate_drops.rs | 2 +- compiler/rustc_resolve/src/late.rs | 4 +-- .../src/traits/const_evaluatable.rs | 6 ++-- .../error_reporting/type_err_ctxt_ext.rs | 2 +- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/outlives_bounds.rs | 2 +- .../src/traits/project.rs | 5 ++-- .../src/traits/query/type_op/custom.rs | 2 +- .../src/traits/query/type_op/mod.rs | 7 ++--- compiler/rustc_ty_utils/src/layout.rs | 3 +- compiler/rustc_ty_utils/src/opaque_types.rs | 2 +- 44 files changed, 87 insertions(+), 157 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a5be91bb87209..ef843da7307d3 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -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"); } } diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 5b235066ea6cb..fea8c5a6de665 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -628,7 +628,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { ) => { // 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( + self.dcx().span_bug( hir_arg.span(), format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"), ); diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 356f0024c071e..0fc0417570594 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -316,8 +316,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { .and(type_op::normalize::Normalize::new(ty)) .fully_perform(self.infcx, span) else { - tcx.dcx().span_delayed_bug(span, format!("failed to normalize {ty:?}")); - continue; + tcx.dcx().span_bug(span, format!("failed to normalize {ty:?}")); }; constraints.extend(c); diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index af5b635ae6688..8af78b08f69c1 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -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. diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index f96c2cbd8c05b..81193902f9b32 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -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) @@ -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"); } } diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 2c60ede79758c..77744945b12fe 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -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. @@ -626,7 +622,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, ); // If this was a hard error, don't bother continuing evaluation. if is_error { - let guard = ecx + let guard: rustc_errors::ErrorGuaranteed = ecx .tcx .dcx() .span_delayed_bug(span, "The deny lint should have already errored"); diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 26ef083219f97..effaedd0820c3 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -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) } diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 1ff72516324c3..cc49e8ea247f7 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -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 {:?}", diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 502e83db65473..385b1f2a3e377 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -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( diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index b3700013f9c2d..b945eed54d048 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -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 @@ -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}"), - )); + ); } } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 1dd27f0cc5314..42a64d8670de7 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -734,11 +734,8 @@ 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))); + tcx.dcx() + .span_bug(return_span, format!("could not fully resolve: {ty} => {err:?}")); } } } @@ -917,7 +914,7 @@ impl<'tcx> ty::FallibleTypeFolder> 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"), + _ => self.tcx.dcx().bug("should've been able to remap region"), }; return Err(guar); }; @@ -1276,9 +1273,8 @@ 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", - )); + tcx.dcx() + .bug("errors comparing numbers of generics of trait/impl functions were not emitted"); } let matchings = [ diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 3d3b21eabb383..da40d6a860e6b 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -154,8 +154,7 @@ 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; + tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)"); } let outlives_env = OutlivesEnvironment::with_bounds( param_env, @@ -163,13 +162,11 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( ); let errors = infcx.resolve_regions(&outlives_env); if !errors.is_empty() { - tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)"); - return; + 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; + tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)"); }; // For quicker lookup, use an `IndexSet` (we don't use one earlier because diff --git a/compiler/rustc_hir_analysis/src/check/dropck.rs b/compiler/rustc_hir_analysis/src/check/dropck.rs index 82a6b6b6f2cb5..9b46b415491ff 100644 --- a/compiler/rustc_hir_analysis/src/check/dropck.rs +++ b/compiler/rustc_hir_analysis/src/check/dropck.rs @@ -67,11 +67,10 @@ pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), Erro // already checked by coherence, but compilation may // not have been terminated. let span = tcx.def_span(drop_impl_did); - let reported = tcx.dcx().span_delayed_bug( + tcx.dcx().span_bug( span, format!("should have been rejected by coherence check: {dtor_self_type}"), ); - Err(reported) } } } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index e7506cee60e7c..81d8a51485f12 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1088,10 +1088,8 @@ fn check_type_defn<'tcx>( 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 + // Unresolved type expression. + tcx.dcx().span_bug(item.span, format!("inference variables in {ty:?}")); } else { ty.needs_drop(tcx, tcx.param_env(item.owner_id)) } diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 9cc6c16c12639..410a069f9568f 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -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:?}"), ); diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 325a0ee9a18fd..efde4e11c79dd 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -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,), ); @@ -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))] diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 48fc2900b0d5e..b662d23c27150 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -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?")); } }) } diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 0f6544c3e1f9c..0a636fa9eacd0 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -76,16 +76,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // While we don't allow *arbitrary* coercions here, we *do* allow // coercions from ! to `expected`. if ty.is_never() { - if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) { - let reported = self.dcx().span_delayed_bug( - expr.span, - "expression with never type wound up being adjusted", - ); - return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] { - target.to_owned() - } else { - Ty::new_error(self.tcx(), reported) - }; + if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) { + self.dcx() + .span_bug(expr.span, "expression with never type wound up being adjusted"); } let adj_ty = self.next_ty_var(TypeVariableOrigin { @@ -1325,7 +1318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // permit break with a value [1]. if ctxt.coerce.is_none() && !ctxt.may_break { // [1] - self.dcx().span_delayed_bug(body.span, "no coercion, but loop may not break"); + self.dcx().span_bug(body.span, "no coercion, but loop may not break"); } ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| Ty::new_unit(self.tcx)) } diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 2dee5093e876d..fd62afbae96aa 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -48,8 +48,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let to = normalize(to); trace!(?from, ?to); if from.has_non_region_infer() || to.has_non_region_infer() { - tcx.dcx().span_delayed_bug(span, "argument to transmute has inference variables"); - return; + tcx.dcx().span_bug(span, "argument to transmute has inference variables"); } // Transmutes that are only changing lifetimes are always ok. if from == to { diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index fefaf9967253b..c300ec7444b2e 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -570,8 +570,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { _ => { self.tcx() .dcx() - .span_delayed_bug(span, "struct or tuple struct pattern not applied to an ADT"); - Err(()) + .span_bug(span, "struct or tuple struct pattern not applied to an ADT"); } } } @@ -583,8 +582,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { match ty.kind() { ty::Tuple(args) => Ok(args.len()), _ => { - self.tcx().dcx().span_delayed_bug(span, "tuple pattern not applied to a tuple"); - Err(()) + self.tcx().dcx().span_bug(span, "tuple pattern not applied to a tuple"); } } } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index d7edc70bce82e..a58e194e20aed 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -804,11 +804,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let trait_ref = principal.with_self_ty(self.tcx, self_ty); self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| { if new_trait_ref.has_non_region_bound_vars() { - this.dcx().span_delayed_bug( + this.dcx().span_bug( this.span, "tried to select method from HRTB with non-lifetime bound vars", ); - return; } let new_trait_ref = this.instantiate_bound_regions_with_erased(new_trait_ref); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 005d217fdc44f..13f33abaa6451 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -924,7 +924,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: item_span, .. })) => { - tcx.dcx().span_delayed_bug( + tcx.dcx().span_bug( *item_span, "auto trait is invoked with no method error, but no error reported?", ); diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 73689b45b95ba..b15c9ef901877 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -1085,10 +1085,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let variant = match res { Res::Err => { - let e = tcx.dcx().span_delayed_bug(pat.span, "`Res::Err` but no error emitted"); - self.set_tainted_by_errors(e); - on_error(e); - return Ty::new_error(tcx, e); + tcx.dcx().span_bug(pat.span, "`Res::Err` but no error emitted"); } Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => { let e = report_unexpected_res(res); diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index c0a99e5cc4177..643fe83e89881 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -303,7 +303,7 @@ where // Ignore this, we presume it will yield an error later, // since if a type variable is not resolved by this point // it never will be. - self.tcx.dcx().span_delayed_bug( + self.tcx.dcx().span_bug( origin.span(), format!("unresolved inference variable in outlives: {v:?}"), ); diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 3ef37bf3466f1..515f44c914d07 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -175,11 +175,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { // Ignore this, we presume it will yield an error later, since // if a type variable is not resolved by this point it never // will be. - self.tcx - .dcx() - .delayed_bug(format!("unresolved inference variable in outlives: {v:?}")); - // Add a bound that never holds. - VerifyBound::AnyBound(vec![]) + self.tcx.dcx().bug(format!("unresolved inference variable in outlives: {v:?}")); } } } diff --git a/compiler/rustc_infer/src/infer/relate/nll.rs b/compiler/rustc_infer/src/infer/relate/nll.rs index 4ba4bd38e9fe4..4cc6457df7a30 100644 --- a/compiler/rustc_infer/src/infer/relate/nll.rs +++ b/compiler/rustc_infer/src/infer/relate/nll.rs @@ -420,11 +420,9 @@ where match b.kind() { ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => { // Forbid inference variables in the RHS. - self.infcx.dcx().span_delayed_bug( - self.delegate.span(), - format!("unexpected inference var {b:?}",), - ); - Ok(a) + self.infcx + .dcx() + .span_bug(self.delegate.span(), format!("unexpected inference var {b:?}",)); } // FIXME(invariance): see the related FIXME above. _ => self.infcx.super_combine_consts(self, a, b), diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index a03ee78a29a58..4287b382604ee 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -410,8 +410,7 @@ impl<'tcx> TypeckResults<'tcx> { pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option { self.pat_binding_modes().get(id).copied().or_else(|| { - s.dcx().span_delayed_bug(sp, "missing binding mode"); - None + s.dcx().span_bug(sp, "missing binding mode"); }) } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 3f539945841b6..95d55a7081db5 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -356,9 +356,7 @@ impl<'tcx> TyCtxt<'tcx> { } let Some(item_id) = self.associated_item_def_ids(impl_did).first() else { - self.dcx() - .span_delayed_bug(self.def_span(impl_did), "Drop impl without drop function"); - return; + self.dcx().span_bug(self.def_span(impl_did), "Drop impl without drop function"); }; if let Some((old_item_id, _)) = dtor_candidate { diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs index a67ec99158210..dae6c0b9d68b8 100644 --- a/compiler/rustc_middle/src/util/bug.rs +++ b/compiler/rustc_middle/src/util/bug.rs @@ -42,7 +42,7 @@ fn opt_span_bug_fmt>( /// delayed bug, so what is the point of this? It exists to help us test the interaction of delayed /// bugs with the query system and incremental. pub fn trigger_delayed_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) { - tcx.dcx().span_delayed_bug( + tcx.dcx().span_bug( tcx.def_span(key), "delayed bug triggered by #[rustc_error(delayed_bug_from_inside_query)]", ); diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 7c3d2671d592c..d66540d8e79e4 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -110,15 +110,12 @@ fn lit_to_mir_constant<'tcx>( let LitToConstInput { lit, ty, neg } = lit_input; let trunc = |n| { let param_ty = ty::ParamEnv::reveal_all().and(ty); - let width = - tcx.layout_of(param_ty) - .map_err(|_| { - LitToConstError::Reported(tcx.dcx().delayed_bug(format!( - "couldn't compute width of literal: {:?}", - lit_input.lit - ))) - })? - .size; + let width = tcx + .layout_of(param_ty) + .map_err(|_| { + tcx.dcx().bug(format!("couldn't compute width of literal: {:?}", lit_input.lit)) + })? + .size; trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = width.truncate(n); trace!("trunc result: {}", result); diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index d444de8b28eec..46580432f1328 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -12,15 +12,12 @@ pub(crate) fn lit_to_const<'tcx>( let trunc = |n| { let param_ty = ParamEnv::reveal_all().and(ty); - let width = - tcx.layout_of(param_ty) - .map_err(|_| { - LitToConstError::Reported(tcx.dcx().delayed_bug(format!( - "couldn't compute width of literal: {:?}", - lit_input.lit - ))) - })? - .size; + let width = tcx + .layout_of(param_ty) + .map_err(|_| { + tcx.dcx().bug(format!("couldn't compute width of literal: {:?}", lit_input.lit)) + })? + .size; trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = width.truncate(n); trace!("trunc result: {}", result); @@ -59,15 +56,11 @@ pub(crate) fn lit_to_const<'tcx>( } (ast::LitKind::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()), (ast::LitKind::Float(n, _), ty::Float(fty)) => { - let bits = - parse_float_into_scalar(*n, *fty, neg) - .ok_or_else(|| { - LitToConstError::Reported(tcx.dcx().delayed_bug(format!( - "couldn't parse float literal: {:?}", - lit_input.lit - ))) - })? - .assert_int(); + let bits = parse_float_into_scalar(*n, *fty, neg) + .ok_or_else(|| { + tcx.dcx().bug(format!("couldn't parse float literal: {:?}", lit_input.lit)) + })? + .assert_int(); ty::ValTree::from_scalar_int(bits) } (ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()), diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 1a5cf13e28978..0329e1d3096dc 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -175,7 +175,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { ) -> Result, ErrorGuaranteed> { if lo_expr.is_none() && hi_expr.is_none() { let msg = "found twice-open range pattern (`..`) outside of error recovery"; - return Err(self.tcx.dcx().span_delayed_bug(span, msg)); + self.tcx.dcx().span_bug(span, msg); } let (lo, lo_ascr, lo_inline) = self.lower_pattern_range_endpoint(lo_expr)?; diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index a0851aa557b86..54b13a40e92dd 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -1615,11 +1615,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { (args.discr_ty(tcx), coroutine_kind.movability() == hir::Movability::Movable) } _ => { - tcx.dcx().span_delayed_bug( - body.span, - format!("unexpected coroutine type {coroutine_ty}"), - ); - return; + tcx.dcx().span_bug(body.span, format!("unexpected coroutine type {coroutine_ty}")); } }; diff --git a/compiler/rustc_mir_transform/src/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs index 8575f552f0ae7..03d952abad118 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -380,7 +380,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { LookupResult::Parent(None) => {} LookupResult::Parent(Some(_)) => { if !replace { - self.tcx.dcx().span_delayed_bug( + self.tcx.dcx().span_bug( terminator.source_info.span, format!("drop of untracked value {bb:?}"), ); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 6aacb0e17d576..676bc9db4a924 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3681,13 +3681,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { None } Res::SelfCtor(_) => { + // njn: remove comment? // We resolve `Self` in pattern position as an ident sometimes during recovery, // so delay a bug instead of ICEing. - self.r.dcx().span_delayed_bug( + self.r.dcx().span_bug( ident.span, "unexpected `SelfCtor` in pattern, expected identifier" ); - None } _ => span_bug!( ident.span, diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 1edf6b11fc343..79f423756fd7a 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -62,14 +62,12 @@ pub fn is_const_evaluatable<'tcx>( match unexpanded_ct.kind() { ty::ConstKind::Expr(_) => { + // njn: ? // FIXME(generic_const_exprs): we have a `ConstKind::Expr` which is fully concrete, // but currently it is not possible to evaluate `ConstKind::Expr` so we are unable // to tell if it is evaluatable or not. For now we just ICE until this is // implemented. - Err(NotConstEvaluatable::Error(tcx.dcx().span_delayed_bug( - span, - "evaluating `ConstKind::Expr` is not currently supported", - ))) + tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported"); } ty::ConstKind::Unevaluated(uv) => { let concrete = infcx.const_eval_resolve(param_env, uv, Some(span)); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 4f674ac7583c9..aa8bd5fdc866b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -3313,7 +3313,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { expected_trait_ref.self_ty().error_reported()?; let Some(found_trait_ty) = found_trait_ref.self_ty().no_bound_vars() else { - return Err(self.dcx().delayed_bug("bound vars outside binder")); + self.dcx().bug("bound vars outside binder"); }; let found_did = match *found_trait_ty.kind() { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 9eec60ea06c21..43f709352a293 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -172,7 +172,7 @@ fn do_normalize_predicates<'tcx>( // the normalized predicates. let errors = infcx.resolve_regions(&outlives_env); if !errors.is_empty() { - tcx.dcx().span_delayed_bug( + tcx.dcx().span_bug( span, format!("failed region resolution while normalizing {elaborated_env:?}: {errors:?}"), ); diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index 8b2e8b54aee64..c4110df45dbb4 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -100,7 +100,7 @@ fn implied_outlives_bounds<'a, 'tcx>( let errors = ocx.select_all_or_error(); if !errors.is_empty() { - infcx.dcx().span_delayed_bug( + infcx.dcx().span_bug( span, "implied_outlives_bounds failed to solve obligations from instantiation", ); diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 9c532ea4d8d85..dc5b62fbd1c72 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -645,7 +645,7 @@ pub fn compute_inherent_assoc_ty_args<'a, 'b, 'tcx>( match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, impl_ty, self_ty) { Ok(mut ok) => obligations.append(&mut ok.obligations), Err(_) => { - tcx.dcx().span_delayed_bug( + tcx.dcx().span_bug( cause.span, format!( "{self_ty:?} was a subtype of {impl_ty:?} during selection but now it is not" @@ -1190,11 +1190,10 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) | ImplSource::Builtin(BuiltinImplSource::TupleUnsizing, _) => { // These traits have no associated types. - selcx.tcx().dcx().span_delayed_bug( + selcx.tcx().dcx().span_bug( obligation.cause.span, format!("Cannot project an associated type from `{impl_source:?}`"), ); - return Err(()); } }; diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs index d533e69a4fa7f..a8d9b0f42d94e 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs @@ -82,7 +82,7 @@ where let value = infcx.commit_if_ok(|_| { let ocx = ObligationCtxt::new(infcx); let value = op(&ocx).map_err(|_| { - infcx.dcx().span_delayed_bug(span, format!("error performing operation: {name}")) + infcx.dcx().span_bug(span, format!("error performing operation: {name}")) })?; let errors = ocx.select_all_or_error(); if errors.is_empty() { diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs index fb09f094d37ae..12ee778ee05c6 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs @@ -190,10 +190,9 @@ where } } if !progress { - return Err(infcx.dcx().span_delayed_bug( - span, - format!("ambiguity processing {obligations:?} from {self:?}"), - )); + infcx + .dcx() + .span_bug(span, format!("ambiguity processing {obligations:?} from {self:?}")); } } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 96f8148bf7204..b00330d335e43 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -90,8 +90,7 @@ fn univariant_uninterned<'tcx>( let dl = cx.data_layout(); let pack = repr.pack; if pack.is_some() && repr.align.is_some() { - cx.tcx.dcx().delayed_bug("struct cannot be packed and aligned"); - return Err(cx.tcx.arena.alloc(LayoutError::Unknown(ty))); + cx.tcx.dcx().bug("struct cannot be packed and aligned"); } cx.univariant(dl, fields, repr, kind).ok_or_else(|| error(cx, LayoutError::SizeOverflow(ty))) diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 329cf32cad5ea..86c7551882aab 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -337,7 +337,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInAssocTypeCollector<'tcx> { .instantiate(self.0.tcx, impl_args) .visit_with(self); } else { - self.0.tcx.dcx().span_delayed_bug( + self.0.tcx.dcx().span_bug( self.0.tcx.def_span(assoc.def_id), "item had incorrect args", ); From 2903bbbc156fb9707b43038af6723844fd4ccf29 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 20 Feb 2024 09:36:28 +1100 Subject: [PATCH 09/11] Convert `bug`s back to `delayed_bug`s. This commit undoes some of the previous commit's mechanical changes, based on human judgment. --- .../rustc_borrowck/src/diagnostics/region_name.rs | 4 ++-- .../src/type_check/free_region_relations.rs | 6 +++++- .../rustc_const_eval/src/const_eval/machine.rs | 2 +- .../src/check/compare_impl_item.rs | 14 +++++++++++++- .../src/check/compare_impl_item/refine.rs | 9 +++++++++ compiler/rustc_hir_analysis/src/check/dropck.rs | 3 ++- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 8 ++------ compiler/rustc_hir_typeck/src/expr.rs | 3 +-- compiler/rustc_hir_typeck/src/intrinsicck.rs | 3 +++ compiler/rustc_hir_typeck/src/method/suggest.rs | 2 +- .../rustc_infer/src/infer/outlives/obligations.rs | 2 +- compiler/rustc_infer/src/infer/outlives/verify.rs | 6 +++++- compiler/rustc_infer/src/infer/relate/nll.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 4 +++- compiler/rustc_middle/src/util/bug.rs | 2 +- .../rustc_mir_build/src/build/expr/as_constant.rs | 10 +++++----- compiler/rustc_mir_build/src/thir/constant.rs | 10 +++++----- compiler/rustc_resolve/src/late.rs | 4 ++-- .../src/traits/const_evaluatable.rs | 9 ++++----- compiler/rustc_trait_selection/src/traits/mod.rs | 2 ++ .../rustc_trait_selection/src/traits/project.rs | 7 +++---- .../src/traits/query/type_op/custom.rs | 2 +- tests/ui/drop/missing-drop-method.rs | 4 ++++ tests/ui/drop/missing-drop-method.stderr | 11 +++++++++++ 24 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 tests/ui/drop/missing-drop-method.rs create mode 100644 tests/ui/drop/missing-drop-method.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index fea8c5a6de665..e228bef1139a6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -626,8 +626,8 @@ 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. + // 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:?}"), diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 0fc0417570594..897918fb0a45b 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -316,7 +316,11 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { .and(type_op::normalize::Normalize::new(ty)) .fully_perform(self.infcx, span) else { - tcx.dcx().span_bug(span, format!("failed to normalize {ty:?}")); + // 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; }; constraints.extend(c); diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 77744945b12fe..946ffc05cc14f 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -622,7 +622,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, ); // If this was a hard error, don't bother continuing evaluation. if is_error { - let guard: rustc_errors::ErrorGuaranteed = ecx + let guard = ecx .tcx .dcx() .span_delayed_bug(span, "The deny lint should have already errored"); diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 42a64d8670de7..435e251b130ea 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -734,6 +734,10 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( remapped_types.insert(def_id, ty::EarlyBinder::bind(ty)); } Err(err) => { + // 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:?}")); } @@ -914,7 +918,13 @@ impl<'tcx> ty::FallibleTypeFolder> for RemapHiddenTyRegions<'tcx> { .with_note(format!("hidden type inferred to be `{}`", self.ty)) .emit() } - _ => self.tcx.dcx().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); }; @@ -1273,6 +1283,8 @@ 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() { + // 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"); } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index da40d6a860e6b..7bdbab4325cbf 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -154,6 +154,9 @@ 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() { + // 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( @@ -162,10 +165,16 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( ); let errors = infcx.resolve_regions(&outlives_env); if !errors.is_empty() { + // 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 { + // 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)"); }; diff --git a/compiler/rustc_hir_analysis/src/check/dropck.rs b/compiler/rustc_hir_analysis/src/check/dropck.rs index 9b46b415491ff..82a6b6b6f2cb5 100644 --- a/compiler/rustc_hir_analysis/src/check/dropck.rs +++ b/compiler/rustc_hir_analysis/src/check/dropck.rs @@ -67,10 +67,11 @@ pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), Erro // already checked by coherence, but compilation may // not have been terminated. let span = tcx.def_span(drop_impl_did); - tcx.dcx().span_bug( + let reported = tcx.dcx().span_delayed_bug( span, format!("should have been rejected by coherence check: {dtor_self_type}"), ); + Err(reported) } } } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 81d8a51485f12..f03d0f8a88529 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1087,12 +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() { - // Unresolved type expression. - tcx.dcx().span_bug(item.span, format!("inference variables in {ty:?}")); - } 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. diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 0a636fa9eacd0..89cc46dc5ab80 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1315,9 +1315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // the LUB of the breaks (possibly ! if none); else, it // is nil. This makes sense because infinite loops // (which would have type !) are only possible iff we - // permit break with a value [1]. + // permit break with a value. if ctxt.coerce.is_none() && !ctxt.may_break { - // [1] self.dcx().span_bug(body.span, "no coercion, but loop may not break"); } ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| Ty::new_unit(self.tcx)) diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index fd62afbae96aa..9e3867e630d48 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -48,6 +48,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let to = normalize(to); trace!(?from, ?to); if from.has_non_region_infer() || to.has_non_region_infer() { + // 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_bug(span, "argument to transmute has inference variables"); } // Transmutes that are only changing lifetimes are always ok. diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 13f33abaa6451..005d217fdc44f 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -924,7 +924,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: item_span, .. })) => { - tcx.dcx().span_bug( + tcx.dcx().span_delayed_bug( *item_span, "auto trait is invoked with no method error, but no error reported?", ); diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 643fe83e89881..c0a99e5cc4177 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -303,7 +303,7 @@ where // Ignore this, we presume it will yield an error later, // since if a type variable is not resolved by this point // it never will be. - self.tcx.dcx().span_bug( + self.tcx.dcx().span_delayed_bug( origin.span(), format!("unresolved inference variable in outlives: {v:?}"), ); diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 515f44c914d07..3ef37bf3466f1 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -175,7 +175,11 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { // Ignore this, we presume it will yield an error later, since // if a type variable is not resolved by this point it never // will be. - self.tcx.dcx().bug(format!("unresolved inference variable in outlives: {v:?}")); + self.tcx + .dcx() + .delayed_bug(format!("unresolved inference variable in outlives: {v:?}")); + // Add a bound that never holds. + VerifyBound::AnyBound(vec![]) } } } diff --git a/compiler/rustc_infer/src/infer/relate/nll.rs b/compiler/rustc_infer/src/infer/relate/nll.rs index 4cc6457df7a30..87a1ae7bbacaf 100644 --- a/compiler/rustc_infer/src/infer/relate/nll.rs +++ b/compiler/rustc_infer/src/infer/relate/nll.rs @@ -422,7 +422,7 @@ where // Forbid inference variables in the RHS. self.infcx .dcx() - .span_bug(self.delegate.span(), format!("unexpected inference var {b:?}",)); + .span_bug(self.delegate.span(), format!("unexpected inference var {b:?}")); } // FIXME(invariance): see the related FIXME above. _ => self.infcx.super_combine_consts(self, a, b), diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 95d55a7081db5..3f539945841b6 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -356,7 +356,9 @@ impl<'tcx> TyCtxt<'tcx> { } let Some(item_id) = self.associated_item_def_ids(impl_did).first() else { - self.dcx().span_bug(self.def_span(impl_did), "Drop impl without drop function"); + self.dcx() + .span_delayed_bug(self.def_span(impl_did), "Drop impl without drop function"); + return; }; if let Some((old_item_id, _)) = dtor_candidate { diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs index dae6c0b9d68b8..a67ec99158210 100644 --- a/compiler/rustc_middle/src/util/bug.rs +++ b/compiler/rustc_middle/src/util/bug.rs @@ -42,7 +42,7 @@ fn opt_span_bug_fmt>( /// delayed bug, so what is the point of this? It exists to help us test the interaction of delayed /// bugs with the query system and incremental. pub fn trigger_delayed_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) { - tcx.dcx().span_bug( + tcx.dcx().span_delayed_bug( tcx.def_span(key), "delayed bug triggered by #[rustc_error(delayed_bug_from_inside_query)]", ); diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index d66540d8e79e4..a557f61b016bc 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -110,12 +110,12 @@ fn lit_to_mir_constant<'tcx>( let LitToConstInput { lit, ty, neg } = lit_input; let trunc = |n| { let param_ty = ty::ParamEnv::reveal_all().and(ty); - let width = tcx - .layout_of(param_ty) - .map_err(|_| { + let width = match tcx.layout_of(param_ty) { + Ok(layout) => layout.size, + Err(_) => { tcx.dcx().bug(format!("couldn't compute width of literal: {:?}", lit_input.lit)) - })? - .size; + } + }; trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = width.truncate(n); trace!("trunc result: {}", result); diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index 46580432f1328..65cc13286afc4 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -12,12 +12,12 @@ pub(crate) fn lit_to_const<'tcx>( let trunc = |n| { let param_ty = ParamEnv::reveal_all().and(ty); - let width = tcx - .layout_of(param_ty) - .map_err(|_| { + let width = match tcx.layout_of(param_ty) { + Ok(layout) => layout.size, + Err(_) => { tcx.dcx().bug(format!("couldn't compute width of literal: {:?}", lit_input.lit)) - })? - .size; + } + }; trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = width.truncate(n); trace!("trunc result: {}", result); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 676bc9db4a924..2f4da29133f1b 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3681,9 +3681,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { None } Res::SelfCtor(_) => { - // njn: remove comment? // We resolve `Self` in pattern position as an ident sometimes during recovery, - // so delay a bug instead of ICEing. + // so delay a bug instead of ICEing. (Note: is this no longer true? We now ICE. If + // this triggers, please convert to a delayed bug and add a test.) self.r.dcx().span_bug( ident.span, "unexpected `SelfCtor` in pattern, expected identifier" diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 79f423756fd7a..189e1ba54bc36 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -62,11 +62,10 @@ pub fn is_const_evaluatable<'tcx>( match unexpanded_ct.kind() { ty::ConstKind::Expr(_) => { - // njn: ? - // FIXME(generic_const_exprs): we have a `ConstKind::Expr` which is fully concrete, - // but currently it is not possible to evaluate `ConstKind::Expr` so we are unable - // to tell if it is evaluatable or not. For now we just ICE until this is - // implemented. + // FIXME(generic_const_exprs): we have a fully concrete `ConstKind::Expr`, but + // haven't implemented evaluating `ConstKind::Expr` yet, so we are unable to tell + // if it is evaluatable or not. As this is unreachable for now, we can simple ICE + // here. tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported"); } ty::ConstKind::Unevaluated(uv) => { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 43f709352a293..cac5379674790 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -172,6 +172,8 @@ fn do_normalize_predicates<'tcx>( // the normalized predicates. let errors = infcx.resolve_regions(&outlives_env); if !errors.is_empty() { + // @lcnr: Let's still ICE here for now. I want a test case + // for that. tcx.dcx().span_bug( span, format!("failed region resolution while normalizing {elaborated_env:?}: {errors:?}"), diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index dc5b62fbd1c72..f8de19043e1bc 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -647,9 +647,7 @@ pub fn compute_inherent_assoc_ty_args<'a, 'b, 'tcx>( Err(_) => { tcx.dcx().span_bug( cause.span, - format!( - "{self_ty:?} was a subtype of {impl_ty:?} during selection but now it is not" - ), + format!("{self_ty:?} was equal to {impl_ty:?} during selection but now it is not"), ); } } @@ -1190,10 +1188,11 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) | ImplSource::Builtin(BuiltinImplSource::TupleUnsizing, _) => { // These traits have no associated types. - selcx.tcx().dcx().span_bug( + selcx.tcx().dcx().span_delayed_bug( obligation.cause.span, format!("Cannot project an associated type from `{impl_source:?}`"), ); + return Err(()) } }; diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs index a8d9b0f42d94e..d533e69a4fa7f 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs @@ -82,7 +82,7 @@ where let value = infcx.commit_if_ok(|_| { let ocx = ObligationCtxt::new(infcx); let value = op(&ocx).map_err(|_| { - infcx.dcx().span_bug(span, format!("error performing operation: {name}")) + infcx.dcx().span_delayed_bug(span, format!("error performing operation: {name}")) })?; let errors = ocx.select_all_or_error(); if errors.is_empty() { diff --git a/tests/ui/drop/missing-drop-method.rs b/tests/ui/drop/missing-drop-method.rs new file mode 100644 index 0000000000000..5828fd6c06381 --- /dev/null +++ b/tests/ui/drop/missing-drop-method.rs @@ -0,0 +1,4 @@ +struct DropNoMethod; +impl Drop for DropNoMethod {} //~ ERROR not all trait items implemented, missing: `drop` + +fn main() {} diff --git a/tests/ui/drop/missing-drop-method.stderr b/tests/ui/drop/missing-drop-method.stderr new file mode 100644 index 0000000000000..1128f33e627b3 --- /dev/null +++ b/tests/ui/drop/missing-drop-method.stderr @@ -0,0 +1,11 @@ +error[E0046]: not all trait items implemented, missing: `drop` + --> $DIR/missing-drop-method.rs:2:1 + | +LL | impl Drop for DropNoMethod {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation + | + = help: implement the missing item: `fn drop(&mut self) { todo!() }` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0046`. From 3da200dc61fb2355672a7a9835fbbc27fc4a2ae4 Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 21 Feb 2024 09:58:03 +0800 Subject: [PATCH 10/11] print proper relative path for descriptive name check --- src/tools/tidy/src/ui_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 54a298492d93f..920fe16a9fcb4 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -162,7 +162,7 @@ pub fn check(path: &Path, bless: bool, bad: &mut bool) { if !remaining_issue_names.remove(stripped_path) { tidy_error!( bad, - "file `{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`", + "file `tests/{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`", issue_n = &test_name[1], ); } From 62e7414a194fb64715933d720e0505553c0834f7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 19 Feb 2024 16:07:39 +0000 Subject: [PATCH 11/11] Docs for extension proc-macro --- compiler/rustc_macros/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 619f93c8a533a..14e6a06839e13 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -41,6 +41,20 @@ pub fn symbols(input: TokenStream) -> TokenStream { symbols::symbols(input.into()).into() } +/// Derive an extension trait for a given impl block. The trait name +/// goes into the parenthesized args of the macro, for greppability. +/// For example: +/// ``` +/// use rustc_macros::extension; +/// #[extension(pub trait Foo)] +/// impl i32 { fn hello() {} } +/// ``` +/// +/// expands to: +/// ``` +/// pub trait Foo { fn hello(); } +/// impl Foo for i32 { fn hello() {} } +/// ``` #[proc_macro_attribute] pub fn extension(attr: TokenStream, input: TokenStream) -> TokenStream { extension::extension(attr, input)