Skip to content

Commit ef07cf4

Browse files
committed
Remove FnCtxt::impl_self_ty
1 parent 9fed360 commit ef07cf4

File tree

8 files changed

+9
-35
lines changed

8 files changed

+9
-35
lines changed

src/librustc_typeck/check/method/confirm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
209209
"impl {:?} is not an inherent impl",
210210
impl_def_id
211211
);
212-
self.impl_self_ty(self.span, impl_def_id).substs
212+
self.fresh_substs_for_item(self.span, impl_def_id)
213213
}
214214

215215
probe::ObjectPick => {

src/librustc_typeck/check/method/probe.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11281128
) -> Option<PickResult<'tcx>> {
11291129
let tcx = self.tcx;
11301130

1131-
// In general, during probing we erase regions. See
1132-
// `impl_self_ty()` for an explanation.
1131+
// In general, during probing we erase regions.
11331132
let region = tcx.lifetimes.re_erased;
11341133

11351134
let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut { ty: self_ty, mutbl });
@@ -1614,8 +1613,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16141613
} else {
16151614
match param.kind {
16161615
GenericParamDefKind::Lifetime => {
1617-
// In general, during probe we erase regions. See
1618-
// `impl_self_ty()` for an explanation.
1616+
// In general, during probe we erase regions.
16191617
self.tcx.lifetimes.re_erased.into()
16201618
}
16211619
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {

src/librustc_typeck/check/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
117117
.span_if_local(item.def_id)
118118
.or_else(|| self.tcx.hir().span_if_local(impl_did));
119119

120-
let impl_ty = self.impl_self_ty(span, impl_did).ty;
120+
let impl_ty = self.tcx.at(span).type_of(impl_did);
121121

122122
let insertion = match self.tcx.impl_trait_ref(impl_did) {
123123
None => String::new(),
@@ -537,7 +537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
537537
// When the "method" is resolved through dereferencing, we really want the
538538
// original type that has the associated function for accurate suggestions.
539539
// (#61411)
540-
let ty = self.impl_self_ty(span, *impl_did).ty;
540+
let ty = tcx.at(span).type_of(*impl_did);
541541
match (&ty.peel_refs().kind, &actual.peel_refs().kind) {
542542
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
543543
// Use `actual` as it will have more `substs` filled in.

src/librustc_typeck/check/mod.rs

-19
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ use std::slice;
154154

155155
use crate::require_c_abi_if_c_variadic;
156156
use crate::util::common::indenter;
157-
use crate::TypeAndSubsts;
158157

159158
use self::autoderef::Autoderef;
160159
use self::callee::DeferredCallResolution;
@@ -4251,24 +4250,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
42514250
}
42524251
}
42534252

4254-
// Determine the `Self` type, using fresh variables for all variables
4255-
// declared on the impl declaration e.g., `impl<A,B> for Vec<(A,B)>`
4256-
// would return `($0, $1)` where `$0` and `$1` are freshly instantiated type
4257-
// variables.
4258-
pub fn impl_self_ty(
4259-
&self,
4260-
span: Span, // (potential) receiver for this impl
4261-
did: DefId,
4262-
) -> TypeAndSubsts<'tcx> {
4263-
let ity = self.tcx.type_of(did);
4264-
debug!("impl_self_ty: ity={:?}", ity);
4265-
4266-
let substs = self.fresh_substs_for_item(span, did);
4267-
let substd_ty = self.instantiate_type_scheme(span, &substs, &ity);
4268-
4269-
TypeAndSubsts { substs, ty: substd_ty }
4270-
}
4271-
42724253
/// Unifies the output type with the expected type early, for more coercions
42734254
/// and forward type information on the input expressions.
42744255
fn expected_inputs_for_expected_output(

src/librustc_typeck/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ use rustc_infer::infer::{InferOk, TyCtxtInferExt};
9797
use rustc_infer::traits::TraitEngineExt as _;
9898
use rustc_middle::middle;
9999
use rustc_middle::ty::query::Providers;
100-
use rustc_middle::ty::subst::SubstsRef;
101100
use rustc_middle::ty::{self, Ty, TyCtxt};
102101
use rustc_middle::util;
103102
use rustc_session::config::EntryFnType;
@@ -111,10 +110,6 @@ use rustc_trait_selection::traits::{
111110
use std::iter;
112111

113112
use astconv::{AstConv, Bounds};
114-
pub struct TypeAndSubsts<'tcx> {
115-
substs: SubstsRef<'tcx>,
116-
ty: Ty<'tcx>,
117-
}
118113

119114
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
120115
if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) {

src/test/ui/issues/issue-18446.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | x.foo();
77
| | multiple `foo` found
88
| help: disambiguate the method call for candidate #2: `T::foo(&x)`
99
|
10-
note: candidate #1 is defined in an impl for the type `dyn T`
10+
note: candidate #1 is defined in an impl for the type `(dyn T + 'a)`
1111
--> $DIR/issue-18446.rs:9:5
1212
|
1313
LL | fn foo(&self) {}

src/test/ui/methods/method-deref-to-same-trait-object-with-separate-params.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ error[E0034]: multiple applicable items in scope
2020
LL | let z = x.foo();
2121
| ^^^ multiple `foo` found
2222
|
23-
note: candidate #1 is defined in an impl of the trait `internal::X` for the type `_`
23+
note: candidate #1 is defined in an impl of the trait `internal::X` for the type `T`
2424
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:43:9
2525
|
2626
LL | fn foo(self: Smaht<Self, u64>) -> u64 {
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28-
note: candidate #2 is defined in an impl of the trait `nuisance_foo::NuisanceFoo` for the type `_`
28+
note: candidate #2 is defined in an impl of the trait `nuisance_foo::NuisanceFoo` for the type `T`
2929
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:70:9
3030
|
3131
LL | fn foo(self) {}

src/test/ui/suggestions/suggest-assoc-fn-call-with-turbofish.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | x.default_hello();
1111
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::default_hello`
1212
|
1313
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
14-
note: the candidate is defined in an impl for the type `GenericAssocMethod<_>`
14+
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
1515
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:4:5
1616
|
1717
LL | fn default_hello() {}

0 commit comments

Comments
 (0)