-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add const generics to infer (and transitive dependencies) #59008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f1c83de
cafa10d
2254727
77447de
d7fdeff
0728b62
14f906f
d4e0951
05ac3ac
b9b9994
7d71a1c
bfc39b9
69423b3
d113ff8
3f675ab
ed3dae4
ef1b2ac
7bf175f
bd2fa22
e965b75
c13aa09
57d3a5a
fa394c2
cf1a719
245a474
f5712d2
e70797b
2308d2d
c888af5
fc16b0a
d8b9387
f241693
972e254
5cf45bc
67176f7
97c0c66
b872e63
d8b1ddb
388f823
beb2f84
a29eca5
c7deb5b
16d6ee3
a188850
1369132
541de81
a68ed06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ | |
//! | ||
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html | ||
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin}; | ||
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, ConstVariableOrigin}; | ||
use crate::mir::interpret::ConstValue; | ||
use rustc_data_structures::indexed_vec::IndexVec; | ||
use rustc_macros::HashStable; | ||
use serialize::UseSpecializedDecodable; | ||
|
@@ -30,7 +31,7 @@ use std::ops::Index; | |
use syntax::source_map::Span; | ||
use crate::ty::fold::TypeFoldable; | ||
use crate::ty::subst::Kind; | ||
use crate::ty::{self, BoundVar, Lift, List, Region, TyCtxt}; | ||
use crate::ty::{self, BoundVar, InferConst, Lift, List, Region, TyCtxt}; | ||
|
||
mod canonicalizer; | ||
|
||
|
@@ -115,6 +116,8 @@ impl CanonicalVarInfo { | |
CanonicalVarKind::PlaceholderTy(_) => false, | ||
CanonicalVarKind::Region(_) => true, | ||
CanonicalVarKind::PlaceholderRegion(..) => false, | ||
CanonicalVarKind::Const(_) => true, | ||
CanonicalVarKind::PlaceholderConst(_) => false, | ||
} | ||
} | ||
} | ||
|
@@ -137,6 +140,12 @@ pub enum CanonicalVarKind { | |
/// are solving a goal like `for<'a> T: Foo<'a>` to represent the | ||
/// bound region `'a`. | ||
PlaceholderRegion(ty::PlaceholderRegion), | ||
|
||
/// Some kind of const inference variable. | ||
Const(ty::UniverseIndex), | ||
|
||
/// A "placeholder" that represents "any const". | ||
PlaceholderConst(ty::PlaceholderConst), | ||
} | ||
|
||
impl CanonicalVarKind { | ||
|
@@ -150,6 +159,8 @@ impl CanonicalVarKind { | |
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.universe, | ||
CanonicalVarKind::Region(ui) => ui, | ||
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.universe, | ||
CanonicalVarKind::Const(ui) => ui, | ||
CanonicalVarKind::PlaceholderConst(placeholder) => placeholder.universe, | ||
} | ||
} | ||
} | ||
|
@@ -388,6 +399,33 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { | |
}; | ||
self.tcx.mk_region(ty::RePlaceholder(placeholder_mapped)).into() | ||
} | ||
|
||
CanonicalVarKind::Const(ui) => { | ||
self.next_const_var_in_universe( | ||
self.next_ty_var_in_universe( | ||
TypeVariableOrigin::MiscVariable(span), | ||
universe_map(ui), | ||
), | ||
ConstVariableOrigin::MiscVariable(span), | ||
universe_map(ui), | ||
).into() | ||
} | ||
|
||
CanonicalVarKind::PlaceholderConst( | ||
ty::PlaceholderConst { universe, name }, | ||
) => { | ||
let universe_mapped = universe_map(universe); | ||
let placeholder_mapped = ty::PlaceholderConst { | ||
universe: universe_mapped, | ||
name, | ||
}; | ||
self.tcx.mk_const( | ||
ty::Const { | ||
val: ConstValue::Placeholder(placeholder_mapped), | ||
ty: self.tcx.types.err, // FIXME(const_generics) | ||
|
||
} | ||
).into() | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -443,8 +481,13 @@ impl<'tcx> CanonicalVarValues<'tcx> { | |
UnpackedKind::Lifetime(..) => tcx.mk_region( | ||
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(i)) | ||
).into(), | ||
UnpackedKind::Const(..) => { | ||
unimplemented!() // FIXME(const_generics) | ||
UnpackedKind::Const(ct) => { | ||
tcx.mk_const(ty::Const { | ||
ty: ct.ty, | ||
val: ConstValue::Infer( | ||
InferConst::Canonical(ty::INNERMOST, ty::BoundVar::from_u32(i)) | ||
), | ||
}).into() | ||
} | ||
}) | ||
.collect() | ||
|
Uh oh!
There was an error while loading. Please reload this page.