Skip to content

Commit f93aa75

Browse files
committed
address review comments
1 parent db3b02f commit f93aa75

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -2682,35 +2682,27 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26822682
.flatten()
26832683
.chain(impls_of.blanket_impls().iter())
26842684
.collect::<Vec<_>>();
2685-
match &impls[..] {
2686-
[] => {}
2687-
[only] => {
2688-
err.help(with_no_trimmed_paths!(format!(
2689-
"type `{}` implements the trait",
2690-
tcx.type_of(*only).instantiate_identity(),
2691-
)));
2692-
}
2693-
impls => {
2694-
let mut types = impls.iter()
2695-
.map(|t| with_no_trimmed_paths!(format!(
2696-
" - {}\n",
2697-
tcx.type_of(*t).instantiate_identity(),
2698-
)))
2699-
.collect::<Vec<_>>();
2700-
let post = if types.len() > 9 {
2701-
let len = types.len();
2702-
types.truncate(8);
2703-
format!("and {} others", len - 8)
2704-
} else {
2705-
String::new()
2706-
};
2707-
err.help(format!(
2708-
"the following types implement the trait:\n{}{post}",
2709-
types.join(""),
2710-
));
2711-
}
2685+
if !impls.is_empty() {
2686+
let len = impls.len();
2687+
let mut types = impls.iter()
2688+
.map(|t| with_no_trimmed_paths!(format!(
2689+
" {}",
2690+
tcx.type_of(*t).instantiate_identity(),
2691+
)))
2692+
.collect::<Vec<_>>();
2693+
let post = if types.len() > 9 {
2694+
types.truncate(8);
2695+
format!("\nand {} others", len - 8)
2696+
} else {
2697+
String::new()
2698+
};
2699+
err.help(format!(
2700+
"the following type{} implement{} the trait:\n{}{post}",
2701+
pluralize!(len),
2702+
if len == 1 { "s" } else { "" },
2703+
types.join("\n"),
2704+
));
27122705
}
2713-
27142706
}
27152707
}
27162708
} else {

tests/ui/privacy/sealed-traits/sealed-trait-local.stderr

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ note: required by a bound in `a::Sealed`
1010
LL | pub trait Sealed: self::b::Hidden {
1111
| ^^^^^^^^^^^^^^^ required by this bound in `Sealed`
1212
= note: `Sealed` is a "sealed trait", because to implement it you also need to implement `a::b::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it
13-
= help: type `a::X` implements the trait
13+
= help: the following type implements the trait:
14+
a::X
1415

1516
error[E0277]: the trait bound `S: d::Hidden` is not satisfied
1617
--> $DIR/sealed-trait-local.rs:53:20
@@ -25,9 +26,8 @@ LL | pub trait Sealed: self::d::Hidden {
2526
| ^^^^^^^^^^^^^^^ required by this bound in `Sealed`
2627
= note: `Sealed` is a "sealed trait", because to implement it you also need to implement `c::d::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it
2728
= help: the following types implement the trait:
28-
- c::X
29-
- c::Y
30-
29+
c::X
30+
c::Y
3131

3232
error[E0277]: the trait bound `S: f::Hidden` is not satisfied
3333
--> $DIR/sealed-trait-local.rs:54:20
@@ -42,9 +42,8 @@ LL | pub trait Sealed: self::f::Hidden {
4242
| ^^^^^^^^^^^^^^^ required by this bound in `Sealed`
4343
= note: `Sealed` is a "sealed trait", because to implement it you also need to implement `e::f::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it
4444
= help: the following types implement the trait:
45-
- e::X
46-
- e::Y
47-
45+
e::X
46+
e::Y
4847

4948
error: aborting due to 3 previous errors
5049

0 commit comments

Comments
 (0)