Skip to content

Commit

Permalink
Remove ProjectionTy::from_ref_and_name
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Feb 13, 2021
1 parent dfa581f commit 9bbd3e0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lang_items.rs
Expand Up @@ -238,6 +238,7 @@ language_item_table! {

Deref, sym::deref, deref_trait, Target::Trait;
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait;
DerefTarget, sym::deref_target, deref_target, Target::AssocTy;
Receiver, sym::receiver, receiver_trait, Target::Trait;

Fn, kw::Fn, fn_trait, Target::Trait;
Expand Down
16 changes: 0 additions & 16 deletions compiler/rustc_middle/src/ty/sty.rs
Expand Up @@ -1112,22 +1112,6 @@ pub struct ProjectionTy<'tcx> {
}

impl<'tcx> ProjectionTy<'tcx> {
/// Construct a `ProjectionTy` by searching the trait from `trait_ref` for the
/// associated item named `item_name`.
pub fn from_ref_and_name(
tcx: TyCtxt<'_>,
trait_ref: ty::TraitRef<'tcx>,
item_name: Ident,
) -> ProjectionTy<'tcx> {
let item_def_id = tcx
.associated_items(trait_ref.def_id)
.find_by_name_and_kind(tcx, item_name, ty::AssocKind::Type, trait_ref.def_id)
.unwrap()
.def_id;

ProjectionTy { substs: trait_ref.substs, item_def_id }
}

/// Extracts the underlying trait reference from this projection.
/// For example, if this is a projection of `<T as Iterator>::Item`,
/// then this function would return a `T: Iterator` trait reference.
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_trait_selection/src/autoderef.rs
Expand Up @@ -6,7 +6,6 @@ use rustc_infer::infer::InferCtxt;
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
use rustc_middle::ty::{ToPredicate, TypeFoldable};
use rustc_session::DiagnosticMessageId;
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -146,11 +145,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
let normalized_ty = fulfillcx.normalize_projection_type(
&self.infcx,
self.param_env,
ty::ProjectionTy::from_ref_and_name(
tcx,
trait_ref,
Ident::with_dummy_span(sym::Target),
),
ty::ProjectionTy {
item_def_id: tcx.lang_items().deref_target()?,
substs: trait_ref.substs,
},
cause,
);
if let Err(e) = fulfillcx.select_where_possible(&self.infcx) {
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ops/deref.rs
Expand Up @@ -64,6 +64,7 @@ pub trait Deref {
/// The resulting type after dereferencing.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "deref_target"]
#[cfg_attr(not(bootstrap), lang = "deref_target")]
type Target: ?Sized;

/// Dereferences the value.
Expand Down

0 comments on commit 9bbd3e0

Please sign in to comment.