From 6f92f5ab66aa5e732e724ec24d825558f326e28f Mon Sep 17 00:00:00 2001 From: Stein Somers Date: Sun, 22 May 2022 13:46:54 +0200 Subject: [PATCH 1/6] BTree: tweak internal comments --- library/alloc/src/collections/btree/fix.rs | 4 ++-- library/alloc/src/collections/btree/map/entry.rs | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/collections/btree/fix.rs b/library/alloc/src/collections/btree/fix.rs index c4861817dd05d..fd73fde2acb2d 100644 --- a/library/alloc/src/collections/btree/fix.rs +++ b/library/alloc/src/collections/btree/fix.rs @@ -91,8 +91,8 @@ impl Root { } } - /// 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(); diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index cacd06b5df153..e2749aac694c8 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -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 From 5ba81faba632883ee69be0d216959a5ef3bba030 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 10 Jun 2022 15:50:06 +0100 Subject: [PATCH 2/6] lint: add diagnostic translation migration lints Introduce allow-by-default lints for checking whether diagnostics are written in `SessionDiagnostic`/`AddSubdiagnostic` impls and whether diagnostics are translatable. These lints can be denied for modules once they are fully migrated to impls and translation. Signed-off-by: David Wood --- compiler/rustc_error_messages/src/lib.rs | 3 + compiler/rustc_errors/src/diagnostic.rs | 8 + compiler/rustc_errors/src/lib.rs | 23 +++ compiler/rustc_feature/src/builtin_attrs.rs | 3 + compiler/rustc_lint/src/internal.rs | 138 ++++++++++++++---- compiler/rustc_lint/src/lib.rs | 2 + compiler/rustc_passes/src/check_attr.rs | 29 +++- compiler/rustc_session/src/lib.rs | 1 + compiler/rustc_session/src/parse.rs | 2 + compiler/rustc_session/src/session.rs | 1 + compiler/rustc_span/src/symbol.rs | 5 + .../ui-fulldeps/internal-lints/diagnostics.rs | 73 +++++++++ .../internal-lints/diagnostics.stderr | 44 ++++++ .../internal-lints/diagnostics_incorrect.rs | 15 ++ .../diagnostics_incorrect.stderr | 17 +++ 15 files changed, 327 insertions(+), 37 deletions(-) create mode 100644 src/test/ui-fulldeps/internal-lints/diagnostics.rs create mode 100644 src/test/ui-fulldeps/internal-lints/diagnostics.stderr create mode 100644 src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.rs create mode 100644 src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.stderr diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 02d076c95ca52..fd4b2daae9c13 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -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> From 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? diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index eaceecc166778..00c0ff8bcaf9c 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -80,6 +80,7 @@ impl<'source> Into> 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) -> &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) -> &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>( &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) -> &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>( &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) -> &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>( &mut self, sp: S, diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 3be6dd5af75ac..4eef00ddff4a3 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -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)] @@ -644,6 +645,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, @@ -655,6 +657,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, @@ -667,6 +670,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, @@ -683,16 +687,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) -> 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) -> 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, @@ -702,6 +709,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, @@ -713,6 +721,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, @@ -726,6 +735,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, @@ -740,6 +750,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, @@ -751,6 +762,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, @@ -762,6 +774,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, @@ -773,6 +786,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, @@ -785,16 +799,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) -> 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) -> 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, @@ -802,11 +819,13 @@ impl Handler { DiagnosticBuilder::new(self, Level::Note, msg) } + #[cfg_attr(not(bootstrap), rustc_lint_diagnostics)] pub fn span_fatal(&self, span: impl Into, msg: impl Into) -> ! { 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, @@ -817,6 +836,7 @@ impl Handler { FatalError.raise() } + #[cfg_attr(not(bootstrap), rustc_lint_diagnostics)] pub fn span_err( &self, span: impl Into, @@ -825,6 +845,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, @@ -837,10 +858,12 @@ impl Handler { ); } + #[cfg_attr(not(bootstrap), rustc_lint_diagnostics)] pub fn span_warn(&self, span: impl Into, msg: impl Into) { 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, diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 5eb2be97f8b92..34c53597dde6b 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -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: diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index b83d63e0da086..e70bcaac0c830 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -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(); + }) + } + } +} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index ff4ed94fab339..f0182883d2b46 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -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( diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 5cc97d326d3d8..e3a02cb8161f8 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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 { diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 59b4981dd0120..044be906b5507 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -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)] diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 6fb87e15a3303..a5ccae047fcc3 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -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, @@ -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) -> DiagnosticBuilder<'_, ()> { self.span_diagnostic.struct_warn(msg) } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b2c23cda6aae5..b1d1f9e7a6ce0 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -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] diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7b0fa65e8086b..6547ec493c862 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -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, diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs new file mode 100644 index 0000000000000..817d8531da905 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -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 +} diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.stderr b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr new file mode 100644 index 0000000000000..bae78ffdc021b --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr @@ -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 + diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.rs b/src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.rs new file mode 100644 index 0000000000000..99f99ffcd3597 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.rs @@ -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() {} diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.stderr b/src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.stderr new file mode 100644 index 0000000000000..46c206f3bf9fb --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.stderr @@ -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 + From 940e0b376510d68e7ce4a8eb30e33517692d83b1 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Tue, 31 May 2022 18:25:06 -0700 Subject: [PATCH 3/6] fix compat_fn option method on miri --- library/std/src/sys/windows/compat.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/library/std/src/sys/windows/compat.rs b/library/std/src/sys/windows/compat.rs index c55df04200313..424a0892b420c 100644 --- a/library/std/src/sys/windows/compat.rs +++ b/library/std/src/sys/windows/compat.rs @@ -103,20 +103,21 @@ macro_rules! compat_fn { #[allow(dead_code)] pub fn option() -> Option { - 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 } } From 682889fb06591c4245422b73b005c5d8ae2d0cad Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 13 Jun 2022 12:56:01 -0700 Subject: [PATCH 4/6] rustdoc: remove link on slice brackets Since #97668 was merged, the slice::get function now looks like this: ![image](https://user-images.githubusercontent.com/1593513/173430685-1dd2b275-2439-4392-b7d4-96bcb355a377.png) That whole thing, `[T]`, is a single link to `primitive.slice.html`. This definitely fixes it for this case, but it's not obvious what we should do for slices of concrete types: ![image](https://user-images.githubusercontent.com/1593513/173430968-7eed1aec-b688-4f84-a492-9210aff0037a.png) There are actually three links in that `[u8]`: the opening brace `[` is a link to `primitive.slice.html`, the `u8` is a link to `primitive.u8.html`, and the final `]` is a link to `primitive.slice.html`. This is a serious [usability bug](https://usability.yale.edu/web-accessibility/articles/links): the square braces are much too small for anyone who doesn't have perfect motor control using mouse or touch, provide an excessive number of tab stops for anyone using keyboard, and no visual indication whatsoever that they're separate links. Now that slices of generic types are linked, it seems reasonable to err on the side of less clutter and stop linking concrete slices to the slice page. --- src/librustdoc/html/format.rs | 29 ++----------------- .../rustdoc/slice-links.link_box_u32.html | 2 +- .../slice-links.link_slice_generic.html | 2 +- .../rustdoc/slice-links.link_slice_u32.html | 2 +- 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index b7789493df647..394db2d0cda6b 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -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 { "&".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() => { diff --git a/src/test/rustdoc/slice-links.link_box_u32.html b/src/test/rustdoc/slice-links.link_box_u32.html index 42fd721a4acf1..7bec7582df7c9 100644 --- a/src/test/rustdoc/slice-links.link_box_u32.html +++ b/src/test/rustdoc/slice-links.link_box_u32.html @@ -1 +1 @@ -pub fn gamma() -> MyBox<[u32]> \ No newline at end of file +pub fn gamma() -> MyBox<[u32]> \ No newline at end of file diff --git a/src/test/rustdoc/slice-links.link_slice_generic.html b/src/test/rustdoc/slice-links.link_slice_generic.html index fe79ca7a82da3..1d0f2bf75a233 100644 --- a/src/test/rustdoc/slice-links.link_slice_generic.html +++ b/src/test/rustdoc/slice-links.link_slice_generic.html @@ -1 +1 @@ -pub fn beta<T>() -> &'static [T] \ No newline at end of file +pub fn beta<T>() -> &'static [T] \ No newline at end of file diff --git a/src/test/rustdoc/slice-links.link_slice_u32.html b/src/test/rustdoc/slice-links.link_slice_u32.html index c7e430b0607f7..c86d383042615 100644 --- a/src/test/rustdoc/slice-links.link_slice_u32.html +++ b/src/test/rustdoc/slice-links.link_slice_u32.html @@ -1 +1 @@ -pub fn alpha() -> &'static [u32] \ No newline at end of file +pub fn alpha() -> &'static [u32] \ No newline at end of file From 5470a389214381917ff7215c5fe700e9045fb838 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Mon, 13 Jun 2022 16:26:05 -0700 Subject: [PATCH 5/6] add inline(always) to option --- library/std/src/sys/windows/compat.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/sys/windows/compat.rs b/library/std/src/sys/windows/compat.rs index 424a0892b420c..ded97bb7eaaed 100644 --- a/library/std/src/sys/windows/compat.rs +++ b/library/std/src/sys/windows/compat.rs @@ -102,6 +102,7 @@ macro_rules! compat_fn { } #[allow(dead_code)] + #[inline(always)] pub fn option() -> Option { unsafe { if cfg!(miri) { From 93e4b6ef06888085dc60d073ca9d66f2d7282112 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 10 Jun 2022 11:18:06 +1000 Subject: [PATCH 6/6] Rename the `ConstS::val` field as `kind`. And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant. --- compiler/rustc_borrowck/src/type_check/mod.rs | 4 ++-- compiler/rustc_codegen_cranelift/src/base.rs | 2 +- .../rustc_codegen_cranelift/src/constant.rs | 6 ++--- .../src/debuginfo/type_names.rs | 8 +++---- .../rustc_codegen_ssa/src/mir/constant.rs | 4 ++-- .../rustc_const_eval/src/const_eval/mod.rs | 2 +- .../rustc_const_eval/src/interpret/operand.rs | 8 +++---- .../rustc_const_eval/src/interpret/util.rs | 4 ++-- .../src/transform/check_consts/qualifs.rs | 3 ++- .../src/transform/promote_consts.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 4 ++-- .../rustc_infer/src/infer/canonical/mod.rs | 2 +- .../src/infer/canonical/query_response.rs | 2 +- compiler/rustc_infer/src/infer/combine.rs | 10 ++++---- .../infer/error_reporting/need_type_info.rs | 6 ++--- compiler/rustc_infer/src/infer/freshen.rs | 2 +- compiler/rustc_infer/src/infer/fudge.rs | 2 +- .../src/infer/higher_ranked/mod.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 4 ++-- .../rustc_infer/src/infer/nll_relate/mod.rs | 4 ++-- compiler/rustc_infer/src/infer/resolve.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 2 +- compiler/rustc_middle/src/infer/canonical.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 14 +++++------ compiler/rustc_middle/src/mir/pretty.rs | 11 +++++---- compiler/rustc_middle/src/ty/_match.rs | 2 +- compiler/rustc_middle/src/ty/consts.rs | 24 +++++++++---------- compiler/rustc_middle/src/ty/context.rs | 12 +++++----- compiler/rustc_middle/src/ty/diagnostics.rs | 2 +- compiler/rustc_middle/src/ty/error.rs | 2 +- compiler/rustc_middle/src/ty/fast_reject.rs | 6 ++--- compiler/rustc_middle/src/ty/flags.rs | 2 +- compiler/rustc_middle/src/ty/fold.rs | 14 +++++------ compiler/rustc_middle/src/ty/print/pretty.rs | 16 ++++++------- compiler/rustc_middle/src/ty/relate.rs | 4 ++-- .../rustc_middle/src/ty/structural_impls.rs | 8 +++---- compiler/rustc_middle/src/ty/subst.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 6 ++--- compiler/rustc_middle/src/ty/walk.rs | 2 +- .../src/build/expr/as_constant.rs | 4 ++-- .../src/thir/pattern/deconstruct_pat.rs | 2 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 2 +- .../rustc_mir_transform/src/const_prop.rs | 4 ++-- .../src/const_prop_lint.rs | 2 +- compiler/rustc_mir_transform/src/inline.rs | 2 +- .../src/required_consts.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 4 ++-- .../rustc_monomorphize/src/polymorphize.rs | 4 ++-- compiler/rustc_symbol_mangling/src/legacy.rs | 6 ++--- compiler/rustc_symbol_mangling/src/v0.rs | 4 ++-- .../rustc_trait_selection/src/opaque_types.rs | 4 ++-- .../src/traits/auto_trait.rs | 2 +- .../src/traits/const_evaluatable.rs | 10 ++++---- .../error_reporting/on_unimplemented.rs | 2 +- .../src/traits/fulfill.rs | 4 ++-- .../src/traits/project.rs | 12 +++++----- .../src/traits/query/normalize.rs | 4 ++-- .../src/traits/select/confirmation.rs | 4 ++-- .../src/traits/select/mod.rs | 4 ++-- .../rustc_trait_selection/src/traits/wf.rs | 8 +++---- compiler/rustc_traits/src/chalk/db.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 6 ++--- compiler/rustc_typeck/src/check/check.rs | 2 +- .../rustc_typeck/src/check/compare_method.rs | 2 +- compiler/rustc_typeck/src/check/wfcheck.rs | 2 +- compiler/rustc_typeck/src/collect.rs | 2 +- .../src/constrained_generic_params.rs | 2 +- .../rustc_typeck/src/variance/constraints.rs | 6 ++--- src/librustdoc/clean/utils.rs | 4 ++-- ...egion_subtyping_basic.main.nll.0.32bit.mir | 2 +- ...egion_subtyping_basic.main.nll.0.64bit.mir | 2 +- .../clippy_lints/src/large_const_arrays.rs | 2 +- .../clippy_lints/src/large_stack_arrays.rs | 2 +- src/tools/clippy/clippy_utils/src/consts.rs | 2 +- 74 files changed, 173 insertions(+), 169 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index e405baf7575dd..ae6b8e0ae30f7 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -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, }, diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 07136e1b76a9f..fbe830b2b1030 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -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 { diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 7d2e3e52f3443..3d14a0eca52bb 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -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), }, diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index ae43464791d23..f849770283285 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -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(); diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index 479b2b05f4305..7e0d3f9adaa28 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -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); diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index db43f7a425ce6..6ee77db4017ea 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -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")] diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 6338e08380f2c..597ca4cfcdd06 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -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>, ) -> 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), } } diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index 0fddafbee7960..b9866995e9f95 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -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 { - match c.val() { + match c.kind() { ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam), _ => c.super_visit_with(self), } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index 9fd94dc334ff2..6e5a0c813ac20 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -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. diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index d1e776854b231..67a356918d1b9 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -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 { diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 076825771971a..9c30c81123b14 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -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()), }) } diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index c7fa2527eb2f3..f251d561c6087 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -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() diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index ec468f428528e..8938ed78a94d7 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -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. diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 120e57ecebd75..67dcb6e708b0e 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -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), diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 4c734b1589b85..07f5d72fac40a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -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(); diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index edafee2df5765..024f74099476c 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -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 diff --git a/compiler/rustc_infer/src/infer/fudge.rs b/compiler/rustc_infer/src/infer/fudge.rs index 1e6995db2698f..2f0eadce631e2 100644 --- a/compiler/rustc_infer/src/infer/fudge.rs +++ b/compiler/rustc_infer/src/infer/fudge.rs @@ -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. diff --git a/compiler/rustc_infer/src/infer/higher_ranked/mod.rs b/compiler/rustc_infer/src/infer/higher_ranked/mod.rs index bb3b410b2bde3..c82685d1b70c9 100644 --- a/compiler/rustc_infer/src/infer/higher_ranked/mod.rs +++ b/compiler/rustc_infer/src/infer/higher_ranked/mod.rs @@ -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 }, }), diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 0e30b136622a0..cc34e2981bc32 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1743,7 +1743,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 { - match ct.val() { + match ct.kind() { ty::ConstKind::Infer(InferConst::Var(v)) => Some(TyOrConstInferVar::Const(v)), _ => None, } @@ -1822,7 +1822,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() diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 9b6e5c8a347af..ebe156d081d32 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -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); } diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index ce3c7328e2da2..d830000b65f69 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -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)); } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 50017955ee19d..7cf447a141970 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -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)) => { diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 6b7ac883f5ceb..79f94802d2017 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -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(), }) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 6823dfc6933dd..1511b51fa2548 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2956,7 +2956,7 @@ impl<'tcx> Constant<'tcx> { impl<'tcx> From> 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> { 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> { 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, diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index eaa68bf1b38dd..739c543dea773 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -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)); } } diff --git a/compiler/rustc_middle/src/ty/_match.rs b/compiler/rustc_middle/src/ty/_match.rs index 3243ef28ff005..e6aab30a150de 100644 --- a/compiler/rustc_middle/src/ty/_match.rs +++ b/compiler/rustc_middle/src/ty/_match.rs @@ -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); } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 7af7eb4f5ecfd..0e87a05bade09 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -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 { - 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 { - 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()), diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 610234d45ce67..5c0cf534b8025 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -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> { diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 1acded8c6e499..a84b3c9373b13 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -478,7 +478,7 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> { } fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow { - match c.val() { + match c.kind() { ConstKind::Infer(..) | ConstKind::Bound(..) | ConstKind::Placeholder(..) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index a6c14ea0de343..812dd2adc2ed7 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -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(); } diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index 208cd9ba16a08..a8145e6820cac 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -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, diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 7a3d615862cba..ea6bb8a7abd4b 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -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); diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 5ccf735f1d2a2..99aa182f3a6a6 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -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 { - 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()), ); diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 53a97a46b2d26..05f332cdd5fd5 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -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)); diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 9712d66b30a22..31103b8d77ea3 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -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, diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 9759bec996e96..961792260e410 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1148,9 +1148,9 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> { folder: &mut F, ) -> Result { 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>(&self, visitor: &mut V) -> ControlFlow { self.ty().visit_with(visitor)?; - self.val().visit_with(visitor) + self.kind().visit_with(visitor) } } diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 1ae16a9015ad3..ca29dd7c08f45 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -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) diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 22cb46a4cbcc2..33ef0283745c1 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -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()), diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 09946f02448d6..02fe1f3a7bded 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -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(_) diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 035e94eecee23..a87134d1f52e3 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -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 } diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs index b7de3f28872e5..26532ae33d0cf 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs @@ -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" ), diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 417cf0f89c412..83175439b70fb 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -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; diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index b17485fd542d3..2529a7c4232b2 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -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, }), diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 84fdb136bd41c..15ad13009e59a 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -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: _, diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index a1490d77ccb5b..49403ba03a45d 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -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, } }), diff --git a/compiler/rustc_mir_transform/src/required_consts.rs b/compiler/rustc_mir_transform/src/required_consts.rs index b87220a3aa4f3..827ce0c02ac42 100644 --- a/compiler/rustc_mir_transform/src/required_consts.rs +++ b/compiler/rustc_mir_transform/src/required_consts.rs @@ -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); } } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index a9ca89217972e..dfaf464587be2 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -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) { diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index dc1f1c9927d5d..f29143b448049 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -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 diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index b3773d5be2874..2f7e413b087ae 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -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 { // 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(_), diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index dc1946bcdc2eb..f79f7a4ebdfc8 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -582,7 +582,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { fn print_const(mut self, ct: ty::Const<'tcx>) -> Result { // 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 diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index c1faa15d43cbe..9dd8588ceceea 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -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()) { diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 4bcd3bdd1ef45..c95d43b71cf1b 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -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, diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index c005541ae1459..6cf39be2a9d5c 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -245,7 +245,7 @@ impl<'tcx> AbstractConst<'tcx> { tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, ) -> Result>, 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, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 4263a6fdf1841..371157a99f881 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -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)))); diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 053e871c14f6e..50735ef048bf6 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -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, diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 7341ab0ab124a..565f3f509db39 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -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() }; diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index e9e2dca17e9e4..b00f8fe73a1de 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -141,7 +141,7 @@ impl<'tcx> TypeVisitor<'tcx> for MaxEscapingBoundVarVisitor { } fn visit_const(&mut self, ct: ty::Const<'tcx>) -> ControlFlow { - 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. diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index cbf29af1c554e..5942bb79d69e8 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -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, }, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index a484b594418c2..07e7bad6cb787 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -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, diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 2ce2a44d3db76..8d666046ad9fd 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -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( diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 3de2fa2215bb2..497819ce5c567 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -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(), diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 4fd512d7b8de2..e9f05ce9e0688 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -514,7 +514,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime LowerInto<'tcx, chalk_ir::Const>> for ty::Const<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Const> { 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) -> 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 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 }) } } diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 80abb28ee58c1..bab751ac040a1 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -539,7 +539,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes<'tcx>( } fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { - 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. diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 974f5ffcbcc52..acb2aa44ad5df 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -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), ), diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 362e034ba5452..2e4756dcf4269 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -1387,7 +1387,7 @@ fn check_where_clauses<'tcx, 'fcx>( } fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { - 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) diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 82f2adda3b043..95985c1231359 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2353,7 +2353,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(( diff --git a/compiler/rustc_typeck/src/constrained_generic_params.rs b/compiler/rustc_typeck/src/constrained_generic_params.rs index fc299057f4bf1..858cf63390a34 100644 --- a/compiler/rustc_typeck/src/constrained_generic_params.rs +++ b/compiler/rustc_typeck/src/constrained_generic_params.rs @@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector { } fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { - match c.val() { + match c.kind() { ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => { // Constant expressions are not injective return c.ty().visit_with(self); diff --git a/compiler/rustc_typeck/src/variance/constraints.rs b/compiler/rustc_typeck/src/variance/constraints.rs index 690c362d853e7..a7dcbfff207f6 100644 --- a/compiler/rustc_typeck/src/variance/constraints.rs +++ b/compiler/rustc_typeck/src/variance/constraints.rs @@ -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); } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index caea2544b5450..e7da6eff51959 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -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()) } diff --git a/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir b/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir index f79e2705ad29c..c357210978a60 100644 --- a/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir +++ b/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir @@ -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 diff --git a/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir b/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir index 162cacef8a54a..382c89a1fb9b5 100644 --- a/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir +++ b/src/test/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir @@ -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 diff --git a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs index 14f84a832aa3e..ed47490e230ce 100644 --- a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs @@ -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; diff --git a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs index 57b0d709acd4d..4ca69465fad41 100644 --- a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs @@ -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; diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index d487868cafe50..159c5d53d0292 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -582,7 +582,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { pub fn miri_to_const(result: ty::Const<'_>) -> Option { 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)),