Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Account for Self params properly
  • Loading branch information
compiler-errors committed Apr 5, 2024
commit 455b4394f856f8e86728baf2d4ce4f787d2901b9
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