Skip to content

Commit

Permalink
Rollup merge of #74399 - mark-i-m:ty-err-4, r=eddyb
Browse files Browse the repository at this point in the history
Move DelaySpanBugEmitted to ty::context

This makes it even hard to abuse.

r? @eddyb

cc @LeSeulArtichaut as this will probably conflict with your PR :/
  • Loading branch information
tmandry committed Aug 16, 2020
2 parents 3ef2244 + e1cd185 commit 54c7434
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/consts/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum ConstKind<'tcx> {

/// A placeholder for a const which could not be computed; this is
/// propagated to avoid useless error messages.
Error(ty::sty::DelaySpanBugEmitted),
Error(ty::DelaySpanBugEmitted),
}

#[cfg(target_arch = "x86_64")]
Expand Down
13 changes: 8 additions & 5 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ use std::mem;
use std::ops::{Bound, Deref};
use std::sync::Arc;

/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
/// except through `tcx.err*()`, which are in this module.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[derive(TyEncodable, TyDecodable, HashStable)]
pub struct DelaySpanBugEmitted(());

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

pub struct CtxtInterners<'tcx> {
Expand Down Expand Up @@ -1171,18 +1177,15 @@ impl<'tcx> TyCtxt<'tcx> {
#[track_caller]
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
self.sess.delay_span_bug(span, msg);
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
self.mk_ty(Error(DelaySpanBugEmitted(())))
}

/// Like `err` but for constants.
#[track_caller]
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
self.sess
.delay_span_bug(DUMMY_SP, "ty::ConstKind::Error constructed but no error reported.");
self.mk_const(ty::Const {
val: ty::ConstKind::Error(super::sty::DelaySpanBugEmitted(())),
ty,
})
self.mk_const(ty::Const { val: ty::ConstKind::Error(DelaySpanBugEmitted(())), ty })
}

pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ pub use self::binding::BindingMode::*;

pub use self::context::{tls, FreeRegionInfo, TyCtxt};
pub use self::context::{
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
UserType, UserTypeAnnotationIndex,
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
DelaySpanBugEmitted, ResolvedOpaqueTy, UserType, UserTypeAnnotationIndex,
};
pub use self::context::{
CtxtInterners, GeneratorInteriorTypeCause, GlobalCtxt, Lift, TypeckResults,
Expand Down
8 changes: 1 addition & 7 deletions src/librustc_middle/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
use crate::ty::{
self, AdtDef, DefIdTree, Discr, Ty, TyCtxt, TypeFlags, TypeFoldable, WithConstness,
};
use crate::ty::{List, ParamEnv, TyS};
use crate::ty::{DelaySpanBugEmitted, List, ParamEnv, TyS};
use polonius_engine::Atom;
use rustc_ast::ast;
use rustc_data_structures::captures::Captures;
Expand Down Expand Up @@ -212,12 +212,6 @@ impl TyKind<'tcx> {
}
}

/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
/// except through `tcx.err*()`.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[derive(TyEncodable, TyDecodable, HashStable)]
pub struct DelaySpanBugEmitted(pub(super) ());

// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
static_assert_size!(TyKind<'_>, 24);
Expand Down

0 comments on commit 54c7434

Please sign in to comment.