SmirError to Error

This commit is contained in:
Makai
2025-07-15 15:58:40 +00:00
parent 9a37aab558
commit a1deaa7097
10 changed files with 25 additions and 26 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
use rustc_abi::Align;
use rustc_middle::mir::ConstValue;
use rustc_middle::mir::interpret::AllocRange;
use rustc_public_bridge::bridge::SmirError;
use rustc_public_bridge::bridge::Error as _;
use rustc_public_bridge::context::CompilerCtxt;
use rustc_public_bridge::{Tables, alloc};
+2 -2
View File
@@ -7,7 +7,7 @@
use std::fmt::{Debug, Display, Formatter};
use std::{fmt, io};
use rustc_public_bridge::bridge::SmirError;
use rustc_public_bridge::bridge;
macro_rules! error {
($fmt: literal $(,)?) => { Error(format!($fmt)) };
@@ -32,7 +32,7 @@ pub enum CompilerError<T> {
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Error(pub(crate) String);
impl SmirError for Error {
impl bridge::Error for Error {
fn new(msg: String) -> Self {
Self(msg)
}
+13 -13
View File
@@ -1,7 +1,7 @@
use std::fmt::{Debug, Formatter};
use std::io;
use rustc_public_bridge::bridge::SmirError;
use rustc_public_bridge::bridge;
use serde::Serialize;
use crate::abi::FnAbi;
@@ -120,9 +120,9 @@ pub fn intrinsic_name(&self) -> Option<Symbol> {
/// Resolve an instance starting from a function definition and generic arguments.
pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
with(|context| {
context
.resolve_instance(def, args)
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
context.resolve_instance(def, args).ok_or_else(|| {
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
})
})
}
@@ -134,9 +134,9 @@ pub fn resolve_drop_in_place(ty: Ty) -> Instance {
/// Resolve an instance for a given function pointer.
pub fn resolve_for_fn_ptr(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
with(|context| {
context
.resolve_for_fn_ptr(def, args)
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
context.resolve_for_fn_ptr(def, args).ok_or_else(|| {
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
})
})
}
@@ -147,9 +147,9 @@ pub fn resolve_closure(
kind: ClosureKind,
) -> Result<Instance, Error> {
with(|context| {
context
.resolve_closure(def, args, kind)
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
context.resolve_closure(def, args, kind).ok_or_else(|| {
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
})
})
}
@@ -201,7 +201,7 @@ fn try_from(item: CrateItem) -> Result<Self, Self::Error> {
if !context.requires_monomorphization(def_id) {
Ok(context.mono_instance(def_id))
} else {
Err(Error::new("Item requires monomorphization".to_string()))
Err(bridge::Error::new("Item requires monomorphization".to_string()))
}
})
}
@@ -217,7 +217,7 @@ fn try_from(value: Instance) -> Result<Self, Self::Error> {
if value.kind == InstanceKind::Item && context.has_body(value.def.def_id()) {
Ok(CrateItem(context.instance_def_id(value.def)))
} else {
Err(Error::new(format!("Item kind `{:?}` cannot be converted", value.kind)))
Err(bridge::Error::new(format!("Item kind `{:?}` cannot be converted", value.kind)))
}
})
}
@@ -263,7 +263,7 @@ fn try_from(value: CrateItem) -> Result<Self, Self::Error> {
if matches!(value.kind(), ItemKind::Static) {
Ok(StaticDef(value.0))
} else {
Err(Error::new(format!("Expected a static item, but found: {value:?}")))
Err(bridge::Error::new(format!("Expected a static item, but found: {value:?}")))
}
}
}
@@ -2,9 +2,8 @@
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::{bug, mir};
use rustc_public_bridge::Tables;
use rustc_public_bridge::bridge::SmirError;
use rustc_public_bridge::context::CompilerCtxt;
use rustc_public_bridge::{Tables, bridge};
use crate::compiler_interface::BridgeTys;
use crate::mir::alloc::GlobalAlloc;
@@ -914,7 +913,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::ErrorHandled {
type T = Error;
fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
Error::new(format!("{self:?}"))
bridge::Error::new(format!("{self:?}"))
}
}
@@ -1,8 +1,8 @@
//! Implementation of InternalCx.
pub(crate) use helpers::*;
use rustc_middle::ty::{List, Ty, TyCtxt};
use rustc_middle::{mir, ty};
pub(crate) use helpers::*;
use super::InternalCx;
+1 -1
View File
@@ -12,7 +12,7 @@
use super::{CompilerCtxt, Tables};
use crate::bridge::Allocation as _;
use crate::{Bridge, SmirError};
use crate::{Bridge, Error};
pub fn create_ty_and_layout<'tcx, B: Bridge>(
cx: &CompilerCtxt<'tcx, B>,
+1 -1
View File
@@ -9,7 +9,7 @@
use super::context::CompilerCtxt;
use super::{Bridge, Tables};
pub trait SmirError {
pub trait Error {
fn new(msg: String) -> Self;
fn from_internal<T: Debug>(err: T) -> Self;
}
@@ -26,7 +26,7 @@
use super::{AllocRangeHelpers, CompilerCtxt, TyHelpers, TypingEnvHelpers};
use crate::builder::BodyBuilder;
use crate::{Bridge, SmirError, Tables, filter_def_ids};
use crate::{Bridge, Error, Tables, filter_def_ids};
impl<'tcx, B: Bridge> TyHelpers<'tcx> for CompilerCtxt<'tcx, B> {
fn new_foreign(&self, def_id: DefId) -> ty::Ty<'tcx> {
@@ -9,10 +9,10 @@
use rustc_middle::ty::layout::{FnAbiOfHelpers, HasTyCtxt, HasTypingEnv, LayoutOfHelpers};
use rustc_middle::ty::{Ty, TyCtxt};
use crate::{Bridge, SmirError};
use crate::{Bridge, Error};
mod impls;
mod helpers;
mod impls;
pub use helpers::*;
+1 -1
View File
@@ -222,7 +222,7 @@ pub trait Bridge: Sized {
type MirConstId: Copy + Debug + PartialEq + IndexedVal;
type Layout: Copy + Debug + PartialEq + IndexedVal;
type Error: SmirError;
type Error: Error;
type CrateItem: CrateItem<Self>;
type AdtDef: AdtDef<Self>;
type ForeignModuleDef: ForeignModuleDef<Self>;