Skip to content

Commit

Permalink
Rollup merge of rust-lang#65263 - mbStavola:dedup-raw-item-fns, r=Cen…
Browse files Browse the repository at this point in the history
…tril

Deduplicate is_{freeze,copy,sized}_raw

Addresses rust-lang#65259

Deduplicates `is_{freeze,copy,sized}_raw` by delegating to a new method which takes in a `LangItem`.
  • Loading branch information
tmandry authored Oct 11, 2019
2 parents 4180187 + ee08114 commit 4e7633d
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,34 +1017,25 @@ impl<'tcx> ty::TyS<'tcx> {
}

fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
let (param_env, ty) = query.into_parts();
let trait_def_id = tcx.require_lang_item(lang_items::CopyTraitLangItem, None);
tcx.infer_ctxt()
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
&infcx,
param_env,
ty,
trait_def_id,
DUMMY_SP,
))
is_item_raw(tcx, query, lang_items::CopyTraitLangItem)
}

fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
let (param_env, ty) = query.into_parts();
let trait_def_id = tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
tcx.infer_ctxt()
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
&infcx,
param_env,
ty,
trait_def_id,
DUMMY_SP,
))
is_item_raw(tcx, query, lang_items::SizedTraitLangItem)

}

fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
is_item_raw(tcx, query, lang_items::FreezeTraitLangItem)
}

fn is_item_raw<'tcx>(
tcx: TyCtxt<'tcx>,
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
item: lang_items::LangItem,
) -> bool {
let (param_env, ty) = query.into_parts();
let trait_def_id = tcx.require_lang_item(lang_items::FreezeTraitLangItem, None);
let trait_def_id = tcx.require_lang_item(item, None);
tcx.infer_ctxt()
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
&infcx,
Expand Down

0 comments on commit 4e7633d

Please sign in to comment.