Rollup merge of #106754 - compiler-errors:ty-infer-method-is-confusing, r=lcnr
Rename `Ty::is_ty_infer` -> `Ty::is_ty_or_numeric_infer` Makes sure people are aware that they may have a type variable *or* an int/float variable. r? `@oli-obk` https://github.com/rust-lang/rust/pull/106322#issuecomment-1376913539 but I could instead implement your solution, let me know. (This will conflict with #106322 for now, ignore that 😄)
This commit is contained in:
commit
d4ad96cf6e
5 changed files with 14 additions and 11 deletions
|
@ -1782,9 +1782,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
// like when you have two references but one is `usize` and the other
|
// like when you have two references but one is `usize` and the other
|
||||||
// is `f32`. In those cases we still want to show the `note`. If the
|
// is `f32`. In those cases we still want to show the `note`. If the
|
||||||
// value from `ef` is `Infer(_)`, then we ignore it.
|
// value from `ef` is `Infer(_)`, then we ignore it.
|
||||||
if !ef.expected.is_ty_infer() {
|
if !ef.expected.is_ty_or_numeric_infer() {
|
||||||
ef.expected != values.expected
|
ef.expected != values.expected
|
||||||
} else if !ef.found.is_ty_infer() {
|
} else if !ef.found.is_ty_or_numeric_infer() {
|
||||||
ef.found != values.found
|
ef.found != values.found
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl InferenceDiagnosticsData {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn where_x_is_kind(&self, in_type: Ty<'_>) -> &'static str {
|
fn where_x_is_kind(&self, in_type: Ty<'_>) -> &'static str {
|
||||||
if in_type.is_ty_infer() {
|
if in_type.is_ty_or_numeric_infer() {
|
||||||
""
|
""
|
||||||
} else if self.name == "_" {
|
} else if self.name == "_" {
|
||||||
// FIXME: Consider specializing this message if there is a single `_`
|
// FIXME: Consider specializing this message if there is a single `_`
|
||||||
|
@ -195,12 +195,12 @@ fn ty_to_string<'tcx>(
|
||||||
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
|
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
|
||||||
(ty::FnDef(..), _) => ty.fn_sig(infcx.tcx).print(printer).unwrap().into_buffer(),
|
(ty::FnDef(..), _) => ty.fn_sig(infcx.tcx).print(printer).unwrap().into_buffer(),
|
||||||
(_, Some(def_id))
|
(_, Some(def_id))
|
||||||
if ty.is_ty_infer()
|
if ty.is_ty_or_numeric_infer()
|
||||||
&& infcx.tcx.get_diagnostic_item(sym::iterator_collect_fn) == Some(def_id) =>
|
&& infcx.tcx.get_diagnostic_item(sym::iterator_collect_fn) == Some(def_id) =>
|
||||||
{
|
{
|
||||||
"Vec<_>".to_string()
|
"Vec<_>".to_string()
|
||||||
}
|
}
|
||||||
_ if ty.is_ty_infer() => "/* Type */".to_string(),
|
_ if ty.is_ty_or_numeric_infer() => "/* Type */".to_string(),
|
||||||
// FIXME: The same thing for closures, but this only works when the closure
|
// FIXME: The same thing for closures, but this only works when the closure
|
||||||
// does not capture anything.
|
// does not capture anything.
|
||||||
//
|
//
|
||||||
|
@ -680,7 +680,7 @@ impl<'tcx> InferSourceKind<'tcx> {
|
||||||
| InferSourceKind::ClosureReturn { ty, .. } => {
|
| InferSourceKind::ClosureReturn { ty, .. } => {
|
||||||
if ty.is_closure() {
|
if ty.is_closure() {
|
||||||
("closure", closure_as_fn_str(infcx, ty))
|
("closure", closure_as_fn_str(infcx, ty))
|
||||||
} else if !ty.is_ty_infer() {
|
} else if !ty.is_ty_or_numeric_infer() {
|
||||||
("normal", ty_to_string(infcx, ty, None))
|
("normal", ty_to_string(infcx, ty, None))
|
||||||
} else {
|
} else {
|
||||||
("other", String::new())
|
("other", String::new())
|
||||||
|
@ -813,7 +813,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
|
||||||
self.attempt += 1;
|
self.attempt += 1;
|
||||||
if let Some(InferSource { kind: InferSourceKind::GenericArg { def_id: did, ..}, .. }) = self.infer_source
|
if let Some(InferSource { kind: InferSourceKind::GenericArg { def_id: did, ..}, .. }) = self.infer_source
|
||||||
&& let InferSourceKind::LetBinding { ref ty, ref mut def_id, ..} = new_source.kind
|
&& let InferSourceKind::LetBinding { ref ty, ref mut def_id, ..} = new_source.kind
|
||||||
&& ty.is_ty_infer()
|
&& ty.is_ty_or_numeric_infer()
|
||||||
{
|
{
|
||||||
// Customize the output so we talk about `let x: Vec<_> = iter.collect();` instead of
|
// Customize the output so we talk about `let x: Vec<_> = iter.collect();` instead of
|
||||||
// `let x: _ = iter.collect();`, as this is a very common case.
|
// `let x: _ = iter.collect();`, as this is a very common case.
|
||||||
|
|
|
@ -1686,7 +1686,7 @@ impl<'tcx> Ty<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ty_infer(self) -> bool {
|
pub fn is_ty_or_numeric_infer(self) -> bool {
|
||||||
matches!(self.kind(), Infer(_))
|
matches!(self.kind(), Infer(_))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ impl<'tcx> GenericArg<'tcx> {
|
||||||
pub fn is_non_region_infer(self) -> bool {
|
pub fn is_non_region_infer(self) -> bool {
|
||||||
match self.unpack() {
|
match self.unpack() {
|
||||||
GenericArgKind::Lifetime(_) => false,
|
GenericArgKind::Lifetime(_) => false,
|
||||||
GenericArgKind::Type(ty) => ty.is_ty_infer(),
|
GenericArgKind::Type(ty) => ty.is_ty_or_numeric_infer(),
|
||||||
GenericArgKind::Const(ct) => ct.is_ct_infer(),
|
GenericArgKind::Const(ct) => ct.is_ct_infer(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2252,8 +2252,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
let ambiguities =
|
let ambiguities =
|
||||||
ambiguity::recompute_applicable_impls(self.infcx, &obligation);
|
ambiguity::recompute_applicable_impls(self.infcx, &obligation);
|
||||||
let has_non_region_infer =
|
let has_non_region_infer = trait_ref
|
||||||
trait_ref.skip_binder().substs.types().any(|t| !t.is_ty_infer());
|
.skip_binder()
|
||||||
|
.substs
|
||||||
|
.types()
|
||||||
|
.any(|t| !t.is_ty_or_numeric_infer());
|
||||||
// It doesn't make sense to talk about applicable impls if there are more
|
// It doesn't make sense to talk about applicable impls if there are more
|
||||||
// than a handful of them.
|
// than a handful of them.
|
||||||
if ambiguities.len() > 1 && ambiguities.len() < 10 && has_non_region_infer {
|
if ambiguities.len() > 1 && ambiguities.len() < 10 && has_non_region_infer {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue