Skip to content

Commit f34365d

Browse files
authored
Rollup merge of #113651 - lcnr:parent-def-id, r=compiler-errors
self type param infer, avoid ICE fixes #113610, which is caused by https://github.com/rust-lang/rust/blob/33a2c2487ac5d9927830ea4c1844335c6b9f77db/compiler/rustc_hir_analysis/src/collect/generics_of.rs#L190-L205
2 parents 6d6bf6c + cf78716 commit f34365d

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::FnCtxt;
22
use rustc_hir as hir;
33
use rustc_hir::def::Res;
44
use rustc_hir::def_id::DefId;
5-
use rustc_infer::traits::ObligationCauseCode;
5+
use rustc_infer::{infer::type_variable::TypeVariableOriginKind, traits::ObligationCauseCode};
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
77
use rustc_span::{self, symbol::kw, Span};
88
use rustc_trait_selection::traits;
@@ -254,8 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254
type BreakTy = ty::GenericArg<'tcx>;
255255
fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
256256
if let Some(origin) = self.0.type_var_origin(ty)
257-
&& let rustc_infer::infer::type_variable::TypeVariableOriginKind::TypeParameterDefinition(_, def_id) =
258-
origin.kind
257+
&& let TypeVariableOriginKind::TypeParameterDefinition(_, def_id) = origin.kind
259258
&& let generics = self.0.tcx.generics_of(self.1)
260259
&& let Some(index) = generics.param_def_id_to_index(self.0.tcx, def_id)
261260
&& let Some(subst) = ty::InternalSubsts::identity_for_item(self.0.tcx, self.1)

Diff for: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
163163
let ty_vars = infcx_inner.type_variables();
164164
let var_origin = ty_vars.var_origin(ty_vid);
165165
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind
166-
&& !var_origin.span.from_expansion()
166+
&& name != kw::SelfUpper && !var_origin.span.from_expansion()
167167
{
168168
let generics = infcx.tcx.generics_of(infcx.tcx.parent(def_id));
169169
let idx = generics.param_def_id_to_index(infcx.tcx, def_id).unwrap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for #113610 where we ICEd when trying to print
2+
// inference variables created by instantiating the self type parameter.
3+
4+
fn main() {
5+
let _ = (Default::default(),);
6+
//~^ ERROR cannot call associated function on trait
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
2+
--> $DIR/infer-var-for-self-param.rs:5:14
3+
|
4+
LL | let _ = (Default::default(),);
5+
| ^^^^^^^^^^^^^^^^ cannot call associated function of trait
6+
|
7+
help: use a fully-qualified path to a specific available implementation (271 found)
8+
|
9+
LL | let _ = (</* self type */ as Default>::default(),);
10+
| +++++++++++++++++++ +
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0790`.

0 commit comments

Comments
 (0)