Auto merge of #98091 - Dylan-DPC:rollup-ueb6b5x, r=Dylan-DPC

Rollup of 5 pull requests

Successful merges:

 - #97869 (BTree: tweak internal comments)
 - #97935 (Rename the `ConstS::val` field as `kind`.)
 - #97948 (lint: add diagnostic translation migration lints)
 - #98042 (Fix compat_fn option method on miri)
 - #98069 (rustdoc:  remove link on slice brackets)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2022-06-14 10:51:16 +00:00
commit edab34ab2a
96 changed files with 522 additions and 250 deletions

View File

@ -378,7 +378,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
} else {
let tcx = self.tcx();
let maybe_uneval = match constant.literal {
ConstantKind::Ty(ct) => match ct.val() {
ConstantKind::Ty(ct) => match ct.kind() {
ty::ConstKind::Unevaluated(uv) => Some(uv),
_ => None,
},
@ -1841,7 +1841,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
fn check_operand(&mut self, op: &Operand<'tcx>, location: Location) {
if let Operand::Constant(constant) = op {
let maybe_uneval = match constant.literal {
ConstantKind::Ty(ct) => match ct.val() {
ConstantKind::Ty(ct) => match ct.kind() {
ty::ConstKind::Unevaluated(uv) => Some(uv),
_ => None,
},

View File

@ -710,7 +710,7 @@ fn codegen_stmt<'tcx>(
let times = fx
.monomorphize(times)
.eval(fx.tcx, ParamEnv::reveal_all())
.val()
.kind()
.try_to_bits(fx.tcx.data_layout.pointer_size)
.unwrap();
if operand.layout().size.bytes() == 0 {

View File

@ -45,7 +45,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
ConstantKind::Ty(ct) => ct,
ConstantKind::Val(..) => continue,
};
match const_.val() {
match const_.kind() {
ConstKind::Value(_) => {}
ConstKind::Unevaluated(unevaluated) => {
if let Err(err) =
@ -126,7 +126,7 @@ pub(crate) fn codegen_constant<'tcx>(
ConstantKind::Ty(ct) => ct,
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
};
let const_val = match const_.val() {
let const_val = match const_.kind() {
ConstKind::Value(const_val) => const_val,
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
if fx.tcx.is_static(def.did) =>
@ -469,7 +469,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
match operand {
Operand::Constant(const_) => match const_.literal {
ConstantKind::Ty(const_) => {
fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val().try_to_value()
fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).kind().try_to_value()
}
ConstantKind::Val(val, _) => Some(val),
},

View File

@ -180,7 +180,7 @@ fn push_debuginfo_type_name<'tcx>(
if cpp_like_debuginfo {
output.push_str("array$<");
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
match len.val() {
match len.kind() {
ty::ConstKind::Param(param) => write!(output, ",{}>", param.name).unwrap(),
_ => write!(output, ",{}>", len.eval_usize(tcx, ty::ParamEnv::reveal_all()))
.unwrap(),
@ -188,7 +188,7 @@ fn push_debuginfo_type_name<'tcx>(
} else {
output.push('[');
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
match len.val() {
match len.kind() {
ty::ConstKind::Param(param) => write!(output, "; {}]", param.name).unwrap(),
_ => write!(output, "; {}]", len.eval_usize(tcx, ty::ParamEnv::reveal_all()))
.unwrap(),
@ -679,7 +679,7 @@ fn push_generic_params_internal<'tcx>(
}
fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) {
match ct.val() {
match ct.kind() {
ty::ConstKind::Param(param) => {
write!(output, "{}", param.name)
}
@ -703,7 +703,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
// but we get a deterministic, virtually unique value for the constant.
let hcx = &mut tcx.create_stable_hashing_context();
let mut hasher = StableHasher::new();
hcx.while_hashing_spans(false, |hcx| ct.val().hash_stable(hcx, &mut hasher));
hcx.while_hashing_spans(false, |hcx| ct.kind().hash_stable(hcx, &mut hasher));
// Let's only emit 64 bits of the hash value. That should be plenty for
// avoiding collisions and will make the emitted type names shorter.
let hash: u64 = hasher.finish();

View File

@ -29,7 +29,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::ConstantKind::Ty(ct) => ct,
mir::ConstantKind::Val(val, _) => return Ok(val),
};
match ct.val() {
match ct.kind() {
ty::ConstKind::Unevaluated(ct) => self
.cx
.tcx()
@ -65,7 +65,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
.fields
.iter()
.map(|field| {
if let Some(prim) = field.val().try_to_scalar() {
if let Some(prim) = field.kind().try_to_scalar() {
let layout = bx.layout_of(field_ty);
let Abi::Scalar(scalar) = layout.abi else {
bug!("from_const: invalid ByVal layout: {:#?}", layout);

View File

@ -197,7 +197,7 @@ pub(crate) fn deref_const<'tcx>(
},
};
tcx.mk_const(ty::ConstS { val: ty::ConstKind::Value(op_to_const(&ecx, &mplace.into())), ty })
tcx.mk_const(ty::ConstS { kind: ty::ConstKind::Value(op_to_const(&ecx, &mplace.into())), ty })
}
#[instrument(skip(tcx), level = "debug")]

View File

@ -622,10 +622,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// "universe" (param_env).
pub fn const_to_op(
&self,
val: ty::Const<'tcx>,
c: ty::Const<'tcx>,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
match val.val() {
match c.kind() {
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => {
throw_inval!(AlreadyReported(reported))
@ -635,9 +635,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())
}
ty::ConstKind::Infer(..) | ty::ConstKind::Placeholder(..) => {
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val)
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c)
}
ty::ConstKind::Value(val_val) => self.const_val_to_op(val_val, val.ty(), layout),
ty::ConstKind::Value(val) => self.const_val_to_op(val, c.ty(), layout),
}
}

View File

@ -55,7 +55,7 @@ where
assert!(matches!(ty.kind(), ty::Param(_)))
}
ty::subst::GenericArgKind::Const(ct) => {
assert!(matches!(ct.val(), ty::ConstKind::Param(_)))
assert!(matches!(ct.kind(), ty::ConstKind::Param(_)))
}
ty::subst::GenericArgKind::Lifetime(..) => (),
},
@ -69,7 +69,7 @@ where
}
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match c.val() {
match c.kind() {
ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam),
_ => c.super_visit_with(self),
}

View File

@ -353,7 +353,8 @@ where
// Check the qualifs of the value of `const` items.
if let Some(ct) = constant.literal.const_for_ty() {
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) = ct.val() {
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) = ct.kind()
{
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
// check performed after the promotion. Verify that with an assertion.

View File

@ -842,7 +842,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
literal: tcx
.mk_const(ty::ConstS {
ty,
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
def,
substs: InternalSubsts::for_item(tcx, def.did, |param, _| {
if let ty::GenericParamDefKind::Lifetime = param.kind {

View File

@ -1,6 +1,7 @@
#![feature(let_chains)]
#![feature(once_cell)]
#![feature(path_try_exists)]
#![feature(rustc_attrs)]
#![feature(type_alias_impl_trait)]
use fluent_bundle::FluentResource;
@ -241,6 +242,7 @@ type FluentId = Cow<'static, str>;
/// message so messages of this type must be combined with a `DiagnosticMessage` (using
/// `DiagnosticMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
/// the `SessionSubdiagnostic` derive refer to Fluent identifiers directly.
#[rustc_diagnostic_item = "SubdiagnosticMessage"]
pub enum SubdiagnosticMessage {
/// Non-translatable diagnostic message.
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
@ -281,6 +283,7 @@ impl<S: Into<String>> From<S> for SubdiagnosticMessage {
///
/// Intended to be removed once diagnostics are entirely translatable.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
#[rustc_diagnostic_item = "DiagnosticMessage"]
pub enum DiagnosticMessage {
/// Non-translatable diagnostic message.
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?

View File

@ -80,6 +80,7 @@ impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(SessionSubdiagnostic)]` -- see [rustc_macros::SessionSubdiagnostic].
#[rustc_diagnostic_item = "AddSubdiagnostic"]
pub trait AddSubdiagnostic {
/// Add a subdiagnostic to an existing diagnostic.
fn add_to_diagnostic(self, diag: &mut Diagnostic);
@ -283,6 +284,7 @@ impl Diagnostic {
///
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only
/// the `Span` supplied when creating the diagnostic is primary.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.span.push_span_label(span, self.subdiagnostic_message_to_diagnostic_message(label));
self
@ -401,6 +403,7 @@ impl Diagnostic {
}
/// Add a note attached to this diagnostic.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.sub(Level::Note, msg, MultiSpan::new(), None);
self
@ -423,6 +426,7 @@ impl Diagnostic {
/// Prints the span with a note above it.
/// This is like [`Diagnostic::note()`], but it gets its own span.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_note<S: Into<MultiSpan>>(
&mut self,
sp: S,
@ -444,6 +448,7 @@ impl Diagnostic {
}
/// Add a warning attached to this diagnostic.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.sub(Level::Warning, msg, MultiSpan::new(), None);
self
@ -451,6 +456,7 @@ impl Diagnostic {
/// Prints the span with a warning above it.
/// This is like [`Diagnostic::warn()`], but it gets its own span.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_warn<S: Into<MultiSpan>>(
&mut self,
sp: S,
@ -461,6 +467,7 @@ impl Diagnostic {
}
/// Add a help message attached to this diagnostic.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.sub(Level::Help, msg, MultiSpan::new(), None);
self
@ -474,6 +481,7 @@ impl Diagnostic {
/// Prints the span with some help above it.
/// This is like [`Diagnostic::help()`], but it gets its own span.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_help<S: Into<MultiSpan>>(
&mut self,
sp: S,

View File

@ -9,6 +9,7 @@
#![feature(let_else)]
#![feature(never_type)]
#![feature(adt_const_params)]
#![feature(rustc_attrs)]
#![allow(incomplete_features)]
#![allow(rustc::potential_query_instability)]
@ -648,6 +649,7 @@ impl Handler {
/// Attempting to `.emit()` the builder will only emit if either:
/// * `can_emit_warnings` is `true`
/// * `is_force_warn` was set in `DiagnosticId::Lint`
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_span_warn(
&self,
span: impl Into<MultiSpan>,
@ -659,6 +661,7 @@ impl Handler {
}
/// Construct a builder at the `Allow` level at the given `span` and with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_span_allow(
&self,
span: impl Into<MultiSpan>,
@ -671,6 +674,7 @@ impl Handler {
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
/// Also include a code.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_span_warn_with_code(
&self,
span: impl Into<MultiSpan>,
@ -687,16 +691,19 @@ impl Handler {
/// Attempting to `.emit()` the builder will only emit if either:
/// * `can_emit_warnings` is `true`
/// * `is_force_warn` was set in `DiagnosticId::Lint`
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Level::Warning, msg)
}
/// Construct a builder at the `Allow` level with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Level::Allow, msg)
}
/// Construct a builder at the `Expect` level with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_expect(
&self,
msg: impl Into<DiagnosticMessage>,
@ -706,6 +713,7 @@ impl Handler {
}
/// Construct a builder at the `Error` level at the given `span` and with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_span_err(
&self,
span: impl Into<MultiSpan>,
@ -717,6 +725,7 @@ impl Handler {
}
/// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_span_err_with_code(
&self,
span: impl Into<MultiSpan>,
@ -730,6 +739,7 @@ impl Handler {
/// Construct a builder at the `Error` level with the `msg`.
// FIXME: This method should be removed (every error should have an associated error code).
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_err(
&self,
msg: impl Into<DiagnosticMessage>,
@ -744,6 +754,7 @@ impl Handler {
}
/// Construct a builder at the `Error` level with the `msg` and the `code`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_err_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
@ -755,6 +766,7 @@ impl Handler {
}
/// Construct a builder at the `Warn` level with the `msg` and the `code`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_warn_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
@ -766,6 +778,7 @@ impl Handler {
}
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_span_fatal(
&self,
span: impl Into<MultiSpan>,
@ -777,6 +790,7 @@ impl Handler {
}
/// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_span_fatal_with_code(
&self,
span: impl Into<MultiSpan>,
@ -789,16 +803,19 @@ impl Handler {
}
/// Construct a builder at the `Error` level with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
DiagnosticBuilder::new_fatal(self, msg)
}
/// Construct a builder at the `Help` level with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Level::Help, msg)
}
/// Construct a builder at the `Note` level with the `msg`.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_note_without_error(
&self,
msg: impl Into<DiagnosticMessage>,
@ -806,11 +823,13 @@ impl Handler {
DiagnosticBuilder::new(self, Level::Note, msg)
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
self.emit_diag_at_span(Diagnostic::new(Fatal, msg), span);
FatalError.raise()
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_fatal_with_code(
&self,
span: impl Into<MultiSpan>,
@ -821,6 +840,7 @@ impl Handler {
FatalError.raise()
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_err(
&self,
span: impl Into<MultiSpan>,
@ -829,6 +849,7 @@ impl Handler {
self.emit_diag_at_span(Diagnostic::new(Error { lint: false }, msg), span).unwrap()
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_err_with_code(
&self,
span: impl Into<MultiSpan>,
@ -841,10 +862,12 @@ impl Handler {
);
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
self.emit_diag_at_span(Diagnostic::new(Warning, msg), span);
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_warn_with_code(
&self,
span: impl Into<MultiSpan>,

View File

@ -615,6 +615,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// Used by the `rustc::potential_query_instability` lint to warn methods which
// might not be stable during incremental compilation.
rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
// Used by the `rustc::untranslatable_diagnostic` and `rustc::diagnostic_outside_of_impl` lints
// to assist in changes to diagnostic APIs.
rustc_attr!(rustc_lint_diagnostics, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
// ==========================================================================
// Internal attributes, Const related:

View File

@ -476,7 +476,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
match ct.val() {
match ct.kind() {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
debug!("canonical: const var found with vid {:?}", vid);
match self.infcx.probe_const_var(vid) {
@ -778,7 +778,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
} else {
let var = self.canonical_var(info, const_var.into());
self.tcx().mk_const(ty::ConstS {
val: ty::ConstKind::Bound(self.binder_index, var),
kind: ty::ConstKind::Bound(self.binder_index, var),
ty: self.fold_ty(const_var.ty()),
})
}

View File

@ -149,7 +149,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
self.tcx
.mk_const(ty::ConstS {
val: ty::ConstKind::Placeholder(placeholder_mapped),
kind: ty::ConstKind::Placeholder(placeholder_mapped),
ty: name.ty,
})
.into()

View File

@ -458,7 +458,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
}
}
GenericArgKind::Const(result_value) => {
if let ty::ConstKind::Bound(debrujin, b) = result_value.val() {
if let ty::ConstKind::Bound(debrujin, b) = result_value.kind() {
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
// We only allow a `ty::INNERMOST` index in substitutions.

View File

@ -142,7 +142,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
let a_is_expected = relation.a_is_expected();
match (a.val(), b.val()) {
match (a.kind(), b.kind()) {
(
ty::ConstKind::Infer(InferConst::Var(a_vid)),
ty::ConstKind::Infer(InferConst::Var(b_vid)),
@ -726,7 +726,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
) -> RelateResult<'tcx, ty::Const<'tcx>> {
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
match c.val() {
match c.kind() {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
let mut inner = self.infcx.inner.borrow_mut();
let variable_table = &mut inner.const_unification_table();
@ -761,7 +761,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
)?;
Ok(self.tcx().mk_const(ty::ConstS {
ty: c.ty(),
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
kind: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
}))
}
_ => relate::super_relate_consts(self, c, c),
@ -941,7 +941,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
debug_assert_eq!(c, _c);
debug!("ConstInferUnifier: c={:?}", c);
match c.val() {
match c.kind() {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
// Check if the current unification would end up
// unifying `target_vid` with a const which contains
@ -992,7 +992,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
)?;
Ok(self.tcx().mk_const(ty::ConstS {
ty: c.ty(),
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
kind: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
}))
}
_ => relate::super_relate_consts(self, c, c),

View File

@ -247,7 +247,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}
GenericArgKind::Const(ct) => {
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val() {
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
let origin =
self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) =
@ -673,7 +673,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
}
(GenericArgKind::Const(inner_ct), GenericArgKind::Const(target_ct)) => {
use ty::InferConst::*;
match (inner_ct.val(), target_ct.val()) {
match (inner_ct.kind(), target_ct.kind()) {
(ty::ConstKind::Infer(Var(a_vid)), ty::ConstKind::Infer(Var(b_vid))) => self
.infcx
.inner
@ -713,7 +713,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
}
}
GenericArgKind::Const(ct) => {
if matches!(ct.val(), ty::ConstKind::Unevaluated(..)) {
if matches!(ct.kind(), ty::ConstKind::Unevaluated(..)) {
// You can't write the generic arguments for
// unevaluated constants.
walker.skip_current_subtree();

View File

@ -218,7 +218,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
match ct.val() {
match ct.kind() {
ty::ConstKind::Infer(ty::InferConst::Var(v)) => {
let opt_ct = self
.infcx

View File

@ -229,7 +229,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.val() {
if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() {
if self.const_vars.0.contains(&vid) {
// This variable was created during the fudging.
// Recreate it with a fresh variable here.

View File

@ -99,7 +99,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let fld_c = |bound_var: ty::BoundVar, ty| {
self.tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Placeholder(ty::PlaceholderConst {
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
universe: next_universe,
name: ty::BoundConst { var: bound_var, ty },
}),

View File

@ -1754,7 +1754,7 @@ impl<'tcx> TyOrConstInferVar<'tcx> {
/// Tries to extract an inference variable from a constant, returns `None`
/// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`).
pub fn maybe_from_const(ct: ty::Const<'tcx>) -> Option<Self> {
match ct.val() {
match ct.kind() {
ty::ConstKind::Infer(InferConst::Var(v)) => Some(TyOrConstInferVar::Const(v)),
_ => None,
}
@ -1833,7 +1833,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val() {
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
self.infcx
.inner
.borrow_mut()

View File

@ -659,7 +659,7 @@ where
b = self.infcx.shallow_resolve(b);
}
match b.val() {
match b.kind() {
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
// Forbid inference variables in the RHS.
bug!("unexpected inference var {:?}", b)
@ -1034,7 +1034,7 @@ where
a: ty::Const<'tcx>,
_: ty::Const<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> {
match a.val() {
match a.kind() {
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
bug!("unexpected inference variable encountered in NLL generalization: {:?}", a);
}

View File

@ -223,7 +223,7 @@ impl<'a, 'tcx> FallibleTypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
Ok(c) // micro-optimize -- if there is nothing in this const that this fold affects...
} else {
let c = self.infcx.shallow_resolve(c);
match c.val() {
match c.kind() {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
return Err(FixupError::UnresolvedConst(vid));
}

View File

@ -2873,7 +2873,7 @@ impl ClashingExternDeclarations {
}
(Array(a_ty, a_const), Array(b_ty, b_const)) => {
// For arrays, we also check the constness of the type.
a_const.val() == b_const.val()
a_const.kind() == b_const.kind()
&& structurally_same_type_impl(seen_types, cx, *a_ty, *b_ty, ckind)
}
(Slice(a_ty), Slice(b_ty)) => {

View File

@ -5,12 +5,14 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
use rustc_ast as ast;
use rustc_errors::Applicability;
use rustc_hir::def::Res;
use rustc_hir::{Expr, ExprKind, GenericArg, PatKind, Path, PathSegment, QPath};
use rustc_hir::{HirId, Item, ItemKind, Node, Pat, Ty, TyKind};
use rustc_hir::{def_id::DefId, Expr, ExprKind, GenericArg, PatKind, Path, PathSegment, QPath};
use rustc_hir::{HirId, Impl, Item, ItemKind, Node, Pat, Ty, TyKind};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
use tracing::debug;
declare_tool_lint! {
pub rustc::DEFAULT_HASH_TYPES,
@ -46,6 +48,41 @@ impl LateLintPass<'_> for DefaultHashTypes {
}
}
/// Helper function for lints that check for expressions with calls and use typeck results to
/// get the `DefId` and `SubstsRef` of the function.
fn typeck_results_of_method_fn<'tcx>(
cx: &LateContext<'tcx>,
expr: &Expr<'_>,
) -> Option<(Span, DefId, ty::subst::SubstsRef<'tcx>)> {
// FIXME(rustdoc): Lints which use this function use typecheck results which can cause
// `rustdoc` to error if there are resolution failures.
//
// As internal lints are currently always run if there are `unstable_options`, they are added
// to the lint store of rustdoc. Internal lints are also not used via the `lint_mod` query.
// Crate lints run outside of a query so rustdoc currently doesn't disable them.
//
// Instead of relying on this, either change crate lints to a query disabled by rustdoc, only
// run internal lints if the user is explicitly opting in or figure out a different way to
// avoid running lints for rustdoc.
if cx.tcx.sess.opts.actually_rustdoc {
return None;
}
match expr.kind {
ExprKind::MethodCall(segment, _, _)
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) =>
{
Some((segment.ident.span, def_id, cx.typeck_results().node_substs(expr.hir_id)))
},
_ => {
match cx.typeck_results().node_type(expr.hir_id).kind() {
&ty::FnDef(def_id, substs) => Some((expr.span, def_id, substs)),
_ => None,
}
}
}
}
declare_tool_lint! {
pub rustc::POTENTIAL_QUERY_INSTABILITY,
Allow,
@ -57,35 +94,7 @@ declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]);
impl LateLintPass<'_> for QueryStability {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
// FIXME(rustdoc): This lint uses typecheck results, causing rustdoc to
// error if there are resolution failures.
//
// As internal lints are currently always run if there are `unstable_options`,
// they are added to the lint store of rustdoc. Internal lints are also
// not used via the `lint_mod` query. Crate lints run outside of a query
// so rustdoc currently doesn't disable them.
//
// Instead of relying on this, either change crate lints to a query disabled by
// rustdoc, only run internal lints if the user is explicitly opting in
// or figure out a different way to avoid running lints for rustdoc.
if cx.tcx.sess.opts.actually_rustdoc {
return;
}
let (span, def_id, substs) = match expr.kind {
ExprKind::MethodCall(segment, _, _)
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) =>
{
(segment.ident.span, def_id, cx.typeck_results().node_substs(expr.hir_id))
},
_ => {
let &ty::FnDef(def_id, substs) =
cx.typeck_results()
.node_type(expr.hir_id)
.kind() else { return };
(expr.span, def_id, substs)
}
};
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) {
let def_id = instance.def_id();
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
@ -376,3 +385,70 @@ impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
}
}
}
declare_tool_lint! {
pub rustc::UNTRANSLATABLE_DIAGNOSTIC,
Allow,
"prevent creation of diagnostics which cannot be translated",
report_in_external_macro: true
}
declare_tool_lint! {
pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL,
Allow,
"prevent creation of diagnostics outside of `SessionDiagnostic`/`AddSubdiagnostic` impls",
report_in_external_macro: true
}
declare_lint_pass!(Diagnostics => [ UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL ]);
impl LateLintPass<'_> for Diagnostics {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
debug!(?span, ?def_id, ?substs);
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) &&
!cx.tcx.has_attr(instance.def_id(), sym::rustc_lint_diagnostics)
{
return;
}
let mut found_impl = false;
for (_, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
debug!(?parent);
if let Node::Item(Item { kind: ItemKind::Impl(impl_), .. }) = parent &&
let Impl { of_trait: Some(of_trait), .. } = impl_ &&
let Some(def_id) = of_trait.trait_def_id() &&
let Some(name) = cx.tcx.get_diagnostic_name(def_id) &&
matches!(name, sym::SessionDiagnostic | sym::AddSubdiagnostic)
{
found_impl = true;
break;
}
}
debug!(?found_impl);
if !found_impl {
cx.struct_span_lint(DIAGNOSTIC_OUTSIDE_OF_IMPL, span, |lint| {
lint.build("diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls")
.emit();
})
}
let mut found_diagnostic_message = false;
for ty in substs.types() {
debug!(?ty);
if let Some(adt_def) = ty.ty_adt_def() &&
let Some(name) = cx.tcx.get_diagnostic_name(adt_def.did()) &&
matches!(name, sym::DiagnosticMessage | sym::SubdiagnosticMessage)
{
found_diagnostic_message = true;
break;
}
}
debug!(?found_diagnostic_message);
if !found_diagnostic_message {
cx.struct_span_lint(UNTRANSLATABLE_DIAGNOSTIC, span, |lint| {
lint.build("diagnostics should be created using translatable messages").emit();
})
}
}
}

View File

@ -508,6 +508,8 @@ fn register_internals(store: &mut LintStore) {
store.register_late_pass(|| Box::new(ExistingDocKeyword));
store.register_lints(&TyTyKind::get_lints());
store.register_late_pass(|| Box::new(TyTyKind));
store.register_lints(&Diagnostics::get_lints());
store.register_late_pass(|| Box::new(Diagnostics));
store.register_lints(&PassByValue::get_lints());
store.register_late_pass(|| Box::new(PassByValue));
store.register_group(

View File

@ -336,7 +336,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
GenericArgKind::Const(ct) => tcx
.mk_const(ty::ConstS {
ty: ct.ty(),
val: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
kind: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
})
.into(),
})

View File

@ -2956,7 +2956,7 @@ impl<'tcx> Constant<'tcx> {
impl<'tcx> From<ty::Const<'tcx>> for ConstantKind<'tcx> {
#[inline]
fn from(ct: ty::Const<'tcx>) -> Self {
match ct.val() {
match ct.kind() {
ty::ConstKind::Value(cv) => {
// FIXME Once valtrees are introduced we need to convert those
// into `ConstValue` instances here
@ -2985,7 +2985,7 @@ impl<'tcx> ConstantKind<'tcx> {
pub fn try_val(&self) -> Option<ConstValue<'tcx>> {
match self {
ConstantKind::Ty(c) => match c.val() {
ConstantKind::Ty(c) => match c.kind() {
ty::ConstKind::Value(v) => Some(v),
_ => None,
},
@ -2996,7 +2996,7 @@ impl<'tcx> ConstantKind<'tcx> {
#[inline]
pub fn try_to_value(self) -> Option<interpret::ConstValue<'tcx>> {
match self {
ConstantKind::Ty(c) => c.val().try_to_value(),
ConstantKind::Ty(c) => c.kind().try_to_value(),
ConstantKind::Val(val, _) => Some(val),
}
}
@ -3027,7 +3027,7 @@ impl<'tcx> ConstantKind<'tcx> {
Self::Ty(c) => {
// FIXME Need to use a different evaluation function that directly returns a `ConstValue`
// if evaluation succeeds and does not create a ValTree first
if let Some(val) = c.val().try_eval(tcx, param_env) {
if let Some(val) = c.kind().try_eval(tcx, param_env) {
match val {
Ok(val) => Self::Val(val, c.ty()),
Err(_) => Self::Ty(tcx.const_error(self.ty())),
@ -3161,7 +3161,7 @@ impl<'tcx> ConstantKind<'tcx> {
ty::InlineConstSubsts::new(tcx, ty::InlineConstSubstsParts { parent_substs, ty })
.substs;
let uneval_const = tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
def: ty::WithOptConstParam::unknown(def_id).to_global(),
substs,
promoted: None,
@ -3221,7 +3221,7 @@ impl<'tcx> ConstantKind<'tcx> {
let index = generics.param_def_id_to_index[&def_id];
let name = tcx.hir().name(hir_id);
let ty_const = tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
kind: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
ty,
});
@ -3258,7 +3258,7 @@ impl<'tcx> ConstantKind<'tcx> {
// Error was handled in `const_eval_resolve`. Here we just create a
// new unevaluated const and error hard later in codegen
let ty_const = tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
def: def.to_global(),
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
promoted: None,

View File

@ -454,8 +454,8 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
ConstValue::ByRef { .. } => format!("ByRef(..)"),
};
let val = match literal {
ConstantKind::Ty(ct) => match ct.val() {
let kind = match literal {
ConstantKind::Ty(ct) => match ct.kind() {
ty::ConstKind::Param(p) => format!("Param({})", p),
ty::ConstKind::Unevaluated(uv) => format!(
"Unevaluated({}, {:?}, {:?})",
@ -476,7 +476,10 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
ConstantKind::Val(val, _) => format!("Value({})", fmt_val(&val)),
};
self.push(&format!("+ literal: Const {{ ty: {}, val: {} }}", literal.ty(), val));
// This reflects what `Const` looked liked before `val` was renamed
// as `kind`. We print it like this to avoid having to update
// expected output in a lot of tests.
self.push(&format!("+ literal: Const {{ ty: {}, val: {} }}", literal.ty(), kind));
}
}
@ -679,7 +682,7 @@ pub fn write_allocations<'tcx>(
impl<'tcx> Visitor<'tcx> for CollectAllocIds {
fn visit_const(&mut self, c: ty::Const<'tcx>, _loc: Location) {
if let ty::ConstKind::Value(val) = c.val() {
if let ty::ConstKind::Value(val) = c.kind() {
self.0.extend(alloc_ids_from_const(val));
}
}

View File

@ -96,7 +96,7 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
return Ok(a);
}
match (a.val(), b.val()) {
match (a.kind(), b.kind()) {
(_, ty::ConstKind::Infer(InferConst::Fresh(_))) => {
return Ok(a);
}

View File

@ -29,7 +29,7 @@ impl<'tcx> fmt::Debug for Const<'tcx> {
// This reflects what `Const` looked liked before `Interned` was
// introduced. We print it like this to avoid having to update expected
// output in a lot of tests.
write!(f, "Const {{ ty: {:?}, val: {:?} }}", self.ty(), self.val())
write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty(), self.kind())
}
}
@ -37,7 +37,7 @@ impl<'tcx> fmt::Debug for Const<'tcx> {
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, TyEncodable, TyDecodable)]
pub struct ConstS<'tcx> {
pub ty: Ty<'tcx>,
pub val: ConstKind<'tcx>,
pub kind: ConstKind<'tcx>,
}
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
@ -50,8 +50,8 @@ impl<'tcx> Const<'tcx> {
}
#[inline]
pub fn val(self) -> ConstKind<'tcx> {
self.0.val
pub fn kind(self) -> ConstKind<'tcx> {
self.0.kind
}
/// Literals and const generic parameters are eagerly converted to a constant, everything else
@ -83,7 +83,7 @@ impl<'tcx> Const<'tcx> {
match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v,
None => tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
def: def.to_global(),
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
promoted: None,
@ -145,7 +145,7 @@ impl<'tcx> Const<'tcx> {
let index = generics.param_def_id_to_index[&def_id];
let name = tcx.hir().name(hir_id);
Some(tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
kind: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
ty,
}))
}
@ -180,7 +180,7 @@ impl<'tcx> Const<'tcx> {
InlineConstSubsts::new(tcx, InlineConstSubstsParts { parent_substs, ty })
.substs;
tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
def: ty::WithOptConstParam::unknown(def_id).to_global(),
substs,
promoted: None,
@ -196,7 +196,7 @@ impl<'tcx> Const<'tcx> {
/// Interns the given value as a constant.
#[inline]
pub fn from_value(tcx: TyCtxt<'tcx>, val: ConstValue<'tcx>, ty: Ty<'tcx>) -> Self {
tcx.mk_const(ConstS { val: ConstKind::Value(val), ty })
tcx.mk_const(ConstS { kind: ConstKind::Value(val), ty })
}
#[inline]
@ -246,24 +246,24 @@ impl<'tcx> Const<'tcx> {
assert_eq!(self.ty(), ty);
let size = tcx.layout_of(param_env.with_reveal_all_normalized(tcx).and(ty)).ok()?.size;
// if `ty` does not depend on generic parameters, use an empty param_env
self.val().eval(tcx, param_env).try_to_bits(size)
self.kind().eval(tcx, param_env).try_to_bits(size)
}
#[inline]
pub fn try_eval_bool(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option<bool> {
self.val().eval(tcx, param_env).try_to_bool()
self.kind().eval(tcx, param_env).try_to_bool()
}
#[inline]
pub fn try_eval_usize(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option<u64> {
self.val().eval(tcx, param_env).try_to_machine_usize(tcx)
self.kind().eval(tcx, param_env).try_to_machine_usize(tcx)
}
#[inline]
/// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the
/// unevaluated constant.
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> {
if let Some(val) = self.val().try_eval(tcx, param_env) {
if let Some(val) = self.kind().try_eval(tcx, param_env) {
match val {
Ok(val) => Const::from_value(tcx, val, self.ty()),
Err(ErrorGuaranteed { .. }) => tcx.const_error(self.ty()),

View File

@ -902,7 +902,7 @@ impl<'tcx> CanonicalUserType<'tcx> {
_ => false,
},
GenericArgKind::Const(ct) => match ct.val() {
GenericArgKind::Const(ct) => match ct.kind() {
ty::ConstKind::Bound(debruijn, b) => {
// We only allow a `ty::INNERMOST` index in substitutions.
assert_eq!(debruijn, ty::INNERMOST);
@ -991,7 +991,7 @@ impl<'tcx> CommonConsts<'tcx> {
CommonConsts {
unit: mk_const(ty::ConstS {
val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::ZST)),
kind: ty::ConstKind::Value(ConstValue::Scalar(Scalar::ZST)),
ty: types.unit,
}),
}
@ -1300,7 +1300,7 @@ impl<'tcx> TyCtxt<'tcx> {
) -> Const<'tcx> {
let reported = self.sess.delay_span_bug(span, msg);
self.mk_const(ty::ConstS {
val: ty::ConstKind::Error(DelaySpanBugEmitted { reported, _priv: () }),
kind: ty::ConstKind::Error(DelaySpanBugEmitted { reported, _priv: () }),
ty,
})
}
@ -2467,7 +2467,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
self.mk_const(ty::ConstS { val: ty::ConstKind::Infer(InferConst::Var(v)), ty })
self.mk_const(ty::ConstS { kind: ty::ConstKind::Infer(InferConst::Var(v)), ty })
}
#[inline]
@ -2487,7 +2487,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_const_infer(self, ic: InferConst<'tcx>, ty: Ty<'tcx>) -> ty::Const<'tcx> {
self.mk_const(ty::ConstS { val: ty::ConstKind::Infer(ic), ty })
self.mk_const(ty::ConstS { kind: ty::ConstKind::Infer(ic), ty })
}
#[inline]
@ -2497,7 +2497,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_const_param(self, index: u32, name: Symbol, ty: Ty<'tcx>) -> Const<'tcx> {
self.mk_const(ty::ConstS { val: ty::ConstKind::Param(ParamConst { index, name }), ty })
self.mk_const(ty::ConstS { kind: ty::ConstKind::Param(ParamConst { index, name }), ty })
}
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {

View File

@ -478,7 +478,7 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
}
fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match c.val() {
match c.kind() {
ConstKind::Infer(..)
| ConstKind::Bound(..)
| ConstKind::Placeholder(..)

View File

@ -254,7 +254,7 @@ impl<'tcx> Ty<'tcx> {
}
let n = tcx.lift(n).unwrap();
if let ty::ConstKind::Value(v) = n.val() {
if let ty::ConstKind::Value(v) = n.kind() {
if let Some(n) = v.try_to_machine_usize(tcx) {
return format!("array of {} element{}", n, pluralize!(n)).into();
}

View File

@ -363,7 +363,7 @@ impl DeepRejectCtxt {
}
pub fn consts_may_unify(self, obligation_ct: ty::Const<'_>, impl_ct: ty::Const<'_>) -> bool {
match impl_ct.val() {
match impl_ct.kind() {
ty::ConstKind::Param(_) | ty::ConstKind::Unevaluated(_) | ty::ConstKind::Error(_) => {
return true;
}
@ -373,8 +373,8 @@ impl DeepRejectCtxt {
}
}
let k = impl_ct.val();
match obligation_ct.val() {
let k = impl_ct.kind();
match obligation_ct.kind() {
ty::ConstKind::Param(_) => match self.treat_obligation_params {
TreatParams::AsPlaceholder => false,
TreatParams::AsInfer => true,

View File

@ -288,7 +288,7 @@ impl FlagComputation {
fn add_const(&mut self, c: ty::Const<'_>) {
self.add_ty(c.ty());
match c.val() {
match c.kind() {
ty::ConstKind::Unevaluated(unevaluated) => self.add_unevaluated_const(unevaluated),
ty::ConstKind::Infer(infer) => {
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);

View File

@ -718,7 +718,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
match ct.val() {
match ct.kind() {
ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => {
let ct = (self.fld_c)(bound_const, ct.ty());
ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32())
@ -865,7 +865,7 @@ impl<'tcx> TyCtxt<'tcx> {
},
|c, ty| {
self.mk_const(ty::ConstS {
val: ty::ConstKind::Bound(
kind: ty::ConstKind::Bound(
ty::INNERMOST,
ty::BoundVar::from_usize(c.as_usize() + bound_vars),
),
@ -1118,13 +1118,13 @@ impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
if let ty::ConstKind::Bound(debruijn, bound_ct) = ct.val() {
if let ty::ConstKind::Bound(debruijn, bound_ct) = ct.kind() {
if self.amount == 0 || debruijn < self.current_index {
ct
} else {
let debruijn = debruijn.shifted_in(self.amount);
self.tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Bound(debruijn, bound_ct),
kind: ty::ConstKind::Bound(debruijn, bound_ct),
ty: ct.ty(),
})
}
@ -1234,7 +1234,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
// otherwise we do want to remember to visit the rest of the
// const, as it has types/regions embedded in a lot of other
// places.
match ct.val() {
match ct.kind() {
ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => {
ControlFlow::Break(FoundEscapingVars)
}
@ -1389,7 +1389,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
// ignore the inputs of an unevaluated const, as they may not appear
// in the normalized form
if self.just_constrained {
if let ty::ConstKind::Unevaluated(..) = c.val() {
if let ty::ConstKind::Unevaluated(..) = c.kind() {
return ControlFlow::CONTINUE;
}
}
@ -1434,7 +1434,7 @@ impl<'tcx> TypeVisitor<'tcx> for MaxUniverse {
}
fn visit_const(&mut self, c: ty::consts::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::ConstKind::Placeholder(placeholder) = c.val() {
if let ty::ConstKind::Placeholder(placeholder) = c.kind() {
self.max_universe = ty::UniverseIndex::from_u32(
self.max_universe.as_u32().max(placeholder.universe.as_u32()),
);

View File

@ -748,14 +748,14 @@ pub trait PrettyPrinter<'tcx>:
p!("[", print(ty), "; ");
if self.tcx().sess.verbose() {
p!(write("{:?}", sz));
} else if let ty::ConstKind::Unevaluated(..) = sz.val() {
} else if let ty::ConstKind::Unevaluated(..) = sz.kind() {
// Do not try to evaluate unevaluated constants. If we are const evaluating an
// array length anon const, rustc will (with debug assertions) print the
// constant's path. Which will end up here again.
p!("_");
} else if let Some(n) = sz.val().try_to_bits(self.tcx().data_layout.pointer_size) {
} else if let Some(n) = sz.kind().try_to_bits(self.tcx().data_layout.pointer_size) {
p!(write("{}", n));
} else if let ty::ConstKind::Param(param) = sz.val() {
} else if let ty::ConstKind::Param(param) = sz.kind() {
p!(print(param));
} else {
p!("_");
@ -1165,7 +1165,7 @@ pub trait PrettyPrinter<'tcx>:
define_scoped_cx!(self);
if self.tcx().sess.verbose() {
p!(write("Const({:?}: {:?})", ct.val(), ct.ty()));
p!(write("Const({:?}: {:?})", ct.kind(), ct.ty()));
return Ok(self);
}
@ -1186,7 +1186,7 @@ pub trait PrettyPrinter<'tcx>:
}};
}
match ct.val() {
match ct.kind() {
ty::ConstKind::Unevaluated(ty::Unevaluated {
def,
substs,
@ -1262,7 +1262,7 @@ pub trait PrettyPrinter<'tcx>:
ty::Ref(_, inner, _) => {
if let ty::Array(elem, len) = inner.kind() {
if let ty::Uint(ty::UintTy::U8) = elem.kind() {
if let ty::ConstKind::Value(ConstValue::Scalar(int)) = len.val() {
if let ty::ConstKind::Value(ConstValue::Scalar(int)) = len.kind() {
match self.tcx().get_global_alloc(alloc_id) {
Some(GlobalAlloc::Memory(alloc)) => {
let len = int.assert_bits(self.tcx().data_layout.pointer_size);
@ -1452,7 +1452,7 @@ pub trait PrettyPrinter<'tcx>:
}
}
(ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if *t == u8_type => {
let n = n.val().try_to_bits(self.tcx().data_layout.pointer_size).unwrap();
let n = n.kind().try_to_bits(self.tcx().data_layout.pointer_size).unwrap();
// cast is ok because we already checked for pointer size (32 or 64 bit) above
let range = AllocRange { start: offset, size: Size::from_bytes(n) };
@ -1475,7 +1475,7 @@ pub trait PrettyPrinter<'tcx>:
(_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_param_types_or_consts() => {
let Some(contents) = self.tcx().try_destructure_const(
ty::ParamEnv::reveal_all()
.and(self.tcx().mk_const(ty::ConstS { val: ty::ConstKind::Value(ct), ty })),
.and(self.tcx().mk_const(ty::ConstS { kind: ty::ConstKind::Value(ct), ty })),
) else {
// Fall back to debug pretty printing for invalid constants.
p!(write("{:?}", ct));

View File

@ -602,7 +602,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
// Currently, the values that can be unified are primitive types,
// and those that derive both `PartialEq` and `Eq`, corresponding
// to structural-match types.
let is_match = match (a.val(), b.val()) {
let is_match = match (a.kind(), b.kind()) {
(ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => {
// The caller should handle these cases!
bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b)
@ -636,7 +636,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
bu.substs,
)?;
return Ok(tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
def: au.def,
substs,
promoted: au.promoted,

View File

@ -1148,9 +1148,9 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> {
folder: &mut F,
) -> Result<Self, F::Error> {
let ty = self.ty().try_fold_with(folder)?;
let val = self.val().try_fold_with(folder)?;
if ty != self.ty() || val != self.val() {
Ok(folder.tcx().mk_const(ty::ConstS { ty, val }))
let kind = self.kind().try_fold_with(folder)?;
if ty != self.ty() || kind != self.kind() {
Ok(folder.tcx().mk_const(ty::ConstS { ty, kind }))
} else {
Ok(self)
}
@ -1158,7 +1158,7 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> {
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.ty().visit_with(visitor)?;
self.val().visit_with(visitor)
self.kind().visit_with(visitor)
}
}

View File

@ -571,7 +571,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
}
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
if let ty::ConstKind::Param(p) = c.val() {
if let ty::ConstKind::Param(p) = c.kind() {
self.const_for_param(p, c)
} else {
c.super_fold_with(self)

View File

@ -450,7 +450,7 @@ impl<'tcx> TyCtxt<'tcx> {
// Error: not a type param
_ => false,
},
GenericArgKind::Const(ct) => match ct.val() {
GenericArgKind::Const(ct) => match ct.kind() {
ty::ConstKind::Param(ref pc) => {
!impl_generics.const_param(pc, self).pure_wrt_drop
}
@ -492,7 +492,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
_ => return Err(NotUniqueParam::NotParam(t.into())),
},
GenericArgKind::Const(c) => match c.val() {
GenericArgKind::Const(c) => match c.kind() {
ty::ConstKind::Param(p) => {
if !seen.insert(p.index) {
return Err(NotUniqueParam::DuplicateParam(c.into()));
@ -1127,7 +1127,7 @@ pub fn needs_drop_components<'tcx>(
ty::Array(elem_ty, size) => {
match needs_drop_components(*elem_ty, target_layout) {
Ok(v) if v.is_empty() => Ok(v),
res => match size.val().try_to_bits(target_layout.pointer_size) {
res => match size.kind().try_to_bits(target_layout.pointer_size) {
// Arrays of size zero don't need drop, even if their element
// type does.
Some(0) => Ok(SmallVec::new()),

View File

@ -190,7 +190,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
GenericArgKind::Lifetime(_) => {}
GenericArgKind::Const(parent_ct) => {
stack.push(parent_ct.ty().into());
match parent_ct.val() {
match parent_ct.kind() {
ty::ConstKind::Infer(_)
| ty::ConstKind::Param(_)
| ty::ConstKind::Placeholder(_)

View File

@ -15,7 +15,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let create_uneval_from_def_id =
|tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>, substs: SubstsRef<'tcx>| {
let uneval = ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
tcx.mk_const(ty::ConstS { val: ty::ConstKind::Unevaluated(uneval), ty })
tcx.mk_const(ty::ConstS { kind: ty::ConstKind::Unevaluated(uneval), ty })
};
let this = self;
@ -64,7 +64,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
ExprKind::ConstParam { param, def_id: _ } => {
let const_param =
tcx.mk_const(ty::ConstS { val: ty::ConstKind::Param(param), ty: expr.ty });
tcx.mk_const(ty::ConstS { kind: ty::ConstKind::Param(param), ty: expr.ty });
let literal = ConstantKind::Ty(const_param);
Constant { user_ty: None, span, literal }

View File

@ -153,7 +153,7 @@ impl IntRange {
return None;
}
}
mir::ConstantKind::Ty(c) => match c.val() {
mir::ConstantKind::Ty(c) => match c.kind() {
ty::ConstKind::Value(_) => bug!(
"encountered ConstValue in mir::ConstantKind::Ty, whereas this is expected to be in ConstantKind::Val"
),

View File

@ -553,7 +553,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
match value {
mir::ConstantKind::Ty(c) => {
match c.val() {
match c.kind() {
ConstKind::Param(_) => {
self.errors.push(PatternError::ConstParamInPattern(span));
return PatKind::Wild;

View File

@ -699,7 +699,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
) {
if let Rvalue::Use(Operand::Constant(c)) = rval {
match c.literal {
ConstantKind::Ty(c) if matches!(c.val(), ConstKind::Unevaluated(..)) => {}
ConstantKind::Ty(c) if matches!(c.kind(), ConstKind::Unevaluated(..)) => {}
_ => {
trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c);
return;
@ -773,7 +773,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
.tcx
.mk_const(ty::ConstS {
ty,
val: ty::ConstKind::Value(ConstValue::ByRef {
kind: ty::ConstKind::Value(ConstValue::ByRef {
alloc,
offset: Size::ZERO,
}),

View File

@ -474,7 +474,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
let err = ConstEvalErr::new(&self.ecx, error, Some(c.span));
if let Some(lint_root) = self.lint_root(source_info) {
let lint_only = match c.literal {
ConstantKind::Ty(ct) => match ct.val() {
ConstantKind::Ty(ct) => match ct.kind() {
// Promoteds must lint and not error as the user didn't ask for them
ConstKind::Unevaluated(ty::Unevaluated {
def: _,

View File

@ -614,7 +614,7 @@ impl<'tcx> Inliner<'tcx> {
caller_body.required_consts.extend(
callee_body.required_consts.iter().copied().filter(|&ct| {
match ct.literal.const_for_ty() {
Some(ct) => matches!(ct.val(), ConstKind::Unevaluated(_)),
Some(ct) => matches!(ct.kind(), ConstKind::Unevaluated(_)),
None => true,
}
}),

View File

@ -15,7 +15,7 @@ impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> {
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
let literal = constant.literal;
if let Some(ct) = literal.const_for_ty() && let ConstKind::Unevaluated(_) = ct.val() {
if let Some(ct) = literal.const_for_ty() && let ConstKind::Unevaluated(_) = ct.kind() {
self.required_consts.push(*constant);
}
}

View File

@ -756,7 +756,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
let literal = self.monomorphize(constant.literal);
let val = match literal {
mir::ConstantKind::Val(val, _) => val,
mir::ConstantKind::Ty(ct) => match ct.val() {
mir::ConstantKind::Ty(ct) => match ct.kind() {
ty::ConstKind::Value(val) => val,
ty::ConstKind::Unevaluated(ct) => {
let param_env = ty::ParamEnv::reveal_all();
@ -784,7 +784,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
let substituted_constant = self.monomorphize(constant);
let param_env = ty::ParamEnv::reveal_all();
match substituted_constant.val() {
match substituted_constant.kind() {
ty::ConstKind::Value(val) => collect_const_value(self.tcx, val, self.output),
ty::ConstKind::Unevaluated(unevaluated) => {
match self.tcx.const_eval_resolve(param_env, unevaluated, None) {

View File

@ -283,7 +283,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
return ControlFlow::CONTINUE;
}
match c.val() {
match c.kind() {
ty::ConstKind::Param(param) => {
debug!(?param);
self.unused_parameters.clear(param.index);
@ -353,7 +353,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
return ControlFlow::CONTINUE;
}
match c.val() {
match c.kind() {
ty::ConstKind::Param(param) => {
if self.unused_parameters.contains(param.index).unwrap_or(false) {
ControlFlow::CONTINUE

View File

@ -118,6 +118,9 @@ impl CheckAttrVisitor<'_> {
sym::rustc_lint_query_instability => {
self.check_rustc_lint_query_instability(&attr, span, target)
}
sym::rustc_lint_diagnostics => {
self.check_rustc_lint_diagnostics(&attr, span, target)
}
sym::rustc_clean
| sym::rustc_dirty
| sym::rustc_if_this_changed
@ -1624,12 +1627,9 @@ impl CheckAttrVisitor<'_> {
}
}
fn check_rustc_lint_query_instability(
&self,
attr: &Attribute,
span: Span,
target: Target,
) -> bool {
/// Helper function for checking that the provided attribute is only applied to a function or
/// method.
fn check_applied_to_fn_or_method(&self, attr: &Attribute, span: Span, target: Target) -> bool {
let is_function = matches!(target, Target::Fn | Target::Method(..));
if !is_function {
self.tcx
@ -1643,6 +1643,23 @@ impl CheckAttrVisitor<'_> {
}
}
/// Checks that the `#[rustc_lint_query_instability]` attribute is only applied to a function
/// or method.
fn check_rustc_lint_query_instability(
&self,
attr: &Attribute,
span: Span,
target: Target,
) -> bool {
self.check_applied_to_fn_or_method(attr, span, target)
}
/// Checks that the `#[rustc_lint_diagnostics]` attribute is only applied to a function or
/// method.
fn check_rustc_lint_diagnostics(&self, attr: &Attribute, span: Span, target: Target) -> bool {
self.check_applied_to_fn_or_method(attr, span, target)
}
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
/// option is passed to the compiler.
fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool {

View File

@ -5,6 +5,7 @@
#![feature(never_type)]
#![feature(once_cell)]
#![feature(option_get_or_insert_default)]
#![feature(rustc_attrs)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]

View File

@ -311,6 +311,7 @@ impl ParseSess {
self.create_warning(warning).emit()
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_err(
&self,
msg: impl Into<DiagnosticMessage>,
@ -318,6 +319,7 @@ impl ParseSess {
self.span_diagnostic.struct_err(msg)
}
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
self.span_diagnostic.struct_warn(msg)
}

View File

@ -209,6 +209,7 @@ pub struct PerfStats {
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic].
#[rustc_diagnostic_item = "SessionDiagnostic"]
pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
/// Write out as a diagnostic out of `sess`.
#[must_use]

View File

@ -125,6 +125,7 @@ symbols! {
Symbols {
AcqRel,
Acquire,
AddSubdiagnostic,
Alignment,
Any,
Arc,
@ -169,6 +170,7 @@ symbols! {
Decoder,
Default,
Deref,
DiagnosticMessage,
DirBuilder,
Display,
DoubleEndedIterator,
@ -253,11 +255,13 @@ symbols! {
RustcEncodable,
Send,
SeqCst,
SessionDiagnostic,
SliceIndex,
Some,
String,
StructuralEq,
StructuralPartialEq,
SubdiagnosticMessage,
Sync,
Target,
ToOwned,
@ -1205,6 +1209,7 @@ symbols! {
rustc_layout_scalar_valid_range_end,
rustc_layout_scalar_valid_range_start,
rustc_legacy_const_generics,
rustc_lint_diagnostics,
rustc_lint_query_instability,
rustc_macro_transparency,
rustc_main,

View File

@ -228,9 +228,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
self.write_str("[")?;
self = self.print_type(ty)?;
self.write_str("; ")?;
if let Some(size) = size.val().try_to_bits(self.tcx().data_layout.pointer_size) {
if let Some(size) = size.kind().try_to_bits(self.tcx().data_layout.pointer_size) {
write!(self, "{}", size)?
} else if let ty::ConstKind::Param(param) = size.val() {
} else if let ty::ConstKind::Param(param) = size.kind() {
self = param.print(self)?
} else {
self.write_str("_")?
@ -260,7 +260,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
// only print integers
match (ct.val(), ct.ty().kind()) {
match (ct.kind(), ct.ty().kind()) {
(
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(scalar))),
ty::Int(_) | ty::Uint(_),

View File

@ -582,7 +582,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
fn print_const(mut self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
// We only mangle a typed value if the const can be evaluated.
let ct = ct.eval(self.tcx, ty::ParamEnv::reveal_all());
match ct.val() {
match ct.kind() {
ty::ConstKind::Value(_) => {}
// Placeholders (should be demangled as `_`).
@ -630,7 +630,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// handle `&str` and include both `&` ("R") and `str` ("e") prefixes.
ty::Ref(_, ty, hir::Mutability::Not) if *ty == self.tcx.types.str_ => {
self.push("R");
match ct.val() {
match ct.kind() {
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => {
// NOTE(eddyb) the following comment was kept from `ty::print::pretty`:
// The `inspect` here is okay since we checked the bounds, and there are no

View File

@ -209,7 +209,7 @@ fn check_opaque_type_parameter_valid(
GenericArgKind::Lifetime(lt) => {
matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_))
}
GenericArgKind::Const(ct) => matches!(ct.val(), ty::ConstKind::Param(_)),
GenericArgKind::Const(ct) => matches!(ct.kind(), ty::ConstKind::Param(_)),
};
if arg_is_param {
@ -452,7 +452,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
trace!("checking const {:?}", ct);
// Find a const parameter
match ct.val() {
match ct.kind() {
ty::ConstKind::Param(..) => {
// Look it up in the substitution list.
match self.map.get(&ct.into()).map(|k| k.unpack()) {

View File

@ -828,7 +828,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
}
ty::PredicateKind::ConstEquate(c1, c2) => {
let evaluate = |c: ty::Const<'tcx>| {
if let ty::ConstKind::Unevaluated(unevaluated) = c.val() {
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
match select.infcx().const_eval_resolve(
obligation.param_env,
unevaluated,

View File

@ -245,7 +245,7 @@ impl<'tcx> AbstractConst<'tcx> {
tcx: TyCtxt<'tcx>,
ct: ty::Const<'tcx>,
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
match ct.val() {
match ct.kind() {
ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv.shrink()),
ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => Err(reported),
_ => Ok(None),
@ -414,7 +414,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
for n in self.nodes.iter() {
if let Node::Leaf(ct) = n {
if let ty::ConstKind::Unevaluated(ct) = ct.val() {
if let ty::ConstKind::Unevaluated(ct) = ct.kind() {
// `AbstractConst`s should not contain any promoteds as they require references which
// are not allowed.
assert_eq!(ct.promoted, None);
@ -457,7 +457,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
let uneval = ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
let constant = self.tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Unevaluated(uneval),
kind: ty::ConstKind::Unevaluated(uneval),
ty: node.ty,
});
@ -466,7 +466,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
ExprKind::ConstParam {param, ..} => {
let const_param = self.tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Param(*param),
kind: ty::ConstKind::Param(*param),
ty: node.ty,
});
self.nodes.push(Node::Leaf(const_param))
@ -748,7 +748,7 @@ impl<'tcx> ConstUnifyCtxt<'tcx> {
return false;
}
match (a_ct.val(), b_ct.val()) {
match (a_ct.kind(), b_ct.kind()) {
// We can just unify errors with everything to reduce the amount of
// emitted errors here.
(ty::ConstKind::Error(_), _) | (_, ty::ConstKind::Error(_)) => true,

View File

@ -234,7 +234,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// Arrays give us `[]`, `[{ty}; _]` and `[{ty}; N]`
if let ty::Array(aty, len) = self_ty.kind() {
flags.push((sym::_Self, Some("[]".to_string())));
let len = len.val().try_to_value().and_then(|v| v.try_to_machine_usize(self.tcx));
let len = len.kind().try_to_value().and_then(|v| v.try_to_machine_usize(self.tcx));
flags.push((sym::_Self, Some(format!("[{}; _]", aty))));
if let Some(n) = len {
flags.push((sym::_Self, Some(format!("[{}; {}]", aty, n))));

View File

@ -578,7 +578,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
//
// Let's just see where this breaks :shrug:
if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) =
(c1.val(), c2.val())
(c1.kind(), c2.kind())
{
if infcx.try_unify_abstract_consts(
a.shrink(),
@ -593,7 +593,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
let stalled_on = &mut pending_obligation.stalled_on;
let mut evaluate = |c: Const<'tcx>| {
if let ty::ConstKind::Unevaluated(unevaluated) = c.val() {
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
match self.selcx.infcx().const_eval_resolve(
obligation.param_env,
unevaluated,

View File

@ -742,7 +742,7 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
match ct.val() {
match ct.kind() {
ty::ConstKind::Bound(debruijn, _)
if debruijn.as_usize() + 1
> self.current_index.as_usize() + self.universe_indices.len() =>
@ -758,7 +758,7 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
self.mapped_consts.insert(p, bound_const);
self.infcx
.tcx
.mk_const(ty::ConstS { val: ty::ConstKind::Placeholder(p), ty: ct.ty() })
.mk_const(ty::ConstS { kind: ty::ConstKind::Placeholder(p), ty: ct.ty() })
}
_ if ct.has_vars_bound_at_or_above(self.current_index) => ct.super_fold_with(self),
_ => ct,
@ -878,7 +878,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
if let ty::ConstKind::Placeholder(p) = ct.val() {
if let ty::ConstKind::Placeholder(p) = ct.kind() {
let replace_var = self.mapped_consts.get(&p);
match replace_var {
Some(replace_var) => {
@ -891,7 +891,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> {
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
);
self.tcx().mk_const(ty::ConstS {
val: ty::ConstKind::Bound(db, *replace_var),
kind: ty::ConstKind::Bound(db, *replace_var),
ty: ct.ty(),
})
}
@ -2018,8 +2018,8 @@ fn confirm_impl_candidate<'cx, 'tcx>(
let identity_substs =
crate::traits::InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
let did = ty::WithOptConstParam::unknown(assoc_ty.item.def_id);
let val = ty::ConstKind::Unevaluated(ty::Unevaluated::new(did, identity_substs));
tcx.mk_const(ty::ConstS { ty, val }).into()
let kind = ty::ConstKind::Unevaluated(ty::Unevaluated::new(did, identity_substs));
tcx.mk_const(ty::ConstS { ty, kind }).into()
} else {
ty.into()
};

View File

@ -141,7 +141,7 @@ impl<'tcx> TypeVisitor<'tcx> for MaxEscapingBoundVarVisitor {
}
fn visit_const(&mut self, ct: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match ct.val() {
match ct.kind() {
ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => {
self.escaping =
self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize());
@ -337,7 +337,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
Ok(match constant {
mir::ConstantKind::Ty(c) => {
let const_folded = c.try_fold_with(self)?;
match const_folded.val() {
match const_folded.kind() {
ty::ConstKind::Value(cv) => {
// FIXME With Valtrees we need to convert `cv: ValTree`
// to a `ConstValue` here.

View File

@ -542,7 +542,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
bound_vars.push(bound_var);
tcx.mk_const(ty::ConstS {
ty: tcx.type_of(param.def_id),
val: ty::ConstKind::Bound(
kind: ty::ConstKind::Bound(
ty::INNERMOST,
ty::BoundVar::from_usize(bound_vars.len() - 1),
),
@ -989,7 +989,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// Lifetimes aren't allowed to change during unsizing.
GenericArgKind::Lifetime(_) => None,
GenericArgKind::Const(ct) => match ct.val() {
GenericArgKind::Const(ct) => match ct.kind() {
ty::ConstKind::Param(p) => Some(p.index),
_ => None,
},

View File

@ -622,7 +622,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
//
// Let's just see where this breaks :shrug:
if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) =
(c1.val(), c2.val())
(c1.kind(), c2.kind())
{
if self.infcx.try_unify_abstract_consts(
a.shrink(),
@ -635,7 +635,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
let evaluate = |c: ty::Const<'tcx>| {
if let ty::ConstKind::Unevaluated(unevaluated) = c.val() {
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
self.infcx
.const_eval_resolve(
obligation.param_env,

View File

@ -41,7 +41,7 @@ pub fn obligations<'a, 'tcx>(
.into()
}
GenericArgKind::Const(ct) => {
match ct.val() {
match ct.kind() {
ty::ConstKind::Infer(infer) => {
let resolved = infcx.shallow_resolve(infer);
if resolved == infer {
@ -51,7 +51,7 @@ pub fn obligations<'a, 'tcx>(
infcx
.tcx
.mk_const(ty::ConstS { val: ty::ConstKind::Infer(resolved), ty: ct.ty() })
.mk_const(ty::ConstS { kind: ty::ConstKind::Infer(resolved), ty: ct.ty() })
}
_ => ct,
}
@ -437,7 +437,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
GenericArgKind::Lifetime(_) => continue,
GenericArgKind::Const(constant) => {
match constant.val() {
match constant.kind() {
ty::ConstKind::Unevaluated(uv) => {
let obligations = self.nominal_obligations(uv.def.did, uv.substs);
self.out.extend(obligations);
@ -460,7 +460,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let cause = self.cause(traits::MiscObligation);
let resolved_constant = self.infcx.tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Infer(resolved),
kind: ty::ConstKind::Infer(resolved),
ty: constant.ty(),
});
self.out.push(traits::Obligation::with_depth(

View File

@ -736,7 +736,7 @@ fn bound_vars_for_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx
ty::GenericParamDefKind::Const { .. } => tcx
.mk_const(ty::ConstS {
val: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
kind: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
ty: tcx.type_of(param.def_id),
})
.into(),

View File

@ -514,7 +514,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
impl<'tcx> LowerInto<'tcx, chalk_ir::Const<RustInterner<'tcx>>> for ty::Const<'tcx> {
fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Const<RustInterner<'tcx>> {
let ty = self.ty().lower_into(interner);
let value = match self.val() {
let value = match self.kind() {
ty::ConstKind::Value(val) => {
chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: val })
}
@ -531,7 +531,7 @@ impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const<RustInterner<'t
fn lower_into(self, interner: RustInterner<'tcx>) -> ty::Const<'tcx> {
let data = self.data(interner);
let ty = data.ty.lower_into(interner);
let val = match data.value {
let kind = match data.value {
chalk_ir::ConstValue::BoundVar(var) => ty::ConstKind::Bound(
ty::DebruijnIndex::from_u32(var.debruijn.depth()),
ty::BoundVar::from_u32(var.index as u32),
@ -540,7 +540,7 @@ impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const<RustInterner<'t
chalk_ir::ConstValue::Placeholder(_p) => unimplemented!(),
chalk_ir::ConstValue::Concrete(c) => ty::ConstKind::Value(c.interned),
};
interner.tcx.mk_const(ty::ConstS { ty, val })
interner.tcx.mk_const(ty::ConstS { ty, kind })
}
}

View File

@ -539,7 +539,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes<'tcx>(
}
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::ConstKind::Unevaluated(..) = c.val() {
if let ty::ConstKind::Unevaluated(..) = c.kind() {
// FIXME(#72219) We currently don't detect lifetimes within substs
// which would violate this check. Even though the particular substitution is not used
// within the const, this should still be fixed.

View File

@ -1379,7 +1379,7 @@ pub fn check_type_bounds<'tcx>(
bound_vars.push(bound_var);
tcx.mk_const(ty::ConstS {
ty: tcx.type_of(param.def_id),
val: ty::ConstKind::Bound(
kind: ty::ConstKind::Bound(
ty::INNERMOST,
ty::BoundVar::from_usize(bound_vars.len() - 1),
),

View File

@ -1382,7 +1382,7 @@ fn check_where_clauses<'tcx, 'fcx>(
}
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::ConstKind::Param(param) = c.val() {
if let ty::ConstKind::Param(param) = c.kind() {
self.params.insert(param.index);
}
c.super_visit_with(self)

View File

@ -2352,7 +2352,7 @@ fn const_evaluatable_predicates_of<'tcx>(
fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
let def_id = self.tcx.hir().local_def_id(c.hir_id);
let ct = ty::Const::from_anon_const(self.tcx, def_id);
if let ty::ConstKind::Unevaluated(uv) = ct.val() {
if let ty::ConstKind::Unevaluated(uv) = ct.kind() {
assert_eq!(uv.promoted, None);
let span = self.tcx.hir().span(c.hir_id);
self.preds.insert((

View File

@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector {
}
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match c.val() {
match c.kind() {
ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => {
// Constant expressions are not injective
return c.ty().visit_with(self);

View File

@ -411,12 +411,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
fn add_constraints_from_const(
&mut self,
current: &CurrentItem,
val: ty::Const<'tcx>,
c: ty::Const<'tcx>,
variance: VarianceTermPtr<'a>,
) {
debug!("add_constraints_from_const(val={:?}, variance={:?})", val, variance);
debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance);
match &val.val() {
match &c.kind() {
ty::ConstKind::Unevaluated(uv) => {
self.add_constraints_from_invariant_substs(current, uv.substs, variance);
}

View File

@ -91,8 +91,8 @@ impl<K, V> Root<K, V> {
}
}
/// Stock up any underfull nodes on the right border of the tree.
/// The other nodes, those that are not the root nor a rightmost edge,
/// Stocks up any underfull nodes on the right border of the tree.
/// The other nodes, those that are neither the root nor a rightmost edge,
/// must be prepared to have up to MIN_LEN elements stolen.
pub fn fix_right_border_of_plentiful(&mut self) {
let mut cur_node = self.borrow_mut();

View File

@ -315,7 +315,7 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
pub fn insert(self, value: V) -> &'a mut V {
let out_ptr = match self.handle {
None => {
// SAFETY: We have consumed self.handle and the reference returned.
// SAFETY: There is no tree yet so no reference to it exists.
let map = unsafe { self.dormant_map.awaken() };
let mut root = NodeRef::new_leaf();
let val_ptr = root.borrow_mut().push(self.key, value) as *mut V;
@ -325,16 +325,17 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
}
Some(handle) => match handle.insert_recursing(self.key, value) {
(None, val_ptr) => {
// SAFETY: We have consumed self.handle and the handle returned.
// SAFETY: We have consumed self.handle.
let map = unsafe { self.dormant_map.awaken() };
map.length += 1;
val_ptr
}
(Some(ins), val_ptr) => {
drop(ins.left);
// SAFETY: We have consumed self.handle and the reference returned.
// SAFETY: We have consumed self.handle and dropped the
// remaining reference to the tree, ins.left.
let map = unsafe { self.dormant_map.awaken() };
let root = map.root.as_mut().unwrap();
let root = map.root.as_mut().unwrap(); // same as ins.left
root.push_internal_level().push(ins.kv.0, ins.kv.1, ins.right);
map.length += 1;
val_ptr

View File

@ -102,21 +102,23 @@ macro_rules! compat_fn {
}
#[allow(dead_code)]
#[inline(always)]
pub fn option() -> Option<F> {
unsafe { PTR }
unsafe {
if cfg!(miri) {
// Miri does not run `init`, so we just call `get_f` each time.
get_f()
} else {
PTR
}
}
}
#[allow(dead_code)]
pub unsafe fn call($($argname: $argtype),*) -> $rettype {
if let Some(ptr) = PTR {
if let Some(ptr) = option() {
return ptr($($argname),*);
}
if cfg!(miri) {
// Miri does not run `init`, so we just call `get_f` each time.
if let Some(ptr) = get_f() {
return ptr($($argname),*);
}
}
$fallback_body
}
}

View File

@ -234,7 +234,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
}
pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
match n.val() {
match n.kind() {
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => {
let mut s = if let Some(def) = def.as_local() {
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did);
@ -307,7 +307,7 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: ty::Const<'_>) -> String {
// Use a slightly different format for integer types which always shows the actual value.
// For all other types, fallback to the original `pretty_print_const`.
match (ct.val(), ct.ty().kind()) {
match (ct.kind(), ct.ty().kind()) {
(ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Uint(ui)) => {
format!("{}{}", format_integer_with_underscore_sep(&int.to_string()), ui.name_str())
}

View File

@ -886,9 +886,9 @@ fn fmt_type<'cx>(
primitive_link(f, PrimitiveType::Slice, &format!("[{name}]"), cx)
}
_ => {
primitive_link(f, PrimitiveType::Slice, "[", cx)?;
write!(f, "[")?;
fmt::Display::fmt(&t.print(cx), f)?;
primitive_link(f, PrimitiveType::Slice, "]", cx)
write!(f, "]")
}
},
clean::Array(ref t, ref n) => {
@ -926,31 +926,6 @@ fn fmt_type<'cx>(
let m = mutability.print_with_space();
let amp = if f.alternate() { "&".to_string() } else { "&amp;".to_string() };
match **ty {
clean::Slice(ref bt) => {
// `BorrowedRef{ ... Slice(T) }` is `&[T]`
match **bt {
clean::Generic(name) => primitive_link(
f,
PrimitiveType::Slice,
&format!("{amp}{lt}{m}[{name}]"),
cx,
),
_ => {
primitive_link(
f,
PrimitiveType::Slice,
&format!("{}{}{}[", amp, lt, m),
cx,
)?;
if f.alternate() {
write!(f, "{:#}", bt.print(cx))?;
} else {
write!(f, "{}", bt.print(cx))?;
}
primitive_link(f, PrimitiveType::Slice, "]", cx)
}
}
}
clean::DynTrait(ref bounds, ref trait_lt)
if bounds.len() > 1 || trait_lt.is_some() =>
{

View File

@ -23,7 +23,7 @@
|
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/region-subtyping-basic.rs:16:11: 16:11
let mut _1: [usize; Const { ty: usize, val: Value(Scalar(0x00000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
let mut _1: [usize; Const { ty: usize, kind: Value(Scalar(0x00000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
let _3: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:16: 18:17
let mut _4: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18
let mut _5: bool; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18

View File

@ -23,7 +23,7 @@
|
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/region-subtyping-basic.rs:16:11: 16:11
let mut _1: [usize; Const { ty: usize, val: Value(Scalar(0x0000000000000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
let mut _1: [usize; Const { ty: usize, kind: Value(Scalar(0x0000000000000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
let _3: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:16: 18:17
let mut _4: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18
let mut _5: bool; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18

View File

@ -1 +1 @@
<code>pub fn gamma() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="{{channel}}/core/primitive.slice.html">[</a><a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a><a class="primitive" href="{{channel}}/core/primitive.slice.html">]</a>&gt;</code>
<code>pub fn gamma() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;[<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>]&gt;</code>

View File

@ -1 +1 @@
<code>pub fn beta&lt;T&gt;() -&gt; <a class="primitive" href="{{channel}}/core/primitive.slice.html">&amp;'static [T]</a></code>
<code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="{{channel}}/core/primitive.slice.html">[T]</a></code>

View File

@ -1 +1 @@
<code>pub fn alpha() -&gt; <a class="primitive" href="{{channel}}/core/primitive.slice.html">&amp;'static [</a><a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a><a class="primitive" href="{{channel}}/core/primitive.slice.html">]</a></code>
<code>pub fn alpha() -&gt; &amp;'static [<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>]</code>

View File

@ -0,0 +1,73 @@
// compile-flags: -Z unstable-options
#![crate_type = "lib"]
#![feature(rustc_private)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
extern crate rustc_errors;
extern crate rustc_macros;
extern crate rustc_session;
extern crate rustc_span;
use rustc_errors::{AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, fluent};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_session::{parse::ParseSess, SessionDiagnostic};
use rustc_span::Span;
#[derive(SessionDiagnostic)]
#[error(slug = "parser-expect-path")]
struct DeriveSessionDiagnostic {
#[primary_span]
span: Span,
}
#[derive(SessionSubdiagnostic)]
#[note(slug = "note")]
struct Note {
#[primary_span]
span: Span,
}
pub struct UntranslatableInSessionDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
sess.struct_err("untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages
}
}
pub struct TranslatableInSessionDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
sess.struct_err(fluent::parser::expect_path)
}
}
pub struct UntranslatableInAddSubdiagnostic;
impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic {
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
diag.note("untranslatable diagnostic");
//~^ ERROR diagnostics should be created using translatable messages
}
}
pub struct TranslatableInAddSubdiagnostic;
impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
diag.note(fluent::typeck::note);
}
}
pub fn make_diagnostics<'a>(sess: &'a ParseSess) {
let _diag = sess.struct_err(fluent::parser::expect_path);
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
let _diag = sess.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages
}

View File

@ -0,0 +1,44 @@
error: diagnostics should be created using translatable messages
--> $DIR/diagnostics.rs:36:14
|
LL | sess.struct_err("untranslatable diagnostic")
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/diagnostics.rs:5:9
|
LL | #![deny(rustc::untranslatable_diagnostic)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostics should be created using translatable messages
--> $DIR/diagnostics.rs:53:14
|
LL | diag.note("untranslatable diagnostic");
| ^^^^
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
--> $DIR/diagnostics.rs:67:22
|
LL | let _diag = sess.struct_err(fluent::parser::expect_path);
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/diagnostics.rs:6:9
|
LL | #![deny(rustc::diagnostic_outside_of_impl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
--> $DIR/diagnostics.rs:70:22
|
LL | let _diag = sess.struct_err("untranslatable diagnostic");
| ^^^^^^^^^^
error: diagnostics should be created using translatable messages
--> $DIR/diagnostics.rs:70:22
|
LL | let _diag = sess.struct_err("untranslatable diagnostic");
| ^^^^^^^^^^
error: aborting due to 5 previous errors

View File

@ -0,0 +1,15 @@
// compile-flags: -Z unstable-options
#![feature(rustc_attrs)]
#[rustc_lint_diagnostics]
//~^ ERROR attribute should be applied to a function
struct Foo;
impl Foo {
#[rustc_lint_diagnostics(a)]
//~^ ERROR malformed `rustc_lint_diagnostics`
fn bar() {}
}
fn main() {}

View File

@ -0,0 +1,17 @@
error: malformed `rustc_lint_diagnostics` attribute input
--> $DIR/diagnostics_incorrect.rs:10:5
|
LL | #[rustc_lint_diagnostics(a)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_lint_diagnostics]`
error: attribute should be applied to a function
--> $DIR/diagnostics_incorrect.rs:5:1
|
LL | #[rustc_lint_diagnostics]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | struct Foo;
| ----------- not a function
error: aborting due to 2 previous errors

View File

@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
if let ItemKind::Const(hir_ty, _) = &item.kind;
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
if let ty::Array(element_type, cst) = ty.kind();
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind();
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
if self.maximum_allowed_size < element_count * element_size;

View File

@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
if_chain! {
if let ExprKind::Repeat(_, _) = expr.kind;
if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind();
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind();
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
if self.maximum_allowed_size < element_count * element_size;

View File

@ -582,7 +582,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
pub fn miri_to_const(result: ty::Const<'_>) -> Option<Constant> {
use rustc_middle::mir::interpret::ConstValue;
match result.val() {
match result.kind() {
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => {
match result.ty().kind() {
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),