Make librustc_infer compile.

This commit is contained in:
Camille GILLOT 2020-01-06 20:13:24 +01:00
parent 187a9741d3
commit f07e889145
34 changed files with 284 additions and 88 deletions

View File

@ -3776,6 +3776,28 @@ dependencies = [
"smallvec 1.0.0",
]
[[package]]
name = "rustc_infer"
version = "0.0.0"
dependencies = [
"fmt_macros",
"graphviz",
"log",
"rustc",
"rustc_attr",
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc_macros",
"rustc_session",
"rustc_span",
"rustc_target",
"smallvec 1.0.0",
"syntax",
]
[[package]]
name = "rustc_interface"
version = "0.0.0"
@ -3838,6 +3860,7 @@ dependencies = [
"rustc_feature",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_session",
"rustc_span",
"rustc_target",
@ -3907,6 +3930,7 @@ dependencies = [
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_lexer",
"rustc_macros",
"rustc_span",
@ -3929,6 +3953,7 @@ dependencies = [
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_macros",
"rustc_session",
"rustc_span",
@ -3969,6 +3994,7 @@ dependencies = [
"rustc_feature",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_session",
"rustc_span",
"rustc_target",
@ -4019,6 +4045,7 @@ dependencies = [
"rustc_expand",
"rustc_feature",
"rustc_hir",
"rustc_infer",
"rustc_metadata",
"rustc_session",
"rustc_span",
@ -4108,6 +4135,7 @@ dependencies = [
"rustc",
"rustc_data_structures",
"rustc_hir",
"rustc_infer",
"rustc_macros",
"rustc_span",
"rustc_target",
@ -4123,6 +4151,7 @@ dependencies = [
"rustc",
"rustc_data_structures",
"rustc_hir",
"rustc_infer",
"rustc_span",
"rustc_target",
]
@ -4139,6 +4168,7 @@ dependencies = [
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_span",
"rustc_target",
"smallvec 1.0.0",

View File

@ -0,0 +1,28 @@
[package]
authors = ["The Rust Project Developers"]
name = "rustc_infer"
version = "0.0.0"
edition = "2018"
[lib]
name = "rustc_infer"
path = "lib.rs"
doctest = false
[dependencies]
fmt_macros = { path = "../libfmt_macros" }
graphviz = { path = "../libgraphviz" }
log = { version = "0.4", features = ["release_max_level_info", "std"] }
rustc_attr = { path = "../librustc_attr" }
rustc = { path = "../librustc" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
rustc_error_codes = { path = "../librustc_error_codes" }
rustc_hir = { path = "../librustc_hir" }
rustc_index = { path = "../librustc_index" }
rustc_macros = { path = "../librustc_macros" }
rustc_session = { path = "../librustc_session" }
rustc_span = { path = "../librustc_span" }
rustc_target = { path = "../librustc_target" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
syntax = { path = "../libsyntax" }

View File

@ -29,12 +29,11 @@ use rustc::ty::{self, BoundVar, List};
use rustc_index::vec::IndexVec;
use rustc_span::source_map::Span;
pub use rustc::infer::types::canonical::*;
pub use rustc::infer::canonical::*;
use substitute::CanonicalExt;
mod canonicalizer;
pub mod query_response;
mod substitute;
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {

View File

@ -8,7 +8,7 @@
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
use crate::arena::ArenaAllocatable;
use crate::infer::canonical::substitute::substitute_value;
use crate::infer::canonical::substitute::{substitute_value, CanonicalExt};
use crate::infer::canonical::{
Canonical, CanonicalVarValues, CanonicalizedQueryResponse, Certainty, OriginalQueryValues,
QueryOutlivesConstraint, QueryRegionConstraints, QueryResponse,
@ -19,9 +19,9 @@ use crate::infer::{InferCtxt, InferOk, InferResult};
use crate::traits::query::{Fallible, NoSolution};
use crate::traits::TraitEngine;
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
use crate::ty::fold::TypeFoldable;
use crate::ty::subst::{GenericArg, GenericArgKind};
use crate::ty::{self, BoundVar, Ty, TyCtxt};
use rustc::ty::fold::TypeFoldable;
use rustc::ty::subst::{GenericArg, GenericArgKind};
use rustc::ty::{self, BoundVar, Ty, TyCtxt};
use rustc_data_structures::captures::Captures;
use rustc_index::vec::Idx;
use rustc_index::vec::IndexVec;

View File

@ -11,15 +11,12 @@ use crate::ty::fold::TypeFoldable;
use crate::ty::subst::GenericArgKind;
use crate::ty::{self, TyCtxt};
impl<'tcx, V> Canonical<'tcx, V> {
pub(super) trait CanonicalExt<'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
fn substitute(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
where
V: TypeFoldable<'tcx>,
{
self.substitute_projected(tcx, var_values, |value| value)
}
V: TypeFoldable<'tcx>;
/// Allows one to apply a substitute to some subset of
/// `self.value`. Invoke `projection_fn` with `self.value` to get
@ -27,7 +24,25 @@ impl<'tcx, V> Canonical<'tcx, V> {
/// variables bound in `self` (usually this extracts from subset
/// of `self`). Apply the substitution `var_values` to this value
/// V, replacing each of the canonical variables.
pub fn substitute_projected<T>(
fn substitute_projected<T>(
&self,
tcx: TyCtxt<'tcx>,
var_values: &CanonicalVarValues<'tcx>,
projection_fn: impl FnOnce(&V) -> &T,
) -> T
where
T: TypeFoldable<'tcx>;
}
impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
fn substitute(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
where
V: TypeFoldable<'tcx>,
{
self.substitute_projected(tcx, var_values, |value| value)
}
fn substitute_projected<T>(
&self,
tcx: TyCtxt<'tcx>,
var_values: &CanonicalVarValues<'tcx>,

View File

@ -49,17 +49,18 @@ use super::lexical_region_resolve::RegionResolutionError;
use super::region_constraints::GenericKind;
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
use crate::hir::map;
use crate::infer::opaque_types;
use crate::infer::{self, SuppressRegionErrors};
use crate::middle::region;
use crate::traits::error_reporting::report_object_safety_error;
use crate::traits::object_safety_violations;
use crate::traits::{
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
};
use crate::ty::error::TypeError;
use crate::ty::{
use rustc::hir::map;
use rustc::middle::region;
use rustc::ty::error::TypeError;
use rustc::ty::{
self,
subst::{Subst, SubstsRef},
Region, Ty, TyCtxt, TypeFoldable,
@ -2005,7 +2006,12 @@ enum FailureCode {
Error0644(&'static str),
}
impl<'tcx> ObligationCause<'tcx> {
trait ObligationCauseExt<'tcx> {
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode;
fn as_requirement_str(&self) -> &'static str;
}
impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode {
use self::FailureCode::*;
use crate::traits::ObligationCauseCode::*;

View File

@ -1,8 +1,8 @@
use crate::infer::error_reporting::note_and_explain_region;
use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt};
use crate::infer::{self, InferCtxt, SubregionOrigin};
use crate::middle::region;
use crate::ty::error::TypeError;
use crate::ty::{self, Region};
use rustc::middle::region;
use rustc::ty::error::TypeError;
use rustc::ty::{self, Region};
use rustc_errors::{struct_span_err, DiagnosticBuilder};
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

View File

@ -7,19 +7,21 @@ pub use self::SubregionOrigin::*;
pub use self::ValuePairs::*;
pub use crate::ty::IntVarValue;
use crate::infer::canonical::{Canonical, CanonicalVarValues};
use crate::infer::unify_key::{ConstVarValue, ConstVariableValue};
use crate::middle::free_region::RegionRelations;
use crate::middle::lang_items;
use crate::middle::region;
use crate::session::config::BorrowckMode;
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
use crate::ty::fold::{TypeFoldable, TypeFolder};
use crate::ty::relate::RelateResult;
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
use crate::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
use crate::ty::{ConstVid, FloatVid, IntVid, TyVid};
use rustc::infer::canonical::{Canonical, CanonicalVarValues};
use rustc::infer::unify_key::{ConstVarValue, ConstVariableValue};
use rustc::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
use rustc::middle::free_region::RegionRelations;
use rustc::middle::lang_items;
use rustc::middle::region;
use rustc::session::config::BorrowckMode;
use rustc::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
use rustc::ty::fold::{TypeFoldable, TypeFolder};
use rustc::ty::relate::RelateResult;
use rustc::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
use rustc::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
use rustc::ty::{ConstVid, FloatVid, IntVid, TyVid};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
@ -40,7 +42,6 @@ use self::outlives::env::OutlivesEnvironment;
use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, VerifyBound};
use self::region_constraints::{RegionConstraintCollector, RegionSnapshot};
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use self::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
pub mod at;
pub mod canonical;
@ -61,8 +62,8 @@ pub mod region_constraints;
pub mod resolve;
mod sub;
pub mod type_variable;
mod types;
pub mod unify_key;
pub use rustc::infer::unify_key;
#[must_use]
#[derive(Debug)]
@ -524,8 +525,12 @@ pub struct InferCtxtBuilder<'tcx> {
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
}
impl TyCtxt<'tcx> {
pub fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
pub trait TyCtxtInferExt<'tcx> {
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx>;
}
impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
InferCtxtBuilder { global_tcx: self, fresh_tables: None }
}
}

View File

@ -66,8 +66,10 @@ use crate::traits::ObligationCause;
use crate::ty::outlives::Component;
use crate::ty::subst::GenericArgKind;
use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use smallvec::smallvec;
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// Registers that the given region obligation must be resolved

View File

@ -6,6 +6,8 @@ use crate::ty::{self, Ty, TyCtxt};
use rustc_data_structures::captures::Captures;
use rustc_hir::def_id::DefId;
use smallvec::smallvec;
/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
/// obligation into a series of `'a: 'b` constraints and "verifys", as
/// described on the module comment. The final constraints are emitted

View File

@ -6,10 +6,10 @@ use self::UndoLog::*;
use super::unify_key;
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
use crate::ty::ReStatic;
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::{ReLateBound, ReVar};
use crate::ty::{Region, RegionVid};
use rustc::ty::ReStatic;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::{ReLateBound, ReVar};
use rustc::ty::{Region, RegionVid};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::unify as ut;
@ -23,7 +23,7 @@ use std::{cmp, fmt, mem};
mod leak_check;
pub use rustc::infer::types::MemberConstraint;
pub use rustc::infer::MemberConstraint;
#[derive(Default)]
pub struct RegionConstraintCollector<'tcx> {

67
src/librustc_infer/lib.rs Normal file
View File

@ -0,0 +1,67 @@
//! This crates defines the trait resolution method and the type inference engine.
//!
//! - **Traits.** Trait resolution is implemented in the `traits` module.
//! - **Type inference.** The type inference code can be found in the `infer` module;
//! this code handles low-level equality and subtyping operations. The
//! type check pass in the compiler is found in the `librustc_typeck` crate.
//!
//! For more information about how rustc works, see the [rustc guide].
//!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/
//!
//! # Note
//!
//! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(arbitrary_self_types)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(const_fn)]
#![feature(const_transmute)]
#![feature(core_intrinsics)]
#![feature(drain_filter)]
#![cfg_attr(windows, feature(libc))]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(overlapping_marker_traits)]
#![feature(extern_types)]
#![feature(nll)]
#![feature(optin_builtin_traits)]
#![feature(option_expect_none)]
#![feature(range_is_empty)]
#![feature(specialization)]
#![feature(unboxed_closures)]
#![feature(thread_local)]
#![feature(trace_macros)]
#![feature(trusted_len)]
#![feature(stmt_expr_attributes)]
#![feature(integer_atomics)]
#![feature(test)]
#![feature(in_band_lifetimes)]
#![feature(crate_visibility_modifier)]
#![feature(log_syntax)]
#![feature(associated_type_bounds)]
#![feature(rustc_attrs)]
#![feature(hash_raw_entry)]
#![recursion_limit = "512"]
#[macro_use]
extern crate rustc_macros;
#[macro_use]
extern crate rustc_data_structures;
#[macro_use]
extern crate log;
#[macro_use]
extern crate rustc;
use rustc::arena;
use rustc::dep_graph;
use rustc::hir;
pub mod infer;
use rustc::middle;
pub use rustc_session as session;
pub mod traits;
use rustc::ty;
use rustc::util;

View File

@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, OriginalQueryValues};
use crate::infer::canonical::OriginalQueryValues;
use crate::infer::InferCtxt;
use crate::traits::query::NoSolution;
use crate::traits::{
@ -8,7 +8,7 @@ use crate::traits::{
use crate::ty::{self, Ty};
use rustc_data_structures::fx::FxHashSet;
pub type CanonicalGoal<'tcx> = Canonical<'tcx, InEnvironment<'tcx, ty::Predicate<'tcx>>>;
pub use rustc::traits::ChalkCanonicalGoal as CanonicalGoal;
pub struct FulfillmentContext<'tcx> {
obligations: FxHashSet<InEnvironment<'tcx, PredicateObligation<'tcx>>>,

View File

@ -3,7 +3,7 @@
// seems likely that they should eventually be merged into more
// general routines.
use crate::infer::InferCtxt;
use crate::infer::{InferCtxt, TyCtxtInferExt};
use crate::traits::{
FulfillmentContext, Obligation, ObligationCause, SelectionContext, TraitEngine, Vtable,
};

View File

@ -4,7 +4,7 @@
//! [trait-resolution]: https://rust-lang.github.io/rustc-guide/traits/resolution.html
//! [trait-specialization]: https://rust-lang.github.io/rustc-guide/traits/specialization.html
use crate::infer::{CombinedSnapshot, InferOk};
use crate::infer::{CombinedSnapshot, InferOk, TyCtxtInferExt};
use crate::traits::select::IntercrateAmbiguityCause;
use crate::traits::SkipLeakCheck;
use crate::traits::{self, Normalized, Obligation, ObligationCause, SelectionContext};

View File

@ -11,18 +11,17 @@ use super::{
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::{self, InferCtxt};
use crate::mir::interpret::ErrorHandled;
use crate::session::DiagnosticMessageId;
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
use crate::traits::object_safety_violations;
use crate::ty::error::ExpectedFound;
use crate::ty::fast_reject;
use crate::ty::fold::TypeFolder;
use crate::ty::SubtypePredicate;
use crate::ty::{
use rustc::mir::interpret::ErrorHandled;
use rustc::session::DiagnosticMessageId;
use rustc::ty::error::ExpectedFound;
use rustc::ty::fast_reject;
use rustc::ty::fold::TypeFolder;
use rustc::ty::SubtypePredicate;
use rustc::ty::{
self, AdtKind, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;

View File

@ -1,8 +1,9 @@
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
use crate::infer::TyCtxtInferExt;
use crate::traits::{self, ObligationCause};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_hir as hir;
#[derive(Clone)]

View File

@ -19,12 +19,11 @@ mod select;
mod specialize;
mod structural_impls;
mod structural_match;
mod types;
mod util;
pub mod wf;
use crate::infer::outlives::env::OutlivesEnvironment;
use crate::infer::{InferCtxt, SuppressRegionErrors};
use crate::infer::{InferCtxt, SuppressRegionErrors, TyCtxtInferExt};
use crate::middle::region;
use crate::ty::error::{ExpectedFound, TypeError};
use crate::ty::fold::TypeFoldable;
@ -38,6 +37,9 @@ use rustc_span::{Span, DUMMY_SP};
use std::fmt::Debug;
pub use self::FulfillmentErrorCode::*;
pub use self::ObligationCauseCode::*;
pub use self::SelectionError::*;
pub use self::Vtable::*;
pub use self::coherence::{add_placeholder_note, orphan_check, overlapping_impls};
pub use self::coherence::{OrphanCheckErr, OverlapResult};
@ -53,8 +55,9 @@ pub use self::project::MismatchedProjectionTypes;
pub use self::project::{
normalize, normalize_projection_type, normalize_to, poly_project_and_unify_type,
};
pub use self::project::{Normalized, ProjectionCache, ProjectionCacheSnapshot};
pub use self::select::{IntercrateAmbiguityCause, SelectionContext};
pub use self::project::{Normalized, ProjectionCache, ProjectionCacheSnapshot, Reveal};
pub use self::select::{EvaluationCache, SelectionCache, SelectionContext};
pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError};
pub use self::specialize::find_associated_item;
pub use self::specialize::specialization_graph::FutureCompatOverlapError;
pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
@ -76,7 +79,7 @@ pub use self::chalk_fulfill::{
CanonicalGoal as ChalkCanonicalGoal, FulfillmentContext as ChalkFulfillmentContext,
};
pub use self::types::*;
pub use rustc::traits::*;
/// Whether to skip the leak check, as part of a future compatibility warning step.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]

View File

@ -10,6 +10,7 @@
use super::elaborate_predicates;
use crate::infer::TyCtxtInferExt;
use crate::traits::{self, Obligation, ObligationCause};
use crate::ty::subst::{InternalSubsts, Subst};
use crate::ty::{self, Predicate, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};

View File

@ -12,4 +12,4 @@ pub mod normalize;
pub mod outlives_bounds;
pub mod type_op;
pub use rustc::traits::types::query::*;
pub use rustc::traits::query::*;

View File

@ -19,7 +19,7 @@ pub mod prove_predicate;
use self::prove_predicate::ProvePredicate;
pub mod subtype;
pub use crate::traits::types::query::type_op::*;
pub use rustc::traits::query::type_op::*;
/// "Type ops" are used in NLL to perform some particular action and
/// extract out the resulting region constraints (or an error if it

View File

@ -54,7 +54,7 @@ use std::fmt::{self, Display};
use std::iter;
use std::rc::Rc;
pub use rustc::traits::types::select::*;
pub use rustc::traits::select::*;
pub struct SelectionContext<'cx, 'tcx> {
infcx: &'cx InferCtxt<'cx, 'tcx>,

View File

@ -10,8 +10,9 @@
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/specialization.html
pub mod specialization_graph;
use specialization_graph::GraphExt;
use crate::infer::{InferCtxt, InferOk};
use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use crate::traits::select::IntercrateAmbiguityCause;
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};

View File

@ -5,7 +5,7 @@ use rustc::ty::fast_reject::{self, SimplifiedType};
use rustc::ty::{self, TyCtxt, TypeFoldable};
use rustc_hir::def_id::DefId;
pub use rustc::traits::types::specialization_graph::*;
pub use rustc::traits::specialization_graph::*;
#[derive(Copy, Clone, Debug)]
pub enum FutureCompatOverlapErrorKind {
@ -31,7 +31,19 @@ enum Inserted {
ShouldRecurseOn(DefId),
}
impl<'tcx> Children {
trait ChildrenExt {
fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId);
fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId);
fn insert(
&mut self,
tcx: TyCtxt<'tcx>,
impl_def_id: DefId,
simplified_self: Option<SimplifiedType>,
) -> Result<Inserted, OverlapError>;
}
impl ChildrenExt for Children {
/// Insert an impl into this set of children without comparing to any existing impls.
fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
@ -76,8 +88,8 @@ impl<'tcx> Children {
debug!("insert(impl_def_id={:?}, simplified_self={:?})", impl_def_id, simplified_self,);
let possible_siblings = match simplified_self {
Some(st) => PotentialSiblings::Filtered(self.filtered(st)),
None => PotentialSiblings::Unfiltered(self.iter()),
Some(st) => PotentialSiblings::Filtered(filtered_children(self, st)),
None => PotentialSiblings::Unfiltered(iter_children(self)),
};
for possible_sibling in possible_siblings {
@ -199,16 +211,19 @@ impl<'tcx> Children {
self.insert_blindly(tcx, impl_def_id);
Ok(Inserted::BecameNewSibling(last_lint))
}
}
fn iter(&mut self) -> impl Iterator<Item = DefId> + '_ {
let nonblanket = self.nonblanket_impls.iter_mut().flat_map(|(_, v)| v.iter());
self.blanket_impls.iter().chain(nonblanket).cloned()
}
fn iter_children(children: &mut Children) -> impl Iterator<Item = DefId> + '_ {
let nonblanket = children.nonblanket_impls.iter_mut().flat_map(|(_, v)| v.iter());
children.blanket_impls.iter().chain(nonblanket).cloned()
}
fn filtered(&mut self, st: SimplifiedType) -> impl Iterator<Item = DefId> + '_ {
let nonblanket = self.nonblanket_impls.entry(st).or_default().iter();
self.blanket_impls.iter().chain(nonblanket).cloned()
}
fn filtered_children(
children: &mut Children,
st: SimplifiedType,
) -> impl Iterator<Item = DefId> + '_ {
let nonblanket = children.nonblanket_impls.entry(st).or_default().iter();
children.blanket_impls.iter().chain(nonblanket).cloned()
}
// A custom iterator used by Children::insert
@ -236,11 +251,25 @@ where
}
}
impl<'tcx> Graph {
pub trait GraphExt {
/// 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(
fn insert(
&mut self,
tcx: TyCtxt<'tcx>,
impl_def_id: DefId,
) -> Result<Option<FutureCompatOverlapError>, OverlapError>;
/// Insert cached metadata mapping from a child impl back to its parent.
fn record_impl_from_cstore(&mut self, tcx: TyCtxt<'tcx>, parent: DefId, child: DefId);
}
impl GraphExt for Graph {
/// 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`.
fn insert(
&mut self,
tcx: TyCtxt<'tcx>,
impl_def_id: DefId,
@ -337,7 +366,7 @@ impl<'tcx> Graph {
}
/// Insert cached metadata mapping from a child impl back to its parent.
pub fn record_impl_from_cstore(&mut self, tcx: TyCtxt<'tcx>, parent: DefId, child: DefId) {
fn record_impl_from_cstore(&mut self, tcx: TyCtxt<'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 \

View File

@ -1,9 +1,8 @@
use crate::ty::fold::{TypeFoldable, TypeVisitor};
use crate::ty::{self, AdtDef, Ty, TyCtxt};
use crate::infer::{InferCtxt, TyCtxtInferExt};
use crate::traits::ObligationCause;
use crate::traits::{self, ConstPatternStructural, TraitEngine};
use rustc::infer::InferCtxt;
use rustc::traits::ObligationCause;
use rustc::traits::{self, ConstPatternStructural, TraitEngine};
use rustc::ty::{self, AdtDef, Ty, TyCtxt, TypeFoldable, TypeVisitor};
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_span::Span;

View File

@ -1,5 +1,6 @@
use rustc_errors::DiagnosticBuilder;
use rustc_span::Span;
use smallvec::smallvec;
use smallvec::SmallVec;
use crate::ty::outlives::Component;

View File

@ -23,3 +23,4 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_feature = { path = "../librustc_feature" }
rustc_index = { path = "../librustc_index" }
rustc_session = { path = "../librustc_session" }
rustc_infer = { path = "../librustc_infer" }

View File

@ -23,6 +23,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
rustc_hir = { path = "../librustc_hir" }
rustc_index = { path = "../librustc_index" }
rustc_infer = { path = "../librustc_infer" }
rustc_lexer = { path = "../librustc_lexer" }
rustc_macros = { path = "../librustc_macros" }
rustc_serialize = { path = "../libserialize", package = "serialize" }

View File

@ -19,6 +19,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_index = { path = "../librustc_index" }
rustc_errors = { path = "../librustc_errors" }
rustc_hir = { path = "../librustc_hir" }
rustc_infer = { path = "../librustc_infer" }
rustc_macros = { path = "../librustc_macros" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
rustc_session = { path = "../librustc_session" }

View File

@ -17,6 +17,7 @@ rustc_errors = { path = "../librustc_errors" }
rustc_feature = { path = "../librustc_feature" }
rustc_hir = { path = "../librustc_hir" }
rustc_index = { path = "../librustc_index" }
rustc_infer = { path = "../librustc_infer" }
rustc_session = { path = "../librustc_session" }
rustc_target = { path = "../librustc_target" }
syntax = { path = "../libsyntax" }

View File

@ -24,6 +24,7 @@ rustc_errors = { path = "../librustc_errors" }
rustc_expand = { path = "../librustc_expand" }
rustc_feature = { path = "../librustc_feature" }
rustc_hir = { path = "../librustc_hir" }
rustc_infer = { path = "../librustc_infer" }
rustc_metadata = { path = "../librustc_metadata" }
rustc_session = { path = "../librustc_session" }
rustc_span = { path = "../librustc_span" }

View File

@ -19,3 +19,4 @@ syntax = { path = "../libsyntax" }
rustc_span = { path = "../librustc_span" }
chalk-engine = { version = "0.9.0", default-features=false }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_infer = { path = "../librustc_infer" }

View File

@ -13,5 +13,6 @@ log = "0.4"
rustc = { path = "../librustc" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_hir = { path = "../librustc_hir" }
rustc_infer = { path = "../librustc_infer" }
rustc_span = { path = "../librustc_span" }
rustc_target = { path = "../librustc_target" }

View File

@ -23,3 +23,4 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] }
syntax = { path = "../libsyntax" }
rustc_span = { path = "../librustc_span" }
rustc_index = { path = "../librustc_index" }
rustc_infer = { path = "../librustc_infer" }