Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Feb 19, 2024
1 parent 3035ada commit 5f00f10
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 33 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"));
}
Expand Down Expand Up @@ -914,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().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 @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)");
};

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/check/dropck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_hir_typeck/src/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ 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_bug(span, "argument to transmute has inference variables");
// 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, "argument to transmute has inference variables");
}
// Transmutes that are only changing lifetimes are always ok.
if from == to {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"),
);
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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![])
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_infer/src/infer/relate/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,7 @@ where
match b.kind() {
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
// Forbid inference variables in the RHS.
self.infcx
.dcx()
.span_bug(self.delegate.span(), format!("unexpected inference var {b:?}",));
self.infcx.dcx().bug(format!("unexpected inference var {b:?}"));
}
// FIXME(invariance): see the related FIXME above.
_ => self.infcx.super_combine_consts(self, a, b),
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/build/expr/as_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ fn lit_to_mir_constant<'tcx>(
let param_ty = ty::ParamEnv::reveal_all().and(ty);
let width = tcx
.layout_of(param_ty)
.map_err(|_| {
tcx.dcx().bug(format!("couldn't compute width of literal: {:?}", lit_input.lit))
})?
.expect(&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);
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/thir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub(crate) fn lit_to_const<'tcx>(
let param_ty = ParamEnv::reveal_all().and(ty);
let width = tcx
.layout_of(param_ty)
.map_err(|_| {
tcx.dcx().bug(format!("couldn't compute width of literal: {:?}", lit_input.lit))
})?
.expect(&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);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,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:?}"),
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,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"),
);
}
}
Expand Down Expand Up @@ -2007,10 +2005,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(())
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/drop/missing-drop-method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct DropNoMethod;
impl Drop for DropNoMethod {} //~ ERROR not all trait items implemented, missing: `drop`

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/drop/missing-drop-method.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 5f00f10

Please sign in to comment.