Skip to content

Commit

Permalink
Account for Self params properly
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 29, 2024
1 parent 48be671 commit 101195c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
use rustc_middle::ty::{self, InferConst};
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef};
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::symbol::{sym, Ident};
use rustc_span::{BytePos, Span};
use std::borrow::Cow;
use std::iter;
Expand Down Expand Up @@ -162,8 +162,10 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
let ty_vars = infcx_inner.type_variables();
let var_origin = ty_vars.var_origin(ty_vid);
if let Some(def_id) = var_origin.param_def_id
// The `Self` param of a trait has the def-id of the trait,
// since it's a synthetic parameter.
&& infcx.tcx.def_kind(def_id) == DefKind::TyParam
&& let name = infcx.tcx.item_name(def_id)
&& name != kw::SelfUpper
&& !var_origin.span.from_expansion()
{
let generics = infcx.tcx.generics_of(infcx.tcx.parent(def_id));
Expand Down Expand Up @@ -277,20 +279,18 @@ impl<'tcx> InferCtxt<'tcx> {
let mut inner = self.inner.borrow_mut();
let ty_vars = &inner.type_variables();
let var_origin = ty_vars.var_origin(ty_vid);
if let Some(def_id) = var_origin.param_def_id {
let name = self.tcx.item_name(def_id);
if name != kw::SelfUpper && !var_origin.span.from_expansion() {
return InferenceDiagnosticsData {
name: name.to_string(),
span: Some(var_origin.span),
kind: UnderspecifiedArgKind::Type {
prefix: "type parameter".into(),
},
parent: InferenceDiagnosticsParentData::for_def_id(
self.tcx, def_id,
),
};
}
if let Some(def_id) = var_origin.param_def_id
// The `Self` param of a trait has the def-id of the trait,
// since it's a synthetic parameter.
&& self.tcx.def_kind(def_id) == DefKind::TyParam
&& !var_origin.span.from_expansion()
{
return InferenceDiagnosticsData {
name: self.tcx.item_name(def_id).to_string(),
span: Some(var_origin.span),
kind: UnderspecifiedArgKind::Type { prefix: "type parameter".into() },
parent: InferenceDiagnosticsParentData::for_def_id(self.tcx, def_id),
};
}
}

Expand Down

0 comments on commit 101195c

Please sign in to comment.