-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Preserve substitutions when making trait obligations for suggestions #71618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
730c6f3
8ea828b
4d9e9c6
d2bacb1
7278e29
f99519b
1fad3b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -532,14 +532,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
}; | ||
let msg = format!("use parentheses to call the {}", callable); | ||
|
||
let obligation = self.mk_obligation_for_def_id( | ||
trait_ref.def_id(), | ||
output_ty.skip_binder(), | ||
obligation.cause.clone(), | ||
obligation.param_env, | ||
); | ||
// `mk_trait_obligation_with_new_self_ty` only works for types with no escaping bound | ||
// variables, so bail out if we have any. | ||
let output_ty = match output_ty.no_bound_vars() { | ||
Some(ty) => ty, | ||
None => return, | ||
}; | ||
|
||
let new_obligation = | ||
self.mk_trait_obligation_with_new_self_ty(obligation.param_env, trait_ref, output_ty); | ||
|
||
match self.evaluate_obligation(&obligation) { | ||
match self.evaluate_obligation(&new_obligation) { | ||
Ok( | ||
EvaluationResult::EvaluatedToOk | ||
| EvaluationResult::EvaluatedToOkModuloRegions | ||
|
@@ -694,7 +697,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
err: &mut DiagnosticBuilder<'_>, | ||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, | ||
) { | ||
let trait_ref = trait_ref.skip_binder(); | ||
let span = obligation.cause.span; | ||
|
||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { | ||
|
@@ -705,17 +707,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
return; | ||
} | ||
|
||
let mut trait_type = trait_ref.self_ty(); | ||
let mut suggested_ty = trait_ref.self_ty(); | ||
|
||
|
||
for refs_remaining in 0..refs_number { | ||
if let ty::Ref(_, t_type, _) = trait_type.kind { | ||
trait_type = t_type; | ||
if let ty::Ref(_, inner_ty, _) = suggested_ty.kind { | ||
|
||
suggested_ty = inner_ty; | ||
|
||
let new_obligation = self.mk_obligation_for_def_id( | ||
trait_ref.def_id, | ||
trait_type, | ||
ObligationCause::dummy(), | ||
let new_obligation = self.mk_trait_obligation_with_new_self_ty( | ||
obligation.param_env, | ||
trait_ref, | ||
suggested_ty, | ||
|
||
); | ||
|
||
if self.predicate_may_hold(&new_obligation) { | ||
|
@@ -782,20 +783,20 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
return; | ||
} | ||
|
||
let trait_type = match mutability { | ||
let suggested_ty = match mutability { | ||
hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type), | ||
hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type), | ||
}; | ||
|
||
let new_obligation = self.mk_obligation_for_def_id( | ||
trait_ref.skip_binder().def_id, | ||
trait_type, | ||
ObligationCause::dummy(), | ||
let new_obligation = self.mk_trait_obligation_with_new_self_ty( | ||
obligation.param_env, | ||
&trait_ref, | ||
suggested_ty, | ||
|
||
); | ||
|
||
if self.evaluate_obligation_no_overflow(&new_obligation).must_apply_modulo_regions() | ||
{ | ||
let suggested_ty_would_satisfy_obligation = self | ||
.evaluate_obligation_no_overflow(&new_obligation) | ||
.must_apply_modulo_regions(); | ||
if suggested_ty_would_satisfy_obligation { | ||
let sp = self | ||
.tcx | ||
.sess | ||
|
@@ -812,7 +813,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
err.note(&format!( | ||
"`{}` is implemented for `{:?}`, but not for `{:?}`", | ||
trait_ref.print_only_trait_path(), | ||
trait_type, | ||
suggested_ty, | ||
trait_ref.skip_binder().self_ty(), | ||
)); | ||
} | ||
|
@@ -1891,7 +1892,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
span: Span, | ||
) { | ||
debug!( | ||
"suggest_await_befor_try: obligation={:?}, span={:?}, trait_ref={:?}, trait_ref_self_ty={:?}", | ||
"suggest_await_before_try: obligation={:?}, span={:?}, trait_ref={:?}, trait_ref_self_ty={:?}", | ||
obligation, | ||
span, | ||
trait_ref, | ||
|
@@ -1946,16 +1947,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
); | ||
|
||
debug!( | ||
"suggest_await_befor_try: normalized_projection_type {:?}", | ||
"suggest_await_before_try: normalized_projection_type {:?}", | ||
self.resolve_vars_if_possible(&normalized_ty) | ||
); | ||
let try_obligation = self.mk_obligation_for_def_id( | ||
trait_ref.def_id(), | ||
normalized_ty, | ||
obligation.cause.clone(), | ||
let try_obligation = self.mk_trait_obligation_with_new_self_ty( | ||
obligation.param_env, | ||
trait_ref, | ||
normalized_ty, | ||
); | ||
debug!("suggest_await_befor_try: try_trait_obligation {:?}", try_obligation); | ||
debug!("suggest_await_before_try: try_trait_obligation {:?}", try_obligation); | ||
if self.predicate_may_hold(&try_obligation) && impls_future { | ||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { | ||
if snippet.ends_with('?') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
let data: &[u8] = &[0; 10]; | ||
let _: &[i8] = data.into(); | ||
//~^ ERROR the trait bound `&[i8]: std::convert::From<&[u8]>` is not satisfied | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0277]: the trait bound `&[i8]: std::convert::From<&[u8]>` is not satisfied | ||
--> $DIR/issue-71394-no-from-impl.rs:3:25 | ||
| | ||
LL | let _: &[i8] = data.into(); | ||
| ^^^^ the trait `std::convert::From<&[u8]>` is not implemented for `&[i8]` | ||
| | ||
= note: required because of the requirements on the impl of `std::convert::Into<&[i8]>` for `&[u8]` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should comment this function and clarify that
new_self_ty
cannot have escaping bound variables