Skip to content
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

Fix some more non_lifetime_binders stuff with higher-ranked trait bounds #108189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,15 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
bug!("encountered a fresh type during canonicalization")
}

ty::Placeholder(placeholder) => self.canonicalize_ty_var(
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
t,
),
ty::Placeholder(mut placeholder) => {
if !self.canonicalize_mode.preserve_universes() {
placeholder.universe = ty::UniverseIndex::ROOT;
}
self.canonicalize_ty_var(
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
t,
)
}

ty::Bound(debruijn, _) => {
if debruijn >= self.binder_index {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,10 @@ pub trait PrettyPrinter<'tcx>:
p!(print(data))
}
}
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
ty::Placeholder(placeholder) => match placeholder.name {
ty::BoundTyKind::Anon(_) => p!(write("Placeholder({:?})", placeholder)),
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
},
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
// We use verbose printing in 'NO_QUERIES' mode, to
// avoid needing to call `predicates_of`. This should
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,12 +2148,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}))
}

ty::Alias(..) | ty::Param(_) => None,
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,
ty::Infer(ty::TyVar(_)) => Ambiguous,

ty::Placeholder(..)
| ty::Bound(..)
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
// We can make this an ICE if/once we actually instantiate the trait obligation.
ty::Bound(..) => None,

ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/traits/non_lifetime_binders/bad-sized-cond.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![feature(non_lifetime_binders)]
//~^ WARN is incomplete and may not be safe

pub fn foo()
where
for<V> V: Sized,
{
}

pub fn bar()
where
for<V> V: IntoIterator,
{
}

fn main() {
foo();
//~^ ERROR the size for values of type `V` cannot be known at compilation time

bar();
//~^ ERROR the size for values of type `V` cannot be known at compilation time
//~| ERROR `V` is not an iterator
}
62 changes: 62 additions & 0 deletions tests/ui/traits/non_lifetime_binders/bad-sized-cond.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/bad-sized-cond.rs:1:12
|
LL | #![feature(non_lifetime_binders)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
= note: `#[warn(incomplete_features)]` on by default

error[E0277]: the size for values of type `V` cannot be known at compilation time
--> $DIR/bad-sized-cond.rs:17:5
|
LL | foo();
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `V`
note: required by a bound in `foo`
--> $DIR/bad-sized-cond.rs:6:15
|
LL | pub fn foo()
| --- required by a bound in this
LL | where
LL | for<V> V: Sized,
| ^^^^^ required by this bound in `foo`

error[E0277]: the size for values of type `V` cannot be known at compilation time
--> $DIR/bad-sized-cond.rs:20:5
|
LL | bar();
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `V`
= note: required for `V` to implement `IntoIterator`
note: required by a bound in `bar`
--> $DIR/bad-sized-cond.rs:12:15
|
LL | pub fn bar()
| --- required by a bound in this
LL | where
LL | for<V> V: IntoIterator,
| ^^^^^^^^^^^^ required by this bound in `bar`

error[E0277]: `V` is not an iterator
--> $DIR/bad-sized-cond.rs:20:5
|
LL | bar();
| ^^^ `V` is not an iterator
|
= help: the trait `Iterator` is not implemented for `V`
= note: required for `V` to implement `IntoIterator`
note: required by a bound in `bar`
--> $DIR/bad-sized-cond.rs:12:15
|
LL | pub fn bar()
| --- required by a bound in this
LL | where
LL | for<V> V: IntoIterator,
| ^^^^^^^^^^^^ required by this bound in `bar`

error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0277`.