1
Fork 0

Rollup merge of #122799 - estebank:issue-122569, r=fee1-dead

Replace closures with `_` when suggesting fully qualified path for method call

```
error[E0283]: type annotations needed
  --> $DIR/into-inference-needs-type.rs:12:10
   |
LL |         .into()?;
   |          ^^^^
   |
   = note: cannot satisfy `_: From<...>`
   = note: required for `FilterMap<...>` to implement `Into<_>`
help: try using a fully qualified path to specify the expected types
   |
LL ~     let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec
LL |         .iter()
LL |         .map(|s| s.strip_prefix("t"))
LL ~         .filter_map(Option::Some))?;
   |
```

Fix #122569.
This commit is contained in:
Matthias Krüger 2024-03-21 12:05:08 +01:00 committed by GitHub
commit 300d3fb2fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 118 additions and 53 deletions

View file

@ -91,7 +91,12 @@ pub trait IsSuggestable<'tcx>: Sized {
/// inference variables to be suggestable.
fn is_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> bool;
fn make_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> Option<Self>;
fn make_suggestable(
self,
tcx: TyCtxt<'tcx>,
infer_suggestable: bool,
placeholder: Option<Ty<'tcx>>,
) -> Option<Self>;
}
impl<'tcx, T> IsSuggestable<'tcx> for T
@ -103,8 +108,13 @@ where
self.visit_with(&mut IsSuggestableVisitor { tcx, infer_suggestable }).is_continue()
}
fn make_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> Option<T> {
self.try_fold_with(&mut MakeSuggestableFolder { tcx, infer_suggestable }).ok()
fn make_suggestable(
self,
tcx: TyCtxt<'tcx>,
infer_suggestable: bool,
placeholder: Option<Ty<'tcx>>,
) -> Option<T> {
self.try_fold_with(&mut MakeSuggestableFolder { tcx, infer_suggestable, placeholder }).ok()
}
}
@ -559,6 +569,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
pub struct MakeSuggestableFolder<'tcx> {
tcx: TyCtxt<'tcx>,
infer_suggestable: bool,
placeholder: Option<Ty<'tcx>>,
}
impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
@ -572,19 +583,24 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
let t = match *t.kind() {
Infer(InferTy::TyVar(_)) if self.infer_suggestable => t,
FnDef(def_id, args) => {
FnDef(def_id, args) if self.placeholder.is_none() => {
Ty::new_fn_ptr(self.tcx, self.tcx.fn_sig(def_id).instantiate(self.tcx, args))
}
// FIXME(compiler-errors): We could replace these with infer, I guess.
Closure(..)
| FnDef(..)
| Infer(..)
| Coroutine(..)
| CoroutineWitness(..)
| Bound(_, _)
| Placeholder(_)
| Error(_) => {
return Err(());
if let Some(placeholder) = self.placeholder {
// We replace these with infer (which is passed in from an infcx).
placeholder
} else {
return Err(());
}
}
Alias(Opaque, AliasTy { def_id, .. }) => {