Skip to content

Commit

Permalink
Auto merge of rust-lang#98091 - Dylan-DPC:rollup-ueb6b5x, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

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

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 14, 2022
2 parents da895e7 + 27f7805 commit edab34a
Show file tree
Hide file tree
Showing 96 changed files with 522 additions and 250 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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),
},
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ 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(),
}
} 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(),
Expand Down Expand Up @@ -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)
}
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// "universe" (param_env).
pub fn const_to_op(
&self,
val: ty::Const<'tcx>,
c: ty::Const<'tcx>,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
match val.val() {
match c.kind() {
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => {
throw_inval!(AlreadyReported(reported))
Expand All @@ -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),
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..) => (),
},
Expand All @@ -69,7 +69,7 @@ where
}

fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match c.val() {
match c.kind() {
ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam),
_ => c.super_visit_with(self),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -281,6 +283,7 @@ impl<S: Into<String>> From<S> for SubdiagnosticMessage {
///
/// Intended to be removed once diagnostics are entirely translatable.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
#[rustc_diagnostic_item = "DiagnosticMessage"]
pub enum DiagnosticMessage {
/// Non-translatable diagnostic message.
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {

/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(SessionSubdiagnostic)]` -- see [rustc_macros::SessionSubdiagnostic].
#[rustc_diagnostic_item = "AddSubdiagnostic"]
pub trait AddSubdiagnostic {
/// Add a subdiagnostic to an existing diagnostic.
fn add_to_diagnostic(self, diag: &mut Diagnostic);
Expand Down Expand Up @@ -283,6 +284,7 @@ impl Diagnostic {
///
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only
/// the `Span` supplied when creating the diagnostic is primary.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.span.push_span_label(span, self.subdiagnostic_message_to_diagnostic_message(label));
self
Expand Down Expand Up @@ -401,6 +403,7 @@ impl Diagnostic {
}

/// Add a note attached to this diagnostic.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.sub(Level::Note, msg, MultiSpan::new(), None);
self
Expand All @@ -423,6 +426,7 @@ impl Diagnostic {

/// Prints the span with a note above it.
/// This is like [`Diagnostic::note()`], but it gets its own span.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_note<S: Into<MultiSpan>>(
&mut self,
sp: S,
Expand All @@ -444,13 +448,15 @@ impl Diagnostic {
}

/// Add a warning attached to this diagnostic.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.sub(Level::Warning, msg, MultiSpan::new(), None);
self
}

/// Prints the span with a warning above it.
/// This is like [`Diagnostic::warn()`], but it gets its own span.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_warn<S: Into<MultiSpan>>(
&mut self,
sp: S,
Expand All @@ -461,6 +467,7 @@ impl Diagnostic {
}

/// Add a help message attached to this diagnostic.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.sub(Level::Help, msg, MultiSpan::new(), None);
self
Expand All @@ -474,6 +481,7 @@ impl Diagnostic {

/// Prints the span with some help above it.
/// This is like [`Diagnostic::help()`], but it gets its own span.
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
pub fn span_help<S: Into<MultiSpan>>(
&mut self,
sp: S,
Expand Down
Loading

0 comments on commit edab34a

Please sign in to comment.