Skip to content

Commit f07e889

Browse files
committed
Make librustc_infer compile.
1 parent 187a974 commit f07e889

File tree

34 files changed

+284
-88
lines changed

34 files changed

+284
-88
lines changed

Cargo.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,6 +3776,28 @@ dependencies = [
37763776
"smallvec 1.0.0",
37773777
]
37783778

3779+
[[package]]
3780+
name = "rustc_infer"
3781+
version = "0.0.0"
3782+
dependencies = [
3783+
"fmt_macros",
3784+
"graphviz",
3785+
"log",
3786+
"rustc",
3787+
"rustc_attr",
3788+
"rustc_data_structures",
3789+
"rustc_error_codes",
3790+
"rustc_errors",
3791+
"rustc_hir",
3792+
"rustc_index",
3793+
"rustc_macros",
3794+
"rustc_session",
3795+
"rustc_span",
3796+
"rustc_target",
3797+
"smallvec 1.0.0",
3798+
"syntax",
3799+
]
3800+
37793801
[[package]]
37803802
name = "rustc_interface"
37813803
version = "0.0.0"
@@ -3838,6 +3860,7 @@ dependencies = [
38383860
"rustc_feature",
38393861
"rustc_hir",
38403862
"rustc_index",
3863+
"rustc_infer",
38413864
"rustc_session",
38423865
"rustc_span",
38433866
"rustc_target",
@@ -3907,6 +3930,7 @@ dependencies = [
39073930
"rustc_errors",
39083931
"rustc_hir",
39093932
"rustc_index",
3933+
"rustc_infer",
39103934
"rustc_lexer",
39113935
"rustc_macros",
39123936
"rustc_span",
@@ -3929,6 +3953,7 @@ dependencies = [
39293953
"rustc_errors",
39303954
"rustc_hir",
39313955
"rustc_index",
3956+
"rustc_infer",
39323957
"rustc_macros",
39333958
"rustc_session",
39343959
"rustc_span",
@@ -3969,6 +3994,7 @@ dependencies = [
39693994
"rustc_feature",
39703995
"rustc_hir",
39713996
"rustc_index",
3997+
"rustc_infer",
39723998
"rustc_session",
39733999
"rustc_span",
39744000
"rustc_target",
@@ -4019,6 +4045,7 @@ dependencies = [
40194045
"rustc_expand",
40204046
"rustc_feature",
40214047
"rustc_hir",
4048+
"rustc_infer",
40224049
"rustc_metadata",
40234050
"rustc_session",
40244051
"rustc_span",
@@ -4108,6 +4135,7 @@ dependencies = [
41084135
"rustc",
41094136
"rustc_data_structures",
41104137
"rustc_hir",
4138+
"rustc_infer",
41114139
"rustc_macros",
41124140
"rustc_span",
41134141
"rustc_target",
@@ -4123,6 +4151,7 @@ dependencies = [
41234151
"rustc",
41244152
"rustc_data_structures",
41254153
"rustc_hir",
4154+
"rustc_infer",
41264155
"rustc_span",
41274156
"rustc_target",
41284157
]
@@ -4139,6 +4168,7 @@ dependencies = [
41394168
"rustc_errors",
41404169
"rustc_hir",
41414170
"rustc_index",
4171+
"rustc_infer",
41424172
"rustc_span",
41434173
"rustc_target",
41444174
"smallvec 1.0.0",

src/librustc_infer/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_infer"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "rustc_infer"
9+
path = "lib.rs"
10+
doctest = false
11+
12+
[dependencies]
13+
fmt_macros = { path = "../libfmt_macros" }
14+
graphviz = { path = "../libgraphviz" }
15+
log = { version = "0.4", features = ["release_max_level_info", "std"] }
16+
rustc_attr = { path = "../librustc_attr" }
17+
rustc = { path = "../librustc" }
18+
rustc_data_structures = { path = "../librustc_data_structures" }
19+
rustc_errors = { path = "../librustc_errors" }
20+
rustc_error_codes = { path = "../librustc_error_codes" }
21+
rustc_hir = { path = "../librustc_hir" }
22+
rustc_index = { path = "../librustc_index" }
23+
rustc_macros = { path = "../librustc_macros" }
24+
rustc_session = { path = "../librustc_session" }
25+
rustc_span = { path = "../librustc_span" }
26+
rustc_target = { path = "../librustc_target" }
27+
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
28+
syntax = { path = "../libsyntax" }

src/librustc_infer/infer/canonical/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ use rustc::ty::{self, BoundVar, List};
2929
use rustc_index::vec::IndexVec;
3030
use rustc_span::source_map::Span;
3131

32-
pub use rustc::infer::types::canonical::*;
32+
pub use rustc::infer::canonical::*;
33+
use substitute::CanonicalExt;
3334

3435
mod canonicalizer;
35-
3636
pub mod query_response;
37-
3837
mod substitute;
3938

4039
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {

src/librustc_infer/infer/canonical/query_response.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
99
1010
use crate::arena::ArenaAllocatable;
11-
use crate::infer::canonical::substitute::substitute_value;
11+
use crate::infer::canonical::substitute::{substitute_value, CanonicalExt};
1212
use crate::infer::canonical::{
1313
Canonical, CanonicalVarValues, CanonicalizedQueryResponse, Certainty, OriginalQueryValues,
1414
QueryOutlivesConstraint, QueryRegionConstraints, QueryResponse,
@@ -19,9 +19,9 @@ use crate::infer::{InferCtxt, InferOk, InferResult};
1919
use crate::traits::query::{Fallible, NoSolution};
2020
use crate::traits::TraitEngine;
2121
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
22-
use crate::ty::fold::TypeFoldable;
23-
use crate::ty::subst::{GenericArg, GenericArgKind};
24-
use crate::ty::{self, BoundVar, Ty, TyCtxt};
22+
use rustc::ty::fold::TypeFoldable;
23+
use rustc::ty::subst::{GenericArg, GenericArgKind};
24+
use rustc::ty::{self, BoundVar, Ty, TyCtxt};
2525
use rustc_data_structures::captures::Captures;
2626
use rustc_index::vec::Idx;
2727
use rustc_index::vec::IndexVec;

src/librustc_infer/infer/canonical/substitute.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,38 @@ use crate::ty::fold::TypeFoldable;
1111
use crate::ty::subst::GenericArgKind;
1212
use crate::ty::{self, TyCtxt};
1313

14-
impl<'tcx, V> Canonical<'tcx, V> {
14+
pub(super) trait CanonicalExt<'tcx, V> {
1515
/// Instantiate the wrapped value, replacing each canonical value
1616
/// with the value given in `var_values`.
17-
pub fn substitute(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
17+
fn substitute(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
1818
where
19-
V: TypeFoldable<'tcx>,
20-
{
21-
self.substitute_projected(tcx, var_values, |value| value)
22-
}
19+
V: TypeFoldable<'tcx>;
2320

2421
/// Allows one to apply a substitute to some subset of
2522
/// `self.value`. Invoke `projection_fn` with `self.value` to get
2623
/// a value V that is expressed in terms of the same canonical
2724
/// variables bound in `self` (usually this extracts from subset
2825
/// of `self`). Apply the substitution `var_values` to this value
2926
/// V, replacing each of the canonical variables.
30-
pub fn substitute_projected<T>(
27+
fn substitute_projected<T>(
28+
&self,
29+
tcx: TyCtxt<'tcx>,
30+
var_values: &CanonicalVarValues<'tcx>,
31+
projection_fn: impl FnOnce(&V) -> &T,
32+
) -> T
33+
where
34+
T: TypeFoldable<'tcx>;
35+
}
36+
37+
impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
38+
fn substitute(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
39+
where
40+
V: TypeFoldable<'tcx>,
41+
{
42+
self.substitute_projected(tcx, var_values, |value| value)
43+
}
44+
45+
fn substitute_projected<T>(
3146
&self,
3247
tcx: TyCtxt<'tcx>,
3348
var_values: &CanonicalVarValues<'tcx>,

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,18 @@ use super::lexical_region_resolve::RegionResolutionError;
4949
use super::region_constraints::GenericKind;
5050
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
5151

52-
use crate::hir::map;
5352
use crate::infer::opaque_types;
5453
use crate::infer::{self, SuppressRegionErrors};
55-
use crate::middle::region;
5654
use crate::traits::error_reporting::report_object_safety_error;
5755
use crate::traits::object_safety_violations;
5856
use crate::traits::{
5957
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
6058
};
61-
use crate::ty::error::TypeError;
62-
use crate::ty::{
59+
60+
use rustc::hir::map;
61+
use rustc::middle::region;
62+
use rustc::ty::error::TypeError;
63+
use rustc::ty::{
6364
self,
6465
subst::{Subst, SubstsRef},
6566
Region, Ty, TyCtxt, TypeFoldable,
@@ -2005,7 +2006,12 @@ enum FailureCode {
20052006
Error0644(&'static str),
20062007
}
20072008

2008-
impl<'tcx> ObligationCause<'tcx> {
2009+
trait ObligationCauseExt<'tcx> {
2010+
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode;
2011+
fn as_requirement_str(&self) -> &'static str;
2012+
}
2013+
2014+
impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
20092015
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode {
20102016
use self::FailureCode::*;
20112017
use crate::traits::ObligationCauseCode::*;

src/librustc_infer/infer/error_reporting/note.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::infer::error_reporting::note_and_explain_region;
1+
use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt};
22
use crate::infer::{self, InferCtxt, SubregionOrigin};
3-
use crate::middle::region;
4-
use crate::ty::error::TypeError;
5-
use crate::ty::{self, Region};
3+
use rustc::middle::region;
4+
use rustc::ty::error::TypeError;
5+
use rustc::ty::{self, Region};
66
use rustc_errors::{struct_span_err, DiagnosticBuilder};
77

88
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

src/librustc_infer/infer/mod.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ pub use self::SubregionOrigin::*;
77
pub use self::ValuePairs::*;
88
pub use crate::ty::IntVarValue;
99

10-
use crate::infer::canonical::{Canonical, CanonicalVarValues};
11-
use crate::infer::unify_key::{ConstVarValue, ConstVariableValue};
12-
use crate::middle::free_region::RegionRelations;
13-
use crate::middle::lang_items;
14-
use crate::middle::region;
15-
use crate::session::config::BorrowckMode;
1610
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
17-
use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
18-
use crate::ty::fold::{TypeFoldable, TypeFolder};
19-
use crate::ty::relate::RelateResult;
20-
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
21-
use crate::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
22-
use crate::ty::{ConstVid, FloatVid, IntVid, TyVid};
11+
12+
use rustc::infer::canonical::{Canonical, CanonicalVarValues};
13+
use rustc::infer::unify_key::{ConstVarValue, ConstVariableValue};
14+
use rustc::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
15+
use rustc::middle::free_region::RegionRelations;
16+
use rustc::middle::lang_items;
17+
use rustc::middle::region;
18+
use rustc::session::config::BorrowckMode;
19+
use rustc::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
20+
use rustc::ty::fold::{TypeFoldable, TypeFolder};
21+
use rustc::ty::relate::RelateResult;
22+
use rustc::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
23+
use rustc::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
24+
use rustc::ty::{ConstVid, FloatVid, IntVid, TyVid};
2325

2426
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2527
use rustc_data_structures::sync::Lrc;
@@ -40,7 +42,6 @@ use self::outlives::env::OutlivesEnvironment;
4042
use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, VerifyBound};
4143
use self::region_constraints::{RegionConstraintCollector, RegionSnapshot};
4244
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
43-
use self::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
4445

4546
pub mod at;
4647
pub mod canonical;
@@ -61,8 +62,8 @@ pub mod region_constraints;
6162
pub mod resolve;
6263
mod sub;
6364
pub mod type_variable;
64-
mod types;
65-
pub mod unify_key;
65+
66+
pub use rustc::infer::unify_key;
6667

6768
#[must_use]
6869
#[derive(Debug)]
@@ -524,8 +525,12 @@ pub struct InferCtxtBuilder<'tcx> {
524525
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
525526
}
526527

527-
impl TyCtxt<'tcx> {
528-
pub fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
528+
pub trait TyCtxtInferExt<'tcx> {
529+
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx>;
530+
}
531+
532+
impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
533+
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
529534
InferCtxtBuilder { global_tcx: self, fresh_tables: None }
530535
}
531536
}

src/librustc_infer/infer/outlives/obligations.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ use crate::traits::ObligationCause;
6666
use crate::ty::outlives::Component;
6767
use crate::ty::subst::GenericArgKind;
6868
use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
69+
6970
use rustc_data_structures::fx::FxHashMap;
7071
use rustc_hir as hir;
72+
use smallvec::smallvec;
7173

7274
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
7375
/// Registers that the given region obligation must be resolved

src/librustc_infer/infer/outlives/verify.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::ty::{self, Ty, TyCtxt};
66
use rustc_data_structures::captures::Captures;
77
use rustc_hir::def_id::DefId;
88

9+
use smallvec::smallvec;
10+
911
/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
1012
/// obligation into a series of `'a: 'b` constraints and "verifys", as
1113
/// described on the module comment. The final constraints are emitted

0 commit comments

Comments
 (0)