Skip to content

Commit a9d780c

Browse files
committed
HIR ty lowering: Validate unbounds in trait object types
Only relevant to the internal feature `more_maybe_bounds`.
1 parent 8de9931 commit a9d780c

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
3636
let mut user_written_bounds = Vec::new();
3737
let mut potential_assoc_types = Vec::new();
3838
for poly_trait_ref in hir_bounds.iter() {
39-
if let hir::BoundPolarity::Maybe(_) = poly_trait_ref.modifiers.polarity {
40-
continue;
41-
}
4239
let result = self.lower_poly_trait_ref(
4340
poly_trait_ref,
4441
dummy_self,

tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ fn main() {
6464
x.leak_foo();
6565
//~^ ERROR the trait bound `dyn Trait: Leak` is not satisfied
6666
x.maybe_leak_foo();
67+
// Ensure that we validate the generic args of maybe-bounds
68+
let _: dyn Trait + ?Leak<(), Undefined = ()>;
69+
//~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied
70+
//~| ERROR associated type `Undefined` not found for `Leak`
6771
}

tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.stderr

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ note: required by a bound in `Trait::leak_foo`
1818
LL | fn leak_foo(&self) {}
1919
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::leak_foo`
2020

21-
error: aborting due to 2 previous errors
21+
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
22+
--> $DIR/maybe-bounds-in-dyn-traits.rs:68:25
23+
|
24+
LL | let _: dyn Trait + ?Leak<(), Undefined = ()>;
25+
| ^^^^-------------------- help: remove the unnecessary generics
26+
| |
27+
| expected 0 generic arguments
28+
|
29+
note: trait defined here, with 0 generic parameters
30+
--> $DIR/maybe-bounds-in-dyn-traits.rs:44:12
31+
|
32+
LL | auto trait Leak {}
33+
| ^^^^
34+
35+
error[E0220]: associated type `Undefined` not found for `Leak`
36+
--> $DIR/maybe-bounds-in-dyn-traits.rs:68:34
37+
|
38+
LL | let _: dyn Trait + ?Leak<(), Undefined = ()>;
39+
| ^^^^^^^^^ associated type `Undefined` not found
40+
41+
error: aborting due to 4 previous errors
2242

23-
For more information about this error, try `rustc --explain E0277`.
43+
Some errors have detailed explanations: E0107, E0220, E0277.
44+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)