resolve vars in node substs

This commit is contained in:
lcnr 2022-07-01 15:20:38 +02:00
parent eef34a648b
commit 7952d2ed83
3 changed files with 19 additions and 5 deletions

View File

@ -692,6 +692,11 @@ fn update_infer_source(&mut self, new_source: InferSource<'tcx>) {
}
}
fn node_substs_opt(&self, hir_id: HirId) -> Option<SubstsRef<'tcx>> {
let substs = self.typeck_results.node_substs_opt(hir_id);
self.infcx.resolve_vars_if_possible(substs)
}
fn opt_node_type(&self, hir_id: HirId) -> Option<Ty<'tcx>> {
let ty = self.typeck_results.node_type_opt(hir_id);
self.infcx.resolve_vars_if_possible(ty)
@ -774,7 +779,7 @@ fn expr_inferred_subst_iter(
let tcx = self.infcx.tcx;
match expr.kind {
hir::ExprKind::Path(ref path) => {
if let Some(substs) = self.typeck_results.node_substs_opt(expr.hir_id) {
if let Some(substs) = self.node_substs_opt(expr.hir_id) {
return self.path_inferred_subst_iter(expr.hir_id, substs, path);
}
}
@ -802,7 +807,7 @@ fn expr_inferred_subst_iter(
if generics.has_impl_trait() {
None?
}
let substs = self.typeck_results.node_substs_opt(expr.hir_id)?;
let substs = self.node_substs_opt(expr.hir_id)?;
let span = tcx.hir().span(segment.hir_id?);
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
InsertableGenericArgs {
@ -1074,7 +1079,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
.any(|generics| generics.has_impl_trait())
};
if let ExprKind::MethodCall(path, args, span) = expr.kind
&& let Some(substs) = self.typeck_results.node_substs_opt(expr.hir_id)
&& let Some(substs) = self.node_substs_opt(expr.hir_id)
&& substs.iter().any(|arg| self.generic_arg_contains_target(arg))
&& let Some(def_id) = self.typeck_results.type_dependent_def_id(expr.hir_id)
&& self.infcx.tcx.trait_of_item(def_id).is_some()

View File

@ -2,7 +2,12 @@ error[E0282]: type annotations needed
--> $DIR/ambiguous_type_parameter.rs:16:19
|
LL | InMemoryStore.get_raw(&String::default());
| ^^^^^^^ cannot infer type for type parameter `K`
| ^^^^^^^
|
help: try using a fully qualified path to specify the expected types
|
LL | <InMemoryStore as Store<String, HashMap<K, String>>>::get_raw(&InMemoryStore, &String::default());
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ~
error: aborting due to previous error

View File

@ -13,7 +13,7 @@ error[E0283]: type annotations needed
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:26:7
|
LL | x.foo();
| ^^^ cannot infer type for struct `Vec<_>`
| ^^^
|
note: multiple `impl`s satisfying `Vec<_>: Foo` found
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:9:1
@ -23,6 +23,10 @@ LL | impl Foo for Vec<usize> {
...
LL | impl Foo for Vec<isize> {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: try using a fully qualified path to specify the expected types
|
LL | <Vec<T> as Foo>::foo(&x);
| ++++++++++++++++++++++ ~
error[E0308]: mismatched types
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:33:20