Skip to content

Commit c5d5c57

Browse files
authored
Rollup merge of #108189 - compiler-errors:non_lifetime_binders-bound-stuff, r=jackh726
Fix some more `non_lifetime_binders` stuff with higher-ranked trait bounds 1. When assembling candidates for `for<T> T: Sized`, we can't ICE because the self-type is a bound type. 2. Fix an issue where, when canonicalizing in non-universe preserving mode, we don't actually set the universe for placeholders to the root even though we do the same for region vars. 3. Make `Placeholder("T")` format like `T` in error messages. Fixes #108180 Fixes #108182 r? types
2 parents 636679e + 6f3706e commit c5d5c57

File tree

5 files changed

+103
-9
lines changed

5 files changed

+103
-9
lines changed

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,15 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
418418
bug!("encountered a fresh type during canonicalization")
419419
}
420420

421-
ty::Placeholder(placeholder) => self.canonicalize_ty_var(
422-
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
423-
t,
424-
),
421+
ty::Placeholder(mut placeholder) => {
422+
if !self.canonicalize_mode.preserve_universes() {
423+
placeholder.universe = ty::UniverseIndex::ROOT;
424+
}
425+
self.canonicalize_ty_var(
426+
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
427+
t,
428+
)
429+
}
425430

426431
ty::Bound(debruijn, _) => {
427432
if debruijn >= self.binder_index {

compiler/rustc_middle/src/ty/print/pretty.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,10 @@ pub trait PrettyPrinter<'tcx>:
735735
p!(print(data))
736736
}
737737
}
738-
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
738+
ty::Placeholder(placeholder) => match placeholder.name {
739+
ty::BoundTyKind::Anon(_) => p!(write("Placeholder({:?})", placeholder)),
740+
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
741+
},
739742
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
740743
// We use verbose printing in 'NO_QUERIES' mode, to
741744
// avoid needing to call `predicates_of`. This should

compiler/rustc_trait_selection/src/traits/select/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2148,12 +2148,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21482148
}))
21492149
}
21502150

2151-
ty::Alias(..) | ty::Param(_) => None,
2151+
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,
21522152
ty::Infer(ty::TyVar(_)) => Ambiguous,
21532153

2154-
ty::Placeholder(..)
2155-
| ty::Bound(..)
2156-
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2154+
// We can make this an ICE if/once we actually instantiate the trait obligation.
2155+
ty::Bound(..) => None,
2156+
2157+
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
21572158
bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
21582159
}
21592160
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(non_lifetime_binders)]
2+
//~^ WARN is incomplete and may not be safe
3+
4+
pub fn foo()
5+
where
6+
for<V> V: Sized,
7+
{
8+
}
9+
10+
pub fn bar()
11+
where
12+
for<V> V: IntoIterator,
13+
{
14+
}
15+
16+
fn main() {
17+
foo();
18+
//~^ ERROR the size for values of type `V` cannot be known at compilation time
19+
20+
bar();
21+
//~^ ERROR the size for values of type `V` cannot be known at compilation time
22+
//~| ERROR `V` is not an iterator
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/bad-sized-cond.rs:1:12
3+
|
4+
LL | #![feature(non_lifetime_binders)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0277]: the size for values of type `V` cannot be known at compilation time
11+
--> $DIR/bad-sized-cond.rs:17:5
12+
|
13+
LL | foo();
14+
| ^^^ doesn't have a size known at compile-time
15+
|
16+
= help: the trait `Sized` is not implemented for `V`
17+
note: required by a bound in `foo`
18+
--> $DIR/bad-sized-cond.rs:6:15
19+
|
20+
LL | pub fn foo()
21+
| --- required by a bound in this
22+
LL | where
23+
LL | for<V> V: Sized,
24+
| ^^^^^ required by this bound in `foo`
25+
26+
error[E0277]: the size for values of type `V` cannot be known at compilation time
27+
--> $DIR/bad-sized-cond.rs:20:5
28+
|
29+
LL | bar();
30+
| ^^^ doesn't have a size known at compile-time
31+
|
32+
= help: the trait `Sized` is not implemented for `V`
33+
= note: required for `V` to implement `IntoIterator`
34+
note: required by a bound in `bar`
35+
--> $DIR/bad-sized-cond.rs:12:15
36+
|
37+
LL | pub fn bar()
38+
| --- required by a bound in this
39+
LL | where
40+
LL | for<V> V: IntoIterator,
41+
| ^^^^^^^^^^^^ required by this bound in `bar`
42+
43+
error[E0277]: `V` is not an iterator
44+
--> $DIR/bad-sized-cond.rs:20:5
45+
|
46+
LL | bar();
47+
| ^^^ `V` is not an iterator
48+
|
49+
= help: the trait `Iterator` is not implemented for `V`
50+
= note: required for `V` to implement `IntoIterator`
51+
note: required by a bound in `bar`
52+
--> $DIR/bad-sized-cond.rs:12:15
53+
|
54+
LL | pub fn bar()
55+
| --- required by a bound in this
56+
LL | where
57+
LL | for<V> V: IntoIterator,
58+
| ^^^^^^^^^^^^ required by this bound in `bar`
59+
60+
error: aborting due to 3 previous errors; 1 warning emitted
61+
62+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)