Skip to content

Commit b40bc12

Browse files
committed
Do not attempt to evaluate obligations on PointeeSized goals
1 parent 3f98535 commit b40bc12

5 files changed

Lines changed: 45 additions & 9 deletions

File tree

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,15 +2632,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
26322632
trait_def_id != def_id
26332633
&& trait_name == self.tcx.item_name(def_id)
26342634
&& trait_has_same_params(def_id)
2635-
&& self.predicate_must_hold_modulo_regions(&Obligation::new(
2636-
self.tcx,
2637-
obligation.cause.clone(),
2638-
obligation.param_env,
2639-
trait_pred.map_bound(|tr| ty::TraitPredicate {
2640-
trait_ref: ty::TraitRef::new(self.tcx, def_id, tr.trait_ref.args),
2641-
..tr
2642-
}),
2643-
))
2635+
// `PointeeSized` is special -- it's a very weak/top sizedness marker that's
2636+
// effectively implemented for all types, and most importantly isn't lowered
2637+
// to the trait solver, so we skip doing any semantic checking for it.
2638+
&& (self.tcx.is_lang_item(def_id, LangItem::PointeeSized)
2639+
|| self.predicate_must_hold_modulo_regions(&Obligation::new(
2640+
self.tcx,
2641+
obligation.cause.clone(),
2642+
obligation.param_env,
2643+
trait_pred.map_bound(|tr| ty::TraitPredicate {
2644+
trait_ref: ty::TraitRef::new(self.tcx, def_id, tr.trait_ref.args),
2645+
..tr
2646+
}),
2647+
)))
26442648
}) {
26452649
err.note(format!(
26462650
"`{}` implements similarly named trait `{}`, but not `{}`",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(sized_hierarchy)]
2+
trait PointeeSized {} //~ HELP this trait has no implementations, consider adding one
3+
4+
fn require_trait<T: PointeeSized>() {} //~ NOTE required by a bound in `require_trait`
5+
//~| NOTE required by this bound in `require_trait`
6+
7+
fn main() {
8+
require_trait::<i32>(); //~ ERROR the trait bound `i32: PointeeSized` is not satisfied
9+
//~^ NOTE the trait `PointeeSized` is not implemented for `i32`
10+
//~| NOTE `i32` implements similarly named trait `std::marker::PointeeSized`, but not `PointeeSized`
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0277]: the trait bound `i32: PointeeSized` is not satisfied
2+
--> $DIR/similarly-named-trait-pointee-sized.rs:8:21
3+
|
4+
LL | require_trait::<i32>();
5+
| ^^^ the trait `PointeeSized` is not implemented for `i32`
6+
|
7+
= note: `i32` implements similarly named trait `std::marker::PointeeSized`, but not `PointeeSized`
8+
help: this trait has no implementations, consider adding one
9+
--> $DIR/similarly-named-trait-pointee-sized.rs:2:1
10+
|
11+
LL | trait PointeeSized {}
12+
| ^^^^^^^^^^^^^^^^^^
13+
note: required by a bound in `require_trait`
14+
--> $DIR/similarly-named-trait-pointee-sized.rs:4:21
15+
|
16+
LL | fn require_trait<T: PointeeSized>() {}
17+
| ^^^^^^^^^^^^ required by this bound in `require_trait`
18+
19+
error: aborting due to 1 previous error
20+
21+
For more information about this error, try `rustc --explain E0277`.
File renamed without changes.

0 commit comments

Comments
 (0)