Rollup merge of #38150 - estebank:fix-23286, r=nikomatsakis
Point out the known type when field doesn't satisfy bound
For file
```rust
use std::path::Path;
fn f(p: Path) { }
```
provide the following error
```nocode
error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied in `std::path::Path`
--> file.rs:3:6
|
3 | fn f(p: Path) { }
| ^ within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`
|
= note: `[u8]` does not have a constant size known at compile-time
= note: required because it appears within the type `std::path::Path`
= note: all local variables must have a statically known size
```
Fix #23286.
This commit is contained in:
commit
2fb2d307e0
3 changed files with 81 additions and 8 deletions
|
|
@ -458,11 +458,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
err
|
||||
}
|
||||
|
||||
|
||||
/// Get the parent trait chain start
|
||||
fn get_parent_trait_ref(&self, code: &ObligationCauseCode<'tcx>) -> Option<String> {
|
||||
match code {
|
||||
&ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
|
||||
let parent_trait_ref = self.resolve_type_vars_if_possible(
|
||||
&data.parent_trait_ref);
|
||||
match self.get_parent_trait_ref(&data.parent_code) {
|
||||
Some(t) => Some(t),
|
||||
None => Some(format!("{}", parent_trait_ref.0.self_ty())),
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report_selection_error(&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
error: &SelectionError<'tcx>)
|
||||
{
|
||||
let span = obligation.cause.span;
|
||||
|
||||
let mut err = match *error {
|
||||
SelectionError::Unimplemented => {
|
||||
if let ObligationCauseCode::CompareImplMethodObligation {
|
||||
|
|
@ -487,14 +504,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
return;
|
||||
} else {
|
||||
let trait_ref = trait_predicate.to_poly_trait_ref();
|
||||
|
||||
let mut err = struct_span_err!(self.tcx.sess, span, E0277,
|
||||
"the trait bound `{}` is not satisfied",
|
||||
trait_ref.to_predicate());
|
||||
err.span_label(span, &format!("the trait `{}` is not implemented \
|
||||
for `{}`",
|
||||
trait_ref,
|
||||
trait_ref.self_ty()));
|
||||
let (post_message, pre_message) = match self.get_parent_trait_ref(
|
||||
&obligation.cause.code)
|
||||
{
|
||||
Some(t) => {
|
||||
(format!(" in `{}`", t), format!("within `{}`, ", t))
|
||||
}
|
||||
None => (String::new(), String::new()),
|
||||
};
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
span,
|
||||
E0277,
|
||||
"the trait bound `{}` is not satisfied{}",
|
||||
trait_ref.to_predicate(),
|
||||
post_message);
|
||||
err.span_label(span,
|
||||
&format!("{}the trait `{}` is not \
|
||||
implemented for `{}`",
|
||||
pre_message,
|
||||
trait_ref,
|
||||
trait_ref.self_ty()));
|
||||
|
||||
// Try to report a help message
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue