Skip to content

Commit

Permalink
following suggestion from @fmease, E0191 and dynless-turbofish have s…
Browse files Browse the repository at this point in the history
…ame Node variant. Pushing print debugging for visibility.
  • Loading branch information
Ashton Hunt committed Jul 3, 2024
1 parent f8911e3 commit e049e7c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use rustc_errors::MultiSpan;
use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed,
};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, Node};
use rustc_middle::bug;
use rustc_middle::query::Key;
use rustc_middle::ty::print::{PrintPolyTraitRefExt as _, PrintTraitRefExt as _};
Expand Down Expand Up @@ -745,7 +745,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
if object_safety_violations {
return;
}

// related to issue #91997, turbofishes added only when in an expr or pat
let mut in_expr_or_pat = false;
if let ([], [bound]) = (&potential_assoc_types[..], &trait_bounds) {
in_expr_or_pat = match tcx.parent_hir_node(bound.trait_ref.hir_ref_id) {
Node::Expr(_) | Node::Pat(_) => true,
_ => false,
};
println!(
"(!!!!!!) parent node: {:#?}",
tcx.parent_hir_node(bound.trait_ref.hir_ref_id)
);
match bound.trait_ref.path.segments {
// FIXME: `trait_ref.path.span` can point to a full path with multiple
// segments, even though `trait_ref.path.segments` is of length `1`. Work
Expand Down Expand Up @@ -901,10 +912,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// `Trait<'a, Item = Type>` while accounting for the `<'a>` in the
// suggestion.
format!("{}, {}>", &snippet[..snippet.len() - 1], types.join(", "))
} else {
} else if in_expr_or_pat {
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
// least we can clue them to the correct syntax `Iterator::<Item = Type>`.
format!("{}::<{}>", snippet, types.join(", "))
} else {
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
// least we can clue them to the correct syntax `Iterator<Item = Type>`.
format!("{}<{}>", snippet, types.join(", "))
};
suggestions.push((*span, code));
} else if dupes {
Expand Down

0 comments on commit e049e7c

Please sign in to comment.