Skip to content

Commit 9a6ef78

Browse files
authored
Unrolled build for rust-lang#115743
Rollup merge of rust-lang#115743 - compiler-errors:no-impls, r=davidtwco Point out if a local trait has no implementations Slightly helps with rust-lang#115741
2 parents 3ebb562 + 30e6cea commit 9a6ef78

File tree

63 files changed

+658
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+658
-6
lines changed

compiler/rustc_middle/src/ty/trait_def.rs

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ pub struct TraitImpls {
9090
}
9191

9292
impl TraitImpls {
93+
pub fn is_empty(&self) -> bool {
94+
self.blanket_impls.is_empty() && self.non_blanket_impls.is_empty()
95+
}
96+
9397
pub fn blanket_impls(&self) -> &[DefId] {
9498
self.blanket_impls.as_slice()
9599
}

compiler/rustc_trait_selection/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ trait_selection_no_value_in_rustc_on_unimplemented = this attribute must have a
4040
.label = expected value here
4141
.note = eg `#[rustc_on_unimplemented(message="foo")]`
4242
43+
trait_selection_trait_has_no_impls = this trait has no implementations, consider adding one
44+
4345
trait_selection_ty_alias_overflow = in case this is a recursive type alias, consider using a struct, enum, or union instead
4446
trait_selection_unable_to_construct_constant_value = unable to construct a constant value for the unevaluated constant {$unevaluated}

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

+19-5
Original file line numberDiff line numberDiff line change
@@ -3009,10 +3009,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
30093009
// Try to report a help message
30103010
if is_fn_trait
30113011
&& let Ok((implemented_kind, params)) = self.type_implements_fn_trait(
3012-
obligation.param_env,
3013-
trait_ref.self_ty(),
3014-
trait_predicate.skip_binder().polarity,
3015-
)
3012+
obligation.param_env,
3013+
trait_ref.self_ty(),
3014+
trait_predicate.skip_binder().polarity,
3015+
)
30163016
{
30173017
self.add_help_message_for_fn_trait(trait_ref, err, implemented_kind, params);
30183018
} else if !trait_ref.has_non_region_infer()
@@ -3031,6 +3031,15 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
30313031
None,
30323032
obligation.cause.body_id,
30333033
);
3034+
} else if trait_ref.def_id().is_local()
3035+
&& self.tcx.trait_impls_of(trait_ref.def_id()).is_empty()
3036+
&& !self.tcx.trait_is_auto(trait_ref.def_id())
3037+
&& !self.tcx.trait_is_alias(trait_ref.def_id())
3038+
{
3039+
err.span_help(
3040+
self.tcx.def_span(trait_ref.def_id()),
3041+
crate::fluent_generated::trait_selection_trait_has_no_impls,
3042+
);
30343043
} else if !suggested && !unsatisfied_const {
30353044
// Can't show anything else useful, try to find similar impls.
30363045
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
@@ -3041,7 +3050,12 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
30413050
err,
30423051
true,
30433052
) {
3044-
self.report_similar_impl_candidates_for_root_obligation(&obligation, *trait_predicate, body_def_id, err);
3053+
self.report_similar_impl_candidates_for_root_obligation(
3054+
&obligation,
3055+
*trait_predicate,
3056+
body_def_id,
3057+
err,
3058+
);
30453059
}
30463060

30473061
self.suggest_convert_to_slice(

tests/ui/associated-consts/associated-const-array-len.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `i32: Foo` is not satisfied
33
|
44
LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
55
| ^^^ the trait `Foo` is not implemented for `i32`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/associated-const-array-len.rs:1:1
9+
|
10+
LL | trait Foo {
11+
| ^^^^^^^^^
612

713
error: aborting due to previous error
814

tests/ui/associated-consts/issue-105330.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
5151
LL | foo::<Demo>()();
5252
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
5353
|
54+
help: this trait has no implementations, consider adding one
55+
--> $DIR/issue-105330.rs:1:1
56+
|
57+
LL | pub trait TraitWAssocConst {
58+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5459
note: required by a bound in `foo`
5560
--> $DIR/issue-105330.rs:11:11
5661
|
@@ -87,6 +92,11 @@ error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
8792
LL | foo::<Demo>();
8893
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
8994
|
95+
help: this trait has no implementations, consider adding one
96+
--> $DIR/issue-105330.rs:1:1
97+
|
98+
LL | pub trait TraitWAssocConst {
99+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
90100
note: required by a bound in `foo`
91101
--> $DIR/issue-105330.rs:11:11
92102
|

tests/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `(): Add<A>` is not satisfied
33
|
44
LL | r = r + a;
55
| ^ the trait `Add<A>` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/associated-types-ICE-when-projecting-out-of-err.rs:15:1
9+
|
10+
LL | trait Add<RHS=Self> {
11+
| ^^^^^^^^^^^^^^^^^^^
612

713
error: aborting due to previous error
814

tests/ui/associated-types/associated-types-no-suitable-supertrait.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `(T, U): Get` is not satisfied
33
|
44
LL | fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
55
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `(T, U)`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/associated-types-no-suitable-supertrait.rs:12:1
9+
|
10+
LL | trait Get {
11+
| ^^^^^^^^^
612

713
error[E0277]: the trait bound `Self: Get` is not satisfied
814
--> $DIR/associated-types-no-suitable-supertrait.rs:17:40

tests/ui/associated-types/defaults-suitability.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ error[E0277]: the trait bound `(): Foo<Self>` is not satisfied
5858
LL | type Assoc: Foo<Self> = ();
5959
| ^^ the trait `Foo<Self>` is not implemented for `()`
6060
|
61+
help: this trait has no implementations, consider adding one
62+
--> $DIR/defaults-suitability.rs:27:1
63+
|
64+
LL | trait Foo<T> {
65+
| ^^^^^^^^^^^^
6166
note: required by a bound in `Bar::Assoc`
6267
--> $DIR/defaults-suitability.rs:34:17
6368
|

tests/ui/associated-types/issue-59324.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ error[E0277]: the trait bound `(): Foo` is not satisfied
4848
|
4949
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
5050
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()`
51+
|
52+
help: this trait has no implementations, consider adding one
53+
--> $DIR/issue-59324.rs:3:1
54+
|
55+
LL | pub trait Foo: NotFoo {
56+
| ^^^^^^^^^^^^^^^^^^^^^
5157

5258
error[E0277]: the trait bound `Bug: Foo` is not satisfied
5359
--> $DIR/issue-59324.rs:19:10

tests/ui/associated-types/issue-64855.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
33
|
44
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
55
| ^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<T>`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-64855.rs:1:1
9+
|
10+
LL | pub trait Foo {
11+
| ^^^^^^^^^^^^^
612

713
error: aborting due to previous error
814

tests/ui/associated-types/point-at-type-on-obligation-failure-2.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied
44
LL | type Assoc = bool;
55
| ^^^^ the trait `Bar` is not implemented for `bool`
66
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/point-at-type-on-obligation-failure-2.rs:1:1
9+
|
10+
LL | trait Bar {}
11+
| ^^^^^^^^^
712
note: required by a bound in `Foo::Assoc`
813
--> $DIR/point-at-type-on-obligation-failure-2.rs:4:17
914
|
@@ -16,6 +21,11 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied
1621
LL | type Assoc = bool;
1722
| ^^^^ the trait `Bar` is not implemented for `bool`
1823
|
24+
help: this trait has no implementations, consider adding one
25+
--> $DIR/point-at-type-on-obligation-failure-2.rs:1:1
26+
|
27+
LL | trait Bar {}
28+
| ^^^^^^^^^
1929
note: required by a bound in `Baz::Assoc`
2030
--> $DIR/point-at-type-on-obligation-failure-2.rs:13:18
2131
|
@@ -31,6 +41,11 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied
3141
LL | type Assoc = bool;
3242
| ^^^^ the trait `Bar` is not implemented for `bool`
3343
|
44+
help: this trait has no implementations, consider adding one
45+
--> $DIR/point-at-type-on-obligation-failure-2.rs:1:1
46+
|
47+
LL | trait Bar {}
48+
| ^^^^^^^^^
3449
note: required by a bound in `Bat::Assoc`
3550
--> $DIR/point-at-type-on-obligation-failure-2.rs:24:27
3651
|

tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ LL | takes_t(t);
66
| |
77
| required by a bound introduced by this call
88
|
9+
help: this trait has no implementations, consider adding one
10+
--> $DIR/coherence-unsafe-trait-object-impl.rs:6:1
11+
|
12+
LL | trait Trait: Sized {
13+
| ^^^^^^^^^^^^^^^^^^
914
note: required by a bound in `takes_t`
1015
--> $DIR/coherence-unsafe-trait-object-impl.rs:10:15
1116
|

tests/ui/const-generics/dont-evaluate-array-len-on-err-1.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `[Adt; std::mem::size_of::<Self::Assoc>()]: Foo` i
33
|
44
LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar()
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/dont-evaluate-array-len-on-err-1.rs:9:1
9+
|
10+
LL | trait Foo {
11+
| ^^^^^^^^^
612

713
error: aborting due to previous error
814

tests/ui/const-generics/generic_const_exprs/issue-85848.stderr

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ LL | writes_to_specific_path(&cap);
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `Delegates<U>` is implemented for `T`
9+
help: this trait has no implementations, consider adding one
10+
--> $DIR/issue-85848.rs:4:1
11+
|
12+
LL | trait _Contains<T> {
13+
| ^^^^^^^^^^^^^^^^^^
1014
note: required for `&C` to implement `Contains<(), true>`
1115
--> $DIR/issue-85848.rs:21:12
1216
|

tests/ui/const-generics/issues/issue-86530.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ LL | z(" ");
66
| |
77
| required by a bound introduced by this call
88
|
9+
help: this trait has no implementations, consider adding one
10+
--> $DIR/issue-86530.rs:4:1
11+
|
12+
LL | pub trait X {
13+
| ^^^^^^^^^^^
914
note: required by a bound in `z`
1015
--> $DIR/issue-86530.rs:10:8
1116
|

tests/ui/cross/cross-fn-cache-hole.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ error[E0277]: the trait bound `i32: Bar<u32>` is not satisfied
44
LL | where i32: Foo<u32, A>
55
| ^^^^^^^^^^^^^^^^ the trait `Bar<u32>` is not implemented for `i32`
66
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/cross-fn-cache-hole.rs:11:1
9+
|
10+
LL | trait Bar<X> { }
11+
| ^^^^^^^^^^^^
712
= help: see issue #48214
813
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
914

tests/ui/dst/dst-bad-coerce1.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied
1515
LL | let f3: &Fat<dyn Bar> = f2;
1616
| ^^ the trait `Bar` is not implemented for `Foo`
1717
|
18+
help: this trait has no implementations, consider adding one
19+
--> $DIR/dst-bad-coerce1.rs:10:1
20+
|
21+
LL | trait Bar { fn bar(&self) {} }
22+
| ^^^^^^^^^
1823
= note: required for the cast from `&Fat<Foo>` to `&Fat<dyn Bar>`
1924

2025
error[E0308]: mismatched types
@@ -34,6 +39,11 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied
3439
LL | let f3: &(dyn Bar,) = f2;
3540
| ^^ the trait `Bar` is not implemented for `Foo`
3641
|
42+
help: this trait has no implementations, consider adding one
43+
--> $DIR/dst-bad-coerce1.rs:10:1
44+
|
45+
LL | trait Bar { fn bar(&self) {} }
46+
| ^^^^^^^^^
3747
= note: required for the cast from `&(Foo,)` to `&(dyn Bar,)`
3848

3949
error: aborting due to 4 previous errors

tests/ui/dyn-star/error.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `{integer}: Foo` is not satisfied
33
|
44
LL | let dyn_i: dyn* Foo = i;
55
| ^ the trait `Foo` is not implemented for `{integer}`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/error.rs:6:1
9+
|
10+
LL | trait Foo {}
11+
| ^^^^^^^^^
612

713
error: aborting due to previous error
814

tests/ui/error-codes/E0277.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ LL | some_func(5i32);
2121
| |
2222
| required by a bound introduced by this call
2323
|
24+
help: this trait has no implementations, consider adding one
25+
--> $DIR/E0277.rs:3:1
26+
|
27+
LL | trait Foo {
28+
| ^^^^^^^^^
2429
note: required by a bound in `some_func`
2530
--> $DIR/E0277.rs:7:17
2631
|

tests/ui/generic-associated-types/issue-101020.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ error[E0277]: the trait bound `for<'a> &'a mut (): Foo<&'a mut ()>` is not satis
44
LL | (&mut EmptyIter).consume(());
55
| ^^^^^^^ the trait `for<'a> Foo<&'a mut ()>` is not implemented for `&'a mut ()`
66
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-101020.rs:28:1
9+
|
10+
LL | trait Foo<T> {}
11+
| ^^^^^^^^^^^^
712
note: required for `&'a mut ()` to implement `for<'a> FuncInput<'a, &'a mut ()>`
813
--> $DIR/issue-101020.rs:27:20
914
|

tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-89118.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied
44
LL | C: StackContext,
55
| ^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()`
66
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-89118.rs:1:1
9+
|
10+
LL | trait BufferMut {}
11+
| ^^^^^^^^^^^^^^^
712
note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>`
813
--> $DIR/issue-89118.rs:5:23
914
|
@@ -26,6 +31,11 @@ error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied
2631
LL | impl<C> EthernetWorker<C> {}
2732
| ^^^^^^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()`
2833
|
34+
help: this trait has no implementations, consider adding one
35+
--> $DIR/issue-89118.rs:1:1
36+
|
37+
LL | trait BufferMut {}
38+
| ^^^^^^^^^^^^^^^
2939
note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>`
3040
--> $DIR/issue-89118.rs:5:23
3141
|
@@ -48,6 +58,11 @@ error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied
4858
LL | type Handler = Ctx<C::Dispatcher>;
4959
| ^^^^^^^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()`
5060
|
61+
help: this trait has no implementations, consider adding one
62+
--> $DIR/issue-89118.rs:1:1
63+
|
64+
LL | trait BufferMut {}
65+
| ^^^^^^^^^^^^^^^
5166
note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>`
5267
--> $DIR/issue-89118.rs:5:23
5368
|

tests/ui/issues/issue-18611.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `isize: HasState` is not satisfied
33
|
44
LL | fn add_state(op: <isize as HasState>::State) {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasState` is not implemented for `isize`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-18611.rs:5:1
9+
|
10+
LL | trait HasState {
11+
| ^^^^^^^^^^^^^^
612

713
error: aborting due to previous error
814

tests/ui/issues/issue-25076.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ LL | do_fold(bot(), ());
66
| |
77
| required by a bound introduced by this call
88
|
9+
help: this trait has no implementations, consider adding one
10+
--> $DIR/issue-25076.rs:3:1
11+
|
12+
LL | trait InOut<T> { type Out; }
13+
| ^^^^^^^^^^^^^^
914
note: required by a bound in `do_fold`
1015
--> $DIR/issue-25076.rs:5:18
1116
|

tests/ui/issues/issue-35570.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied
33
|
44
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
55
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-35570.rs:4:1
9+
|
10+
LL | trait Trait2<'a> {
11+
| ^^^^^^^^^^^^^^^^
612

713
error: aborting due to previous error
814

0 commit comments

Comments
 (0)