Skip to content

Commit 240bd89

Browse files
committed
Auto merge of #53707 - eddyb:phantom-waffles, r=<try>
rustc_typeck: turn `where Type:,` into a WF(Type) predicate, instead of ignoring it. Fixes #53696, assuming crater doesn't catch anyone using this syntax already. r? @nikomatsakis cc @petrochenkov
2 parents 545f223 + e7cab97 commit 240bd89

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

src/librustc_typeck/collect.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,12 @@ fn explicit_predicates_of<'a, 'tcx>(
17991799
&hir::WherePredicate::BoundPredicate(ref bound_pred) => {
18001800
let ty = icx.to_ty(&bound_pred.bounded_ty);
18011801

1802+
// Keep the type around in a WF predicate, in case of no bounds.
1803+
// That way, `where Ty:` is not a complete noop (see #53696).
1804+
if bound_pred.bounds.is_empty() {
1805+
predicates.push(ty::Predicate::WellFormed(ty));
1806+
}
1807+
18021808
for bound in bound_pred.bounds.iter() {
18031809
match bound {
18041810
&hir::GenericBound::Trait(ref poly_trait_ref, _) => {

src/test/ui/chalkify/lower_trait_where_clause.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ use std::fmt::{Debug, Display};
1414
use std::borrow::Borrow;
1515

1616
#[rustc_dump_program_clauses] //~ ERROR program clause dump
17-
trait Foo<'a, 'b, S, T, U> where S: Debug, T: Borrow<U>, U: ?Sized, 'a: 'b, U: 'b {
18-
fn s(S) -> S;
17+
trait Foo<'a, 'b, S, T, U>
18+
where
19+
S: Debug,
20+
T: Borrow<U>,
21+
U: ?Sized,
22+
'a: 'b,
23+
U: 'b,
24+
Vec<T>:, // NOTE(#53696) this checks an empty list of bounds.
25+
{ fn s(S) -> S;
1926
fn t(T) -> T;
2027
fn u(U) -> U;
2128
}

src/test/ui/chalkify/lower_trait_where_clause.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
1111
= note: Implemented(Self: Foo<'a, 'b, S, T, U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
1212
= note: RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
1313
= note: TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
14-
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(S: std::marker::Sized), WellFormed(T: std::marker::Sized), WellFormed(S: std::fmt::Debug), WellFormed(T: std::borrow::Borrow<U>), RegionOutlives('a : 'b), TypeOutlives(U : 'b).
14+
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(S: std::marker::Sized), WellFormed(T: std::marker::Sized), WellFormed(S: std::fmt::Debug), WellFormed(T: std::borrow::Borrow<U>), WellFormed(U), RegionOutlives('a : 'b), TypeOutlives(U : 'b), WellFormed(std::vec::Vec<T>).
15+
= note: WellFormed(U) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
16+
= note: WellFormed(std::vec::Vec<T>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
1517

1618
error: aborting due to previous error
1719

src/test/ui/wf/wf-fn-where-clause.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// Test that we check where-clauses on fn items.
1212

13-
#![feature(associated_type_defaults)]
1413
#![feature(rustc_attrs)]
1514
#![allow(dead_code)]
1615

@@ -20,5 +19,9 @@ fn foo<T,U>() where T: ExtraCopy<U> //~ ERROR E0277
2019
{
2120
}
2221

22+
fn bar() where Vec<dyn Copy>:, {}
23+
//~^ ERROR E0277
24+
//~| ERROR E0038
25+
2326
#[rustc_error]
2427
fn main() { }
+23-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied
2-
--> $DIR/wf-fn-where-clause.rs:19:1
2+
--> $DIR/wf-fn-where-clause.rs:18:1
33
|
44
LL | / fn foo<T,U>() where T: ExtraCopy<U> //~ ERROR E0277
55
LL | | {
@@ -8,11 +8,30 @@ LL | | }
88
|
99
= help: consider adding a `where U: std::marker::Copy` bound
1010
note: required by `ExtraCopy`
11-
--> $DIR/wf-fn-where-clause.rs:17:1
11+
--> $DIR/wf-fn-where-clause.rs:16:1
1212
|
1313
LL | trait ExtraCopy<T:Copy> { }
1414
| ^^^^^^^^^^^^^^^^^^^^^^^
1515

16-
error: aborting due to previous error
16+
error[E0277]: the size for values of type `(dyn std::marker::Copy + 'static)` cannot be known at compilation time
17+
--> $DIR/wf-fn-where-clause.rs:22:1
18+
|
19+
LL | fn bar() where Vec<dyn Copy>:, {}
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
21+
|
22+
= help: the trait `std::marker::Sized` is not implemented for `(dyn std::marker::Copy + 'static)`
23+
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
24+
= note: required by `std::vec::Vec`
25+
26+
error[E0038]: the trait `std::marker::Copy` cannot be made into an object
27+
--> $DIR/wf-fn-where-clause.rs:22:1
28+
|
29+
LL | fn bar() where Vec<dyn Copy>:, {}
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` cannot be made into an object
31+
|
32+
= note: the trait cannot require that `Self : Sized`
33+
34+
error: aborting due to 3 previous errors
1735

18-
For more information about this error, try `rustc --explain E0277`.
36+
Some errors occurred: E0038, E0277.
37+
For more information about an error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)