break_index: CFGIndex, // where to go on a `break`
}
-pub fn construct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- body: &hir::Body) -> CFG {
+pub fn construct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &hir::Body) -> CFG {
let mut graph = graph::Graph::new();
let entry = graph.add_node(CFGNodeData::Entry);
pub type CFGEdge = graph::Edge<CFGEdgeData>;
impl CFG {
- pub fn new<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- body: &hir::Body) -> CFG {
+ pub fn new<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &hir::Body) -> CFG {
construct::construct(tcx, body)
}
}
impl<'gcx: 'tcx, 'tcx, T> DepNodeParams<'gcx, 'tcx> for T
- where T: HashStable<StableHashingContext<'tcx>> + fmt::Debug
+where
+ T: HashStable<StableHashingContext<'tcx>> + fmt::Debug,
{
default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
}
impl DepGraph {
-
pub fn new(prev_graph: PreviousDepGraph,
prev_work_products: FxHashMap<WorkProductId, WorkProduct>) -> DepGraph {
let prev_graph_node_count = prev_graph.node_count();
pub fn try_mark_green_and_read(
&self,
tcx: TyCtxt<'_, '_>,
- dep_node: &DepNode
+ dep_node: &DepNode,
) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> {
self.try_mark_green(tcx, dep_node).map(|(prev_index, dep_node_index)| {
debug_assert!(self.is_green(&dep_node));
pub fn try_mark_green(
&self,
tcx: TyCtxt<'_, '_>,
- dep_node: &DepNode
+ dep_node: &DepNode,
) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> {
debug_assert!(!dep_node.kind.is_eval_always());
tcx: TyCtxt<'tcx, 'tcx>,
data: &DepGraphData,
prev_dep_node_index: SerializedDepNodeIndex,
- dep_node: &DepNode
+ dep_node: &DepNode,
) -> Option<DepNodeIndex> {
debug!("try_mark_previous_green({:?}) - BEGIN", dep_node);
/// The type context itself can be used to access all kinds of tracked
/// state, but those accesses should always generate read events.
-impl<'gcx, 'tcx> DepGraphSafe for TyCtxt<'gcx, 'tcx> {
-}
+impl<'gcx, 'tcx> DepGraphSafe for TyCtxt<'gcx, 'tcx> {}
/// Tuples make it easy to build up state.
impl<A, B> DepGraphSafe for (A, B)
impl<'tcx, V> Canonical<'tcx, V> {
/// Instantiate the wrapped value, replacing each canonical value
/// with the value given in `var_values`.
- pub fn substitute(
- &self,
- tcx: TyCtxt<'_, 'tcx>,
- var_values: &CanonicalVarValues<'tcx>,
- ) -> V
+ pub fn substitute(&self, tcx: TyCtxt<'_, 'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
where
V: TypeFoldable<'tcx>,
{
}
impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
- pub fn super_combine_tys<R>(&self,
- relation: &mut R,
- a: Ty<'tcx>,
- b: Ty<'tcx>)
- -> RelateResult<'tcx, Ty<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>
+ pub fn super_combine_tys<R>(
+ &self,
+ relation: &mut R,
+ a: Ty<'tcx>,
+ b: Ty<'tcx>,
+ ) -> RelateResult<'tcx, Ty<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
{
let a_is_expected = relation.a_is_expected();
}
impl<'gcx, 'tcx, T> fmt::Display for Highlighted<'gcx, 'tcx, T>
- where T: for<'a, 'b, 'c> Print<'gcx, 'tcx,
+ where
+ T: for<'a, 'b, 'c> Print<
+ 'gcx,
+ 'tcx,
FmtPrinter<'a, 'gcx, 'tcx, &'b mut fmt::Formatter<'c>>,
Error = fmt::Error,
>,
use crate::ty::{self, Ty};
use crate::ty::relate::{RelateResult, TypeRelation};
-pub trait LatticeDir<'f, 'gcx: 'f+'tcx, 'tcx: 'f> : TypeRelation<'gcx, 'tcx> {
+pub trait LatticeDir<'f, 'gcx: 'f + 'tcx, 'tcx: 'f>: TypeRelation<'gcx, 'tcx> {
fn infcx(&self) -> &'f InferCtxt<'f, 'gcx, 'tcx>;
fn cause(&self) -> &ObligationCause<'tcx>;
/// cases, this is more conservative than necessary, in order to
/// avoid making arbitrary choices. See
/// `TransitiveRelation::postdom_upper_bound` for more details.
- pub fn lub_free_regions<'gcx>(&self,
- tcx: TyCtxt<'gcx, 'tcx>,
- r_a: Region<'tcx>,
- r_b: Region<'tcx>)
- -> Region<'tcx> {
+ pub fn lub_free_regions<'gcx>(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ r_a: Region<'tcx>,
+ r_b: Region<'tcx>,
+ ) -> Region<'tcx> {
debug!("lub_free_regions(r_a={:?}, r_b={:?})", r_a, r_b);
assert!(is_free(r_a));
assert!(is_free(r_b));
}
}
-fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
- tcx: TyCtxt<'tcx, 'tcx>,
- pass: T
-) {
+fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx, 'tcx>, pass: T) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let krate = tcx.hir().krate();
fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
tcx: TyCtxt<'tcx, 'tcx>,
- builtin_lints: T
+ builtin_lints: T,
) {
let mut passes = tcx.sess.lint_store.borrow().late_passes.lock().take().unwrap();
attrs.iter().any(|attr| Level::from_symbol(attr.name_or_empty()).is_some())
}
-fn lint_levels<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum)
- -> &'tcx LintLevelMap
-{
+fn lint_levels<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> &'tcx LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE);
let mut builder = LintLevelMapBuilder {
levels: LintLevelSets::builder(tcx.sess),
fn crates_untracked(&self) -> Vec<CrateNum>;
// utility functions
- fn encode_metadata<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> EncodedMetadata;
+ fn encode_metadata<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>) -> EncodedMetadata;
fn metadata_encoding_version(&self) -> &[u8];
}
// In order to get this left-to-right dependency ordering, we perform a
// topological sort of all crates putting the leaves at the right-most
// positions.
-pub fn used_crates(tcx: TyCtxt<'_, '_>, prefer: LinkagePreference)
- -> Vec<(CrateNum, LibSource)>
-{
+pub fn used_crates(tcx: TyCtxt<'_, '_>, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)> {
let mut libs = tcx.crates()
.iter()
.cloned()
// explored. For example, if it's a live Node::Item that is a
// function, then we should explore its block to check for codes that
// may need to be marked as live.
-fn should_explore<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- hir_id: hir::HirId) -> bool {
+fn should_explore<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir_id: hir::HirId) -> bool {
match tcx.hir().find_by_hir_id(hir_id) {
Some(Node::Item(..)) |
Some(Node::ImplItem(..)) |
}
}
-fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_>,
- id: hir::HirId,
- attrs: &[ast::Attribute]) -> bool {
+fn has_allow_dead_code_or_lang_attr(
+ tcx: TyCtxt<'_, '_>,
+ id: hir::HirId,
+ attrs: &[ast::Attribute],
+) -> bool {
if attr::contains_name(attrs, sym::lang) {
return true;
}
(life_seeder.worklist, life_seeder.struct_constructors)
}
-fn find_live<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- access_levels: &privacy::AccessLevels,
- krate: &hir::Crate)
- -> FxHashSet<hir::HirId> {
+fn find_live<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ access_levels: &privacy::AccessLevels,
+ krate: &hir::Crate,
+) -> FxHashSet<hir::HirId> {
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate);
let mut symbol_visitor = MarkSymbolVisitor {
worklist,
sess.dependency_formats.set(fmts);
}
-fn calculate_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty: config::CrateType) -> DependencyList {
-
+fn calculate_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: config::CrateType) -> DependencyList {
let sess = &tcx.sess;
if !sess.opts.output_types.should_codegen() {
ret
}
-fn add_library(tcx: TyCtxt<'_, '_>,
- cnum: CrateNum,
- link: LinkagePreference,
- m: &mut FxHashMap<CrateNum, LinkagePreference>) {
+fn add_library(
+ tcx: TyCtxt<'_, '_>,
+ cnum: CrateNum,
+ link: LinkagePreference,
+ m: &mut FxHashMap<CrateNum, LinkagePreference>,
+) {
match m.get(&cnum) {
Some(&link2) => {
// If the linkages differ, then we'd have two copies of the library
}
impl<'tcx> ExportedSymbol<'tcx> {
- pub fn symbol_name(&self,
- tcx: TyCtxt<'tcx, '_>)
- -> ty::SymbolName {
+ pub fn symbol_name(&self, tcx: TyCtxt<'tcx, '_>) -> ty::SymbolName {
match *self {
ExportedSymbol::NonGeneric(def_id) => {
tcx.symbol_name(ty::Instance::mono(tcx, def_id))
}
}
- pub fn compare_stable(&self,
- tcx: TyCtxt<'tcx, '_>,
- other: &ExportedSymbol<'tcx>)
- -> cmp::Ordering {
+ pub fn compare_stable(
+ &self,
+ tcx: TyCtxt<'tcx, '_>,
+ other: &ExportedSymbol<'tcx>,
+ ) -> cmp::Ordering {
match *self {
ExportedSymbol::NonGeneric(self_def_id) => match *other {
ExportedSymbol::NonGeneric(other_def_id) => {
/// `None` means that rvalues will be given more conservative lifetimes.
///
/// See also `with_infer`, which is used *during* typeck.
- pub fn new(delegate: &'a mut (dyn Delegate<'tcx>+'a),
- tcx: TyCtxt<'tcx, 'tcx>,
- body_owner: DefId,
- param_env: ty::ParamEnv<'tcx>,
- region_scope_tree: &'a region::ScopeTree,
- tables: &'a ty::TypeckTables<'tcx>,
- rvalue_promotable_map: Option<&'tcx ItemLocalSet>)
- -> Self
- {
+ pub fn new(
+ delegate: &'a mut (dyn Delegate<'tcx> + 'a),
+ tcx: TyCtxt<'tcx, 'tcx>,
+ body_owner: DefId,
+ param_env: ty::ParamEnv<'tcx>,
+ region_scope_tree: &'a region::ScopeTree,
+ tables: &'a ty::TypeckTables<'tcx>,
+ rvalue_promotable_map: Option<&'tcx ItemLocalSet>,
+ ) -> Self {
ExprUseVisitor {
mc: mc::MemCategorizationContext::new(tcx,
body_owner,
}
struct ItemVisitor<'tcx> {
- tcx: TyCtxt<'tcx, 'tcx>
+ tcx: TyCtxt<'tcx, 'tcx>,
}
struct ExprVisitor<'tcx> {
/// If the type is `Option<T>`, it will return `T`, otherwise
/// the type itself. Works on most `Option`-like types.
-fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>)
- -> Ty<'tcx> {
+fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
let (def, substs) = match ty.sty {
ty::Adt(def, substs) => (def, substs),
_ => return ty
}
}
-fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'tcx>,
- fk: FnKind<'tcx>,
- decl: &'tcx hir::FnDecl,
- body_id: hir::BodyId,
- sp: Span,
- id: hir::HirId) {
+fn visit_fn<'a, 'tcx: 'a>(
+ ir: &mut IrMaps<'tcx>,
+ fk: FnKind<'tcx>,
+ decl: &'tcx hir::FnDecl,
+ body_id: hir::BodyId,
+ sp: Span,
+ id: hir::HirId,
+) {
debug!("visit_fn");
// swap in a new set of IR maps for this function body:
}
#[derive(Clone)]
-pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
+pub struct MemCategorizationContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
pub tcx: TyCtxt<'gcx, 'tcx>,
pub body_owner: DefId,
pub upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
ret
}
- fn from_local(tcx: TyCtxt<'_, '_>, tables: &ty::TypeckTables<'_>,
- id: ast::NodeId) -> MutabilityCategory {
+ fn from_local(
+ tcx: TyCtxt<'_, '_>,
+ tables: &ty::TypeckTables<'_>,
+ id: ast::NodeId,
+ ) -> MutabilityCategory {
let ret = match tcx.hir().get(id) {
Node::Binding(p) => match p.node {
PatKind::Binding(..) => {
}
impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
- pub fn new(tcx: TyCtxt<'tcx, 'tcx>,
- body_owner: DefId,
- region_scope_tree: &'a region::ScopeTree,
- tables: &'a ty::TypeckTables<'tcx>,
- rvalue_promotable_map: Option<&'tcx ItemLocalSet>)
- -> MemCategorizationContext<'a, 'tcx, 'tcx> {
+ pub fn new(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ body_owner: DefId,
+ region_scope_tree: &'a region::ScopeTree,
+ tables: &'a ty::TypeckTables<'tcx>,
+ rvalue_promotable_map: Option<&'tcx ItemLocalSet>,
+ ) -> MemCategorizationContext<'a, 'tcx, 'tcx> {
MemCategorizationContext {
tcx,
body_owner,
// Returns true if the given item must be inlined because it may be
// monomorphized or it was marked with `#[inline]`. This will only return
// true for functions.
-fn item_might_be_inlined(tcx: TyCtxt<'tcx, 'tcx>,
- item: &hir::Item,
- attrs: CodegenFnAttrs) -> bool {
+fn item_might_be_inlined(tcx: TyCtxt<'tcx, 'tcx>, item: &hir::Item, attrs: CodegenFnAttrs) -> bool {
if attrs.requests_inline() {
return true
}
}
}
-fn method_might_be_inlined<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_item: &hir::ImplItem,
- impl_src: DefId) -> bool {
+fn method_might_be_inlined<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_item: &hir::ImplItem,
+ impl_src: DefId,
+) -> bool {
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner_def_id());
let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(impl_item.hir_id));
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
/// Assuming that the provided region was defined within this `ScopeTree`,
/// returns the outermost `Scope` that the region outlives.
- pub fn early_free_scope<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>,
- br: &ty::EarlyBoundRegion)
- -> Scope {
+ pub fn early_free_scope<'gcx>(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ br: &ty::EarlyBoundRegion,
+ ) -> Scope {
let param_owner = tcx.parent(br.def_id).unwrap();
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
/// Assuming that the provided region was defined within this `ScopeTree`,
/// returns the outermost `Scope` that the region outlives.
- pub fn free_scope<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, fr: &ty::FreeRegion)
- -> Scope {
+ pub fn free_scope<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, fr: &ty::FreeRegion) -> Scope {
let param_owner = match fr.bound_region {
ty::BoundRegion::BrNamed(def_id, _) => {
tcx.parent(def_id).unwrap()
}
/// Records the lifetime of a local variable as `cx.var_parent`
-fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_>,
- var_id: hir::ItemLocalId,
- _sp: Span) {
+fn record_var_lifetime(
+ visitor: &mut RegionResolutionVisitor<'_>,
+ var_id: hir::ItemLocalId,
+ _sp: Span,
+) {
match visitor.cx.var_parent {
None => {
// this can happen in extern fn declarations like
visitor.cx = prev_cx;
}
-fn resolve_local<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>,
- pat: Option<&'tcx hir::Pat>,
- init: Option<&'tcx hir::Expr>) {
+fn resolve_local<'tcx>(
+ visitor: &mut RegionResolutionVisitor<'tcx>,
+ pat: Option<&'tcx hir::Pat>,
+ init: Option<&'tcx hir::Expr>,
+) {
debug!("resolve_local(pat={:?}, init={:?})", pat, init);
let blk_scope = visitor.cx.var_parent.map(|(p, _)| p);
fn record_rvalue_scope_if_borrow_expr<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>,
expr: &hir::Expr,
- blk_id: Option<Scope>)
- {
+ blk_id: Option<Scope>,
+ ) {
match expr.node {
hir::ExprKind::AddrOf(_, ref subexpr) => {
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
/// | <rvalue>
///
/// Note: ET is intended to match "rvalues or places based on rvalues".
- fn record_rvalue_scope<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>,
- expr: &hir::Expr,
- blk_scope: Option<Scope>) {
+ fn record_rvalue_scope<'tcx>(
+ visitor: &mut RegionResolutionVisitor<'tcx>,
+ expr: &hir::Expr,
+ blk_scope: Option<Scope>,
+ ) {
let mut expr = expr;
loop {
// Note: give all the expressions matching `ET` with the
}
}
-fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId)
- -> &'tcx ScopeTree
-{
+fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx ScopeTree {
let closure_base_def_id = tcx.closure_base_def_id(def_id);
if closure_base_def_id != def_id {
return tcx.region_scope_tree(closure_base_def_id);
/// entire crate. You should not read the result of this query
/// directly, but rather use `named_region_map`, `is_late_bound_map`,
/// etc.
-fn resolve_lifetimes<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- for_krate: CrateNum,
-) -> &'tcx ResolveLifetimes {
+fn resolve_lifetimes<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, for_krate: CrateNum) -> &'tcx ResolveLifetimes {
assert_eq!(for_krate, LOCAL_CRATE);
let named_region_map = krate(tcx);
}
}
-fn compute_object_lifetime_defaults(
- tcx: TyCtxt<'_, '_>,
-) -> HirIdMap<Vec<ObjectLifetimeDefault>> {
+fn compute_object_lifetime_defaults(tcx: TyCtxt<'_, '_>) -> HirIdMap<Vec<ObjectLifetimeDefault>> {
let mut map = HirIdMap::default();
for item in tcx.hir().krate().items.values() {
match item.node {
AnnotationKind::Required,
|v| intravisit::walk_crate(v, krate));
}
- return index
+ return index;
}
pub fn local_stability(&self, id: HirId) -> Option<&'tcx Stability> {
tcx: TyCtxt<'tcx, 'tcx>,
span: Span,
feature: Symbol,
- since: Symbol
+ since: Symbol,
) {
tcx.lint_hir(lint::builtin::STABLE_FEATURES,
hir::CRATE_HIR_ID,
}
impl<'gcx, 'tcx> ConstEvalErr<'tcx> {
- pub fn struct_error(&self,
+ pub fn struct_error(
+ &self,
tcx: TyCtxtAt<'gcx, 'tcx>,
- message: &str)
- -> Result<DiagnosticBuilder<'tcx>, ErrorHandled>
- {
+ message: &str,
+ ) -> Result<DiagnosticBuilder<'tcx>, ErrorHandled> {
self.struct_generic(tcx, message, None)
}
- pub fn report_as_error(&self,
- tcx: TyCtxtAt<'gcx, 'tcx>,
- message: &str
- ) -> ErrorHandled {
+ pub fn report_as_error(&self, tcx: TyCtxtAt<'gcx, 'tcx>, message: &str) -> ErrorHandled {
let err = self.struct_error(tcx, message);
match err {
Ok(mut err) => {
}
}
- pub fn report_as_lint(&self,
+ pub fn report_as_lint(
+ &self,
tcx: TyCtxtAt<'gcx, 'tcx>,
message: &str,
lint_root: hir::HirId,
}
}
-pub fn struct_error<'gcx, 'tcx>(
- tcx: TyCtxtAt<'gcx, 'tcx>,
- msg: &str,
-) -> DiagnosticBuilder<'tcx> {
+pub fn struct_error<'gcx, 'tcx>(tcx: TyCtxtAt<'gcx, 'tcx>, msg: &str) -> DiagnosticBuilder<'tcx> {
struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg)
}
}
impl<'s> AllocDecodingSession<'s> {
-
// Decodes an AllocId in a thread-safe way.
- pub fn decode_alloc_id<D>(&self,
- decoder: &mut D)
- -> Result<AllocId, D::Error>
- where D: TyDecoder<'tcx>,
+ pub fn decode_alloc_id<D>(&self, decoder: &mut D) -> Result<AllocId, D::Error>
+ where
+ D: TyDecoder<'tcx>,
{
// Read the index of the allocation
let idx = decoder.read_u32()? as usize;
/*
* TypeFoldable implementations for MIR types
- */
+*/
CloneTypeFoldableAndLiftImpls! {
BlockTailInfo,
}
}
- pub fn instantiation_mode(&self,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> InstantiationMode {
+ pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx, 'tcx>) -> InstantiationMode {
let inline_in_all_cgus =
tcx.sess.opts.debugging_opts.inline_in_all_cgus.unwrap_or_else(|| {
tcx.sess.opts.optimize != OptLevel::No
}
};
- fn to_string_internal<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- prefix: &str,
- instance: Instance<'tcx>,
- debug: bool)
- -> String {
+ fn to_string_internal<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ prefix: &str,
+ instance: Instance<'tcx>,
+ debug: bool,
+ ) -> String {
let mut result = String::with_capacity(32);
result.push_str(prefix);
let printer = DefPathBasedNames::new(tcx, false, false);
})
}
- pub fn items_in_deterministic_order(&self,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> Vec<(MonoItem<'tcx>,
- (Linkage, Visibility))> {
+ pub fn items_in_deterministic_order(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ) -> Vec<(MonoItem<'tcx>, (Linkage, Visibility))> {
// The codegen tests rely on items being process in the same order as
// they appear in the file, so for local items, we sort by node_id first
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct ItemSortKey(Option<HirId>, SymbolName);
- fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- item: MonoItem<'tcx>) -> ItemSortKey {
+ fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, item: MonoItem<'tcx>) -> ItemSortKey {
ItemSortKey(match item {
MonoItem::Fn(ref instance) => {
match instance.def {
/// not carry a `Ty` for `T`.)
///
/// Note that the resulting type has not been normalized.
- pub fn field_ty(self, tcx: TyCtxt<'gcx, 'tcx>, f: &Field) -> Ty<'tcx>
- {
+ pub fn field_ty(self, tcx: TyCtxt<'gcx, 'tcx>, f: &Field) -> Ty<'tcx> {
let answer = match self.ty.sty {
ty::Adt(adt_def, substs) => {
let variant_def = match self.variant_index {
/// Convenience wrapper around `projection_ty_core` for
/// `PlaceElem`, where we can just use the `Ty` that is already
/// stored inline on field projection elems.
- pub fn projection_ty(self, tcx: TyCtxt<'gcx, 'tcx>,
- elem: &PlaceElem<'tcx>)
- -> PlaceTy<'tcx>
- {
+ pub fn projection_ty(self, tcx: TyCtxt<'gcx, 'tcx>, elem: &PlaceElem<'tcx>) -> PlaceTy<'tcx> {
self.projection_ty_core(tcx, elem, |_, _, ty| ty)
}
self,
tcx: TyCtxt<'gcx, 'tcx>,
elem: &ProjectionElem<V, T>,
- mut handle_field: impl FnMut(&Self, &Field, &T) -> Ty<'tcx>)
- -> PlaceTy<'tcx>
+ mut handle_field: impl FnMut(&Self, &Field, &T) -> Ty<'tcx>,
+ ) -> PlaceTy<'tcx>
where
- V: ::std::fmt::Debug, T: ::std::fmt::Debug
+ V: ::std::fmt::Debug,
+ T: ::std::fmt::Debug,
{
let answer = match *elem {
ProjectionElem::Deref => {
impl<'tcx> Place<'tcx> {
pub fn ty<'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'gcx, 'tcx>) -> PlaceTy<'tcx>
- where D: HasLocalDecls<'tcx>
+ where
+ D: HasLocalDecls<'tcx>,
{
match *self {
Place::Base(PlaceBase::Local(index)) =>
impl<'tcx> Rvalue<'tcx> {
pub fn ty<'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'gcx, 'tcx>) -> Ty<'tcx>
- where D: HasLocalDecls<'tcx>
+ where
+ D: HasLocalDecls<'tcx>,
{
match *self {
Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
impl<'tcx> Operand<'tcx> {
pub fn ty<'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'gcx, 'tcx>) -> Ty<'tcx>
- where D: HasLocalDecls<'tcx>
+ where
+ D: HasLocalDecls<'tcx>,
{
match self {
&Operand::Copy(ref l) |
}
impl<'tcx> BinOp {
- pub fn ty<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>,
- lhs_ty: Ty<'tcx>,
- rhs_ty: Ty<'tcx>)
- -> Ty<'tcx> {
+ pub fn ty<'gcx>(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ lhs_ty: Ty<'tcx>,
+ rhs_ty: Ty<'tcx>,
+ ) -> Ty<'tcx> {
// FIXME: handle SIMD correctly
match self {
&BinOp::Add | &BinOp::Sub | &BinOp::Mul | &BinOp::Div | &BinOp::Rem |
/// that type check should guarantee to us that all nested
/// obligations *could be* resolved if we wanted to.
/// Assumes that this is run after the entire crate has been successfully type-checked.
-pub fn codegen_fulfill_obligation<'tcx>(ty: TyCtxt<'tcx, 'tcx>,
- (param_env, trait_ref):
- (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>))
- -> Vtable<'tcx, ()>
-{
+pub fn codegen_fulfill_obligation<'tcx>(
+ ty: TyCtxt<'tcx, 'tcx>,
+ (param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
+) -> Vtable<'tcx, ()> {
// Remove any references to regions; this helps improve caching.
let trait_ref = ty.erase_regions(&trait_ref);
Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder })
}
-pub fn trait_ref_is_knowable<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: ty::TraitRef<'tcx>)
- -> Option<Conflict>
-{
+pub fn trait_ref_is_knowable<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_ref: ty::TraitRef<'tcx>,
+) -> Option<Conflict> {
debug!("trait_ref_is_knowable(trait_ref={:?})", trait_ref);
if orphan_check_trait_ref(tcx, trait_ref, InCrate::Remote).is_ok() {
// A downstream or cousin crate is allowed to implement some
}
}
-pub fn trait_ref_is_local_or_fundamental<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: ty::TraitRef<'tcx>)
- -> bool {
+pub fn trait_ref_is_local_or_fundamental<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_ref: ty::TraitRef<'tcx>,
+) -> bool {
trait_ref.def_id.krate == LOCAL_CRATE || tcx.has_attr(trait_ref.def_id, sym::fundamental)
}
///
/// 1. All type parameters in `Self` must be "covered" by some local type constructor.
/// 2. Some local type must appear in `Self`.
-pub fn orphan_check<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- impl_def_id: DefId)
- -> Result<(), OrphanCheckErr<'tcx>>
-{
+pub fn orphan_check<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ impl_def_id: DefId,
+) -> Result<(), OrphanCheckErr<'tcx>> {
debug!("orphan_check({:?})", impl_def_id);
// We only except this routine to be invoked on implementations
///
/// Note that this function is never called for types that have both type
/// parameters and inference variables.
-fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt<'_, '_>,
- trait_ref: ty::TraitRef<'tcx>,
- in_crate: InCrate)
- -> Result<(), OrphanCheckErr<'tcx>>
-{
+fn orphan_check_trait_ref<'tcx>(
+ tcx: TyCtxt<'_, '_>,
+ trait_ref: ty::TraitRef<'tcx>,
+ in_crate: InCrate,
+) -> Result<(), OrphanCheckErr<'tcx>> {
debug!("orphan_check_trait_ref(trait_ref={:?}, in_crate={:?})",
trait_ref, in_crate);
}
}
-fn uncovered_tys<'tcx>(tcx: TyCtxt<'_, '_>, ty: Ty<'tcx>, in_crate: InCrate)
- -> Vec<Ty<'tcx>> {
+fn uncovered_tys<'tcx>(tcx: TyCtxt<'_, '_>, ty: Ty<'tcx>, in_crate: InCrate) -> Vec<Ty<'tcx>> {
if ty_is_local_constructor(ty, in_crate) {
vec![]
} else if fundamental_ty(ty) {
err
}
- fn report_closure_arg_mismatch(&self,
- span: Span,
- found_span: Option<Span>,
- expected_ref: ty::PolyTraitRef<'tcx>,
- found: ty::PolyTraitRef<'tcx>)
- -> DiagnosticBuilder<'tcx>
- {
- fn build_fn_sig_string<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: &ty::TraitRef<'tcx>) -> String {
+ fn report_closure_arg_mismatch(
+ &self,
+ span: Span,
+ found_span: Option<Span>,
+ expected_ref: ty::PolyTraitRef<'tcx>,
+ found: ty::PolyTraitRef<'tcx>,
+ ) -> DiagnosticBuilder<'tcx> {
+ fn build_fn_sig_string<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_ref: &ty::TraitRef<'tcx>,
+ ) -> String {
let inputs = trait_ref.substs.type_at(1);
let sig = if let ty::Tuple(inputs) = inputs.sty {
tcx.mk_fn_sig(
/// Returns `true` if the trait predicate may apply for *some* assignment
/// to the type parameters.
- fn predicate_can_apply(&self,
- param_env: ty::ParamEnv<'tcx>,
- pred: ty::PolyTraitRef<'tcx>)
- -> bool {
+ fn predicate_can_apply(
+ &self,
+ param_env: ty::ParamEnv<'tcx>,
+ pred: ty::PolyTraitRef<'tcx>,
+ ) -> bool {
struct ParamToVarFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
var_map: FxHashMap<Ty<'tcx>, Ty<'tcx>>
}
}
-fn do_normalize_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- region_context: DefId,
- cause: ObligationCause<'tcx>,
- elaborated_env: ty::ParamEnv<'tcx>,
- predicates: Vec<ty::Predicate<'tcx>>)
- -> Result<Vec<ty::Predicate<'tcx>>, ErrorReported>
-{
+fn do_normalize_predicates<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ region_context: DefId,
+ cause: ObligationCause<'tcx>,
+ elaborated_env: ty::ParamEnv<'tcx>,
+ predicates: Vec<ty::Predicate<'tcx>>,
+) -> Result<Vec<ty::Predicate<'tcx>>, ErrorReported> {
debug!(
"do_normalize_predicates(predicates={:?}, region_context={:?}, cause={:?})",
predicates,
// FIXME: this is gonna need to be removed ...
/// Normalizes the parameter environment, reporting errors if they occur.
-pub fn normalize_param_env_or_error<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- region_context: DefId,
- unnormalized_env: ty::ParamEnv<'tcx>,
- cause: ObligationCause<'tcx>)
- -> ty::ParamEnv<'tcx>
-{
+pub fn normalize_param_env_or_error<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ region_context: DefId,
+ unnormalized_env: ty::ParamEnv<'tcx>,
+ cause: ObligationCause<'tcx>,
+) -> ty::ParamEnv<'tcx> {
// I'm not wild about reporting errors here; I'd prefer to
// have the errors get reported at a defined place (e.g.,
// during typeck). Instead I have all parameter
/// environment. If this returns false, then either normalize
/// encountered an error or one of the predicates did not hold. Used
/// when creating vtables to check for unsatisfiable methods.
-fn normalize_and_test_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- predicates: Vec<ty::Predicate<'tcx>>)
- -> bool
-{
+fn normalize_and_test_predicates<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ predicates: Vec<ty::Predicate<'tcx>>,
+) -> bool {
debug!("normalize_and_test_predicates(predicates={:?})",
predicates);
result
}
-fn substitute_normalize_and_test_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- key: (DefId, SubstsRef<'tcx>))
- -> bool
-{
+fn substitute_normalize_and_test_predicates<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ key: (DefId, SubstsRef<'tcx>),
+) -> bool {
debug!("substitute_normalize_and_test_predicates(key={:?})",
key);
#[inline] // FIXME(#35870): avoid closures being unexported due to `impl Trait`.
fn vtable_methods<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
- trait_ref: ty::PolyTraitRef<'tcx>)
- -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>]
-{
+ trait_ref: ty::PolyTraitRef<'tcx>,
+) -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] {
debug!("vtable_methods({:?})", trait_ref);
tcx.arena.alloc_from_iter(
}
impl<'tcx> TyCtxt<'tcx, 'tcx> {
-
/// Returns the object safety violations that affect
/// astconv -- currently, `Self` in supertraits. This is needed
/// because `object_safety_violations` can't be used during
}
}
-pub(super) fn is_object_safe_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- trait_def_id: DefId) -> bool {
+pub(super) fn is_object_safe_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, trait_def_id: DefId) -> bool {
tcx.object_safety_violations(trait_def_id).is_empty()
}
}
}
-fn parse_error(tcx: TyCtxt<'_, '_>, span: Span,
- message: &str,
- label: &str,
- note: Option<&str>)
- -> ErrorReported
-{
+fn parse_error(
+ tcx: TyCtxt<'_, '_>,
+ span: Span,
+ message: &str,
+ label: &str,
+ note: Option<&str>,
+) -> ErrorReported {
let mut diag = struct_span_err!(
tcx.sess, span, E0232, "{}", message);
diag.span_label(span, label);
}
impl<'gcx, 'tcx> OnUnimplementedDirective {
- fn parse(tcx: TyCtxt<'gcx, 'tcx>,
- trait_def_id: DefId,
- items: &[NestedMetaItem],
- span: Span,
- is_root: bool)
- -> Result<Self, ErrorReported>
- {
+ fn parse(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_def_id: DefId,
+ items: &[NestedMetaItem],
+ span: Span,
+ is_root: bool,
+ ) -> Result<Self, ErrorReported> {
let mut errored = false;
let mut item_iter = items.iter();
}
}
-
- pub fn of_item(tcx: TyCtxt<'gcx, 'tcx>,
- trait_def_id: DefId,
- impl_def_id: DefId)
- -> Result<Option<Self>, ErrorReported>
- {
+ pub fn of_item(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_def_id: DefId,
+ impl_def_id: DefId,
+ ) -> Result<Option<Self>, ErrorReported> {
let attrs = tcx.get_attrs(impl_def_id);
let attr = if let Some(item) = attr::find_by_name(&attrs, sym::rustc_on_unimplemented) {
result
}
- pub fn evaluate(&self,
- tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: ty::TraitRef<'tcx>,
- options: &[(Symbol, Option<String>)])
- -> OnUnimplementedNote
- {
+ pub fn evaluate(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_ref: ty::TraitRef<'tcx>,
+ options: &[(Symbol, Option<String>)],
+ ) -> OnUnimplementedNote {
let mut message = None;
let mut label = None;
let mut note = None;
}
impl<'gcx, 'tcx> OnUnimplementedFormatString {
- fn try_parse(tcx: TyCtxt<'gcx, 'tcx>,
- trait_def_id: DefId,
- from: LocalInternedString,
- err_sp: Span)
- -> Result<Self, ErrorReported>
- {
+ fn try_parse(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_def_id: DefId,
+ from: LocalInternedString,
+ err_sp: Span,
+ ) -> Result<Self, ErrorReported> {
let result = OnUnimplementedFormatString(from);
result.verify(tcx, trait_def_id, err_sp)?;
Ok(result)
}
impl<'tcx> DropckOutlivesResult<'tcx> {
- pub fn report_overflows(
- &self,
- tcx: TyCtxt<'_, 'tcx>,
- span: Span,
- ty: Ty<'tcx>,
- ) {
+ pub fn report_overflows(&self, tcx: TyCtxt<'_, 'tcx>, span: Span, ty: Ty<'tcx>) {
if let Some(overflow_ty) = self.overflows.iter().next() {
let mut err = struct_span_err!(
tcx.sess,
/// Specialization is determined by the sets of types to which the impls apply;
/// `impl1` specializes `impl2` if it applies to a subset of the types `impl2` applies
/// to.
-pub(super) fn specializes<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- (impl1_def_id, impl2_def_id): (DefId, DefId))
- -> bool
-{
+pub(super) fn specializes<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ (impl1_def_id, impl2_def_id): (DefId, DefId),
+) -> bool {
debug!("specializes({:?}, {:?})", impl1_def_id, impl2_def_id);
// The feature gate should prevent introducing new specializations, but not
impl<'gcx, 'tcx> Children {
/// Insert an impl into this set of children without comparing to any existing impls.
- fn insert_blindly(&mut self,
- tcx: TyCtxt<'gcx, 'tcx>,
- impl_def_id: DefId) {
+ fn insert_blindly(&mut self, tcx: TyCtxt<'gcx, 'tcx>, impl_def_id: DefId) {
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) {
debug!("insert_blindly: impl_def_id={:?} sty={:?}", impl_def_id, sty);
/// Removes an impl from this set of children. Used when replacing
/// an impl with a parent. The impl must be present in the list of
/// children already.
- fn remove_existing(&mut self,
- tcx: TyCtxt<'gcx, 'tcx>,
- impl_def_id: DefId) {
+ fn remove_existing(&mut self, tcx: TyCtxt<'gcx, 'tcx>, impl_def_id: DefId) {
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let vec: &mut Vec<DefId>;
if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) {
/// Attempt to insert an impl into this set of children, while comparing for
/// specialization relationships.
- fn insert(&mut self,
- tcx: TyCtxt<'gcx, 'tcx>,
- impl_def_id: DefId,
- simplified_self: Option<SimplifiedType>)
- -> Result<Inserted, OverlapError>
- {
+ fn insert(
+ &mut self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ impl_def_id: DefId,
+ simplified_self: Option<SimplifiedType>,
+ ) -> Result<Inserted, OverlapError> {
let mut last_lint = None;
let mut replace_children = Vec::new();
/// Insert a local impl into the specialization graph. If an existing impl
/// conflicts with it (has overlap, but neither specializes the other),
/// information about the area of overlap is returned in the `Err`.
- pub fn insert(&mut self,
- tcx: TyCtxt<'gcx, 'tcx>,
- impl_def_id: DefId)
- -> Result<Option<FutureCompatOverlapError>, OverlapError> {
+ pub fn insert(
+ &mut self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ impl_def_id: DefId,
+ ) -> Result<Option<FutureCompatOverlapError>, OverlapError> {
assert!(impl_def_id.is_local());
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
}
/// Insert cached metadata mapping from a child impl back to its parent.
- pub fn record_impl_from_cstore(&mut self,
- tcx: TyCtxt<'gcx, 'tcx>,
- parent: DefId,
- child: DefId) {
+ pub fn record_impl_from_cstore(
+ &mut self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ parent: DefId,
+ child: DefId,
+ ) {
if self.parent.insert(child, parent).is_some() {
bug!("When recording an impl from the crate store, information about its parent \
was already present.");
}
/// Iterate over the items defined directly by the given (impl or trait) node.
- pub fn items(
- &self,
- tcx: TyCtxt<'gcx, 'tcx>,
- ) -> ty::AssocItemsIterator<'gcx, 'tcx> {
+ pub fn items(&self, tcx: TyCtxt<'gcx, 'tcx>) -> ty::AssocItemsIterator<'gcx, 'tcx> {
tcx.associated_items(self.def_id())
}
/// Walk up the specialization ancestors of a given impl, starting with that
/// impl itself.
-pub fn ancestors(tcx: TyCtxt<'tcx, '_>,
- trait_def_id: DefId,
- start_from_impl: DefId)
- -> Ancestors<'tcx> {
+pub fn ancestors(
+ tcx: TyCtxt<'tcx, '_>,
+ trait_def_id: DefId,
+ start_from_impl: DefId,
+) -> Ancestors<'tcx> {
let specialization_graph = tcx.specialization_graph_of(trait_def_id);
Ancestors {
trait_def_id,
use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized};
-fn anonymize_predicate<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- pred: &ty::Predicate<'tcx>)
- -> ty::Predicate<'tcx> {
+fn anonymize_predicate<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ pred: &ty::Predicate<'tcx>,
+) -> ty::Predicate<'tcx> {
match *pred {
ty::Predicate::Trait(ref data) =>
ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data)),
pub fn elaborate_trait_ref<'gcx, 'tcx>(
tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: ty::PolyTraitRef<'tcx>)
- -> Elaborator<'gcx, 'tcx>
-{
+ trait_ref: ty::PolyTraitRef<'tcx>,
+) -> Elaborator<'gcx, 'tcx> {
elaborate_predicates(tcx, vec![trait_ref.to_predicate()])
}
pub fn elaborate_trait_refs<'gcx, 'tcx>(
tcx: TyCtxt<'gcx, 'tcx>,
- trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
- -> Elaborator<'gcx, 'tcx>
-{
+ trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
+) -> Elaborator<'gcx, 'tcx> {
let predicates = trait_refs.map(|trait_ref| trait_ref.to_predicate()).collect();
elaborate_predicates(tcx, predicates)
}
pub fn elaborate_predicates<'gcx, 'tcx>(
tcx: TyCtxt<'gcx, 'tcx>,
- mut predicates: Vec<ty::Predicate<'tcx>>)
- -> Elaborator<'gcx, 'tcx>
-{
+ mut predicates: Vec<ty::Predicate<'tcx>>,
+) -> Elaborator<'gcx, 'tcx> {
let mut visited = PredicateSet::new(tcx);
predicates.retain(|pred| visited.insert(pred));
Elaborator { stack: predicates, visited }
pub type Supertraits<'gcx, 'tcx> = FilterToTraits<Elaborator<'gcx, 'tcx>>;
-pub fn supertraits<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: ty::PolyTraitRef<'tcx>)
- -> Supertraits<'gcx, 'tcx> {
+pub fn supertraits<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_ref: ty::PolyTraitRef<'tcx>,
+) -> Supertraits<'gcx, 'tcx> {
elaborate_trait_ref(tcx, trait_ref).filter_to_traits()
}
-pub fn transitive_bounds<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
- -> Supertraits<'gcx, 'tcx> {
+pub fn transitive_bounds<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
+) -> Supertraits<'gcx, 'tcx> {
elaborate_trait_refs(tcx, bounds).filter_to_traits()
}
pub fn expand_trait_aliases<'gcx, 'tcx>(
tcx: TyCtxt<'gcx, 'tcx>,
- trait_refs: impl IntoIterator<Item = (ty::PolyTraitRef<'tcx>, Span)>
+ trait_refs: impl IntoIterator<Item = (ty::PolyTraitRef<'tcx>, Span)>,
) -> TraitAliasExpander<'gcx, 'tcx> {
let items: Vec<_> = trait_refs
.into_iter()
visited: FxHashSet<DefId>,
}
-pub fn supertrait_def_ids<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- trait_def_id: DefId)
- -> SupertraitDefIds<'gcx, 'tcx>
-{
+pub fn supertrait_def_ids<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_def_id: DefId,
+) -> SupertraitDefIds<'gcx, 'tcx> {
SupertraitDefIds {
tcx,
stack: vec![trait_def_id],
/// important thing about the result is Ok/Err. Also, matching never
/// affects any type variables or unification state.
pub struct Match<'gcx, 'tcx> {
- tcx: TyCtxt<'gcx, 'tcx>
+ tcx: TyCtxt<'gcx, 'tcx>,
}
impl Match<'gcx, 'tcx> {
}
impl<'gcx, 'tcx> OverloadedDeref<'tcx> {
- pub fn method_call(&self, tcx: TyCtxt<'gcx, 'tcx>, source: Ty<'tcx>)
- -> (DefId, SubstsRef<'tcx>) {
+ pub fn method_call(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ source: Ty<'tcx>,
+ ) -> (DefId, SubstsRef<'tcx>) {
let trait_def_id = match self.mutbl {
hir::MutImmutable => tcx.lang_items().deref_trait(),
hir::MutMutable => tcx.lang_items().deref_mut_trait()
#[inline]
pub fn decode_arena_allocable<D, T: ArenaAllocatable + Decodable>(
- decoder: &mut D
+ decoder: &mut D,
) -> Result<&'tcx T, D::Error>
- where D: TyDecoder<'tcx>,
+where
+ D: TyDecoder<'tcx>,
{
Ok(decoder.tcx().arena.alloc(Decodable::decode(decoder)?))
}
#[inline]
pub fn decode_arena_allocable_slice<D, T: ArenaAllocatable + Decodable>(
- decoder: &mut D
+ decoder: &mut D,
) -> Result<&'tcx [T], D::Error>
- where D: TyDecoder<'tcx>,
+where
+ D: TyDecoder<'tcx>,
{
Ok(decoder.tcx().arena.alloc_from_iter(<Vec<T> as Decodable>::decode(decoder)?))
}
#[inline]
pub fn decode_cnum<D>(decoder: &mut D) -> Result<CrateNum, D::Error>
- where D: TyDecoder<'tcx>,
+where
+ D: TyDecoder<'tcx>,
{
let cnum = CrateNum::from_u32(u32::decode(decoder)?);
Ok(decoder.map_encoded_cnum_to_current(cnum))
#[inline]
pub fn decode_ty<D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error>
- where D: TyDecoder<'tcx>,
+where
+ D: TyDecoder<'tcx>,
{
// Handle shorthands first, if we have an usize > 0x80.
if decoder.positioned_at_shorthand() {
}
#[inline]
-pub fn decode_predicates<D>(decoder: &mut D)
- -> Result<ty::GenericPredicates<'tcx>, D::Error>
- where D: TyDecoder<'tcx>,
+pub fn decode_predicates<D>(decoder: &mut D) -> Result<ty::GenericPredicates<'tcx>, D::Error>
+where
+ D: TyDecoder<'tcx>,
{
Ok(ty::GenericPredicates {
parent: Decodable::decode(decoder)?,
#[inline]
pub fn decode_substs<D>(decoder: &mut D) -> Result<SubstsRef<'tcx>, D::Error>
- where D: TyDecoder<'tcx>,
+where
+ D: TyDecoder<'tcx>,
{
let len = decoder.read_usize()?;
let tcx = decoder.tcx();
#[inline]
pub fn decode_region<D>(decoder: &mut D) -> Result<ty::Region<'tcx>, D::Error>
- where D: TyDecoder<'tcx>,
+where
+ D: TyDecoder<'tcx>,
{
Ok(decoder.tcx().mk_region(Decodable::decode(decoder)?))
}
#[inline]
-pub fn decode_ty_slice<D>(decoder: &mut D)
- -> Result<&'tcx ty::List<Ty<'tcx>>, D::Error>
- where D: TyDecoder<'tcx>,
+pub fn decode_ty_slice<D>(decoder: &mut D) -> Result<&'tcx ty::List<Ty<'tcx>>, D::Error>
+where
+ D: TyDecoder<'tcx>,
{
let len = decoder.read_usize()?;
Ok(decoder.tcx().mk_type_list((0..len).map(|_| Decodable::decode(decoder)))?)
}
#[inline]
-pub fn decode_adt_def<D>(decoder: &mut D)
- -> Result<&'tcx ty::AdtDef, D::Error>
- where D: TyDecoder<'tcx>,
+pub fn decode_adt_def<D>(decoder: &mut D) -> Result<&'tcx ty::AdtDef, D::Error>
+where
+ D: TyDecoder<'tcx>,
{
let def_id = DefId::decode(decoder)?;
Ok(decoder.tcx().adt_def(def_id))
}
#[inline]
-pub fn decode_existential_predicate_slice<D>(decoder: &mut D)
- -> Result<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>, D::Error>
- where D: TyDecoder<'tcx>,
+pub fn decode_existential_predicate_slice<D>(
+ decoder: &mut D,
+) -> Result<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>, D::Error>
+where
+ D: TyDecoder<'tcx>,
{
let len = decoder.read_usize()?;
Ok(decoder.tcx()
}
#[inline]
-pub fn decode_canonical_var_infos<D>(decoder: &mut D)
- -> Result<CanonicalVarInfos<'tcx>, D::Error>
- where D: TyDecoder<'tcx>,
+pub fn decode_canonical_var_infos<D>(decoder: &mut D) -> Result<CanonicalVarInfos<'tcx>, D::Error>
+where
+ D: TyDecoder<'tcx>,
{
let len = decoder.read_usize()?;
let interned: Result<Vec<CanonicalVarInfo>, _> = (0..len).map(|_| Decodable::decode(decoder))
}
#[inline]
-pub fn decode_const<D>(decoder: &mut D)
- -> Result<&'tcx ty::Const<'tcx>, D::Error>
- where D: TyDecoder<'tcx>,
+pub fn decode_const<D>(decoder: &mut D) -> Result<&'tcx ty::Const<'tcx>, D::Error>
+where
+ D: TyDecoder<'tcx>,
{
Ok(decoder.tcx().mk_const(Decodable::decode(decoder)?))
}
#[inline]
-pub fn decode_allocation<D>(decoder: &mut D)
- -> Result<&'tcx Allocation, D::Error>
- where D: TyDecoder<'tcx>,
+pub fn decode_allocation<D>(decoder: &mut D) -> Result<&'tcx Allocation, D::Error>
+where
+ D: TyDecoder<'tcx>,
{
Ok(decoder.tcx().intern_const_alloc(Decodable::decode(decoder)?))
}
/// Call the closure with a local `TyCtxt` using the given arena.
/// `interners` is a slot passed so we can create a CtxtInterners
/// with the same lifetime as `arena`.
- pub fn enter_local<'tcx, F, R>(
- &'gcx self,
- f: F
- ) -> R
+ pub fn enter_local<'tcx, F, R>(&'gcx self, f: F) -> R
where
F: FnOnce(TyCtxt<'gcx, 'tcx>) -> R,
'gcx: 'tcx,
macro_rules! nop_lift {
($ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<'tcx> for $ty {
- type Lifted = $lifted;
- fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<Self::Lifted> {
- if tcx.interners.arena.in_arena(*self as *const _) {
- return Some(unsafe { mem::transmute(*self) });
- }
- // Also try in the global tcx if we're not that.
- if !tcx.is_global() {
- self.lift_to_tcx(tcx.global_tcx())
- } else {
- None
+ type Lifted = $lifted;
+ fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<Self::Lifted> {
+ if tcx.interners.arena.in_arena(*self as *const _) {
+ return Some(unsafe { mem::transmute(*self) });
+ }
+ // Also try in the global tcx if we're not that.
+ if !tcx.is_global() {
+ self.lift_to_tcx(tcx.global_tcx())
+ } else {
+ None
+ }
+ }
}
- }
- }
};
}
macro_rules! nop_list_lift {
($ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
- type Lifted = &'tcx List<$lifted>;
- fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<Self::Lifted> {
- if self.is_empty() {
- return Some(List::empty());
- }
- if tcx.interners.arena.in_arena(*self as *const _) {
- return Some(unsafe { mem::transmute(*self) });
- }
- // Also try in the global tcx if we're not that.
- if !tcx.is_global() {
- self.lift_to_tcx(tcx.global_tcx())
- } else {
- None
+ type Lifted = &'tcx List<$lifted>;
+ fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<Self::Lifted> {
+ if self.is_empty() {
+ return Some(List::empty());
+ }
+ if tcx.interners.arena.in_arena(*self as *const _) {
+ return Some(unsafe { mem::transmute(*self) });
+ }
+ // Also try in the global tcx if we're not that.
+ if !tcx.is_global() {
+ self.lift_to_tcx(tcx.global_tcx())
+ } else {
+ None
+ }
+ }
}
- }
- }
};
}
/// This happens once per rustc session and TyCtxts only exists
/// inside the `f` function.
pub fn enter_global<'gcx, F, R>(gcx: &'gcx GlobalCtxt<'gcx>, f: F) -> R
- where F: FnOnce(TyCtxt<'gcx, 'gcx>) -> R
+ where
+ F: FnOnce(TyCtxt<'gcx, 'gcx>) -> R,
{
// Update GCX_PTR to indicate there's a GlobalCtxt available
GCX_PTR.with(|lock| {
/// Creates a TyCtxt and ImplicitCtxt based on the GCX_PTR thread local.
/// This is used in the deadlock handler.
pub unsafe fn with_global<F, R>(f: F) -> R
- where F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R
+ where
+ F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R,
{
let gcx = GCX_PTR.with(|lock| *lock.lock());
assert!(gcx != 0);
/// the current ImplicitCtxt's tcx field.
#[inline]
pub fn with_related_context<'gcx, 'tcx1, F, R>(tcx: TyCtxt<'gcx, 'tcx1>, f: F) -> R
- where F: for<'b, 'tcx2> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx2>) -> R
+ where
+ F: for<'b, 'tcx2> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx2>) -> R,
{
with_context(|context| {
unsafe {
/// a different local interner from the current ImplicitCtxt's tcx field.
#[inline]
pub fn with_fully_related_context<'gcx, 'tcx, F, R>(tcx: TyCtxt<'gcx, 'tcx>, f: F) -> R
- where F: for<'b> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx>) -> R
+ where
+ F: for<'b> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx>) -> R,
{
with_context(|context| {
unsafe {
/// Panics if there is no ImplicitCtxt available
#[inline]
pub fn with<F, R>(f: F) -> R
- where F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R
+ where
+ F: for<'gcx, 'tcx> FnOnce(TyCtxt<'gcx, 'tcx>) -> R,
{
with_context(|context| f(context.tcx))
}
/// The closure is passed None if there is no ImplicitCtxt available
#[inline]
pub fn with_opt<F, R>(f: F) -> R
- where F: for<'gcx, 'tcx> FnOnce(Option<TyCtxt<'gcx, 'tcx>>) -> R
+ where
+ F: for<'gcx, 'tcx> FnOnce(Option<TyCtxt<'gcx, 'tcx>>) -> R,
{
with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx)))
}
/// then we can't say much about whether two types would unify. Put another way,
/// `can_simplify_params` should be true if type parameters appear free in `ty` and `false` if they
/// are to be considered bound.
-pub fn simplify_type<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- ty: Ty<'_>,
- can_simplify_params: bool)
- -> Option<SimplifiedType>
-{
+pub fn simplify_type<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ty: Ty<'_>,
+ can_simplify_params: bool,
+) -> Option<SimplifiedType> {
match ty.sty {
ty::Bool => Some(BoolSimplifiedType),
ty::Char => Some(CharSimplifiedType),
/// default implementation that does an "identity" fold. Within each
/// identity fold, it should invoke `foo.fold_with(self)` to fold each
/// sub-item.
-pub trait TypeFolder<'gcx: 'tcx, 'tcx> : Sized {
+pub trait TypeFolder<'gcx: 'tcx, 'tcx>: Sized {
fn tcx<'a>(&'a self) -> TyCtxt<'gcx, 'tcx>;
fn fold_binder<T>(&mut self, t: &Binder<T>) -> Binder<T>
// Some sample folders
pub struct BottomUpFolder<'gcx, 'tcx, F, G, H>
- where F: FnMut(Ty<'tcx>) -> Ty<'tcx>,
- G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>,
- H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>,
+where
+ F: FnMut(Ty<'tcx>) -> Ty<'tcx>,
+ G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>,
+ H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>,
{
pub tcx: TyCtxt<'gcx, 'tcx>,
pub ty_op: F,
}
impl<'gcx, 'tcx, F, G, H> TypeFolder<'gcx, 'tcx> for BottomUpFolder<'gcx, 'tcx, F, G, H>
- where F: FnMut(Ty<'tcx>) -> Ty<'tcx>,
- G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>,
- H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>,
+where
+ F: FnMut(Ty<'tcx>) -> Ty<'tcx>,
+ G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>,
+ H: FnMut(&'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx>,
{
- fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx }
+ fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> {
+ self.tcx
+ }
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
let t = ty.super_fold_with(self);
/// visited by this folder; only regions that occur free will be
/// visited by `fld_r`.
-pub struct RegionFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
+pub struct RegionFolder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
tcx: TyCtxt<'gcx, 'tcx>,
skipped_regions: &'a mut bool,
/// Callback invokes for each free region. The `DebruijnIndex`
/// points to the binder *just outside* the ones we have passed
/// through.
- fold_region_fn: &'a mut (dyn FnMut(
- ty::Region<'tcx>,
- ty::DebruijnIndex,
- ) -> ty::Region<'tcx> + 'a),
+ fold_region_fn:
+ &'a mut (dyn FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx> + 'a),
}
impl<'a, 'gcx, 'tcx> RegionFolder<'a, 'gcx, 'tcx> {
}
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFolder<'a, 'gcx, 'tcx> {
- fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx }
+ fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> {
+ self.tcx
+ }
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
self.current_index.shift_in(1);
fld_t: &'a mut G,
fld_c: &'a mut H,
) -> Self
- where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
- G: FnMut(ty::BoundTy) -> Ty<'tcx>,
- H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>,
+ where
+ F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
+ G: FnMut(ty::BoundTy) -> Ty<'tcx>,
+ H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>,
{
BoundVarReplacer {
tcx,
}
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for BoundVarReplacer<'a, 'gcx, 'tcx> {
- fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx }
+ fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> {
+ self.tcx
+ }
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
self.current_index.shift_in(1);
}
impl TypeFolder<'gcx, 'tcx> for Shifter<'gcx, 'tcx> {
- fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx }
+ fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> {
+ self.tcx
+ }
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
self.current_index.shift_in(1);
pub fn shift_region<'gcx, 'tcx>(
tcx: TyCtxt<'gcx, 'tcx>,
region: ty::Region<'tcx>,
- amount: u32
+ amount: u32,
) -> ty::Region<'tcx> {
match region {
ty::ReLateBound(debruijn, br) if amount > 0 => {
}
}
-pub fn shift_vars<'gcx, 'tcx, T>(
- tcx: TyCtxt<'gcx, 'tcx>,
- value: &T,
- amount: u32
-) -> T where T: TypeFoldable<'tcx> {
+pub fn shift_vars<'gcx, 'tcx, T>(tcx: TyCtxt<'gcx, 'tcx>, value: &T, amount: u32) -> T
+where
+ T: TypeFoldable<'tcx>,
+{
debug!("shift_vars(value={:?}, amount={})",
value, amount);
value.fold_with(&mut Shifter::new(tcx, amount, Direction::In))
}
-pub fn shift_out_vars<'gcx, 'tcx, T>(
- tcx: TyCtxt<'gcx, 'tcx>,
- value: &T,
- amount: u32
-) -> T where T: TypeFoldable<'tcx> {
+pub fn shift_out_vars<'gcx, 'tcx, T>(tcx: TyCtxt<'gcx, 'tcx>, value: &T, amount: u32) -> T
+where
+ T: TypeFoldable<'tcx>,
+{
debug!("shift_out_vars(value={:?}, amount={})",
value, amount);
}
/// Tests whether the forest contains a given DefId.
- pub fn contains(&self,
- tcx: TyCtxt<'gcx, 'tcx>,
- id: DefId) -> bool
- {
+ pub fn contains(&self, tcx: TyCtxt<'gcx, 'tcx>, id: DefId) -> bool {
self.root_ids.iter().any(|root_id| tcx.is_descendant_of(id, *root_id))
}
/// Calculate the intersection of a collection of forests.
- pub fn intersection<I>(tcx: TyCtxt<'gcx, 'tcx>,
- iter: I) -> DefIdForest
- where I: IntoIterator<Item=DefIdForest>
+ pub fn intersection<I>(tcx: TyCtxt<'gcx, 'tcx>, iter: I) -> DefIdForest
+ where
+ I: IntoIterator<Item = DefIdForest>,
{
let mut iter = iter.into_iter();
let mut ret = if let Some(first) = iter.next() {
}
/// Calculate the union of a collection of forests.
- pub fn union<I>(tcx: TyCtxt<'gcx, 'tcx>,
- iter: I) -> DefIdForest
- where I: IntoIterator<Item=DefIdForest>
+ pub fn union<I>(tcx: TyCtxt<'gcx, 'tcx>, iter: I) -> DefIdForest
+ where
+ I: IntoIterator<Item = DefIdForest>,
{
let mut ret = DefIdForest::empty();
let mut next_ret = SmallVec::new();
impl<'gcx, 'tcx> AdtDef {
/// Calculate the forest of DefIds from which this adt is visibly uninhabited.
- fn uninhabited_from(
- &self,
- tcx: TyCtxt<'gcx, 'tcx>,
- substs: SubstsRef<'tcx>) -> DefIdForest
- {
+ fn uninhabited_from(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: SubstsRef<'tcx>) -> DefIdForest {
// Non-exhaustive ADTs from other crates are always considered inhabited.
if self.is_variant_list_non_exhaustive() && !self.did.is_local() {
DefIdForest::empty()
&self,
tcx: TyCtxt<'gcx, 'tcx>,
substs: SubstsRef<'tcx>,
- adt_kind: AdtKind) -> DefIdForest
- {
+ adt_kind: AdtKind,
+ ) -> DefIdForest {
let is_enum = match adt_kind {
// For now, `union`s are never considered uninhabited.
// The precise semantics of inhabitedness with respect to unions is currently undecided.
impl<'gcx, 'tcx> TyS<'tcx> {
/// Calculate the forest of DefIds from which this type is visibly uninhabited.
- fn uninhabited_from(&self, tcx: TyCtxt<'gcx, 'tcx>) -> DefIdForest
- {
+ fn uninhabited_from(&self, tcx: TyCtxt<'gcx, 'tcx>) -> DefIdForest {
match self.sty {
Adt(def, substs) => def.uninhabited_from(tcx, substs),
}
impl<'tcx> Instance<'tcx> {
- pub fn ty(&self,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> Ty<'tcx>
- {
+ pub fn ty(&self, tcx: TyCtxt<'tcx, 'tcx>) -> Ty<'tcx> {
let ty = tcx.type_of(self.def.def_id());
tcx.subst_and_normalize_erasing_regions(
self.substs,
tcx.get_attrs(self.def_id())
}
- pub fn is_inline(
- &self,
- tcx: TyCtxt<'tcx, 'tcx>
- ) -> bool {
+ pub fn is_inline(&self, tcx: TyCtxt<'tcx, 'tcx>) -> bool {
use crate::hir::map::DefPathData;
let def_id = match *self {
ty::InstanceDef::Item(def_id) => def_id,
}
}
- pub fn requires_local(
- &self,
- tcx: TyCtxt<'tcx, 'tcx>
- ) -> bool {
+ pub fn requires_local(&self, tcx: TyCtxt<'tcx, 'tcx>) -> bool {
if self.is_inline(tcx) {
return true
}
/// Presuming that coherence and type-check have succeeded, if this method is invoked
/// in a monomorphic context (i.e., like during codegen), then it is guaranteed to return
/// `Some`.
- pub fn resolve(tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- def_id: DefId,
- substs: SubstsRef<'tcx>) -> Option<Instance<'tcx>> {
+ pub fn resolve(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ def_id: DefId,
+ substs: SubstsRef<'tcx>,
+ ) -> Option<Instance<'tcx>> {
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env);
result
}
- pub fn resolve_for_vtable(tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- def_id: DefId,
- substs: SubstsRef<'tcx>) -> Option<Instance<'tcx>> {
+ pub fn resolve_for_vtable(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ def_id: DefId,
+ substs: SubstsRef<'tcx>,
+ ) -> Option<Instance<'tcx>> {
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
let fn_sig = tcx.fn_sig(def_id);
let is_vtable_shim =
tcx: TyCtxt<'tcx, 'tcx>,
def_id: DefId,
substs: ty::ClosureSubsts<'tcx>,
- requested_kind: ty::ClosureKind)
- -> Instance<'tcx>
- {
+ requested_kind: ty::ClosureKind,
+ ) -> Instance<'tcx> {
let actual_kind = substs.closure_kind(def_id, tcx);
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
}
}
- pub fn resolve_drop_in_place(
- tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>)
- -> ty::Instance<'tcx>
- {
+ pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
let def_id = tcx.require_lang_item(DropInPlaceFnLangItem);
let substs = tcx.intern_substs(&[ty.into()]);
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap()
pub fn fn_once_adapter_instance(
tcx: TyCtxt<'tcx, 'tcx>,
closure_did: DefId,
- substs: ty::ClosureSubsts<'tcx>)
- -> Instance<'tcx>
- {
+ substs: ty::ClosureSubsts<'tcx>,
+ ) -> Instance<'tcx> {
debug!("fn_once_adapter_shim({:?}, {:?})",
closure_did,
substs);
ArgAttribute, ArgAttributes, ArgType, Conv, FnType, IgnoreMode, PassMode, Reg, RegKind
};
-
-
pub trait IntegerExt {
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, signed: bool) -> Ty<'tcx>;
fn from_attr<C: HasDataLayout>(cx: &C, ity: attr::IntType) -> Integer;
- fn repr_discr<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>,
- repr: &ReprOptions,
- min: i128,
- max: i128)
- -> (Integer, bool);
+ fn repr_discr<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ty: Ty<'tcx>,
+ repr: &ReprOptions,
+ min: i128,
+ max: i128,
+ ) -> (Integer, bool);
}
impl IntegerExt for Integer {
/// signed discriminant range and #[repr] attribute.
/// N.B.: u128 values above i128::MAX will be treated as signed, but
/// that shouldn't affect anything, other than maybe debuginfo.
- fn repr_discr<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>,
- repr: &ReprOptions,
- min: i128,
- max: i128)
- -> (Integer, bool) {
+ fn repr_discr<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ty: Ty<'tcx>,
+ repr: &ReprOptions,
+ min: i128,
+ max: i128,
+ ) -> (Integer, bool) {
// Theoretically, negative values could be larger in unsigned representation
// than the unsigned representation of the signed minimum. However, if there
// are any negative values, the only valid unsigned representation is u128
}
}
-fn layout_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
- -> Result<&'tcx LayoutDetails, LayoutError<'tcx>>
-{
+fn layout_raw<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
+) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
ty::tls::with_related_context(tcx, move |icx| {
let rec_limit = *tcx.sess.recursion_limit.get();
let (param_env, ty) = query.into_parts();
}
impl<'tcx> SizeSkeleton<'tcx> {
- pub fn compute(ty: Ty<'tcx>,
- tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>)
- -> Result<SizeSkeleton<'tcx>, LayoutError<'tcx>> {
+ pub fn compute(
+ ty: Ty<'tcx>,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ ) -> Result<SizeSkeleton<'tcx>, LayoutError<'tcx>> {
debug_assert!(!ty.has_infer_types());
// First try computing a static layout.
false
}
- pub fn region_param(&'tcx self,
- param: &EarlyBoundRegion,
- tcx: TyCtxt<'gcx, 'tcx>)
- -> &'tcx GenericParamDef
- {
+ pub fn region_param(
+ &'tcx self,
+ param: &EarlyBoundRegion,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ) -> &'tcx GenericParamDef {
if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
let param = &self.params[index as usize];
match param.kind {
}
/// Returns the `GenericParamDef` associated with this `ParamTy`.
- pub fn type_param(&'tcx self,
- param: &ParamTy,
- tcx: TyCtxt<'gcx, 'tcx>)
- -> &'tcx GenericParamDef {
+ pub fn type_param(
+ &'tcx self,
+ param: &ParamTy,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ) -> &'tcx GenericParamDef {
if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
let param = &self.params[index as usize];
match param.kind {
}
/// Returns the `ConstParameterDef` associated with this `ParamConst`.
- pub fn const_param(&'tcx self,
- param: &ParamConst,
- tcx: TyCtxt<'gcx, 'tcx>)
- -> &GenericParamDef {
+ pub fn const_param(
+ &'tcx self,
+ param: &ParamConst,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ) -> &GenericParamDef {
if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
let param = &self.params[index as usize];
match param.kind {
impl<'tcx> serialize::UseSpecializedDecodable for GenericPredicates<'tcx> {}
impl<'gcx, 'tcx> GenericPredicates<'tcx> {
- pub fn instantiate(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: SubstsRef<'tcx>)
- -> InstantiatedPredicates<'tcx> {
+ pub fn instantiate(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ substs: SubstsRef<'tcx>,
+ ) -> InstantiatedPredicates<'tcx> {
let mut instantiated = InstantiatedPredicates::empty();
self.instantiate_into(tcx, &mut instantiated, substs);
instantiated
}
- pub fn instantiate_own(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: SubstsRef<'tcx>)
- -> InstantiatedPredicates<'tcx> {
+ pub fn instantiate_own(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ substs: SubstsRef<'tcx>,
+ ) -> InstantiatedPredicates<'tcx> {
InstantiatedPredicates {
predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(),
}
}
- fn instantiate_into(&self, tcx: TyCtxt<'gcx, 'tcx>,
- instantiated: &mut InstantiatedPredicates<'tcx>,
- substs: SubstsRef<'tcx>) {
+ fn instantiate_into(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ instantiated: &mut InstantiatedPredicates<'tcx>,
+ substs: SubstsRef<'tcx>,
+ ) {
if let Some(def_id) = self.parent {
tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs);
}
);
}
- pub fn instantiate_identity(&self, tcx: TyCtxt<'gcx, 'tcx>)
- -> InstantiatedPredicates<'tcx> {
+ pub fn instantiate_identity(&self, tcx: TyCtxt<'gcx, 'tcx>) -> InstantiatedPredicates<'tcx> {
let mut instantiated = InstantiatedPredicates::empty();
self.instantiate_identity_into(tcx, &mut instantiated);
instantiated
}
- fn instantiate_identity_into(&self, tcx: TyCtxt<'gcx, 'tcx>,
- instantiated: &mut InstantiatedPredicates<'tcx>) {
+ fn instantiate_identity_into(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ instantiated: &mut InstantiatedPredicates<'tcx>,
+ ) {
if let Some(def_id) = self.parent {
tcx.predicates_of(def_id).instantiate_identity_into(tcx, instantiated);
}
instantiated.predicates.extend(self.predicates.iter().map(|&(p, _)| p))
}
- pub fn instantiate_supertrait(&self, tcx: TyCtxt<'gcx, 'tcx>,
- poly_trait_ref: &ty::PolyTraitRef<'tcx>)
- -> InstantiatedPredicates<'tcx>
- {
+ pub fn instantiate_supertrait(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ poly_trait_ref: &ty::PolyTraitRef<'tcx>,
+ ) -> InstantiatedPredicates<'tcx> {
assert_eq!(self.parent, None);
InstantiatedPredicates {
predicates: self.predicates.iter().map(|(pred, _)| {
/// poly-trait-ref holds. This is slightly different from a normal
/// substitution in terms of what happens with bound regions. See
/// lengthy comment below for details.
- pub fn subst_supertrait(&self, tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: &ty::PolyTraitRef<'tcx>)
- -> ty::Predicate<'tcx>
- {
+ pub fn subst_supertrait(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_ref: &ty::PolyTraitRef<'tcx>,
+ ) -> ty::Predicate<'tcx> {
// The interaction between HRTB and supertraits is not entirely
// obvious. Let me walk you (and myself) through an example.
//
pub fn inhibit_union_abi_opt(&self) -> bool {
self.c()
}
-
}
impl<'gcx, 'tcx> AdtDef {
did: DefId,
kind: AdtKind,
variants: IndexVec<VariantIdx, VariantDef>,
- repr: ReprOptions
+ repr: ReprOptions,
) -> Self {
debug!("AdtDef::new({:?}, {:?}, {:?}, {:?})", did, kind, variants, repr);
let mut flags = AdtFlags::NO_ADT_FLAGS;
/// discriminant (the last one before the requested variant),
/// assuming there are no constant-evaluation errors there.
#[inline]
- pub fn discriminant_for_variant(&self,
- tcx: TyCtxt<'gcx, 'tcx>,
- variant_index: VariantIdx)
- -> Discr<'tcx> {
+ pub fn discriminant_for_variant(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ variant_index: VariantIdx,
+ ) -> Discr<'tcx> {
let (val, offset) = self.discriminant_def_for_variant(variant_index);
let explicit_value = val
.and_then(|expr_did| self.eval_explicit_discr(tcx, expr_did))
tcx.adt_sized_constraint(self.did).0
}
- fn sized_constraint_for_ty(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>)
- -> Vec<Ty<'tcx>> {
+ fn sized_constraint_for_ty(&self, tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> Vec<Ty<'tcx>> {
let result = match ty.sty {
Bool | Char | Int(..) | Uint(..) | Float(..) |
RawPtr(..) | Ref(..) | FnDef(..) | FnPtr(_) |
/// Returns an iterator of the `DefId`s for all body-owners in this
/// crate. If you would prefer to iterate over the bodies
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
- pub fn body_owners(
- self,
- ) -> impl Iterator<Item = DefId> + Captures<'gcx> + 'tcx {
+ pub fn body_owners(self) -> impl Iterator<Item = DefId> + Captures<'gcx> + 'tcx {
self.hir().krate()
.body_ids
.iter()
})
}
- pub fn associated_items(
- self,
- def_id: DefId,
- ) -> AssocItemsIterator<'gcx, 'tcx> {
+ pub fn associated_items(self, def_id: DefId) -> AssocItemsIterator<'gcx, 'tcx> {
// Ideally, we would use `-> impl Iterator` here, but it falls
// afoul of the conservative "capture [restrictions]" we put
// in place, so we use a hand-written iterator.
/// such.
/// - a Error, if a type contained itself. The representability
/// check should catch this case.
-fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> AdtSizedConstraint<'tcx> {
+fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> AdtSizedConstraint<'tcx> {
let def = tcx.adt_def(def_id);
let result = tcx.mk_type_list(def.variants.iter().flat_map(|v| {
AdtSizedConstraint(result)
}
-fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> &'tcx [DefId] {
+fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx [DefId] {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item = tcx.hir().expect_item_by_hir_id(id);
match item.node {
}
/// See `ParamEnv` struct definition for details.
-fn param_env<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> ParamEnv<'tcx>
-{
+fn param_env<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> ParamEnv<'tcx> {
// The param_env of an impl Trait type is its defining function's param_env
if let Some(parent) = is_impl_trait_defn(tcx, def_id) {
return param_env(tcx, parent);
traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause)
}
-fn crate_disambiguator<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- crate_num: CrateNum) -> CrateDisambiguator {
+fn crate_disambiguator<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) -> CrateDisambiguator {
assert_eq!(crate_num, LOCAL_CRATE);
tcx.sess.local_crate_disambiguator()
}
-fn original_crate_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- crate_num: CrateNum) -> Symbol {
+fn original_crate_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) -> Symbol {
assert_eq!(crate_num, LOCAL_CRATE);
tcx.crate_name.clone()
}
-fn crate_hash<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- crate_num: CrateNum)
- -> Svh {
+fn crate_hash<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) -> Svh {
assert_eq!(crate_num, LOCAL_CRATE);
tcx.hir().crate_hash
}
-fn instance_def_size_estimate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- instance_def: InstanceDef<'tcx>)
- -> usize {
+fn instance_def_size_estimate<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ instance_def: InstanceDef<'tcx>,
+) -> usize {
match instance_def {
InstanceDef::Item(..) |
InstanceDef::DropGlue(..) => {
/// If `def_id` is an issue 33140 hack impl, returns its self type; otherwise, returns `None`.
///
/// See [`ImplOverlapKind::Issue33140`] for more details.
-fn issue33140_self_ty<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> Option<Ty<'tcx>>
-{
+fn issue33140_self_ty<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option<Ty<'tcx>> {
debug!("issue33140_self_ty({:?})", def_id);
let trait_ref = tcx.impl_trait_ref(def_id).unwrap_or_else(|| {
false
}
- fn try_load_from_disk(_: TyCtxt<'tcx, 'tcx>,
- _: SerializedDepNodeIndex)
- -> Option<Self::Value> {
+ fn try_load_from_disk(_: TyCtxt<'tcx, 'tcx>, _: SerializedDepNodeIndex) -> Option<Self::Value> {
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
}
}
-impl<'tcx, M: QueryAccessors<'tcx, Key=DefId>> QueryDescription<'tcx> for M {
+impl<'tcx, M: QueryAccessors<'tcx, Key = DefId>> QueryDescription<'tcx> for M {
default fn describe(tcx: TyCtxt<'_, '_>, def_id: DefId) -> Cow<'static, str> {
if !tcx.sess.verbose() {
format!("processing `{}`", tcx.def_path_str(def_id)).into()
fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, Lrc<QueryJob<'tcx>>)>(
tcx: TyCtxt<'tcx, '_>,
queries: &'a [T],
- f: F
+ f: F,
) -> &'a T {
// Deterministically pick an entry point
// FIXME: Sort this instead
fn remove_cycle<'tcx>(
jobs: &mut Vec<Lrc<QueryJob<'tcx>>>,
wakelist: &mut Vec<Lrc<QueryWaiter<'tcx>>>,
- tcx: TyCtxt<'tcx, '_>
+ tcx: TyCtxt<'tcx, '_>,
) -> bool {
let mut visited = FxHashSet::default();
let mut stack = Vec::new();
}
}
-impl<'tcx> Key for ty::PolyTraitRef<'tcx>{
+impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
fn query_crate(&self) -> CrateNum {
self.def_id().krate
}
}
}
- pub fn serialize<'tcx, E>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- encoder: &mut E)
- -> Result<(), E::Error>
- where E: ty_codec::TyEncoder
- {
+ pub fn serialize<'tcx, E>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ encoder: &mut E,
+ ) -> Result<(), E::Error>
+ where
+ E: ty_codec::TyEncoder,
+ {
// Serializing the DepGraph should not modify it:
tcx.dep_graph.with_ignore(|| {
// Allocate SourceFileIndices
}
/// Loads a diagnostic emitted during the previous compilation session.
- pub fn load_diagnostics<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- dep_node_index: SerializedDepNodeIndex)
- -> Vec<Diagnostic> {
+ pub fn load_diagnostics<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ dep_node_index: SerializedDepNodeIndex,
+ ) -> Vec<Diagnostic> {
let diagnostics: Option<EncodedDiagnostics> = self.load_indexed(
tcx,
dep_node_index,
/// Returns the cached query result if there is something in the cache for
/// the given `SerializedDepNodeIndex`; otherwise returns `None`.
- pub fn try_load_query_result<'tcx, T>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- dep_node_index: SerializedDepNodeIndex)
- -> Option<T>
- where T: Decodable
+ pub fn try_load_query_result<'tcx, T>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ dep_node_index: SerializedDepNodeIndex,
+ ) -> Option<T>
+ where
+ T: Decodable,
{
self.load_indexed(tcx,
dep_node_index,
x.extend(Into::<Vec<_>>::into(diagnostics));
}
- fn load_indexed<'tcx, T>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- dep_node_index: SerializedDepNodeIndex,
- index: &FxHashMap<SerializedDepNodeIndex,
- AbsoluteBytePos>,
- debug_tag: &'static str)
- -> Option<T>
- where T: Decodable
+ fn load_indexed<'tcx, T>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ dep_node_index: SerializedDepNodeIndex,
+ index: &FxHashMap<SerializedDepNodeIndex, AbsoluteBytePos>,
+ debug_tag: &'static str,
+ ) -> Option<T>
+ where
+ T: Decodable,
{
let pos = index.get(&dep_node_index).cloned()?;
// current-session-CrateNum. There might be CrateNums from the previous
// Session that don't occur in the current one. For these, the mapping
// maps to None.
- fn compute_cnum_map(tcx: TyCtxt<'_, '_>,
- prev_cnums: &[(u32, String, CrateDisambiguator)])
- -> IndexVec<CrateNum, Option<CrateNum>>
- {
+ fn compute_cnum_map(
+ tcx: TyCtxt<'_, '_>,
+ prev_cnums: &[(u32, String, CrateDisambiguator)],
+ ) -> IndexVec<CrateNum, Option<CrateNum>> {
tcx.dep_graph.with_ignore(|| {
let current_cnums = tcx.all_crate_nums(LOCAL_CRATE).iter().map(|&cnum| {
let crate_name = tcx.original_crate_name(cnum)
Ok(value)
}
-
impl<'a, 'tcx> ty_codec::TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx, 'tcx> {
}
}
-implement_ty_decoder!( CacheDecoder<'a, 'tcx> );
+implement_ty_decoder!(CacheDecoder<'a, 'tcx>);
impl<'a, 'tcx> SpecializedDecoder<interpret::AllocId> for CacheDecoder<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<interpret::AllocId, Self::Error> {
}
impl<'a, 'tcx, T: Decodable> SpecializedDecoder<mir::ClearCrossCrate<T>>
-for CacheDecoder<'a, 'tcx> {
+ for CacheDecoder<'a, 'tcx>
+{
#[inline]
fn specialized_decode(&mut self) -> Result<mir::ClearCrossCrate<T>, Self::Error> {
let discr = u8::decode(self)?;
}
impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
fn source_file_index(&mut self, source_file: Lrc<SourceFile>) -> SourceFileIndex {
self.file_to_file_index[&(&*source_file as *const SourceFile)]
}
impl<'a, 'tcx, E> SpecializedEncoder<interpret::AllocId> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
fn specialized_encode(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> {
use std::collections::hash_map::Entry;
}
impl<'a, 'tcx, E> SpecializedEncoder<Span> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> {
}
impl<'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn position(&self) -> usize {
}
impl<'a, 'tcx, E> SpecializedEncoder<CrateNum> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn specialized_encode(&mut self, cnum: &CrateNum) -> Result<(), Self::Error> {
}
impl<'a, 'tcx, E> SpecializedEncoder<Ty<'tcx>> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn specialized_encode(&mut self, ty: &Ty<'tcx>) -> Result<(), Self::Error> {
}
}
-impl<'a, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>>
- for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+impl<'a, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>> for CacheEncoder<'a, 'tcx, E>
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn specialized_encode(&mut self,
}
impl<'a, 'tcx, E> SpecializedEncoder<hir::HirId> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn specialized_encode(&mut self, id: &hir::HirId) -> Result<(), Self::Error> {
}
}
-
impl<'a, 'tcx, E> SpecializedEncoder<DefId> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn specialized_encode(&mut self, id: &DefId) -> Result<(), Self::Error> {
}
impl<'a, 'tcx, E> SpecializedEncoder<LocalDefId> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn specialized_encode(&mut self, id: &LocalDefId) -> Result<(), Self::Error> {
}
impl<'a, 'tcx, E> SpecializedEncoder<DefIndex> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
fn specialized_encode(&mut self, _: &DefIndex) -> Result<(), Self::Error> {
bug!("Encoding DefIndex without context.")
// NodeIds are not stable across compilation sessions, so we store them in their
// HirId representation. This allows use to map them to the current NodeId.
impl<'a, 'tcx, E> SpecializedEncoder<NodeId> for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
#[inline]
fn specialized_encode(&mut self, node_id: &NodeId) -> Result<(), Self::Error> {
}
}
-impl<'a, 'tcx> SpecializedEncoder<Fingerprint>
-for CacheEncoder<'a, 'tcx, opaque::Encoder>
-{
+impl<'a, 'tcx> SpecializedEncoder<Fingerprint> for CacheEncoder<'a, 'tcx, opaque::Encoder> {
fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> {
f.encode_opaque(&mut self.encoder)
}
}
-impl<'a, 'tcx, E, T> SpecializedEncoder<mir::ClearCrossCrate<T>>
-for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder,
- T: Encodable,
+impl<'a, 'tcx, E, T> SpecializedEncoder<mir::ClearCrossCrate<T>> for CacheEncoder<'a, 'tcx, E>
+where
+ E: 'a + ty_codec::TyEncoder,
+ T: Encodable,
{
#[inline]
fn specialized_encode(&mut self,
}
impl<'a, 'tcx, E> Encoder for CacheEncoder<'a, 'tcx, E>
- where E: 'a + ty_codec::TyEncoder
+where
+ E: 'a + ty_codec::TyEncoder,
{
type Error = E::Error;
}
}
-fn encode_query_results<'a, 'tcx, Q, E>(tcx: TyCtxt<'tcx, 'tcx>,
- encoder: &mut CacheEncoder<'a, 'tcx, E>,
- query_result_index: &mut EncodedQueryResultIndex)
- -> Result<(), E::Error>
- where Q: super::config::QueryDescription<'tcx>,
- E: 'a + TyEncoder,
- Q::Value: Encodable,
+fn encode_query_results<'a, 'tcx, Q, E>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ encoder: &mut CacheEncoder<'a, 'tcx, E>,
+ query_result_index: &mut EncodedQueryResultIndex,
+) -> Result<(), E::Error>
+where
+ Q: super::config::QueryDescription<'tcx>,
+ E: 'a + TyEncoder,
+ Q::Value: Encodable,
{
let desc = &format!("encode_query_results for {}",
unsafe { ::std::intrinsics::type_name::<Q>() });
self,
job: Lrc<QueryJob<'gcx>>,
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
- compute: F)
- -> R
+ compute: F,
+ ) -> R
where
- F: for<'lcx> FnOnce(TyCtxt<'gcx, 'lcx>) -> R
+ F: for<'lcx> FnOnce(TyCtxt<'gcx, 'lcx>) -> R,
{
// The TyCtxt stored in TLS has the same global interner lifetime
// as `self`, so we use `with_related_context` to relate the 'gcx lifetimes
#[cold]
pub(super) fn report_cycle(
self,
- CycleError { usage, cycle: stack }: CycleError<'gcx>
- ) -> DiagnosticBuilder<'tcx>
- {
+ CycleError { usage, cycle: stack }: CycleError<'gcx>,
+ ) -> DiagnosticBuilder<'tcx> {
assert!(!stack.is_empty());
let fix_span = |span: Span, query: &Query<'gcx>| {
/// then `force_from_dep_node()` should not fail for it. Otherwise, you can just
/// add it to the "We don't have enough information to reconstruct..." group in
/// the match below.
-pub fn force_from_dep_node<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- dep_node: &DepNode
-) -> bool {
+pub fn force_from_dep_node<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, dep_node: &DepNode) -> bool {
use crate::dep_graph::RecoverKey;
// We must avoid ever having to call force_from_dep_node() for a
ExistentialRegionBound, // relating an existential region bound
}
-pub trait TypeRelation<'gcx: 'tcx, 'tcx> : Sized {
+pub trait TypeRelation<'gcx: 'tcx, 'tcx>: Sized {
fn tcx(&self) -> TyCtxt<'gcx, 'tcx>;
/// Returns a static string we can use for printouts.
}
pub trait Relate<'tcx>: TypeFoldable<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self)
- -> RelateResult<'tcx, Self>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a;
+ fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self) -> RelateResult<'tcx, Self>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a;
}
///////////////////////////////////////////////////////////////////////////
// Relate impls
impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::TypeAndMut<'tcx>,
- b: &ty::TypeAndMut<'tcx>)
- -> RelateResult<'tcx, ty::TypeAndMut<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::TypeAndMut<'tcx>,
+ b: &ty::TypeAndMut<'tcx>,
+ ) -> RelateResult<'tcx, ty::TypeAndMut<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
debug!("{}.mts({:?}, {:?})",
relation.tag(),
}
}
-pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
- variances: Option<&[ty::Variance]>,
- a_subst: SubstsRef<'tcx>,
- b_subst: SubstsRef<'tcx>)
- -> RelateResult<'tcx, SubstsRef<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+pub fn relate_substs<'a, 'gcx, 'tcx, R>(
+ relation: &mut R,
+ variances: Option<&[ty::Variance]>,
+ a_subst: SubstsRef<'tcx>,
+ b_subst: SubstsRef<'tcx>,
+) -> RelateResult<'tcx, SubstsRef<'tcx>>
+where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let tcx = relation.tcx();
}
impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::FnSig<'tcx>,
- b: &ty::FnSig<'tcx>)
- -> RelateResult<'tcx, ty::FnSig<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::FnSig<'tcx>,
+ b: &ty::FnSig<'tcx>,
+ ) -> RelateResult<'tcx, ty::FnSig<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let tcx = relation.tcx();
}
impl<'tcx> Relate<'tcx> for ast::Unsafety {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ast::Unsafety,
- b: &ast::Unsafety)
- -> RelateResult<'tcx, ast::Unsafety>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ast::Unsafety,
+ b: &ast::Unsafety,
+ ) -> RelateResult<'tcx, ast::Unsafety>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
if a != b {
Err(TypeError::UnsafetyMismatch(expected_found(relation, a, b)))
}
impl<'tcx> Relate<'tcx> for abi::Abi {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &abi::Abi,
- b: &abi::Abi)
- -> RelateResult<'tcx, abi::Abi>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &abi::Abi,
+ b: &abi::Abi,
+ ) -> RelateResult<'tcx, abi::Abi>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
if a == b {
Ok(*a)
}
impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::ProjectionTy<'tcx>,
- b: &ty::ProjectionTy<'tcx>)
- -> RelateResult<'tcx, ty::ProjectionTy<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::ProjectionTy<'tcx>,
+ b: &ty::ProjectionTy<'tcx>,
+ ) -> RelateResult<'tcx, ty::ProjectionTy<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
if a.item_def_id != b.item_def_id {
Err(TypeError::ProjectionMismatched(
}
impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::ExistentialProjection<'tcx>,
- b: &ty::ExistentialProjection<'tcx>)
- -> RelateResult<'tcx, ty::ExistentialProjection<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::ExistentialProjection<'tcx>,
+ b: &ty::ExistentialProjection<'tcx>,
+ ) -> RelateResult<'tcx, ty::ExistentialProjection<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
if a.item_def_id != b.item_def_id {
Err(TypeError::ProjectionMismatched(
}
impl<'tcx> Relate<'tcx> for Vec<ty::PolyExistentialProjection<'tcx>> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &Vec<ty::PolyExistentialProjection<'tcx>>,
- b: &Vec<ty::PolyExistentialProjection<'tcx>>)
- -> RelateResult<'tcx, Vec<ty::PolyExistentialProjection<'tcx>>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &Vec<ty::PolyExistentialProjection<'tcx>>,
+ b: &Vec<ty::PolyExistentialProjection<'tcx>>,
+ ) -> RelateResult<'tcx, Vec<ty::PolyExistentialProjection<'tcx>>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
// To be compatible, `a` and `b` must be for precisely the
// same set of traits and item names. We always require that
}
impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::TraitRef<'tcx>,
- b: &ty::TraitRef<'tcx>)
- -> RelateResult<'tcx, ty::TraitRef<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::TraitRef<'tcx>,
+ b: &ty::TraitRef<'tcx>,
+ ) -> RelateResult<'tcx, ty::TraitRef<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
// Different traits cannot be related
if a.def_id != b.def_id {
}
impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::ExistentialTraitRef<'tcx>,
- b: &ty::ExistentialTraitRef<'tcx>)
- -> RelateResult<'tcx, ty::ExistentialTraitRef<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::ExistentialTraitRef<'tcx>,
+ b: &ty::ExistentialTraitRef<'tcx>,
+ ) -> RelateResult<'tcx, ty::ExistentialTraitRef<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
// Different traits cannot be related
if a.def_id != b.def_id {
}
impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &GeneratorWitness<'tcx>,
- b: &GeneratorWitness<'tcx>)
- -> RelateResult<'tcx, GeneratorWitness<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &GeneratorWitness<'tcx>,
+ b: &GeneratorWitness<'tcx>,
+ ) -> RelateResult<'tcx, GeneratorWitness<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
assert_eq!(a.0.len(), b.0.len());
let tcx = relation.tcx();
}
impl<'tcx> Relate<'tcx> for Ty<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &Ty<'tcx>,
- b: &Ty<'tcx>)
- -> RelateResult<'tcx, Ty<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &Ty<'tcx>,
+ b: &Ty<'tcx>,
+ ) -> RelateResult<'tcx, Ty<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
relation.tys(a, b)
}
/// The main "type relation" routine. Note that this does not handle
/// inference artifacts, so you should filter those out before calling
/// it.
-pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
- a: Ty<'tcx>,
- b: Ty<'tcx>)
- -> RelateResult<'tcx, Ty<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(
+ relation: &mut R,
+ a: Ty<'tcx>,
+ b: Ty<'tcx>,
+) -> RelateResult<'tcx, Ty<'tcx>>
+where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let tcx = relation.tcx();
debug!("super_relate_tys: a={:?} b={:?}", a, b);
pub fn super_relate_consts<'a, 'gcx, 'tcx, R>(
relation: &mut R,
a: &'tcx ty::Const<'tcx>,
- b: &'tcx ty::Const<'tcx>
+ b: &'tcx ty::Const<'tcx>,
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>>
where
- R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let tcx = relation.tcx();
}
impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &Self,
- b: &Self)
- -> RelateResult<'tcx, Self>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a {
-
+ fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self) -> RelateResult<'tcx, Self>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
+ {
if a.len() != b.len() {
return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
}
}
impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::ClosureSubsts<'tcx>,
- b: &ty::ClosureSubsts<'tcx>)
- -> RelateResult<'tcx, ty::ClosureSubsts<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::ClosureSubsts<'tcx>,
+ b: &ty::ClosureSubsts<'tcx>,
+ ) -> RelateResult<'tcx, ty::ClosureSubsts<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let substs = relate_substs(relation, None, a.substs, b.substs)?;
Ok(ty::ClosureSubsts { substs })
}
impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::GeneratorSubsts<'tcx>,
- b: &ty::GeneratorSubsts<'tcx>)
- -> RelateResult<'tcx, ty::GeneratorSubsts<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::GeneratorSubsts<'tcx>,
+ b: &ty::GeneratorSubsts<'tcx>,
+ ) -> RelateResult<'tcx, ty::GeneratorSubsts<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let substs = relate_substs(relation, None, a.substs, b.substs)?;
Ok(ty::GeneratorSubsts { substs })
}
impl<'tcx> Relate<'tcx> for SubstsRef<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &SubstsRef<'tcx>,
- b: &SubstsRef<'tcx>)
- -> RelateResult<'tcx, SubstsRef<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &SubstsRef<'tcx>,
+ b: &SubstsRef<'tcx>,
+ ) -> RelateResult<'tcx, SubstsRef<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
relate_substs(relation, None, a, b)
}
}
impl<'tcx> Relate<'tcx> for ty::Region<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::Region<'tcx>,
- b: &ty::Region<'tcx>)
- -> RelateResult<'tcx, ty::Region<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::Region<'tcx>,
+ b: &ty::Region<'tcx>,
+ ) -> RelateResult<'tcx, ty::Region<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
relation.regions(*a, *b)
}
}
impl<'tcx> Relate<'tcx> for &'tcx ty::Const<'tcx> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &&'tcx ty::Const<'tcx>,
- b: &&'tcx ty::Const<'tcx>)
- -> RelateResult<'tcx, &'tcx ty::Const<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &&'tcx ty::Const<'tcx>,
+ b: &&'tcx ty::Const<'tcx>,
+ ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
relation.consts(*a, *b)
}
}
impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for ty::Binder<T> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &ty::Binder<T>,
- b: &ty::Binder<T>)
- -> RelateResult<'tcx, ty::Binder<T>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(
+ relation: &mut R,
+ a: &ty::Binder<T>,
+ b: &ty::Binder<T>,
+ ) -> RelateResult<'tcx, ty::Binder<T>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
relation.binders(a, b)
}
}
impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Rc<T> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &Rc<T>,
- b: &Rc<T>)
- -> RelateResult<'tcx, Rc<T>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(relation: &mut R, a: &Rc<T>, b: &Rc<T>) -> RelateResult<'tcx, Rc<T>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let a: &T = a;
let b: &T = b;
}
impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Box<T> {
- fn relate<'a, 'gcx, R>(relation: &mut R,
- a: &Box<T>,
- b: &Box<T>)
- -> RelateResult<'tcx, Box<T>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
+ fn relate<'a, 'gcx, R>(relation: &mut R, a: &Box<T>, b: &Box<T>) -> RelateResult<'tcx, Box<T>>
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
let a: &T = a;
let b: &T = b;
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &Kind<'tcx>,
- b: &Kind<'tcx>
+ b: &Kind<'tcx>,
) -> RelateResult<'tcx, Kind<'tcx>>
where
- R: TypeRelation<'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a,
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
match (a.unpack(), b.unpack()) {
(UnpackedKind::Lifetime(a_lt), UnpackedKind::Lifetime(b_lt)) => {
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &ty::TraitPredicate<'tcx>,
- b: &ty::TraitPredicate<'tcx>
+ b: &ty::TraitPredicate<'tcx>,
) -> RelateResult<'tcx, ty::TraitPredicate<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
Ok(ty::TraitPredicate {
trait_ref: relation.relate(&a.trait_ref, &b.trait_ref)?,
a: &ty::ProjectionPredicate<'tcx>,
b: &ty::ProjectionPredicate<'tcx>,
) -> RelateResult<'tcx, ty::ProjectionPredicate<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
Ok(ty::ProjectionPredicate {
projection_ty: relation.relate(&a.projection_ty, &b.projection_ty)?,
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::WhereClause<'tcx>,
- b: &traits::WhereClause<'tcx>
+ b: &traits::WhereClause<'tcx>,
) -> RelateResult<'tcx, traits::WhereClause<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
use crate::traits::WhereClause::*;
match (a, b) {
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::WellFormed<'tcx>,
- b: &traits::WellFormed<'tcx>
+ b: &traits::WellFormed<'tcx>,
) -> RelateResult<'tcx, traits::WellFormed<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
use crate::traits::WellFormed::*;
match (a, b) {
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::FromEnv<'tcx>,
- b: &traits::FromEnv<'tcx>
+ b: &traits::FromEnv<'tcx>,
) -> RelateResult<'tcx, traits::FromEnv<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
use crate::traits::FromEnv::*;
match (a, b) {
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::DomainGoal<'tcx>,
- b: &traits::DomainGoal<'tcx>
+ b: &traits::DomainGoal<'tcx>,
) -> RelateResult<'tcx, traits::DomainGoal<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
use crate::traits::DomainGoal::*;
match (a, b) {
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::Goal<'tcx>,
- b: &traits::Goal<'tcx>
+ b: &traits::Goal<'tcx>,
) -> RelateResult<'tcx, traits::Goal<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
use crate::traits::GoalKind::*;
match (a, b) {
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::Goals<'tcx>,
- b: &traits::Goals<'tcx>
+ b: &traits::Goals<'tcx>,
) -> RelateResult<'tcx, traits::Goals<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
if a.len() != b.len() {
return Err(TypeError::Mismatch);
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::Clause<'tcx>,
- b: &traits::Clause<'tcx>
+ b: &traits::Clause<'tcx>,
) -> RelateResult<'tcx, traits::Clause<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
use crate::traits::Clause::*;
match (a, b) {
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::Clauses<'tcx>,
- b: &traits::Clauses<'tcx>
+ b: &traits::Clauses<'tcx>,
) -> RelateResult<'tcx, traits::Clauses<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
if a.len() != b.len() {
return Err(TypeError::Mismatch);
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::ProgramClause<'tcx>,
- b: &traits::ProgramClause<'tcx>
+ b: &traits::ProgramClause<'tcx>,
) -> RelateResult<'tcx, traits::ProgramClause<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
Ok(traits::ProgramClause {
goal: relation.relate(&a.goal, &b.goal)?,
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::Environment<'tcx>,
- b: &traits::Environment<'tcx>
+ b: &traits::Environment<'tcx>,
) -> RelateResult<'tcx, traits::Environment<'tcx>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
Ok(traits::Environment {
clauses: relation.relate(&a.clauses, &b.clauses)?,
}
impl<'tcx, G> Relate<'tcx> for traits::InEnvironment<'tcx, G>
- where G: Relate<'tcx>
+where
+ G: Relate<'tcx>,
{
fn relate<'a, 'gcx, R>(
relation: &mut R,
a: &traits::InEnvironment<'tcx, G>,
- b: &traits::InEnvironment<'tcx, G>
+ b: &traits::InEnvironment<'tcx, G>,
) -> RelateResult<'tcx, traits::InEnvironment<'tcx, G>>
- where R: TypeRelation<'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
+ where
+ R: TypeRelation<'gcx, 'tcx>,
+ 'gcx: 'tcx,
+ 'tcx: 'a,
{
Ok(traits::InEnvironment {
environment: relation.relate(&a.environment, &b.environment)?,
///////////////////////////////////////////////////////////////////////////
// Error handling
-pub fn expected_found<'a, 'gcx, 'tcx, R, T>(relation: &mut R,
- a: &T,
- b: &T)
- -> ExpectedFound<T>
- where R: TypeRelation<'gcx, 'tcx>, T: Clone, 'gcx: 'a+'tcx, 'tcx: 'a
+pub fn expected_found<'a, 'gcx, 'tcx, R, T>(relation: &mut R, a: &T, b: &T) -> ExpectedFound<T>
+where
+ R: TypeRelation<'gcx, 'tcx>,
+ T: Clone,
+ 'gcx: 'a + 'tcx,
+ 'tcx: 'a,
{
expected_found_bool(relation.a_is_expected(), a, b)
}
impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
type Lifted = ty::TraitPredicate<'tcx>;
- fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>)
- -> Option<ty::TraitPredicate<'tcx>> {
+ fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<ty::TraitPredicate<'tcx>> {
tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
trait_ref,
})
impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
type Lifted = ty::SubtypePredicate<'tcx>;
- fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>)
- -> Option<ty::SubtypePredicate<'tcx>> {
+ fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<ty::SubtypePredicate<'tcx>> {
tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
a_is_expected: self.a_is_expected,
a,
}
}
-impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
+impl<'tcx, A: Copy + Lift<'tcx>, B: Copy + Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<Self::Lifted> {
tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
type Lifted = ty::ProjectionTy<'tcx>;
- fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>)
- -> Option<ty::ProjectionTy<'tcx>> {
+ fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<ty::ProjectionTy<'tcx>> {
tcx.lift(&self.substs).map(|substs| {
ty::ProjectionTy {
item_def_id: self.item_def_id,
impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
type Lifted = ty::ProjectionPredicate<'tcx>;
- fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>)
- -> Option<ty::ProjectionPredicate<'tcx>> {
+ fn lift_to_tcx<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Option<ty::ProjectionPredicate<'tcx>> {
tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| {
ty::ProjectionPredicate {
projection_ty,
}
#[inline]
- pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_>) ->
- impl Iterator<Item=Ty<'tcx>> + 'tcx
- {
+ pub fn upvar_tys(
+ self,
+ def_id: DefId,
+ tcx: TyCtxt<'_, '_>,
+ ) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx);
upvar_kinds.iter().map(|t| {
if let UnpackedKind::Type(ty) = t.unpack() {
}
#[inline]
- pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_>) ->
- impl Iterator<Item=Ty<'tcx>> + 'tcx
- {
+ pub fn upvar_tys(
+ self,
+ def_id: DefId,
+ tcx: TyCtxt<'_, '_>,
+ ) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let SplitGeneratorSubsts { upvar_kinds, .. } = self.split(def_id, tcx);
upvar_kinds.iter().map(|t| {
if let UnpackedKind::Type(ty) = t.unpack() {
/// out of range.
#[inline]
pub fn discriminant_for_variant(
- &self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx>, variant_index: VariantIdx
+ &self,
+ def_id: DefId,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ variant_index: VariantIdx,
) -> Discr<'tcx> {
// Generators don't support explicit discriminant values, so they are
// the same as the variant index.
/// variant indices.
#[inline]
pub fn discriminants(
- &'tcx self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx>
- ) -> impl Iterator<Item=(VariantIdx, Discr<'tcx>)> + Captures<'gcx> {
+ &'tcx self,
+ def_id: DefId,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'gcx> {
self.variant_range(def_id, tcx).map(move |index| {
(index, Discr { val: index.as_usize() as u128, ty: self.discr_ty(tcx) })
})
/// The locals are grouped by their variant number. Note that some locals may
/// be repeated in multiple variants.
#[inline]
- pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx>) ->
- impl Iterator<Item=impl Iterator<Item=Ty<'tcx>> + Captures<'gcx>>
- {
+ pub fn state_tys(
+ self,
+ def_id: DefId,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + Captures<'gcx>> {
let layout = tcx.generator_layout(def_id);
layout.variant_fields.iter().map(move |variant| {
variant.iter().map(move |field| {
/// This is the types of the fields of a generator which are not stored in a
/// variant.
#[inline]
- pub fn prefix_tys(self, def_id: DefId, tcx: TyCtxt<'gcx, 'tcx>) ->
- impl Iterator<Item=Ty<'tcx>>
- {
+ pub fn prefix_tys(
+ self,
+ def_id: DefId,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ) -> impl Iterator<Item = Ty<'tcx>> {
self.upvar_tys(def_id, tcx)
}
}
impl<'tcx> UpvarSubsts<'tcx> {
#[inline]
- pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_>) ->
- impl Iterator<Item=Ty<'tcx>> + 'tcx
- {
+ pub fn upvar_tys(
+ self,
+ def_id: DefId,
+ tcx: TyCtxt<'_, '_>,
+ ) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let upvar_kinds = match self {
UpvarSubsts::Closure(substs) => substs.split(def_id, tcx).upvar_kinds,
UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds,
(AutoTrait(_), _) => Ordering::Greater,
}
}
-
}
impl<'gcx, 'tcx> Binder<ExistentialPredicate<'tcx>> {
- pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>)
- -> ty::Predicate<'tcx> {
+ pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> {
use crate::ty::ToPredicate;
match *self.skip_binder() {
ExistentialPredicate::Trait(tr) => Binder(tr).with_self_ty(tcx, self_ty).to_predicate(),
self.substs.types()
}
- pub fn from_method(tcx: TyCtxt<'_, 'tcx>,
- trait_id: DefId,
- substs: SubstsRef<'tcx>)
- -> ty::TraitRef<'tcx> {
+ pub fn from_method(
+ tcx: TyCtxt<'_, 'tcx>,
+ trait_id: DefId,
+ substs: SubstsRef<'tcx>,
+ ) -> ty::TraitRef<'tcx> {
let defs = tcx.generics_of(trait_id);
ty::TraitRef {
self.substs.types()
}
- pub fn erase_self_ty(tcx: TyCtxt<'gcx, 'tcx>,
- trait_ref: ty::TraitRef<'tcx>)
- -> ty::ExistentialTraitRef<'tcx> {
+ pub fn erase_self_ty(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ trait_ref: ty::TraitRef<'tcx>,
+ ) -> ty::ExistentialTraitRef<'tcx> {
// Assert there is a Self.
trait_ref.substs.type_at(0);
/// we convert the principal trait-ref into a normal trait-ref,
/// you must give *some* self type. A common choice is `mk_err()`
/// or some placeholder type.
- pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>)
- -> ty::TraitRef<'tcx> {
+ pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>) -> ty::TraitRef<'tcx> {
// otherwise the escaping vars would be captured by the binder
// debug_assert!(!self_ty.has_escaping_bound_vars());
/// we convert the principal trait-ref into a normal trait-ref,
/// you must give *some* self type. A common choice is `mk_err()`
/// or some placeholder type.
- pub fn with_self_ty(&self, tcx: TyCtxt<'_, 'tcx>,
- self_ty: Ty<'tcx>)
- -> ty::PolyTraitRef<'tcx> {
+ pub fn with_self_ty(&self, tcx: TyCtxt<'_, 'tcx>, self_ty: Ty<'tcx>) -> ty::PolyTraitRef<'tcx> {
self.map_bound(|trait_ref| trait_ref.with_self_ty(tcx, self_ty))
}
}
/// 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
+ tcx: TyCtxt<'_, '_>,
+ trait_ref: ty::TraitRef<'tcx>,
+ item_name: Ident,
) -> ProjectionTy<'tcx> {
let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| {
item.kind == ty::AssocKind::Type &&
}
}
- pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>,
- self_ty: Ty<'tcx>)
- -> ty::ProjectionPredicate<'tcx>
- {
+ pub fn with_self_ty(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ self_ty: Ty<'tcx>,
+ ) -> ty::ProjectionPredicate<'tcx> {
// otherwise the escaping regions would be captured by the binders
debug_assert!(!self_ty.has_escaping_bound_vars());
}
impl<'tcx, 'gcx> PolyExistentialProjection<'tcx> {
- pub fn with_self_ty(&self, tcx: TyCtxt<'gcx, 'tcx>, self_ty: Ty<'tcx>)
- -> ty::PolyProjectionPredicate<'tcx> {
+ pub fn with_self_ty(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ self_ty: Ty<'tcx>,
+ ) -> ty::PolyProjectionPredicate<'tcx> {
self.map_bound(|p| p.with_self_ty(tcx, self_ty))
}
pub fn discriminant_for_variant(
&self,
tcx: TyCtxt<'gcx, 'tcx>,
- variant_index: VariantIdx
+ variant_index: VariantIdx,
) -> Option<Discr<'tcx>> {
match self.sty {
TyKind::Adt(adt, _) => Some(adt.discriminant_for_variant(tcx, variant_index)),
impl<'tcx> Const<'tcx> {
#[inline]
- pub fn from_scalar(
- tcx: TyCtxt<'_, 'tcx>,
- val: Scalar,
- ty: Ty<'tcx>,
- ) -> &'tcx Self {
+ pub fn from_scalar(tcx: TyCtxt<'_, 'tcx>, val: Scalar, ty: Ty<'tcx>) -> &'tcx Self {
tcx.mk_const(Self {
val: ConstValue::Scalar(val),
ty,
}
#[inline]
- pub fn to_bits(
- &self,
- tcx: TyCtxt<'_, 'tcx>,
- ty: ParamEnvAnd<'tcx, Ty<'tcx>>,
- ) -> Option<u128> {
+ pub fn to_bits(&self, tcx: TyCtxt<'_, 'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option<u128> {
if self.ty != ty.value {
return None;
}
}
#[inline]
- pub fn unwrap_bits(
- &self,
- tcx: TyCtxt<'_, '_>,
- ty: ParamEnvAnd<'tcx, Ty<'tcx>>,
- ) -> u128 {
+ pub fn unwrap_bits(&self, tcx: TyCtxt<'_, '_>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> u128 {
self.assert_bits(tcx, ty).unwrap_or_else(||
bug!("expected bits of {}, got {:#?}", ty.value, self))
}
/// var bound at index `0`. For types, we use a `BoundVar` index equal to
/// the type parameter index. For regions, we use the `BoundRegion::BrNamed`
/// variant (which has a `DefId`).
- pub fn bound_vars_for_item(
- tcx: TyCtxt<'gcx, 'tcx>,
- def_id: DefId
- ) -> SubstsRef<'tcx> {
+ pub fn bound_vars_for_item(tcx: TyCtxt<'gcx, 'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
Self::for_item(tcx, def_id, |param, _| {
match param.kind {
ty::GenericParamDefKind::Type { .. } => {
/// The closures get to observe the `InternalSubsts` as they're
/// being built, which can be used to correctly
/// substitute defaults of generic parameters.
- pub fn for_item<F>(tcx: TyCtxt<'gcx, 'tcx>,
- def_id: DefId,
- mut mk_kind: F)
- -> SubstsRef<'tcx>
- where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
+ pub fn for_item<F>(tcx: TyCtxt<'gcx, 'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx>
+ where
+ F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>,
{
let defs = tcx.generics_of(def_id);
let count = defs.count();
tcx.intern_substs(&substs)
}
- pub fn extend_to<F>(&self,
- tcx: TyCtxt<'gcx, 'tcx>,
- def_id: DefId,
- mut mk_kind: F)
- -> SubstsRef<'tcx>
- where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
+ pub fn extend_to<F>(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ def_id: DefId,
+ mut mk_kind: F,
+ ) -> SubstsRef<'tcx>
+ where
+ F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>,
{
Self::for_item(tcx, def_id, |param, substs| {
self.get(param.index as usize)
})
}
- fn fill_item<F>(substs: &mut SmallVec<[Kind<'tcx>; 8]>,
- tcx: TyCtxt<'gcx, 'tcx>,
- defs: &ty::Generics,
- mk_kind: &mut F)
- where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
+ fn fill_item<F>(
+ substs: &mut SmallVec<[Kind<'tcx>; 8]>,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ defs: &ty::Generics,
+ mk_kind: &mut F,
+ ) where
+ F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>,
{
if let Some(def_id) = defs.parent {
let parent_defs = tcx.generics_of(def_id);
/// in a different item, with `target_substs` as the base for
/// the target impl/trait, with the source child-specific
/// parameters (e.g., method parameters) on top of that base.
- pub fn rebase_onto(&self, tcx: TyCtxt<'gcx, 'tcx>,
- source_ancestor: DefId,
- target_substs: SubstsRef<'tcx>)
- -> SubstsRef<'tcx> {
+ pub fn rebase_onto(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ source_ancestor: DefId,
+ target_substs: SubstsRef<'tcx>,
+ ) -> SubstsRef<'tcx> {
let defs = tcx.generics_of(source_ancestor);
tcx.mk_substs(target_substs.iter().chain(&self[defs.params.len()..]).cloned())
}
- pub fn truncate_to(&self, tcx: TyCtxt<'gcx, 'tcx>, generics: &ty::Generics)
- -> SubstsRef<'tcx> {
+ pub fn truncate_to(&self, tcx: TyCtxt<'gcx, 'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> {
tcx.mk_substs(self.iter().take(generics.count()).cloned())
}
}
// there is more information available (for better errors).
pub trait Subst<'tcx>: Sized {
- fn subst<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>,
- substs: &[Kind<'tcx>]) -> Self {
+ fn subst<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>, substs: &[Kind<'tcx>]) -> Self {
self.subst_spanned(tcx, substs, None)
}
- fn subst_spanned<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>,
- substs: &[Kind<'tcx>],
- span: Option<Span>)
- -> Self;
+ fn subst_spanned<'gcx>(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ substs: &[Kind<'tcx>],
+ span: Option<Span>,
+ ) -> Self;
}
-impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T {
- fn subst_spanned<'gcx>(&self, tcx: TyCtxt<'gcx, 'tcx>,
- substs: &[Kind<'tcx>],
- span: Option<Span>)
- -> T
- {
+impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
+ fn subst_spanned<'gcx>(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ substs: &[Kind<'tcx>],
+ span: Option<Span>,
+ ) -> T {
let mut folder = SubstFolder { tcx,
substs,
span,
///////////////////////////////////////////////////////////////////////////
// The actual substitution engine itself is a type folder.
-struct SubstFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
+struct SubstFolder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
tcx: TyCtxt<'gcx, 'tcx>,
substs: &'a [Kind<'tcx>],
}
}
- pub fn ancestors(&self, tcx: TyCtxt<'gcx, 'tcx>,
- of_impl: DefId)
- -> specialization_graph::Ancestors<'gcx> {
+ pub fn ancestors(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ of_impl: DefId,
+ ) -> specialization_graph::Ancestors<'gcx> {
specialization_graph::ancestors(tcx, self.def_id, of_impl)
}
}
}
// Query provider for `trait_impls_of`.
-pub(super) fn trait_impls_of_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- trait_id: DefId)
- -> &'tcx TraitImpls {
+pub(super) fn trait_impls_of_provider<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ trait_id: DefId,
+) -> &'tcx TraitImpls {
let mut impls = TraitImpls::default();
{
pub trait IntTypeExt {
fn to_ty<'gcx, 'tcx>(&self, tcx: TyCtxt<'gcx, 'tcx>) -> Ty<'tcx>;
- fn disr_incr<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, val: Option<Discr<'tcx>>)
- -> Option<Discr<'tcx>>;
+ fn disr_incr<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ val: Option<Discr<'tcx>>,
+ ) -> Option<Discr<'tcx>>;
fn initial_discriminant<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>) -> Discr<'tcx>;
}
}
impl<'tcx> ty::ParamEnv<'tcx> {
- pub fn can_type_implement_copy(self,
- tcx: TyCtxt<'tcx, 'tcx>,
- self_type: Ty<'tcx>)
- -> Result<(), CopyImplementationError<'tcx>> {
+ pub fn can_type_implement_copy(
+ self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ self_type: Ty<'tcx>,
+ ) -> Result<(), CopyImplementationError<'tcx>> {
// FIXME: (@jroesch) float this code up
tcx.infer_ctxt().enter(|infcx| {
let (adt, substs) = match self_type.sty {
/// does copies even when the type actually doesn't satisfy the
/// full requirements for the `Copy` trait (cc #29149) -- this
/// winds up being reported as an error during NLL borrow check.
- pub fn is_copy_modulo_regions(&'tcx self,
- tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- span: Span)
- -> bool {
+ pub fn is_copy_modulo_regions(
+ &'tcx self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ span: Span,
+ ) -> bool {
tcx.at(span).is_copy_raw(param_env.and(self))
}
/// over-approximation in generic contexts, where one can have
/// strange rules like `<T as Foo<'static>>::Bar: Sized` that
/// actually carry lifetime requirements.
- pub fn is_sized(&'tcx self,
- tcx_at: TyCtxtAt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>)-> bool
- {
+ pub fn is_sized(
+ &'tcx self,
+ tcx_at: TyCtxtAt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ ) -> bool {
tcx_at.is_sized_raw(param_env.and(self))
}
/// optimization as well as the rules around static values. Note
/// that the `Freeze` trait is not exposed to end users and is
/// effectively an implementation detail.
- pub fn is_freeze(&'tcx self,
- tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- span: Span)-> bool
- {
+ pub fn is_freeze(
+ &'tcx self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ span: Span,
+ ) -> bool {
tcx.at(span).is_freeze_raw(param_env.and(self))
}
/// (Note that this implies that if `ty` has a destructor attached,
/// then `needs_drop` will definitely return `true` for `ty`.)
#[inline]
- pub fn needs_drop(&'tcx self,
- tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>)
- -> bool {
+ pub fn needs_drop(&'tcx self, tcx: TyCtxt<'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
tcx.needs_drop_raw(param_env.and(self)).0
}
/// Check whether a type is representable. This means it cannot contain unboxed
/// structural recursion. This check is needed for structs and enums.
- pub fn is_representable(&'tcx self,
- tcx: TyCtxt<'tcx, 'tcx>,
- sp: Span)
- -> Representability
- {
+ pub fn is_representable(&'tcx self, tcx: TyCtxt<'tcx, 'tcx>, sp: Span) -> Representability {
// Iterate until something non-representable is found
fn fold_repr<It: Iterator<Item=Representability>>(iter: It) -> Representability {
iter.fold(Representability::Representable, |r1, r2| {
}
fn are_inner_types_recursive<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>, sp: Span,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ sp: Span,
seen: &mut Vec<Ty<'tcx>>,
representable_cache: &mut FxHashMap<Ty<'tcx>, Representability>,
- ty: Ty<'tcx>)
- -> Representability
- {
+ ty: Ty<'tcx>,
+ ) -> Representability {
match ty.sty {
Tuple(ref ts) => {
// Find non representable
sp: Span,
seen: &mut Vec<Ty<'tcx>>,
representable_cache: &mut FxHashMap<Ty<'tcx>, Representability>,
- ty: Ty<'tcx>) -> Representability
- {
+ ty: Ty<'tcx>,
+ ) -> Representability {
debug!("is_type_structurally_recursive: {:?} {:?}", ty, sp);
if let Some(representability) = representable_cache.get(ty) {
debug!("is_type_structurally_recursive: {:?} {:?} - (cached) {:?}",
sp: Span,
seen: &mut Vec<Ty<'tcx>>,
representable_cache: &mut FxHashMap<Ty<'tcx>, Representability>,
- ty: Ty<'tcx>) -> Representability
- {
+ ty: Ty<'tcx>,
+ ) -> Representability {
match ty.sty {
Adt(def, _) => {
{
}
}
-fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
- -> bool
-{
+fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx, '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);
tcx.infer_ctxt()
))
}
-fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
- -> bool
-{
+fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx, '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);
tcx.infer_ctxt()
))
}
-fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
- -> bool
-{
+fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx, '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::FreezeTraitLangItem);
tcx.infer_ctxt()
#[derive(Clone, HashStable)]
pub struct NeedsDrop(pub bool);
-fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
- -> NeedsDrop
-{
+fn needs_drop_raw<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
+) -> NeedsDrop {
let (param_env, ty) = query.into_parts();
let needs_drop = |ty: Ty<'tcx>| -> bool {
/// `ty::required_region_bounds`, see that for more information.
pub fn object_region_bounds<'gcx, 'tcx>(
tcx: TyCtxt<'gcx, 'tcx>,
- existential_predicates: ty::Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>)
- -> Vec<ty::Region<'tcx>>
-{
+ existential_predicates: ty::Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>,
+) -> Vec<ty::Region<'tcx>> {
// Since we don't actually *know* the self type for an object,
// this "open(err)" serves as a kind of dummy standin -- basically
// a placeholder type.
fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) { }
}
-pub fn check_loans<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
- dfcx_loans: &LoanDataFlow<'tcx>,
- move_data: &move_data::FlowedMoveData<'tcx>,
- all_loans: &[Loan<'tcx>],
- body: &hir::Body) {
+pub fn check_loans<'a, 'tcx>(
+ bccx: &BorrowckCtxt<'a, 'tcx>,
+ dfcx_loans: &LoanDataFlow<'tcx>,
+ move_data: &move_data::FlowedMoveData<'tcx>,
+ all_loans: &[Loan<'tcx>],
+ body: &hir::Body,
+) {
debug!("check_loans(body id={})", body.value.hir_id);
let def_id = bccx.tcx.hir().body_owner_def_id(body.id());
pub move_data: move_data::FlowedMoveData<'tcx>,
}
-fn borrowck<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, owner_def_id: DefId)
- -> &'tcx BorrowCheckResult
-{
+fn borrowck<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, owner_def_id: DefId) -> &'tcx BorrowCheckResult {
assert!(tcx.use_ast_borrowck() || tcx.migrate_borrowck());
debug!("borrowck(body_owner_def_id={:?})", owner_def_id);
})
}
-fn build_borrowck_dataflow_data<'a, 'c, 'tcx, F>(this: &mut BorrowckCtxt<'a, 'tcx>,
- force_analysis: bool,
- body_id: hir::BodyId,
- get_cfg: F)
- -> Option<AnalysisData<'tcx>>
- where F: FnOnce(&mut BorrowckCtxt<'a, 'tcx>) -> &'c cfg::CFG
+fn build_borrowck_dataflow_data<'a, 'c, 'tcx, F>(
+ this: &mut BorrowckCtxt<'a, 'tcx>,
+ force_analysis: bool,
+ body_id: hir::BodyId,
+ get_cfg: F,
+) -> Option<AnalysisData<'tcx>>
+where
+ F: FnOnce(&mut BorrowckCtxt<'a, 'tcx>) -> &'c cfg::CFG,
{
// Check the body of fn items.
let (all_loans, move_data) =
pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
body_id: hir::BodyId,
- cfg: &cfg::CFG)
- -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'tcx>)
-{
+ cfg: &cfg::CFG,
+) -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'tcx>) {
let owner_id = tcx.hir().body_owner(body_id);
let owner_def_id = tcx.hir().local_def_id(owner_id);
let tables = tcx.typeck_tables_of(owner_def_id);
signalled_any_error: Cell<SignalledError>,
}
-
impl BorrowckCtxt<'_, 'tcx> {
fn signal_error(&self) {
self.signalled_any_error.set(SignalledError::SawSomeError);
LpInterior(Option<DefId>, InteriorKind),
}
-fn closure_to_block(closure_id: LocalDefId,
- tcx: TyCtxt<'_, '_>) -> HirId {
+fn closure_to_block(closure_id: LocalDefId, tcx: TyCtxt<'_, '_>) -> HirId {
let closure_id = tcx.hir().local_def_id_to_node_id(closure_id);
match tcx.hir().get(closure_id) {
Node::Expr(expr) => match expr.node {
// We could (and maybe should, for efficiency) combine both move
// and assign data flow into one, but this way it's easier to
// distinguish the bits that correspond to moves and assignments.
- pub dfcx_assign: AssignDataFlow<'tcx>
+ pub dfcx_assign: AssignDataFlow<'tcx>,
}
/// Index into `MoveData.paths`, used like a pointer
/// Returns the existing move path index for `lp`, if any, and otherwise adds a new index for
/// `lp` and any of its base paths that do not yet have an index.
- pub fn move_path(&self, tcx: TyCtxt<'tcx, 'tcx>,
- lp: Rc<LoanPath<'tcx>>) -> MovePathIndex {
+ pub fn move_path(&self, tcx: TyCtxt<'tcx, 'tcx>, lp: Rc<LoanPath<'tcx>>) -> MovePathIndex {
if let Some(&index) = self.path_map.borrow().get(&lp) {
return index;
}
}
/// Adds a new move entry for a move of `lp` that occurs at location `id` with kind `kind`.
- pub fn add_move(&self, tcx: TyCtxt<'tcx, 'tcx>,
- orig_lp: Rc<LoanPath<'tcx>>,
- id: hir::ItemLocalId,
- kind: MoveKind) {
+ pub fn add_move(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ orig_lp: Rc<LoanPath<'tcx>>,
+ id: hir::ItemLocalId,
+ kind: MoveKind,
+ ) {
// Moving one union field automatically moves all its fields. Also move siblings of
// all parent union fields, moves do not propagate upwards automatically.
let mut lp = orig_lp.clone();
self.add_move_helper(tcx, orig_lp, id, kind);
}
- fn add_move_helper(&self, tcx: TyCtxt<'tcx, 'tcx>,
- lp: Rc<LoanPath<'tcx>>,
- id: hir::ItemLocalId,
- kind: MoveKind) {
+ fn add_move_helper(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ lp: Rc<LoanPath<'tcx>>,
+ id: hir::ItemLocalId,
+ kind: MoveKind,
+ ) {
debug!("add_move(lp={:?}, id={:?}, kind={:?})",
lp,
id,
/// Adds a new record for an assignment to `lp` that occurs at location `id` with the given
/// `span`.
- pub fn add_assignment(&self, tcx: TyCtxt<'tcx, 'tcx>,
- lp: Rc<LoanPath<'tcx>>,
- assign_id: hir::ItemLocalId,
- span: Span) {
+ pub fn add_assignment(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ lp: Rc<LoanPath<'tcx>>,
+ assign_id: hir::ItemLocalId,
+ span: Span,
+ ) {
// Assigning to one union field automatically assigns to all its fields.
if let LpExtend(ref base_lp, mutbl, LpInterior(opt_variant_id, interior)) = lp.kind {
if let ty::Adt(adt_def, _) = base_lp.ty.sty {
self.add_assignment_helper(tcx, lp, assign_id, span);
}
- fn add_assignment_helper(&self, tcx: TyCtxt<'tcx, 'tcx>,
- lp: Rc<LoanPath<'tcx>>,
- assign_id: hir::ItemLocalId,
- span: Span) {
+ fn add_assignment_helper(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ lp: Rc<LoanPath<'tcx>>,
+ assign_id: hir::ItemLocalId,
+ span: Span,
+ ) {
debug!("add_assignment(lp={:?}, assign_id={:?}", lp, assign_id);
let path_index = self.move_path(tcx, lp.clone());
/// Moves are generated by moves and killed by assignments and
/// scoping. Assignments are generated by assignment to variables and
/// killed by scoping. See `README.md` for more details.
- fn add_gen_kills(&self,
- bccx: &BorrowckCtxt<'_, 'tcx>,
- dfcx_moves: &mut MoveDataFlow<'_>,
- dfcx_assign: &mut AssignDataFlow<'_>) {
+ fn add_gen_kills(
+ &self,
+ bccx: &BorrowckCtxt<'_, 'tcx>,
+ dfcx_moves: &mut MoveDataFlow<'_>,
+ dfcx_assign: &mut AssignDataFlow<'_>,
+ ) {
for (i, the_move) in self.moves.borrow().iter().enumerate() {
dfcx_moves.add_gen(the_move.id, i);
}
ret
}
- fn kill_moves(&self,
- path: MovePathIndex,
- kill_id: hir::ItemLocalId,
- kill_kind: KillFrom,
- dfcx_moves: &mut MoveDataFlow<'_>) {
+ fn kill_moves(
+ &self,
+ path: MovePathIndex,
+ kill_id: hir::ItemLocalId,
+ kill_kind: KillFrom,
+ dfcx_moves: &mut MoveDataFlow<'_>,
+ ) {
// We can only perform kills for paths that refer to a unique location,
// since otherwise we may kill a move from one location with an
// assignment referring to another location.
}
impl<'tcx> FlowedMoveData<'tcx> {
- pub fn new(move_data: MoveData<'tcx>,
- bccx: &BorrowckCtxt<'_, 'tcx>,
- cfg: &cfg::CFG,
- body: &hir::Body)
- -> FlowedMoveData<'tcx> {
+ pub fn new(
+ move_data: MoveData<'tcx>,
+ bccx: &BorrowckCtxt<'_, 'tcx>,
+ cfg: &cfg::CFG,
+ body: &hir::Body,
+ ) -> FlowedMoveData<'tcx> {
let tcx = bccx.tcx;
let mut dfcx_moves =
// `id_range`, there is a range of words equal to `words_per_id`.
// So, to access the bits for any given id, you take a slice of
// the full vector (see the method `compute_id_range()`).
-
/// bits generated as we exit the cfg node. Updated by `add_gen()`.
gens: Vec<usize>,
struct PropagationContext<'a, 'tcx, O> {
dfcx: &'a mut DataFlowContext<'tcx, O>,
- changed: bool
+ changed: bool,
}
fn get_cfg_indices<'a>(id: hir::ItemLocalId,
}
}
-impl<'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'tcx, O> {
+impl<'tcx, O: DataFlowOperator> pprust::PpAnn for DataFlowContext<'tcx, O> {
fn nested(&self, state: &mut pprust::State<'_>, nested: pprust::Nested) -> io::Result<()> {
pprust::PpAnn::nested(self.tcx.hir(), state, nested)
}
}
impl<'tcx, O: DataFlowOperator> DataFlowContext<'tcx, O> {
- pub fn new(tcx: TyCtxt<'tcx, 'tcx>,
- analysis_name: &'static str,
- body: Option<&hir::Body>,
- cfg: &cfg::CFG,
- oper: O,
- bits_per_id: usize) -> DataFlowContext<'tcx, O> {
+ pub fn new(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ analysis_name: &'static str,
+ body: Option<&hir::Body>,
+ cfg: &cfg::CFG,
+ oper: O,
+ bits_per_id: usize,
+ ) -> DataFlowContext<'tcx, O> {
let usize_bits = mem::size_of::<usize>() * 8;
let words_per_id = (bits_per_id + usize_bits - 1) / usize_bits;
let num_nodes = cfg.graph.all_nodes().len();
}
}
- fn build_set<O:DataFlowOperator, F>(&self,
- e: EntryOrExit,
- cfgidx: CFGIndex,
- dfcx: &DataFlowContext<'tcx, O>,
- mut to_lp: F) -> String where
+ fn build_set<O: DataFlowOperator, F>(
+ &self,
+ e: EntryOrExit,
+ cfgidx: CFGIndex,
+ dfcx: &DataFlowContext<'tcx, O>,
+ mut to_lp: F,
+ ) -> String
+ where
F: FnMut(usize) -> Rc<LoanPath<'tcx>>,
{
let mut saw_some = false;
pub fn write_compressed_metadata<'a, 'gcx>(
tcx: TyCtxt<'gcx, 'gcx>,
metadata: &EncodedMetadata,
- llvm_module: &mut ModuleLlvm
+ llvm_module: &mut ModuleLlvm,
) {
use std::io::Write;
use flate2::Compression;
/// Cache instances of monomorphic and polymorphic items
pub instances: RefCell<FxHashMap<Instance<'tcx>, &'ll Value>>,
/// Cache generated vtables
- pub vtables: RefCell<FxHashMap<
- (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>,
+ pub vtables:
+ RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>,
/// Cache of constant strings,
pub const_cstr_cache: RefCell<FxHashMap<LocalInternedString, &'ll Value>>,
}
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
- crate fn new(tcx: TyCtxt<'tcx, 'tcx>,
- codegen_unit: Arc<CodegenUnit<'tcx>>,
- llvm_module: &'ll crate::ModuleLlvm)
- -> Self {
+ crate fn new(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ codegen_unit: Arc<CodegenUnit<'tcx>>,
+ llvm_module: &'ll crate::ModuleLlvm,
+ ) -> Self {
// An interesting part of Windows which MSVC forces our hand on (and
// apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
// attributes in LLVM IR as well as native dependencies (in C these
}
}
-pub fn compile_unit_metadata(tcx: TyCtxt<'_, '_>,
- codegen_unit_name: &str,
- debug_context: &CrateDebugContext<'ll, '_>)
- -> &'ll DIDescriptor {
+pub fn compile_unit_metadata(
+ tcx: TyCtxt<'_, '_>,
+ codegen_unit_name: &str,
+ debug_context: &CrateDebugContext<'ll, '_>,
+) -> &'ll DIDescriptor {
let mut name_in_debuginfo = match tcx.sess.local_crate_source_file {
Some(ref path) => path.clone(),
None => PathBuf::from(&*tcx.crate_name(LOCAL_CRATE).as_str()),
&self,
tcx: TyCtxt<'gcx, 'gcx>,
metadata: &EncodedMetadata,
- llvm_module: &mut ModuleLlvm
+ llvm_module: &mut ModuleLlvm,
) {
base::write_compressed_metadata(tcx, metadata, llvm_module)
}
&self,
tcx: TyCtxt<'gcx, 'gcx>,
mods: &mut ModuleLlvm,
- kind: AllocatorKind
+ kind: AllocatorKind,
) {
unsafe { allocator::codegen(tcx, mods, kind) }
}
tcx: TyCtxt<'tcx, 'tcx>,
metadata: EncodedMetadata,
need_metadata_module: bool,
- rx: mpsc::Receiver<Box<dyn Any + Send>>
+ rx: mpsc::Receiver<Box<dyn Any + Send>>,
) -> Box<dyn Any> {
box rustc_codegen_ssa::base::codegen_crate(
LlvmCodegenBackend(()), tcx, metadata, need_metadata_module, rx)
}
}
-fn reachable_non_generics_provider<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- cnum: CrateNum)
- -> &'tcx DefIdMap<SymbolExportLevel>
-{
+fn reachable_non_generics_provider<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ cnum: CrateNum,
+) -> &'tcx DefIdMap<SymbolExportLevel> {
assert_eq!(cnum, LOCAL_CRATE);
if !tcx.sess.opts.output_types.should_codegen() {
tcx.arena.alloc(reachable_non_generics)
}
-fn is_reachable_non_generic_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> bool {
+fn is_reachable_non_generic_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool {
let export_threshold = threshold(tcx);
if let Some(&level) = tcx.reachable_non_generics(def_id.krate).get(&def_id) {
}
}
-fn is_reachable_non_generic_provider_extern<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> bool {
+fn is_reachable_non_generic_provider_extern<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool {
tcx.reachable_non_generics(def_id.krate).contains_key(&def_id)
}
-fn exported_symbols_provider_local<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- cnum: CrateNum)
- -> Arc<Vec<(ExportedSymbol<'tcx>,
- SymbolExportLevel)>>
-{
+fn exported_symbols_provider_local<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ cnum: CrateNum,
+) -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>> {
assert_eq!(cnum, LOCAL_CRATE);
if !tcx.sess.opts.output_types.should_codegen() {
fn upstream_monomorphizations_provider<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
- cnum: CrateNum)
- -> &'tcx DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>>
-{
+ cnum: CrateNum,
+) -> &'tcx DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
debug_assert!(cnum == LOCAL_CRATE);
let cnums = tcx.all_crate_nums(LOCAL_CRATE);
fn upstream_monomorphizations_for_provider<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
-{
+ def_id: DefId,
+) -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
debug_assert!(!def_id.is_local());
tcx.upstream_monomorphizations(LOCAL_CRATE).get(&def_id)
}
tcx: TyCtxt<'_, '_>,
metadata: EncodedMetadata,
coordinator_receive: Receiver<Box<dyn Any + Send>>,
- total_cgus: usize
+ total_cgus: usize,
) -> OngoingCodegen<B> {
let sess = tcx.sess;
let crate_name = tcx.crate_name(LOCAL_CRATE);
jobserver: Client,
modules_config: Arc<ModuleConfig>,
metadata_config: Arc<ModuleConfig>,
- allocator_config: Arc<ModuleConfig>
+ allocator_config: Arc<ModuleConfig>,
) -> thread::JoinHandle<Result<CompiledModules, ()>> {
let coordinator_send = tcx.tx_to_llvm_workers.lock().clone();
let sess = tcx.sess;
}, work_products)
}
- pub fn submit_pre_codegened_module_to_llvm(&self,
- tcx: TyCtxt<'_, '_>,
- module: ModuleCodegen<B::Module>) {
+ pub fn submit_pre_codegened_module_to_llvm(
+ &self,
+ tcx: TyCtxt<'_, '_>,
+ module: ModuleCodegen<B::Module>,
+ ) {
self.wait_for_signal_to_codegen_item();
self.check_for_errors(tcx.sess);
_backend: &B,
tcx: TyCtxt<'_, '_>,
module: ModuleCodegen<B::Module>,
- cost: u64
+ cost: u64,
) {
let llvm_work_item = WorkItem::Optimize(module);
drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone::<B> {
pub fn submit_post_lto_module_to_llvm<B: ExtraBackendMethods>(
_backend: &B,
tcx: TyCtxt<'_, '_>,
- module: CachedModuleCodegen
+ module: CachedModuleCodegen,
) {
let llvm_work_item = WorkItem::CopyPostLtoArtifacts(module);
drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone::<B> {
pub fn submit_pre_lto_module_to_llvm<B: ExtraBackendMethods>(
_backend: &B,
tcx: TyCtxt<'_, '_>,
- module: CachedModuleCodegen
+ module: CachedModuleCodegen,
) {
let filename = pre_lto_bitcode_filename(&module.name);
let bc_path = in_incr_comp_dir_sess(tcx.sess, &filename);
tcx: TyCtxt<'tcx, 'tcx>,
metadata: EncodedMetadata,
need_metadata_module: bool,
- rx: mpsc::Receiver<Box<dyn Any + Send>>
+ rx: mpsc::Receiver<Box<dyn Any + Send>>,
) -> OngoingCodegen<B> {
-
check_for_rustc_errors_attr(tcx);
// Skip crate items and just output metadata in -Z no-codegen mode.
info.missing_lang_items.insert(cnum, missing);
}
- return info
+ return info;
}
}
};
}
-fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- cgu: &CodegenUnit<'tcx>)
- -> CguReuse {
+fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse {
if !tcx.dep_graph.is_fully_enabled() {
return CguReuse::No
}
}
}
-pub fn langcall(tcx: TyCtxt<'_, '_>,
- span: Option<Span>,
- msg: &str,
- li: LangItem)
- -> DefId {
+pub fn langcall(tcx: TyCtxt<'_, '_>, span: Option<Span>, msg: &str, li: LangItem) -> DefId {
tcx.lang_items().require(li).unwrap_or_else(|s| {
let msg = format!("{} {}", msg, s);
match span {
// any caching, i.e., calling the function twice with the same type will also do
// the work twice. The `qualified` parameter only affects the first level of the
// type name, further levels (i.e., type parameters) are always fully qualified.
-pub fn compute_debuginfo_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- t: Ty<'tcx>,
- qualified: bool)
- -> String {
+pub fn compute_debuginfo_type_name<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ t: Ty<'tcx>,
+ qualified: bool,
+) -> String {
let mut result = String::with_capacity(64);
let mut visited = FxHashSet::default();
push_debuginfo_type_name(tcx, t, qualified, &mut result, &mut visited);
// Pushes the name of the type as it should be stored in debuginfo on the
// `output` String. See also compute_debuginfo_type_name().
-pub fn push_debuginfo_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- t: Ty<'tcx>,
- qualified: bool,
- output: &mut String,
- visited: &mut FxHashSet<Ty<'tcx>>) {
-
+pub fn push_debuginfo_type_name<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ t: Ty<'tcx>,
+ qualified: bool,
+ output: &mut String,
+ visited: &mut FxHashSet<Ty<'tcx>>,
+) {
// When targeting MSVC, emit C++ style type names for compatibility with
// .natvis visualizers (and perhaps other existing native debuggers?)
let cpp_like_names = tcx.sess.target.target.options.is_like_msvc;
}
}
- fn push_item_name(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- qualified: bool,
- output: &mut String) {
+ fn push_item_name(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+ qualified: bool,
+ output: &mut String,
+ ) {
if qualified {
output.push_str(&tcx.crate_name(def_id.krate).as_str());
for path_element in tcx.def_path(def_id).data {
// reconstructed for items from non-local crates. For local crates, this
// would be possible but with inlining and LTO we have to use the least
// common denominator - otherwise we would run into conflicts.
- fn push_type_params<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- substs: SubstsRef<'tcx>,
- output: &mut String,
- visited: &mut FxHashSet<Ty<'tcx>>) {
+ fn push_type_params<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ substs: SubstsRef<'tcx>,
+ output: &mut String,
+ visited: &mut FxHashSet<Ty<'tcx>>,
+ ) {
if substs.types().next().is_none() {
return;
}
&self,
tcx: TyCtxt<'gcx, 'gcx>,
mods: &mut Self::Module,
- kind: AllocatorKind
- );
- fn compile_codegen_unit<'a, 'tcx: 'a>(
- &self,
- tcx: TyCtxt<'tcx, 'tcx>,
- cgu_name: InternedString,
+ kind: AllocatorKind,
);
+ fn compile_codegen_unit<'a, 'tcx: 'a>(&self, tcx: TyCtxt<'tcx, 'tcx>, cgu_name: InternedString);
// If find_features is true this won't access `sess.crate_types` by assuming
// that `is_pie_binary` is false. When we discover LLVM target features
// `sess.crate_types` is uninitialized so we cannot access it.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![deny(warnings)]
-
#![feature(box_syntax)]
use std::any::Any;
tcx: TyCtxt<'tcx, 'tcx>,
metadata: EncodedMetadata,
need_metadata_module: bool,
- rx: mpsc::Receiver<Box<dyn Any + Send>>
+ rx: mpsc::Receiver<Box<dyn Any + Send>>,
) -> Box<dyn Any>;
/// This is called on the returned `Box<dyn Any>` from `codegen_backend`
impl PpSourceMode {
/// Constructs a `PrinterSupport` object and passes it to `f`.
- fn call_with_pp_support<'tcx, A, F>(&self,
- sess: &'tcx Session,
- tcx: Option<TyCtxt<'tcx, 'tcx>>,
- f: F)
- -> A
- where F: FnOnce(&dyn PrinterSupport) -> A
+ fn call_with_pp_support<'tcx, A, F>(
+ &self,
+ sess: &'tcx Session,
+ tcx: Option<TyCtxt<'tcx, 'tcx>>,
+ f: F,
+ ) -> A
+ where
+ F: FnOnce(&dyn PrinterSupport) -> A,
{
match *self {
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
_ => panic!("Should use call_with_pp_support_hir"),
}
}
- fn call_with_pp_support_hir<'tcx, A, F>(
- &self,
- tcx: TyCtxt<'tcx, 'tcx>,
- f: F
- ) -> A
- where F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate) -> A
+ fn call_with_pp_support_hir<'tcx, A, F>(&self, tcx: TyCtxt<'tcx, 'tcx>, f: F) -> A
+ where
+ F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate) -> A,
{
match *self {
PpmNormal => {
}
}
-
struct TypedAnnotation<'a, 'tcx: 'a> {
tcx: TyCtxt<'tcx, 'tcx>,
tables: Cell<&'a ty::TypeckTables<'tcx>>,
}
}
-fn print_flowgraph<'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
- tcx: TyCtxt<'tcx, 'tcx>,
- code: blocks::Code<'tcx>,
- mode: PpFlowGraphMode,
- mut out: W)
- -> io::Result<()> {
+fn print_flowgraph<'tcx, W: Write>(
+ variants: Vec<borrowck_dot::Variant>,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ code: blocks::Code<'tcx>,
+ mode: PpFlowGraphMode,
+ mut out: W,
+) -> io::Result<()> {
let body_id = match code {
blocks::Code::Expr(expr) => {
// Find the function this expression is from.
krate: &ast::Crate,
ppm: PpMode,
opt_uii: Option<UserIdentifiedItem>,
- ofile: Option<&Path>) {
+ ofile: Option<&Path>,
+) {
if ppm.needs_analysis() {
abort_on_err(print_with_analysis(
tcx,
tcx: TyCtxt<'tcx, 'tcx>,
ppm: PpMode,
uii: Option<UserIdentifiedItem>,
- ofile: Option<&Path>
+ ofile: Option<&Path>,
) -> Result<(), ErrorReported> {
let nodeid = if let Some(uii) = uii {
debug!("pretty printing for {:?}", uii);
}
}
-fn check_paths<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- if_this_changed: &Sources,
- then_this_would_need: &Targets)
-{
+fn check_paths<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ if_this_changed: &Sources,
+ then_this_would_need: &Targets,
+) {
// Return early here so as not to construct the query, which is not cheap.
if if_this_changed.is_empty() {
for &(target_span, _, _, _) in then_this_would_need {
}
}
-fn encode_dep_graph(tcx: TyCtxt<'_, '_>,
- encoder: &mut Encoder) {
+fn encode_dep_graph(tcx: TyCtxt<'_, '_>, encoder: &mut Encoder) {
// First encode the commandline arguments hash
tcx.sess.opts.dep_tracking_hash().encode(encoder).unwrap();
serialized_products.encode(encoder).unwrap();
}
-fn encode_query_cache(tcx: TyCtxt<'_, '_>,
- encoder: &mut Encoder) {
+fn encode_query_cache(tcx: TyCtxt<'_, '_>, encoder: &mut Encoder) {
time(tcx.sess, "serialize query result cache", || {
tcx.serialize_query_result_cache(encoder).unwrap();
})
impl BoxedGlobalCtxt {
pub fn enter<F, R>(&mut self, f: F) -> R
where
- F: for<'tcx> FnOnce(TyCtxt<'tcx, 'tcx>) -> R
+ F: for<'tcx> FnOnce(TyCtxt<'tcx, 'tcx>) -> R,
{
self.access(|gcx| ty::tls::enter_global(gcx, |tcx| f(tcx)))
}
/// Runs the resolution, type-checking, region checking and other
/// miscellaneous analysis passes on the crate.
-fn analysis<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- cnum: CrateNum,
-) -> Result<()> {
+fn analysis<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> Result<()> {
assert_eq!(cnum, LOCAL_CRATE);
let sess = tcx.sess;
tcx.proc_macro_decls_static(LOCAL_CRATE)
}
-fn proc_macro_decls_static<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- cnum: CrateNum,
-) -> Option<DefId> {
+fn proc_macro_decls_static<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> Option<DefId> {
assert_eq!(cnum, LOCAL_CRATE);
let mut finder = Finder { decls: None };
/// to function pointers, references, core::num::NonZero*,
/// core::ptr::NonNull, and #[repr(transparent)] newtypes.
/// FIXME: This duplicates code in codegen.
-fn is_repr_nullable_ptr<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>,
- ty_def: &'tcx ty::AdtDef,
- substs: SubstsRef<'tcx>)
- -> bool {
+fn is_repr_nullable_ptr<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ty: Ty<'tcx>,
+ ty_def: &'tcx ty::AdtDef,
+ substs: SubstsRef<'tcx>,
+) -> bool {
if ty_def.variants.len() != 2 {
return false;
}
fn add_query_description_impl(
query: &Query,
modifiers: QueryModifiers,
- impls: &mut proc_macro2::TokenStream
+ impls: &mut proc_macro2::TokenStream,
) {
let name = &query.name;
let arg = &query.arg;
self.do_postorder_cnums_untracked()
}
- fn encode_metadata<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> EncodedMetadata
- {
+ fn encode_metadata<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>) -> EncodedMetadata {
encoder::encode_metadata(tcx)
}
fn raw_bytes(self) -> &'a [u8];
fn cdata(self) -> Option<&'a CrateMetadata> { None }
fn sess(self) -> Option<&'a Session> { None }
- fn tcx(self) -> Option<TyCtxt<'tcx, 'tcx>> { None }
+ fn tcx(self) -> Option<TyCtxt<'tcx, 'tcx>> {
+ None
+ }
fn decoder(self, pos: usize) -> DecodeContext<'a, 'tcx> {
let tcx = self.tcx();
}
impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
-
#[inline]
fn tcx(&self) -> TyCtxt<'tcx, 'tcx> {
self.tcx.expect("missing TyCtxt in DecodeContext")
item: &Entry<'_>,
index: DefIndex,
parent_did: DefId,
- adt_kind: ty::AdtKind
+ adt_kind: ty::AdtKind,
) -> ty::VariantDef {
let data = match item.kind {
EntryKind::Variant(data) |
)
}
- pub fn get_adt_def(&self,
- item_id: DefIndex,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> &'tcx ty::AdtDef {
+ pub fn get_adt_def(&self, item_id: DefIndex, tcx: TyCtxt<'tcx, 'tcx>) -> &'tcx ty::AdtDef {
let item = self.entry(item_id);
let did = self.local_def_id(item_id);
tcx.alloc_adt_def(did, kind, variants, repr)
}
- pub fn get_predicates(&self,
- item_id: DefIndex,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> ty::GenericPredicates<'tcx> {
+ pub fn get_predicates(
+ &self,
+ item_id: DefIndex,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ) -> ty::GenericPredicates<'tcx> {
self.entry(item_id).predicates.unwrap().decode((self, tcx))
}
- pub fn get_predicates_defined_on(&self,
- item_id: DefIndex,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> ty::GenericPredicates<'tcx> {
+ pub fn get_predicates_defined_on(
+ &self,
+ item_id: DefIndex,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ) -> ty::GenericPredicates<'tcx> {
self.entry(item_id).predicates_defined_on.unwrap().decode((self, tcx))
}
- pub fn get_super_predicates(&self,
- item_id: DefIndex,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> ty::GenericPredicates<'tcx> {
+ pub fn get_super_predicates(
+ &self,
+ item_id: DefIndex,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ) -> ty::GenericPredicates<'tcx> {
let super_predicates = match self.entry(item_id).kind {
EntryKind::Trait(data) => data.decode(self).super_predicates,
EntryKind::TraitAlias(data) => data.decode(self).super_predicates,
self.get_impl_data(id).coerce_unsized_info
}
- pub fn get_impl_trait(&self,
- id: DefIndex,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> Option<ty::TraitRef<'tcx>> {
+ pub fn get_impl_trait(
+ &self,
+ id: DefIndex,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ) -> Option<ty::TraitRef<'tcx>> {
self.get_impl_data(id).trait_ref.map(|tr| tr.decode((self, tcx)))
}
}
/// Iterates over the language items in the given crate.
- pub fn get_lang_items(
- &self,
- tcx: TyCtxt<'tcx, '_>,
- ) -> &'tcx [(DefId, usize)] {
+ pub fn get_lang_items(&self, tcx: TyCtxt<'tcx, '_>) -> &'tcx [(DefId, usize)] {
if self.proc_macros.is_some() {
// Proc macro crates do not export any lang-items to the target.
&[]
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
}
- pub fn maybe_get_optimized_mir(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- id: DefIndex)
- -> Option<Body<'tcx>> {
+ pub fn maybe_get_optimized_mir(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ id: DefIndex,
+ ) -> Option<Body<'tcx>> {
match self.is_proc_macro(id) {
true => None,
false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
pub fn get_inherent_implementations_for_type(
&self,
tcx: TyCtxt<'tcx, '_>,
- id: DefIndex
+ id: DefIndex,
) -> &'tcx [DefId] {
tcx.arena.alloc_from_iter(self.entry(id)
.inherent_impls
}
}
- pub fn get_foreign_modules(
- &self,
- tcx: TyCtxt<'tcx, '_>,
- ) -> &'tcx [ForeignModule] {
+ pub fn get_foreign_modules(&self, tcx: TyCtxt<'tcx, '_>) -> &'tcx [ForeignModule] {
if self.proc_macros.is_some() {
// Proc macro crates do not have any *target* foreign modules.
&[]
}))
}
- pub fn get_missing_lang_items(
- &self,
- tcx: TyCtxt<'tcx, '_>,
- ) -> &'tcx [lang_items::LangItem] {
+ pub fn get_missing_lang_items(&self, tcx: TyCtxt<'tcx, '_>) -> &'tcx [lang_items::LangItem] {
if self.proc_macros.is_some() {
// Proc macro crates do not depend on any target weak lang-items.
&[]
arg_names.decode(self).collect()
}
- pub fn exported_symbols(&self,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)> {
+ pub fn exported_symbols(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ) -> Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)> {
if self.proc_macros.is_some() {
// If this crate is a custom derive crate, then we're not even going to
// link those in so we skip those crates.
}
}
- pub fn fn_sig(&self,
- id: DefIndex,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> ty::PolyFnSig<'tcx> {
+ pub fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx, 'tcx>) -> ty::PolyFnSig<'tcx> {
let sig = match self.entry(id).kind {
EntryKind::Fn(data) |
EntryKind::ForeignFn(data) => data.decode(self).sig,
}
}
-impl<'tcx, T: Encodable> SpecializedEncoder<mir::ClearCrossCrate<T>>
-for EncodeContext<'tcx> {
+impl<'tcx, T: Encodable> SpecializedEncoder<mir::ClearCrossCrate<T>> for EncodeContext<'tcx> {
fn specialized_encode(&mut self,
_: &mir::ClearCrossCrate<T>)
-> Result<(), Self::Error> {
}
impl<'tcx> EncodeContext<'tcx> {
-
fn emit_node<F: FnOnce(&mut Self, usize) -> R, R>(&mut self, f: F) -> R {
assert_eq!(self.lazy_state, LazyState::NoNode);
let pos = self.position();
// will allow us to slice the metadata to the precise length that we just
// generated regardless of trailing bytes that end up in it.
-pub fn encode_metadata<'tcx>(tcx: TyCtxt<'tcx, 'tcx>)
- -> EncodedMetadata
-{
+pub fn encode_metadata<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> EncodedMetadata {
let mut encoder = opaque::Encoder::new(vec![]);
encoder.emit_raw_bytes(METADATA_HEADER);
modules: Vec::new(),
};
tcx.hir().krate().visit_all_item_likes(&mut collector);
- return collector.modules
+ return collector.modules;
}
struct Collector<'tcx> {
}
}
- return collector.args
+ return collector.args;
}
struct Collector {
};
tcx.hir().krate().visit_all_item_likes(&mut collector);
collector.process_command_line();
- return collector.libs
+ return collector.libs;
}
pub fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool {
tcx: TyCtxt<'_, 'tcx>,
body: &Body<'tcx>,
locals_are_invalidated_at_exit: bool,
- move_data: &MoveData<'tcx>
+ move_data: &MoveData<'tcx>,
) -> Self {
-
let mut visitor = GatherBorrows {
tcx,
body,
}
/// Encapsulates the idea of iterating over every borrow that involves a particular path
-pub(super) fn each_borrow_involving_path<'tcx, 'gcx: 'tcx, F, I, S> (
+pub(super) fn each_borrow_involving_path<'tcx, 'gcx: 'tcx, F, I, S>(
s: &mut S,
tcx: TyCtxt<'gcx, 'tcx>,
body: &Body<'tcx>,
mut op: F,
) where
F: FnMut(&mut S, BorrowIndex, &BorrowData<'tcx>) -> Control,
- I: Iterator<Item=BorrowIndex>
+ I: Iterator<Item = BorrowIndex>,
{
let (access, place) = access_place;
tcx: TyCtxt<'_, 'tcx>,
body: &Body<'tcx>,
locals_state_at_exit: &LocalsStateAtExit,
- ) -> bool;
+ ) -> bool;
}
impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
/// can change `'tcx` so we have to transmute afterwards.
struct GlobalizeMir<'gcx> {
tcx: TyCtxt<'gcx, 'gcx>,
- span: Span
+ span: Span,
}
impl<'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'gcx> {
///////////////////////////////////////////////////////////////////////////
// BuildMir -- walks a crate, looking for fn items and methods to build MIR from
-fn liberated_closure_env_ty<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- closure_expr_id: hir::HirId,
- body_id: hir::BodyId)
- -> Ty<'tcx> {
+fn liberated_closure_env_ty<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ closure_expr_id: hir::HirId,
+ body_id: hir::BodyId,
+) -> Ty<'tcx> {
let closure_ty = tcx.body_tables(body_id).node_type(closure_expr_id);
let (closure_def_id, closure_substs) = match closure_ty.sty {
};
}
-fn should_abort_on_panic<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- fn_def_id: DefId,
- abi: Abi)
- -> bool {
+fn should_abort_on_panic<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, fn_def_id: DefId, abi: Abi) -> bool {
// Not callable from C, so we can safely unwind through these
if abi == Abi::Rust || abi == Abi::RustCall { return false; }
}
}
-impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx>
- for CompileTimeInterpreter<'mir, 'tcx>
-{
+impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> {
type MemoryKinds = !;
type PointerTag = ();
}
#[inline(always)]
- fn stack_push(
- _ecx: &mut InterpretCx<'mir, 'tcx, Self>,
- ) -> InterpResult<'tcx> {
+ fn stack_push(_ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
Ok(())
}
/// Called immediately before a stack frame gets popped.
#[inline(always)]
- fn stack_pop(
- _ecx: &mut InterpretCx<'mir, 'tcx, Self>,
- _extra: (),
- ) -> InterpResult<'tcx> {
+ fn stack_pop(_ecx: &mut InterpretCx<'mir, 'tcx, Self>, _extra: ()) -> InterpResult<'tcx> {
Ok(())
}
}
pub fn error_to_const_error<'mir, 'tcx>(
ecx: &InterpretCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
- mut error: InterpErrorInfo<'tcx>
+ mut error: InterpErrorInfo<'tcx>,
) -> ConstEvalErr<'tcx> {
error.print_backtrace();
let stacktrace = ecx.generate_stacktrace(None);
/// is no need to maintain separate drop flags to track such state.
//
// FIXME: we have to do something for moving slice patterns.
-fn place_contents_drop_state_cannot_differ<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- body: &Body<'tcx>,
- place: &mir::Place<'tcx>) -> bool {
+fn place_contents_drop_state_cannot_differ<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ body: &Body<'tcx>,
+ place: &mir::Place<'tcx>,
+) -> bool {
let ty = place.ty(body, tcx).ty;
match ty.sty {
ty::Array(..) => {
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
lookup_result: LookupResult,
- each_child: F)
- where F: FnMut(MovePathIndex)
+ each_child: F,
+) where
+ F: FnMut(MovePathIndex),
{
match lookup_result {
LookupResult::Parent(..) => {
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
move_path_index: MovePathIndex,
- mut each_child: F)
- where F: FnMut(MovePathIndex)
+ mut each_child: F,
+) where
+ F: FnMut(MovePathIndex),
{
fn is_terminal_path<'gcx, 'tcx>(
tcx: TyCtxt<'gcx, 'tcx>,
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
- path: MovePathIndex) -> bool
- {
+ path: MovePathIndex,
+ ) -> bool {
place_contents_drop_state_cannot_differ(
tcx, body, &move_data.move_paths[path].place)
}
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
move_path_index: MovePathIndex,
- each_child: &mut F)
- where F: FnMut(MovePathIndex)
+ each_child: &mut F,
+ ) where
+ F: FnMut(MovePathIndex),
{
each_child(move_path_index);
body: &Body<'tcx>,
ctxt: &MoveDataParamEnv<'gcx, 'tcx>,
path: MovePathIndex,
- mut each_child: F)
- where F: FnMut(MovePathIndex)
+ mut each_child: F,
+) where
+ F: FnMut(MovePathIndex),
{
on_all_children_bits(tcx, body, &ctxt.move_data, path, |child| {
let place = &ctxt.move_data.move_paths[path].place;
tcx: TyCtxt<'gcx, 'tcx>,
body: &Body<'tcx>,
ctxt: &MoveDataParamEnv<'gcx, 'tcx>,
- mut callback: F)
- where F: FnMut(MovePathIndex, DropFlagState)
+ mut callback: F,
+) where
+ F: FnMut(MovePathIndex, DropFlagState),
{
let move_data = &ctxt.move_data;
for arg in body.args_iter() {
body: &Body<'tcx>,
ctxt: &MoveDataParamEnv<'gcx, 'tcx>,
loc: Location,
- mut callback: F)
- where F: FnMut(MovePathIndex, DropFlagState)
+ mut callback: F,
+) where
+ F: FnMut(MovePathIndex, DropFlagState),
{
let move_data = &ctxt.move_data;
debug!("drop_flag_effects_for_location({:?})", loc);
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
loc: Location,
- mut callback: F)
- where F: FnMut(MovePathIndex)
+ mut callback: F,
+) where
+ F: FnMut(MovePathIndex),
{
for ii in &move_data.init_loc_map[loc] {
let init = move_data.inits[*ii];
}
impl<'a, 'gcx: 'tcx, 'tcx> MaybeInitializedPlaces<'a, 'gcx, 'tcx> {
- pub fn new(tcx: TyCtxt<'gcx, 'tcx>,
- body: &'a Body<'tcx>,
- mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>)
- -> Self
- {
+ pub fn new(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ body: &'a Body<'tcx>,
+ mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>,
+ ) -> Self {
MaybeInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe }
}
}
}
impl<'a, 'gcx, 'tcx> MaybeUninitializedPlaces<'a, 'gcx, 'tcx> {
- pub fn new(tcx: TyCtxt<'gcx, 'tcx>,
- body: &'a Body<'tcx>,
- mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>)
- -> Self
- {
+ pub fn new(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ body: &'a Body<'tcx>,
+ mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>,
+ ) -> Self {
MaybeUninitializedPlaces { tcx: tcx, body: body, mdpe: mdpe }
}
}
}
impl<'a, 'gcx, 'tcx: 'a> DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> {
- pub fn new(tcx: TyCtxt<'gcx, 'tcx>,
- body: &'a Body<'tcx>,
- mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>)
- -> Self
- {
+ pub fn new(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ body: &'a Body<'tcx>,
+ mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>,
+ ) -> Self {
DefinitelyInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe }
}
}
}
impl<'a, 'gcx: 'tcx, 'tcx: 'a> EverInitializedPlaces<'a, 'gcx, 'tcx> {
- pub fn new(tcx: TyCtxt<'gcx, 'tcx>,
- body: &'a Body<'tcx>,
- mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>)
- -> Self
- {
+ pub fn new(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ body: &'a Body<'tcx>,
+ mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>,
+ ) -> Self {
EverInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe }
}
}
pub(crate) param_env: ty::ParamEnv<'gcx>,
}
-pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'gcx, 'tcx>,
- body: &'a Body<'tcx>,
- def_id: DefId,
- attributes: &[ast::Attribute],
- dead_unwinds: &BitSet<BasicBlock>,
- bd: BD,
- p: P)
- -> DataflowResults<'tcx, BD>
- where BD: BitDenotation<'tcx> + InitialFlow,
- P: Fn(&BD, BD::Idx) -> DebugFormatted
+pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ body: &'a Body<'tcx>,
+ def_id: DefId,
+ attributes: &[ast::Attribute],
+ dead_unwinds: &BitSet<BasicBlock>,
+ bd: BD,
+ p: P,
+) -> DataflowResults<'tcx, BD>
+where
+ BD: BitDenotation<'tcx> + InitialFlow,
+ P: Fn(&BD, BD::Idx) -> DebugFormatted,
{
let flow_state = DataflowAnalysis::new(body, dead_unwinds, bd);
flow_state.run(tcx, def_id, attributes, p)
}
-impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx>
+impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
+where
+ BD: BitDenotation<'tcx>,
{
- pub(crate) fn run<P>(self,
- tcx: TyCtxt<'gcx, 'tcx>,
- def_id: DefId,
- attributes: &[ast::Attribute],
- p: P) -> DataflowResults<'tcx, BD>
- where P: Fn(&BD, BD::Idx) -> DebugFormatted
+ pub(crate) fn run<P>(
+ self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ def_id: DefId,
+ attributes: &[ast::Attribute],
+ p: P,
+ ) -> DataflowResults<'tcx, BD>
+ where
+ P: Fn(&BD, BD::Idx) -> DebugFormatted,
{
let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
if let Some(item) = has_rustc_mir_with(attrs, name) {
pub(super) fn gather_moves<'gcx, 'tcx>(
body: &Body<'tcx>,
- tcx: TyCtxt<'gcx, 'tcx>
+ tcx: TyCtxt<'gcx, 'tcx>,
) -> Result<MoveData<'tcx>, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)> {
let mut builder = MoveDataBuilder::new(body, tcx);
}
impl<'gcx, 'tcx> MoveData<'tcx> {
- pub fn gather_moves(body: &Body<'tcx>, tcx: TyCtxt<'gcx, 'tcx>)
- -> Result<Self, (Self, Vec<(Place<'tcx>, MoveError<'tcx>)>)> {
+ pub fn gather_moves(
+ body: &Body<'tcx>,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ ) -> Result<Self, (Self, Vec<(Place<'tcx>, MoveError<'tcx>)>)> {
builder::gather_moves(body, tcx)
}
}
struct LiteralExpander<'tcx> {
- tcx: TyCtxt<'tcx, 'tcx>
+ tcx: TyCtxt<'tcx, 'tcx>,
}
impl LiteralExpander<'tcx> {
tcx: TyCtxt<'tcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
module: DefId,
- f: F) -> R
- where F: for<'b> FnOnce(MatchCheckCtxt<'b, 'tcx>) -> R
+ f: F,
+ ) -> R
+ where
+ F: for<'b> FnOnce(MatchCheckCtxt<'b, 'tcx>) -> R,
{
let pattern_arena = TypedArena::default();
}
impl<'tcx> IntRange<'tcx> {
- fn from_ctor(tcx: TyCtxt<'tcx, 'tcx>,
- ctor: &Constructor<'tcx>)
- -> Option<IntRange<'tcx>> {
+ fn from_ctor(tcx: TyCtxt<'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> Option<IntRange<'tcx>> {
// Floating-point ranges are permitted and we don't want
// to consider them when constructing integer ranges.
fn is_integral<'tcx>(ty: Ty<'tcx>) -> bool {
}
}
- fn from_pat(tcx: TyCtxt<'tcx, 'tcx>,
- mut pat: &Pattern<'tcx>)
- -> Option<IntRange<'tcx>> {
+ fn from_pat(tcx: TyCtxt<'tcx, 'tcx>, mut pat: &Pattern<'tcx>) -> Option<IntRange<'tcx>> {
let range = loop {
match pat.kind {
box PatternKind::Constant { value } => break ConstantValue(value),
/// Returns a collection of ranges that spans the values covered by `ranges`, subtracted
/// by the values covered by `self`: i.e., `ranges \ self` (in set notation).
- fn subtract_from(self,
- tcx: TyCtxt<'tcx, 'tcx>,
- ranges: Vec<Constructor<'tcx>>)
- -> Vec<Constructor<'tcx>> {
+ fn subtract_from(
+ self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ranges: Vec<Constructor<'tcx>>,
+ ) -> Vec<Constructor<'tcx>> {
let ranges = ranges.into_iter().filter_map(|r| {
IntRange::from_ctor(tcx, &r).map(|i| i.range)
});
const_val: &'tcx ty::Const<'tcx>,
prefix: &[Pattern<'tcx>],
slice: &Option<Pattern<'tcx>>,
- suffix: &[Pattern<'tcx>]
+ suffix: &[Pattern<'tcx>],
) -> Result<bool, ErrorReported> {
let data: &[u8] = match (const_val.val, &const_val.ty.sty) {
(ConstValue::ByRef(ptr, alloc), ty::Array(t, n)) => {
// Whether to evaluate a constructor using exhaustive integer matching. This is true if the
// constructor is a range or constant with an integer type.
-fn should_treat_range_exhaustively(
- tcx: TyCtxt<'tcx, 'tcx>,
- ctor: &Constructor<'tcx>,
-) -> bool {
+fn should_treat_range_exhaustively(tcx: TyCtxt<'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> bool {
let ty = match ctor {
ConstantValue(value) => value.ty,
ConstantRange(_, _, ty, _) => ty,
}
impl<'a, 'tcx> Pattern<'tcx> {
- pub fn from_hir(tcx: TyCtxt<'tcx, 'tcx>,
- param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>,
- tables: &'a ty::TypeckTables<'tcx>,
- pat: &'tcx hir::Pat) -> Self {
+ pub fn from_hir(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>,
+ tables: &'a ty::TypeckTables<'tcx>,
+ pat: &'tcx hir::Pat,
+ ) -> Self {
let mut pcx = PatternContext::new(tcx, param_env_and_substs, tables);
let result = pcx.lower_pattern(pat);
if !pcx.errors.is_empty() {
}
impl<'a, 'tcx> PatternContext<'a, 'tcx> {
- pub fn new(tcx: TyCtxt<'tcx, 'tcx>,
- param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>,
- tables: &'a ty::TypeckTables<'tcx>) -> Self {
+ pub fn new(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>,
+ tables: &'a ty::TypeckTables<'tcx>,
+ ) -> Self {
PatternContext {
tcx,
param_env: param_env_and_substs.param_env,
pub(crate) stack: Vec<Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>>,
/// A cache for deduplicating vtables
- pub(super) vtables: FxHashMap<
- (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>),
- Pointer<M::PointerTag>
- >,
+ pub(super) vtables:
+ FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), Pointer<M::PointerTag>>,
}
/// A stack frame.
}
}
-impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout
- for InterpretCx<'mir, 'tcx, M>
-{
+impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for InterpretCx<'mir, 'tcx, M> {
#[inline]
fn data_layout(&self) -> &layout::TargetDataLayout {
&self.tcx.data_layout
}
impl<'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for InterpretCx<'mir, 'tcx, M>
- where M: Machine<'mir, 'tcx>
+where
+ M: Machine<'mir, 'tcx>,
{
#[inline]
fn tcx(&self) -> TyCtxt<'tcx, 'tcx> {
}
impl<'mir, 'tcx, M> layout::HasParamEnv<'tcx> for InterpretCx<'mir, 'tcx, M>
- where M: Machine<'mir, 'tcx>
+where
+ M: Machine<'mir, 'tcx>,
{
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}
}
-impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf
- for InterpretCx<'mir, 'tcx, M>
-{
+impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpretCx<'mir, 'tcx, M> {
type Ty = Ty<'tcx>;
type TyLayout = InterpResult<'tcx, TyLayout<'tcx>>;
}
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
- pub fn new(
- tcx: TyCtxtAt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- machine: M,
- ) -> Self {
+ pub fn new(tcx: TyCtxtAt<'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, machine: M) -> Self {
InterpretCx {
machine,
tcx,
}
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
-pub(super) fn alloc_type_name<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>
-) -> &'tcx Allocation {
+pub(super) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>) -> &'tcx Allocation {
let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path;
let alloc = Allocation::from_byte_aligned_bytes(path.into_bytes());
tcx.intern_const_alloc(alloc)
}
/// Called immediately before a new stack frame got pushed
- fn stack_push(
- ecx: &mut InterpretCx<'mir, 'tcx, Self>,
- ) -> InterpResult<'tcx, Self::FrameExtra>;
+ fn stack_push(ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, Self::FrameExtra>;
/// Called immediately after a stack frame gets popped
fn stack_pop(
pub(super) tcx: TyCtxtAt<'tcx, 'tcx>,
}
-impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout
- for Memory<'mir, 'tcx, M>
-{
+impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for Memory<'mir, 'tcx, M> {
#[inline]
fn data_layout(&self) -> &TargetDataLayout {
&self.tcx.data_layout
// FIXME: Really we shouldn't clone memory, ever. Snapshot machinery should instead
// carefully copy only the reachable parts.
-impl<'mir, 'tcx, M>
- Clone
-for
- Memory<'mir, 'tcx, M>
+impl<'mir, 'tcx, M> Clone for Memory<'mir, 'tcx, M>
where
- M: Machine<'mir, 'tcx, PointerTag=(), AllocExtra=(), MemoryExtra=()>,
+ M: Machine<'mir, 'tcx, PointerTag = (), AllocExtra = (), MemoryExtra = ()>,
M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation)>,
{
fn clone(&self) -> Self {
/// Interning (for CTFE)
impl<'mir, 'tcx, M> Memory<'mir, 'tcx, M>
where
- M: Machine<'mir, 'tcx, PointerTag=(), AllocExtra=(), MemoryExtra=()>,
+ M: Machine<'mir, 'tcx, PointerTag = (), AllocExtra = (), MemoryExtra = ()>,
// FIXME: Working around https://github.com/rust-lang/rust/issues/24159
M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation)>,
{
where
// FIXME: Working around https://github.com/rust-lang/rust/issues/54385
Tag: ::std::fmt::Debug + Copy + Eq + Hash + 'static,
- M: Machine<'mir, 'tcx, PointerTag=Tag>,
+ M: Machine<'mir, 'tcx, PointerTag = Tag>,
// FIXME: Working around https://github.com/rust-lang/rust/issues/24159
M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation<Tag, M::AllocExtra>)>,
M::AllocExtra: AllocationExtra<Tag>,
pub fn mplace_array_fields(
&self,
base: MPlaceTy<'tcx, Tag>,
- ) ->
- InterpResult<'tcx, impl Iterator<Item=InterpResult<'tcx, MPlaceTy<'tcx, Tag>>> + 'tcx>
+ ) -> InterpResult<'tcx, impl Iterator<Item = InterpResult<'tcx, MPlaceTy<'tcx, Tag>>> + 'tcx>
{
let len = base.len(self)?; // also asserts that we have a type where this makes sense
let stride = match base.layout.fields {
snapshots: FxHashSet<InterpSnapshot<'mir, 'tcx>>,
}
-impl<'mir, 'tcx> InfiniteLoopDetector<'mir, 'tcx>
-{
+impl<'mir, 'tcx> InfiniteLoopDetector<'mir, 'tcx> {
pub fn observe_and_analyze(
&mut self,
tcx: TyCtxt<'tcx, 'tcx>,
impl InterpSnapshot<'mir, 'tcx> {
fn new(
memory: &Memory<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
- stack: &[Frame<'mir, 'tcx>]
+ stack: &[Frame<'mir, 'tcx>],
) -> Self {
InterpSnapshot {
memory: memory.clone(),
// Start with the stack, iterate and recursively snapshot
self.stack.iter().map(|frame| frame.snapshot(&self.memory)).collect()
}
-
}
impl<'mir, 'tcx> Hash for InterpSnapshot<'mir, 'tcx> {
}
}
-impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>>
- ValueVisitor<'mir, 'tcx, M> for ValidityVisitor<'rt, 'mir, 'tcx, M>
+impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
+ for ValidityVisitor<'rt, 'mir, 'tcx, M>
{
type V = OpTy<'tcx, M::PointerTag>;
// A thing that we can project into, and that has a layout.
// This wouldn't have to depend on `Machine` but with the current type inference,
// that's just more convenient to work with (avoids repeating all the `Machine` bounds).
-pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy
-{
+pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy {
/// Gets this value's layout.
fn layout(&self) -> TyLayout<'tcx>;
// Operands and memory-places are both values.
// Places in general are not due to `place_field` having to do `force_allocation`.
-impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M>
- for OpTy<'tcx, M::PointerTag>
-{
+impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M::PointerTag> {
#[inline(always)]
fn layout(&self) -> TyLayout<'tcx> {
self.layout
ecx.operand_field(self, field)
}
}
-impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M>
- for MPlaceTy<'tcx, M::PointerTag>
-{
+impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx, M::PointerTag> {
#[inline(always)]
fn layout(&self) -> TyLayout<'tcx> {
self.layout
use rustc::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt};
use rustc::ty::subst::InternalSubsts;
-pub fn check(tcx: TyCtxt<'tcx, 'tcx>,
- body: &Body<'tcx>,
- def_id: DefId) {
+pub fn check(tcx: TyCtxt<'tcx, 'tcx>, body: &Body<'tcx>, def_id: DefId) {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) {
}
}
-fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'tcx, 'tcx>,
- fn_kind: FnKind<'_>,
- body: &Body<'tcx>,
- def_id: DefId) {
+fn check_fn_for_unconditional_recursion(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ fn_kind: FnKind<'_>,
+ body: &Body<'tcx>,
+ def_id: DefId,
+) {
if let FnKind::Closure(_) = fn_kind {
// closures can't recur, so they don't matter.
return;
}
}
-pub fn collect_crate_mono_items<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- mode: MonoItemCollectionMode)
- -> (FxHashSet<MonoItem<'tcx>>,
- InliningMap<'tcx>) {
+pub fn collect_crate_mono_items<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ mode: MonoItemCollectionMode,
+) -> (FxHashSet<MonoItem<'tcx>>, InliningMap<'tcx>) {
let roots = time(tcx.sess, "collecting roots", || {
collect_roots(tcx, mode)
});
// Find all non-generic items by walking the HIR. These items serve as roots to
// start monomorphizing from.
-fn collect_roots<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- mode: MonoItemCollectionMode)
- -> Vec<MonoItem<'tcx>> {
+fn collect_roots<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ mode: MonoItemCollectionMode,
+) -> Vec<MonoItem<'tcx>> {
debug!("Collecting roots");
let mut roots = Vec::new();
}
// Collect all monomorphized items reachable from `starting_point`
-fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx, 'tcx>,
- starting_point: MonoItem<'tcx>,
- visited: MTRef<'_, MTLock<FxHashSet<MonoItem<'tcx>>>>,
- recursion_depths: &mut DefIdMap<usize>,
- inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>) {
+fn collect_items_rec<'a, 'tcx: 'a>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ starting_point: MonoItem<'tcx>,
+ visited: MTRef<'_, MTLock<FxHashSet<MonoItem<'tcx>>>>,
+ recursion_depths: &mut DefIdMap<usize>,
+ inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>,
+) {
if !visited.lock_mut().insert(starting_point.clone()) {
// We've been here already, no need to search again.
return;
debug!("END collect_items_rec({})", starting_point.to_string(tcx, true));
}
-fn record_accesses<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- caller: MonoItem<'tcx>,
- callees: &[MonoItem<'tcx>],
- inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>) {
+fn record_accesses<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ caller: MonoItem<'tcx>,
+ callees: &[MonoItem<'tcx>],
+ inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>,
+) {
let is_inlining_candidate = |mono_item: &MonoItem<'tcx>| {
mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy
};
inlining_map.lock_mut().record_accesses(caller, accesses);
}
-fn check_recursion_limit<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- instance: Instance<'tcx>,
- recursion_depths: &mut DefIdMap<usize>)
- -> (DefId, usize) {
+fn check_recursion_limit<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ instance: Instance<'tcx>,
+ recursion_depths: &mut DefIdMap<usize>,
+) -> (DefId, usize) {
let def_id = instance.def_id();
let recursion_depth = recursion_depths.get(&def_id).cloned().unwrap_or(0);
debug!(" => recursion depth={}", recursion_depth);
(def_id, recursion_depth)
}
-fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- instance: Instance<'tcx>)
-{
+fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: Instance<'tcx>) {
let type_length = instance.substs.types().flat_map(|ty| ty.walk()).count();
let const_length = instance.substs.consts().flat_map(|ct| ct.ty.walk()).count();
debug!(" => type length={}, const length={}", type_length, const_length);
}
}
-fn visit_drop_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>,
- is_direct_call: bool,
- output: &mut Vec<MonoItem<'tcx>>)
-{
+fn visit_drop_use<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ty: Ty<'tcx>,
+ is_direct_call: bool,
+ output: &mut Vec<MonoItem<'tcx>>,
+) {
let instance = Instance::resolve_drop_in_place(tcx, ty);
visit_instance_use(tcx, instance, is_direct_call, output);
}
-fn visit_fn_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>,
- is_direct_call: bool,
- output: &mut Vec<MonoItem<'tcx>>)
-{
+fn visit_fn_use<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ ty: Ty<'tcx>,
+ is_direct_call: bool,
+ output: &mut Vec<MonoItem<'tcx>>,
+) {
if let ty::FnDef(def_id, substs) = ty.sty {
let instance = ty::Instance::resolve(tcx,
ty::ParamEnv::reveal_all(),
}
}
-fn visit_instance_use<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- instance: ty::Instance<'tcx>,
- is_direct_call: bool,
- output: &mut Vec<MonoItem<'tcx>>)
-{
+fn visit_instance_use<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ instance: ty::Instance<'tcx>,
+ is_direct_call: bool,
+ output: &mut Vec<MonoItem<'tcx>>,
+) {
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
if !should_monomorphize_locally(tcx, &instance) {
return
// Returns true if we should codegen an instance in the local crate.
// Returns false if we can just link to the upstream crate and therefore don't
// need a mono item.
-fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: &Instance<'tcx>)
- -> bool {
+fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: &Instance<'tcx>) -> bool {
let def_id = match instance.def {
ty::InstanceDef::Item(def_id) => def_id,
ty::InstanceDef::VtableShim(..) |
}
return true;
- fn is_available_upstream_generic<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- substs: SubstsRef<'tcx>)
- -> bool {
+ fn is_available_upstream_generic<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+ substs: SubstsRef<'tcx>,
+ ) -> bool {
debug_assert!(!def_id.is_local());
// If we are not in share generics mode, we don't link to upstream
///
/// Finally, there is also the case of custom unsizing coercions, e.g., for
/// smart pointers such as `Rc` and `Arc`.
-fn find_vtable_types_for_unsizing<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- source_ty: Ty<'tcx>,
- target_ty: Ty<'tcx>)
- -> (Ty<'tcx>, Ty<'tcx>) {
+fn find_vtable_types_for_unsizing<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ source_ty: Ty<'tcx>,
+ target_ty: Ty<'tcx>,
+) -> (Ty<'tcx>, Ty<'tcx>) {
let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| {
let type_has_metadata = |ty: Ty<'tcx>| -> bool {
use syntax_pos::DUMMY_SP;
/// Creates a `MonoItem` for each method that is referenced by the vtable for
/// the given trait/impl pair.
-fn create_mono_items_for_vtable_methods<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- trait_ty: Ty<'tcx>,
- impl_ty: Ty<'tcx>,
- output: &mut Vec<MonoItem<'tcx>>) {
+fn create_mono_items_for_vtable_methods<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ trait_ty: Ty<'tcx>,
+ impl_ty: Ty<'tcx>,
+ output: &mut Vec<MonoItem<'tcx>>,
+) {
assert!(!trait_ty.needs_subst() && !trait_ty.has_escaping_bound_vars() &&
!impl_ty.needs_subst() && !impl_ty.has_escaping_bound_vars());
generics.requires_monomorphization(tcx)
}
-fn create_mono_items_for_default_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- item: &'tcx hir::Item,
- output: &mut Vec<MonoItem<'tcx>>) {
+fn create_mono_items_for_default_impls<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ item: &'tcx hir::Item,
+ output: &mut Vec<MonoItem<'tcx>>,
+) {
match item.node {
hir::ItemKind::Impl(_, _, _, ref generics, .., ref impl_item_refs) => {
for param in &generics.params {
}
/// Scan the MIR in order to find function calls, closures, and drop-glue
-fn collect_neighbours<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- instance: Instance<'tcx>,
- output: &mut Vec<MonoItem<'tcx>>)
-{
+fn collect_neighbours<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ instance: Instance<'tcx>,
+ output: &mut Vec<MonoItem<'tcx>>,
+) {
let body = tcx.instance_mir(instance.def);
MirNeighborCollector {
}
}
-fn def_id_to_string<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> String {
+fn def_id_to_string<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> String {
let mut output = String::new();
let printer = DefPathBasedNames::new(tcx, false, false);
printer.push_def_path(def_id, &mut output);
}
}
}
- fn instantiation_mode(&self,
- tcx: TyCtxt<'tcx, 'tcx>)
- -> InstantiationMode {
+ fn instantiation_mode(&self, tcx: TyCtxt<'tcx, 'tcx>) -> InstantiationMode {
let inline_in_all_cgus =
tcx.sess.opts.debugging_opts.inline_in_all_cgus.unwrap_or_else(|| {
tcx.sess.opts.optimize != OptLevel::No
}
};
- fn to_string_internal<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- prefix: &str,
- instance: Instance<'tcx>,
- debug: bool)
- -> String {
+ fn to_string_internal<'a, 'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ prefix: &str,
+ instance: Instance<'tcx>,
+ debug: bool,
+ ) -> String {
let mut result = String::with_capacity(32);
result.push_str(prefix);
let printer = DefPathBasedNames::new(tcx, false, false);
pub mod collector;
pub mod partitioning;
-pub fn custom_coerce_unsize_info<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- source_ty: Ty<'tcx>,
- target_ty: Ty<'tcx>)
- -> CustomCoerceUnsized {
+pub fn custom_coerce_unsize_info<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ source_ty: Ty<'tcx>,
+ target_ty: Ty<'tcx>,
+) -> CustomCoerceUnsized {
let def_id = tcx.lang_items().coerce_unsized_trait().unwrap();
let trait_ref = ty::Binder::bind(ty::TraitRef {
name_builder.build_cgu_name(LOCAL_CRATE, &["fallback"], Some("cgu"))
}
-pub fn partition<'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>,
- mono_items: I,
- strategy: PartitioningStrategy,
- inlining_map: &InliningMap<'tcx>)
- -> Vec<CodegenUnit<'tcx>>
- where I: Iterator<Item = MonoItem<'tcx>>
+pub fn partition<'tcx, I>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ mono_items: I,
+ strategy: PartitioningStrategy,
+ inlining_map: &InliningMap<'tcx>,
+) -> Vec<CodegenUnit<'tcx>>
+where
+ I: Iterator<Item = MonoItem<'tcx>>,
{
// In the first step, we place all regular monomorphizations into their
// respective 'home' codegen unit. Regular monomorphizations are all
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
}
-fn place_root_mono_items<'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>,
- mono_items: I)
- -> PreInliningPartitioning<'tcx>
- where I: Iterator<Item = MonoItem<'tcx>>
+fn place_root_mono_items<'tcx, I>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ mono_items: I,
+) -> PreInliningPartitioning<'tcx>
+where
+ I: Iterator<Item = MonoItem<'tcx>>,
{
let mut roots = FxHashSet::default();
let mut codegen_units = FxHashMap::default();
}
}
-fn merge_codegen_units<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- initial_partitioning: &mut PreInliningPartitioning<'tcx>,
- target_cgu_count: usize) {
+fn merge_codegen_units<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ initial_partitioning: &mut PreInliningPartitioning<'tcx>,
+ target_cgu_count: usize,
+) {
assert!(target_cgu_count >= 1);
let codegen_units = &mut initial_partitioning.codegen_units;
}
}
-fn internalize_symbols<'tcx>(_tcx: TyCtxt<'tcx, 'tcx>,
- partitioning: &mut PostInliningPartitioning<'tcx>,
- inlining_map: &InliningMap<'tcx>) {
+fn internalize_symbols<'tcx>(
+ _tcx: TyCtxt<'tcx, 'tcx>,
+ partitioning: &mut PostInliningPartitioning<'tcx>,
+ inlining_map: &InliningMap<'tcx>,
+) {
if partitioning.codegen_units.len() == 1 {
// Fast path for when there is only one codegen unit. In this case we
// can internalize all candidates, since there is nowhere else they
}
}
-fn characteristic_def_id_of_mono_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- mono_item: MonoItem<'tcx>)
- -> Option<DefId> {
+fn characteristic_def_id_of_mono_item<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ mono_item: MonoItem<'tcx>,
+) -> Option<DefId> {
match mono_item {
MonoItem::Fn(instance) => {
let def_id = match instance.def {
type CguNameCache = FxHashMap<(DefId, bool), InternedString>;
-fn compute_codegen_unit_name(tcx: TyCtxt<'_, '_>,
- name_builder: &mut CodegenUnitNameBuilder<'_, '_>,
- def_id: DefId,
- volatile: bool,
- cache: &mut CguNameCache)
- -> InternedString {
+fn compute_codegen_unit_name(
+ tcx: TyCtxt<'_, '_>,
+ name_builder: &mut CodegenUnitNameBuilder<'_, '_>,
+ def_id: DefId,
+ volatile: bool,
+ cache: &mut CguNameCache,
+) -> InternedString {
// Find the innermost module that is not nested within a function.
let mut current_def_id = def_id;
let mut cgu_def_id = None;
}).clone()
}
-fn numbered_codegen_unit_name(name_builder: &mut CodegenUnitNameBuilder<'_, '_>,
- index: usize)
- -> InternedString {
+fn numbered_codegen_unit_name(
+ name_builder: &mut CodegenUnitNameBuilder<'_, '_>,
+ index: usize,
+) -> InternedString {
name_builder.build_cgu_name_no_mangle(LOCAL_CRATE, &["cgu"], Some(index))
}
-fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>,
- label: &str,
- cgus: I)
- where I: Iterator<Item=&'b CodegenUnit<'tcx>>,
- 'tcx: 'a + 'b
+fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx, 'tcx>, label: &str, cgus: I)
+where
+ I: Iterator<Item = &'b CodegenUnit<'tcx>>,
+ 'tcx: 'a + 'b,
{
if cfg!(debug_assertions) {
debug!("{}", label);
#[inline(never)] // give this a place in the profiler
fn assert_symbols_are_distinct<'a, 'tcx: 'a, I>(tcx: TyCtxt<'tcx, 'tcx>, mono_items: I)
- where I: Iterator<Item=&'a MonoItem<'tcx>>
+where
+ I: Iterator<Item = &'a MonoItem<'tcx>>,
{
let mut symbols: Vec<_> = mono_items.map(|mono_item| {
(mono_item, mono_item.symbol_name(tcx))
fn collect_and_partition_mono_items<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
cnum: CrateNum,
-) -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>)
-{
+) -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>) {
assert_eq!(cnum, LOCAL_CRATE);
let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items {
providers.mir_shims = make_shim;
}
-fn make_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- instance: ty::InstanceDef<'tcx>)
- -> &'tcx Body<'tcx>
-{
+fn make_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
debug!("make_shim({:?})", instance);
let mut result = match instance {
.collect()
}
-fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- ty: Option<Ty<'tcx>>)
- -> Body<'tcx>
-{
+fn build_drop_shim<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+ ty: Option<Ty<'tcx>>,
+) -> Body<'tcx> {
debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty);
// Check if this is a generator, if so, return the drop glue for it
fn patch(&mut self) -> &mut MirPatch<'tcx> { &mut self.patch }
fn body(&self) -> &'a Body<'tcx> { self.body }
- fn tcx(&self) -> TyCtxt<'tcx, 'tcx> { self.tcx }
+ fn tcx(&self) -> TyCtxt<'tcx, 'tcx> {
+ self.tcx
+ }
fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env }
fn drop_style(&self, _path: Self::Path, mode: DropFlagMode) -> DropStyle {
}
/// Builds a `Clone::clone` shim for `self_ty`. Here, `def_id` is `Clone::clone`.
-fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- self_ty: Ty<'tcx>)
- -> Body<'tcx>
-{
+fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Body<'tcx> {
debug!("build_clone_shim(def_id={:?})", def_id);
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
}
impl CloneShimBuilder<'tcx> {
- fn new(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- self_ty: Ty<'tcx>) -> Self {
+ fn new(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Self {
// we must subst the self_ty because it's
// otherwise going to be TySelf and we can't index
// or access fields of a Place of type TySelf.
///
/// If `untuple_args` is a vec of types, the second argument of the
/// function will be untupled as these types.
-fn build_call_shim<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- rcvr_adjustment: Adjustment,
- call_kind: CallKind,
- untuple_args: Option<&[Ty<'tcx>]>)
- -> Body<'tcx>
-{
+fn build_call_shim<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+ rcvr_adjustment: Adjustment,
+ call_kind: CallKind,
+ untuple_args: Option<&[Ty<'tcx>]>,
+) -> Body<'tcx> {
debug!("build_call_shim(def_id={:?}, rcvr_adjustment={:?}, \
call_kind={:?}, untuple_args={:?})",
def_id, rcvr_adjustment, call_kind, untuple_args);
*/
impl MirPass for AddCallGuards {
- fn run_pass<'tcx>(&self,
- _tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ _tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
self.add_call_guards(body);
}
}
pub struct AddMovesForPackedDrops;
impl MirPass for AddMovesForPackedDrops {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- src: MirSource<'tcx>,
- body: &mut Body<'tcx>)
- {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) {
debug!("add_moves_for_packed_drops({:?} @ {:?})", src, body.span);
add_moves_for_packed_drops(tcx, body, src.def_id());
}
pub fn add_moves_for_packed_drops<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
body: &mut Body<'tcx>,
- def_id: DefId)
-{
+ def_id: DefId,
+) {
let patch = add_moves_for_packed_drops_patch(tcx, body, def_id);
patch.apply(body);
}
fn add_moves_for_packed_drops_patch<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
body: &Body<'tcx>,
- def_id: DefId)
- -> MirPatch<'tcx>
-{
+ def_id: DefId,
+) -> MirPatch<'tcx> {
let mut patch = MirPatch::new(body);
let param_env = tcx.param_env(def_id);
patch: &mut MirPatch<'tcx>,
terminator: &Terminator<'tcx>,
loc: Location,
- is_cleanup: bool)
-{
+ is_cleanup: bool,
+) {
debug!("add_move_for_packed_drop({:?} @ {:?})", terminator, loc);
let (location, target, unwind) = match terminator.kind {
TerminatorKind::Drop { ref location, target, unwind } =>
}
impl MirPass for AddRetag {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>)
- {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
if !tcx.sess.opts.debugging_opts.mir_emit_retag {
return;
}
}
}
-fn check_unused_unsafe<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- used_unsafe: &FxHashSet<hir::HirId>,
- unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>)
-{
+fn check_unused_unsafe<'a, 'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+ used_unsafe: &FxHashSet<hir::HirId>,
+ unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>,
+) {
let body_id =
tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| {
tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)
hir::intravisit::Visitor::visit_body(&mut visitor, body);
}
-fn unsafety_check_result<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId)
- -> UnsafetyCheckResult
-{
+fn unsafety_check_result<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> UnsafetyCheckResult {
debug!("unsafety_violations({:?})", def_id);
// N.B., this borrow is valid because all the consumers of
}
/// Returns the `HirId` for an enclosing scope that is also `unsafe`.
-fn is_enclosed(tcx: TyCtxt<'_, '_>,
- used_unsafe: &FxHashSet<hir::HirId>,
- id: hir::HirId) -> Option<(String, hir::HirId)> {
+fn is_enclosed(
+ tcx: TyCtxt<'_, '_>,
+ used_unsafe: &FxHashSet<hir::HirId>,
+ id: hir::HirId,
+) -> Option<(String, hir::HirId)> {
let parent_id = tcx.hir().get_parent_node_by_hir_id(id);
if parent_id != id {
if used_unsafe.contains(&parent_id) {
}
}
-fn report_unused_unsafe(tcx: TyCtxt<'_, '_>,
- used_unsafe: &FxHashSet<hir::HirId>,
- id: hir::HirId) {
+fn report_unused_unsafe(tcx: TyCtxt<'_, '_>, used_unsafe: &FxHashSet<hir::HirId>, id: hir::HirId) {
let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id));
let msg = "unnecessary `unsafe` block";
let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg);
pub struct DeleteNonCodegenStatements;
impl MirPass for CleanupNonCodegenStatements {
- fn run_pass<'tcx>(&self,
- _tcx: TyCtxt<'tcx, 'tcx>,
- _source: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ _tcx: TyCtxt<'tcx, 'tcx>,
+ _source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
let mut delete = DeleteNonCodegenStatements;
delete.visit_body(body);
}
pub struct ConstProp;
impl MirPass for ConstProp {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- source: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
// will be evaluated by miri and produce its errors there
if source.promoted.is_some() {
return;
}
}
-fn type_size_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- ty: Ty<'tcx>) -> Option<u64> {
+fn type_size_of<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ ty: Ty<'tcx>,
+) -> Option<u64> {
tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
}
pub struct CopyPropagation;
impl MirPass for CopyPropagation {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _source: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
// We only run when the MIR optimization level is > 1.
// This avoids a slow pass, and messing up debug info.
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
pub struct Deaggregator;
impl MirPass for Deaggregator {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _source: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
let local_decls = &*local_decls;
for bb in basic_blocks {
Cow::Borrowed(self.0)
}
- fn run_pass<'tcx>(&self,
- _tcx: TyCtxt<'tcx, 'tcx>,
- _source: MirSource<'tcx>,
- _body: &mut Body<'tcx>)
- {
+ fn run_pass<'tcx>(
+ &self,
+ _tcx: TyCtxt<'tcx, 'tcx>,
+ _source: MirSource<'tcx>,
+ _body: &mut Body<'tcx>,
+ ) {
}
}
}
}
-
-pub fn on_mir_pass<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- pass_num: &dyn fmt::Display,
- pass_name: &str,
- source: MirSource<'tcx>,
- body: &Body<'tcx>,
- is_after: bool) {
+pub fn on_mir_pass<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ pass_num: &dyn fmt::Display,
+ pass_name: &str,
+ source: MirSource<'tcx>,
+ body: &Body<'tcx>,
+ is_after: bool,
+) {
if mir_util::dump_enabled(tcx, pass_name, source) {
mir_util::dump_mir(tcx,
Some(pass_num),
}
}
-pub fn emit_mir<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- outputs: &OutputFilenames)
- -> io::Result<()>
-{
+pub fn emit_mir<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, outputs: &OutputFilenames) -> io::Result<()> {
let path = outputs.path(OutputType::Mir);
let mut f = File::create(&path)?;
mir_util::write_mir_pretty(tcx, None, &mut f)?;
pub struct ElaborateDrops;
impl MirPass for ElaborateDrops {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- src: MirSource<'tcx>,
- body: &mut Body<'tcx>)
- {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) {
debug!("elaborate_drops({:?} @ {:?})", src, body.span);
let def_id = src.def_id();
/// Returns the set of basic blocks whose unwind edges are known
/// to not be reachable, because they are `drop` terminators
/// that can't drop anything.
-fn find_dead_unwinds< 'tcx>(
+fn find_dead_unwinds<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
body: &Body<'tcx>,
def_id: hir::def_id::DefId,
- env: &MoveDataParamEnv<'tcx, 'tcx>)
- -> BitSet<BasicBlock>
-{
+ env: &MoveDataParamEnv<'tcx, 'tcx>,
+) -> BitSet<BasicBlock> {
debug!("find_dead_unwinds({:?})", body.span);
// We only need to do this pass once, because unwind edges can only
// reach cleanup blocks, which can't have unwind edges themselves.
}
impl InitializationData {
- fn apply_location<'tcx>(&mut self,
- tcx: TyCtxt<'tcx, 'tcx>,
- body: &Body<'tcx>,
- env: &MoveDataParamEnv<'tcx, 'tcx>,
- loc: Location)
- {
+ fn apply_location<'tcx>(
+ &mut self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ body: &Body<'tcx>,
+ env: &MoveDataParamEnv<'tcx, 'tcx>,
+ loc: Location,
+ ) {
drop_flag_effects_for_location(tcx, body, env, loc, |path, df| {
debug!("at location {:?}: setting {:?} to {:?}",
loc, path, df);
body: &'a Body<'tcx>,
env: &'a MoveDataParamEnv<'tcx, 'tcx>,
flow_inits: DataflowResults<'tcx, MaybeInitializedPlaces<'a, 'tcx, 'tcx>>,
- flow_uninits: DataflowResults<'tcx, MaybeUninitializedPlaces<'a, 'tcx, 'tcx>>,
+ flow_uninits: DataflowResults<'tcx, MaybeUninitializedPlaces<'a, 'tcx, 'tcx>>,
drop_flags: FxHashMap<MovePathIndex, Local>,
patch: MirPatch<'tcx>,
}
pub struct EraseRegions;
impl MirPass for EraseRegions {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
EraseRegionsVisitor::new(tcx).visit_body(body);
}
}
}
fn make_generator_state_argument_indirect<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- body: &mut Body<'tcx>) {
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+ body: &mut Body<'tcx>,
+) {
let gen_ty = body.local_decls.raw[1].ty;
let region = ty::ReFree(ty::FreeRegion {
DerefArgVisitor.visit_body(body);
}
-fn make_generator_state_argument_pinned<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- body: &mut Body<'tcx>) {
+fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &mut Body<'tcx>) {
let ref_gen_ty = body.local_decls.raw[1].ty;
let pin_did = tcx.lang_items().pin_type().unwrap();
}
}
-fn compute_layout<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- source: MirSource<'tcx>,
- upvars: &Vec<Ty<'tcx>>,
- interior: Ty<'tcx>,
- movable: bool,
- body: &mut Body<'tcx>)
- -> (FxHashMap<Local, (Ty<'tcx>, VariantIdx, usize)>,
- GeneratorLayout<'tcx>,
- FxHashMap<BasicBlock, liveness::LiveVarSet>)
-{
+fn compute_layout<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ source: MirSource<'tcx>,
+ upvars: &Vec<Ty<'tcx>>,
+ interior: Ty<'tcx>,
+ movable: bool,
+ body: &mut Body<'tcx>,
+) -> (
+ FxHashMap<Local, (Ty<'tcx>, VariantIdx, usize)>,
+ GeneratorLayout<'tcx>,
+ FxHashMap<BasicBlock, liveness::LiveVarSet>,
+) {
// Use a liveness analysis to compute locals which are live across a suspension point
let LivenessInfo {
live_locals, live_locals_at_suspension_points, storage_conflicts, storage_liveness
(remap, layout, storage_liveness)
}
-fn insert_switch<'tcx>(body: &mut Body<'tcx>,
- cases: Vec<(usize, BasicBlock)>,
- transform: &TransformVisitor<'tcx>,
- default: TerminatorKind<'tcx>) {
+fn insert_switch<'tcx>(
+ body: &mut Body<'tcx>,
+ cases: Vec<(usize, BasicBlock)>,
+ transform: &TransformVisitor<'tcx>,
+ default: TerminatorKind<'tcx>,
+) {
let default_block = insert_term_block(body, default);
let (assign, discr) = transform.get_discr(body);
let switch = TerminatorKind::SwitchInt {
}
}
-fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- body: &mut Body<'tcx>) {
+fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, body: &mut Body<'tcx>) {
use crate::util::elaborate_drops::{elaborate_drop, Unwind};
use crate::util::patch::MirPatch;
use crate::shim::DropShimElaborator;
}
fn create_generator_drop_shim<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- transform: &TransformVisitor<'tcx>,
- def_id: DefId,
- source: MirSource<'tcx>,
- gen_ty: Ty<'tcx>,
- body: &Body<'tcx>,
- drop_clean: BasicBlock) -> Body<'tcx> {
+ tcx: TyCtxt<'tcx, 'tcx>,
+ transform: &TransformVisitor<'tcx>,
+ def_id: DefId,
+ source: MirSource<'tcx>,
+ gen_ty: Ty<'tcx>,
+ body: &Body<'tcx>,
+ drop_clean: BasicBlock,
+) -> Body<'tcx> {
let mut body = body.clone();
let source_info = source_info(&body);
term_block
}
-fn insert_panic_block<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- body: &mut Body<'tcx>,
- message: AssertMessage<'tcx>) -> BasicBlock {
+fn insert_panic_block<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ body: &mut Body<'tcx>,
+ message: AssertMessage<'tcx>,
+) -> BasicBlock {
let assert_block = BasicBlock::new(body.basic_blocks().len());
let term = TerminatorKind::Assert {
cond: Operand::Constant(box Constant {
}
fn create_generator_resume_function<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- transform: TransformVisitor<'tcx>,
- def_id: DefId,
- source: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ tcx: TyCtxt<'tcx, 'tcx>,
+ transform: TransformVisitor<'tcx>,
+ def_id: DefId,
+ source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+) {
// Poison the generator when it unwinds
for block in body.basic_blocks_mut() {
let source_info = block.terminator().source_info;
drop_clean
}
-fn create_cases<'tcx, F>(body: &mut Body<'tcx>,
- transform: &TransformVisitor<'tcx>,
- target: F) -> Vec<(usize, BasicBlock)>
- where F: Fn(&SuspensionPoint) -> Option<BasicBlock> {
+fn create_cases<'tcx, F>(
+ body: &mut Body<'tcx>,
+ transform: &TransformVisitor<'tcx>,
+ target: F,
+) -> Vec<(usize, BasicBlock)>
+where
+ F: Fn(&SuspensionPoint) -> Option<BasicBlock>,
+{
let source_info = source_info(body);
transform.suspension_points.iter().filter_map(|point| {
}
impl MirPass for StateTransform {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- source: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
let yield_ty = if let Some(yield_ty) = body.yield_ty {
yield_ty
} else {
}
impl MirPass for Inline {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- source: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
Inliner { tcx, source }.run_pass(body);
}
}
}
-fn type_size_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- ty: Ty<'tcx>) -> Option<u64> {
+fn type_size_of<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ ty: Ty<'tcx>,
+) -> Option<u64> {
tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
}
* Integrates blocks from the callee function into the calling function.
* Updates block indices, references to locals and other control flow
* stuff.
- */
+*/
struct Integrator<'a, 'tcx: 'a> {
block_idx: usize,
args: &'a [Local],
pub struct InstCombine;
impl MirPass for InstCombine {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
// We only run when optimizing MIR (at any level).
if tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
return
pub struct Lower128Bit;
impl MirPass for Lower128Bit {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
let debugging_override = tcx.sess.opts.debugging_opts.lower_128bit_ops;
let target_default = tcx.sess.host.options.i128_lowering;
if !debugging_override.unwrap_or(target_default) {
}
self.lower_128bit_ops(tcx, body);
- }
+}
}
impl Lower128Bit {
lhs: &Operand<'tcx>,
rhs: &Operand<'tcx>,
local_decls: &D,
- tcx: TyCtxt<'tcx, 'tcx>)
--> DefId
- where D: HasLocalDecls<'tcx>
+ tcx: TyCtxt<'tcx, 'tcx>,
+) -> DefId
+where
+ D: HasLocalDecls<'tcx>,
{
let did = tcx.require_lang_item(lang_item);
let poly_sig = tcx.fn_sig(did);
did
}
-fn lower_to<'tcx, D>(statement: &Statement<'tcx>, local_decls: &D, tcx: TyCtxt<'tcx, 'tcx>)
- -> Option<(LangItem, RhsKind)>
- where D: HasLocalDecls<'tcx>
+fn lower_to<'tcx, D>(
+ statement: &Statement<'tcx>,
+ local_decls: &D,
+ tcx: TyCtxt<'tcx, 'tcx>,
+) -> Option<(LangItem, RhsKind)>
+where
+ D: HasLocalDecls<'tcx>,
{
match statement.kind {
StatementKind::Assign(_, box Rvalue::BinaryOp(bin_op, ref lhs, _)) => {
/// Finds the full set of `DefId`s within the current crate that have
/// MIR associated with them.
-fn mir_keys<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, krate: CrateNum)
- -> &'tcx DefIdSet {
+fn mir_keys<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, krate: CrateNum) -> &'tcx DefIdSet {
assert_eq!(krate, LOCAL_CRATE);
let mut set = DefIdSet::default();
default_name::<Self>()
}
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- source: MirSource<'tcx>,
- body: &mut Body<'tcx>);
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ source: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ );
}
pub fn run_passes(
pub struct NoLandingPads;
impl MirPass for NoLandingPads {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
no_landing_pads(tcx, body)
}
}
/// If true, all nested temps are also kept in the
/// source MIR, not moved to the promoted MIR.
- keep_original: bool
+ keep_original: bool,
}
impl<'a, 'tcx> Promoter<'a, 'tcx> {
}
}
-pub fn promote_candidates<'tcx>(body: &mut Body<'tcx>,
- tcx: TyCtxt<'tcx, 'tcx>,
- mut temps: IndexVec<Local, TempState>,
- candidates: Vec<Candidate>) {
+pub fn promote_candidates<'tcx>(
+ body: &mut Body<'tcx>,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ mut temps: IndexVec<Local, TempState>,
+ candidates: Vec<Candidate>,
+) {
// Visit candidates in reverse, in case they're nested.
debug!("promote_candidates({:?})", candidates);
}
impl<'a, 'tcx> Checker<'a, 'tcx> {
- fn new(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- body: &'a Body<'tcx>,
- mode: Mode)
- -> Self {
+ fn new(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, body: &'a Body<'tcx>, mode: Mode) -> Self {
assert!(def_id.is_local());
let mut rpo = traversal::reverse_postorder(body);
let temps = promote_consts::collect_temps(body, &mut rpo);
};
}
-fn mir_const_qualif<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> (u8, &'tcx BitSet<Local>) {
+fn mir_const_qualif<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> (u8, &'tcx BitSet<Local>) {
// N.B., this `borrow()` is guaranteed to be valid (i.e., the value
// cannot yet be stolen), because `mir_validated()`, which steals
// from `mir_const(), forces this query to execute before
pub struct QualifyAndPromoteConstants;
impl MirPass for QualifyAndPromoteConstants {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) {
// There's not really any point in promoting errorful MIR.
if body.return_ty().references_error() {
tcx.sess.delay_span_bug(body.span, "QualifyAndPromoteConstants: MIR had errors");
type McfResult = Result<(), (Span, Cow<'static, str>)>;
-pub fn is_min_const_fn(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- body: &'a Body<'tcx>,
-) -> McfResult {
+pub fn is_min_const_fn(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult {
let mut current = def_id;
loop {
let predicates = tcx.predicates_of(current);
Ok(())
}
-fn check_ty(
- tcx: TyCtxt<'tcx, 'tcx>,
- ty: Ty<'tcx>,
- span: Span,
- fn_def_id: DefId,
-) -> McfResult {
+fn check_ty(tcx: TyCtxt<'tcx, 'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult {
for ty in ty.walk() {
match ty.sty {
ty::Ref(_, _, hir::Mutability::MutMutable) => return Err((
/// code for these.
pub struct RemoveNoopLandingPads;
-pub fn remove_noop_landing_pads<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- body: &mut Body<'tcx>)
-{
+pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.no_landing_pads() {
return
}
}
impl MirPass for RemoveNoopLandingPads {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
remove_noop_landing_pads(tcx, body);
}
}
pub struct SanityCheck;
impl MirPass for SanityCheck {
- fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>,
- src: MirSource<'tcx>, body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) {
let def_id = src.def_id();
if !tcx.has_attr(def_id, sym::rustc_mir) {
debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
/// (If there are any calls to `rustc_peek` that do not match the
/// expression form above, then that emits an error as well, but those
/// errors are not intended to be used for unit tests.)
-pub fn sanity_check_via_rustc_peek<'tcx, O>(tcx: TyCtxt<'tcx, 'tcx>,
- body: &Body<'tcx>,
- def_id: DefId,
- _attributes: &[ast::Attribute],
- results: &DataflowResults<'tcx, O>)
- where O: BitDenotation<'tcx, Idx=MovePathIndex> + HasMoveData<'tcx>
+pub fn sanity_check_via_rustc_peek<'tcx, O>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ body: &Body<'tcx>,
+ def_id: DefId,
+ _attributes: &[ast::Attribute],
+ results: &DataflowResults<'tcx, O>,
+) where
+ O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>,
{
debug!("sanity_check_via_rustc_peek def_id: {:?}", def_id);
// FIXME: this is not DRY. Figure out way to abstract this and
}
}
-fn each_block<'tcx, O>(tcx: TyCtxt<'tcx, 'tcx>,
- body: &Body<'tcx>,
- results: &DataflowResults<'tcx, O>,
- bb: mir::BasicBlock) where
- O: BitDenotation<'tcx, Idx=MovePathIndex> + HasMoveData<'tcx>
+fn each_block<'tcx, O>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ body: &Body<'tcx>,
+ results: &DataflowResults<'tcx, O>,
+ bb: mir::BasicBlock,
+) where
+ O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>,
{
let move_data = results.0.operator.move_data();
let mir::BasicBlockData { ref statements, ref terminator, is_cleanup: _ } = body[bb];
form `&expr`"));
}
-fn is_rustc_peek<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- terminator: &'a Option<mir::Terminator<'tcx>>)
- -> Option<(&'a [mir::Operand<'tcx>], Span)> {
+fn is_rustc_peek<'a, 'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ terminator: &'a Option<mir::Terminator<'tcx>>,
+) -> Option<(&'a [mir::Operand<'tcx>], Span)> {
if let Some(mir::Terminator { ref kind, source_info, .. }) = *terminator {
if let mir::TerminatorKind::Call { func: ref oper, ref args, .. } = *kind {
if let mir::Operand::Constant(ref func) = *oper {
Cow::Borrowed(&self.label)
}
- fn run_pass<'tcx>(&self,
- _tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ _tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body);
simplify_cfg(body);
}
pub struct SimplifyLocals;
impl MirPass for SimplifyLocals {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx, 'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
let mut marker = DeclMarker { locals: BitSet::new_empty(body.local_decls.len()) };
marker.visit_body(body);
// Return pointer and arguments are always live
Cow::Borrowed(&self.label)
}
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
for block in body.basic_blocks_mut() {
let terminator = block.terminator_mut();
terminator.kind = match terminator.kind {
pub struct UniformArrayMoveOut;
impl MirPass for UniformArrayMoveOut {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
let mut patch = MirPatch::new(body);
{
let mut visitor = UniformArrayMoveOutVisitor{body, patch: &mut patch, tcx};
pub struct RestoreSubsliceArrayMoveOut;
impl MirPass for RestoreSubsliceArrayMoveOut {
- fn run_pass<'tcx>(&self,
- tcx: TyCtxt<'tcx, 'tcx>,
- _src: MirSource<'tcx>,
- body: &mut Body<'tcx>) {
+ fn run_pass<'tcx>(
+ &self,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ _src: MirSource<'tcx>,
+ body: &mut Body<'tcx>,
+ ) {
let mut patch = MirPatch::new(body);
{
let mut visitor = RestoreDataCollector {
/// Returns `true` if this place is allowed to be less aligned
/// than its containing struct (because it is within a packed
/// struct).
-pub fn is_disaligned<'tcx, L>(tcx: TyCtxt<'tcx, 'tcx>,
- local_decls: &L,
- param_env: ty::ParamEnv<'tcx>,
- place: &Place<'tcx>)
- -> bool
- where L: HasLocalDecls<'tcx>
+pub fn is_disaligned<'tcx, L>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ local_decls: &L,
+ param_env: ty::ParamEnv<'tcx>,
+ place: &Place<'tcx>,
+) -> bool
+where
+ L: HasLocalDecls<'tcx>,
{
debug!("is_disaligned({:?})", place);
if !is_within_packed(tcx, local_decls, place) {
}
}
-fn is_within_packed<'tcx, L>(tcx: TyCtxt<'tcx, 'tcx>,
- local_decls: &L,
- place: &Place<'tcx>)
- -> bool
- where L: HasLocalDecls<'tcx>
+fn is_within_packed<'tcx, L>(tcx: TyCtxt<'tcx, 'tcx>, local_decls: &L, place: &Place<'tcx>) -> bool
+where
+ L: HasLocalDecls<'tcx>,
{
let mut place = place;
while let &Place::Projection(box Projection {
}
}
-pub trait DropElaborator<'a, 'tcx: 'a> : fmt::Debug {
+pub trait DropElaborator<'a, 'tcx: 'a>: fmt::Debug {
type Path : Copy + fmt::Debug;
fn patch(&mut self) -> &mut MirPatch<'tcx>;
use super::pretty::dump_mir_def_ids;
/// Write a graphviz DOT graph of a list of MIRs.
-pub fn write_mir_graphviz<'tcx, W>(tcx: TyCtxt<'_, 'tcx>,
- single: Option<DefId>,
- w: &mut W)
- -> io::Result<()>
- where W: Write
+pub fn write_mir_graphviz<'tcx, W>(
+ tcx: TyCtxt<'_, 'tcx>,
+ single: Option<DefId>,
+ w: &mut W,
+) -> io::Result<()>
+where
+ W: Write,
{
for def_id in dump_mir_def_ids(tcx, single) {
let body = &tcx.optimized_mir(def_id);
}
/// Write a graphviz DOT graph of the MIR.
-pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, 'tcx>,
- def_id: DefId,
- body: &Body<'_>,
- w: &mut W) -> io::Result<()>
- where W: Write
+pub fn write_mir_fn_graphviz<'tcx, W>(
+ tcx: TyCtxt<'_, 'tcx>,
+ def_id: DefId,
+ body: &Body<'_>,
+ w: &mut W,
+) -> io::Result<()>
+where
+ W: Write,
{
writeln!(w, "digraph Mir_{} {{", graphviz_safe_def_name(def_id))?;
/// Write the graphviz DOT label for the overall graph. This is essentially a block of text that
/// will appear below the graph, showing the type of the `fn` this MIR represents and the types of
/// all the variables and temporaries.
-fn write_graph_label<'gcx, 'tcx, W: Write>(tcx: TyCtxt<'gcx, 'tcx>,
- def_id: DefId,
- body: &Body<'_>,
- w: &mut W)
- -> io::Result<()> {
+fn write_graph_label<'gcx, 'tcx, W: Write>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ def_id: DefId,
+ body: &Body<'_>,
+ w: &mut W,
+) -> io::Result<()> {
write!(w, " label=<fn {}(", dot::escape_html(&tcx.def_path_str(def_id)))?;
// fn argument types.
};
}
-fn const_is_rvalue_promotable_to_static<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> bool
-{
+fn const_is_rvalue_promotable_to_static<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool {
assert!(def_id.is_local());
let hir_id = tcx.hir().as_local_hir_id(def_id)
tcx.rvalue_promotable_map(def_id).contains(&body_id.hir_id.local_id)
}
-fn rvalue_promotable_map<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> &'tcx ItemLocalSet
-{
+fn rvalue_promotable_map<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx ItemLocalSet {
let outer_def_id = tcx.closure_base_def_id(def_id);
if outer_def_id != def_id {
return tcx.rvalue_promotable_map(outer_def_id);
tcx.plugin_registrar_fn(LOCAL_CRATE)
}
-fn plugin_registrar_fn<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- cnum: CrateNum,
-) -> Option<DefId> {
+fn plugin_registrar_fn<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, cnum: CrateNum) -> Option<DefId> {
assert_eq!(cnum, LOCAL_CRATE);
let mut finder = RegistrarFinder { registrars: Vec::new() };
}
struct DefIdVisitorSkeleton<'v, 'tcx, V>
- where V: DefIdVisitor<'tcx> + ?Sized
+where
+ V: DefIdVisitor<'tcx> + ?Sized,
{
def_id_visitor: &'v mut V,
visited_opaque_tys: FxHashSet<DefId>,
}
impl<'tcx, V> DefIdVisitorSkeleton<'_, 'tcx, V>
- where V: DefIdVisitor<'tcx> + ?Sized
+where
+ V: DefIdVisitor<'tcx> + ?Sized,
{
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> bool {
let TraitRef { def_id, substs } = trait_ref;
}
impl<'tcx, V> TypeVisitor<'tcx> for DefIdVisitorSkeleton<'_, 'tcx, V>
- where V: DefIdVisitor<'tcx> + ?Sized
+where
+ V: DefIdVisitor<'tcx> + ?Sized,
{
fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
let tcx = self.def_id_visitor.tcx();
}
}
-fn def_id_visibility<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId)
- -> (ty::Visibility, Span, &'static str) {
+fn def_id_visibility<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+) -> (ty::Visibility, Span, &'static str) {
match tcx.hir().as_local_hir_id(def_id) {
Some(hir_id) => {
let vis = match tcx.hir().get_by_hir_id(hir_id) {
// Set the correct `TypeckTables` for the given `item_id` (or an empty table if
// there is no `TypeckTables` for the item).
-fn item_tables<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- hir_id: hir::HirId,
- empty_tables: &'a ty::TypeckTables<'tcx>)
- -> &'a ty::TypeckTables<'tcx> {
+fn item_tables<'a, 'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ hir_id: hir::HirId,
+ empty_tables: &'a ty::TypeckTables<'tcx>,
+) -> &'a ty::TypeckTables<'tcx> {
let def_id = tcx.hir().local_def_id_from_hir_id(hir_id);
if tcx.has_typeck_tables(def_id) { tcx.typeck_tables_of(def_id) } else { empty_tables }
}
-fn min<'tcx>(vis1: ty::Visibility, vis2: ty::Visibility, tcx: TyCtxt<'tcx, 'tcx>)
- -> ty::Visibility {
+fn min<'tcx>(
+ vis1: ty::Visibility,
+ vis2: ty::Visibility,
+ tcx: TyCtxt<'tcx, 'tcx>,
+) -> ty::Visibility {
if vis1.is_at_least(vis2, tcx) { vis2 } else { vis1 }
}
/// in crates that have been updated to use pub(restricted).
////////////////////////////////////////////////////////////////////////////////
struct PubRestrictedVisitor<'tcx> {
- tcx: TyCtxt<'tcx, 'tcx>,
+ tcx: TyCtxt<'tcx, 'tcx>,
has_pub_restricted: bool,
}
// Returns an over-approximation (`skip_assoc_tys` = true) of visibility due to
// associated types for which we can't determine visibility precisely.
- fn of_impl<'a, 'tcx>(hir_id: hir::HirId, tcx: TyCtxt<'tcx, 'tcx>,
- access_levels: &'a AccessLevels) -> Self {
+ fn of_impl<'a, 'tcx>(
+ hir_id: hir::HirId,
+ tcx: TyCtxt<'tcx, 'tcx>,
+ access_levels: &'a AccessLevels,
+ ) -> Self {
let mut find = FindMin { tcx, access_levels, min: Self::MAX };
let def_id = tcx.hir().local_def_id_from_hir_id(hir_id);
find.visit(tcx.type_of(def_id));
}
}
- fn reach(&mut self, item_id: hir::HirId, access_level: Option<AccessLevel>)
- -> ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
+ fn reach(
+ &mut self,
+ item_id: hir::HirId,
+ access_level: Option<AccessLevel>,
+ ) -> ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
ReachEverythingInTheInterfaceVisitor {
access_level: cmp::min(access_level, Some(AccessLevel::Reachable)),
item_def_id: self.tcx.hir().local_def_id_from_hir_id(item_id),
}
impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
- fn check(&self, item_id: hir::HirId, required_visibility: ty::Visibility)
- -> SearchInterfaceForPrivateItemsVisitor<'tcx> {
+ fn check(
+ &self,
+ item_id: hir::HirId,
+ required_visibility: ty::Visibility,
+ ) -> SearchInterfaceForPrivateItemsVisitor<'tcx> {
let mut has_old_errors = false;
// Slow path taken only if there any errors in the crate.
intravisit::walk_mod(&mut visitor, module, hir_id);
}
-fn privacy_access_levels<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- krate: CrateNum,
-) -> &'tcx AccessLevels {
+fn privacy_access_levels<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, krate: CrateNum) -> &'tcx AccessLevels {
assert_eq!(krate, LOCAL_CRATE);
// Build up a set of all exported items in the AST. This is a set of all
fn lift_ex_clause_to_tcx(
ex_clause: &ChalkExClause<'a>,
- tcx: TyCtxt<'gcx, 'tcx>
+ tcx: TyCtxt<'gcx, 'tcx>,
) -> Option<Self::LiftedExClause> {
Some(ChalkExClause {
subst: tcx.lift(&ex_clause.subst)?,
fn lift_delayed_literal_to_tcx(
literal: &DelayedLiteral<ChalkArenas<'a>>,
- tcx: TyCtxt<'gcx, 'tcx>
+ tcx: TyCtxt<'gcx, 'tcx>,
) -> Option<Self::LiftedDelayedLiteral> {
Some(match literal {
DelayedLiteral::CannotProve(()) => DelayedLiteral::CannotProve(()),
crate fn evaluate_goal<'tcx>(
tcx: TyCtxt<'tcx, 'tcx>,
- goal: ChalkCanonicalGoal<'tcx>
-) -> Result<
- &'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>,
- traits::query::NoSolution
-> {
+ goal: ChalkCanonicalGoal<'tcx>,
+) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, traits::query::NoSolution> {
use crate::lowering::Lower;
use rustc::traits::WellFormed;
tcx: TyCtxt<'_, 'tcx>,
ty: Ty<'tcx>,
nested: &[Kind<'tcx>],
- trait_def_id: DefId
+ trait_def_id: DefId,
) -> ProgramClause<'tcx> {
ProgramClause {
goal: ty::TraitPredicate {
unsize_def_id: DefId,
source: Ty<'tcx>,
target: Ty<'tcx>,
- clauses: &mut Vec<Clause<'tcx>>
+ clauses: &mut Vec<Clause<'tcx>>,
) {
match (&source.sty, &target.sty) {
(ty::Dynamic(data_a, ..), ty::Dynamic(data_b, ..)) => {
tcx: TyCtxt<'_, 'tcx>,
sized_def_id: DefId,
ty: Ty<'tcx>,
- clauses: &mut Vec<Clause<'tcx>>
+ clauses: &mut Vec<Clause<'tcx>>,
) {
let mut push_builtin_impl = |ty: Ty<'tcx>, nested: &[Kind<'tcx>]| {
let clause = builtin_impl_clause(tcx, ty, nested, sized_def_id);
tcx: TyCtxt<'_, 'tcx>,
trait_def_id: DefId,
ty: Ty<'tcx>,
- clauses: &mut Vec<Clause<'tcx>>
+ clauses: &mut Vec<Clause<'tcx>>,
) {
let mut push_builtin_impl = |ty: Ty<'tcx>, nested: &[Kind<'tcx>]| {
let clause = builtin_impl_clause(tcx, ty, nested, trait_def_id);
fn assemble_clauses_from_impls<'tcx>(
tcx: TyCtxt<'_, 'tcx>,
trait_def_id: DefId,
- clauses: &mut Vec<Clause<'tcx>>
+ clauses: &mut Vec<Clause<'tcx>>,
) {
tcx.for_each_impl(trait_def_id, |impl_def_id| {
clauses.extend(
fn assemble_clauses_from_assoc_ty_values<'tcx>(
tcx: TyCtxt<'_, 'tcx>,
trait_def_id: DefId,
- clauses: &mut Vec<Clause<'tcx>>
+ clauses: &mut Vec<Clause<'tcx>>,
) {
tcx.for_each_impl(trait_def_id, |impl_def_id| {
for def_id in tcx.associated_item_def_ids(impl_def_id).iter() {
crate fn wf_clause_for_raw_ptr<'tcx>(
tcx: TyCtxt<'_, 'tcx>,
- mutbl: hir::Mutability
+ mutbl: hir::Mutability,
) -> Clauses<'tcx> {
let ptr_ty = generic_types::raw_ptr(tcx, mutbl);
arity_and_output: usize,
variadic: bool,
unsafety: hir::Unsafety,
- abi: abi::Abi
+ abi: abi::Abi,
) -> Clauses<'tcx> {
let fn_ptr = generic_types::fn_ptr(tcx, arity_and_output, variadic, unsafety, abi);
crate fn wf_clause_for_array<'tcx>(
tcx: TyCtxt<'_, 'tcx>,
- length: &'tcx ty::Const<'tcx>
+ length: &'tcx ty::Const<'tcx>,
) -> Clauses<'tcx> {
let ty = generic_types::bound(tcx, 0);
let array_ty = tcx.mk_ty(ty::Array(ty, length));
tcx.mk_clauses(iter::once(wf_clause))
}
-crate fn wf_clause_for_tuple<'tcx>(
- tcx: TyCtxt<'_, 'tcx>,
- arity: usize
-) -> Clauses<'tcx> {
+crate fn wf_clause_for_tuple<'tcx>(tcx: TyCtxt<'_, 'tcx>, arity: usize) -> Clauses<'tcx> {
let type_list = generic_types::type_list(tcx, arity);
let tuple_ty = tcx.mk_ty(ty::Tuple(type_list));
tcx.mk_clauses(iter::once(wf_clause))
}
-crate fn wf_clause_for_ref<'tcx>(
- tcx: TyCtxt<'_, 'tcx>,
- mutbl: hir::Mutability
-) -> Clauses<'tcx> {
+crate fn wf_clause_for_ref<'tcx>(tcx: TyCtxt<'_, 'tcx>, mutbl: hir::Mutability) -> Clauses<'tcx> {
let region = tcx.mk_region(
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(0))
);
tcx.mk_clauses(iter::once(wf_clause))
}
-crate fn wf_clause_for_fn_def<'tcx>(
- tcx: TyCtxt<'_, 'tcx>,
- def_id: DefId
-) -> Clauses<'tcx> {
+crate fn wf_clause_for_fn_def<'tcx>(tcx: TyCtxt<'_, 'tcx>, def_id: DefId) -> Clauses<'tcx> {
let fn_def = generic_types::fn_def(tcx, def_id);
let wf_clause = ProgramClause {
arity_and_output: usize,
c_variadic: bool,
unsafety: hir::Unsafety,
- abi: abi::Abi
+ abi: abi::Abi,
) -> Ty<'tcx> {
let inputs_and_output = tcx.mk_type_list(
(0..arity_and_output).into_iter()
tcx: TyCtxt<'tcx, 'tcx>,
goal: CanonicalTyGoal<'tcx>,
) -> Result<
- &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
- NoSolution,
+ &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
+ NoSolution,
> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&goal, |infcx, _fulfill_cx, key| {
);
}
-crate fn environment<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId
-) -> Environment<'tcx> {
+crate fn environment<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Environment<'tcx> {
use super::{Lower, IntoFromEnvGoal};
use rustc::hir::{Node, TraitItemKind, ImplItemKind, ItemKind, ForeignItemKind};
}
}
-crate fn program_clauses_for<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
-) -> Clauses<'tcx> {
+crate fn program_clauses_for<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> {
// FIXME(eddyb) this should only be using `def_kind`.
match tcx.def_key(def_id).disambiguated_data.data {
DefPathData::TypeNs(..) => match tcx.def_kind(def_id) {
}
}
-fn program_clauses_for_trait<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
-) -> Clauses<'tcx> {
+fn program_clauses_for_trait<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> {
// `trait Trait<P1..Pn> where WC { .. } // P0 == Self`
// Rule Implemented-From-Env (see rustc guide)
tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::bind(clause))))
}
-pub fn program_clauses_for_type_def<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
-) -> Clauses<'tcx> {
+pub fn program_clauses_for_type_def<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> {
// Rule WellFormed-Type
//
// `struct Ty<P1..Pn> where WC1, ..., WCm`
/// where-clauses). Because some of our bounds listings (e.g.,
/// regions) don't include the self-type, you must supply the
/// self-type here (the `param_ty` parameter).
- pub fn predicates(&self, tcx: TyCtxt<'gcx, 'tcx>, param_ty: Ty<'tcx>)
- -> Vec<(ty::Predicate<'tcx>, Span)>
- {
+ pub fn predicates(
+ &self,
+ tcx: TyCtxt<'gcx, 'tcx>,
+ param_ty: Ty<'tcx>,
+ ) -> Vec<(ty::Predicate<'tcx>, Span)> {
// If it could be sized, and is, add the `Sized` predicate.
let sized_predicate = self.implicitly_sized.and_then(|span| {
tcx.lang_items().sized_trait().map(|sized| {
}
pub fn report_autoderef_recursion_limit_error<'gcx, 'tcx>(
- tcx: TyCtxt<'gcx, 'tcx>, span: Span, ty: Ty<'tcx>)
-{
+ tcx: TyCtxt<'gcx, 'tcx>,
+ span: Span,
+ ty: Ty<'tcx>,
+) {
// We've reached the recursion limit, error gracefully.
let suggested_limit = *tcx.sess.recursion_limit.get() * 2;
let msg = format!("reached the recursion limit while auto-dereferencing `{:?}`",
/// - `trait_m`: the method in the trait
/// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
-pub fn compare_impl_method<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_m: &ty::AssocItem,
- impl_m_span: Span,
- trait_m: &ty::AssocItem,
- impl_trait_ref: ty::TraitRef<'tcx>,
- trait_item_span: Option<Span>) {
+pub fn compare_impl_method<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_m: &ty::AssocItem,
+ impl_m_span: Span,
+ trait_m: &ty::AssocItem,
+ impl_trait_ref: ty::TraitRef<'tcx>,
+ trait_item_span: Option<Span>,
+) {
debug!("compare_impl_method(impl_trait_ref={:?})",
impl_trait_ref);
}
}
-fn compare_predicate_entailment<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_m: &ty::AssocItem,
- impl_m_span: Span,
- trait_m: &ty::AssocItem,
- impl_trait_ref: ty::TraitRef<'tcx>)
- -> Result<(), ErrorReported> {
+fn compare_predicate_entailment<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_m: &ty::AssocItem,
+ impl_m_span: Span,
+ trait_m: &ty::AssocItem,
+ impl_trait_ref: ty::TraitRef<'tcx>,
+) -> Result<(), ErrorReported> {
let trait_to_impl_substs = impl_trait_ref.substs;
// This node-id should be used for the `body_id` field on each
})
}
-fn check_region_bounds_on_impl_method<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- span: Span,
- impl_m: &ty::AssocItem,
- trait_m: &ty::AssocItem,
- trait_generics: &ty::Generics,
- impl_generics: &ty::Generics,
- trait_to_skol_substs: SubstsRef<'tcx>)
- -> Result<(), ErrorReported> {
+fn check_region_bounds_on_impl_method<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ span: Span,
+ impl_m: &ty::AssocItem,
+ trait_m: &ty::AssocItem,
+ trait_generics: &ty::Generics,
+ impl_generics: &ty::Generics,
+ trait_to_skol_substs: SubstsRef<'tcx>,
+) -> Result<(), ErrorReported> {
let trait_params = trait_generics.own_counts().lifetimes;
let impl_params = impl_generics.own_counts().lifetimes;
}
}
-fn compare_self_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_m: &ty::AssocItem,
- impl_m_span: Span,
- trait_m: &ty::AssocItem,
- impl_trait_ref: ty::TraitRef<'tcx>)
- -> Result<(), ErrorReported>
-{
+fn compare_self_type<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_m: &ty::AssocItem,
+ impl_m_span: Span,
+ trait_m: &ty::AssocItem,
+ impl_trait_ref: ty::TraitRef<'tcx>,
+) -> Result<(), ErrorReported> {
// Try to give more informative error messages about self typing
// mismatches. Note that any mismatch will also be detected
// below, where we construct a canonical function type that
}
}
-fn compare_number_of_method_arguments<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_m: &ty::AssocItem,
- impl_m_span: Span,
- trait_m: &ty::AssocItem,
- trait_item_span: Option<Span>)
- -> Result<(), ErrorReported> {
+fn compare_number_of_method_arguments<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_m: &ty::AssocItem,
+ impl_m_span: Span,
+ trait_m: &ty::AssocItem,
+ trait_item_span: Option<Span>,
+) -> Result<(), ErrorReported> {
let impl_m_fty = tcx.fn_sig(impl_m.def_id);
let trait_m_fty = tcx.fn_sig(trait_m.def_id);
let trait_number_args = trait_m_fty.inputs().skip_binder().len();
Ok(())
}
-fn compare_synthetic_generics<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_m: &ty::AssocItem,
- trait_m: &ty::AssocItem)
- -> Result<(), ErrorReported> {
+fn compare_synthetic_generics<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_m: &ty::AssocItem,
+ trait_m: &ty::AssocItem,
+) -> Result<(), ErrorReported> {
// FIXME(chrisvittal) Clean up this function, list of FIXME items:
// 1. Better messages for the span labels
// 2. Explanation as to what is going on
}
}
-pub fn compare_const_impl<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_c: &ty::AssocItem,
- impl_c_span: Span,
- trait_c: &ty::AssocItem,
- impl_trait_ref: ty::TraitRef<'tcx>) {
+pub fn compare_const_impl<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_c: &ty::AssocItem,
+ impl_c_span: Span,
+ trait_c: &ty::AssocItem,
+ impl_trait_ref: ty::TraitRef<'tcx>,
+) {
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
tcx.infer_ctxt().enter(|infcx| {
/// Remember to add all intrinsics here, in librustc_codegen_llvm/intrinsic.rs,
/// and in libcore/intrinsics.rs
-pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- it: &hir::ForeignItem) {
+pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, it: &hir::ForeignItem) {
let param = |n| tcx.mk_ty_param(n, InternedString::intern(&format!("P{}", n)));
let name = it.ident.as_str();
}
/// Type-check `extern "platform-intrinsic" { ... }` functions.
-pub fn check_platform_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- it: &hir::ForeignItem) {
+pub fn check_platform_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, it: &hir::ForeignItem) {
let param = |n| {
let name = InternedString::intern(&format!("P{}", n));
tcx.mk_ty_param(n, name)
providers.method_autoderef_steps = method_autoderef_steps;
}
-fn method_autoderef_steps<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>,
- goal: CanonicalTyGoal<'tcx>)
- -> MethodAutoderefStepsResult<'gcx>
-{
+fn method_autoderef_steps<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'gcx>,
+ goal: CanonicalTyGoal<'tcx>,
+) -> MethodAutoderefStepsResult<'gcx> {
debug!("method_autoderef_steps({:?})", goal);
tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &goal, |ref infcx, goal, inference_vars| {
// Cross-crate:
let mut external_mods = FxHashSet::default();
- fn handle_external_res(tcx: TyCtxt<'_, '_>,
- traits: &mut Vec<DefId>,
- external_mods: &mut FxHashSet<DefId>,
- res: Res) {
+ fn handle_external_res(
+ tcx: TyCtxt<'_, '_>,
+ traits: &mut Vec<DefId>,
+ external_mods: &mut FxHashSet<DefId>,
+ res: Res,
+ ) {
match res {
Res::Def(DefKind::Trait, def_id) |
Res::Def(DefKind::TraitAlias, def_id) => {
target_module: hir::HirId,
span: Option<Span>,
found_use: bool,
- tcx: TyCtxt<'gcx, 'tcx>
+ tcx: TyCtxt<'gcx, 'tcx>,
}
impl UsePlacementFinder<'tcx, 'gcx> {
}
impl Inherited<'_, 'gcx, 'tcx> {
- pub fn build(tcx: TyCtxt<'gcx, 'gcx>, def_id: DefId)
- -> InheritedBuilder<'gcx, 'tcx> {
+ pub fn build(tcx: TyCtxt<'gcx, 'gcx>, def_id: DefId) -> InheritedBuilder<'gcx, 'tcx> {
let hir_id_root = if def_id.is_local() {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
DefId::local(hir_id.owner)
impl<'gcx, 'tcx> InheritedBuilder<'gcx, 'tcx> {
fn enter<F, R>(&'tcx mut self, f: F) -> R
- where F: for<'a> FnOnce(Inherited<'a, 'gcx, 'tcx>) -> R
+ where
+ F: for<'a> FnOnce(Inherited<'a, 'gcx, 'tcx>) -> R,
{
let def_id = self.def_id;
self.infcx.enter(|infcx| f(Inherited::new(infcx, def_id)))
}
}
-struct CheckItemTypesVisitor<'tcx> { tcx: TyCtxt<'tcx, 'tcx> }
+struct CheckItemTypesVisitor<'tcx> {
+ tcx: TyCtxt<'tcx, 'tcx>,
+}
impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> {
fn visit_item(&mut self, i: &'tcx hir::Item) {
};
}
-fn adt_destructor<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> Option<ty::Destructor> {
+fn adt_destructor<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option<ty::Destructor> {
tcx.calculate_dtor(def_id, &mut dropck::check_drop_impl)
}
/// may not succeed. In some cases where this function returns `None`
/// (notably closures), `typeck_tables(def_id)` would wind up
/// redirecting to the owning function.
-fn primary_body_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- id: hir::HirId)
- -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)>
-{
+fn primary_body_of<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ id: hir::HirId,
+) -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> {
match tcx.hir().get_by_hir_id(id) {
Node::Item(item) => {
match item.node {
}
}
-fn has_typeck_tables<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> bool {
+fn has_typeck_tables<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> bool {
// Closures' tables come from their outermost function,
// as they are part of the same "inference environment".
let outer_def_id = tcx.closure_base_def_id(def_id);
primary_body_of(tcx, id).is_some()
}
-fn used_trait_imports<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> &'tcx DefIdSet {
+fn used_trait_imports<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx DefIdSet {
&*tcx.typeck_tables_of(def_id).used_trait_imports
}
-fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId)
- -> &'tcx ty::TypeckTables<'tcx> {
+fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TypeckTables<'tcx> {
// Closures' tables come from their outermost function,
// as they are part of the same "inference environment".
let outer_def_id = tcx.closure_base_def_id(def_id);
(fcx, gen_ty)
}
-fn check_struct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- id: hir::HirId,
- span: Span) {
+fn check_struct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, id: hir::HirId, span: Span) {
let def_id = tcx.hir().local_def_id_from_hir_id(id);
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
check_packed(tcx, span, def_id);
}
-fn check_union<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- id: hir::HirId,
- span: Span) {
+fn check_union<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, id: hir::HirId, span: Span) {
let def_id = tcx.hir().local_def_id_from_hir_id(id);
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
check_packed(tcx, span, def_id);
}
-fn check_opaque<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- substs: SubstsRef<'tcx>,
- span: Span,
-) {
+fn check_opaque<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId, substs: SubstsRef<'tcx>, span: Span) {
if let Err(partially_expanded_type) = tcx.try_expand_impl_trait_type(def_id, substs) {
let mut err = struct_span_err!(
tcx.sess, span, E0720,
}
}
-fn check_on_unimplemented<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- trait_def_id: DefId,
- item: &hir::Item) {
+fn check_on_unimplemented<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, trait_def_id: DefId, item: &hir::Item) {
let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id);
// an error would be reported if this fails.
let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id);
}
-fn report_forbidden_specialization<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_item: &hir::ImplItem,
- parent_impl: DefId)
-{
+fn report_forbidden_specialization<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_item: &hir::ImplItem,
+ parent_impl: DefId,
+) {
let mut err = struct_span_err!(
tcx.sess, impl_item.span, E0520,
"`{}` specializes an item from a parent `impl`, but \
err.emit();
}
-fn check_specialization_validity<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- trait_def: &ty::TraitDef,
- trait_item: &ty::AssocItem,
- impl_id: DefId,
- impl_item: &hir::ImplItem)
-{
+fn check_specialization_validity<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ trait_def: &ty::TraitDef,
+ trait_item: &ty::AssocItem,
+ impl_id: DefId,
+ impl_item: &hir::ImplItem,
+) {
let ancestors = trait_def.ancestors(tcx, impl_id);
let kind = match impl_item.node {
}
-fn check_impl_items_against_trait<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_span: Span,
- impl_id: DefId,
- impl_trait_ref: ty::TraitRef<'tcx>,
- impl_item_refs: &[hir::ImplItemRef]) {
+fn check_impl_items_against_trait<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_span: Span,
+ impl_id: DefId,
+ impl_trait_ref: ty::TraitRef<'tcx>,
+ impl_item_refs: &[hir::ImplItemRef],
+) {
let impl_span = tcx.sess.source_map().def_span(impl_span);
// If the trait reference itself is erroneous (so the compilation is going
/// Checks whether a type can be represented in memory. In particular, it
/// identifies types that contain themselves without indirection through a
/// pointer, which would mean their size is unbounded.
-fn check_representable<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- sp: Span,
- item_def_id: DefId)
- -> bool {
+fn check_representable<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, sp: Span, item_def_id: DefId) -> bool {
let rty = tcx.type_of(item_def_id);
// Check that it is possible to represent this type. This call identifies
}
Representability::Representable | Representability::ContainsRecursive => (),
}
- return true
+ return true;
}
pub fn check_simd<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, sp: Span, def_id: DefId) {
}
}
-fn check_packed_inner<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
- stack: &mut Vec<DefId>) -> bool {
+fn check_packed_inner<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ def_id: DefId,
+ stack: &mut Vec<DefId>,
+) -> bool {
let t = tcx.type_of(def_id);
if stack.contains(&def_id) {
debug!("check_packed_inner: {:?} is recursive", t);
}
#[allow(trivial_numeric_casts)]
-pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- sp: Span,
- vs: &'tcx [hir::Variant],
- id: hir::HirId) {
+pub fn check_enum<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ sp: Span,
+ vs: &'tcx [hir::Variant],
+ id: hir::HirId,
+) {
let def_id = tcx.hir().local_def_id_from_hir_id(id);
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
check_transparent(tcx, sp, def_id);
}
-fn report_unexpected_variant_res<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- res: Res,
- span: Span,
- qpath: &QPath) {
+fn report_unexpected_variant_res<'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'tcx>,
+ res: Res,
+ span: Span,
+ qpath: &QPath,
+) {
span_err!(tcx.sess, span, E0533,
"expected unit struct/variant or constant, found {} `{}`",
res.descr(),
}
impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
- fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> { self.tcx }
+ fn tcx<'b>(&'b self) -> TyCtxt<'gcx, 'tcx> {
+ self.tcx
+ }
fn get_type_parameter_bounds(&self, _: Span, def_id: DefId)
-> &'tcx ty::GenericPredicates<'tcx>
}
}
-pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- generics: &ty::Generics,
- ty: Ty<'tcx>) {
+pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, generics: &ty::Generics, ty: Ty<'tcx>) {
let own_counts = generics.own_counts();
debug!(
"check_bounds_are_used(n_tys={}, n_cts={}, ty={:?})",
}
impl<'gcx, 'tcx> CheckWfFcxBuilder<'gcx, 'tcx> {
- fn with_fcx<F>(&'tcx mut self, f: F) where
- F: for<'b> FnOnce(&FnCtxt<'b, 'gcx, 'tcx>,
- TyCtxt<'gcx, 'gcx>) -> Vec<Ty<'tcx>>
+ fn with_fcx<F>(&'tcx mut self, f: F)
+ where
+ F: for<'b> FnOnce(&FnCtxt<'b, 'gcx, 'tcx>, TyCtxt<'gcx, 'gcx>) -> Vec<Ty<'tcx>>,
{
let id = self.id;
let span = self.span;
check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig);
}
-fn check_associated_item<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- item_id: hir::HirId,
- span: Span,
- sig_if_method: Option<&hir::MethodSig>) {
+fn check_associated_item<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ item_id: hir::HirId,
+ span: Span,
+ sig_if_method: Option<&hir::MethodSig>,
+) {
debug!("check_associated_item: {:?}", item_id);
let code = ObligationCauseCode::MiscObligation;
})
}
-fn for_item<'gcx: 'tcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>, item: &hir::Item)
- -> CheckWfFcxBuilder<'gcx, 'tcx> {
+fn for_item<'gcx: 'tcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'gcx>,
+ item: &hir::Item,
+) -> CheckWfFcxBuilder<'gcx, 'tcx> {
for_id(tcx, item.hir_id, item.span)
}
-fn for_id<'gcx: 'tcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>, id: hir::HirId, span: Span)
- -> CheckWfFcxBuilder<'gcx, 'tcx> {
+fn for_id<'gcx: 'tcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'gcx>,
+ id: hir::HirId,
+ span: Span,
+) -> CheckWfFcxBuilder<'gcx, 'tcx> {
let def_id = tcx.hir().local_def_id_from_hir_id(id);
CheckWfFcxBuilder {
inherited: Inherited::build(tcx, def_id),
}
/// In a type definition, we check that to ensure that the types of the fields are well-formed.
-fn check_type_defn<'tcx, F>(tcx: TyCtxt<'tcx, 'tcx>,
- item: &hir::Item, all_sized: bool, mut lookup_fields: F)
- where F: for<'fcx, 'gcx, 'tcx2> FnMut(&FnCtxt<'fcx, 'gcx, 'tcx2>) -> Vec<AdtVariant<'tcx2>>
+fn check_type_defn<'tcx, F>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ item: &hir::Item,
+ all_sized: bool,
+ mut lookup_fields: F,
+) where
+ F: for<'fcx, 'gcx, 'tcx2> FnMut(&FnCtxt<'fcx, 'gcx, 'tcx2>) -> Vec<AdtVariant<'tcx2>>,
{
for_item(tcx, item).with_fcx(|fcx, fcx_tcx| {
let variants = lookup_fields(fcx);
});
}
-fn check_impl<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- item: &hir::Item,
- ast_self_ty: &hir::Ty,
- ast_trait_ref: &Option<hir::TraitRef>)
-{
+fn check_impl<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ item: &hir::Item,
+ ast_self_ty: &hir::Ty,
+ ast_trait_ref: &Option<hir::TraitRef>,
+) {
debug!("check_impl: {:?}", item);
for_item(tcx, item).with_fcx(|fcx, tcx| {
}
}
-fn check_fn_or_method<'fcx, 'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'gcx>,
- fcx: &FnCtxt<'fcx, 'gcx, 'tcx>,
- span: Span,
- sig: ty::PolyFnSig<'tcx>,
- def_id: DefId,
- implied_bounds: &mut Vec<Ty<'tcx>>)
-{
+fn check_fn_or_method<'fcx, 'gcx, 'tcx>(
+ tcx: TyCtxt<'gcx, 'gcx>,
+ fcx: &FnCtxt<'fcx, 'gcx, 'tcx>,
+ span: Span,
+ sig: ty::PolyFnSig<'tcx>,
+ def_id: DefId,
+ implied_bounds: &mut Vec<Ty<'tcx>>,
+) {
let sig = fcx.normalize_associated_types_in(span, &sig);
let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
true
}
-fn check_variances_for_type_defn<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- item: &hir::Item,
- hir_generics: &hir::Generics)
-{
+fn check_variances_for_type_defn<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ item: &hir::Item,
+ hir_generics: &hir::Generics,
+) {
let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id);
let ty = tcx.type_of(item_def_id);
if tcx.has_error_field(ty) {
}
}
-fn report_bivariance<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- span: Span,
- param_name: ast::Name)
-{
+fn report_bivariance<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, span: Span, param_name: ast::Name) {
let mut err = error_392(tcx, span, param_name);
let suggested_marker_id = tcx.lang_items().phantom_data();
}
}
-fn error_392<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, span: Span, param_name: ast::Name)
- -> DiagnosticBuilder<'tcx> {
+fn error_392<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ span: Span,
+ param_name: ast::Name,
+) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(tcx.sess, span, E0392,
"parameter `{}` is never used", param_name);
err.span_label(span, "unused parameter");
struct Checker<'tcx> {
tcx: TyCtxt<'tcx, 'tcx>,
- trait_def_id: DefId
+ trait_def_id: DefId,
}
impl<'tcx> Checker<'tcx> {
fn check<F>(&self, trait_def_id: Option<DefId>, mut f: F) -> &Self
- where F: FnMut(TyCtxt<'tcx, 'tcx>, DefId)
+ where
+ F: FnMut(TyCtxt<'tcx, 'tcx>, DefId),
{
if Some(self.trait_def_id) == trait_def_id {
for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) {
}
}
-fn visit_implementation_of_dispatch_from_dyn<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- impl_did: DefId,
-) {
+fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, impl_did: DefId) {
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}",
impl_did);
if impl_did.is_local() {
}
}
-pub fn coerce_unsized_info<'gcx>(gcx: TyCtxt<'gcx, 'gcx>,
- impl_did: DefId)
- -> CoerceUnsizedInfo {
+pub fn coerce_unsized_info<'gcx>(gcx: TyCtxt<'gcx, 'gcx>, impl_did: DefId) -> CoerceUnsizedInfo {
debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did);
let coerce_unsized_trait = gcx.lang_items().coerce_unsized_trait().unwrap();
use syntax_pos::Span;
/// On-demand query: yields a map containing all types mapped to their inherent impls.
-pub fn crate_inherent_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- crate_num: CrateNum)
- -> &'tcx CrateInherentImpls {
+pub fn crate_inherent_impls<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ crate_num: CrateNum,
+) -> &'tcx CrateInherentImpls {
assert_eq!(crate_num, LOCAL_CRATE);
let krate = tcx.hir().krate();
}
/// On-demand query: yields a vector of the inherent impls for a specific type.
-pub fn inherent_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- ty_def_id: DefId)
- -> &'tcx [DefId] {
+pub fn inherent_impls<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ty_def_id: DefId) -> &'tcx [DefId] {
assert!(ty_def_id.is_local());
// NB. Until we adopt the red-green dep-tracking algorithm (see
use rustc::traits::{self, IntercrateMode};
use rustc::ty::TyCtxt;
-pub fn crate_inherent_impls_overlap_check<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- crate_num: CrateNum) {
+pub fn crate_inherent_impls_overlap_check<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum) {
assert_eq!(crate_num, LOCAL_CRATE);
let krate = tcx.hir().krate();
krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx });
}
struct InherentOverlapChecker<'tcx> {
- tcx: TyCtxt<'tcx, 'tcx>
+ tcx: TyCtxt<'tcx, 'tcx>,
}
impl InherentOverlapChecker<'tcx> {
fn enforce_trait_manually_implementable(
tcx: TyCtxt<'_, '_>,
impl_def_id: DefId,
- trait_def_id: DefId
+ trait_def_id: DefId,
) {
let did = Some(trait_def_id);
let li = tcx.lang_items();
fn enforce_empty_impls_for_marker_traits(
tcx: TyCtxt<'_, '_>,
impl_def_id: DefId,
- trait_def_id: DefId
+ trait_def_id: DefId,
) {
if !tcx.trait_def(trait_def_id).is_marker {
return;
/// parameter with ID `param_id`. We use this so as to avoid running
/// `ast_ty_to_ty`, because we want to avoid triggering an all-out
/// conversion of the type to avoid inducing unnecessary cycles.
-fn is_param<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- ast_ty: &hir::Ty,
- param_id: hir::HirId,
-) -> bool {
+fn is_param<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, ast_ty: &hir::Ty, param_id: hir::HirId) -> bool {
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node {
match path.res {
Res::SelfTy(Some(def_id), None) | Res::Def(DefKind::TyParam, def_id) => {
discr: ty::VariantDiscr,
def: &hir::VariantData,
adt_kind: ty::AdtKind,
- parent_did: DefId
+ parent_did: DefId,
) -> ty::VariantDef {
let mut seen_fields: FxHashMap<ast::Ident, Span> = Default::default();
let hir_id = tcx.hir().as_local_hir_id(variant_did.unwrap_or(parent_did)).unwrap();
tcx.arena.alloc(def)
}
-fn has_late_bound_regions<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- node: Node<'tcx>,
-) -> Option<Span> {
+fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, node: Node<'tcx>) -> Option<Span> {
struct LateBoundRegionsDetector<'tcx> {
tcx: TyCtxt<'tcx, 'tcx>,
outer_index: ty::DebruijnIndex,
})
}
-fn find_existential_constraints<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
-) -> Ty<'tcx> {
+fn find_existential_constraints<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
use rustc::hir::{ImplItem, Item, TraitItem};
debug!("find_existential_constraints({:?})", def_id);
}
}
-fn impl_trait_ref<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
-) -> Option<ty::TraitRef<'tcx>> {
+fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option<ty::TraitRef<'tcx>> {
let icx = ItemCtxt::new(tcx, def_id);
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
}
}
-fn static_mutability<'tcx>(
- tcx: TyCtxt<'tcx, 'tcx>,
- def_id: DefId,
-) -> Option<hir::Mutability> {
+fn static_mutability<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, def_id: DefId) -> Option<hir::Mutability> {
match tcx.hir().get_if_local(def_id) {
Some(Node::Item(&hir::Item {
node: hir::ItemKind::Static(_, mutbl, _), ..
}
}
-pub fn identify_constrained_generic_params<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- predicates: &ty::GenericPredicates<'tcx>,
- impl_trait_ref: Option<ty::TraitRef<'tcx>>,
- input_parameters: &mut FxHashSet<Parameter>)
-{
+pub fn identify_constrained_generic_params<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ predicates: &ty::GenericPredicates<'tcx>,
+ impl_trait_ref: Option<ty::TraitRef<'tcx>>,
+ input_parameters: &mut FxHashSet<Parameter>,
+) {
let mut predicates = predicates.predicates.clone();
setup_constraining_predicates(tcx, &mut predicates, impl_trait_ref, input_parameters);
}
/// which is determined by 1, which requires `U`, that is determined
/// by 0. I should probably pick a less tangled example, but I can't
/// think of any.
-pub fn setup_constraining_predicates<'tcx>(tcx: TyCtxt<'_, '_>,
- predicates: &mut [(ty::Predicate<'tcx>, Span)],
- impl_trait_ref: Option<ty::TraitRef<'tcx>>,
- input_parameters: &mut FxHashSet<Parameter>)
-{
+pub fn setup_constraining_predicates<'tcx>(
+ tcx: TyCtxt<'_, '_>,
+ predicates: &mut [(ty::Predicate<'tcx>, Span)],
+ impl_trait_ref: Option<ty::TraitRef<'tcx>>,
+ input_parameters: &mut FxHashSet<Parameter>,
+) {
// The canonical way of doing the needed topological sort
// would be a DFS, but getting the graph and its ownership
// right is annoying, so I am using an in-place fixed-point iteration,
fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem) { }
}
-fn enforce_impl_params_are_constrained<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_def_id: DefId,
- impl_item_refs: &[hir::ImplItemRef])
-{
+fn enforce_impl_params_are_constrained<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_def_id: DefId,
+ impl_item_refs: &[hir::ImplItemRef],
+) {
// Every lifetime used in an associated type must be constrained.
let impl_self_ty = tcx.type_of(impl_def_id);
let impl_generics = tcx.generics_of(impl_def_id);
// used elsewhere are not projected back out.
}
-fn report_unused_parameter(tcx: TyCtxt<'_, '_>,
- span: Span,
- kind: &str,
- name: &str)
-{
+fn report_unused_parameter(tcx: TyCtxt<'_, '_>, span: Span, kind: &str, name: &str) {
struct_span_err!(
tcx.sess, span, E0207,
"the {} parameter `{}` is not constrained by the \
}
/// Enforce that we do not have two items in an impl with the same name.
-fn enforce_impl_items_are_distinct<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- impl_item_refs: &[hir::ImplItemRef])
-{
+fn enforce_impl_items_are_distinct<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ impl_item_refs: &[hir::ImplItemRef],
+) {
let mut seen_type_items = FxHashMap::default();
let mut seen_value_items = FxHashMap::default();
for impl_item_ref in impl_item_refs {
ty: Ty<'tcx>,
}
-fn check_type_alias_enum_variants_enabled<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>,
- span: Span) {
+fn check_type_alias_enum_variants_enabled<'gcx, 'tcx>(tcx: TyCtxt<'gcx, 'tcx>, span: Span) {
if !tcx.features().type_alias_enum_variants {
let mut err = tcx.sess.struct_span_err(
span,
}
}
-fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_, '_>,
- decl: &hir::FnDecl,
- abi: Abi,
- span: Span) {
+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) {
let mut err = struct_span_err!(tcx.sess, span, E0045,
"C-variadic function must have C or cdecl calling convention");
}
}
-fn require_same_types<'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- cause: &ObligationCause<'tcx>,
- expected: Ty<'tcx>,
- actual: Ty<'tcx>)
- -> bool {
+fn require_same_types<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ cause: &ObligationCause<'tcx>,
+ expected: Ty<'tcx>,
+ actual: Ty<'tcx>,
+) -> bool {
tcx.infer_ctxt().enter(|ref infcx| {
let param_env = ty::ParamEnv::empty();
let mut fulfill_cx = TraitEngine::new(infcx.tcx);
impl_wf_check::provide(providers);
}
-pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>)
- -> Result<(), ErrorReported>
-{
+pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) -> Result<(), ErrorReported> {
tcx.sess.profiler(|p| p.start_activity("type-check crate"));
// this ensures that later parts of type checking can assume that items
astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty)
}
-pub fn hir_trait_to_predicates<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir_trait: &hir::TraitRef)
- -> (ty::PolyTraitRef<'tcx>, Bounds<'tcx>) {
+pub fn hir_trait_to_predicates<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ hir_trait: &hir::TraitRef,
+) -> (ty::PolyTraitRef<'tcx>, Bounds<'tcx>) {
// In case there are any projections, etc., find the "environment"
// def-ID that will be used to determine the traits/predicates in
// scope. This is derived from the enclosing item-like thing.
};
}
-fn crate_variances<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, crate_num: CrateNum)
- -> &'tcx CrateVariancesMap<'tcx> {
+fn crate_variances<'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ crate_num: CrateNum,
+) -> &'tcx CrateVariancesMap<'tcx> {
assert_eq!(crate_num, LOCAL_CRATE);
let mut arena = arena::TypedArena::default();
let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &mut arena);
tcx.arena.alloc(solve::solve_constraints(constraints_cx))
}
-fn variances_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, item_def_id: DefId)
- -> &'tcx [ty::Variance] {
+fn variances_of<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, item_def_id: DefId) -> &'tcx [ty::Variance] {
let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id");
let unsupported = || {
// Variance not relevant.
pub inferred_terms: Vec<VarianceTermPtr<'a>>,
}
-pub fn determine_parameters_to_be_inferred<'a, 'tcx>(tcx: TyCtxt<'tcx, 'tcx>,
- arena: &'a mut TypedArena<VarianceTerm<'a>>)
- -> TermsContext<'a, 'tcx> {
+pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
+ tcx: TyCtxt<'tcx, 'tcx>,
+ arena: &'a mut TypedArena<VarianceTerm<'a>>,
+) -> TermsContext<'a, 'tcx> {
let mut terms_cx = TermsContext {
tcx,
arena,
}
struct VarianceTest<'tcx> {
- tcx: TyCtxt<'tcx, 'tcx>
+ tcx: TyCtxt<'tcx, 'tcx>,
}
impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> {
-thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1085:5
+thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1084:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: internal compiler error: unexpected panic