From d520b18316c71e1b61f2ed4df761f03149ff59e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 13 Dec 2024 22:59:26 +0000 Subject: [PATCH 1/8] Mention `#[default]` in E0655 code index --- .../rustc_error_codes/src/error_codes/E0665.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0665.md b/compiler/rustc_error_codes/src/error_codes/E0665.md index ae54d6d15798d..d5fd2130840de 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0665.md +++ b/compiler/rustc_error_codes/src/error_codes/E0665.md @@ -16,18 +16,30 @@ The `Default` cannot be derived on an enum for the simple reason that the compiler doesn't know which value to pick by default whereas it can for a struct as long as all its fields implement the `Default` trait as well. -If you still want to implement `Default` on your enum, you'll have to do it "by -hand": +For the case where the desired default variant has no data, you can annotate +it with `#[default]` to derive it: ``` +#[derive(Default)] enum Food { + #[default] Sweet, Salty, } +``` + +In the case where the default variant does have data, you will have to +implement `Default` on your enum "by hand": + +``` +enum Food { + Sweet(i32), + Salty, +} impl Default for Food { fn default() -> Food { - Food::Sweet + Food::Sweet(1) } } ``` From 7b500d852d449a4ef06680e89730a46159267d64 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Fri, 20 Dec 2024 17:18:33 -0800 Subject: [PATCH 2/8] Explain why a type is not eligible for `impl PointerLike`. The rules were baffling when I ran in to them trying to add some impls, so I made the compiler explain them to me. The logic of the successful cases is unchanged, but I did rearrange it to reverse the order of the primitive and `Adt` cases; this makes producing the errors easier. --- .../src/coherence/builtin.rs | 100 ++++++++++++------ tests/ui/dyn-star/pointer-like-impl-rules.rs | 82 ++++++++++++++ .../dyn-star/pointer-like-impl-rules.stderr | 85 +++++++++++++++ 3 files changed, 236 insertions(+), 31 deletions(-) create mode 100644 tests/ui/dyn-star/pointer-like-impl-rules.rs create mode 100644 tests/ui/dyn-star/pointer-like-impl-rules.stderr diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 2eea65125b038..3b98f358b1e95 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -673,37 +673,6 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err let impl_span = tcx.def_span(checker.impl_def_id); let self_ty = tcx.impl_trait_ref(checker.impl_def_id).unwrap().instantiate_identity().self_ty(); - // If an ADT is repr(transparent)... - if let ty::Adt(def, args) = *self_ty.kind() - && def.repr().transparent() - { - // FIXME(compiler-errors): This should and could be deduplicated into a query. - // Find the nontrivial field. - let adt_typing_env = ty::TypingEnv::non_body_analysis(tcx, def.did()); - let nontrivial_field = def.all_fields().find(|field_def| { - let field_ty = tcx.type_of(field_def.did).instantiate_identity(); - !tcx.layout_of(adt_typing_env.as_query_input(field_ty)) - .is_ok_and(|layout| layout.layout.is_1zst()) - }); - - if let Some(nontrivial_field) = nontrivial_field { - // Check that the nontrivial field implements `PointerLike`. - let nontrivial_field = nontrivial_field.ty(tcx, args); - let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); - let ocx = ObligationCtxt::new(&infcx); - ocx.register_bound( - ObligationCause::misc(impl_span, checker.impl_def_id), - param_env, - nontrivial_field, - tcx.lang_items().pointer_like().unwrap(), - ); - // FIXME(dyn-star): We should regionck this implementation. - if ocx.select_all_or_error().is_empty() { - return Ok(()); - } - } - } - let is_permitted_primitive = match *self_ty.kind() { ty::Adt(def, _) => def.is_box(), ty::Uint(..) | ty::Int(..) | ty::RawPtr(..) | ty::Ref(..) | ty::FnPtr(..) => true, @@ -717,6 +686,74 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err return Ok(()); } + let why_disqualified = match *self_ty.kind() { + // If an ADT is repr(transparent) + ty::Adt(self_ty_def, args) => { + if self_ty_def.repr().transparent() { + // FIXME(compiler-errors): This should and could be deduplicated into a query. + // Find the nontrivial field. + let adt_typing_env = ty::TypingEnv::non_body_analysis(tcx, self_ty_def.did()); + let nontrivial_field = self_ty_def.all_fields().find(|field_def| { + let field_ty = tcx.type_of(field_def.did).instantiate_identity(); + !tcx.layout_of(adt_typing_env.as_query_input(field_ty)) + .is_ok_and(|layout| layout.layout.is_1zst()) + }); + + if let Some(nontrivial_field) = nontrivial_field { + // Check that the nontrivial field implements `PointerLike`. + let nontrivial_field_ty = nontrivial_field.ty(tcx, args); + let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); + let ocx = ObligationCtxt::new(&infcx); + ocx.register_bound( + ObligationCause::misc(impl_span, checker.impl_def_id), + param_env, + nontrivial_field_ty, + tcx.lang_items().pointer_like().unwrap(), + ); + // FIXME(dyn-star): We should regionck this implementation. + if ocx.select_all_or_error().is_empty() { + return Ok(()); + } else { + format!( + "the field `{field_name}` of {descr} `{self_ty}` \ + does not implement `PointerLike`", + field_name = nontrivial_field.name, + descr = self_ty_def.descr() + ) + } + } else { + format!( + "the {descr} `{self_ty}` is `repr(transparent)`, \ + but does not have a non-trivial field (it is zero-sized)", + descr = self_ty_def.descr() + ) + } + } else if self_ty_def.is_box() { + // If we got here, then the `layout.is_pointer_like()` check failed + // and this box is not a thin pointer. + + String::from("boxes of dynamically-sized types are too large to be `PointerLike`") + } else { + format!( + "the {descr} `{self_ty}` is not `repr(transparent)`", + descr = self_ty_def.descr() + ) + } + } + ty::Ref(..) => { + // If we got here, then the `layout.is_pointer_like()` check failed + // and this reference is not a thin pointer. + String::from("references to dynamically-sized types are too large to be `PointerLike`") + } + ty::Dynamic(..) | ty::Foreign(..) => { + String::from("types of dynamic or unknown size may not implement `PointerLike`") + } + _ => { + // This is a white lie; it is true everywhere outside the standard library. + format!("only user-defined sized types are eligible for `impl PointerLike`") + } + }; + Err(tcx .dcx() .struct_span_err( @@ -724,5 +761,6 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err "implementation must be applied to type that has the same ABI as a pointer, \ or is `repr(transparent)` and whose field is `PointerLike`", ) + .with_note(why_disqualified) .emit()) } diff --git a/tests/ui/dyn-star/pointer-like-impl-rules.rs b/tests/ui/dyn-star/pointer-like-impl-rules.rs new file mode 100644 index 0000000000000..c234e86e09a84 --- /dev/null +++ b/tests/ui/dyn-star/pointer-like-impl-rules.rs @@ -0,0 +1,82 @@ +//@ check-fail + +#![feature(extern_types)] +#![feature(pointer_like_trait)] + +use std::marker::PointerLike; + +struct NotReprTransparent; +impl PointerLike for NotReprTransparent {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: the struct `NotReprTransparent` is not `repr(transparent)` + +#[repr(transparent)] +struct FieldIsPl(usize); +impl PointerLike for FieldIsPl {} + +#[repr(transparent)] +struct FieldIsPlAndHasOtherField(usize, ()); +impl PointerLike for FieldIsPlAndHasOtherField {} + +#[repr(transparent)] +struct FieldIsNotPl(u8); +impl PointerLike for FieldIsNotPl {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: the field `0` of struct `FieldIsNotPl` does not implement `PointerLike` + +#[repr(transparent)] +struct GenericFieldIsNotPl(T); +impl PointerLike for GenericFieldIsNotPl {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: the field `0` of struct `GenericFieldIsNotPl` does not implement `PointerLike` + +#[repr(transparent)] +struct GenericFieldIsPl(T); +impl PointerLike for GenericFieldIsPl {} + +#[repr(transparent)] +struct IsZeroSized(()); +impl PointerLike for IsZeroSized {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: the struct `IsZeroSized` is `repr(transparent)`, but does not have a non-trivial field + +trait SomeTrait {} +impl PointerLike for dyn SomeTrait {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: types of dynamic or unknown size + +extern "C" { + type ExternType; +} +impl PointerLike for ExternType {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: types of dynamic or unknown size + +struct LocalSizedType(&'static str); +struct LocalUnsizedType(str); + +// This is not a special error but a normal coherence error, +// which should still happen. +impl PointerLike for &LocalSizedType {} +//~^ ERROR: conflicting implementations of trait `PointerLike` +//~| NOTE: conflicting implementation in crate `core` + +impl PointerLike for &LocalUnsizedType {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: references to dynamically-sized types are too large to be `PointerLike` + +impl PointerLike for Box {} +//~^ ERROR: conflicting implementations of trait `PointerLike` +//~| NOTE: conflicting implementation in crate `alloc` + +impl PointerLike for Box {} +//~^ ERROR: implementation must be applied to type that +//~| NOTE: boxes of dynamically-sized types are too large to be `PointerLike` + +fn expects_pointer_like(x: impl PointerLike) {} + +fn main() { + expects_pointer_like(FieldIsPl(1usize)); + expects_pointer_like(FieldIsPlAndHasOtherField(1usize, ())); + expects_pointer_like(GenericFieldIsPl(1usize)); +} diff --git a/tests/ui/dyn-star/pointer-like-impl-rules.stderr b/tests/ui/dyn-star/pointer-like-impl-rules.stderr new file mode 100644 index 0000000000000..39f08f442c443 --- /dev/null +++ b/tests/ui/dyn-star/pointer-like-impl-rules.stderr @@ -0,0 +1,85 @@ +error[E0119]: conflicting implementations of trait `PointerLike` for type `&LocalSizedType` + --> $DIR/pointer-like-impl-rules.rs:60:1 + | +LL | impl PointerLike for &LocalSizedType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `core`: + - impl PointerLike for &T; + +error[E0119]: conflicting implementations of trait `PointerLike` for type `Box` + --> $DIR/pointer-like-impl-rules.rs:68:1 + | +LL | impl PointerLike for Box {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `alloc`: + - impl PointerLike for Box; + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:9:1 + | +LL | impl PointerLike for NotReprTransparent {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the struct `NotReprTransparent` is not `repr(transparent)` + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:23:1 + | +LL | impl PointerLike for FieldIsNotPl {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the field `0` of struct `FieldIsNotPl` does not implement `PointerLike` + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:29:1 + | +LL | impl PointerLike for GenericFieldIsNotPl {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the field `0` of struct `GenericFieldIsNotPl` does not implement `PointerLike` + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:39:1 + | +LL | impl PointerLike for IsZeroSized {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the struct `IsZeroSized` is `repr(transparent)`, but does not have a non-trivial field (it is zero-sized) + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:44:1 + | +LL | impl PointerLike for dyn SomeTrait {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: types of dynamic or unknown size may not implement `PointerLike` + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:51:1 + | +LL | impl PointerLike for ExternType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: types of dynamic or unknown size may not implement `PointerLike` + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:64:1 + | +LL | impl PointerLike for &LocalUnsizedType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: references to dynamically-sized types are too large to be `PointerLike` + +error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` + --> $DIR/pointer-like-impl-rules.rs:72:1 + | +LL | impl PointerLike for Box {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: boxes of dynamically-sized types are too large to be `PointerLike` + +error: aborting due to 10 previous errors + +For more information about this error, try `rustc --explain E0119`. From 1cc8289791570b6d06e5f12dea385d886378089a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 20 Dec 2024 20:33:59 -0800 Subject: [PATCH 3/8] Support pretty-printing dyn* trait objects --- compiler/rustc_ast_pretty/src/pprust/state.rs | 6 ++++-- compiler/rustc_hir_pretty/src/lib.rs | 6 ++++-- tests/ui-fulldeps/pprust-parenthesis-insertion.rs | 3 --- .../suggestions/wrap-dyn-in-suggestion-issue-120223.stderr | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 24c1c0f221ee3..172df10292920 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1204,8 +1204,10 @@ impl<'a> State<'a> { } ast::TyKind::Path(Some(qself), path) => self.print_qpath(path, qself, false), ast::TyKind::TraitObject(bounds, syntax) => { - if *syntax == ast::TraitObjectSyntax::Dyn { - self.word_nbsp("dyn"); + match syntax { + ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"), + ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"), + ast::TraitObjectSyntax::None => {} } self.print_type_bounds(bounds); } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index de2a7726e9b9e..5c1c58921907e 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -402,8 +402,10 @@ impl<'a> State<'a> { } hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false), hir::TyKind::TraitObject(bounds, lifetime, syntax) => { - if syntax == ast::TraitObjectSyntax::Dyn { - self.word_space("dyn"); + match syntax { + ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"), + ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"), + ast::TraitObjectSyntax::None => {} } let mut first = true; for bound in bounds { diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs index 184458bad5551..54a8fdf9cd5c8 100644 --- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs +++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs @@ -129,10 +129,7 @@ static EXPRS: &[&str] = &[ "(0.).to_string()", "0. .. 1.", */ - /* - // FIXME: pretty-printer loses the dyn*. `i as Trait` "i as dyn* Trait", - */ ]; // Flatten the content of parenthesis nodes into their parent node. For example diff --git a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr index f7fc17ea24f18..1fb3e7d211edb 100644 --- a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr +++ b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr @@ -58,14 +58,14 @@ help: consider adding an explicit lifetime bound LL | executor: impl FnOnce(T) -> (dyn Future) + 'static, | + +++++++++++ -error[E0310]: the parameter type `impl FnOnce(T) -> Future` may not live long enough +error[E0310]: the parameter type `impl FnOnce(T) -> dyn* Future` may not live long enough --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5 | LL | Box::new(executor) | ^^^^^^^^^^^^^^^^^^ | | - | the parameter type `impl FnOnce(T) -> Future` must be valid for the static lifetime... - | ...so that the type `impl FnOnce(T) -> Future` will meet its required lifetime bounds + | the parameter type `impl FnOnce(T) -> dyn* Future` must be valid for the static lifetime... + | ...so that the type `impl FnOnce(T) -> dyn* Future` will meet its required lifetime bounds | help: consider adding an explicit lifetime bound | From 23a250738b6dbba043a4722d18561c0629cfa453 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 20 Dec 2024 20:41:34 -0800 Subject: [PATCH 4/8] Relocate dyn* test out of parenthesis insertion test --- tests/ui-fulldeps/pprust-parenthesis-insertion.rs | 1 - tests/ui/unpretty/expanded-exhaustive.rs | 2 ++ tests/ui/unpretty/expanded-exhaustive.stdout | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs index 54a8fdf9cd5c8..60904c7afec14 100644 --- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs +++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs @@ -129,7 +129,6 @@ static EXPRS: &[&str] = &[ "(0.).to_string()", "0. .. 1.", */ - "i as dyn* Trait", ]; // Flatten the content of parenthesis nodes into their parent node. For example diff --git a/tests/ui/unpretty/expanded-exhaustive.rs b/tests/ui/unpretty/expanded-exhaustive.rs index 98fe05cf7c8b4..e052627e71cfe 100644 --- a/tests/ui/unpretty/expanded-exhaustive.rs +++ b/tests/ui/unpretty/expanded-exhaustive.rs @@ -9,6 +9,7 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deref_patterns)] +#![feature(dyn_star)] #![feature(explicit_tail_calls)] #![feature(gen_blocks)] #![feature(let_chains)] @@ -800,6 +801,7 @@ mod types { let _: dyn Send + 'static; let _: dyn 'static + Send; let _: dyn for<'a> Send; + let _: dyn* Send; } /// TyKind::ImplTrait diff --git a/tests/ui/unpretty/expanded-exhaustive.stdout b/tests/ui/unpretty/expanded-exhaustive.stdout index 452c06dd7e4e7..132d00cd8edd5 100644 --- a/tests/ui/unpretty/expanded-exhaustive.stdout +++ b/tests/ui/unpretty/expanded-exhaustive.stdout @@ -10,6 +10,7 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deref_patterns)] +#![feature(dyn_star)] #![feature(explicit_tail_calls)] #![feature(gen_blocks)] #![feature(let_chains)] @@ -647,6 +648,7 @@ mod types { let _: dyn Send + 'static; let _: dyn 'static + Send; let _: dyn for<'a> Send; + let _: dyn* Send; } /// TyKind::ImplTrait const fn ty_impl_trait() { From 8f9fede0b877966a702c1f1ac6e4ade7028aef8a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 21 Dec 2024 16:27:23 +0100 Subject: [PATCH 5/8] coroutine_clone: add comments --- compiler/rustc_middle/src/mir/syntax.rs | 5 +++++ tests/ui/coroutine/clone-impl-static.rs | 2 ++ tests/ui/coroutine/clone-impl-static.stderr | 16 ++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index b7ece5ffa62e0..0c17a2e0fe5a1 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -821,6 +821,11 @@ pub enum TerminatorKind<'tcx> { /// continues at the `resume` basic block, with the second argument written to the `resume_arg` /// place. If the coroutine is dropped before then, the `drop` basic block is invoked. /// + /// Note that coroutines can be (unstably) cloned under certain conditions, which means that + /// this terminator can **return multiple times**! MIR optimizations that reorder code into + /// different basic blocks needs to be aware of that. + /// See . + /// /// Not permitted in bodies that are not coroutine bodies, or after coroutine lowering. /// /// **Needs clarification**: What about the evaluation order of the `resume_arg` and `value`? diff --git a/tests/ui/coroutine/clone-impl-static.rs b/tests/ui/coroutine/clone-impl-static.rs index 62d4392e30cff..f6fadff7faf13 100644 --- a/tests/ui/coroutine/clone-impl-static.rs +++ b/tests/ui/coroutine/clone-impl-static.rs @@ -1,6 +1,8 @@ //@compile-flags: --diagnostic-width=300 // gate-test-coroutine_clone // Verifies that static coroutines cannot be cloned/copied. +// This is important: the cloned coroutine would reference state of the original +// coroutine, leading to semantic nonsense. #![feature(coroutines, coroutine_clone, stmt_expr_attributes)] diff --git a/tests/ui/coroutine/clone-impl-static.stderr b/tests/ui/coroutine/clone-impl-static.stderr index bf16b16696074..db1d2770346b6 100644 --- a/tests/ui/coroutine/clone-impl-static.stderr +++ b/tests/ui/coroutine/clone-impl-static.stderr @@ -1,27 +1,27 @@ -error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}: Copy` is not satisfied - --> $DIR/clone-impl-static.rs:12:16 +error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}: Copy` is not satisfied + --> $DIR/clone-impl-static.rs:14:16 | LL | check_copy(&gen); - | ---------- ^^^^ the trait `Copy` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}` + | ---------- ^^^^ the trait `Copy` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}` | | | required by a bound introduced by this call | note: required by a bound in `check_copy` - --> $DIR/clone-impl-static.rs:18:18 + --> $DIR/clone-impl-static.rs:20:18 | LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}: Clone` is not satisfied - --> $DIR/clone-impl-static.rs:14:17 +error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}: Clone` is not satisfied + --> $DIR/clone-impl-static.rs:16:17 | LL | check_clone(&gen); - | ----------- ^^^^ the trait `Clone` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}` + | ----------- ^^^^ the trait `Clone` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}` | | | required by a bound introduced by this call | note: required by a bound in `check_clone` - --> $DIR/clone-impl-static.rs:19:19 + --> $DIR/clone-impl-static.rs:21:19 | LL | fn check_clone(_x: &T) {} | ^^^^^ required by this bound in `check_clone` From 94812f1c8f455579a3a1c127c2bbac48fc7cecef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 21 Dec 2024 02:43:09 +0000 Subject: [PATCH 6/8] Use E0665 for missing `#[default]` error Use orphaned error code for the same error it belonged to before. ``` error[E0665]: `#[derive(Default)]` on enum with no `#[default]` --> $DIR/macros-nonfatal-errors.rs:42:10 | LL | #[derive(Default)] | ^^^^^^^ LL | / enum NoDeclaredDefault { LL | | Foo, LL | | Bar, LL | | } | |_- this enum needs a unit variant marked with `#[default]` | = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) help: make this unit variant default by placing `#[default]` on it | LL | #[default] Foo, | ~~~~~~~~~~~~~~ help: make this unit variant default by placing `#[default]` on it | LL | #[default] Bar, | ~~~~~~~~~~~~~~ ``` --- compiler/rustc_builtin_macros/messages.ftl | 6 +- .../src/deriving/default.rs | 13 ++- compiler/rustc_builtin_macros/src/errors.rs | 13 +-- .../src/error_codes/E0665.md | 15 ++-- tests/ui/macros/macros-nonfatal-errors.rs | 8 +- tests/ui/macros/macros-nonfatal-errors.stderr | 82 ++++++++++++------- 6 files changed, 84 insertions(+), 53 deletions(-) diff --git a/compiler/rustc_builtin_macros/messages.ftl b/compiler/rustc_builtin_macros/messages.ftl index 87d3d288013a3..7a31d2a223917 100644 --- a/compiler/rustc_builtin_macros/messages.ftl +++ b/compiler/rustc_builtin_macros/messages.ftl @@ -249,9 +249,9 @@ builtin_macros_naked_functions_testing_attribute = .label = function marked with testing attribute here .naked_attribute = `#[naked]` is incompatible with testing attributes -builtin_macros_no_default_variant = no default declared - .help = make a unit variant default by placing `#[default]` above it - .suggestion = make `{$ident}` default +builtin_macros_no_default_variant = `#[derive(Default)]` on enum with no `#[default]` + .label = this enum needs a unit variant marked with `#[default]` + .suggestion = make this unit variant default by placing `#[default]` on it builtin_macros_non_abi = at least one abi must be provided as an argument to `clobber_abi` diff --git a/compiler/rustc_builtin_macros/src/deriving/default.rs b/compiler/rustc_builtin_macros/src/deriving/default.rs index a7d9f608cbdd0..3c7bebd0f192e 100644 --- a/compiler/rustc_builtin_macros/src/deriving/default.rs +++ b/compiler/rustc_builtin_macros/src/deriving/default.rs @@ -42,7 +42,9 @@ pub(crate) fn expand_deriving_default( StaticStruct(_, fields) => { default_struct_substructure(cx, trait_span, substr, fields) } - StaticEnum(enum_def, _) => default_enum_substructure(cx, trait_span, enum_def), + StaticEnum(enum_def, _) => { + default_enum_substructure(cx, trait_span, enum_def, item.span()) + } _ => cx.dcx().span_bug(trait_span, "method in `derive(Default)`"), } })), @@ -96,9 +98,10 @@ fn default_enum_substructure( cx: &ExtCtxt<'_>, trait_span: Span, enum_def: &EnumDef, + item_span: Span, ) -> BlockOrExpr { let expr = match try { - let default_variant = extract_default_variant(cx, enum_def, trait_span)?; + let default_variant = extract_default_variant(cx, enum_def, trait_span, item_span)?; validate_default_attribute(cx, default_variant)?; default_variant } { @@ -146,6 +149,7 @@ fn extract_default_variant<'a>( cx: &ExtCtxt<'_>, enum_def: &'a EnumDef, trait_span: Span, + item_span: Span, ) -> Result<&'a rustc_ast::Variant, ErrorGuaranteed> { let default_variants: SmallVec<[_; 1]> = enum_def .variants @@ -163,9 +167,10 @@ fn extract_default_variant<'a>( .filter(|variant| !attr::contains_name(&variant.attrs, sym::non_exhaustive)); let suggs = possible_defaults - .map(|v| errors::NoDefaultVariantSugg { span: v.span, ident: v.ident }) + .map(|v| errors::NoDefaultVariantSugg { span: v.span.shrink_to_lo() }) .collect(); - let guar = cx.dcx().emit_err(errors::NoDefaultVariant { span: trait_span, suggs }); + let guar = + cx.dcx().emit_err(errors::NoDefaultVariant { span: trait_span, item_span, suggs }); return Err(guar); } diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index b3198e7743d8b..1abdfdb9c65c9 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -369,26 +369,21 @@ pub(crate) struct DerivePathArgsValue { } #[derive(Diagnostic)] -#[diag(builtin_macros_no_default_variant)] -#[help] +#[diag(builtin_macros_no_default_variant, code = E0665)] pub(crate) struct NoDefaultVariant { #[primary_span] pub(crate) span: Span, + #[label] + pub(crate) item_span: Span, #[subdiagnostic] pub(crate) suggs: Vec, } #[derive(Subdiagnostic)] -#[suggestion( - builtin_macros_suggestion, - code = "#[default] {ident}", - applicability = "maybe-incorrect", - style = "tool-only" -)] +#[suggestion(builtin_macros_suggestion, code = "#[default] ", applicability = "maybe-incorrect")] pub(crate) struct NoDefaultVariantSugg { #[primary_span] pub(crate) span: Span, - pub(crate) ident: Ident, } #[derive(Diagnostic)] diff --git a/compiler/rustc_error_codes/src/error_codes/E0665.md b/compiler/rustc_error_codes/src/error_codes/E0665.md index d5fd2130840de..caa944233778b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0665.md +++ b/compiler/rustc_error_codes/src/error_codes/E0665.md @@ -1,10 +1,9 @@ -#### Note: this error code is no longer emitted by the compiler. - -The `Default` trait was derived on an enum. +The `Default` trait was derived on an enum without specifying the default +variant. Erroneous code example: -```compile_fail +```compile_fail,E0665 #[derive(Default)] enum Food { Sweet, @@ -16,8 +15,8 @@ The `Default` cannot be derived on an enum for the simple reason that the compiler doesn't know which value to pick by default whereas it can for a struct as long as all its fields implement the `Default` trait as well. -For the case where the desired default variant has no data, you can annotate -it with `#[default]` to derive it: +For the case where the desired default variant has no payload, you can +annotate it with `#[default]` to derive it: ``` #[derive(Default)] @@ -28,8 +27,8 @@ enum Food { } ``` -In the case where the default variant does have data, you will have to -implement `Default` on your enum "by hand": +In the case where the default variant does have a payload, you will have to +implement `Default` on your enum manually: ``` enum Food { diff --git a/tests/ui/macros/macros-nonfatal-errors.rs b/tests/ui/macros/macros-nonfatal-errors.rs index 46e865031ecd5..658455b1b5b8b 100644 --- a/tests/ui/macros/macros-nonfatal-errors.rs +++ b/tests/ui/macros/macros-nonfatal-errors.rs @@ -39,12 +39,18 @@ enum AttrOnInnerExpression { Baz, } -#[derive(Default)] //~ ERROR no default declared +#[derive(Default)] //~ ERROR `#[derive(Default)]` on enum with no `#[default]` enum NoDeclaredDefault { Foo, Bar, } +#[derive(Default)] //~ ERROR `#[derive(Default)]` on enum with no `#[default]` +enum NoDeclaredDefaultWithoutUnitVariant { + Foo(i32), + Bar(i32), +} + #[derive(Default)] //~ ERROR multiple declared defaults enum MultipleDefaults { #[default] diff --git a/tests/ui/macros/macros-nonfatal-errors.stderr b/tests/ui/macros/macros-nonfatal-errors.stderr index abf43e2a009d7..fd5e41986a836 100644 --- a/tests/ui/macros/macros-nonfatal-errors.stderr +++ b/tests/ui/macros/macros-nonfatal-errors.stderr @@ -46,18 +46,43 @@ LL | Bar([u8; #[default] 1]), | = help: consider a manual implementation of `Default` -error: no default declared +error[E0665]: `#[derive(Default)]` on enum with no `#[default]` --> $DIR/macros-nonfatal-errors.rs:42:10 | -LL | #[derive(Default)] - | ^^^^^^^ +LL | #[derive(Default)] + | ^^^^^^^ +LL | / enum NoDeclaredDefault { +LL | | Foo, +LL | | Bar, +LL | | } + | |_- this enum needs a unit variant marked with `#[default]` | - = help: make a unit variant default by placing `#[default]` above it = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) +help: make this unit variant default by placing `#[default]` on it + | +LL | #[default] Foo, + | ++++++++++ +help: make this unit variant default by placing `#[default]` on it + | +LL | #[default] Bar, + | ++++++++++ -error: multiple declared defaults +error[E0665]: `#[derive(Default)]` on enum with no `#[default]` --> $DIR/macros-nonfatal-errors.rs:48:10 | +LL | #[derive(Default)] + | ^^^^^^^ +LL | / enum NoDeclaredDefaultWithoutUnitVariant { +LL | | Foo(i32), +LL | | Bar(i32), +LL | | } + | |_- this enum needs a unit variant marked with `#[default]` + | + = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: multiple declared defaults + --> $DIR/macros-nonfatal-errors.rs:54:10 + | LL | #[derive(Default)] | ^^^^^^^ ... @@ -74,7 +99,7 @@ LL | Baz, = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) error: `#[default]` attribute does not accept a value - --> $DIR/macros-nonfatal-errors.rs:60:5 + --> $DIR/macros-nonfatal-errors.rs:66:5 | LL | #[default = 1] | ^^^^^^^^^^^^^^ @@ -82,7 +107,7 @@ LL | #[default = 1] = help: try using `#[default]` error: multiple `#[default]` attributes - --> $DIR/macros-nonfatal-errors.rs:68:5 + --> $DIR/macros-nonfatal-errors.rs:74:5 | LL | #[default] | ---------- `#[default]` used here @@ -93,13 +118,13 @@ LL | Foo, | = note: only one `#[default]` attribute is needed help: try removing this - --> $DIR/macros-nonfatal-errors.rs:67:5 + --> $DIR/macros-nonfatal-errors.rs:73:5 | LL | #[default] | ^^^^^^^^^^ error: multiple `#[default]` attributes - --> $DIR/macros-nonfatal-errors.rs:78:5 + --> $DIR/macros-nonfatal-errors.rs:84:5 | LL | #[default] | ---------- `#[default]` used here @@ -111,7 +136,7 @@ LL | Foo, | = note: only one `#[default]` attribute is needed help: try removing these - --> $DIR/macros-nonfatal-errors.rs:75:5 + --> $DIR/macros-nonfatal-errors.rs:81:5 | LL | #[default] | ^^^^^^^^^^ @@ -121,7 +146,7 @@ LL | #[default] | ^^^^^^^^^^ error: the `#[default]` attribute may only be used on unit enum variants - --> $DIR/macros-nonfatal-errors.rs:85:5 + --> $DIR/macros-nonfatal-errors.rs:91:5 | LL | Foo {}, | ^^^ @@ -129,7 +154,7 @@ LL | Foo {}, = help: consider a manual implementation of `Default` error: default variant must be exhaustive - --> $DIR/macros-nonfatal-errors.rs:93:5 + --> $DIR/macros-nonfatal-errors.rs:99:5 | LL | #[non_exhaustive] | ----------------- declared `#[non_exhaustive]` here @@ -139,37 +164,37 @@ LL | Foo, = help: consider a manual implementation of `Default` error: asm template must be a string literal - --> $DIR/macros-nonfatal-errors.rs:98:10 + --> $DIR/macros-nonfatal-errors.rs:104:10 | LL | asm!(invalid); | ^^^^^^^ error: `concat_idents!()` requires ident args - --> $DIR/macros-nonfatal-errors.rs:101:5 + --> $DIR/macros-nonfatal-errors.rs:107:5 | LL | concat_idents!("not", "idents"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: argument must be a string literal - --> $DIR/macros-nonfatal-errors.rs:103:17 + --> $DIR/macros-nonfatal-errors.rs:109:17 | LL | option_env!(invalid); | ^^^^^^^ error: expected string literal - --> $DIR/macros-nonfatal-errors.rs:104:10 + --> $DIR/macros-nonfatal-errors.rs:110:10 | LL | env!(invalid); | ^^^^^^^ error: `env!()` takes 1 or 2 arguments - --> $DIR/macros-nonfatal-errors.rs:105:5 + --> $DIR/macros-nonfatal-errors.rs:111:5 | LL | env!(foo, abr, baz); | ^^^^^^^^^^^^^^^^^^^ error: environment variable `RUST_HOPEFULLY_THIS_DOESNT_EXIST` not defined at compile time - --> $DIR/macros-nonfatal-errors.rs:106:5 + --> $DIR/macros-nonfatal-errors.rs:112:5 | LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +203,7 @@ LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST"); = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) error: format argument must be a string literal - --> $DIR/macros-nonfatal-errors.rs:108:13 + --> $DIR/macros-nonfatal-errors.rs:114:13 | LL | format!(invalid); | ^^^^^^^ @@ -189,19 +214,19 @@ LL | format!("{}", invalid); | +++++ error: argument must be a string literal - --> $DIR/macros-nonfatal-errors.rs:110:14 + --> $DIR/macros-nonfatal-errors.rs:116:14 | LL | include!(invalid); | ^^^^^^^ error: argument must be a string literal - --> $DIR/macros-nonfatal-errors.rs:112:18 + --> $DIR/macros-nonfatal-errors.rs:118:18 | LL | include_str!(invalid); | ^^^^^^^ error: couldn't read `$DIR/i'd be quite surprised if a file with this name existed`: $FILE_NOT_FOUND_MSG - --> $DIR/macros-nonfatal-errors.rs:113:5 + --> $DIR/macros-nonfatal-errors.rs:119:5 | LL | include_str!("i'd be quite surprised if a file with this name existed"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,13 +234,13 @@ LL | include_str!("i'd be quite surprised if a file with this name existed") = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) error: argument must be a string literal - --> $DIR/macros-nonfatal-errors.rs:114:20 + --> $DIR/macros-nonfatal-errors.rs:120:20 | LL | include_bytes!(invalid); | ^^^^^^^ error: couldn't read `$DIR/i'd be quite surprised if a file with this name existed`: $FILE_NOT_FOUND_MSG - --> $DIR/macros-nonfatal-errors.rs:115:5 + --> $DIR/macros-nonfatal-errors.rs:121:5 | LL | include_bytes!("i'd be quite surprised if a file with this name existed"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -223,13 +248,13 @@ LL | include_bytes!("i'd be quite surprised if a file with this name existed = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: trace_macros! accepts only `true` or `false` - --> $DIR/macros-nonfatal-errors.rs:117:5 + --> $DIR/macros-nonfatal-errors.rs:123:5 | LL | trace_macros!(invalid); | ^^^^^^^^^^^^^^^^^^^^^^ error: default variant must be exhaustive - --> $DIR/macros-nonfatal-errors.rs:127:9 + --> $DIR/macros-nonfatal-errors.rs:133:9 | LL | #[non_exhaustive] | ----------------- declared `#[non_exhaustive]` here @@ -239,10 +264,11 @@ LL | Foo, = help: consider a manual implementation of `Default` error: cannot find macro `llvm_asm` in this scope - --> $DIR/macros-nonfatal-errors.rs:99:5 + --> $DIR/macros-nonfatal-errors.rs:105:5 | LL | llvm_asm!(invalid); | ^^^^^^^^ -error: aborting due to 28 previous errors +error: aborting due to 29 previous errors +For more information about this error, try `rustc --explain E0665`. From 466335205f702edc38fc06dcb45a3b1e424ccecb Mon Sep 17 00:00:00 2001 From: Yusuf Bham Date: Sat, 21 Dec 2024 15:35:33 -0500 Subject: [PATCH 7/8] Use `&raw` for `ptr` primitive docs --- library/core/src/primitive_docs.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index e105ceadff757..c5f029363e589 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -563,11 +563,11 @@ impl () {} /// Note that here the call to [`drop`] is for clarity - it indicates /// that we are done with the given value and it should be destroyed. /// -/// ## 3. Create it using `ptr::addr_of!` +/// ## 3. Create it using `&raw` /// -/// Instead of coercing a reference to a raw pointer, you can use the macros -/// [`ptr::addr_of!`] (for `*const T`) and [`ptr::addr_of_mut!`] (for `*mut T`). -/// These macros allow you to create raw pointers to fields to which you cannot +/// Instead of coercing a reference to a raw pointer, you can use the raw borrow +/// operators `&raw const` (for `*const T`) and `&raw mut` (for `*mut T`). +/// These operators allow you to create raw pointers to fields to which you cannot /// create a reference (without causing undefined behavior), such as an /// unaligned field. This might be necessary if packed structs or uninitialized /// memory is involved. @@ -580,7 +580,7 @@ impl () {} /// unaligned: u32, /// } /// let s = S::default(); -/// let p = std::ptr::addr_of!(s.unaligned); // not allowed with coercion +/// let p = &raw const s.unaligned; // not allowed with coercion /// ``` /// /// ## 4. Get it from C. From 582167a2fc4298337b8aa840a519998bf2296fde Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 22 Dec 2024 01:02:35 +0000 Subject: [PATCH 8/8] Flatten effects directory now that it doesn't really test anything specific --- .../{effects => }/auxiliary/minicore.rs | 0 ...nst_closure-const_trait_impl-ice-113381.rs | 0 ...closure-const_trait_impl-ice-113381.stderr | 0 ...dont-prefer-param-env-for-infer-self-ty.rs | 0 .../{effects => }/effect-param-infer.rs | 0 .../effects/auxiliary/cross-crate.rs | 13 ---- .../no-explicit-const-params-cross-crate.rs | 18 ------ ...o-explicit-const-params-cross-crate.stderr | 59 ------------------- .../const-traits/{effects => }/fallback.rs | 0 .../{effects => }/group-traits.rs | 0 .../ice-112822-expected-type-for-param.rs | 0 .../ice-112822-expected-type-for-param.stderr | 0 ...ice-113375-index-out-of-bounds-generics.rs | 0 .../{effects => }/infer-fallback.rs | 0 .../minicore-const-fn-early-bound.rs | 0 .../{effects => }/minicore-deref-fail.rs | 0 .../{effects => }/minicore-deref-fail.stderr | 0 .../{effects => }/minicore-drop-fail.rs | 0 .../{effects => }/minicore-drop-fail.stderr | 0 ...nicore-drop-without-feature-gate.no.stderr | 0 .../minicore-drop-without-feature-gate.rs | 0 .../{effects => }/minicore-fn-fail.rs | 0 .../{effects => }/minicore-fn-fail.stderr | 0 .../{effects => }/minicore-works.rs | 0 .../{effects => }/mismatched_generic_args.rs | 0 .../mismatched_generic_args.stderr | 0 .../{effects => }/no-explicit-const-params.rs | 0 .../no-explicit-const-params.stderr | 0 .../const-traits/{effects => }/project.rs | 0 .../{effects => }/span-bug-issue-121418.rs | 0 .../span-bug-issue-121418.stderr | 0 .../{effects => }/spec-effectvar-ice.rs | 0 .../{effects => }/spec-effectvar-ice.stderr | 0 .../{effects => }/trait-fn-const.rs | 0 .../{effects => }/trait-fn-const.stderr | 0 35 files changed, 90 deletions(-) rename tests/ui/traits/const-traits/{effects => }/auxiliary/minicore.rs (100%) rename tests/ui/traits/const-traits/{effects => }/const_closure-const_trait_impl-ice-113381.rs (100%) rename tests/ui/traits/const-traits/{effects => }/const_closure-const_trait_impl-ice-113381.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/dont-prefer-param-env-for-infer-self-ty.rs (100%) rename tests/ui/traits/const-traits/{effects => }/effect-param-infer.rs (100%) delete mode 100644 tests/ui/traits/const-traits/effects/auxiliary/cross-crate.rs delete mode 100644 tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.rs delete mode 100644 tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.stderr rename tests/ui/traits/const-traits/{effects => }/fallback.rs (100%) rename tests/ui/traits/const-traits/{effects => }/group-traits.rs (100%) rename tests/ui/traits/const-traits/{effects => }/ice-112822-expected-type-for-param.rs (100%) rename tests/ui/traits/const-traits/{effects => }/ice-112822-expected-type-for-param.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/ice-113375-index-out-of-bounds-generics.rs (100%) rename tests/ui/traits/const-traits/{effects => }/infer-fallback.rs (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-const-fn-early-bound.rs (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-deref-fail.rs (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-deref-fail.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-drop-fail.rs (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-drop-fail.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-drop-without-feature-gate.no.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-drop-without-feature-gate.rs (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-fn-fail.rs (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-fn-fail.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/minicore-works.rs (100%) rename tests/ui/traits/const-traits/{effects => }/mismatched_generic_args.rs (100%) rename tests/ui/traits/const-traits/{effects => }/mismatched_generic_args.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/no-explicit-const-params.rs (100%) rename tests/ui/traits/const-traits/{effects => }/no-explicit-const-params.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/project.rs (100%) rename tests/ui/traits/const-traits/{effects => }/span-bug-issue-121418.rs (100%) rename tests/ui/traits/const-traits/{effects => }/span-bug-issue-121418.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/spec-effectvar-ice.rs (100%) rename tests/ui/traits/const-traits/{effects => }/spec-effectvar-ice.stderr (100%) rename tests/ui/traits/const-traits/{effects => }/trait-fn-const.rs (100%) rename tests/ui/traits/const-traits/{effects => }/trait-fn-const.stderr (100%) diff --git a/tests/ui/traits/const-traits/effects/auxiliary/minicore.rs b/tests/ui/traits/const-traits/auxiliary/minicore.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/auxiliary/minicore.rs rename to tests/ui/traits/const-traits/auxiliary/minicore.rs diff --git a/tests/ui/traits/const-traits/effects/const_closure-const_trait_impl-ice-113381.rs b/tests/ui/traits/const-traits/const_closure-const_trait_impl-ice-113381.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/const_closure-const_trait_impl-ice-113381.rs rename to tests/ui/traits/const-traits/const_closure-const_trait_impl-ice-113381.rs diff --git a/tests/ui/traits/const-traits/effects/const_closure-const_trait_impl-ice-113381.stderr b/tests/ui/traits/const-traits/const_closure-const_trait_impl-ice-113381.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/const_closure-const_trait_impl-ice-113381.stderr rename to tests/ui/traits/const-traits/const_closure-const_trait_impl-ice-113381.stderr diff --git a/tests/ui/traits/const-traits/effects/dont-prefer-param-env-for-infer-self-ty.rs b/tests/ui/traits/const-traits/dont-prefer-param-env-for-infer-self-ty.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/dont-prefer-param-env-for-infer-self-ty.rs rename to tests/ui/traits/const-traits/dont-prefer-param-env-for-infer-self-ty.rs diff --git a/tests/ui/traits/const-traits/effects/effect-param-infer.rs b/tests/ui/traits/const-traits/effect-param-infer.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/effect-param-infer.rs rename to tests/ui/traits/const-traits/effect-param-infer.rs diff --git a/tests/ui/traits/const-traits/effects/auxiliary/cross-crate.rs b/tests/ui/traits/const-traits/effects/auxiliary/cross-crate.rs deleted file mode 100644 index e02bf6a4d2c43..0000000000000 --- a/tests/ui/traits/const-traits/effects/auxiliary/cross-crate.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ compile-flags: -Znext-solver -#![feature(const_trait_impl)] - -pub const fn foo() {} - -#[const_trait] -pub trait Bar { - fn bar(); -} - -impl Bar for () { - fn bar() {} -} diff --git a/tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.rs b/tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.rs deleted file mode 100644 index 97052a1d09a48..0000000000000 --- a/tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ aux-build: cross-crate.rs -extern crate cross_crate; - -use cross_crate::{Bar, foo}; - -fn main() { - foo::(); - //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied - <() as Bar>::bar(); - //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied -} - -const FOO: () = { - foo::(); - //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied - <() as Bar>::bar(); - //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied -}; diff --git a/tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.stderr b/tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.stderr deleted file mode 100644 index d1180dbd80e68..0000000000000 --- a/tests/ui/traits/const-traits/effects/no-explicit-const-params-cross-crate.stderr +++ /dev/null @@ -1,59 +0,0 @@ -error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params-cross-crate.rs:14:5 - | -LL | foo::(); - | ^^^--------- help: remove the unnecessary generics - | | - | expected 0 generic arguments - | -note: function defined here, with 0 generic parameters - --> $DIR/auxiliary/cross-crate.rs:4:14 - | -LL | pub const fn foo() {} - | ^^^ - -error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params-cross-crate.rs:16:12 - | -LL | <() as Bar>::bar(); - | ^^^------- help: remove the unnecessary generics - | | - | expected 0 generic arguments - | -note: trait defined here, with 0 generic parameters - --> $DIR/auxiliary/cross-crate.rs:7:11 - | -LL | pub trait Bar { - | ^^^ - -error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params-cross-crate.rs:7:5 - | -LL | foo::(); - | ^^^-------- help: remove the unnecessary generics - | | - | expected 0 generic arguments - | -note: function defined here, with 0 generic parameters - --> $DIR/auxiliary/cross-crate.rs:4:14 - | -LL | pub const fn foo() {} - | ^^^ - -error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params-cross-crate.rs:9:12 - | -LL | <() as Bar>::bar(); - | ^^^------ help: remove the unnecessary generics - | | - | expected 0 generic arguments - | -note: trait defined here, with 0 generic parameters - --> $DIR/auxiliary/cross-crate.rs:7:11 - | -LL | pub trait Bar { - | ^^^ - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/traits/const-traits/effects/fallback.rs b/tests/ui/traits/const-traits/fallback.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/fallback.rs rename to tests/ui/traits/const-traits/fallback.rs diff --git a/tests/ui/traits/const-traits/effects/group-traits.rs b/tests/ui/traits/const-traits/group-traits.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/group-traits.rs rename to tests/ui/traits/const-traits/group-traits.rs diff --git a/tests/ui/traits/const-traits/effects/ice-112822-expected-type-for-param.rs b/tests/ui/traits/const-traits/ice-112822-expected-type-for-param.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/ice-112822-expected-type-for-param.rs rename to tests/ui/traits/const-traits/ice-112822-expected-type-for-param.rs diff --git a/tests/ui/traits/const-traits/effects/ice-112822-expected-type-for-param.stderr b/tests/ui/traits/const-traits/ice-112822-expected-type-for-param.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/ice-112822-expected-type-for-param.stderr rename to tests/ui/traits/const-traits/ice-112822-expected-type-for-param.stderr diff --git a/tests/ui/traits/const-traits/effects/ice-113375-index-out-of-bounds-generics.rs b/tests/ui/traits/const-traits/ice-113375-index-out-of-bounds-generics.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/ice-113375-index-out-of-bounds-generics.rs rename to tests/ui/traits/const-traits/ice-113375-index-out-of-bounds-generics.rs diff --git a/tests/ui/traits/const-traits/effects/infer-fallback.rs b/tests/ui/traits/const-traits/infer-fallback.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/infer-fallback.rs rename to tests/ui/traits/const-traits/infer-fallback.rs diff --git a/tests/ui/traits/const-traits/effects/minicore-const-fn-early-bound.rs b/tests/ui/traits/const-traits/minicore-const-fn-early-bound.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-const-fn-early-bound.rs rename to tests/ui/traits/const-traits/minicore-const-fn-early-bound.rs diff --git a/tests/ui/traits/const-traits/effects/minicore-deref-fail.rs b/tests/ui/traits/const-traits/minicore-deref-fail.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-deref-fail.rs rename to tests/ui/traits/const-traits/minicore-deref-fail.rs diff --git a/tests/ui/traits/const-traits/effects/minicore-deref-fail.stderr b/tests/ui/traits/const-traits/minicore-deref-fail.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-deref-fail.stderr rename to tests/ui/traits/const-traits/minicore-deref-fail.stderr diff --git a/tests/ui/traits/const-traits/effects/minicore-drop-fail.rs b/tests/ui/traits/const-traits/minicore-drop-fail.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-drop-fail.rs rename to tests/ui/traits/const-traits/minicore-drop-fail.rs diff --git a/tests/ui/traits/const-traits/effects/minicore-drop-fail.stderr b/tests/ui/traits/const-traits/minicore-drop-fail.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-drop-fail.stderr rename to tests/ui/traits/const-traits/minicore-drop-fail.stderr diff --git a/tests/ui/traits/const-traits/effects/minicore-drop-without-feature-gate.no.stderr b/tests/ui/traits/const-traits/minicore-drop-without-feature-gate.no.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-drop-without-feature-gate.no.stderr rename to tests/ui/traits/const-traits/minicore-drop-without-feature-gate.no.stderr diff --git a/tests/ui/traits/const-traits/effects/minicore-drop-without-feature-gate.rs b/tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-drop-without-feature-gate.rs rename to tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs diff --git a/tests/ui/traits/const-traits/effects/minicore-fn-fail.rs b/tests/ui/traits/const-traits/minicore-fn-fail.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-fn-fail.rs rename to tests/ui/traits/const-traits/minicore-fn-fail.rs diff --git a/tests/ui/traits/const-traits/effects/minicore-fn-fail.stderr b/tests/ui/traits/const-traits/minicore-fn-fail.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-fn-fail.stderr rename to tests/ui/traits/const-traits/minicore-fn-fail.stderr diff --git a/tests/ui/traits/const-traits/effects/minicore-works.rs b/tests/ui/traits/const-traits/minicore-works.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/minicore-works.rs rename to tests/ui/traits/const-traits/minicore-works.rs diff --git a/tests/ui/traits/const-traits/effects/mismatched_generic_args.rs b/tests/ui/traits/const-traits/mismatched_generic_args.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/mismatched_generic_args.rs rename to tests/ui/traits/const-traits/mismatched_generic_args.rs diff --git a/tests/ui/traits/const-traits/effects/mismatched_generic_args.stderr b/tests/ui/traits/const-traits/mismatched_generic_args.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/mismatched_generic_args.stderr rename to tests/ui/traits/const-traits/mismatched_generic_args.stderr diff --git a/tests/ui/traits/const-traits/effects/no-explicit-const-params.rs b/tests/ui/traits/const-traits/no-explicit-const-params.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/no-explicit-const-params.rs rename to tests/ui/traits/const-traits/no-explicit-const-params.rs diff --git a/tests/ui/traits/const-traits/effects/no-explicit-const-params.stderr b/tests/ui/traits/const-traits/no-explicit-const-params.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/no-explicit-const-params.stderr rename to tests/ui/traits/const-traits/no-explicit-const-params.stderr diff --git a/tests/ui/traits/const-traits/effects/project.rs b/tests/ui/traits/const-traits/project.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/project.rs rename to tests/ui/traits/const-traits/project.rs diff --git a/tests/ui/traits/const-traits/effects/span-bug-issue-121418.rs b/tests/ui/traits/const-traits/span-bug-issue-121418.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/span-bug-issue-121418.rs rename to tests/ui/traits/const-traits/span-bug-issue-121418.rs diff --git a/tests/ui/traits/const-traits/effects/span-bug-issue-121418.stderr b/tests/ui/traits/const-traits/span-bug-issue-121418.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/span-bug-issue-121418.stderr rename to tests/ui/traits/const-traits/span-bug-issue-121418.stderr diff --git a/tests/ui/traits/const-traits/effects/spec-effectvar-ice.rs b/tests/ui/traits/const-traits/spec-effectvar-ice.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/spec-effectvar-ice.rs rename to tests/ui/traits/const-traits/spec-effectvar-ice.rs diff --git a/tests/ui/traits/const-traits/effects/spec-effectvar-ice.stderr b/tests/ui/traits/const-traits/spec-effectvar-ice.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/spec-effectvar-ice.stderr rename to tests/ui/traits/const-traits/spec-effectvar-ice.stderr diff --git a/tests/ui/traits/const-traits/effects/trait-fn-const.rs b/tests/ui/traits/const-traits/trait-fn-const.rs similarity index 100% rename from tests/ui/traits/const-traits/effects/trait-fn-const.rs rename to tests/ui/traits/const-traits/trait-fn-const.rs diff --git a/tests/ui/traits/const-traits/effects/trait-fn-const.stderr b/tests/ui/traits/const-traits/trait-fn-const.stderr similarity index 100% rename from tests/ui/traits/const-traits/effects/trait-fn-const.stderr rename to tests/ui/traits/const-traits/trait-fn-const.stderr