Skip to content

Commit de1f540

Browse files
committed
Rename DiagnosticStyledString as DiagStyledString.
1 parent 634fdd2 commit de1f540

File tree

5 files changed

+53
-60
lines changed

5 files changed

+53
-60
lines changed

compiler/rustc_errors/src/diagnostic.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ pub struct IsLint {
213213
}
214214

215215
#[derive(Debug, PartialEq, Eq)]
216-
pub struct DiagnosticStyledString(pub Vec<StringPart>);
216+
pub struct DiagStyledString(pub Vec<StringPart>);
217217

218-
impl DiagnosticStyledString {
219-
pub fn new() -> DiagnosticStyledString {
220-
DiagnosticStyledString(vec![])
218+
impl DiagStyledString {
219+
pub fn new() -> DiagStyledString {
220+
DiagStyledString(vec![])
221221
}
222222
pub fn push_normal<S: Into<String>>(&mut self, t: S) {
223223
self.0.push(StringPart::normal(t));
@@ -232,12 +232,12 @@ impl DiagnosticStyledString {
232232
self.push_normal(t);
233233
}
234234
}
235-
pub fn normal<S: Into<String>>(t: S) -> DiagnosticStyledString {
236-
DiagnosticStyledString(vec![StringPart::normal(t)])
235+
pub fn normal<S: Into<String>>(t: S) -> DiagStyledString {
236+
DiagStyledString(vec![StringPart::normal(t)])
237237
}
238238

239-
pub fn highlighted<S: Into<String>>(t: S) -> DiagnosticStyledString {
240-
DiagnosticStyledString(vec![StringPart::highlighted(t)])
239+
pub fn highlighted<S: Into<String>>(t: S) -> DiagStyledString {
240+
DiagStyledString(vec![StringPart::highlighted(t)])
241241
}
242242

243243
pub fn content(&self) -> String {
@@ -638,19 +638,19 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
638638
pub fn note_expected_found(
639639
&mut self,
640640
expected_label: &dyn fmt::Display,
641-
expected: DiagnosticStyledString,
641+
expected: DiagStyledString,
642642
found_label: &dyn fmt::Display,
643-
found: DiagnosticStyledString,
643+
found: DiagStyledString,
644644
) -> &mut Self {
645645
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
646646
}
647647

648648
pub fn note_expected_found_extra(
649649
&mut self,
650650
expected_label: &dyn fmt::Display,
651-
expected: DiagnosticStyledString,
651+
expected: DiagStyledString,
652652
found_label: &dyn fmt::Display,
653-
found: DiagnosticStyledString,
653+
found: DiagStyledString,
654654
expected_extra: &dyn fmt::Display,
655655
found_extra: &dyn fmt::Display,
656656
) -> &mut Self {

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ extern crate self as rustc_errors;
3838
pub use codes::*;
3939
pub use diagnostic::{
4040
AddToDiagnostic, BugAbort, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue,
41-
DiagInner, DiagnosticStyledString, EmissionGuarantee, FatalAbort, IntoDiagnostic,
42-
IntoDiagnosticArg, StringPart, Subdiag, SubdiagnosticMessageOp,
41+
DiagInner, DiagStyledString, EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg,
42+
StringPart, Subdiag, SubdiagnosticMessageOp,
4343
};
4444
pub use diagnostic_impls::{
4545
DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime,

compiler/rustc_infer/src/errors/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hir::GenericParamKind;
22
use rustc_errors::{
3-
codes::*, AddToDiagnostic, Applicability, Diag, DiagnosticMessage, DiagnosticStyledString,
3+
codes::*, AddToDiagnostic, Applicability, Diag, DiagStyledString, DiagnosticMessage,
44
EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp,
55
};
66
use rustc_hir as hir;
@@ -220,7 +220,7 @@ pub enum RegionOriginNote<'a> {
220220
WithRequirement {
221221
span: Span,
222222
requirement: ObligationCauseAsDiagArg<'a>,
223-
expected_found: Option<(DiagnosticStyledString, DiagnosticStyledString)>,
223+
expected_found: Option<(DiagStyledString, DiagStyledString)>,
224224
},
225225
}
226226

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+33-40
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ use crate::traits::{
6060

6161
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
6262
use rustc_errors::{
63-
codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt,
64-
DiagnosticStyledString, ErrorGuaranteed, IntoDiagnosticArg,
63+
codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString,
64+
ErrorGuaranteed, IntoDiagnosticArg,
6565
};
6666
use rustc_hir as hir;
6767
use rustc_hir::def::DefKind;
@@ -943,8 +943,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
943943
/// ```
944944
fn highlight_outer(
945945
&self,
946-
value: &mut DiagnosticStyledString,
947-
other_value: &mut DiagnosticStyledString,
946+
value: &mut DiagStyledString,
947+
other_value: &mut DiagStyledString,
948948
name: String,
949949
sub: ty::GenericArgsRef<'tcx>,
950950
pos: usize,
@@ -1017,8 +1017,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10171017
/// ```
10181018
fn cmp_type_arg(
10191019
&self,
1020-
t1_out: &mut DiagnosticStyledString,
1021-
t2_out: &mut DiagnosticStyledString,
1020+
t1_out: &mut DiagStyledString,
1021+
t2_out: &mut DiagStyledString,
10221022
path: String,
10231023
sub: &'tcx [ty::GenericArg<'tcx>],
10241024
other_path: String,
@@ -1046,8 +1046,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10461046
/// Adds a `,` to the type representation only if it is appropriate.
10471047
fn push_comma(
10481048
&self,
1049-
value: &mut DiagnosticStyledString,
1050-
other_value: &mut DiagnosticStyledString,
1049+
value: &mut DiagStyledString,
1050+
other_value: &mut DiagStyledString,
10511051
len: usize,
10521052
pos: usize,
10531053
) {
@@ -1062,7 +1062,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10621062
&self,
10631063
sig1: &ty::PolyFnSig<'tcx>,
10641064
sig2: &ty::PolyFnSig<'tcx>,
1065-
) -> (DiagnosticStyledString, DiagnosticStyledString) {
1065+
) -> (DiagStyledString, DiagStyledString) {
10661066
let sig1 = &(self.normalize_fn_sig)(*sig1);
10671067
let sig2 = &(self.normalize_fn_sig)(*sig2);
10681068

@@ -1079,10 +1079,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10791079
let (lt2, sig2) = get_lifetimes(sig2);
10801080

10811081
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
1082-
let mut values = (
1083-
DiagnosticStyledString::normal("".to_string()),
1084-
DiagnosticStyledString::normal("".to_string()),
1085-
);
1082+
let mut values =
1083+
(DiagStyledString::normal("".to_string()), DiagStyledString::normal("".to_string()));
10861084

10871085
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
10881086
// ^^^^^^
@@ -1171,15 +1169,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11711169

11721170
/// Compares two given types, eliding parts that are the same between them and highlighting
11731171
/// relevant differences, and return two representation of those types for highlighted printing.
1174-
pub fn cmp(
1175-
&self,
1176-
t1: Ty<'tcx>,
1177-
t2: Ty<'tcx>,
1178-
) -> (DiagnosticStyledString, DiagnosticStyledString) {
1172+
pub fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagStyledString, DiagStyledString) {
11791173
debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind());
11801174

11811175
// helper functions
1182-
let recurse = |t1, t2, values: &mut (DiagnosticStyledString, DiagnosticStyledString)| {
1176+
let recurse = |t1, t2, values: &mut (DiagStyledString, DiagStyledString)| {
11831177
let (x1, x2) = self.cmp(t1, t2);
11841178
(values.0).0.extend(x1.0);
11851179
(values.1).0.extend(x2.0);
@@ -1198,7 +1192,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11981192
fn push_ref<'tcx>(
11991193
region: ty::Region<'tcx>,
12001194
mutbl: hir::Mutability,
1201-
s: &mut DiagnosticStyledString,
1195+
s: &mut DiagStyledString,
12021196
) {
12031197
s.push_highlighted(fmt_region(region));
12041198
s.push_highlighted(mutbl.prefix_str());
@@ -1207,7 +1201,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12071201
fn maybe_highlight<T: Eq + ToString>(
12081202
t1: T,
12091203
t2: T,
1210-
(buf1, buf2): &mut (DiagnosticStyledString, DiagnosticStyledString),
1204+
(buf1, buf2): &mut (DiagStyledString, DiagStyledString),
12111205
tcx: TyCtxt<'_>,
12121206
) {
12131207
let highlight = t1 != t2;
@@ -1226,7 +1220,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12261220
mut1: hir::Mutability,
12271221
r2: ty::Region<'tcx>,
12281222
mut2: hir::Mutability,
1229-
ss: &mut (DiagnosticStyledString, DiagnosticStyledString),
1223+
ss: &mut (DiagStyledString, DiagStyledString),
12301224
) {
12311225
let (r1, r2) = (fmt_region(r1), fmt_region(r2));
12321226
if r1 != r2 {
@@ -1255,7 +1249,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12551249
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
12561250
let sub_no_defaults_2 =
12571251
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
1258-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1252+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
12591253
let path1 = self.tcx.def_path_str(did1);
12601254
let path2 = self.tcx.def_path_str(did2);
12611255
if did1 == did2 {
@@ -1424,8 +1418,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14241418
if split_idx >= min_len {
14251419
// paths are identical, highlight everything
14261420
(
1427-
DiagnosticStyledString::highlighted(t1_str),
1428-
DiagnosticStyledString::highlighted(t2_str),
1421+
DiagStyledString::highlighted(t1_str),
1422+
DiagStyledString::highlighted(t2_str),
14291423
)
14301424
} else {
14311425
let (common, uniq1) = t1_str.split_at(split_idx);
@@ -1444,29 +1438,28 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14441438

14451439
// When finding `&T != &T`, compare the references, then recurse into pointee type
14461440
(&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) => {
1447-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1441+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
14481442
cmp_ty_refs(r1, mutbl1, r2, mutbl2, &mut values);
14491443
recurse(ref_ty1, ref_ty2, &mut values);
14501444
values
14511445
}
14521446
// When finding T != &T, highlight the borrow
14531447
(&ty::Ref(r1, ref_ty1, mutbl1), _) => {
1454-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1448+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
14551449
push_ref(r1, mutbl1, &mut values.0);
14561450
recurse(ref_ty1, t2, &mut values);
14571451
values
14581452
}
14591453
(_, &ty::Ref(r2, ref_ty2, mutbl2)) => {
1460-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1454+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
14611455
push_ref(r2, mutbl2, &mut values.1);
14621456
recurse(t1, ref_ty2, &mut values);
14631457
values
14641458
}
14651459

14661460
// When encountering tuples of the same size, highlight only the differing types
14671461
(&ty::Tuple(args1), &ty::Tuple(args2)) if args1.len() == args2.len() => {
1468-
let mut values =
1469-
(DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("("));
1462+
let mut values = (DiagStyledString::normal("("), DiagStyledString::normal("("));
14701463
let len = args1.len();
14711464
for (i, (left, right)) in args1.iter().zip(args2).enumerate() {
14721465
recurse(left, right, &mut values);
@@ -1516,7 +1509,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
15161509
(ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2),
15171510

15181511
_ => {
1519-
let mut strs = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1512+
let mut strs = (DiagStyledString::new(), DiagStyledString::new());
15201513
maybe_highlight(t1, t2, &mut strs, self.tcx);
15211514
strs
15221515
}
@@ -2215,7 +2208,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22152208
fn values_str(
22162209
&self,
22172210
values: ValuePairs<'tcx>,
2218-
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
2211+
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
22192212
match values {
22202213
infer::Regions(exp_found) => self.expected_found_str(exp_found),
22212214
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
@@ -2248,7 +2241,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22482241
fn expected_found_str_term(
22492242
&self,
22502243
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
2251-
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
2244+
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
22522245
let exp_found = self.resolve_vars_if_possible(exp_found);
22532246
if exp_found.references_error() {
22542247
return None;
@@ -2266,17 +2259,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22662259
let mut path = None;
22672260
if exp_s.len() > len {
22682261
let exp_s = self.tcx.short_ty_string(expected, &mut path);
2269-
exp = DiagnosticStyledString::highlighted(exp_s);
2262+
exp = DiagStyledString::highlighted(exp_s);
22702263
}
22712264
if fnd_s.len() > len {
22722265
let fnd_s = self.tcx.short_ty_string(found, &mut path);
2273-
fnd = DiagnosticStyledString::highlighted(fnd_s);
2266+
fnd = DiagStyledString::highlighted(fnd_s);
22742267
}
22752268
(exp, fnd, path)
22762269
}
22772270
_ => (
2278-
DiagnosticStyledString::highlighted(exp_found.expected.to_string()),
2279-
DiagnosticStyledString::highlighted(exp_found.found.to_string()),
2271+
DiagStyledString::highlighted(exp_found.expected.to_string()),
2272+
DiagStyledString::highlighted(exp_found.found.to_string()),
22802273
None,
22812274
),
22822275
})
@@ -2286,15 +2279,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22862279
fn expected_found_str<T: fmt::Display + TypeFoldable<TyCtxt<'tcx>>>(
22872280
&self,
22882281
exp_found: ty::error::ExpectedFound<T>,
2289-
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
2282+
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
22902283
let exp_found = self.resolve_vars_if_possible(exp_found);
22912284
if exp_found.references_error() {
22922285
return None;
22932286
}
22942287

22952288
Some((
2296-
DiagnosticStyledString::highlighted(exp_found.expected.to_string()),
2297-
DiagnosticStyledString::highlighted(exp_found.found.to_string()),
2289+
DiagStyledString::highlighted(exp_found.expected.to_string()),
2290+
DiagStyledString::highlighted(exp_found.found.to_string()),
22982291
None,
22992292
))
23002293
}

compiler/rustc_lint/src/lints.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::num::NonZero;
55
use crate::errors::RequestedLevel;
66
use crate::fluent_generated as fluent;
77
use rustc_errors::{
8-
codes::*, AddToDiagnostic, Applicability, DecorateLint, Diag, DiagnosticMessage,
9-
DiagnosticStyledString, EmissionGuarantee, SubdiagnosticMessageOp, SuggestionStyle,
8+
codes::*, AddToDiagnostic, Applicability, DecorateLint, Diag, DiagStyledString,
9+
DiagnosticMessage, EmissionGuarantee, SubdiagnosticMessageOp, SuggestionStyle,
1010
};
1111
use rustc_hir::def_id::DefId;
1212
use rustc_macros::{LintDiagnostic, Subdiagnostic};
@@ -508,9 +508,9 @@ impl AddToDiagnostic for BuiltinClashingExternSub<'_> {
508508
diag: &mut Diag<'_, G>,
509509
_f: F,
510510
) {
511-
let mut expected_str = DiagnosticStyledString::new();
511+
let mut expected_str = DiagStyledString::new();
512512
expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
513-
let mut found_str = DiagnosticStyledString::new();
513+
let mut found_str = DiagStyledString::new();
514514
found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
515515
diag.note_expected_found(&"", expected_str, &"", found_str);
516516
}

0 commit comments

Comments
 (0)