Skip to content

Commit 9b3520e

Browse files
committed
Rename DiagnosticStyledString as DiagStyledString.
1 parent 6280a8c commit 9b3520e

File tree

5 files changed

+53
-60
lines changed

5 files changed

+53
-60
lines changed

Diff for: 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 {

Diff for: 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,

Diff for: 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

Diff for: 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;
@@ -945,8 +945,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
945945
/// ```
946946
fn highlight_outer(
947947
&self,
948-
value: &mut DiagnosticStyledString,
949-
other_value: &mut DiagnosticStyledString,
948+
value: &mut DiagStyledString,
949+
other_value: &mut DiagStyledString,
950950
name: String,
951951
sub: ty::GenericArgsRef<'tcx>,
952952
pos: usize,
@@ -1019,8 +1019,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10191019
/// ```
10201020
fn cmp_type_arg(
10211021
&self,
1022-
t1_out: &mut DiagnosticStyledString,
1023-
t2_out: &mut DiagnosticStyledString,
1022+
t1_out: &mut DiagStyledString,
1023+
t2_out: &mut DiagStyledString,
10241024
path: String,
10251025
sub: &'tcx [ty::GenericArg<'tcx>],
10261026
other_path: String,
@@ -1048,8 +1048,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10481048
/// Adds a `,` to the type representation only if it is appropriate.
10491049
fn push_comma(
10501050
&self,
1051-
value: &mut DiagnosticStyledString,
1052-
other_value: &mut DiagnosticStyledString,
1051+
value: &mut DiagStyledString,
1052+
other_value: &mut DiagStyledString,
10531053
len: usize,
10541054
pos: usize,
10551055
) {
@@ -1064,7 +1064,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10641064
&self,
10651065
sig1: &ty::PolyFnSig<'tcx>,
10661066
sig2: &ty::PolyFnSig<'tcx>,
1067-
) -> (DiagnosticStyledString, DiagnosticStyledString) {
1067+
) -> (DiagStyledString, DiagStyledString) {
10681068
let sig1 = &(self.normalize_fn_sig)(*sig1);
10691069
let sig2 = &(self.normalize_fn_sig)(*sig2);
10701070

@@ -1081,10 +1081,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10811081
let (lt2, sig2) = get_lifetimes(sig2);
10821082

10831083
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
1084-
let mut values = (
1085-
DiagnosticStyledString::normal("".to_string()),
1086-
DiagnosticStyledString::normal("".to_string()),
1087-
);
1084+
let mut values =
1085+
(DiagStyledString::normal("".to_string()), DiagStyledString::normal("".to_string()));
10881086

10891087
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
10901088
// ^^^^^^
@@ -1173,15 +1171,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11731171

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

11831177
// helper functions
1184-
let recurse = |t1, t2, values: &mut (DiagnosticStyledString, DiagnosticStyledString)| {
1178+
let recurse = |t1, t2, values: &mut (DiagStyledString, DiagStyledString)| {
11851179
let (x1, x2) = self.cmp(t1, t2);
11861180
(values.0).0.extend(x1.0);
11871181
(values.1).0.extend(x2.0);
@@ -1200,7 +1194,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12001194
fn push_ref<'tcx>(
12011195
region: ty::Region<'tcx>,
12021196
mutbl: hir::Mutability,
1203-
s: &mut DiagnosticStyledString,
1197+
s: &mut DiagStyledString,
12041198
) {
12051199
s.push_highlighted(fmt_region(region));
12061200
s.push_highlighted(mutbl.prefix_str());
@@ -1209,7 +1203,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12091203
fn maybe_highlight<T: Eq + ToString>(
12101204
t1: T,
12111205
t2: T,
1212-
(buf1, buf2): &mut (DiagnosticStyledString, DiagnosticStyledString),
1206+
(buf1, buf2): &mut (DiagStyledString, DiagStyledString),
12131207
tcx: TyCtxt<'_>,
12141208
) {
12151209
let highlight = t1 != t2;
@@ -1228,7 +1222,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12281222
mut1: hir::Mutability,
12291223
r2: ty::Region<'tcx>,
12301224
mut2: hir::Mutability,
1231-
ss: &mut (DiagnosticStyledString, DiagnosticStyledString),
1225+
ss: &mut (DiagStyledString, DiagStyledString),
12321226
) {
12331227
let (r1, r2) = (fmt_region(r1), fmt_region(r2));
12341228
if r1 != r2 {
@@ -1257,7 +1251,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12571251
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
12581252
let sub_no_defaults_2 =
12591253
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
1260-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1254+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
12611255
let path1 = self.tcx.def_path_str(did1);
12621256
let path2 = self.tcx.def_path_str(did2);
12631257
if did1 == did2 {
@@ -1426,8 +1420,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14261420
if split_idx >= min_len {
14271421
// paths are identical, highlight everything
14281422
(
1429-
DiagnosticStyledString::highlighted(t1_str),
1430-
DiagnosticStyledString::highlighted(t2_str),
1423+
DiagStyledString::highlighted(t1_str),
1424+
DiagStyledString::highlighted(t2_str),
14311425
)
14321426
} else {
14331427
let (common, uniq1) = t1_str.split_at(split_idx);
@@ -1446,29 +1440,28 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14461440

14471441
// When finding `&T != &T`, compare the references, then recurse into pointee type
14481442
(&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) => {
1449-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1443+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
14501444
cmp_ty_refs(r1, mutbl1, r2, mutbl2, &mut values);
14511445
recurse(ref_ty1, ref_ty2, &mut values);
14521446
values
14531447
}
14541448
// When finding T != &T, highlight the borrow
14551449
(&ty::Ref(r1, ref_ty1, mutbl1), _) => {
1456-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1450+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
14571451
push_ref(r1, mutbl1, &mut values.0);
14581452
recurse(ref_ty1, t2, &mut values);
14591453
values
14601454
}
14611455
(_, &ty::Ref(r2, ref_ty2, mutbl2)) => {
1462-
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1456+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
14631457
push_ref(r2, mutbl2, &mut values.1);
14641458
recurse(t1, ref_ty2, &mut values);
14651459
values
14661460
}
14671461

14681462
// When encountering tuples of the same size, highlight only the differing types
14691463
(&ty::Tuple(args1), &ty::Tuple(args2)) if args1.len() == args2.len() => {
1470-
let mut values =
1471-
(DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("("));
1464+
let mut values = (DiagStyledString::normal("("), DiagStyledString::normal("("));
14721465
let len = args1.len();
14731466
for (i, (left, right)) in args1.iter().zip(args2).enumerate() {
14741467
recurse(left, right, &mut values);
@@ -1518,7 +1511,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
15181511
(ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2),
15191512

15201513
_ => {
1521-
let mut strs = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1514+
let mut strs = (DiagStyledString::new(), DiagStyledString::new());
15221515
maybe_highlight(t1, t2, &mut strs, self.tcx);
15231516
strs
15241517
}
@@ -2217,7 +2210,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22172210
fn values_str(
22182211
&self,
22192212
values: ValuePairs<'tcx>,
2220-
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
2213+
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
22212214
match values {
22222215
infer::Regions(exp_found) => self.expected_found_str(exp_found),
22232216
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
@@ -2250,7 +2243,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22502243
fn expected_found_str_term(
22512244
&self,
22522245
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
2253-
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
2246+
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
22542247
let exp_found = self.resolve_vars_if_possible(exp_found);
22552248
if exp_found.references_error() {
22562249
return None;
@@ -2268,17 +2261,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22682261
let mut path = None;
22692262
if exp_s.len() > len {
22702263
let exp_s = self.tcx.short_ty_string(expected, &mut path);
2271-
exp = DiagnosticStyledString::highlighted(exp_s);
2264+
exp = DiagStyledString::highlighted(exp_s);
22722265
}
22732266
if fnd_s.len() > len {
22742267
let fnd_s = self.tcx.short_ty_string(found, &mut path);
2275-
fnd = DiagnosticStyledString::highlighted(fnd_s);
2268+
fnd = DiagStyledString::highlighted(fnd_s);
22762269
}
22772270
(exp, fnd, path)
22782271
}
22792272
_ => (
2280-
DiagnosticStyledString::highlighted(exp_found.expected.to_string()),
2281-
DiagnosticStyledString::highlighted(exp_found.found.to_string()),
2273+
DiagStyledString::highlighted(exp_found.expected.to_string()),
2274+
DiagStyledString::highlighted(exp_found.found.to_string()),
22822275
None,
22832276
),
22842277
})
@@ -2288,15 +2281,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22882281
fn expected_found_str<T: fmt::Display + TypeFoldable<TyCtxt<'tcx>>>(
22892282
&self,
22902283
exp_found: ty::error::ExpectedFound<T>,
2291-
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
2284+
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
22922285
let exp_found = self.resolve_vars_if_possible(exp_found);
22932286
if exp_found.references_error() {
22942287
return None;
22952288
}
22962289

22972290
Some((
2298-
DiagnosticStyledString::highlighted(exp_found.expected.to_string()),
2299-
DiagnosticStyledString::highlighted(exp_found.found.to_string()),
2291+
DiagStyledString::highlighted(exp_found.expected.to_string()),
2292+
DiagStyledString::highlighted(exp_found.found.to_string()),
23002293
None,
23012294
))
23022295
}

Diff for: 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)