-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Convert delayed_bug
s to bug
s.
#121208
Convert delayed_bug
s to bug
s.
#121208
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the original UI test for #82126 does not trigger this anymore, so we should get a new test if it's still reachable. Please update the comment before merge 2 |
||
hir_arg.span(), | ||
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"), | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 |
||
break; | ||
.span_bug(body.span, "found more normalized_input_ty than local_decls"); | ||
} | ||
|
||
// In MIR, argument N is stored in local N+1. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 not as confident as I maybe should be, but I would really like a test for cases where this is triggered if reachable. |
||
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 |
||
} else { | ||
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us, | ||
// so this should be unreachable. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 |
||
self.body.span, | ||
format!( | ||
"broken MIR in {:?} ({}):\ninvalid source scope {:?}", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 |
||
}; | ||
|
||
self.one_bound_for_assoc_item( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 |
||
}; | ||
|
||
// 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 we already check the opaque in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_borrowck/region_infer/opaque_types/fn.check_opaque_type_well_formed.html |
||
span, | ||
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"), | ||
)); | ||
); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:?}")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expect that to be reachable but only undetected because we lack tests for RPITIT. would like to merge it to get a regression test here, with a comment that this has been changed from |
||
} | ||
} | ||
} | ||
|
@@ -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); | ||
}; | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very much sure it should be reachable, should get a test here 🤷 I guess keep it as a |
||
"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 = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk about these three, I'd land them as |
||
}; | ||
|
||
// For quicker lookup, use an `IndexSet` (we don't use one earlier because | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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()); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
ty.needs_drop(tcx, tcx.param_env(item.owner_id)) | ||||
} | ||||
}; | ||||
// All fields (except for possibly the last) should be sized. | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretty sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
param.span, | ||
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"), | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { | |
} | ||
} | ||
|
||
self.tcx.dcx().span_delayed_bug( | ||
self.tcx.dcx().span_bug( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 |
||
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:?}")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 |
||
} | ||
|
||
#[instrument(level = "debug", skip(self))] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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?")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 |
||
} | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1/2 fairly confident that this is unreachable and expect anything that would hit this to be at least somewhat easy to minimize |
||
self.dcx() | ||
.span_bug(expr.span, "expression with never type wound up being adjusted"); | ||
} | ||
|
||
let adj_ty = self.next_ty_var(TypeVariableOrigin { | ||
|
@@ -1322,10 +1315,9 @@ 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_delayed_bug(body.span, "no coercion, but loop may not break"); | ||
self.dcx().span_bug(body.span, "no coercion, but loop may not break"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 what's that |
||
} | ||
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| Ty::new_unit(self.tcx)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +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_delayed_bug(span, "argument to transmute has inference variables"); | ||
return; | ||
// 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is theoretically reachable, maybe the following is enough? fn unconstrained<T: ?Sized>() -> *const T {
todo!()
}
fn main() {
let x = unconstrained();
let mut y = unconstrained();
y = unsafe { std::mem::transmute(&x) };
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't trigger. I will convert back to |
||
} | ||
// Transmutes that are only changing lifetimes are always ok. | ||
if from == to { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 |
||
} | ||
} | ||
} | ||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably reachable with |
||
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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷 i'd keep this as a span_bug |
||
} | ||
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => { | ||
let e = report_unexpected_res(res); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2