Skip to content

Commit 7952d2e

Browse files
committed
resolve vars in node substs
1 parent eef34a6 commit 7952d2e

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
692692
}
693693
}
694694

695+
fn node_substs_opt(&self, hir_id: HirId) -> Option<SubstsRef<'tcx>> {
696+
let substs = self.typeck_results.node_substs_opt(hir_id);
697+
self.infcx.resolve_vars_if_possible(substs)
698+
}
699+
695700
fn opt_node_type(&self, hir_id: HirId) -> Option<Ty<'tcx>> {
696701
let ty = self.typeck_results.node_type_opt(hir_id);
697702
self.infcx.resolve_vars_if_possible(ty)
@@ -774,7 +779,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
774779
let tcx = self.infcx.tcx;
775780
match expr.kind {
776781
hir::ExprKind::Path(ref path) => {
777-
if let Some(substs) = self.typeck_results.node_substs_opt(expr.hir_id) {
782+
if let Some(substs) = self.node_substs_opt(expr.hir_id) {
778783
return self.path_inferred_subst_iter(expr.hir_id, substs, path);
779784
}
780785
}
@@ -802,7 +807,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
802807
if generics.has_impl_trait() {
803808
None?
804809
}
805-
let substs = self.typeck_results.node_substs_opt(expr.hir_id)?;
810+
let substs = self.node_substs_opt(expr.hir_id)?;
806811
let span = tcx.hir().span(segment.hir_id?);
807812
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
808813
InsertableGenericArgs {
@@ -1074,7 +1079,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
10741079
.any(|generics| generics.has_impl_trait())
10751080
};
10761081
if let ExprKind::MethodCall(path, args, span) = expr.kind
1077-
&& let Some(substs) = self.typeck_results.node_substs_opt(expr.hir_id)
1082+
&& let Some(substs) = self.node_substs_opt(expr.hir_id)
10781083
&& substs.iter().any(|arg| self.generic_arg_contains_target(arg))
10791084
&& let Some(def_id) = self.typeck_results.type_dependent_def_id(expr.hir_id)
10801085
&& self.infcx.tcx.trait_of_item(def_id).is_some()

src/test/ui/inference/ambiguous_type_parameter.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ error[E0282]: type annotations needed
22
--> $DIR/ambiguous_type_parameter.rs:16:19
33
|
44
LL | InMemoryStore.get_raw(&String::default());
5-
| ^^^^^^^ cannot infer type for type parameter `K`
5+
| ^^^^^^^
6+
|
7+
help: try using a fully qualified path to specify the expected types
8+
|
9+
LL | <InMemoryStore as Store<String, HashMap<K, String>>>::get_raw(&InMemoryStore, &String::default());
10+
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ~
611

712
error: aborting due to previous error
813

src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ error[E0283]: type annotations needed
1313
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:26:7
1414
|
1515
LL | x.foo();
16-
| ^^^ cannot infer type for struct `Vec<_>`
16+
| ^^^
1717
|
1818
note: multiple `impl`s satisfying `Vec<_>: Foo` found
1919
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:9:1
@@ -23,6 +23,10 @@ LL | impl Foo for Vec<usize> {
2323
...
2424
LL | impl Foo for Vec<isize> {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^
26+
help: try using a fully qualified path to specify the expected types
27+
|
28+
LL | <Vec<T> as Foo>::foo(&x);
29+
| ++++++++++++++++++++++ ~
2630

2731
error[E0308]: mismatched types
2832
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:33:20

0 commit comments

Comments
 (0)