Skip to content
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

Rollup of 13 pull requests #121078

Merged
merged 32 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
29fd82b
Be less confident when `dyn` suggestion is not checked for object safety
trevyn Jan 20, 2024
ccd6513
Additional doc links and explanation of `Wake`.
kpreid Oct 3, 2023
cef46f9
URL-encode chars in fragment.
kpreid Nov 6, 2023
a6c91f0
Remove the link.
kpreid Feb 11, 2024
114b0c7
std: enabling new netbsd (10) calls.
devnexen Dec 8, 2023
4ac90e2
Fix suggestion span for ?Sized
OdenShirataki Feb 11, 2024
fb5ed29
Clarify the lifetimes of allocations returned by the `Allocator` trait
Amanieu Dec 12, 2023
1c7ea30
implement `Default` for `AsciiChar`
joseluis Feb 13, 2024
8e9c8dd
Add information about allocation lifetime to Allocator::allocate
Amanieu Feb 13, 2024
f4e8863
Uplift TypeVisitableExt into rustc_type_ir
compiler-errors Jan 30, 2024
edc5053
Add assertions back to canonicalizer
compiler-errors Jan 30, 2024
7e80867
Move visitable bounds up into interner
compiler-errors Feb 13, 2024
7ec9601
Add test.
cjgillot Feb 13, 2024
a97e4af
Fix handling of adjustment casts.
cjgillot Feb 13, 2024
24b52fd
Do not point at `#[allow(_)]` as the reason for compat lint triggering
estebank Feb 13, 2024
71f2e3a
Optimize `delayed_bug` handling.
nnethercote Feb 13, 2024
b06f891
Fix typos in `OneLock` doc
IgorLaborieWefox Feb 14, 2024
ee88f34
Fix two UI tests with incorrect directive / invalid revision
jieyouxu Feb 10, 2024
05849e8
Use fewer delayed bugs.
nnethercote Feb 14, 2024
5d114f3
Rollup merge of #116387 - kpreid:wake-doc, r=cuviper
oli-obk Feb 14, 2024
1c7a999
Rollup merge of #118738 - devnexen:netbsd10_update, r=cuviper
oli-obk Feb 14, 2024
407de0e
Rollup merge of #118890 - Amanieu:allocator-lifetime, r=Mark-Simulacrum
oli-obk Feb 14, 2024
cc54612
Rollup merge of #120498 - compiler-errors:type-flags, r=lcnr
oli-obk Feb 14, 2024
c4371a7
Rollup merge of #120530 - trevyn:issue-116434, r=compiler-errors
oli-obk Feb 14, 2024
f3e66ed
Rollup merge of #120915 - OdenShirataki:master, r=fmease
oli-obk Feb 14, 2024
bad2cb0
Rollup merge of #121015 - nnethercote:opt-delayed-bug, r=oli-obk
oli-obk Feb 14, 2024
c1a8021
Rollup merge of #121024 - joseluis:feat-asciichar-default, r=scottmcm
oli-obk Feb 14, 2024
93bc340
Rollup merge of #121039 - cjgillot:gvn-adjust, r=compiler-errors
oli-obk Feb 14, 2024
f77870e
Rollup merge of #121045 - jieyouxu:fix-ui-tests, r=oli-obk
oli-obk Feb 14, 2024
9e31121
Rollup merge of #121049 - estebank:issue-121009, r=fmease
oli-obk Feb 14, 2024
638f525
Rollup merge of #121071 - nnethercote:fewer-delayed-bugs, r=oli-obk
oli-obk Feb 14, 2024
96635da
Rollup merge of #121073 - IgorLaborieWefox:patch-1, r=workingjubilee
oli-obk Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
}
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
ExprKind::Err => {
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
}
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),

ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
match block {
Some(block) => self.lower_block_expr(block),
None => self.expr_err(span, self.dcx().span_delayed_bug(span, "no block")),
None => self.expr_err(span, self.dcx().has_errors().unwrap()),
}
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,9 +1285,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
let kind = match &t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => {
hir::TyKind::Err(self.dcx().span_delayed_bug(t.span, "TyKind::Err lowered"))
}
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
// Lower the anonymous structs or unions in a nested lowering context.
//
// ```
Expand Down
20 changes: 8 additions & 12 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,14 @@ struct CfgChecker<'a, 'tcx> {
impl<'a, 'tcx> CfgChecker<'a, 'tcx> {
#[track_caller]
fn fail(&self, location: Location, msg: impl AsRef<str>) {
let span = self.body.source_info(location).span;
// We use `span_delayed_bug` as we might see broken MIR when other errors have already
// occurred.
self.tcx.dcx().span_delayed_bug(
span,
format!(
"broken MIR in {:?} ({}) at {:?}:\n{}",
self.body.source.instance,
self.when,
location,
msg.as_ref()
),
// We might see broken MIR when other errors have already occurred.
assert!(
self.tcx.dcx().has_errors().is_some(),
"broken MIR in {:?} ({}) at {:?}:\n{}",
self.body.source.instance,
self.when,
location,
msg.as_ref(),
);
}

Expand Down
39 changes: 27 additions & 12 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,9 @@ impl DiagCtxtInner {
self.future_breakage_diagnostics.push(diagnostic.clone());
}

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

if is_error {
// If we have any delayed bugs recorded, we can discard them
// because they won't be used. (This should only occur if there
// have been no errors previously emitted, because we don't add
// new delayed bugs once the first error is emitted.)
if !self.delayed_bugs.is_empty() {
assert_eq!(self.lint_err_guars.len() + self.err_guars.len(), 0);
self.delayed_bugs.clear();
self.delayed_bugs.shrink_to_fit();
}

// This `unchecked_error_guaranteed` is valid. It is where the
// `ErrorGuaranteed` for errors and lint errors originates.
#[allow(deprecated)]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_expand/src/mbe/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ pub(super) fn failed_to_match_macro<'cx>(
if try_success_result.is_ok() {
// Nonterminal parser recovery might turn failed matches into successful ones,
// but for that it must have emitted an error already
tracker
.cx
.dcx()
.span_delayed_bug(sp, "Macro matching returned a success on the second try");
assert!(
tracker.cx.dcx().has_errors().is_some(),
"Macro matching returned a success on the second try"
);
}

if let Some(result) = tracker.result {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
if self_ty.span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
"use `dyn`",
"if this is an object-safe trait, use `dyn`",
sugg,
Applicability::MachineApplicable,
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// since we should have emitten an error for them earlier, and they will
// not be well-formed!
if polarity == ty::ImplPolarity::Negative {
self.tcx().dcx().span_delayed_bug(
binding.span,
assert!(
self.tcx().dcx().has_errors().is_some(),
"negative trait bounds should not have bindings",
);
continue;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,13 +1865,13 @@ fn check_variances_for_type_defn<'tcx>(
let hir_param = &hir_generics.params[index];

if ty_param.def_id != hir_param.def_id.into() {
// valid programs always have lifetimes before types in the generic parameter list
// Valid programs always have lifetimes before types in the generic parameter list.
// ty_generics are normalized to be in this required order, and variances are built
// from ty generics, not from hir generics. but we need hir generics to get
// a span out
// a span out.
//
// if they aren't in the same order, then the user has written invalid code, and already
// got an error about it (or I'm wrong about this)
// If they aren't in the same order, then the user has written invalid code, and already
// got an error about it (or I'm wrong about this).
tcx.dcx().span_delayed_bug(
hir_param.span,
"hir generics and ty generics in different order",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub(super) fn check_item(

(_, _, Unsafety::Unsafe, Negative) => {
// Reported in AST validation
tcx.dcx().span_delayed_bug(tcx.def_span(def_id), "unsafe negative impl");
assert!(tcx.dcx().has_errors().is_some(), "unsafe negative impl");
Ok(())
}
(_, _, Unsafety::Normal, Negative)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::Never
| ty::Dynamic(_, _, ty::DynStar)
| ty::Error(_) => {
let reported = self
let guar = self
.dcx()
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
return Err(reported);
return Err(guar);
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
if base_ty.is_none() {
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
// that isn't in the type table. We assume more relevant errors have already been
// emitted, so we delay an ICE if none have. (#64638)
self.tcx().dcx().span_delayed_bug(e.span, format!("bad base: `{base:?}`"));
// emitted. (#64638)
assert!(self.tcx().dcx().has_errors().is_some(), "bad base: `{base:?}`");
}
if let Some(base_ty) = base_ty
&& let ty::Ref(_, base_ty_inner, _) = *base_ty.kind()
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,12 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
}

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

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ where
self.components_must_outlive(origin, subcomponents, region, category);
}
Component::UnresolvedInferenceVariable(v) => {
// 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
// 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(
origin.span(),
format!("unresolved inference variable in outlives: {v:?}"),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
self.bound_from_components(components, visited)
}
Component::UnresolvedInferenceVariable(v) => {
// 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
// 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
// Add a bound that never holds.
VerifyBound::AnyBound(vec![])
}
}
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,13 @@ pub fn check_ast_node_inner<'a, T: EarlyLintPass>(
// If not, that means that we somehow buffered a lint for a node id
// that was not lint-checked (perhaps it doesn't exist?). This is a bug.
for (id, lints) in cx.context.buffered.map {
for early_lint in lints {
sess.dcx().span_delayed_bug(
early_lint.span,
format!(
"failed to process buffered lint here (dummy = {})",
id == ast::DUMMY_NODE_ID
),
if !lints.is_empty() {
assert!(
sess.dcx().has_errors().is_some(),
"failed to process buffered lint here (dummy = {})",
id == ast::DUMMY_NODE_ID
);
break;
}
}
}
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ pub fn explain_lint_level_source(
err: &mut Diagnostic,
) {
let name = lint.name_lower();
if let Level::Allow = level {
// Do not point at `#[allow(compat_lint)]` as the reason for a compatibility lint
// triggering. (#121009)
return;
}
match src {
LintLevelSource::Default => {
err.note_once(format!("`#[{}({})]` on by default", level.as_str(), name));
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ impl<'tcx> IntoKind for Const<'tcx> {
}
}

impl<'tcx> rustc_type_ir::visit::Flags for Const<'tcx> {
fn flags(&self) -> TypeFlags {
self.0.flags
}

fn outer_exclusive_binder(&self) -> rustc_type_ir::DebruijnIndex {
self.0.outer_exclusive_binder
}
}

impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
fn ty(self) -> Ty<'tcx> {
self.ty()
Expand Down Expand Up @@ -63,11 +73,13 @@ impl<'tcx> Const<'tcx> {
self.0.kind
}

// FIXME(compiler-errors): Think about removing this.
#[inline]
pub fn flags(self) -> TypeFlags {
self.0.flags
}

// FIXME(compiler-errors): Think about removing this.
#[inline]
pub fn outer_exclusive_binder(self) -> ty::DebruijnIndex {
self.0.outer_exclusive_binder
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::ty::{
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Const, ConstData, GenericParamDefKind,
ImplPolarity, List, ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate,
PredicateKind, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
Visibility,
TypeVisitable, Visibility,
};
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
use rustc_ast::{self as ast, attr};
Expand Down Expand Up @@ -87,7 +87,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type GenericArg = ty::GenericArg<'tcx>;
type Term = ty::Term<'tcx>;

type Binder<T> = Binder<'tcx, T>;
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
type BoundVars = &'tcx List<ty::BoundVariableKind>;
type BoundVar = ty::BoundVariableKind;
type CanonicalVars = CanonicalVarInfos<'tcx>;

type Ty = Ty<'tcx>;
Expand Down Expand Up @@ -151,6 +153,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
) -> Self::Const {
Const::new_bound(self, debruijn, var, ty)
}

fn expect_error_or_delayed_bug() {
let has_errors = ty::tls::with(|tcx| tcx.dcx().has_errors_or_lint_errors_or_delayed_bugs());
assert!(has_errors.is_some());
}
}

type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ impl<'tcx> IntoKind for Ty<'tcx> {
}
}

impl<'tcx> rustc_type_ir::visit::Flags for Ty<'tcx> {
fn flags(&self) -> TypeFlags {
self.0.flags
}

fn outer_exclusive_binder(&self) -> DebruijnIndex {
self.0.outer_exclusive_binder
}
}

impl EarlyParamRegion {
/// Does this early bound region have a name? Early bound regions normally
/// always have names except when using anonymous lifetimes (`'_`).
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_middle/src/ty/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,30 @@ pub struct Predicate<'tcx>(
pub(super) Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
);

impl<'tcx> rustc_type_ir::visit::Flags for Predicate<'tcx> {
fn flags(&self) -> TypeFlags {
self.0.flags
}

fn outer_exclusive_binder(&self) -> ty::DebruijnIndex {
self.0.outer_exclusive_binder
}
}

impl<'tcx> Predicate<'tcx> {
/// Gets the inner `ty::Binder<'tcx, PredicateKind<'tcx>>`.
#[inline]
pub fn kind(self) -> ty::Binder<'tcx, PredicateKind<'tcx>> {
self.0.internee
}

// FIXME(compiler-errors): Think about removing this.
#[inline(always)]
pub fn flags(self) -> TypeFlags {
self.0.flags
}

// FIXME(compiler-errors): Think about removing this.
#[inline(always)]
pub fn outer_exclusive_binder(self) -> DebruijnIndex {
self.0.outer_exclusive_binder
Expand Down
Loading
Loading