review comments
This commit is contained in:
parent
2c998aa8bb
commit
794b644f0b
3 changed files with 87 additions and 93 deletions
|
@ -17,6 +17,7 @@
|
|||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(or_patterns)]
|
||||
#![feature(str_strip)]
|
||||
#![feature(option_zip)]
|
||||
#![recursion_limit = "512"] // For rustdoc
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -388,7 +388,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
// which is somewhat confusing.
|
||||
self.suggest_restricting_param_bound(
|
||||
&mut err,
|
||||
&trait_ref,
|
||||
trait_ref,
|
||||
obligation.cause.body_id,
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
fn suggest_restricting_param_bound(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::PolyTraitRef<'_>,
|
||||
trait_ref: ty::PolyTraitRef<'_>,
|
||||
body_id: hir::HirId,
|
||||
);
|
||||
|
||||
|
@ -168,28 +168,24 @@ fn suggest_restriction(
|
|||
err: &mut DiagnosticBuilder<'_>,
|
||||
fn_sig: Option<&hir::FnSig<'_>>,
|
||||
projection: Option<&ty::ProjectionTy<'_>>,
|
||||
trait_ref: &ty::PolyTraitRef<'_>,
|
||||
trait_ref: ty::PolyTraitRef<'_>,
|
||||
) {
|
||||
let span = generics.where_clause.span_for_predicates_or_empty_place();
|
||||
if !span.from_expansion() && span.desugaring_kind().is_none() {
|
||||
if span.from_expansion() || span.desugaring_kind().is_some() {
|
||||
return;
|
||||
}
|
||||
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...
|
||||
if let Some((name, fn_sig)) = fn_sig.and_then(|sig| {
|
||||
projection.and_then(|p| {
|
||||
if let Some((name, fn_sig)) =
|
||||
fn_sig.zip(projection).and_then(|(sig, p)| match p.self_ty().kind {
|
||||
// Shenanigans to get the `Trait` from the `impl Trait`.
|
||||
match p.self_ty().kind {
|
||||
ty::Param(param) => {
|
||||
// `fn foo(t: impl Trait)`
|
||||
// ^^^^^ get this string
|
||||
param
|
||||
.name
|
||||
.as_str()
|
||||
.strip_prefix("impl")
|
||||
.map(|s| (s.trim_start().to_string(), sig))
|
||||
param.name.as_str().strip_prefix("impl").map(|s| (s.trim_start().to_string(), sig))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
}) {
|
||||
{
|
||||
// We know we have an `impl Trait` that doesn't satisfy a required projection.
|
||||
|
||||
// Find all of the ocurrences of `impl Trait` for `Trait` in the function arguments'
|
||||
|
@ -258,21 +254,18 @@ fn suggest_restriction(
|
|||
);
|
||||
} else {
|
||||
// Trivial case: `T` needs an extra bound: `T: Bound`.
|
||||
let (sp, s) = predicate_constraint(
|
||||
generics,
|
||||
trait_ref.without_const().to_predicate().to_string(),
|
||||
);
|
||||
let (sp, s) =
|
||||
predicate_constraint(generics, trait_ref.without_const().to_predicate().to_string());
|
||||
let appl = Applicability::MachineApplicable;
|
||||
err.span_suggestion(sp, &format!("consider further restricting {}", msg), s, appl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
fn suggest_restricting_param_bound(
|
||||
&self,
|
||||
mut err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::PolyTraitRef<'_>,
|
||||
trait_ref: ty::PolyTraitRef<'_>,
|
||||
body_id: hir::HirId,
|
||||
) {
|
||||
let self_ty = trait_ref.self_ty();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue