Skip to content

Commit 340bb19

Browse files
committed
Auto merge of #121078 - oli-obk:rollup-p11zsav, r=oli-obk
Rollup of 13 pull requests Successful merges: - #116387 (Additional doc links and explanation of `Wake`.) - #118738 (Netbsd10 update) - #118890 (Clarify the lifetimes of allocations returned by the `Allocator` trait) - #120498 (Uplift `TypeVisitableExt` into `rustc_type_ir`) - #120530 (Be less confident when `dyn` suggestion is not checked for object safety) - #120915 (Fix suggestion span for `?Sized` when param type has default) - #121015 (Optimize `delayed_bug` handling.) - #121024 (implement `Default` for `AsciiChar`) - #121039 (Correctly compute adjustment casts in GVN) - #121045 (Fix two UI tests with incorrect directive / invalid revision) - #121049 (Do not point at `#[allow(_)]` as the reason for compat lint triggering) - #121071 (Use fewer delayed bugs.) - #121073 (Fix typos in `OneLock` doc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 81b757c + 96635da commit 340bb19

File tree

93 files changed

+966
-589
lines changed

Some content is hidden

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

93 files changed

+966
-589
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
323323
)
324324
}
325325
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
326-
ExprKind::Err => {
327-
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
328-
}
326+
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
329327
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
330328

331329
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

compiler/rustc_ast_lowering/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10681068
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
10691069
match block {
10701070
Some(block) => self.lower_block_expr(block),
1071-
None => self.expr_err(span, self.dcx().span_delayed_bug(span, "no block")),
1071+
None => self.expr_err(span, self.dcx().has_errors().unwrap()),
10721072
}
10731073
}
10741074

compiler/rustc_ast_lowering/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12851285
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
12861286
let kind = match &t.kind {
12871287
TyKind::Infer => hir::TyKind::Infer,
1288-
TyKind::Err => {
1289-
hir::TyKind::Err(self.dcx().span_delayed_bug(t.span, "TyKind::Err lowered"))
1290-
}
1288+
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
12911289
// Lower the anonymous structs or unions in a nested lowering context.
12921290
//
12931291
// ```

compiler/rustc_const_eval/src/transform/validate.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,14 @@ struct CfgChecker<'a, 'tcx> {
117117
impl<'a, 'tcx> CfgChecker<'a, 'tcx> {
118118
#[track_caller]
119119
fn fail(&self, location: Location, msg: impl AsRef<str>) {
120-
let span = self.body.source_info(location).span;
121-
// We use `span_delayed_bug` as we might see broken MIR when other errors have already
122-
// occurred.
123-
self.tcx.dcx().span_delayed_bug(
124-
span,
125-
format!(
126-
"broken MIR in {:?} ({}) at {:?}:\n{}",
127-
self.body.source.instance,
128-
self.when,
129-
location,
130-
msg.as_ref()
131-
),
120+
// We might see broken MIR when other errors have already occurred.
121+
assert!(
122+
self.tcx.dcx().has_errors().is_some(),
123+
"broken MIR in {:?} ({}) at {:?}:\n{}",
124+
self.body.source.instance,
125+
self.when,
126+
location,
127+
msg.as_ref(),
132128
);
133129
}
134130

compiler/rustc_errors/src/lib.rs

+27-12
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ impl DiagCtxtInner {
13151315
self.future_breakage_diagnostics.push(diagnostic.clone());
13161316
}
13171317

1318+
// Note that because this comes before the `match` below,
1319+
// `-Zeagerly-emit-delayed-bugs` continues to work even after we've
1320+
// issued an error and stopped recording new delayed bugs.
13181321
if diagnostic.level == DelayedBug && self.flags.eagerly_emit_delayed_bugs {
13191322
diagnostic.level = Error;
13201323
}
@@ -1326,18 +1329,20 @@ impl DiagCtxtInner {
13261329
diagnostic.level = Bug;
13271330
}
13281331
DelayedBug => {
1329-
// FIXME(eddyb) this should check for `has_errors` and stop pushing
1330-
// once *any* errors were emitted (and truncate `delayed_bugs`
1331-
// when an error is first emitted, also), but maybe there's a case
1332-
// in which that's not sound? otherwise this is really inefficient.
1333-
let backtrace = std::backtrace::Backtrace::capture();
1334-
// This `unchecked_error_guaranteed` is valid. It is where the
1335-
// `ErrorGuaranteed` for delayed bugs originates.
1336-
#[allow(deprecated)]
1337-
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
1338-
self.delayed_bugs
1339-
.push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar));
1340-
return Some(guar);
1332+
// If we have already emitted at least one error, we don't need
1333+
// to record the delayed bug, because it'll never be used.
1334+
return if let Some(guar) = self.has_errors_or_lint_errors() {
1335+
Some(guar)
1336+
} else {
1337+
let backtrace = std::backtrace::Backtrace::capture();
1338+
// This `unchecked_error_guaranteed` is valid. It is where the
1339+
// `ErrorGuaranteed` for delayed bugs originates.
1340+
#[allow(deprecated)]
1341+
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
1342+
self.delayed_bugs
1343+
.push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar));
1344+
Some(guar)
1345+
};
13411346
}
13421347
Warning if !self.flags.can_emit_warnings => {
13431348
if diagnostic.has_future_breakage() {
@@ -1403,6 +1408,16 @@ impl DiagCtxtInner {
14031408
}
14041409

14051410
if is_error {
1411+
// If we have any delayed bugs recorded, we can discard them
1412+
// because they won't be used. (This should only occur if there
1413+
// have been no errors previously emitted, because we don't add
1414+
// new delayed bugs once the first error is emitted.)
1415+
if !self.delayed_bugs.is_empty() {
1416+
assert_eq!(self.lint_err_guars.len() + self.err_guars.len(), 0);
1417+
self.delayed_bugs.clear();
1418+
self.delayed_bugs.shrink_to_fit();
1419+
}
1420+
14061421
// This `unchecked_error_guaranteed` is valid. It is where the
14071422
// `ErrorGuaranteed` for errors and lint errors originates.
14081423
#[allow(deprecated)]

compiler/rustc_expand/src/mbe/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pub(super) fn failed_to_match_macro<'cx>(
3434
if try_success_result.is_ok() {
3535
// Nonterminal parser recovery might turn failed matches into successful ones,
3636
// but for that it must have emitted an error already
37-
tracker
38-
.cx
39-
.dcx()
40-
.span_delayed_bug(sp, "Macro matching returned a success on the second try");
37+
assert!(
38+
tracker.cx.dcx().has_errors().is_some(),
39+
"Macro matching returned a success on the second try"
40+
);
4141
}
4242

4343
if let Some(result) = tracker.result {

compiler/rustc_hir_analysis/src/astconv/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
243243
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
244244
if self_ty.span.can_be_used_for_suggestions() {
245245
lint.multipart_suggestion_verbose(
246-
"use `dyn`",
246+
"if this is an object-safe trait, use `dyn`",
247247
sugg,
248248
Applicability::MachineApplicable,
249249
);

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
758758
// since we should have emitten an error for them earlier, and they will
759759
// not be well-formed!
760760
if polarity == ty::ImplPolarity::Negative {
761-
self.tcx().dcx().span_delayed_bug(
762-
binding.span,
761+
assert!(
762+
self.tcx().dcx().has_errors().is_some(),
763763
"negative trait bounds should not have bindings",
764764
);
765765
continue;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1865,13 +1865,13 @@ fn check_variances_for_type_defn<'tcx>(
18651865
let hir_param = &hir_generics.params[index];
18661866

18671867
if ty_param.def_id != hir_param.def_id.into() {
1868-
// valid programs always have lifetimes before types in the generic parameter list
1868+
// Valid programs always have lifetimes before types in the generic parameter list.
18691869
// ty_generics are normalized to be in this required order, and variances are built
18701870
// from ty generics, not from hir generics. but we need hir generics to get
1871-
// a span out
1871+
// a span out.
18721872
//
1873-
// if they aren't in the same order, then the user has written invalid code, and already
1874-
// got an error about it (or I'm wrong about this)
1873+
// If they aren't in the same order, then the user has written invalid code, and already
1874+
// got an error about it (or I'm wrong about this).
18751875
tcx.dcx().span_delayed_bug(
18761876
hir_param.span,
18771877
"hir generics and ty generics in different order",

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(super) fn check_item(
8585

8686
(_, _, Unsafety::Unsafe, Negative) => {
8787
// Reported in AST validation
88-
tcx.dcx().span_delayed_bug(tcx.def_span(def_id), "unsafe negative impl");
88+
assert!(tcx.dcx().has_errors().is_some(), "unsafe negative impl");
8989
Ok(())
9090
}
9191
(_, _, Unsafety::Normal, Negative)

compiler/rustc_hir_typeck/src/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139139
| ty::Never
140140
| ty::Dynamic(_, _, ty::DynStar)
141141
| ty::Error(_) => {
142-
let reported = self
142+
let guar = self
143143
.dcx()
144144
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
145-
return Err(reported);
145+
return Err(guar);
146146
}
147147
})
148148
}

compiler/rustc_hir_typeck/src/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
221221
if base_ty.is_none() {
222222
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
223223
// that isn't in the type table. We assume more relevant errors have already been
224-
// emitted, so we delay an ICE if none have. (#64638)
225-
self.tcx().dcx().span_delayed_bug(e.span, format!("bad base: `{base:?}`"));
224+
// emitted. (#64638)
225+
assert!(self.tcx().dcx().has_errors().is_some(), "bad base: `{base:?}`");
226226
}
227227
if let Some(base_ty) = base_ty
228228
&& let ty::Ref(_, base_ty_inner, _) = *base_ty.kind()

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,12 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
802802
}
803803

804804
// Errors in earlier passes can yield error variables without
805-
// resolution errors here; delay ICE in favor of those errors.
806-
self.tcx().dcx().span_delayed_bug(
807-
self.var_infos[node_idx].origin.span(),
808-
format!(
809-
"collect_error_for_expanding_node() could not find \
810-
error for var {node_idx:?} in universe {node_universe:?}, lower_bounds={lower_bounds:#?}, \
811-
upper_bounds={upper_bounds:#?}"
812-
),
805+
// resolution errors here; ICE if no errors have been emitted yet.
806+
assert!(
807+
self.tcx().dcx().has_errors().is_some(),
808+
"collect_error_for_expanding_node() could not find error for var {node_idx:?} in \
809+
universe {node_universe:?}, lower_bounds={lower_bounds:#?}, \
810+
upper_bounds={upper_bounds:#?}",
813811
);
814812
}
815813

compiler/rustc_infer/src/infer/outlives/obligations.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ where
300300
self.components_must_outlive(origin, subcomponents, region, category);
301301
}
302302
Component::UnresolvedInferenceVariable(v) => {
303-
// ignore this, we presume it will yield an error
304-
// later, since if a type variable is not resolved by
305-
// this point it never will be
303+
// Ignore this, we presume it will yield an error later,
304+
// since if a type variable is not resolved by this point
305+
// it never will be.
306306
self.tcx.dcx().span_delayed_bug(
307307
origin.span(),
308308
format!("unresolved inference variable in outlives: {v:?}"),

compiler/rustc_infer/src/infer/outlives/verify.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
172172
self.bound_from_components(components, visited)
173173
}
174174
Component::UnresolvedInferenceVariable(v) => {
175-
// ignore this, we presume it will yield an error
176-
// later, since if a type variable is not resolved by
177-
// this point it never will be
175+
// Ignore this, we presume it will yield an error later, since
176+
// if a type variable is not resolved by this point it never
177+
// will be.
178178
self.tcx
179179
.dcx()
180180
.delayed_bug(format!("unresolved inference variable in outlives: {v:?}"));
181-
// add a bound that never holds
181+
// Add a bound that never holds.
182182
VerifyBound::AnyBound(vec![])
183183
}
184184
}

compiler/rustc_lint/src/early.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,13 @@ pub fn check_ast_node_inner<'a, T: EarlyLintPass>(
431431
// If not, that means that we somehow buffered a lint for a node id
432432
// that was not lint-checked (perhaps it doesn't exist?). This is a bug.
433433
for (id, lints) in cx.context.buffered.map {
434-
for early_lint in lints {
435-
sess.dcx().span_delayed_bug(
436-
early_lint.span,
437-
format!(
438-
"failed to process buffered lint here (dummy = {})",
439-
id == ast::DUMMY_NODE_ID
440-
),
434+
if !lints.is_empty() {
435+
assert!(
436+
sess.dcx().has_errors().is_some(),
437+
"failed to process buffered lint here (dummy = {})",
438+
id == ast::DUMMY_NODE_ID
441439
);
440+
break;
442441
}
443442
}
444443
}

compiler/rustc_middle/src/lint.rs

+5
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ pub fn explain_lint_level_source(
207207
err: &mut Diagnostic,
208208
) {
209209
let name = lint.name_lower();
210+
if let Level::Allow = level {
211+
// Do not point at `#[allow(compat_lint)]` as the reason for a compatibility lint
212+
// triggering. (#121009)
213+
return;
214+
}
210215
match src {
211216
LintLevelSource::Default => {
212217
err.note_once(format!("`#[{}({})]` on by default", level.as_str(), name));

compiler/rustc_middle/src/ty/consts.rs

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ impl<'tcx> IntoKind for Const<'tcx> {
3535
}
3636
}
3737

38+
impl<'tcx> rustc_type_ir::visit::Flags for Const<'tcx> {
39+
fn flags(&self) -> TypeFlags {
40+
self.0.flags
41+
}
42+
43+
fn outer_exclusive_binder(&self) -> rustc_type_ir::DebruijnIndex {
44+
self.0.outer_exclusive_binder
45+
}
46+
}
47+
3848
impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
3949
fn ty(self) -> Ty<'tcx> {
4050
self.ty()
@@ -63,11 +73,13 @@ impl<'tcx> Const<'tcx> {
6373
self.0.kind
6474
}
6575

76+
// FIXME(compiler-errors): Think about removing this.
6677
#[inline]
6778
pub fn flags(self) -> TypeFlags {
6879
self.0.flags
6980
}
7081

82+
// FIXME(compiler-errors): Think about removing this.
7183
#[inline]
7284
pub fn outer_exclusive_binder(self) -> ty::DebruijnIndex {
7385
self.0.outer_exclusive_binder

compiler/rustc_middle/src/ty/context.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ty::{
2828
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Const, ConstData, GenericParamDefKind,
2929
ImplPolarity, List, ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate,
3030
PredicateKind, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
31-
Visibility,
31+
TypeVisitable, Visibility,
3232
};
3333
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
3434
use rustc_ast::{self as ast, attr};
@@ -87,7 +87,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
8787
type GenericArg = ty::GenericArg<'tcx>;
8888
type Term = ty::Term<'tcx>;
8989

90-
type Binder<T> = Binder<'tcx, T>;
90+
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
91+
type BoundVars = &'tcx List<ty::BoundVariableKind>;
92+
type BoundVar = ty::BoundVariableKind;
9193
type CanonicalVars = CanonicalVarInfos<'tcx>;
9294

9395
type Ty = Ty<'tcx>;
@@ -151,6 +153,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
151153
) -> Self::Const {
152154
Const::new_bound(self, debruijn, var, ty)
153155
}
156+
157+
fn expect_error_or_delayed_bug() {
158+
let has_errors = ty::tls::with(|tcx| tcx.dcx().has_errors_or_lint_errors_or_delayed_bugs());
159+
assert!(has_errors.is_some());
160+
}
154161
}
155162

156163
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;

compiler/rustc_middle/src/ty/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@ impl<'tcx> IntoKind for Ty<'tcx> {
504504
}
505505
}
506506

507+
impl<'tcx> rustc_type_ir::visit::Flags for Ty<'tcx> {
508+
fn flags(&self) -> TypeFlags {
509+
self.0.flags
510+
}
511+
512+
fn outer_exclusive_binder(&self) -> DebruijnIndex {
513+
self.0.outer_exclusive_binder
514+
}
515+
}
516+
507517
impl EarlyParamRegion {
508518
/// Does this early bound region have a name? Early bound regions normally
509519
/// always have names except when using anonymous lifetimes (`'_`).

compiler/rustc_middle/src/ty/predicate.rs

+12
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,30 @@ pub struct Predicate<'tcx>(
2929
pub(super) Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
3030
);
3131

32+
impl<'tcx> rustc_type_ir::visit::Flags for Predicate<'tcx> {
33+
fn flags(&self) -> TypeFlags {
34+
self.0.flags
35+
}
36+
37+
fn outer_exclusive_binder(&self) -> ty::DebruijnIndex {
38+
self.0.outer_exclusive_binder
39+
}
40+
}
41+
3242
impl<'tcx> Predicate<'tcx> {
3343
/// Gets the inner `ty::Binder<'tcx, PredicateKind<'tcx>>`.
3444
#[inline]
3545
pub fn kind(self) -> ty::Binder<'tcx, PredicateKind<'tcx>> {
3646
self.0.internee
3747
}
3848

49+
// FIXME(compiler-errors): Think about removing this.
3950
#[inline(always)]
4051
pub fn flags(self) -> TypeFlags {
4152
self.0.flags
4253
}
4354

55+
// FIXME(compiler-errors): Think about removing this.
4456
#[inline(always)]
4557
pub fn outer_exclusive_binder(self) -> DebruijnIndex {
4658
self.0.outer_exclusive_binder

0 commit comments

Comments
 (0)