Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,19 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
BackendRepr::ScalarPair {
a: a @ abi::Scalar::Initialized { .. },
b: b @ abi::Scalar::Initialized { .. },
b_offset,
b_offset: local_b_offset,
} => {
let (a_size, b_size) = (a.size(bx), b.size(bx));
assert!(b_offset.bytes() > 0);
let alloc_b_offset = offset + local_b_offset;
assert!(alloc_b_offset.bytes() > 0);
let a_val = read_scalar(
offset,
a_size,
a,
bx.scalar_pair_element_backend_type(layout, 0, true),
);
let b_val = read_scalar(
b_offset,
alloc_b_offset,
b_size,
b,
bx.scalar_pair_element_backend_type(layout, 1, true),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use super::qualifs::{self, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
use super::resolver::FlowSensitiveAnalysis;
use super::{ConstCx, Qualif};
use crate::check_consts::is_fn_or_trait_safe_to_expose_on_stable;
use crate::errors;
use crate::diagnostics;

type QualifResults<'mir, 'tcx, Q> =
rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'tcx, Q>>;
Expand Down Expand Up @@ -475,7 +475,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
if self.enforce_recursive_const_stability()
&& !is_fn_or_trait_safe_to_expose_on_stable(self.tcx, def_id)
{
self.dcx().emit_err(errors::UnmarkedConstItemExposed {
self.dcx().emit_err(diagnostics::UnmarkedConstItemExposed {
span: self.span,
def_path: self.tcx.def_path_str(def_id),
});
Expand Down Expand Up @@ -874,7 +874,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
// regular stability, and regular stability is checked separately.
// However, we *do* have to worry about *recursive* const stability.
if !is_const_stable && self.enforce_recursive_const_stability() {
self.dcx().emit_err(errors::UnmarkedIntrinsicExposed {
self.dcx().emit_err(diagnostics::UnmarkedIntrinsicExposed {
span: self.span,
def_path: self.tcx.def_path_str(callee),
});
Expand Down Expand Up @@ -988,7 +988,7 @@ fn emit_unstable_in_stable_exposed_error(
) -> ErrorGuaranteed {
let attr_span = ccx.tcx.def_span(ccx.def_id()).shrink_to_lo();

ccx.dcx().emit_err(errors::UnstableInStableExposed {
ccx.dcx().emit_err(diagnostics::UnstableInStableExposed {
gate: gate.to_string(),
span,
attr_span,
Expand Down
63 changes: 33 additions & 30 deletions compiler/rustc_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_trait_selection::traits::SelectionContext;
use tracing::debug;

use super::ConstCx;
use crate::errors;
use crate::diagnostics;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Status {
Expand Down Expand Up @@ -71,7 +71,7 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug {
pub(crate) struct FnCallIndirect;
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
ccx.dcx().create_err(diagnostics::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
}
}

Expand All @@ -90,7 +90,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallCVariadic {

fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.tcx.sess.create_feature_err(
errors::NonConstCVariadicCall { span, kind: ccx.const_kind() },
diagnostics::NonConstCVariadicCall { span, kind: ccx.const_kind() },
sym::const_c_variadic,
)
}
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
// FIXME(const_trait_impl) revisit this
if !tcx.is_const_trait_impl(data.impl_def_id) {
let span = tcx.def_span(data.impl_def_id);
err.subdiagnostic(errors::NonConstImplNote { span });
err.subdiagnostic(diagnostics::NonConstImplNote { span });
}
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ fn build_error_for_const_call<'tcx>(
CallKind::Normal { desugaring: Some((kind, self_ty)), .. } => {
macro_rules! error {
($err:ident) => {
tcx.dcx().create_err(errors::$err {
tcx.dcx().create_err(diagnostics::$err {
span,
ty: self_ty,
kind: ccx.const_kind(),
Expand Down Expand Up @@ -273,14 +273,14 @@ fn build_error_for_const_call<'tcx>(
span_bug!(span, "calling const FnDef errored when it shouldn't");
}

Some(errors::NonConstClosureNote::FnDef { span })
Some(diagnostics::NonConstClosureNote::FnDef { span })
}
FnPtr(..) => Some(errors::NonConstClosureNote::FnPtr { kind }),
Closure(..) => Some(errors::NonConstClosureNote::Closure { kind }),
FnPtr(..) => Some(diagnostics::NonConstClosureNote::FnPtr { kind }),
Closure(..) => Some(diagnostics::NonConstClosureNote::Closure { kind }),
_ => None,
};

let mut err = tcx.dcx().create_err(errors::NonConstClosure {
let mut err = tcx.dcx().create_err(diagnostics::NonConstClosure {
span,
kind: ccx.const_kind(),
note,
Expand All @@ -292,7 +292,7 @@ fn build_error_for_const_call<'tcx>(
}
CallKind::Operator { trait_id, self_ty, .. } => {
let mut err = if let CallSource::MatchCmp = call_source {
tcx.dcx().create_err(errors::NonConstMatchEq {
tcx.dcx().create_err(diagnostics::NonConstMatchEq {
span,
kind: ccx.const_kind(),
ty: self_ty,
Expand Down Expand Up @@ -323,7 +323,7 @@ fn build_error_for_const_call<'tcx>(
{
let rhs_pos = span.lo() + BytePos::from_usize(eq_idx + 2 + rhs_idx);
let rhs_span = span.with_lo(rhs_pos).with_hi(rhs_pos);
sugg = Some(errors::ConsiderDereferencing {
sugg = Some(diagnostics::ConsiderDereferencing {
deref,
span: span.shrink_to_lo(),
rhs_span,
Expand All @@ -333,7 +333,7 @@ fn build_error_for_const_call<'tcx>(
_ => {}
}
}
tcx.dcx().create_err(errors::NonConstOperator {
tcx.dcx().create_err(diagnostics::NonConstOperator {
span,
kind: ccx.const_kind(),
sugg,
Expand All @@ -354,7 +354,7 @@ fn build_error_for_const_call<'tcx>(
None
};

let mut err = tcx.dcx().create_err(errors::NonConstDerefCoercion {
let mut err = tcx.dcx().create_err(diagnostics::NonConstDerefCoercion {
span,
ty: self_ty,
kind: ccx.const_kind(),
Expand All @@ -367,15 +367,15 @@ fn build_error_for_const_call<'tcx>(
err
}
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::FmtArgumentsNew) => {
ccx.dcx().create_err(errors::NonConstFmtMacroCall {
ccx.dcx().create_err(diagnostics::NonConstFmtMacroCall {
span,
kind: ccx.const_kind(),
non_or_conditionally,
})
}
_ => {
let def_descr = ccx.tcx.def_descr(callee);
let mut err = ccx.dcx().create_err(errors::NonConstFnCall {
let mut err = ccx.dcx().create_err(diagnostics::NonConstFnCall {
span,
def_descr,
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
Expand Down Expand Up @@ -471,12 +471,12 @@ impl<'tcx> NonConstOp<'tcx> for CallUnstable {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
assert!(!self.feature_enabled);
let mut err = if self.is_function_call {
ccx.dcx().create_err(errors::UnstableConstFn {
ccx.dcx().create_err(diagnostics::UnstableConstFn {
span,
def_path: ccx.tcx.def_path_str(self.def_id),
})
} else {
ccx.dcx().create_err(errors::UnstableConstTrait {
ccx.dcx().create_err(diagnostics::UnstableConstTrait {
span,
def_path: ccx.tcx.def_path_str(self.def_id),
})
Expand All @@ -494,7 +494,7 @@ pub(crate) struct IntrinsicNonConst {

impl<'tcx> NonConstOp<'tcx> for IntrinsicNonConst {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::NonConstIntrinsic {
ccx.dcx().create_err(diagnostics::NonConstIntrinsic {
span,
name: self.name,
kind: ccx.const_kind(),
Expand Down Expand Up @@ -523,7 +523,7 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
}

fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::UnstableIntrinsic {
ccx.dcx().create_err(diagnostics::UnstableIntrinsic {
span,
name: self.name,
feature: self.feature,
Expand Down Expand Up @@ -556,9 +556,11 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
let msg = format!("{} are not allowed in {}s", self.0.to_plural_string(), ccx.const_kind());
if let Status::Unstable { gate, .. } = self.status_in_item(ccx) {
ccx.tcx.sess.create_feature_err(errors::UnallowedOpInConstContext { span, msg }, gate)
ccx.tcx
.sess
.create_feature_err(diagnostics::UnallowedOpInConstContext { span, msg }, gate)
} else {
ccx.dcx().create_err(errors::UnallowedOpInConstContext { span, msg })
ccx.dcx().create_err(diagnostics::UnallowedOpInConstContext { span, msg })
}
}
}
Expand All @@ -567,7 +569,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
pub(crate) struct InlineAsm;
impl<'tcx> NonConstOp<'tcx> for InlineAsm {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() })
ccx.dcx().create_err(diagnostics::UnallowedInlineAsm { span, kind: ccx.const_kind() })
}
}

Expand All @@ -593,15 +595,15 @@ impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {

fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
if self.needs_non_const_drop {
ccx.dcx().create_err(errors::LiveDrop {
ccx.dcx().create_err(diagnostics::LiveDrop {
span,
dropped_ty: self.dropped_ty,
kind: ccx.const_kind(),
dropped_at: self.dropped_at,
})
} else {
ccx.tcx.sess.create_feature_err(
errors::LiveDrop {
diagnostics::LiveDrop {
span,
dropped_ty: self.dropped_ty,
kind: ccx.const_kind(),
Expand All @@ -625,7 +627,8 @@ impl<'tcx> NonConstOp<'tcx> for EscapingCellBorrow {
DiagImportance::Secondary
}
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::InteriorMutableBorrowEscaping { span, kind: ccx.const_kind() })
ccx.dcx()
.create_err(diagnostics::InteriorMutableBorrowEscaping { span, kind: ccx.const_kind() })
}
}

Expand All @@ -647,7 +650,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow {
}

fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::MutableBorrowEscaping { span, kind: ccx.const_kind() })
ccx.dcx().create_err(diagnostics::MutableBorrowEscaping { span, kind: ccx.const_kind() })
}
}

Expand All @@ -656,7 +659,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow {
pub(crate) struct PanicNonStr;
impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::PanicNonStrErr { span })
ccx.dcx().create_err(diagnostics::PanicNonStrErr { span })
}
}

Expand All @@ -668,7 +671,7 @@ pub(crate) struct RawPtrComparison;
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
// FIXME(const_trait_impl): revert to span_bug?
ccx.dcx().create_err(errors::RawPtrComparisonErr { span })
ccx.dcx().create_err(diagnostics::RawPtrComparisonErr { span })
}
}

Expand All @@ -679,7 +682,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
pub(crate) struct RawPtrToIntCast;
impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::RawPtrToIntErr { span })
ccx.dcx().create_err(diagnostics::RawPtrToIntErr { span })
}
}

Expand All @@ -688,6 +691,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
pub(crate) struct ThreadLocalAccess;
impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::ThreadLocalAccessErr { span })
ccx.dcx().create_err(diagnostics::ThreadLocalAccessErr { span })
}
}
14 changes: 7 additions & 7 deletions compiler/rustc_const_eval/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::ty::layout::LayoutError;
use rustc_span::{DUMMY_SP, Span, Symbol};

use super::CompileTimeMachine;
use crate::errors::{self, FrameNote};
use crate::diagnostics::{self, FrameNote};
use crate::interpret::{
CtfeProvenance, ErrorHandled, Frame, InterpCx, InterpErrorInfo, InterpErrorKind,
MachineStopType, Pointer, err_inval, err_machine_stop,
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
pub(crate) fn get_span_and_frames<'tcx>(
tcx: TyCtxtAt<'tcx>,
stack: &[Frame<'tcx, impl Provenance, impl Sized>],
) -> (Span, Vec<errors::FrameNote>) {
) -> (Span, Vec<diagnostics::FrameNote>) {
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack, *tcx);
// Filter out `requires_caller_location` frames.
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
Expand All @@ -106,8 +106,8 @@ pub(crate) fn get_span_and_frames<'tcx>(
// Add notes to the backtrace. Don't print a single-line backtrace though.
if stacktrace.len() > 1 {
// Helper closure to print duplicated lines.
let mut add_frame = |mut frame: errors::FrameNote| {
frames.push(errors::FrameNote { times: 0, ..frame.clone() });
let mut add_frame = |mut frame: diagnostics::FrameNote| {
frames.push(diagnostics::FrameNote { times: 0, ..frame.clone() });
// Don't print [... additional calls ...] if the number of lines is small
if frame.times < 3 {
let times = frame.times;
Expand All @@ -118,7 +118,7 @@ pub(crate) fn get_span_and_frames<'tcx>(
}
};

let mut last_frame: Option<errors::FrameNote> = None;
let mut last_frame: Option<diagnostics::FrameNote> = None;
for frame_info in &stacktrace {
let frame = frame_info.as_note(*tcx);
match last_frame.as_mut() {
Expand Down Expand Up @@ -207,7 +207,7 @@ pub(super) fn report<'tcx>(
{
let bytes = ecx.print_alloc_bytes_for_diagnostics(alloc_id);
let info = ecx.get_alloc_info(alloc_id);
let raw_bytes = errors::RawBytesNote {
let raw_bytes = diagnostics::RawBytesNote {
size: info.size.bytes(),
align: info.align.bytes(),
bytes,
Expand Down Expand Up @@ -241,7 +241,7 @@ pub(super) fn lint<'tcx, L>(
tcx: TyCtxtAt<'tcx>,
machine: &CompileTimeMachine<'tcx>,
lint: &'static rustc_session::lint::Lint,
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
decorator: impl FnOnce(Vec<diagnostics::FrameNote>) -> L,
) where
L: for<'a> rustc_errors::Diagnostic<'a, ()>,
{
Expand Down
Loading
Loading