Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
HIR ty lowering: Validate relaxed bounds in trait object types
Only relevant to the internal feature `more_maybe_bounds`.
  • Loading branch information
fmease committed Jul 18, 2025
commit 10d7e5faf20d019568de77503cb13f0203296d02
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let mut user_written_bounds = Vec::new();
let mut potential_assoc_types = Vec::new();
for poly_trait_ref in hir_bounds.iter() {
if let hir::BoundPolarity::Maybe(_) = poly_trait_ref.modifiers.polarity {
continue;
}
let result = self.lower_poly_trait_ref(
poly_trait_ref,
dummy_self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ fn main() {
x.leak_foo();
//~^ ERROR the trait bound `dyn Trait: Leak` is not satisfied
x.maybe_leak_foo();
// Ensure that we validate the generic args of relaxed bounds in trait object types.
let _: dyn Trait + ?Leak<(), Undefined = ()>;
//~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied
//~| ERROR associated type `Undefined` not found for `Leak`
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ note: required by a bound in `Trait::leak_foo`
LL | fn leak_foo(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::leak_foo`

error: aborting due to 2 previous errors
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/maybe-bounds-in-dyn-traits.rs:68:25
|
LL | let _: dyn Trait + ?Leak<(), Undefined = ()>;
| ^^^^-------------------- help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
note: trait defined here, with 0 generic parameters
--> $DIR/maybe-bounds-in-dyn-traits.rs:44:12
|
LL | auto trait Leak {}
| ^^^^

error[E0220]: associated type `Undefined` not found for `Leak`
--> $DIR/maybe-bounds-in-dyn-traits.rs:68:34
|
LL | let _: dyn Trait + ?Leak<(), Undefined = ()>;
| ^^^^^^^^^ associated type `Undefined` not found

error: aborting due to 4 previous errors

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