Skip to content

Commit 8d5cbc7

Browse files
authoredNov 1, 2024
Rollup merge of rust-lang#132147 - estebank:long-types-2, r=davidtwco
Tweak E0277 output when a candidate is available *Follow up to rust-lang#132086.* Go from ``` error[E0277]: the trait bound `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@src/main.rs:9:17: 9:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@src/main.rs:11:24: 11:27}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>: CSTParser<'a>` is not satisfied --> src/main.rs:7:50 | 7 | fn leaf<'a, O>(parser: impl CSTParser<'a, O>) -> impl CSTParser<'a, ()> { | ^^^^^^^^^^^^^^^^^^^^^^ the trait `chumsky::private::ParserSealed<'_, &str, (), chumsky::extra::Full<EmptyErr, (), ()>>` is not implemented for `Then<Ignored<Filter<Any<&str, ...>, ...>, ...>, ..., ..., ..., ...>`, which is required by `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@src/main.rs:9:17: 9:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@src/main.rs:11:24: 11:27}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>: CSTParser<'a>` | = help: the trait `chumsky::private::ParserSealed<'_, &'a str, ((), ()), chumsky::extra::Full<EmptyErr, (), ()>>` is implemented for `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@src/main.rs:9:17: 9:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@src/main.rs:11:24: 11:27}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>` = help: for that trait implementation, expected `((), ())`, found `()` = note: required for `Then<Ignored<Filter<Any<&str, ...>, ...>, ...>, ..., ..., ..., ...>` to implement `Parser<'_, &str, ()>` note: required for `Then<Ignored<Filter<Any<&str, ...>, ...>, ...>, ..., ..., ..., ...>` to implement `CSTParser<'a>` --> src/main.rs:5:16 | 5 | impl<'a, O, T> CSTParser<'a, O> for T where T: Parser<'a, &'a str, O> {} | ^^^^^^^^^^^^^^^^ ^ ---------------------- unsatisfied trait bound introduced here = note: the full name for the type has been written to '/home/gh-estebank/longlong/target/debug/deps/longlong-0008f9a4f2023b08.long-type-13239977239800463552.txt' = note: consider using `--verbose` to print the full type name to the console = note: the full name for the type has been written to '/home/gh-estebank/longlong/target/debug/deps/longlong-0008f9a4f2023b08.long-type-13239977239800463552.txt' = note: consider using `--verbose` to print the full type name to the console ``` to ``` error[E0277]: the trait bound `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@src/main.rs:9:17: 9:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@src/main.rs:11:24: 11:27}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>: CSTParser<'a>` is not satisfied --> src/main.rs:7:50 | 7 | fn leaf<'a, O>(parser: impl CSTParser<'a, O>) -> impl CSTParser<'a, ()> { | ^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound ... 11 | ws.then(parser.map(|_| ())) | --------------------------- return type was inferred to be `Then<Ignored<..., ...>, ..., ..., ..., ...>` here | = help: the trait `ParserSealed<'_, &_, (), Full<_, _, _>>` is not implemented for `Then<Ignored<..., ...>, ..., ..., ..., ...>` but trait `ParserSealed<'_, &'a _, ((), ()), Full<_, _, _>>` is implemented for it = help: for that trait implementation, expected `((), ())`, found `()` = note: required for `Then<Ignored<..., ...>, ..., ..., ..., ...>` to implement `Parser<'_, &str, ()>` note: required for `Then<Ignored<..., ...>, ..., ..., ..., ...>` to implement `CSTParser<'a>` --> src/main.rs:5:16 | 5 | impl<'a, O, T> CSTParser<'a, O> for T where T: Parser<'a, &'a str, O> {} | ^^^^^^^^^^^^^^^^ ^ ---------------------- unsatisfied trait bound introduced here = note: the full name for the type has been written to '/home/gh-estebank/longlong/target/debug/deps/longlong-df9d52be87eada65.long-type-1337037744507305372.txt' = note: consider using `--verbose` to print the full type name to the console ``` * Remove redundant wording * Introduce trait diff highlighting logic and use it * Fix incorrect "long type written to path" logic (can be split off) * Point at tail expression in more cases in E0277 * Avoid long primary span labels in E0277 by moving them to a `help` Fix rust-lang#132013. There are individual commits that can be their own PR. If the review load is too big, happy to split them off.
2 parents 7bcac57 + 083d70f commit 8d5cbc7

File tree

75 files changed

+476
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+476
-217
lines changed
 

Diff for: ‎compiler/rustc_middle/src/ty/error.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::borrow::Cow;
2+
use std::fs::File;
23
use std::hash::{DefaultHasher, Hash, Hasher};
4+
use std::io::{Read, Write};
35
use std::path::PathBuf;
46

57
use rustc_errors::pluralize;
@@ -250,8 +252,8 @@ impl<'tcx> TyCtxt<'tcx> {
250252
}
251253

252254
let width = self.sess.diagnostic_width();
253-
let length_limit = width.saturating_sub(30);
254-
if regular.len() <= width {
255+
let length_limit = width / 2;
256+
if regular.len() <= width * 2 / 3 {
255257
return regular;
256258
}
257259
let short = self.ty_string_with_limit(ty, length_limit);
@@ -265,7 +267,20 @@ impl<'tcx> TyCtxt<'tcx> {
265267
*path = Some(path.take().unwrap_or_else(|| {
266268
self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None)
267269
}));
268-
match std::fs::write(path.as_ref().unwrap(), &format!("{regular}\n")) {
270+
let Ok(mut file) =
271+
File::options().create(true).read(true).append(true).open(&path.as_ref().unwrap())
272+
else {
273+
return regular;
274+
};
275+
276+
// Do not write the same type to the file multiple times.
277+
let mut contents = String::new();
278+
let _ = file.read_to_string(&mut contents);
279+
if let Some(_) = contents.lines().find(|line| line == &regular) {
280+
return short;
281+
}
282+
283+
match write!(file, "{regular}\n") {
269284
Ok(_) => short,
270285
Err(_) => regular,
271286
}

Diff for: ‎compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+61
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,67 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
766766
values
767767
}
768768

769+
pub fn cmp_traits(
770+
&self,
771+
def_id1: DefId,
772+
args1: &[ty::GenericArg<'tcx>],
773+
def_id2: DefId,
774+
args2: &[ty::GenericArg<'tcx>],
775+
) -> (DiagStyledString, DiagStyledString) {
776+
let mut values = (DiagStyledString::new(), DiagStyledString::new());
777+
778+
if def_id1 != def_id2 {
779+
values.0.push_highlighted(self.tcx.def_path_str(def_id1).as_str());
780+
values.1.push_highlighted(self.tcx.def_path_str(def_id2).as_str());
781+
} else {
782+
values.0.push_normal(self.tcx.item_name(def_id1).as_str());
783+
values.1.push_normal(self.tcx.item_name(def_id2).as_str());
784+
}
785+
786+
if args1.len() != args2.len() {
787+
let (pre, post) = if args1.len() > 0 { ("<", ">") } else { ("", "") };
788+
values.0.push_normal(format!(
789+
"{pre}{}{post}",
790+
args1.iter().map(|a| a.to_string()).collect::<Vec<_>>().join(", ")
791+
));
792+
let (pre, post) = if args2.len() > 0 { ("<", ">") } else { ("", "") };
793+
values.1.push_normal(format!(
794+
"{pre}{}{post}",
795+
args2.iter().map(|a| a.to_string()).collect::<Vec<_>>().join(", ")
796+
));
797+
return values;
798+
}
799+
800+
if args1.len() > 0 {
801+
values.0.push_normal("<");
802+
values.1.push_normal("<");
803+
}
804+
for (i, (a, b)) in std::iter::zip(args1, args2).enumerate() {
805+
let a_str = a.to_string();
806+
let b_str = b.to_string();
807+
if let (Some(a), Some(b)) = (a.as_type(), b.as_type()) {
808+
let (a, b) = self.cmp(a, b);
809+
values.0.0.extend(a.0);
810+
values.1.0.extend(b.0);
811+
} else if a_str != b_str {
812+
values.0.push_highlighted(a_str);
813+
values.1.push_highlighted(b_str);
814+
} else {
815+
values.0.push_normal(a_str);
816+
values.1.push_normal(b_str);
817+
}
818+
if i + 1 < args1.len() {
819+
values.0.push_normal(", ");
820+
values.1.push_normal(", ");
821+
}
822+
}
823+
if args1.len() > 0 {
824+
values.0.push_normal(">");
825+
values.1.push_normal(">");
826+
}
827+
values
828+
}
829+
769830
/// Compares two given types, eliding parts that are the same between them and highlighting
770831
/// relevant differences, and return two representation of those types for highlighted printing.
771832
pub fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagStyledString, DiagStyledString) {

0 commit comments

Comments
 (0)