From fe8c4ed1628fbfd26c49de1b76ddbc9f64cbfb67 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 1 Feb 2024 23:05:34 +0000 Subject: [PATCH 1/3] Avoid emitting trait bound errors of incoherent traits --- .../error_reporting/type_err_ctxt_ext.rs | 14 ++++++++++++++ .../in-trait/coherence-constrained.rs | 2 -- .../in-trait/coherence-constrained.stderr | 19 +++---------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index dee3e14f3c918..556c7e746cd71 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -2365,6 +2365,12 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { return e; } + if let Err(guar) = self.tcx.ensure().coherent_trait(trait_ref.def_id()) { + // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case + // other `Foo` impls are incoherent. + return guar; + } + // This is kind of a hack: it frequently happens that some earlier // error prevents types from being fully inferred, and then we get // a bunch of uninteresting errors saying something like " InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if let Some(e) = self.tainted_by_errors() { return e; } + + if let Err(guar) = + self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_ty.def_id)) + { + // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case + // other `Foo` impls are incoherent. + return guar; + } let subst = data .projection_ty .args diff --git a/tests/ui/async-await/in-trait/coherence-constrained.rs b/tests/ui/async-await/in-trait/coherence-constrained.rs index 8e62b3e0e90bf..82c8724ca3e61 100644 --- a/tests/ui/async-await/in-trait/coherence-constrained.rs +++ b/tests/ui/async-await/in-trait/coherence-constrained.rs @@ -12,7 +12,6 @@ impl Foo for Bar { type T = (); async fn foo(&self) {} - //~^ ERROR type annotations needed: cannot satisfy `::T == ()` } impl Foo for Bar { @@ -20,7 +19,6 @@ impl Foo for Bar { type T = (); async fn foo(&self) {} - //~^ ERROR type annotations needed: cannot satisfy `::T == ()` } fn main() {} diff --git a/tests/ui/async-await/in-trait/coherence-constrained.stderr b/tests/ui/async-await/in-trait/coherence-constrained.stderr index 570a357ca8fb7..5c48a1fe98fc5 100644 --- a/tests/ui/async-await/in-trait/coherence-constrained.stderr +++ b/tests/ui/async-await/in-trait/coherence-constrained.stderr @@ -1,17 +1,5 @@ -error[E0284]: type annotations needed: cannot satisfy `::T == ()` - --> $DIR/coherence-constrained.rs:14:5 - | -LL | async fn foo(&self) {} - | ^^^^^^^^^^^^^^^^^^^ cannot satisfy `::T == ()` - -error[E0284]: type annotations needed: cannot satisfy `::T == ()` - --> $DIR/coherence-constrained.rs:22:5 - | -LL | async fn foo(&self) {} - | ^^^^^^^^^^^^^^^^^^^ cannot satisfy `::T == ()` - error[E0119]: conflicting implementations of trait `Foo` for type `Bar` - --> $DIR/coherence-constrained.rs:18:1 + --> $DIR/coherence-constrained.rs:17:1 | LL | impl Foo for Bar { | ---------------- first implementation here @@ -19,7 +7,6 @@ LL | impl Foo for Bar { LL | impl Foo for Bar { | ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar` -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0119, E0284. -For more information about an error, try `rustc --explain E0119`. +For more information about this error, try `rustc --explain E0119`. From 965da3a5d1659c0752f9b47dda27f7bd1a6525bc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 2 Feb 2024 08:36:46 +0000 Subject: [PATCH 2/3] Stop bailing out from compilation just because there were incoherent traits --- .../src/check/compare_impl_item.rs | 4 ++ .../rustc_hir_analysis/src/check/wfcheck.rs | 7 ++++ compiler/rustc_hir_analysis/src/lib.rs | 4 +- tests/ui/associated-consts/issue-105330.rs | 1 + .../ui/associated-consts/issue-105330.stderr | 12 ++++-- tests/ui/coherence/associated-type2.rs | 20 +++++++++ tests/ui/coherence/associated-type2.stderr | 12 ++++++ ...t-conflicts-with-specific-multidispatch.rs | 1 + ...nflicts-with-specific-multidispatch.stderr | 22 +++++++++- tests/ui/coherence/coherence-orphan.rs | 3 ++ tests/ui/coherence/coherence-orphan.stderr | 33 +++++++++++++-- tests/ui/coherence/deep-bad-copy-reason.rs | 5 +++ .../ui/coherence/deep-bad-copy-reason.stderr | 31 ++++++++++++-- .../occurs-check/opaques.next.stderr | 13 ++++-- tests/ui/coherence/occurs-check/opaques.rs | 1 + tests/ui/error-codes/E0117.rs | 1 + tests/ui/error-codes/E0117.stderr | 14 +++++-- tests/ui/error-codes/E0120.rs | 2 + tests/ui/error-codes/E0120.stderr | 27 +++++++++++- tests/ui/error-codes/E0374.rs | 2 +- tests/ui/error-codes/E0374.stderr | 13 +++++- tests/ui/error-codes/E0375.rs | 2 +- tests/ui/error-codes/E0375.stderr | 30 +++++++++++++- tests/ui/issues/issue-67535.rs | 6 +-- tests/ui/issues/issue-67535.stderr | 41 ++++++++++++++++++- .../override-item-on-marker-trait.rs | 2 + .../override-item-on-marker-trait.stderr | 21 ++++++++-- ...n-default-items-drop-coherence.next.stderr | 11 ++++- ...ialization-default-items-drop-coherence.rs | 14 +++---- .../missing-bound-in-derive-copy-impl-3.fixed | 4 +- .../missing-bound-in-derive-copy-impl-3.rs | 2 +- ...missing-bound-in-derive-copy-impl-3.stderr | 21 +++++++++- .../missing-bound-in-derive-copy-impl.rs | 2 + .../missing-bound-in-derive-copy-impl.stderr | 37 ++++++++++++++++- tests/ui/traits/issue-50480.rs | 2 + tests/ui/traits/issue-50480.stderr | 28 ++++++++++--- tests/ui/traits/issue-78372.rs | 3 +- tests/ui/traits/issue-78372.stderr | 33 +++++++++++++-- .../trait_ref_is_knowable-norm-overflow.rs | 1 + ...trait_ref_is_knowable-norm-overflow.stderr | 24 +++++++++-- .../next-solver/issue-118950-root-region.rs | 1 + .../issue-118950-root-region.stderr | 12 ++++-- .../ui/typeck/typeck_type_placeholder_item.rs | 1 + .../typeck_type_placeholder_item.stderr | 37 ++++++++++------- 44 files changed, 480 insertions(+), 83 deletions(-) create mode 100644 tests/ui/coherence/associated-type2.rs create mode 100644 tests/ui/coherence/associated-type2.stderr diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 379c1154e5f26..d0683686d3812 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -1990,6 +1990,10 @@ pub(super) fn check_type_bounds<'tcx>( impl_ty: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, ) -> Result<(), ErrorGuaranteed> { + // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case + // other `Foo` impls are incoherent. + tcx.ensure().coherent_trait(impl_trait_ref.def_id)?; + let param_env = tcx.param_env(impl_ty.def_id); debug!(?param_env); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index b0510f9a75b3b..141ec33178938 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1006,6 +1006,10 @@ fn check_associated_item( enter_wf_checking_ctxt(tcx, span, item_id, |wfcx| { let item = tcx.associated_item(item_id); + // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case + // other `Foo` impls are incoherent. + tcx.ensure().coherent_trait(tcx.local_parent(item_id))?; + let self_ty = match item.container { ty::TraitContainer => tcx.types.self_param, ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(), @@ -1292,6 +1296,9 @@ fn check_impl<'tcx>( // therefore don't need to be WF (the trait's `Self: Trait` predicate // won't hold). let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity(); + // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case + // other `Foo` impls are incoherent. + tcx.ensure().coherent_trait(trait_ref.def_id)?; let trait_ref = wfcx.normalize( ast_trait_ref.path.span, Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 454cb97ac148b..2e85da98269cf 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -169,11 +169,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { tcx.sess.time("coherence_checking", || { // Check impls constrain their parameters - let mut res = + let res = tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_impl_wf(module)); for &trait_def_id in tcx.all_local_trait_impls(()).keys() { - res = res.and(tcx.ensure().coherent_trait(trait_def_id)); + let _ = tcx.ensure().coherent_trait(trait_def_id); } // these queries are executed for side-effects (error reporting): res.and(tcx.ensure().crate_inherent_impls(())) diff --git a/tests/ui/associated-consts/issue-105330.rs b/tests/ui/associated-consts/issue-105330.rs index 285e89cce4985..6c6dae864f340 100644 --- a/tests/ui/associated-consts/issue-105330.rs +++ b/tests/ui/associated-consts/issue-105330.rs @@ -14,5 +14,6 @@ fn foo>() { //~ ERROR E0658 fn main>() { //~^ ERROR E0658 + //~| ERROR E0131 foo::(); } diff --git a/tests/ui/associated-consts/issue-105330.stderr b/tests/ui/associated-consts/issue-105330.stderr index 452367bed1201..b4c021d0f4fdc 100644 --- a/tests/ui/associated-consts/issue-105330.stderr +++ b/tests/ui/associated-consts/issue-105330.stderr @@ -43,7 +43,13 @@ LL | impl TraitWAssocConst for impl Demo { | = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error: aborting due to 5 previous errors +error[E0131]: `main` function is not allowed to have generic parameters + --> $DIR/issue-105330.rs:15:8 + | +LL | fn main>() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters + +error: aborting due to 6 previous errors -Some errors have detailed explanations: E0404, E0562, E0658. -For more information about an error, try `rustc --explain E0404`. +Some errors have detailed explanations: E0131, E0404, E0562, E0658. +For more information about an error, try `rustc --explain E0131`. diff --git a/tests/ui/coherence/associated-type2.rs b/tests/ui/coherence/associated-type2.rs new file mode 100644 index 0000000000000..2aadfb04af05d --- /dev/null +++ b/tests/ui/coherence/associated-type2.rs @@ -0,0 +1,20 @@ +//! A regression test for #120343. The overlap error was previously +//! silenced in coherence because projecting `<() as ToUnit>::Unit` +//! failed. Then then silenced the missing items error in the `ToUnit` +//! impl, causing us to not emit any errors and ICEing due to a +//! `span_delay_bug`. + +trait ToUnit { + type Unit; +} + +impl ToUnit for *const T {} +//~^ ERROR: not all trait items implemented + +trait Overlap {} + +impl Overlap for T {} + +impl Overlap<<*const T as ToUnit>::Unit> for T {} + +fn main() {} diff --git a/tests/ui/coherence/associated-type2.stderr b/tests/ui/coherence/associated-type2.stderr new file mode 100644 index 0000000000000..62d3d8b8ebd1c --- /dev/null +++ b/tests/ui/coherence/associated-type2.stderr @@ -0,0 +1,12 @@ +error[E0046]: not all trait items implemented, missing: `Unit` + --> $DIR/associated-type2.rs:11:1 + | +LL | type Unit; + | --------- `Unit` from trait +... +LL | impl ToUnit for *const T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Unit` in implementation + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0046`. diff --git a/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs b/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs index 6a9db217373f9..cdec81271d090 100644 --- a/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs +++ b/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs @@ -22,6 +22,7 @@ struct MyType { impl MyTrait for MyType { //~^ ERROR E0119 fn get(&self) -> usize { (*self).clone() } + //~^ ERROR incompatible type } fn main() { } diff --git a/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr b/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr index ddb7474c2899a..471dfe1cae79d 100644 --- a/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr +++ b/tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr @@ -7,6 +7,24 @@ LL | impl MyTrait for T { LL | impl MyTrait for MyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType` -error: aborting due to 1 previous error +error[E0053]: method `get` has an incompatible type for trait + --> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:24:22 + | +LL | fn get(&self) -> usize { (*self).clone() } + | ^^^^^ + | | + | expected `MyType`, found `usize` + | help: change the output type to match the trait: `MyType` + | +note: type in trait + --> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:8:22 + | +LL | fn get(&self) -> T; + | ^ + = note: expected signature `fn(&MyType) -> MyType` + found signature `fn(&MyType) -> usize` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0119`. +Some errors have detailed explanations: E0053, E0119. +For more information about an error, try `rustc --explain E0053`. diff --git a/tests/ui/coherence/coherence-orphan.rs b/tests/ui/coherence/coherence-orphan.rs index bed782203af50..985cfe8716130 100644 --- a/tests/ui/coherence/coherence-orphan.rs +++ b/tests/ui/coherence/coherence-orphan.rs @@ -9,10 +9,13 @@ struct TheType; impl TheTrait for isize { } //~^ ERROR E0117 +//~| ERROR not all trait items implemented impl TheTrait for isize { } +//~^ ERROR not all trait items implemented impl TheTrait for TheType { } +//~^ ERROR not all trait items implemented impl !Send for Vec { } //~ ERROR E0117 //~^ WARNING diff --git a/tests/ui/coherence/coherence-orphan.stderr b/tests/ui/coherence/coherence-orphan.stderr index 9ec1d0dc32aa4..78fad837647b4 100644 --- a/tests/ui/coherence/coherence-orphan.stderr +++ b/tests/ui/coherence/coherence-orphan.stderr @@ -11,7 +11,7 @@ LL | impl TheTrait for isize { } = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate - --> $DIR/coherence-orphan.rs:17:1 + --> $DIR/coherence-orphan.rs:20:1 | LL | impl !Send for Vec { } | ^^^^^^^^^^^^^^^---------- @@ -22,7 +22,7 @@ LL | impl !Send for Vec { } = note: define and implement a trait or new type instead warning: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/coherence-orphan.rs:17:1 + --> $DIR/coherence-orphan.rs:20:1 | LL | impl !Send for Vec { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,6 +34,31 @@ note: try using the same sequence of generic parameters as the struct definition --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL = note: `#[warn(suspicious_auto_trait_impls)]` on by default -error: aborting due to 2 previous errors; 1 warning emitted +error[E0046]: not all trait items implemented, missing: `the_fn` + --> $DIR/coherence-orphan.rs:10:1 + | +LL | impl TheTrait for isize { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation + | + = help: implement the missing item: `fn the_fn(&self) { todo!() }` + +error[E0046]: not all trait items implemented, missing: `the_fn` + --> $DIR/coherence-orphan.rs:14:1 + | +LL | impl TheTrait for isize { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation + | + = help: implement the missing item: `fn the_fn(&self) { todo!() }` + +error[E0046]: not all trait items implemented, missing: `the_fn` + --> $DIR/coherence-orphan.rs:17:1 + | +LL | impl TheTrait for TheType { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation + | + = help: implement the missing item: `fn the_fn(&self) { todo!() }` + +error: aborting due to 5 previous errors; 1 warning emitted -For more information about this error, try `rustc --explain E0117`. +Some errors have detailed explanations: E0046, E0117. +For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/coherence/deep-bad-copy-reason.rs b/tests/ui/coherence/deep-bad-copy-reason.rs index 97fd3f719bfbf..cb7b7eb116565 100644 --- a/tests/ui/coherence/deep-bad-copy-reason.rs +++ b/tests/ui/coherence/deep-bad-copy-reason.rs @@ -5,12 +5,15 @@ extern "Rust" { } pub struct ListS { + //~^ NOTE: required because it appears within the type len: usize, data: [T; 0], opaque: OpaqueListContents, } pub struct Interned<'a, T>(&'a T); +//~^ NOTE: required by this bound +//~| NOTE: required by a bound impl<'a, T> Clone for Interned<'a, T> { fn clone(&self) -> Self { @@ -23,6 +26,8 @@ impl<'a, T> Copy for Interned<'a, T> {} pub struct List<'tcx, T>(Interned<'tcx, ListS>); //~^ NOTE this field does not implement `Copy` //~| NOTE the `Copy` impl for `Interned<'tcx, ListS>` requires that `OpaqueListContents: Sized` +//~| NOTE: doesn't have a size known at compile-time +//~| ERROR: cannot be known at compilation time impl<'tcx, T> Clone for List<'tcx, T> { fn clone(&self) -> Self { diff --git a/tests/ui/coherence/deep-bad-copy-reason.stderr b/tests/ui/coherence/deep-bad-copy-reason.stderr index e79abe35597d4..0b5c0ec713b42 100644 --- a/tests/ui/coherence/deep-bad-copy-reason.stderr +++ b/tests/ui/coherence/deep-bad-copy-reason.stderr @@ -1,5 +1,5 @@ error[E0204]: the trait `Copy` cannot be implemented for this type - --> $DIR/deep-bad-copy-reason.rs:33:24 + --> $DIR/deep-bad-copy-reason.rs:38:24 | LL | pub struct List<'tcx, T>(Interned<'tcx, ListS>); | ------------------------ this field does not implement `Copy` @@ -8,11 +8,34 @@ LL | impl<'tcx, T> Copy for List<'tcx, T> {} | ^^^^^^^^^^^^^ | note: the `Copy` impl for `Interned<'tcx, ListS>` requires that `OpaqueListContents: Sized` - --> $DIR/deep-bad-copy-reason.rs:23:26 + --> $DIR/deep-bad-copy-reason.rs:26:26 | LL | pub struct List<'tcx, T>(Interned<'tcx, ListS>); | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error[E0277]: the size for values of type `OpaqueListContents` cannot be known at compilation time + --> $DIR/deep-bad-copy-reason.rs:26:26 + | +LL | pub struct List<'tcx, T>(Interned<'tcx, ListS>); + | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: within `ListS`, the trait `Sized` is not implemented for `OpaqueListContents`, which is required by `ListS: Sized` +note: required because it appears within the type `ListS` + --> $DIR/deep-bad-copy-reason.rs:7:12 + | +LL | pub struct ListS { + | ^^^^^ +note: required by a bound in `Interned` + --> $DIR/deep-bad-copy-reason.rs:14:25 + | +LL | pub struct Interned<'a, T>(&'a T); + | ^ required by this bound in `Interned` +help: consider relaxing the implicit `Sized` restriction + | +LL | pub struct Interned<'a, T: ?Sized>(&'a T); + | ++++++++ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0204`. +Some errors have detailed explanations: E0204, E0277. +For more information about an error, try `rustc --explain E0204`. diff --git a/tests/ui/coherence/occurs-check/opaques.next.stderr b/tests/ui/coherence/occurs-check/opaques.next.stderr index 428ee902ea528..4ad8257d2c14b 100644 --- a/tests/ui/coherence/occurs-check/opaques.next.stderr +++ b/tests/ui/coherence/occurs-check/opaques.next.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait>` for type `Alias<_>` - --> $DIR/opaques.rs:29:1 + --> $DIR/opaques.rs:30:1 | LL | impl Trait for T { | ---------------------- first implementation here @@ -7,6 +7,13 @@ LL | impl Trait for T { LL | impl Trait for defining_scope::Alias { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Alias<_>` -error: aborting due to 1 previous error +error[E0282]: type annotations needed + --> $DIR/opaques.rs:13:20 + | +LL | pub fn cast(x: Container, T>) -> Container { + | ^ cannot infer type for struct `Container, T>` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0119`. +Some errors have detailed explanations: E0119, E0282. +For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/coherence/occurs-check/opaques.rs b/tests/ui/coherence/occurs-check/opaques.rs index 2fa9dcebfdec4..73cd42bf3f25d 100644 --- a/tests/ui/coherence/occurs-check/opaques.rs +++ b/tests/ui/coherence/occurs-check/opaques.rs @@ -11,6 +11,7 @@ mod defining_scope { pub type Alias = impl Sized; pub fn cast(x: Container, T>) -> Container { + //[next]~^ ERROR type annotations needed x } } diff --git a/tests/ui/error-codes/E0117.rs b/tests/ui/error-codes/E0117.rs index 406d24e366614..32b9863806c04 100644 --- a/tests/ui/error-codes/E0117.rs +++ b/tests/ui/error-codes/E0117.rs @@ -1,4 +1,5 @@ impl Drop for u32 {} //~ ERROR E0117 //~| ERROR the `Drop` trait may only be implemented for local structs, enums, and unions +//~| ERROR not all trait items implemented fn main() {} diff --git a/tests/ui/error-codes/E0117.stderr b/tests/ui/error-codes/E0117.stderr index f144aa9f72c13..058a64b20d171 100644 --- a/tests/ui/error-codes/E0117.stderr +++ b/tests/ui/error-codes/E0117.stderr @@ -15,7 +15,15 @@ error[E0120]: the `Drop` trait may only be implemented for local structs, enums, LL | impl Drop for u32 {} | ^^^ must be a struct, enum, or union in the current crate -error: aborting due to 2 previous errors +error[E0046]: not all trait items implemented, missing: `drop` + --> $DIR/E0117.rs:1:1 + | +LL | impl Drop for u32 {} + | ^^^^^^^^^^^^^^^^^ missing `drop` in implementation + | + = help: implement the missing item: `fn drop(&mut self) { todo!() }` + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0117, E0120. -For more information about an error, try `rustc --explain E0117`. +Some errors have detailed explanations: E0046, E0117, E0120. +For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/error-codes/E0120.rs b/tests/ui/error-codes/E0120.rs index a0a301a06e2ed..eb6f4e22bb5f3 100644 --- a/tests/ui/error-codes/E0120.rs +++ b/tests/ui/error-codes/E0120.rs @@ -3,6 +3,8 @@ trait MyTrait { fn foo() {} } impl Drop for dyn MyTrait { //~^ ERROR E0120 fn drop(&mut self) {} + //~^ ERROR E0038 + } fn main() {} diff --git a/tests/ui/error-codes/E0120.stderr b/tests/ui/error-codes/E0120.stderr index aef777ad06071..f8189486bdcd7 100644 --- a/tests/ui/error-codes/E0120.stderr +++ b/tests/ui/error-codes/E0120.stderr @@ -4,6 +4,29 @@ error[E0120]: the `Drop` trait may only be implemented for local structs, enums, LL | impl Drop for dyn MyTrait { | ^^^^^^^^^^^ must be a struct, enum, or union in the current crate -error: aborting due to 1 previous error +error[E0038]: the trait `MyTrait` cannot be made into an object + --> $DIR/E0120.rs:5:18 + | +LL | fn drop(&mut self) {} + | ^^^^ `MyTrait` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/E0120.rs:1:20 + | +LL | trait MyTrait { fn foo() {} } + | ------- ^^^ ...because associated function `foo` has no `self` parameter + | | + | this trait cannot be made into an object... +help: consider turning `foo` into a method by giving it a `&self` argument + | +LL | trait MyTrait { fn foo(&self) {} } + | +++++ +help: alternatively, consider constraining `foo` so it does not apply to trait objects + | +LL | trait MyTrait { fn foo() where Self: Sized {} } + | +++++++++++++++++ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0120`. +Some errors have detailed explanations: E0038, E0120. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/error-codes/E0374.rs b/tests/ui/error-codes/E0374.rs index 41fcedc328df1..47b9bea978e40 100644 --- a/tests/ui/error-codes/E0374.rs +++ b/tests/ui/error-codes/E0374.rs @@ -1,7 +1,7 @@ #![feature(coerce_unsized)] use std::ops::CoerceUnsized; -struct Foo { +struct Foo { //~ ERROR `T` is never used a: i32, } diff --git a/tests/ui/error-codes/E0374.stderr b/tests/ui/error-codes/E0374.stderr index 148fa1348ab66..d70ac205c2f81 100644 --- a/tests/ui/error-codes/E0374.stderr +++ b/tests/ui/error-codes/E0374.stderr @@ -7,6 +7,15 @@ LL | | where T: CoerceUnsized {} | = note: expected a single field to be coerced, none found -error: aborting due to 1 previous error +error[E0392]: parameter `T` is never used + --> $DIR/E0374.rs:4:12 + | +LL | struct Foo { + | ^ unused parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0374`. +Some errors have detailed explanations: E0374, E0392. +For more information about an error, try `rustc --explain E0374`. diff --git a/tests/ui/error-codes/E0375.rs b/tests/ui/error-codes/E0375.rs index 0c03a8761df01..eaf99dd384230 100644 --- a/tests/ui/error-codes/E0375.rs +++ b/tests/ui/error-codes/E0375.rs @@ -3,7 +3,7 @@ use std::ops::CoerceUnsized; struct Foo { a: i32, - b: T, + b: T, //~ ERROR E0277 c: U, } diff --git a/tests/ui/error-codes/E0375.stderr b/tests/ui/error-codes/E0375.stderr index 0a5e4128ae9d7..d5340022d68ce 100644 --- a/tests/ui/error-codes/E0375.stderr +++ b/tests/ui/error-codes/E0375.stderr @@ -7,6 +7,32 @@ LL | impl CoerceUnsized> for Foo {} = note: `CoerceUnsized` may only be implemented for a coercion between structures with one field being coerced = note: currently, 2 fields need coercions: `b` (`T` to `U`), `c` (`U` to `T`) -error: aborting due to 1 previous error +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/E0375.rs:6:8 + | +LL | struct Foo { + | - this type parameter needs to be `Sized` +LL | a: i32, +LL | b: T, + | ^ doesn't have a size known at compile-time + | + = note: only the last field of a struct may have a dynamically sized type + = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - struct Foo { +LL + struct Foo { + | +help: borrowed types always have a statically known size + | +LL | b: &T, + | + +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | b: Box, + | ++++ + + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0375`. +Some errors have detailed explanations: E0277, E0375. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/issues/issue-67535.rs b/tests/ui/issues/issue-67535.rs index 24f50621310f1..153b95a167434 100644 --- a/tests/ui/issues/issue-67535.rs +++ b/tests/ui/issues/issue-67535.rs @@ -2,21 +2,21 @@ fn main() {} impl std::ops::AddAssign for () { //~^ ERROR only traits defined in the current crate can be implemented for arbitrary types - fn add_assign(&self, other: ()) -> () { + fn add_assign(&self, other: ()) -> () { //~ ERROR incompatible type () } } impl std::ops::AddAssign for [(); 1] { //~^ ERROR only traits defined in the current crate can be implemented for arbitrary types - fn add_assign(&self, other: [(); 1]) -> [(); 1] { + fn add_assign(&self, other: [(); 1]) -> [(); 1] { //~ ERROR incompatible type [()] } } impl std::ops::AddAssign for &[u8] { //~^ ERROR only traits defined in the current crate can be implemented for arbitrary types - fn add_assign(&self, other: &[u8]) -> &[u8] { + fn add_assign(&self, other: &[u8]) -> &[u8] { //~ ERROR incompatible type self } } diff --git a/tests/ui/issues/issue-67535.stderr b/tests/ui/issues/issue-67535.stderr index 4d7a02a50969f..c8bde2cb88c77 100644 --- a/tests/ui/issues/issue-67535.stderr +++ b/tests/ui/issues/issue-67535.stderr @@ -34,6 +34,43 @@ LL | impl std::ops::AddAssign for &[u8] { | = note: define and implement a trait or new type instead -error: aborting due to 3 previous errors +error[E0053]: method `add_assign` has an incompatible type for trait + --> $DIR/issue-67535.rs:5:19 + | +LL | fn add_assign(&self, other: ()) -> () { + | ^^^^^ + | | + | types differ in mutability + | help: change the self-receiver type to match the trait: `&mut self` + | + = note: expected signature `fn(&mut (), ())` + found signature `fn(&(), ())` + +error[E0053]: method `add_assign` has an incompatible type for trait + --> $DIR/issue-67535.rs:12:19 + | +LL | fn add_assign(&self, other: [(); 1]) -> [(); 1] { + | ^^^^^ + | | + | types differ in mutability + | help: change the self-receiver type to match the trait: `&mut self` + | + = note: expected signature `fn(&mut _, _)` + found signature `fn(&_, _) -> [(); 1]` + +error[E0053]: method `add_assign` has an incompatible type for trait + --> $DIR/issue-67535.rs:19:19 + | +LL | fn add_assign(&self, other: &[u8]) -> &[u8] { + | ^^^^^ + | | + | types differ in mutability + | help: change the self-receiver type to match the trait: `&mut self` + | + = note: expected signature `fn(&mut &_, &_)` + found signature `fn(&&_, &_) -> &[u8]` + +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0117`. +Some errors have detailed explanations: E0053, E0117. +For more information about an error, try `rustc --explain E0053`. diff --git a/tests/ui/marker_trait_attr/override-item-on-marker-trait.rs b/tests/ui/marker_trait_attr/override-item-on-marker-trait.rs index 5376fc89d4f4a..d91a8055aa16d 100644 --- a/tests/ui/marker_trait_attr/override-item-on-marker-trait.rs +++ b/tests/ui/marker_trait_attr/override-item-on-marker-trait.rs @@ -3,7 +3,9 @@ #[marker] trait Marker { const N: usize = 0; + //~^ ERROR marker traits cannot have associated items fn do_something() {} + //~^ ERROR marker traits cannot have associated items } struct OverrideConst; diff --git a/tests/ui/marker_trait_attr/override-item-on-marker-trait.stderr b/tests/ui/marker_trait_attr/override-item-on-marker-trait.stderr index 1d30c6d566742..92a54cff7f5fa 100644 --- a/tests/ui/marker_trait_attr/override-item-on-marker-trait.stderr +++ b/tests/ui/marker_trait_attr/override-item-on-marker-trait.stderr @@ -1,15 +1,28 @@ error[E0715]: impls for marker traits cannot contain items - --> $DIR/override-item-on-marker-trait.rs:10:1 + --> $DIR/override-item-on-marker-trait.rs:12:1 | LL | impl Marker for OverrideConst { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0715]: impls for marker traits cannot contain items - --> $DIR/override-item-on-marker-trait.rs:16:1 + --> $DIR/override-item-on-marker-trait.rs:18:1 | LL | impl Marker for OverrideFn { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error[E0714]: marker traits cannot have associated items + --> $DIR/override-item-on-marker-trait.rs:5:5 + | +LL | const N: usize = 0; + | ^^^^^^^^^^^^^^ + +error[E0714]: marker traits cannot have associated items + --> $DIR/override-item-on-marker-trait.rs:7:5 + | +LL | fn do_something() {} + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0715`. +Some errors have detailed explanations: E0714, E0715. +For more information about an error, try `rustc --explain E0714`. diff --git a/tests/ui/specialization/specialization-default-items-drop-coherence.next.stderr b/tests/ui/specialization/specialization-default-items-drop-coherence.next.stderr index e9498a003179b..78d77a78e0eef 100644 --- a/tests/ui/specialization/specialization-default-items-drop-coherence.next.stderr +++ b/tests/ui/specialization/specialization-default-items-drop-coherence.next.stderr @@ -7,6 +7,13 @@ LL | impl Overlap for u32 { LL | impl Overlap for ::Id { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u32` -error: aborting due to 1 previous error +error[E0282]: type annotations needed + --> $DIR/specialization-default-items-drop-coherence.rs:18:23 + | +LL | default type Id = T; + | ^ cannot infer type for associated type `::Id` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0119`. +Some errors have detailed explanations: E0119, E0282. +For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/specialization/specialization-default-items-drop-coherence.rs b/tests/ui/specialization/specialization-default-items-drop-coherence.rs index 37903c210714e..87eb5d90def70 100644 --- a/tests/ui/specialization/specialization-default-items-drop-coherence.rs +++ b/tests/ui/specialization/specialization-default-items-drop-coherence.rs @@ -11,25 +11,25 @@ #![allow(incomplete_features)] trait Default { - type Id; + type Id; } impl Default for T { - default type Id = T; + default type Id = T; //[next]~ ERROR type annotations needed } trait Overlap { - type Assoc; + type Assoc; } impl Overlap for u32 { - type Assoc = usize; + type Assoc = usize; } impl Overlap for ::Id { - //[coherence]~^ ERROR conflicting implementations of trait `Overlap` for type `u32` - //[next]~^^ ERROR conflicting implementations of trait `Overlap` for type `u32` - type Assoc = Box; + //[coherence]~^ ERROR conflicting implementations of trait `Overlap` for type `u32` + //[next]~^^ ERROR conflicting implementations of trait `Overlap` for type `u32` + type Assoc = Box; } fn main() {} diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.fixed b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.fixed index 47b35b412c037..53476ee8c5936 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.fixed +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.fixed @@ -8,8 +8,8 @@ pub struct Vector2{ } #[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented for this type -pub struct AABB{ - pub loc: Vector2, +pub struct AABB{ + pub loc: Vector2, //~ ERROR `K` doesn't implement `Debug` pub size: Vector2 } diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.rs b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.rs index 771e9105c6211..08c4f344e4ef0 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.rs +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.rs @@ -9,7 +9,7 @@ pub struct Vector2{ #[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented for this type pub struct AABB{ - pub loc: Vector2, + pub loc: Vector2, //~ ERROR `K` doesn't implement `Debug` pub size: Vector2 } diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr index ed1bde5f83e53..bfb96b4076b0f 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr @@ -18,6 +18,23 @@ help: consider further restricting this bound LL | pub struct AABB{ | +++++++ -error: aborting due to 1 previous error +error[E0277]: `K` doesn't implement `Debug` + --> $DIR/missing-bound-in-derive-copy-impl-3.rs:12:14 + | +LL | pub loc: Vector2, + | ^^^^^^^^^^ `K` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | +note: required by a bound in `Vector2` + --> $DIR/missing-bound-in-derive-copy-impl-3.rs:5:23 + | +LL | pub struct Vector2{ + | ^^^^^ required by this bound in `Vector2` +help: consider further restricting this bound + | +LL | pub struct AABB{ + | +++++++++++++++++ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0204`. +Some errors have detailed explanations: E0204, E0277. +For more information about an error, try `rustc --explain E0204`. diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs index 9c7b7ba099c43..2f1ebc1f133d6 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs @@ -9,6 +9,8 @@ pub struct Vector2{ #[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented for this type pub struct AABB{ pub loc: Vector2, + //~^ ERROR doesn't implement `Debug` + //~| ERROR `K: Copy` is not satisfied pub size: Vector2 } diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr index 03db737fa8761..f3213e1a4c818 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr @@ -18,6 +18,39 @@ help: consider restricting type parameter `K` LL | pub struct AABB{ | +++++++ -error: aborting due to 1 previous error +error[E0277]: `K` doesn't implement `Debug` + --> $DIR/missing-bound-in-derive-copy-impl.rs:11:14 + | +LL | pub loc: Vector2, + | ^^^^^^^^^^ `K` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | +note: required by a bound in `Vector2` + --> $DIR/missing-bound-in-derive-copy-impl.rs:4:23 + | +LL | pub struct Vector2{ + | ^^^^^ required by this bound in `Vector2` +help: consider restricting type parameter `K` + | +LL | pub struct AABB{ + | +++++++++++++++++ + +error[E0277]: the trait bound `K: Copy` is not satisfied + --> $DIR/missing-bound-in-derive-copy-impl.rs:11:14 + | +LL | pub loc: Vector2, + | ^^^^^^^^^^ the trait `Copy` is not implemented for `K` + | +note: required by a bound in `Vector2` + --> $DIR/missing-bound-in-derive-copy-impl.rs:4:31 + | +LL | pub struct Vector2{ + | ^^^^ required by this bound in `Vector2` +help: consider restricting type parameter `K` + | +LL | pub struct AABB{ + | +++++++++++++++++++ + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0204`. +Some errors have detailed explanations: E0204, E0277. +For more information about an error, try `rustc --explain E0204`. diff --git a/tests/ui/traits/issue-50480.rs b/tests/ui/traits/issue-50480.rs index 683a85a32c1c6..cc7ea32eb3a5c 100644 --- a/tests/ui/traits/issue-50480.rs +++ b/tests/ui/traits/issue-50480.rs @@ -5,11 +5,13 @@ struct Foo(N, NotDefined, ::Item, Vec, String); //~| ERROR cannot find type `NotDefined` in this scope //~| ERROR cannot find type `N` in this scope //~| ERROR cannot find type `N` in this scope +//~| ERROR `i32` is not an iterator #[derive(Clone, Copy)] //~^ ERROR the trait `Copy` cannot be implemented for this type struct Bar(T, N, NotDefined, ::Item, Vec, String); //~^ ERROR cannot find type `NotDefined` in this scope //~| ERROR cannot find type `N` in this scope +//~| ERROR `i32` is not an iterator fn main() {} diff --git a/tests/ui/traits/issue-50480.stderr b/tests/ui/traits/issue-50480.stderr index 4f72db60a1647..68d3d5c80d0d2 100644 --- a/tests/ui/traits/issue-50480.stderr +++ b/tests/ui/traits/issue-50480.stderr @@ -38,7 +38,7 @@ LL | struct Foo(N, NotDefined, ::Item, Vec, St | ++++++++++++ error[E0412]: cannot find type `N` in this scope - --> $DIR/issue-50480.rs:11:18 + --> $DIR/issue-50480.rs:12:18 | LL | struct Bar(T, N, NotDefined, ::Item, Vec, String); | - ^ @@ -55,7 +55,7 @@ LL | struct Bar(T, N, NotDefined, ::Item, Vec, Strin | +++ error[E0412]: cannot find type `NotDefined` in this scope - --> $DIR/issue-50480.rs:11:21 + --> $DIR/issue-50480.rs:12:21 | LL | struct Bar(T, N, NotDefined, ::Item, Vec, String); | ^^^^^^^^^^ not found in this scope @@ -74,7 +74,7 @@ LL | struct Foo(N, NotDefined, ::Item, Vec, String); = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0204]: the trait `Copy` cannot be implemented for this type - --> $DIR/issue-50480.rs:9:17 + --> $DIR/issue-50480.rs:10:17 | LL | #[derive(Clone, Copy)] | ^^^^ @@ -86,7 +86,25 @@ LL | struct Bar(T, N, NotDefined, ::Item, Vec, String); | = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 8 previous errors +error[E0277]: `i32` is not an iterator + --> $DIR/issue-50480.rs:3:27 + | +LL | struct Foo(N, NotDefined, ::Item, Vec, String); + | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator + | + = help: the trait `Iterator` is not implemented for `i32` + = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` + +error[E0277]: `i32` is not an iterator + --> $DIR/issue-50480.rs:12:33 + | +LL | struct Bar(T, N, NotDefined, ::Item, Vec, String); + | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator + | + = help: the trait `Iterator` is not implemented for `i32` + = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` + +error: aborting due to 10 previous errors -Some errors have detailed explanations: E0204, E0412. +Some errors have detailed explanations: E0204, E0277, E0412. For more information about an error, try `rustc --explain E0204`. diff --git a/tests/ui/traits/issue-78372.rs b/tests/ui/traits/issue-78372.rs index 92f9f4b467a97..143325c097c13 100644 --- a/tests/ui/traits/issue-78372.rs +++ b/tests/ui/traits/issue-78372.rs @@ -6,8 +6,9 @@ impl DispatchFromDyn> for T {} //~ ERROR cannot find type `U` //~| ERROR the trait `DispatchFromDyn` may only be implemented for a coercion between structures trait Foo: X {} trait X { - fn foo(self: Smaht); + fn foo(self: Smaht); //~ ERROR: invalid `self` } trait Marker {} impl Marker for dyn Foo {} +//~^ ERROR cannot be made into an object fn main() {} diff --git a/tests/ui/traits/issue-78372.stderr b/tests/ui/traits/issue-78372.stderr index 44a62988daf37..edb07957c445c 100644 --- a/tests/ui/traits/issue-78372.stderr +++ b/tests/ui/traits/issue-78372.stderr @@ -61,7 +61,34 @@ error[E0378]: the trait `DispatchFromDyn` may only be implemented for a coercion LL | impl DispatchFromDyn> for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 6 previous errors +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/issue-78372.rs:12:17 + | +LL | fn foo(self: Smaht); + | -------------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` +... +LL | impl Marker for dyn Foo {} + | ^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/issue-78372.rs:9:18 + | +LL | trait Foo: X {} + | --- this trait cannot be made into an object... +LL | trait X { +LL | fn foo(self: Smaht); + | ^^^^^^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on -Some errors have detailed explanations: E0378, E0412, E0658. -For more information about an error, try `rustc --explain E0378`. +error[E0307]: invalid `self` parameter type: Smaht + --> $DIR/issue-78372.rs:9:18 + | +LL | fn foo(self: Smaht); + | ^^^^^^^^^^^^^^ + | + = note: type of `self` must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0038, E0307, E0378, E0412, E0658. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs index af471b5e19345..d7a2c8e7a928e 100644 --- a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs @@ -8,6 +8,7 @@ trait Overflow { } impl Overflow for T { type Assoc = ::Assoc; + //~^ ERROR: overflow } diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr index e3c0dabf549e8..583945723d5f0 100644 --- a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` for type `::Assoc` - --> $DIR/trait_ref_is_knowable-norm-overflow.rs:17:1 + --> $DIR/trait_ref_is_knowable-norm-overflow.rs:18:1 | LL | impl Trait for T {} | ------------------------- first implementation here @@ -7,6 +7,24 @@ LL | struct LocalTy; LL | impl Trait for ::Assoc {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `::Assoc` -error: aborting due to 1 previous error +error[E0275]: overflow evaluating the requirement `::Assoc: Sized` + --> $DIR/trait_ref_is_knowable-norm-overflow.rs:10:18 + | +LL | type Assoc = ::Assoc; + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`trait_ref_is_knowable_norm_overflow`) +note: required by a bound in `Overflow::Assoc` + --> $DIR/trait_ref_is_knowable-norm-overflow.rs:7:5 + | +LL | type Assoc; + | ^^^^^^^^^^^ required by this bound in `Overflow::Assoc` +help: consider relaxing the implicit `Sized` restriction + | +LL | type Assoc: ?Sized; + | ++++++++ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0119`. +Some errors have detailed explanations: E0119, E0275. +For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/next-solver/issue-118950-root-region.rs b/tests/ui/traits/next-solver/issue-118950-root-region.rs index 10fb7d525b7a1..c50276c78b4f8 100644 --- a/tests/ui/traits/next-solver/issue-118950-root-region.rs +++ b/tests/ui/traits/next-solver/issue-118950-root-region.rs @@ -12,6 +12,7 @@ trait ToUnit<'a> { trait Overlap {} type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit; +//~^ ERROR: not well-formed impl Overlap for T {} diff --git a/tests/ui/traits/next-solver/issue-118950-root-region.stderr b/tests/ui/traits/next-solver/issue-118950-root-region.stderr index c16a48d5f154c..f4638348358fc 100644 --- a/tests/ui/traits/next-solver/issue-118950-root-region.stderr +++ b/tests/ui/traits/next-solver/issue-118950-root-region.stderr @@ -1,5 +1,5 @@ error[E0412]: cannot find type `Missing` in this scope - --> $DIR/issue-118950-root-region.rs:18:55 + --> $DIR/issue-118950-root-region.rs:19:55 | LL | impl Overlap fn(Assoc<'a, T>)> for T where Missing: Overlap {} | ^^^^^^^ not found in this scope @@ -22,7 +22,7 @@ WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) }) WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [RePlaceholder(!1_BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) }) error[E0119]: conflicting implementations of trait `Overlap` for type `fn(_)` - --> $DIR/issue-118950-root-region.rs:18:1 + --> $DIR/issue-118950-root-region.rs:19:1 | LL | impl Overlap for T {} | ------------------------ first implementation here @@ -30,7 +30,13 @@ LL | LL | impl Overlap fn(Assoc<'a, T>)> for T where Missing: Overlap {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(_)` -error: aborting due to 2 previous errors; 1 warning emitted +error: the type `<*const T as ToUnit<'a>>::Unit` is not well-formed + --> $DIR/issue-118950-root-region.rs:14:21 + | +LL | type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors; 1 warning emitted Some errors have detailed explanations: E0119, E0412. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs index 4eba14f5a93fb..591a7278ddcf6 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -198,6 +198,7 @@ trait Qux { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types } impl Qux for Struct { + //~^ ERROR not all trait items implemented, missing: `F` type A = _; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types type B = _; diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index a4325b01f02c4..bfcc76c1dae7d 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -29,7 +29,7 @@ LL | struct BadStruct2<_, T>(_, T); | ^ expected identifier, found reserved identifier error: associated constant in `impl` without body - --> $DIR/typeck_type_placeholder_item.rs:205:5 + --> $DIR/typeck_type_placeholder_item.rs:206:5 | LL | const C: _; | ^^^^^^^^^^- @@ -411,7 +411,7 @@ LL | type Y = impl Trait<_>; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:216:31 + --> $DIR/typeck_type_placeholder_item.rs:217:31 | LL | fn value() -> Option<&'static _> { | ----------------^- @@ -420,7 +420,7 @@ LL | fn value() -> Option<&'static _> { | help: replace with the correct return type: `Option<&'static u8>` error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:221:10 + --> $DIR/typeck_type_placeholder_item.rs:222:10 | LL | const _: Option<_> = map(value); | ^^^^^^^^^ @@ -429,7 +429,7 @@ LL | const _: Option<_> = map(value); | help: replace with the correct type: `Option` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:224:31 + --> $DIR/typeck_type_placeholder_item.rs:225:31 | LL | fn evens_squared(n: usize) -> _ { | ^ @@ -438,13 +438,13 @@ LL | fn evens_squared(n: usize) -> _ { | help: replace with an appropriate return type: `impl Iterator` error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:229:10 + --> $DIR/typeck_type_placeholder_item.rs:230:10 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^ not allowed in type signatures | -note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:229:29}>, {closure@typeck_type_placeholder_item.rs:229:49}>` cannot be named - --> $DIR/typeck_type_placeholder_item.rs:229:14 +note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:230:29}>, {closure@typeck_type_placeholder_item.rs:230:49}>` cannot be named + --> $DIR/typeck_type_placeholder_item.rs:230:14 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -631,25 +631,25 @@ LL | fn clone_from(&mut self, other: &FnTest9) { *self = FnTest9; } | ~~~~~~~~ error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:201:14 + --> $DIR/typeck_type_placeholder_item.rs:202:14 | LL | type A = _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:203:14 + --> $DIR/typeck_type_placeholder_item.rs:204:14 | LL | type B = _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:205:14 + --> $DIR/typeck_type_placeholder_item.rs:206:14 | LL | const C: _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:208:14 + --> $DIR/typeck_type_placeholder_item.rs:209:14 | LL | const D: _ = 42; | ^ @@ -657,7 +657,16 @@ LL | const D: _ = 42; | not allowed in type signatures | help: replace with the correct type: `i32` -error: aborting due to 71 previous errors +error[E0046]: not all trait items implemented, missing: `F` + --> $DIR/typeck_type_placeholder_item.rs:200:1 + | +LL | type F: std::ops::Fn(_); + | ----------------------- `F` from trait +... +LL | impl Qux for Struct { + | ^^^^^^^^^^^^^^^^^^^ missing `F` in implementation + +error: aborting due to 72 previous errors -Some errors have detailed explanations: E0121, E0282, E0403. -For more information about an error, try `rustc --explain E0121`. +Some errors have detailed explanations: E0046, E0121, E0282, E0403. +For more information about an error, try `rustc --explain E0046`. From 32b44ecc6be6f1566e54ebc0c69fd3d3c022c333 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sun, 4 Feb 2024 13:07:16 +0000 Subject: [PATCH 3/3] Remove some invalid cfg(doc) code --- library/core/src/primitive_docs.rs | 36 ------------------------------ 1 file changed, 36 deletions(-) diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index bf47d767a9277..85595b059ad9a 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -448,22 +448,6 @@ mod prim_unit {} #[doc(hidden)] impl () {} -// Fake impl that's only really used for docs. -#[cfg(doc)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for () { - fn clone(&self) -> Self { - loop {} - } -} - -// Fake impl that's only really used for docs. -#[cfg(doc)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Copy for () { - // empty -} - #[rustc_doc_primitive = "pointer"] #[doc(alias = "ptr")] #[doc(alias = "*")] @@ -1690,23 +1674,3 @@ mod prim_fn {} // See src/librustdoc/passes/collect_trait_impls.rs:collect_trait_impls #[doc(hidden)] impl fn(T) -> Ret {} - -// Fake impl that's only really used for docs. -#[cfg(doc)] -#[stable(feature = "rust1", since = "1.0.0")] -#[doc(fake_variadic)] -/// This trait is implemented on function pointers with any number of arguments. -impl Clone for fn(T) -> Ret { - fn clone(&self) -> Self { - loop {} - } -} - -// Fake impl that's only really used for docs. -#[cfg(doc)] -#[stable(feature = "rust1", since = "1.0.0")] -#[doc(fake_variadic)] -/// This trait is implemented on function pointers with any number of arguments. -impl Copy for fn(T) -> Ret { - // empty -}