1
Fork 0

Use DiagnosticArgName in a few more places.

This commit is contained in:
Nicholas Nethercote 2024-02-02 10:14:14 +11:00
parent df322fc29f
commit 6fdaf3ef7f
8 changed files with 18 additions and 17 deletions

View file

@ -39,7 +39,6 @@ use rustc_target::spec::{MergeFunctions, SanitizerSet};
use crate::errors::ErrorCreatingRemarkDir; use crate::errors::ErrorCreatingRemarkDir;
use std::any::Any; use std::any::Any;
use std::borrow::Cow;
use std::fs; use std::fs;
use std::io; use std::io;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -1812,7 +1811,7 @@ impl Translate for SharedEmitter {
impl Emitter for SharedEmitter { impl Emitter for SharedEmitter {
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) { fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
let args: FxHashMap<Cow<'_, str>, DiagnosticArgValue> = let args: FxHashMap<DiagnosticArgName, DiagnosticArgValue> =
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect(); diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msgs: diag.messages.clone(), msgs: diag.messages.clone(),

View file

@ -1,6 +1,8 @@
use std::mem; use std::mem;
use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg}; use rustc_errors::{
DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg,
};
use rustc_hir::CRATE_HIR_ID; use rustc_hir::CRATE_HIR_ID;
use rustc_middle::mir::AssertKind; use rustc_middle::mir::AssertKind;
use rustc_middle::query::TyCtxtAt; use rustc_middle::query::TyCtxtAt;
@ -32,10 +34,7 @@ impl MachineStopType for ConstEvalErrKind {
AssertFailure(x) => x.diagnostic_message(), AssertFailure(x) => x.diagnostic_message(),
} }
} }
fn add_args( fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) {
self: Box<Self>,
adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue),
) {
use ConstEvalErrKind::*; use ConstEvalErrKind::*;
match *self { match *self {
ConstAccessesStatic | ModifiedGlobal => {} ConstAccessesStatic | ModifiedGlobal => {}

View file

@ -900,7 +900,7 @@ impl Diagnostic {
pub fn arg( pub fn arg(
&mut self, &mut self,
name: impl Into<Cow<'static, str>>, name: impl Into<DiagnosticArgName>,
arg: impl IntoDiagnosticArg, arg: impl IntoDiagnosticArg,
) -> &mut Self { ) -> &mut Self {
self.args.insert(name.into(), arg.into_diagnostic_arg()); self.args.insert(name.into(), arg.into_diagnostic_arg());

View file

@ -1,7 +1,6 @@
use std::borrow::Cow;
use std::fmt; use std::fmt;
use rustc_errors::{codes::*, DiagnosticArgValue, DiagnosticMessage}; use rustc_errors::{codes::*, DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage};
use rustc_macros::Diagnostic; use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
@ -95,14 +94,14 @@ pub(super) struct ConstNotUsedTraitAlias {
pub struct CustomSubdiagnostic<'a> { pub struct CustomSubdiagnostic<'a> {
pub msg: fn() -> DiagnosticMessage, pub msg: fn() -> DiagnosticMessage,
pub add_args: Box<dyn FnOnce(&mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue)) + 'a>, pub add_args: Box<dyn FnOnce(&mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) + 'a>,
} }
impl<'a> CustomSubdiagnostic<'a> { impl<'a> CustomSubdiagnostic<'a> {
pub fn label(x: fn() -> DiagnosticMessage) -> Self { pub fn label(x: fn() -> DiagnosticMessage) -> Self {
Self::label_and_then(x, |_| {}) Self::label_and_then(x, |_| {})
} }
pub fn label_and_then<F: FnOnce(&mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue)) + 'a>( pub fn label_and_then<F: FnOnce(&mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) + 'a>(
msg: fn() -> DiagnosticMessage, msg: fn() -> DiagnosticMessage,
f: F, f: F,
) -> Self { ) -> Self {

View file

@ -5,7 +5,9 @@ use crate::mir::{ConstAlloc, ConstValue};
use crate::ty::{layout, tls, Ty, TyCtxt, ValTree}; use crate::ty::{layout, tls, Ty, TyCtxt, ValTree};
use rustc_data_structures::sync::Lock; use rustc_data_structures::sync::Lock;
use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_errors::{
DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
};
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace; use rustc_session::CtfeBacktrace;
use rustc_span::{def_id::DefId, Span, DUMMY_SP}; use rustc_span::{def_id::DefId, Span, DUMMY_SP};
@ -485,7 +487,7 @@ pub trait MachineStopType: Any + fmt::Debug + Send {
fn diagnostic_message(&self) -> DiagnosticMessage; fn diagnostic_message(&self) -> DiagnosticMessage;
/// Add diagnostic arguments by passing name and value pairs to `adder`, which are passed to /// Add diagnostic arguments by passing name and value pairs to `adder`, which are passed to
/// fluent for formatting the translated diagnostic message. /// fluent for formatting the translated diagnostic message.
fn add_args(self: Box<Self>, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue)); fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue));
} }
impl dyn MachineStopType { impl dyn MachineStopType {

View file

@ -14,7 +14,9 @@ use crate::ty::{AdtDef, InstanceDef, UserTypeAnnotationIndex};
use crate::ty::{GenericArg, GenericArgsRef}; use crate::ty::{GenericArg, GenericArgsRef};
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_errors::{
DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
};
use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind}; use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind};

View file

@ -292,7 +292,7 @@ impl<O> AssertKind<O> {
} }
} }
pub fn add_args(self, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue)) pub fn add_args(self, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue))
where where
O: fmt::Debug, O: fmt::Debug,
{ {

View file

@ -34,7 +34,7 @@ pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{
fn add_args( fn add_args(
self: Box<Self>, self: Box<Self>,
_: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue), _: &mut dyn FnMut(rustc_errors::DiagnosticArgName, rustc_errors::DiagnosticArgValue),
) {} ) {}
} }
throw_machine_stop!(Zst) throw_machine_stop!(Zst)