Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -2632,15 +2632,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
trait_def_id != def_id
&& trait_name == self.tcx.item_name(def_id)
&& trait_has_same_params(def_id)
&& self.predicate_must_hold_modulo_regions(&Obligation::new(
self.tcx,
obligation.cause.clone(),
obligation.param_env,
trait_pred.map_bound(|tr| ty::TraitPredicate {
trait_ref: ty::TraitRef::new(self.tcx, def_id, tr.trait_ref.args),
..tr
}),
))
// `PointeeSized` is special -- it's a very weak/top sizedness marker that's
// effectively implemented for all types, and most importantly isn't lowered
// to the trait solver, so we skip doing any semantic checking for it.
&& (self.tcx.is_lang_item(def_id, LangItem::PointeeSized)
|| self.predicate_must_hold_modulo_regions(&Obligation::new(
self.tcx,
obligation.cause.clone(),
obligation.param_env,
trait_pred.map_bound(|tr| ty::TraitPredicate {
trait_ref: ty::TraitRef::new(self.tcx, def_id, tr.trait_ref.args),
..tr
}),
)))
}) {
err.note(format!(
"`{}` implements similarly named trait `{}`, but not `{}`",
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/traits/similarly-named-trait-pointee-sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(sized_hierarchy)]
trait PointeeSized {} //~ HELP this trait has no implementations, consider adding one

fn require_trait<T: PointeeSized>() {} //~ NOTE required by a bound in `require_trait`
//~| NOTE required by this bound in `require_trait`

fn main() {
require_trait::<i32>(); //~ ERROR the trait bound `i32: PointeeSized` is not satisfied
//~^ NOTE the trait `PointeeSized` is not implemented for `i32`
//~| NOTE `i32` implements similarly named trait `std::marker::PointeeSized`, but not `PointeeSized`
}
21 changes: 21 additions & 0 deletions tests/ui/traits/similarly-named-trait-pointee-sized.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0277]: the trait bound `i32: PointeeSized` is not satisfied
--> $DIR/similarly-named-trait-pointee-sized.rs:8:21
|
LL | require_trait::<i32>();
| ^^^ the trait `PointeeSized` is not implemented for `i32`
|
= note: `i32` implements similarly named trait `std::marker::PointeeSized`, but not `PointeeSized`
help: this trait has no implementations, consider adding one
--> $DIR/similarly-named-trait-pointee-sized.rs:2:1
|
LL | trait PointeeSized {}
| ^^^^^^^^^^^^^^^^^^
note: required by a bound in `require_trait`
--> $DIR/similarly-named-trait-pointee-sized.rs:4:21
|
LL | fn require_trait<T: PointeeSized>() {}
| ^^^^^^^^^^^^ required by this bound in `require_trait`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
error[E0277]: the trait bound `St: Trait` is not satisfied
--> $DIR/similarly_named_trait.rs:20:10
--> $DIR/similarly-named-trait.rs:20:10
|
LL | func(m::St);
| ---- ^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
help: the trait `Trait` is not implemented for `St`
--> $DIR/similarly_named_trait.rs:7:5
--> $DIR/similarly-named-trait.rs:7:5
|
LL | pub struct St;
| ^^^^^^^^^^^^^
= note: `St` implements similarly named trait `m::Trait`, but not `Trait`
help: this trait has no implementations, consider adding one
--> $DIR/similarly_named_trait.rs:1:1
--> $DIR/similarly-named-trait.rs:1:1
|
LL | trait Trait {}
| ^^^^^^^^^^^
note: required by a bound in `func`
--> $DIR/similarly_named_trait.rs:13:12
--> $DIR/similarly-named-trait.rs:13:12
|
LL | fn func<T: Trait>(_: T) {}
| ^^^^^ required by this bound in `func`

error[E0277]: the trait bound `St: TraitWithParam<St>` is not satisfied
--> $DIR/similarly_named_trait.rs:24:11
--> $DIR/similarly-named-trait.rs:24:11
|
LL | func2(m::St);
| ----- ^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
help: the trait `TraitWithParam<St>` is not implemented for `St`
--> $DIR/similarly_named_trait.rs:7:5
--> $DIR/similarly-named-trait.rs:7:5
|
LL | pub struct St;
| ^^^^^^^^^^^^^
= note: `St` implements similarly named trait `m::TraitWithParam`, but not `TraitWithParam<St>`
help: this trait has no implementations, consider adding one
--> $DIR/similarly_named_trait.rs:2:1
--> $DIR/similarly-named-trait.rs:2:1
|
LL | trait TraitWithParam<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `func2`
--> $DIR/similarly_named_trait.rs:16:13
--> $DIR/similarly-named-trait.rs:16:13
|
LL | fn func2<T: TraitWithParam<T>> (_: T) {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `func2`
Expand Down
Loading