Auto merge of #76028 - aticu:improve_e0118, r=estebank,jyn514,GuillaumeGomez
Improve E0118 - Changes the "base type" terminology to "nominal type" (according to the [reference](https://doc.rust-lang.org/stable/reference/items/implementations.html#inherent-implementations)). - Suggests removing a reference, if one is present on the type. - Clarify what is meant by a "nominal type". closes #69392 This is my first not-entirely-trivial PR, so please let me know if I missed anything or if something could be improved. Though I probably won't be able to fix anything in the upcoming week.
This commit is contained in:
commit
95386b656e
7 changed files with 71 additions and 21 deletions
|
@ -308,18 +308,25 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Error(_) => {}
|
||||
_ => {
|
||||
struct_span_err!(
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
ty.span,
|
||||
E0118,
|
||||
"no base type found for inherent implementation"
|
||||
)
|
||||
.span_label(ty.span, "impl requires a base type")
|
||||
.note(
|
||||
"either implement a trait on it or create a newtype \
|
||||
to wrap it instead",
|
||||
)
|
||||
.emit();
|
||||
"no nominal type found for inherent implementation"
|
||||
);
|
||||
|
||||
err.span_label(ty.span, "impl requires a nominal type")
|
||||
.note("either implement a trait on it or create a newtype to wrap it instead");
|
||||
|
||||
if let ty::Ref(_, subty, _) = self_ty.kind() {
|
||||
err.note(&format!(
|
||||
"you could also try moving the reference to \
|
||||
uses of `{}` (such as `self`) within the implementation",
|
||||
subty
|
||||
));
|
||||
}
|
||||
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue