Migrate MutDeref, TransientMutBorrow diagnostics
This commit is contained in:
parent
584e5d4c4f
commit
f97f2a47ff
4 changed files with 69 additions and 19 deletions
|
@ -63,3 +63,27 @@ pub(crate) struct PanicNonStrErr {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(const_eval::mut_deref, code = "E0658")]
|
||||||
|
pub(crate) struct MutDerefErr {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub kind: ConstContext,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(const_eval::transient_mut_borrow, code = "E0658")]
|
||||||
|
pub(crate) struct TransientMutBorrowErr {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub kind: ConstContext,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(const_eval::transient_mut_borrow_raw, code = "E0658")]
|
||||||
|
pub(crate) struct TransientMutBorrowErrRaw {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub kind: ConstContext,
|
||||||
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ use rustc_trait_selection::traits::SelectionContext;
|
||||||
|
|
||||||
use super::ConstCx;
|
use super::ConstCx;
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
NonConstOpErr, PanicNonStrErr, RawPtrComparisonErr, RawPtrToIntErr, StaticAccessErr,
|
MutDerefErr, NonConstOpErr, PanicNonStrErr, RawPtrComparisonErr, RawPtrToIntErr,
|
||||||
|
StaticAccessErr, TransientMutBorrowErr, TransientMutBorrowErrRaw,
|
||||||
};
|
};
|
||||||
use crate::util::{call_kind, CallDesugaringKind, CallKind};
|
use crate::util::{call_kind, CallDesugaringKind, CallKind};
|
||||||
|
|
||||||
|
@ -595,17 +596,17 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
|
||||||
ccx: &ConstCx<'_, 'tcx>,
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
let raw = match self.0 {
|
let kind = ccx.const_kind();
|
||||||
hir::BorrowKind::Raw => "raw ",
|
match self.0 {
|
||||||
hir::BorrowKind::Ref => "",
|
hir::BorrowKind::Raw => ccx
|
||||||
};
|
.tcx
|
||||||
|
.sess
|
||||||
feature_err(
|
.create_feature_err(TransientMutBorrowErrRaw { span, kind }, sym::const_mut_refs),
|
||||||
&ccx.tcx.sess.parse_sess,
|
hir::BorrowKind::Ref => ccx
|
||||||
sym::const_mut_refs,
|
.tcx
|
||||||
span,
|
.sess
|
||||||
&format!("{}mutable references are not allowed in {}s", raw, ccx.const_kind()),
|
.create_feature_err(TransientMutBorrowErr { span, kind }, sym::const_mut_refs),
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,12 +627,9 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
|
||||||
ccx: &ConstCx<'_, 'tcx>,
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
feature_err(
|
ccx.tcx
|
||||||
&ccx.tcx.sess.parse_sess,
|
.sess
|
||||||
sym::const_mut_refs,
|
.create_feature_err(MutDerefErr { span, kind: ccx.const_kind() }, sym::const_mut_refs)
|
||||||
span,
|
|
||||||
&format!("mutation through a reference is not allowed in {}s", ccx.const_kind()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,3 +26,22 @@ const-eval-raw-ptr-comparison =
|
||||||
.note = see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
.note = see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
||||||
|
|
||||||
const-eval-panic-non-str = argument to `panic!()` in a const context must have type `&str`
|
const-eval-panic-non-str = argument to `panic!()` in a const context must have type `&str`
|
||||||
|
|
||||||
|
const-eval-mut-deref =
|
||||||
|
mutation through a reference is not allowed in { $kind ->
|
||||||
|
[constant function] constant functions
|
||||||
|
[static] statics
|
||||||
|
*[constant] constants
|
||||||
|
}
|
||||||
|
|
||||||
|
const-eval-transient-mut-borrow = mutable references are not allowed in { $kind ->
|
||||||
|
[constant function] constant functions
|
||||||
|
[static] statics
|
||||||
|
*[constant] constants
|
||||||
|
}
|
||||||
|
|
||||||
|
const-eval-transient-mut-borrow-raw = raw mutable references are not allowed in { $kind ->
|
||||||
|
[constant function] constant functions
|
||||||
|
[static] statics
|
||||||
|
*[constant] constants
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::cgu_reuse_tracker::CguReuseTracker;
|
||||||
use crate::code_stats::CodeStats;
|
use crate::code_stats::CodeStats;
|
||||||
pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
||||||
use crate::config::{self, CrateType, OutputType, SwitchWithOptPath};
|
use crate::config::{self, CrateType, OutputType, SwitchWithOptPath};
|
||||||
use crate::parse::ParseSess;
|
use crate::parse::{add_feature_diagnostics, ParseSess};
|
||||||
use crate::search_paths::{PathKind, SearchPath};
|
use crate::search_paths::{PathKind, SearchPath};
|
||||||
use crate::{filesearch, lint};
|
use crate::{filesearch, lint};
|
||||||
|
|
||||||
|
@ -458,6 +458,15 @@ impl Session {
|
||||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||||
self.parse_sess.create_err(err)
|
self.parse_sess.create_err(err)
|
||||||
}
|
}
|
||||||
|
pub fn create_feature_err<'a>(
|
||||||
|
&'a self,
|
||||||
|
err: impl SessionDiagnostic<'a>,
|
||||||
|
feature: Symbol,
|
||||||
|
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||||
|
let mut err = self.parse_sess.create_err(err);
|
||||||
|
add_feature_diagnostics(&mut err, &self.parse_sess, feature);
|
||||||
|
err
|
||||||
|
}
|
||||||
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
|
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
|
||||||
self.parse_sess.emit_err(err)
|
self.parse_sess.emit_err(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue