Skip to content

Commit 2eb4609

Browse files
committed
Refactor default TypeVisitable::error_reported
1 parent e0767d9 commit 2eb4609

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
124124
type FreeRegion = ty::FreeRegion;
125125
type RegionVid = ty::RegionVid;
126126
type PlaceholderRegion = ty::PlaceholderRegion;
127+
128+
#[track_caller]
129+
fn expect_failure() -> ErrorGuaranteed {
130+
if let Some(reported) = ty::tls::with(|tcx| tcx.sess.is_compilation_going_to_fail()) {
131+
reported
132+
} else {
133+
bug!("expect tcx.sess.is_compilation_going_to_fail return `Some`");
134+
}
135+
}
127136
}
128137

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

compiler/rustc_middle/src/ty/visit.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
//! - u.visit_with(visitor)
4040
//! ```
4141
use crate::ty::{
42-
self, Binder, BoundAtOrAboveBinder, BoundIndex, Flags, OuterExclusiveBinder, Ty, TyCtxt,
43-
TypeFlags,
42+
self, Binder, BoundAtOrAboveBinder, BoundIndex, Flags, Interner, OuterExclusiveBinder, Ty,
43+
TyCtxt, TypeFlags,
4444
};
4545
use rustc_errors::ErrorGuaranteed;
4646

@@ -110,15 +110,7 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
110110
self.has_type_flags(TypeFlags::HAS_ERROR)
111111
}
112112
fn error_reported(&self) -> Result<(), ErrorGuaranteed> {
113-
if self.references_error() {
114-
if let Some(reported) = ty::tls::with(|tcx| tcx.sess.is_compilation_going_to_fail()) {
115-
Err(reported)
116-
} else {
117-
bug!("expect tcx.sess.is_compilation_going_to_fail return `Some`");
118-
}
119-
} else {
120-
Ok(())
121-
}
113+
if self.references_error() { Err(TyCtxt::expect_failure()) } else { Ok(()) }
122114
}
123115
fn has_non_region_param(&self) -> bool {
124116
self.has_type_flags(TypeFlags::NEEDS_SUBST - TypeFlags::HAS_RE_PARAM)

compiler/rustc_type_ir/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub trait Interner {
6464
type FreeRegion: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
6565
type RegionVid: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
6666
type PlaceholderRegion: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
67+
68+
fn expect_failure() -> Self::ErrorGuaranteed;
6769
}
6870

6971
pub trait InternAs<T: ?Sized, R> {

0 commit comments

Comments
 (0)