Rollup merge of #99580 - fmease:fix-issue-99565, r=estebank
Don't suggest unnameable generic arguments Fixes #99565. `@rustbot` label T-compiler A-diagnostics r? `@rust-lang/wg-diagnostics`
This commit is contained in:
commit
b6d6f100a1
12 changed files with 90 additions and 22 deletions
|
@ -3,7 +3,7 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use crate::ty::{
|
||||
visit::TypeVisitable, Const, ConstKind, DefIdTree, ExistentialPredicate, InferTy,
|
||||
visit::TypeVisitable, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst, InferTy,
|
||||
PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
|
||||
};
|
||||
|
||||
|
@ -82,15 +82,18 @@ pub trait IsSuggestable<'tcx> {
|
|||
/// meaningful rendered suggestions when pretty-printed. We leave some
|
||||
/// nonsense, such as region vars, since those render as `'_` and are
|
||||
/// usually okay to reinterpret as elided lifetimes.
|
||||
fn is_suggestable(self, tcx: TyCtxt<'tcx>) -> bool;
|
||||
///
|
||||
/// Only if `infer_suggestable` is true, we consider type and const
|
||||
/// inference variables to be suggestable.
|
||||
fn is_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> bool;
|
||||
}
|
||||
|
||||
impl<'tcx, T> IsSuggestable<'tcx> for T
|
||||
where
|
||||
T: TypeVisitable<'tcx>,
|
||||
{
|
||||
fn is_suggestable(self, tcx: TyCtxt<'tcx>) -> bool {
|
||||
self.visit_with(&mut IsSuggestableVisitor { tcx }).is_continue()
|
||||
fn is_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> bool {
|
||||
self.visit_with(&mut IsSuggestableVisitor { tcx, infer_suggestable }).is_continue()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +103,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
|
|||
err: &mut Diagnostic,
|
||||
trait_pred: PolyTraitPredicate<'tcx>,
|
||||
) -> bool {
|
||||
if !trait_pred.is_suggestable(tcx) {
|
||||
if !trait_pred.is_suggestable(tcx, false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -419,6 +422,7 @@ impl<'v> hir::intravisit::Visitor<'v> for StaticLifetimeVisitor<'v> {
|
|||
|
||||
pub struct IsSuggestableVisitor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
infer_suggestable: bool,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
|
||||
|
@ -426,6 +430,8 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
|
|||
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match t.kind() {
|
||||
Infer(InferTy::TyVar(_)) if self.infer_suggestable => {}
|
||||
|
||||
FnDef(..)
|
||||
| Closure(..)
|
||||
| Infer(..)
|
||||
|
@ -479,6 +485,8 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
|
|||
|
||||
fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match c.kind() {
|
||||
ConstKind::Infer(InferConst::Var(_)) if self.infer_suggestable => {}
|
||||
|
||||
ConstKind::Infer(..)
|
||||
| ConstKind::Bound(..)
|
||||
| ConstKind::Placeholder(..)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue