Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 26, 2023
1 parent db3b02f commit f93aa75
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2682,35 +2682,27 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.flatten()
.chain(impls_of.blanket_impls().iter())
.collect::<Vec<_>>();
match &impls[..] {
[] => {}
[only] => {
err.help(with_no_trimmed_paths!(format!(
"type `{}` implements the trait",
tcx.type_of(*only).instantiate_identity(),
)));
}
impls => {
let mut types = impls.iter()
.map(|t| with_no_trimmed_paths!(format!(
" - {}\n",
tcx.type_of(*t).instantiate_identity(),
)))
.collect::<Vec<_>>();
let post = if types.len() > 9 {
let len = types.len();
types.truncate(8);
format!("and {} others", len - 8)
} else {
String::new()
};
err.help(format!(
"the following types implement the trait:\n{}{post}",
types.join(""),
));
}
if !impls.is_empty() {
let len = impls.len();
let mut types = impls.iter()
.map(|t| with_no_trimmed_paths!(format!(
" {}",
tcx.type_of(*t).instantiate_identity(),
)))
.collect::<Vec<_>>();
let post = if types.len() > 9 {
types.truncate(8);
format!("\nand {} others", len - 8)
} else {
String::new()
};
err.help(format!(
"the following type{} implement{} the trait:\n{}{post}",
pluralize!(len),
if len == 1 { "s" } else { "" },
types.join("\n"),
));
}

}
}
} else {
Expand Down
13 changes: 6 additions & 7 deletions tests/ui/privacy/sealed-traits/sealed-trait-local.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ note: required by a bound in `a::Sealed`
LL | pub trait Sealed: self::b::Hidden {
| ^^^^^^^^^^^^^^^ required by this bound in `Sealed`
= 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
= help: type `a::X` implements the trait
= help: the following type implements the trait:
a::X

error[E0277]: the trait bound `S: d::Hidden` is not satisfied
--> $DIR/sealed-trait-local.rs:53:20
Expand All @@ -25,9 +26,8 @@ LL | pub trait Sealed: self::d::Hidden {
| ^^^^^^^^^^^^^^^ required by this bound in `Sealed`
= 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
= help: the following types implement the trait:
- c::X
- c::Y

c::X
c::Y

error[E0277]: the trait bound `S: f::Hidden` is not satisfied
--> $DIR/sealed-trait-local.rs:54:20
Expand All @@ -42,9 +42,8 @@ LL | pub trait Sealed: self::f::Hidden {
| ^^^^^^^^^^^^^^^ required by this bound in `Sealed`
= 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
= help: the following types implement the trait:
- e::X
- e::Y

e::X
e::Y

error: aborting due to 3 previous errors

Expand Down

0 comments on commit f93aa75

Please sign in to comment.