Skip to content

Commit 67f5667

Browse files
committed
Use Term in ProjectionPredicate
ProjectionPredicate should be able to handle both associated types and consts so this adds the first step of that. It mainly just pipes types all the way down, not entirely sure how to handle consts, but hopefully that'll come with time.
1 parent fb57b75 commit 67f5667

File tree

51 files changed

+274
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+274
-259
lines changed

Diff for: Cargo.lock

+9-45
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ dependencies = [
335335
"cargo-test-macro",
336336
"cargo-test-support",
337337
"cargo-util",
338-
"clap 3.0.6",
338+
"clap",
339339
"crates-io",
340340
"crossbeam-utils",
341341
"curl",
@@ -615,28 +615,13 @@ dependencies = [
615615
"ansi_term 0.12.1",
616616
"atty",
617617
"bitflags",
618-
"strsim 0.8.0",
619-
"textwrap 0.11.0",
618+
"strsim",
619+
"textwrap",
620620
"unicode-width",
621621
"vec_map",
622622
"yaml-rust 0.3.5",
623623
]
624624

625-
[[package]]
626-
name = "clap"
627-
version = "3.0.6"
628-
source = "registry+https://github.com/rust-lang/crates.io-index"
629-
checksum = "1957aa4a5fb388f0a0a73ce7556c5b42025b874e5cdc2c670775e346e97adec0"
630-
dependencies = [
631-
"atty",
632-
"bitflags",
633-
"indexmap",
634-
"os_str_bytes",
635-
"strsim 0.10.0",
636-
"termcolor",
637-
"textwrap 0.14.2",
638-
]
639-
640625
[[package]]
641626
name = "clippy"
642627
version = "0.1.60"
@@ -669,7 +654,7 @@ version = "0.0.1"
669654
dependencies = [
670655
"bytecount",
671656
"cargo_metadata 0.14.0",
672-
"clap 2.34.0",
657+
"clap",
673658
"indoc",
674659
"itertools 0.10.1",
675660
"opener",
@@ -1751,7 +1736,7 @@ name = "installer"
17511736
version = "0.0.0"
17521737
dependencies = [
17531738
"anyhow",
1754-
"clap 2.34.0",
1739+
"clap",
17551740
"flate2",
17561741
"lazy_static",
17571742
"num_cpus",
@@ -2190,7 +2175,7 @@ dependencies = [
21902175
"ammonia",
21912176
"anyhow",
21922177
"chrono",
2193-
"clap 2.34.0",
2178+
"clap",
21942179
"elasticlunr-rs",
21952180
"env_logger 0.7.1",
21962181
"handlebars",
@@ -2521,15 +2506,6 @@ dependencies = [
25212506
"winapi",
25222507
]
25232508

2524-
[[package]]
2525-
name = "os_str_bytes"
2526-
version = "6.0.0"
2527-
source = "registry+https://github.com/rust-lang/crates.io-index"
2528-
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
2529-
dependencies = [
2530-
"memchr",
2531-
]
2532-
25332509
[[package]]
25342510
name = "output_vt100"
25352511
version = "0.1.2"
@@ -2934,7 +2910,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
29342910
checksum = "b0b4b5faaf07040474e8af74a9e19ff167d5d204df5db5c5c765edecfb900358"
29352911
dependencies = [
29362912
"bitflags",
2937-
"clap 2.34.0",
2913+
"clap",
29382914
"derive_more",
29392915
"env_logger 0.7.1",
29402916
"humantime 2.0.1",
@@ -3282,7 +3258,7 @@ dependencies = [
32823258
name = "rustbook"
32833259
version = "0.1.0"
32843260
dependencies = [
3285-
"clap 2.34.0",
3261+
"clap",
32863262
"env_logger 0.7.1",
32873263
"mdbook",
32883264
]
@@ -4898,19 +4874,13 @@ version = "0.8.0"
48984874
source = "registry+https://github.com/rust-lang/crates.io-index"
48994875
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
49004876

4901-
[[package]]
4902-
name = "strsim"
4903-
version = "0.10.0"
4904-
source = "registry+https://github.com/rust-lang/crates.io-index"
4905-
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
4906-
49074877
[[package]]
49084878
name = "structopt"
49094879
version = "0.3.25"
49104880
source = "registry+https://github.com/rust-lang/crates.io-index"
49114881
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
49124882
dependencies = [
4913-
"clap 2.34.0",
4883+
"clap",
49144884
"lazy_static",
49154885
"structopt-derive",
49164886
]
@@ -5081,12 +5051,6 @@ dependencies = [
50815051
"unicode-width",
50825052
]
50835053

5084-
[[package]]
5085-
name = "textwrap"
5086-
version = "0.14.2"
5087-
source = "registry+https://github.com/rust-lang/crates.io-index"
5088-
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
5089-
50905054
[[package]]
50915055
name = "thiserror"
50925056
version = "1.0.30"

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -997,10 +997,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
997997
};
998998

999999
let kind = match constraint.kind {
1000-
AssocConstraintKind::Equality { ref term } => match term {
1001-
Term::Ty(ref ty) => hir::TypeBindingKind::Equality { ty: self.lower_ty(ty, itctx) },
1002-
Term::Const(ref c) => hir::TypeBindingKind::Const { c: self.lower_anon_const(c) },
1003-
},
1000+
AssocConstraintKind::Equality { ref term } => {
1001+
let term = match term {
1002+
Term::Ty(ref ty) => self.lower_ty(ty, itctx).into(),
1003+
Term::Const(ref c) => self.lower_anon_const(c).into(),
1004+
};
1005+
hir::TypeBindingKind::Equality { term }
1006+
}
10041007
AssocConstraintKind::Bound { ref bounds } => {
10051008
let mut capturable_lifetimes;
10061009
let mut parent_def_id = self.current_hir_id_owner;
@@ -1079,7 +1082,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10791082
itctx,
10801083
);
10811084

1082-
hir::TypeBindingKind::Equality { ty }
1085+
hir::TypeBindingKind::Equality { term: ty.into() }
10831086
})
10841087
} else {
10851088
// Desugar `AssocTy: Bounds` into a type binding where the

Diff for: compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
420420
ty: &'hir hir::Ty<'hir>,
421421
) -> hir::TypeBinding<'hir> {
422422
let ident = Ident::with_dummy_span(hir::FN_OUTPUT_NAME);
423-
let kind = hir::TypeBindingKind::Equality { ty };
423+
let kind = hir::TypeBindingKind::Equality { term: ty.into() };
424424
let args = arena_vec![self;];
425425
let bindings = arena_vec![self;];
426426
let gen_args = self.arena.alloc(hir::GenericArgs {

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -964,9 +964,7 @@ impl<'a> State<'a> {
964964
Term::Const(c) => self.print_expr_anon_const(c),
965965
}
966966
}
967-
ast::AssocConstraintKind::Bound { bounds } => {
968-
self.print_type_bounds(":", &*bounds);
969-
}
967+
ast::AssocConstraintKind::Bound { bounds } => self.print_type_bounds(":", &*bounds),
970968
}
971969
}
972970

Diff for: compiler/rustc_borrowck/src/diagnostics/region_name.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,10 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
779779
[
780780
hir::TypeBinding {
781781
ident: Ident { name: sym::Output, .. },
782-
kind: hir::TypeBindingKind::Equality { ty },
782+
kind:
783+
hir::TypeBindingKind::Equality {
784+
term: hir::Term::Ty(ty),
785+
},
783786
..
784787
},
785788
],

Diff for: compiler/rustc_hir/src/hir.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl GenericArgs<'_> {
377377
GenericArg::Type(ty) => matches!(ty.kind, TyKind::Err),
378378
_ => false,
379379
}) || self.bindings.iter().any(|arg| match arg.kind {
380-
TypeBindingKind::Equality { ty } => matches!(ty.kind, TyKind::Err),
380+
TypeBindingKind::Equality { term: Term::Ty(ty) } => matches!(ty.kind, TyKind::Err),
381381
_ => false,
382382
})
383383
}
@@ -2129,21 +2129,37 @@ pub struct TypeBinding<'hir> {
21292129
pub span: Span,
21302130
}
21312131

2132+
#[derive(Debug, HashStable_Generic)]
2133+
pub enum Term<'hir> {
2134+
Ty(&'hir Ty<'hir>),
2135+
Const(AnonConst),
2136+
}
2137+
2138+
impl<'hir> From<&'hir Ty<'hir>> for Term<'hir> {
2139+
fn from(ty: &'hir Ty<'hir>) -> Self {
2140+
Term::Ty(ty)
2141+
}
2142+
}
2143+
2144+
impl<'hir> From<AnonConst> for Term<'hir> {
2145+
fn from(c: AnonConst) -> Self {
2146+
Term::Const(c)
2147+
}
2148+
}
2149+
21322150
// Represents the two kinds of type bindings.
21332151
#[derive(Debug, HashStable_Generic)]
21342152
pub enum TypeBindingKind<'hir> {
21352153
/// E.g., `Foo<Bar: Send>`.
21362154
Constraint { bounds: &'hir [GenericBound<'hir>] },
2137-
/// E.g., `Foo<Bar = ()>`.
2138-
Equality { ty: &'hir Ty<'hir> },
2139-
/// E.g., `Foo<N = 3>`.
2140-
Const { c: AnonConst },
2155+
/// E.g., `Foo<Bar = ()>`, `Foo<Bar = ()>`
2156+
Equality { term: Term<'hir> },
21412157
}
21422158

21432159
impl TypeBinding<'_> {
21442160
pub fn ty(&self) -> &Ty<'_> {
21452161
match self.kind {
2146-
TypeBindingKind::Equality { ref ty } => ty,
2162+
TypeBindingKind::Equality { term: Term::Ty(ref ty) } => ty,
21472163
_ => panic!("expected equality type binding for parenthesized generic args"),
21482164
}
21492165
}

Diff for: compiler/rustc_hir/src/intravisit.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -827,11 +827,11 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
827827
visitor.visit_ident(type_binding.ident);
828828
visitor.visit_generic_args(type_binding.span, type_binding.gen_args);
829829
match type_binding.kind {
830-
TypeBindingKind::Equality { ref ty } => visitor.visit_ty(ty),
831-
TypeBindingKind::Const { ref c } => visitor.visit_anon_const(c),
832-
TypeBindingKind::Constraint { bounds } => {
833-
walk_list!(visitor, visit_param_bound, bounds);
834-
}
830+
TypeBindingKind::Equality { ref term } => match term {
831+
Term::Ty(ref ty) => visitor.visit_ty(ty),
832+
Term::Const(ref c) => visitor.visit_anon_const(c),
833+
},
834+
TypeBindingKind::Constraint { bounds } => walk_list!(visitor, visit_param_bound, bounds),
835835
}
836836
}
837837

Diff for: compiler/rustc_hir_pretty/src/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
66
use rustc_ast_pretty::pp::{self, Breaks};
77
use rustc_ast_pretty::pprust::{Comments, PrintState};
88
use rustc_hir as hir;
9-
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, Node};
9+
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, Node, Term};
1010
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
1111
use rustc_span::source_map::{SourceMap, Spanned};
1212
use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol};
@@ -1752,13 +1752,12 @@ impl<'a> State<'a> {
17521752
self.print_generic_args(binding.gen_args, false, false);
17531753
self.space();
17541754
match generic_args.bindings[0].kind {
1755-
hir::TypeBindingKind::Equality { ref ty } => {
1755+
hir::TypeBindingKind::Equality { ref term } => {
17561756
self.word_space("=");
1757-
self.print_type(ty);
1758-
}
1759-
hir::TypeBindingKind::Const { ref c } => {
1760-
self.word_space("=");
1761-
self.print_anon_const(c);
1757+
match term {
1758+
Term::Ty(ref ty) => self.print_type(ty),
1759+
Term::Const(ref c) => self.print_anon_const(c),
1760+
}
17621761
}
17631762
hir::TypeBindingKind::Constraint { bounds } => {
17641763
self.print_bounds(":", bounds);

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use rustc_middle::ty::error::TypeError;
6969
use rustc_middle::ty::{
7070
self,
7171
subst::{GenericArgKind, Subst, SubstsRef},
72-
Region, Ty, TyCtxt, TypeFoldable,
72+
Region, Term, Ty, TyCtxt, TypeFoldable,
7373
};
7474
use rustc_span::{sym, BytePos, DesugaringKind, MultiSpan, Pos, Span};
7575
use rustc_target::spec::abi;
@@ -1780,7 +1780,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17801780
{
17811781
if projection_predicate.projection_ty.item_def_id == item_def_id {
17821782
// We don't account for multiple `Future::Output = Ty` contraints.
1783-
return Some(projection_predicate.ty);
1783+
match projection_predicate.term {
1784+
Term::Ty(ty) => return Some(ty),
1785+
// Can return None, but not sure if that makes sense?
1786+
Term::Const(_c) => todo!(),
1787+
}
17841788
}
17851789
}
17861790
}

Diff for: compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
122122
{
123123
for type_binding in generic_args.bindings.iter() {
124124
if type_binding.ident.name == rustc_span::sym::Output {
125-
if let hir::TypeBindingKind::Equality { ty } =
126-
type_binding.kind
125+
if let hir::TypeBindingKind::Equality {
126+
term: hir::Term::Ty(ty),
127+
} = type_binding.kind
127128
{
128129
return Some(ty);
129130
}

Diff for: compiler/rustc_infer/src/infer/opaque_types.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir as hir;
77
use rustc_hir::def_id::LocalDefId;
88
use rustc_middle::ty::fold::BottomUpFolder;
99
use rustc_middle::ty::subst::{GenericArgKind, Subst};
10-
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitor};
10+
use rustc_middle::ty::{self, OpaqueTypeKey, Term, Ty, TyCtxt, TypeFoldable, TypeVisitor};
1111
use rustc_span::Span;
1212

1313
use std::ops::ControlFlow;
@@ -584,9 +584,13 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
584584
debug!(?predicate);
585585

586586
if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {
587-
if projection.ty.references_error() {
588-
// No point on adding these obligations since there's a type error involved.
589-
return tcx.ty_error();
587+
if let Term::Ty(ty) = projection.term {
588+
if ty.references_error() {
589+
// No point on adding these obligations since there's a type error involved.
590+
return tcx.ty_error();
591+
}
592+
} else {
593+
todo!();
590594
}
591595
}
592596

Diff for: compiler/rustc_infer/src/infer/projection.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2626
kind: TypeVariableOriginKind::NormalizeProjectionType,
2727
span: self.tcx.def_span(def_id),
2828
});
29-
let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var });
29+
let projection =
30+
ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, term: ty_var.into() });
3031
let obligation = Obligation::with_depth(
3132
cause,
3233
recursion_depth,

Diff for: compiler/rustc_middle/src/ty/flags.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ty::subst::{GenericArg, GenericArgKind};
2-
use crate::ty::{self, InferConst, Ty, TypeFlags};
2+
use crate::ty::{self, InferConst, Term, Ty, TypeFlags};
33
use std::slice;
44

55
#[derive(Debug)]
@@ -241,9 +241,12 @@ impl FlagComputation {
241241
self.add_ty(a);
242242
self.add_ty(b);
243243
}
244-
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
244+
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => {
245245
self.add_projection_ty(projection_ty);
246-
self.add_ty(ty);
246+
match term {
247+
Term::Ty(ty) => self.add_ty(ty),
248+
Term::Const(_c) => todo!(),
249+
}
247250
}
248251
ty::PredicateKind::WellFormed(arg) => {
249252
self.add_substs(slice::from_ref(&arg));

0 commit comments

Comments
 (0)