Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove FnCtxt::impl_self_ty #71087

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
"impl {:?} is not an inherent impl",
impl_def_id
);
self.impl_self_ty(self.span, impl_def_id).substs
self.fresh_substs_for_item(self.span, impl_def_id)
}

probe::ObjectPick => {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
) -> Option<PickResult<'tcx>> {
let tcx = self.tcx;

// In general, during probing we erase regions. See
// `impl_self_ty()` for an explanation.
JohnTitor marked this conversation as resolved.
Show resolved Hide resolved
// In general, during probing we erase regions.
let region = tcx.lifetimes.re_erased;

let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut { ty: self_ty, mutbl });
Expand Down Expand Up @@ -1614,8 +1613,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} else {
match param.kind {
GenericParamDefKind::Lifetime => {
// In general, during probe we erase regions. See
// `impl_self_ty()` for an explanation.
// In general, during probe we erase regions.
self.tcx.lifetimes.re_erased.into()
}
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.span_if_local(item.def_id)
.or_else(|| self.tcx.hir().span_if_local(impl_did));

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

let insertion = match self.tcx.impl_trait_ref(impl_did) {
None => String::new(),
Expand Down Expand Up @@ -537,7 +537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// When the "method" is resolved through dereferencing, we really want the
// original type that has the associated function for accurate suggestions.
// (#61411)
let ty = self.impl_self_ty(span, *impl_did).ty;
let ty = tcx.at(span).type_of(*impl_did);
match (&ty.peel_refs().kind, &actual.peel_refs().kind) {
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
// Use `actual` as it will have more `substs` filled in.
Expand Down
19 changes: 0 additions & 19 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ use std::slice;

use crate::require_c_abi_if_c_variadic;
use crate::util::common::indenter;
use crate::TypeAndSubsts;

use self::autoderef::Autoderef;
use self::callee::DeferredCallResolution;
Expand Down Expand Up @@ -4251,24 +4250,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

// Determine the `Self` type, using fresh variables for all variables
// declared on the impl declaration e.g., `impl<A,B> for Vec<(A,B)>`
// would return `($0, $1)` where `$0` and `$1` are freshly instantiated type
// variables.
pub fn impl_self_ty(
&self,
span: Span, // (potential) receiver for this impl
did: DefId,
) -> TypeAndSubsts<'tcx> {
let ity = self.tcx.type_of(did);
debug!("impl_self_ty: ity={:?}", ity);

let substs = self.fresh_substs_for_item(span, did);
let substd_ty = self.instantiate_type_scheme(span, &substs, &ity);

TypeAndSubsts { substs, ty: substd_ty }
}

/// Unifies the output type with the expected type early, for more coercions
/// and forward type information on the input expressions.
fn expected_inputs_for_expected_output(
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ use rustc_infer::infer::{InferOk, TyCtxtInferExt};
use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::middle;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::util;
use rustc_session::config::EntryFnType;
Expand All @@ -111,10 +110,6 @@ use rustc_trait_selection::traits::{
use std::iter;

use astconv::{AstConv, Bounds};
pub struct TypeAndSubsts<'tcx> {
substs: SubstsRef<'tcx>,
ty: Ty<'tcx>,
}

fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-18446.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | x.foo();
| | multiple `foo` found
| help: disambiguate the method call for candidate #2: `T::foo(&x)`
|
note: candidate #1 is defined in an impl for the type `dyn T`
note: candidate #1 is defined in an impl for the type `(dyn T + 'a)`
--> $DIR/issue-18446.rs:9:5
|
LL | fn foo(&self) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ error[E0034]: multiple applicable items in scope
LL | let z = x.foo();
| ^^^ multiple `foo` found
|
note: candidate #1 is defined in an impl of the trait `internal::X` for the type `_`
note: candidate #1 is defined in an impl of the trait `internal::X` for the type `T`
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:43:9
|
LL | fn foo(self: Smaht<Self, u64>) -> u64 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl of the trait `nuisance_foo::NuisanceFoo` for the type `_`
note: candidate #2 is defined in an impl of the trait `nuisance_foo::NuisanceFoo` for the type `T`
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:70:9
|
LL | fn foo(self) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | x.default_hello();
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::default_hello`
|
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in an impl for the type `GenericAssocMethod<_>`
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:4:5
|
LL | fn default_hello() {}
Expand Down