diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 258655de486f9..6a0f03c8b3196 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -34,7 +34,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { modifiers: Option, ) -> hir::QPath<'hir> { let qself_position = qself.as_ref().map(|q| q.position); - let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx)); + let qself = qself + .as_ref() + // Reject cases like `::Assoc` and `::Assoc`. + .map(|q| self.lower_ty(&q.ty, ImplTraitContext::Disallowed(ImplTraitPosition::Path))); let partial_res = self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err)); @@ -75,6 +78,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { None }; + // Only permit `impl Trait` in the final segment. E.g., we permit `Option`, + // `option::Option::Xyz` and reject `option::Option::Xyz`. + let itctx = |i| { + if i + 1 == p.segments.len() { + itctx + } else { + ImplTraitContext::Disallowed(ImplTraitPosition::Path) + } + }; + let path_span_lo = p.span.shrink_to_lo(); let proj_start = p.segments.len() - unresolved_segments; let path = self.arena.alloc(hir::Path { @@ -121,7 +134,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { segment, param_mode, generic_args_mode, - itctx, + itctx(i), bound_modifier_allowed_features.clone(), ) }, @@ -185,7 +198,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { segment, param_mode, generic_args_mode, - itctx, + itctx(i), None, )); let qpath = hir::QPath::TypeRelative(ty, hir_segment); diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index 92acaaa5f36b0..d81fd53938b89 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -146,8 +146,6 @@ ast_passes_generic_before_constraints = generic arguments must come before the f ast_passes_generic_default_trailing = generic parameters with a default must be trailing -ast_passes_impl_trait_path = `impl Trait` is not allowed in path parameters - ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed .help = remove one of these features diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 1d149e91b8513..0a4f86d4822f7 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -80,10 +80,6 @@ struct AstValidator<'a> { disallow_tilde_const: Option, - /// Used to ban `impl Trait` in path projections like `::Item` - /// or `Foo::Bar` - is_impl_trait_banned: bool, - /// Used to ban explicit safety on foreign items when the extern block is not marked as unsafe. extern_mod_safety: Option, @@ -123,12 +119,6 @@ impl<'a> AstValidator<'a> { self.extern_mod_safety = old; } - fn with_banned_impl_trait(&mut self, f: impl FnOnce(&mut Self)) { - let old = mem::replace(&mut self.is_impl_trait_banned, true); - f(self); - self.is_impl_trait_banned = old; - } - fn with_tilde_const( &mut self, disallowed: Option, @@ -213,37 +203,6 @@ impl<'a> AstValidator<'a> { .with_tilde_const(Some(TildeConstReason::TraitObject), |this| { visit::walk_ty(this, t) }), - TyKind::Path(qself, path) => { - // We allow these: - // - `Option` - // - `option::Option` - // - `option::Option::Foo` - // - // But not these: - // - `::Foo` - // - `option::Option::Foo`. - // - // To implement this, we disallow `impl Trait` from `qself` - // (for cases like `::Foo>`) - // but we allow `impl Trait` in `GenericArgs` - // iff there are no more PathSegments. - if let Some(qself) = qself { - // `impl Trait` in `qself` is always illegal - self.with_banned_impl_trait(|this| this.visit_ty(&qself.ty)); - } - - // Note that there should be a call to visit_path here, - // so if any logic is added to process `Path`s a call to it should be - // added both in visit_path and here. This code mirrors visit::walk_path. - for (i, segment) in path.segments.iter().enumerate() { - // Allow `impl Trait` iff we're on the final path segment - if i == path.segments.len() - 1 { - self.visit_path_segment(segment); - } else { - self.with_banned_impl_trait(|this| this.visit_path_segment(segment)); - } - } - } _ => visit::walk_ty(self, t), } } @@ -737,10 +696,6 @@ impl<'a> AstValidator<'a> { } } TyKind::ImplTrait(_, bounds) => { - if self.is_impl_trait_banned { - self.dcx().emit_err(errors::ImplTraitPath { span: ty.span }); - } - if let Some(outer_impl_trait_sp) = self.outer_impl_trait { self.dcx().emit_err(errors::NestedImplTrait { span: ty.span, @@ -1729,7 +1684,6 @@ pub fn check_crate( has_proc_macro_decls: false, outer_impl_trait: None, disallow_tilde_const: Some(TildeConstReason::Item), - is_impl_trait_banned: false, extern_mod_safety: None, lint_buffer: lints, }; diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 4ca1acde1e289..8c3ac9864ed8a 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -418,13 +418,6 @@ pub(crate) struct TraitObjectBound { pub span: Span, } -#[derive(Diagnostic)] -#[diag(ast_passes_impl_trait_path, code = E0667)] -pub(crate) struct ImplTraitPath { - #[primary_span] - pub span: Span, -} - #[derive(Diagnostic)] #[diag(ast_passes_nested_impl_trait, code = E0666)] pub(crate) struct NestedImplTrait { diff --git a/compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs similarity index 95% rename from compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs rename to compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs index 731945f5cbfbf..53e938ee216b3 100644 --- a/compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs +++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs @@ -19,7 +19,7 @@ macro_rules! path { ($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] } } -pub(crate) fn expand_deriving_smart_ptr( +pub(crate) fn expand_deriving_coerce_pointee( cx: &ExtCtxt<'_>, span: Span, _mitem: &MetaItem, @@ -41,7 +41,7 @@ pub(crate) fn expand_deriving_smart_ptr( cx.dcx() .struct_span_err( span, - "`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`", + "`CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`", ) .emit(); return; @@ -54,7 +54,7 @@ pub(crate) fn expand_deriving_smart_ptr( cx.dcx() .struct_span_err( span, - "`SmartPointer` can only be derived on `struct`s with at least one field", + "`CoercePointee` can only be derived on `struct`s with at least one field", ) .emit(); return; @@ -64,7 +64,7 @@ pub(crate) fn expand_deriving_smart_ptr( cx.dcx() .struct_span_err( span, - "`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`", + "`CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`", ) .emit(); return; @@ -94,10 +94,10 @@ pub(crate) fn expand_deriving_smart_ptr( .collect(); let pointee_param_idx = if type_params.is_empty() { - // `#[derive(SmartPointer)]` requires at least one generic type on the target `struct` + // `#[derive(CoercePointee)]` requires at least one generic type on the target `struct` cx.dcx().struct_span_err( span, - "`SmartPointer` can only be derived on `struct`s that are generic over at least one type", + "`CoercePointee` can only be derived on `struct`s that are generic over at least one type", ).emit(); return; } else if type_params.len() == 1 { @@ -113,7 +113,7 @@ pub(crate) fn expand_deriving_smart_ptr( (None, _) => { cx.dcx().struct_span_err( span, - "exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits", + "exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits", ).emit(); return; } @@ -121,7 +121,7 @@ pub(crate) fn expand_deriving_smart_ptr( cx.dcx() .struct_span_err( vec![one, another], - "only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits", + "only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits", ) .emit(); return; @@ -185,7 +185,7 @@ pub(crate) fn expand_deriving_smart_ptr( .struct_span_err( pointee_ty_ident.span, format!( - "`derive(SmartPointer)` requires {} to be marked `?Sized`", + "`derive(CoercePointee)` requires {} to be marked `?Sized`", pointee_ty_ident.name ), ) @@ -195,7 +195,7 @@ pub(crate) fn expand_deriving_smart_ptr( let arg = GenericArg::Type(s_ty.clone()); let unsize = cx.path_all(span, true, path!(span, core::marker::Unsize), vec![arg]); pointee.bounds.push(cx.trait_bound(unsize, false)); - // Drop `#[pointee]` attribute since it should not be recognized outside `derive(SmartPointer)` + // Drop `#[pointee]` attribute since it should not be recognized outside `derive(CoercePointee)` pointee.attrs.retain(|attr| !attr.has_name(sym::pointee)); } diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index e884c0ec71897..681fbd1651db1 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -22,12 +22,12 @@ macro path_std($($x:tt)*) { pub(crate) mod bounds; pub(crate) mod clone; +pub(crate) mod coerce_pointee; pub(crate) mod debug; pub(crate) mod decodable; pub(crate) mod default; pub(crate) mod encodable; pub(crate) mod hash; -pub(crate) mod smart_ptr; #[path = "cmp/eq.rs"] pub(crate) mod eq; diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 377d7f542cf46..9eee92164cf13 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -133,7 +133,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { PartialOrd: partial_ord::expand_deriving_partial_ord, RustcDecodable: decodable::expand_deriving_rustc_decodable, RustcEncodable: encodable::expand_deriving_rustc_encodable, - SmartPointer: smart_ptr::expand_deriving_smart_ptr, + CoercePointee: coerce_pointee::expand_deriving_coerce_pointee, } let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote); diff --git a/compiler/rustc_error_codes/src/error_codes/E0667.md b/compiler/rustc_error_codes/src/error_codes/E0667.md index 0709a24c43312..339bc0686103a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0667.md +++ b/compiler/rustc_error_codes/src/error_codes/E0667.md @@ -1,8 +1,10 @@ +#### Note: this error code is no longer emitted by the compiler. + `impl Trait` is not allowed in path parameters. Erroneous code example: -```compile_fail,E0667 +```ignore (removed error code) fn some_fn(mut x: impl Iterator) -> ::Item { // error! x.next().unwrap() } @@ -11,7 +13,7 @@ fn some_fn(mut x: impl Iterator) -> ::Item { // error! You cannot use `impl Trait` in path parameters. If you want something equivalent, you can do this instead: -``` +```ignore (removed error code) fn some_fn(mut x: T) -> T::Item { // ok! x.next().unwrap() } diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index fe3a67fd66704..8d2e1e8c8041e 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -85,6 +85,8 @@ declare_features! ( /// Allows default type parameters to influence type inference. (removed, default_type_parameter_fallback, "1.82.0", Some(27336), Some("never properly implemented; requires significant design work")), + /// Allows deriving traits as per `SmartPointer` specification + (removed, derive_smart_pointer, "1.79.0", Some(123430), Some("replaced by `CoercePointee`")), /// Allows using `#[doc(keyword = "...")]`. (removed, doc_keyword, "1.28.0", Some(51315), Some("merged into `#![feature(rustdoc_internals)]`")), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index a81058e6ea160..93047d420ad9e 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -450,8 +450,6 @@ declare_features! ( (unstable, deprecated_suggestion, "1.61.0", Some(94785)), /// Allows deref patterns. (incomplete, deref_patterns, "1.79.0", Some(87121)), - /// Allows deriving `SmartPointer` traits - (unstable, derive_smart_pointer, "1.79.0", Some(123430)), /// Controls errors in trait implementations. (unstable, do_not_recommend, "1.67.0", Some(51992)), /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`. diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 863c077a9e03c..cfd1241ad69c8 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1203,15 +1203,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { err.emit() } else if let Err(reported) = qself_ty.error_reported() { reported - } else if let ty::Alias(ty::Opaque, alias_ty) = qself_ty.kind() { - // `::Assoc` makes no sense. - struct_span_code_err!( - self.dcx(), - tcx.def_span(alias_ty.def_id), - E0667, - "`impl Trait` is not allowed in path parameters" - ) - .emit() // Already reported in an earlier stage. } else { self.maybe_report_similar_assoc_fn(span, qself_ty, qself)?; diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 3ee4980a94821..dbb8c66753236 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -4,21 +4,14 @@ //! AST visitor. Also see `rustc_session::lint::builtin`, which contains the //! definitions of lints that are emitted directly inside the main compiler. //! -//! To add a new lint to rustc, declare it here using `declare_lint!()`. +//! To add a new lint to rustc, declare it here using [`declare_lint!`]. //! Then add code to emit the new lint in the appropriate circumstances. -//! You can do that in an existing `LintPass` if it makes sense, or in a -//! new `LintPass`, or using `Session::add_lint` elsewhere in the -//! compiler. Only do the latter if the check can't be written cleanly as a -//! `LintPass` (also, note that such lints will need to be defined in -//! `rustc_session::lint::builtin`, not here). //! -//! If you define a new `EarlyLintPass`, you will also need to add it to the -//! `add_early_builtin!` or `add_early_builtin_with_new!` invocation in -//! `lib.rs`. Use the former for unit-like structs and the latter for structs -//! with a `pub fn new()`. +//! If you define a new [`EarlyLintPass`], you will also need to add it to the +//! [`crate::early_lint_methods!`] invocation in `lib.rs`. //! -//! If you define a new `LateLintPass`, you will also need to add it to the -//! `late_lint_methods!` invocation in `lib.rs`. +//! If you define a new [`LateLintPass`], you will also need to add it to the +//! [`crate::late_lint_methods!`] invocation in `lib.rs`. use std::fmt::Write; diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 39f90a8e9ed14..4af1fd1baf9cd 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -1,18 +1,7 @@ -//! Implementation of lint checking. +//! Basic types for managing and implementing lints. //! -//! The lint checking is mostly consolidated into one pass which runs -//! after all other analyses. Throughout compilation, lint warnings -//! can be added via the `add_lint` method on the Session structure. This -//! requires a span and an ID of the node that the lint is being added to. The -//! lint isn't actually emitted at that time because it is unknown what the -//! actual lint level at that location is. -//! -//! To actually emit lint warnings/errors, a separate pass is used. -//! A context keeps track of the current state of all lint levels. -//! Upon entering a node of the ast which can modify the lint settings, the -//! previous lint state is pushed onto a stack and the ast is then recursed -//! upon. As the ast is traversed, this keeps track of the current lint level -//! for all lint attributes. +//! See for an +//! overview of how lints are implemented. use std::cell::Cell; use std::{iter, slice}; @@ -52,9 +41,6 @@ type LateLintPassFactory = dyn for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> + sync::DynSend + sync::DynSync; /// Information about the registered lints. -/// -/// This is basically the subset of `Context` that we can -/// build early in the compile pipeline. pub struct LintStore { /// Registered lints. lints: Vec<&'static Lint>, diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index e2247d3a1f6c3..acccff77a10a7 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -1,18 +1,8 @@ -//! Implementation of lint checking. +//! Implementation of the early lint pass. //! -//! The lint checking is mostly consolidated into one pass which runs -//! after all other analyses. Throughout compilation, lint warnings -//! can be added via the `add_lint` method on the Session structure. This -//! requires a span and an ID of the node that the lint is being added to. The -//! lint isn't actually emitted at that time because it is unknown what the -//! actual lint level at that location is. -//! -//! To actually emit lint warnings/errors, a separate pass is used. -//! A context keeps track of the current state of all lint levels. -//! Upon entering a node of the ast which can modify the lint settings, the -//! previous lint state is pushed onto a stack and the ast is then recursed -//! upon. As the ast is traversed, this keeps track of the current lint level -//! for all lint attributes. +//! The early lint pass works on AST nodes after macro expansion and name +//! resolution, just before AST lowering. These lints are for purely +//! syntactical lints. use rustc_ast::ptr::P; use rustc_ast::visit::{self as ast_visit, Visitor, walk_list}; diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 9b1877599bae1..9d35ce19b5702 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -1,18 +1,7 @@ -//! Implementation of lint checking. +//! Implementation of the late lint pass. //! -//! The lint checking is mostly consolidated into one pass which runs -//! after all other analyses. Throughout compilation, lint warnings -//! can be added via the `add_lint` method on the Session structure. This -//! requires a span and an ID of the node that the lint is being added to. The -//! lint isn't actually emitted at that time because it is unknown what the -//! actual lint level at that location is. -//! -//! To actually emit lint warnings/errors, a separate pass is used. -//! A context keeps track of the current state of all lint levels. -//! Upon entering a node of the ast which can modify the lint settings, the -//! previous lint state is pushed onto a stack and the ast is then recursed -//! upon. As the ast is traversed, this keeps track of the current lint level -//! for all lint attributes. +//! The late lint pass Works on HIR nodes, towards the end of analysis (after +//! borrow checking, etc.). These lints have full type information available. use std::any::Any; use std::cell::Cell; diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 5389860e23bb2..d950b1ff5ec88 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -6,20 +6,14 @@ //! other phases of the compiler, which are generally required to hold in order //! to compile the program at all. //! -//! Most lints can be written as [LintPass] instances. These run after +//! Most lints can be written as [`LintPass`] instances. These run after //! all other analyses. The `LintPass`es built into rustc are defined //! within [rustc_session::lint::builtin], //! which has further comments on how to add such a lint. //! rustc can also load external lint plugins, as is done for Clippy. //! -//! Some of rustc's lints are defined elsewhere in the compiler and work by -//! calling `add_lint()` on the overall `Session` object. This works when -//! it happens before the main lint pass, which emits the lints stored by -//! `add_lint()`. To emit lints after the main lint pass (from codegen, for -//! example) requires more effort. See `emit_lint` and `GatherNodeLevels` -//! in `context.rs`. -//! -//! Some code also exists in [rustc_session::lint], [rustc_middle::lint]. +//! See for an +//! overview of how lints are implemented. //! //! ## Note //! diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ed0d7ed8acc6b..acde27c6728c1 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -262,7 +262,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | sym::cfg_attr // need to be fixed | sym::cfi_encoding // FIXME(cfi_encoding) - | sym::pointee // FIXME(derive_smart_pointer) + | sym::pointee // FIXME(derive_coerce_pointee) | sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section) | sym::used // handled elsewhere to restrict to static items | sym::repr // handled elsewhere to restrict to type decls items diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 134a1a1db305a..9214cf7593356 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -174,6 +174,7 @@ symbols! { Center, Cleanup, Clone, + CoercePointee, CoerceUnsized, Command, ConstParamTy, @@ -307,7 +308,6 @@ symbols! { Sized, SliceIndex, SliceIter, - SmartPointer, Some, SpanCtxt, String, @@ -732,6 +732,7 @@ symbols! { deref_pure, deref_target, derive, + derive_coerce_pointee, derive_const, derive_default_enum, derive_smart_pointer, diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 1237fc82a171b..1c5c58d64a2b2 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1063,9 +1063,10 @@ pub trait FnPtr: Copy + Clone { } /// Derive macro generating impls of traits related to smart pointers. -#[rustc_builtin_macro(SmartPointer, attributes(pointee))] +#[rustc_builtin_macro(CoercePointee, attributes(pointee))] #[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)] -#[unstable(feature = "derive_smart_pointer", issue = "123430")] -pub macro SmartPointer($item:item) { +#[unstable(feature = "derive_coerce_pointee", issue = "123430")] +#[cfg(not(bootstrap))] +pub macro CoercePointee($item:item) { /* compiler built-in */ } diff --git a/tests/crashes/126725.rs b/tests/crashes/126725.rs deleted file mode 100644 index d7a7d21ae4244..0000000000000 --- a/tests/crashes/126725.rs +++ /dev/null @@ -1,20 +0,0 @@ -//@ known-bug: rust-lang/rust#126725 -trait Foo { - fn foo<'a>(&'a self) -> <&'a impl Sized as Bar>::Output; -} - -trait Bar { - type Output; -} - -struct X(i32); - -impl<'a> Bar for &'a X { - type Output = &'a i32; -} - -impl Foo for X { - fn foo<'a>(&'a self) -> <&'a Self as Bar>::Output { - &self.0 - } -} diff --git a/tests/ui/deriving/auxiliary/another-proc-macro.rs b/tests/ui/deriving/auxiliary/another-proc-macro.rs index a05175c9de926..c992cde4066b1 100644 --- a/tests/ui/deriving/auxiliary/another-proc-macro.rs +++ b/tests/ui/deriving/auxiliary/another-proc-macro.rs @@ -6,7 +6,7 @@ extern crate proc_macro; -use proc_macro::{quote, TokenStream}; +use proc_macro::{TokenStream, quote}; #[proc_macro_derive(AnotherMacro, attributes(pointee))] pub fn derive(_input: TokenStream) -> TokenStream { diff --git a/tests/ui/deriving/built-in-proc-macro-scope.rs b/tests/ui/deriving/built-in-proc-macro-scope.rs index 41c95f63b135e..6c473aefc5b0c 100644 --- a/tests/ui/deriving/built-in-proc-macro-scope.rs +++ b/tests/ui/deriving/built-in-proc-macro-scope.rs @@ -2,14 +2,14 @@ //@ aux-build: another-proc-macro.rs //@ compile-flags: -Zunpretty=expanded -#![feature(derive_smart_pointer)] +#![feature(derive_coerce_pointee)] #[macro_use] extern crate another_proc_macro; -use another_proc_macro::{pointee, AnotherMacro}; +use another_proc_macro::{AnotherMacro, pointee}; -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct Ptr<'a, #[pointee] T: ?Sized> { data: &'a mut T, diff --git a/tests/ui/deriving/built-in-proc-macro-scope.stdout b/tests/ui/deriving/built-in-proc-macro-scope.stdout index c649b7a9a574c..07767dc229fd7 100644 --- a/tests/ui/deriving/built-in-proc-macro-scope.stdout +++ b/tests/ui/deriving/built-in-proc-macro-scope.stdout @@ -4,7 +4,7 @@ //@ aux-build: another-proc-macro.rs //@ compile-flags: -Zunpretty=expanded -#![feature(derive_smart_pointer)] +#![feature(derive_coerce_pointee)] #[prelude_import] use ::std::prelude::rust_2015::*; #[macro_use] @@ -13,7 +13,7 @@ extern crate std; #[macro_use] extern crate another_proc_macro; -use another_proc_macro::{pointee, AnotherMacro}; +use another_proc_macro::{AnotherMacro, pointee}; #[repr(transparent)] pub struct Ptr<'a, #[pointee] T: ?Sized> { diff --git a/tests/ui/deriving/smart-pointer-bounds-issue-127647.rs b/tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs similarity index 82% rename from tests/ui/deriving/smart-pointer-bounds-issue-127647.rs rename to tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs index 4cae1b32896fb..a1aabf1cb527d 100644 --- a/tests/ui/deriving/smart-pointer-bounds-issue-127647.rs +++ b/tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs @@ -1,8 +1,8 @@ //@ check-pass -#![feature(derive_smart_pointer)] +#![feature(derive_coerce_pointee)] -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct Ptr<'a, #[pointee] T: OnDrop + ?Sized, X> { data: &'a mut T, @@ -13,7 +13,7 @@ pub trait OnDrop { fn on_drop(&mut self); } -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct Ptr2<'a, #[pointee] T: ?Sized, X> where @@ -25,7 +25,7 @@ where pub trait MyTrait {} -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct Ptr3<'a, #[pointee] T: ?Sized, X> where @@ -35,14 +35,14 @@ where x: core::marker::PhantomData, } -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct Ptr4<'a, #[pointee] T: MyTrait + ?Sized, X> { data: &'a mut T, x: core::marker::PhantomData, } -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct Ptr5<'a, #[pointee] T: ?Sized, X> where @@ -56,7 +56,7 @@ where pub struct Ptr5Companion(core::marker::PhantomData); pub struct Ptr5Companion2; -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait = (), const PARAM: usize = 0> { data: &'a mut T, @@ -65,7 +65,7 @@ pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait = (), const PARAM: usize // a reduced example from https://lore.kernel.org/all/20240402-linked-list-v1-1-b1c59ba7ae3b@google.com/ #[repr(transparent)] -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] pub struct ListArc<#[pointee] T, const ID: u64 = 0> where T: ListArcSafe + ?Sized, diff --git a/tests/ui/deriving/deriving-smart-pointer-expanded.rs b/tests/ui/deriving/deriving-coerce-pointee-expanded.rs similarity index 75% rename from tests/ui/deriving/deriving-smart-pointer-expanded.rs rename to tests/ui/deriving/deriving-coerce-pointee-expanded.rs index e48ad3dd4bc6c..94be7031fb77f 100644 --- a/tests/ui/deriving/deriving-smart-pointer-expanded.rs +++ b/tests/ui/deriving/deriving-coerce-pointee-expanded.rs @@ -1,17 +1,17 @@ //@ check-pass //@ compile-flags: -Zunpretty=expanded -#![feature(derive_smart_pointer)] -use std::marker::SmartPointer; +#![feature(derive_coerce_pointee)] +use std::marker::CoercePointee; pub trait MyTrait {} -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct MyPointer<'a, #[pointee] T: ?Sized> { ptr: &'a T, } -#[derive(core::marker::SmartPointer)] +#[derive(core::marker::CoercePointee)] #[repr(transparent)] pub struct MyPointer2<'a, Y, Z: MyTrait, #[pointee] T: ?Sized + MyTrait, X: MyTrait = ()> where @@ -21,7 +21,7 @@ where x: core::marker::PhantomData, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct MyPointerWithoutPointee<'a, T: ?Sized> { ptr: &'a T, diff --git a/tests/ui/deriving/deriving-smart-pointer-expanded.stdout b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout similarity index 96% rename from tests/ui/deriving/deriving-smart-pointer-expanded.stdout rename to tests/ui/deriving/deriving-coerce-pointee-expanded.stdout index 68ef17f2b0547..d6eaca5cba188 100644 --- a/tests/ui/deriving/deriving-smart-pointer-expanded.stdout +++ b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout @@ -2,12 +2,12 @@ #![no_std] //@ check-pass //@ compile-flags: -Zunpretty=expanded -#![feature(derive_smart_pointer)] +#![feature(derive_coerce_pointee)] #[prelude_import] use ::std::prelude::rust_2015::*; #[macro_use] extern crate std; -use std::marker::SmartPointer; +use std::marker::CoercePointee; pub trait MyTrait {} diff --git a/tests/ui/deriving/deriving-smart-pointer-neg.rs b/tests/ui/deriving/deriving-coerce-pointee-neg.rs similarity index 50% rename from tests/ui/deriving/deriving-smart-pointer-neg.rs rename to tests/ui/deriving/deriving-coerce-pointee-neg.rs index 41d3039236f71..deef35cdf701d 100644 --- a/tests/ui/deriving/deriving-smart-pointer-neg.rs +++ b/tests/ui/deriving/deriving-coerce-pointee-neg.rs @@ -1,115 +1,131 @@ -#![feature(derive_smart_pointer, arbitrary_self_types)] +#![feature(derive_coerce_pointee, arbitrary_self_types)] extern crate core; -use std::marker::SmartPointer; +use std::marker::CoercePointee; -#[derive(SmartPointer)] -//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` +#[derive(CoercePointee)] +//~^ ERROR: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]` enum NotStruct<'a, T: ?Sized> { Variant(&'a T), } -#[derive(SmartPointer)] -//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field +#[derive(CoercePointee)] +//~^ ERROR: `CoercePointee` can only be derived on `struct`s with at least one field #[repr(transparent)] struct NoField<'a, #[pointee] T: ?Sized> {} //~^ ERROR: lifetime parameter `'a` is never used //~| ERROR: type parameter `T` is never used -#[derive(SmartPointer)] -//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field +#[derive(CoercePointee)] +//~^ ERROR: `CoercePointee` can only be derived on `struct`s with at least one field #[repr(transparent)] struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); //~^ ERROR: lifetime parameter `'a` is never used //~| ERROR: type parameter `T` is never used -#[derive(SmartPointer)] -//~^ ERROR: `SmartPointer` can only be derived on `struct`s that are generic over at least one type +#[derive(CoercePointee)] +//~^ ERROR: `CoercePointee` can only be derived on `struct`s that are generic over at least one type #[repr(transparent)] struct NoGeneric<'a>(&'a u8); -#[derive(SmartPointer)] -//~^ ERROR: exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits +#[derive(CoercePointee)] +//~^ ERROR: exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits #[repr(transparent)] struct AmbiguousPointee<'a, T1: ?Sized, T2: ?Sized> { a: (&'a T1, &'a T2), } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct TooManyPointees<'a, #[pointee] A: ?Sized, #[pointee] B: ?Sized>((&'a A, &'a B)); -//~^ ERROR: only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits +//~^ ERROR: only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits -#[derive(SmartPointer)] -//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` +#[derive(CoercePointee)] +//~^ ERROR: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]` struct NotTransparent<'a, #[pointee] T: ?Sized> { ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct NoMaybeSized<'a, #[pointee] T> { - //~^ ERROR: `derive(SmartPointer)` requires T to be marked `?Sized` + //~^ ERROR: `derive(CoercePointee)` requires T to be marked `?Sized` ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct PointeeOnField<'a, #[pointee] T: ?Sized> { #[pointee] //~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters - ptr: &'a T + ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] -struct PointeeInTypeConstBlock<'a, T: ?Sized = [u32; const { struct UhOh<#[pointee] T>(T); 10 }]> { - //~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters +struct PointeeInTypeConstBlock< + 'a, + T: ?Sized = [u32; const { + struct UhOh<#[pointee] T>(T); + //~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters + 10 + }], +> { ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct PointeeInConstConstBlock< 'a, T: ?Sized, - const V: u32 = { struct UhOh<#[pointee] T>(T); 10 }> - //~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters -{ + const V: u32 = { + struct UhOh<#[pointee] T>(T); + //~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters + 10 + }, +> { ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct PointeeInAnotherTypeConstBlock<'a, #[pointee] T: ?Sized> { - ptr: PointeeInConstConstBlock<'a, T, { struct UhOh<#[pointee] T>(T); 0 }> - //~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters + ptr: PointeeInConstConstBlock< + 'a, + T, + { + struct UhOh<#[pointee] T>(T); + //~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters + 0 + }, + >, } // However, reordering attributes should work nevertheless. #[repr(transparent)] -#[derive(SmartPointer)] -struct ThisIsAPossibleSmartPointer<'a, #[pointee] T: ?Sized> { +#[derive(CoercePointee)] +struct ThisIsAPossibleCoercePointee<'a, #[pointee] T: ?Sized> { ptr: &'a T, } // Also, these paths to Sized should work -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct StdSized<'a, #[pointee] T: ?std::marker::Sized> { ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct CoreSized<'a, #[pointee] T: ?core::marker::Sized> { ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct GlobalStdSized<'a, #[pointee] T: ?::std::marker::Sized> { ptr: &'a T, } -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct GlobalCoreSized<'a, #[pointee] T: ?::core::marker::Sized> { ptr: &'a T, diff --git a/tests/ui/deriving/deriving-coerce-pointee-neg.stderr b/tests/ui/deriving/deriving-coerce-pointee-neg.stderr new file mode 100644 index 0000000000000..e590d636d0e35 --- /dev/null +++ b/tests/ui/deriving/deriving-coerce-pointee-neg.stderr @@ -0,0 +1,119 @@ +error: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]` + --> $DIR/deriving-coerce-pointee-neg.rs:6:10 + | +LL | #[derive(CoercePointee)] + | ^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `CoercePointee` can only be derived on `struct`s with at least one field + --> $DIR/deriving-coerce-pointee-neg.rs:12:10 + | +LL | #[derive(CoercePointee)] + | ^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `CoercePointee` can only be derived on `struct`s with at least one field + --> $DIR/deriving-coerce-pointee-neg.rs:19:10 + | +LL | #[derive(CoercePointee)] + | ^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `CoercePointee` can only be derived on `struct`s that are generic over at least one type + --> $DIR/deriving-coerce-pointee-neg.rs:26:10 + | +LL | #[derive(CoercePointee)] + | ^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits + --> $DIR/deriving-coerce-pointee-neg.rs:31:10 + | +LL | #[derive(CoercePointee)] + | ^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits + --> $DIR/deriving-coerce-pointee-neg.rs:40:39 + | +LL | struct TooManyPointees<'a, #[pointee] A: ?Sized, #[pointee] B: ?Sized>((&'a A, &'a B)); + | ^ ^ + +error: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]` + --> $DIR/deriving-coerce-pointee-neg.rs:43:10 + | +LL | #[derive(CoercePointee)] + | ^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `derive(CoercePointee)` requires T to be marked `?Sized` + --> $DIR/deriving-coerce-pointee-neg.rs:51:36 + | +LL | struct NoMaybeSized<'a, #[pointee] T> { + | ^ + +error: the `#[pointee]` attribute may only be used on generic parameters + --> $DIR/deriving-coerce-pointee-neg.rs:59:5 + | +LL | #[pointee] + | ^^^^^^^^^^ + +error: the `#[pointee]` attribute may only be used on generic parameters + --> $DIR/deriving-coerce-pointee-neg.rs:69:33 + | +LL | struct UhOh<#[pointee] T>(T); + | ^^^^^^^^^^ + +error: the `#[pointee]` attribute may only be used on generic parameters + --> $DIR/deriving-coerce-pointee-neg.rs:83:21 + | +LL | struct UhOh<#[pointee] T>(T); + | ^^^^^^^^^^ + +error: the `#[pointee]` attribute may only be used on generic parameters + --> $DIR/deriving-coerce-pointee-neg.rs:98:25 + | +LL | struct UhOh<#[pointee] T>(T); + | ^^^^^^^^^^ + +error[E0392]: lifetime parameter `'a` is never used + --> $DIR/deriving-coerce-pointee-neg.rs:15:16 + | +LL | struct NoField<'a, #[pointee] T: ?Sized> {} + | ^^ unused lifetime parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: type parameter `T` is never used + --> $DIR/deriving-coerce-pointee-neg.rs:15:31 + | +LL | struct NoField<'a, #[pointee] T: ?Sized> {} + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: lifetime parameter `'a` is never used + --> $DIR/deriving-coerce-pointee-neg.rs:22:20 + | +LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); + | ^^ unused lifetime parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: type parameter `T` is never used + --> $DIR/deriving-coerce-pointee-neg.rs:22:35 + | +LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 16 previous errors + +For more information about this error, try `rustc --explain E0392`. diff --git a/tests/ui/deriving/deriving-smart-pointer.rs b/tests/ui/deriving/deriving-coerce-pointee.rs similarity index 90% rename from tests/ui/deriving/deriving-smart-pointer.rs rename to tests/ui/deriving/deriving-coerce-pointee.rs index d34a502da684f..26762e4d0face 100644 --- a/tests/ui/deriving/deriving-smart-pointer.rs +++ b/tests/ui/deriving/deriving-coerce-pointee.rs @@ -1,9 +1,9 @@ //@ run-pass -#![feature(derive_smart_pointer, arbitrary_self_types)] +#![feature(derive_coerce_pointee, arbitrary_self_types)] -use std::marker::SmartPointer; +use std::marker::CoercePointee; -#[derive(SmartPointer)] +#[derive(CoercePointee)] #[repr(transparent)] struct MyPointer<'a, #[pointee] T: ?Sized> { ptr: &'a T, diff --git a/tests/ui/deriving/deriving-smart-pointer-neg.stderr b/tests/ui/deriving/deriving-smart-pointer-neg.stderr deleted file mode 100644 index 9ab117698c7a0..0000000000000 --- a/tests/ui/deriving/deriving-smart-pointer-neg.stderr +++ /dev/null @@ -1,119 +0,0 @@ -error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` - --> $DIR/deriving-smart-pointer-neg.rs:6:10 - | -LL | #[derive(SmartPointer)] - | ^^^^^^^^^^^^ - | - = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `SmartPointer` can only be derived on `struct`s with at least one field - --> $DIR/deriving-smart-pointer-neg.rs:12:10 - | -LL | #[derive(SmartPointer)] - | ^^^^^^^^^^^^ - | - = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `SmartPointer` can only be derived on `struct`s with at least one field - --> $DIR/deriving-smart-pointer-neg.rs:19:10 - | -LL | #[derive(SmartPointer)] - | ^^^^^^^^^^^^ - | - = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `SmartPointer` can only be derived on `struct`s that are generic over at least one type - --> $DIR/deriving-smart-pointer-neg.rs:26:10 - | -LL | #[derive(SmartPointer)] - | ^^^^^^^^^^^^ - | - = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits - --> $DIR/deriving-smart-pointer-neg.rs:31:10 - | -LL | #[derive(SmartPointer)] - | ^^^^^^^^^^^^ - | - = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits - --> $DIR/deriving-smart-pointer-neg.rs:40:39 - | -LL | struct TooManyPointees<'a, #[pointee] A: ?Sized, #[pointee] B: ?Sized>((&'a A, &'a B)); - | ^ ^ - -error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` - --> $DIR/deriving-smart-pointer-neg.rs:43:10 - | -LL | #[derive(SmartPointer)] - | ^^^^^^^^^^^^ - | - = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `derive(SmartPointer)` requires T to be marked `?Sized` - --> $DIR/deriving-smart-pointer-neg.rs:51:36 - | -LL | struct NoMaybeSized<'a, #[pointee] T> { - | ^ - -error: the `#[pointee]` attribute may only be used on generic parameters - --> $DIR/deriving-smart-pointer-neg.rs:59:5 - | -LL | #[pointee] - | ^^^^^^^^^^ - -error: the `#[pointee]` attribute may only be used on generic parameters - --> $DIR/deriving-smart-pointer-neg.rs:66:74 - | -LL | struct PointeeInTypeConstBlock<'a, T: ?Sized = [u32; const { struct UhOh<#[pointee] T>(T); 10 }]> { - | ^^^^^^^^^^ - -error: the `#[pointee]` attribute may only be used on generic parameters - --> $DIR/deriving-smart-pointer-neg.rs:76:34 - | -LL | const V: u32 = { struct UhOh<#[pointee] T>(T); 10 }> - | ^^^^^^^^^^ - -error: the `#[pointee]` attribute may only be used on generic parameters - --> $DIR/deriving-smart-pointer-neg.rs:85:56 - | -LL | ptr: PointeeInConstConstBlock<'a, T, { struct UhOh<#[pointee] T>(T); 0 }> - | ^^^^^^^^^^ - -error[E0392]: lifetime parameter `'a` is never used - --> $DIR/deriving-smart-pointer-neg.rs:15:16 - | -LL | struct NoField<'a, #[pointee] T: ?Sized> {} - | ^^ unused lifetime parameter - | - = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` - -error[E0392]: type parameter `T` is never used - --> $DIR/deriving-smart-pointer-neg.rs:15:31 - | -LL | struct NoField<'a, #[pointee] T: ?Sized> {} - | ^ unused type parameter - | - = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` - -error[E0392]: lifetime parameter `'a` is never used - --> $DIR/deriving-smart-pointer-neg.rs:22:20 - | -LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); - | ^^ unused lifetime parameter - | - = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` - -error[E0392]: type parameter `T` is never used - --> $DIR/deriving-smart-pointer-neg.rs:22:35 - | -LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); - | ^ unused type parameter - | - = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` - -error: aborting due to 16 previous errors - -For more information about this error, try `rustc --explain E0392`. diff --git a/tests/ui/deriving/proc-macro-attribute-mixing.rs b/tests/ui/deriving/proc-macro-attribute-mixing.rs index 489665ebeb520..80a0d068ce7dd 100644 --- a/tests/ui/deriving/proc-macro-attribute-mixing.rs +++ b/tests/ui/deriving/proc-macro-attribute-mixing.rs @@ -1,5 +1,5 @@ // This test certify that we can mix attribute macros from Rust and external proc-macros. -// For instance, `#[derive(Default)]` uses `#[default]` and `#[derive(SmartPointer)]` uses +// For instance, `#[derive(Default)]` uses `#[default]` and `#[derive(CoercePointee)]` uses // `#[pointee]`. // The scoping rule should allow the use of the said two attributes when external proc-macros // are in scope. @@ -8,7 +8,7 @@ //@ aux-build: another-proc-macro.rs //@ compile-flags: -Zunpretty=expanded -#![feature(derive_smart_pointer)] +#![feature(derive_coerce_pointee)] #[macro_use] extern crate another_proc_macro; diff --git a/tests/ui/deriving/proc-macro-attribute-mixing.stdout b/tests/ui/deriving/proc-macro-attribute-mixing.stdout index f314f6efbe2b9..03128c6c957cf 100644 --- a/tests/ui/deriving/proc-macro-attribute-mixing.stdout +++ b/tests/ui/deriving/proc-macro-attribute-mixing.stdout @@ -1,7 +1,7 @@ #![feature(prelude_import)] #![no_std] // This test certify that we can mix attribute macros from Rust and external proc-macros. -// For instance, `#[derive(Default)]` uses `#[default]` and `#[derive(SmartPointer)]` uses +// For instance, `#[derive(Default)]` uses `#[default]` and `#[derive(CoercePointee)]` uses // `#[pointee]`. // The scoping rule should allow the use of the said two attributes when external proc-macros // are in scope. @@ -10,7 +10,7 @@ //@ aux-build: another-proc-macro.rs //@ compile-flags: -Zunpretty=expanded -#![feature(derive_smart_pointer)] +#![feature(derive_coerce_pointee)] #[prelude_import] use ::std::prelude::rust_2015::*; #[macro_use] diff --git a/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs new file mode 100644 index 0000000000000..69bc70e8666a3 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs @@ -0,0 +1,9 @@ +use std::marker::CoercePointee; //~ ERROR use of unstable library feature 'derive_coerce_pointee' + +#[derive(CoercePointee)] //~ ERROR use of unstable library feature 'derive_coerce_pointee' +#[repr(transparent)] +struct MyPointer<'a, #[pointee] T: ?Sized> { + ptr: &'a T, +} + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr new file mode 100644 index 0000000000000..0b52ceb782aea --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr @@ -0,0 +1,23 @@ +error[E0658]: use of unstable library feature 'derive_coerce_pointee' + --> $DIR/feature-gate-derive-coerce-pointee.rs:3:10 + | +LL | #[derive(CoercePointee)] + | ^^^^^^^^^^^^^ + | + = note: see issue #123430 for more information + = help: add `#![feature(derive_coerce_pointee)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: use of unstable library feature 'derive_coerce_pointee' + --> $DIR/feature-gate-derive-coerce-pointee.rs:1:5 + | +LL | use std::marker::CoercePointee; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #123430 for more information + = help: add `#![feature(derive_coerce_pointee)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.rs b/tests/ui/feature-gates/feature-gate-derive-smart-pointer.rs deleted file mode 100644 index 7b4764ee768ab..0000000000000 --- a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.rs +++ /dev/null @@ -1,9 +0,0 @@ -use std::marker::SmartPointer; //~ ERROR use of unstable library feature 'derive_smart_pointer' - -#[derive(SmartPointer)] //~ ERROR use of unstable library feature 'derive_smart_pointer' -#[repr(transparent)] -struct MyPointer<'a, #[pointee] T: ?Sized> { - ptr: &'a T, -} - -fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.stderr b/tests/ui/feature-gates/feature-gate-derive-smart-pointer.stderr deleted file mode 100644 index ea4d1271b7c87..0000000000000 --- a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0658]: use of unstable library feature 'derive_smart_pointer' - --> $DIR/feature-gate-derive-smart-pointer.rs:3:10 - | -LL | #[derive(SmartPointer)] - | ^^^^^^^^^^^^ - | - = note: see issue #123430 for more information - = help: add `#![feature(derive_smart_pointer)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: use of unstable library feature 'derive_smart_pointer' - --> $DIR/feature-gate-derive-smart-pointer.rs:1:5 - | -LL | use std::marker::SmartPointer; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #123430 for more information - = help: add `#![feature(derive_smart_pointer)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/impl-trait/impl_trait_projections.rs b/tests/ui/impl-trait/impl_trait_projections.rs index 365ac85e2f665..2c277aee06dad 100644 --- a/tests/ui/impl-trait/impl_trait_projections.rs +++ b/tests/ui/impl-trait/impl_trait_projections.rs @@ -10,30 +10,27 @@ fn path_parametrized_type_is_allowed() -> option::Option { } fn projection_is_disallowed(x: impl Iterator) -> ::Item { -//~^ ERROR `impl Trait` is not allowed in path parameters -//~| ERROR `impl Trait` is not allowed in path parameters +//~^ ERROR `impl Trait` is not allowed in paths x.next().unwrap() } fn projection_with_named_trait_is_disallowed(mut x: impl Iterator) -> ::Item -//~^ ERROR `impl Trait` is not allowed in path parameters +//~^ ERROR `impl Trait` is not allowed in paths { x.next().unwrap() } fn projection_with_named_trait_inside_path_is_disallowed() -> <::std::ops::Range as Iterator>::Item -//~^ ERROR `impl Trait` is not allowed in path parameters -//~| ERROR `impl Debug: Step` is not satisfied +//~^ ERROR `impl Trait` is not allowed in paths { - //~^ ERROR `impl Debug: Step` is not satisfied (1i32..100).next().unwrap() } fn projection_from_impl_trait_inside_dyn_trait_is_disallowed() -> as Iterator>::Item -//~^ ERROR `impl Trait` is not allowed in path parameters +//~^ ERROR `impl Trait` is not allowed in paths { panic!() } diff --git a/tests/ui/impl-trait/impl_trait_projections.stderr b/tests/ui/impl-trait/impl_trait_projections.stderr index d62e3ac4183f5..5e0b80fcd5922 100644 --- a/tests/ui/impl-trait/impl_trait_projections.stderr +++ b/tests/ui/impl-trait/impl_trait_projections.stderr @@ -1,73 +1,35 @@ -error[E0667]: `impl Trait` is not allowed in path parameters +error[E0562]: `impl Trait` is not allowed in paths --> $DIR/impl_trait_projections.rs:12:51 | LL | fn projection_is_disallowed(x: impl Iterator) -> ::Item { | ^^^^^^^^^^^^^ + | + = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error[E0667]: `impl Trait` is not allowed in path parameters - --> $DIR/impl_trait_projections.rs:19:9 +error[E0562]: `impl Trait` is not allowed in paths + --> $DIR/impl_trait_projections.rs:18:9 | LL | -> ::Item | ^^^^^^^^^^^^^ + | + = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error[E0667]: `impl Trait` is not allowed in path parameters - --> $DIR/impl_trait_projections.rs:26:27 +error[E0562]: `impl Trait` is not allowed in paths + --> $DIR/impl_trait_projections.rs:25:27 | LL | -> <::std::ops::Range as Iterator>::Item | ^^^^^^^^^^ + | + = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error[E0667]: `impl Trait` is not allowed in path parameters - --> $DIR/impl_trait_projections.rs:35:29 +error[E0562]: `impl Trait` is not allowed in paths + --> $DIR/impl_trait_projections.rs:32:29 | LL | -> as Iterator>::Item | ^^^^^^^^^^ - -error[E0667]: `impl Trait` is not allowed in path parameters - --> $DIR/impl_trait_projections.rs:12:51 - | -LL | fn projection_is_disallowed(x: impl Iterator) -> ::Item { - | ^^^^^^^^^^^^^ - -error[E0277]: the trait bound `impl Debug: Step` is not satisfied - --> $DIR/impl_trait_projections.rs:26:8 - | -LL | -> <::std::ops::Range as Iterator>::Item - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Step` is not implemented for `impl Debug`, which is required by `std::ops::Range: Iterator` - | - = help: the following other types implement trait `Step`: - Char - Ipv4Addr - Ipv6Addr - char - i128 - i16 - i32 - i64 - and 8 others - = note: required for `std::ops::Range` to implement `Iterator` - -error[E0277]: the trait bound `impl Debug: Step` is not satisfied - --> $DIR/impl_trait_projections.rs:29:1 - | -LL | / { -LL | | -LL | | (1i32..100).next().unwrap() -LL | | } - | |_^ the trait `Step` is not implemented for `impl Debug`, which is required by `std::ops::Range: Iterator` | - = help: the following other types implement trait `Step`: - Char - Ipv4Addr - Ipv6Addr - char - i128 - i16 - i32 - i64 - and 8 others - = note: required for `std::ops::Range` to implement `Iterator` + = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error: aborting due to 7 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0277, E0667. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0562`. diff --git a/tests/ui/impl-trait/in-trait/bad-projection-from-opaque.rs b/tests/ui/impl-trait/in-trait/bad-projection-from-opaque.rs new file mode 100644 index 0000000000000..c2c22cd1abfcc --- /dev/null +++ b/tests/ui/impl-trait/in-trait/bad-projection-from-opaque.rs @@ -0,0 +1,22 @@ +// issue: rust-lang/rust#126725 + +trait Foo { + fn foo<'a>() -> <&'a impl Sized as Bar>::Output; + //~^ ERROR `impl Trait` is not allowed in paths +} + +trait Bar { + type Output; +} + +impl<'a> Bar for &'a () { + type Output = &'a i32; +} + +impl Foo for () { + fn foo<'a>() -> <&'a Self as Bar>::Output { + &0 + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/bad-projection-from-opaque.stderr b/tests/ui/impl-trait/in-trait/bad-projection-from-opaque.stderr new file mode 100644 index 0000000000000..bea7ccd1a18d0 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/bad-projection-from-opaque.stderr @@ -0,0 +1,11 @@ +error[E0562]: `impl Trait` is not allowed in paths + --> $DIR/bad-projection-from-opaque.rs:4:26 + | +LL | fn foo<'a>() -> <&'a impl Sized as Bar>::Output; + | ^^^^^^^^^^ + | + = note: `impl Trait` is only allowed in arguments and return types of functions and methods + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0562`. diff --git a/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs b/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs index c5ecd1caae1f9..9466668b1dcd4 100644 --- a/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs +++ b/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs @@ -6,7 +6,7 @@ pub trait Bar { } pub trait Quux { type Assoc; } pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } -//~^ ERROR `impl Trait` is not allowed in path parameters +//~^ ERROR `impl Trait` is not allowed in paths impl Quux for () { type Assoc = u32; } fn main() { } diff --git a/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr b/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr index 55f47785f0eeb..25547dfa66f5d 100644 --- a/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr +++ b/tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr @@ -1,9 +1,11 @@ -error[E0667]: `impl Trait` is not allowed in path parameters +error[E0562]: `impl Trait` is not allowed in paths --> $DIR/issue-57979-impl-trait-in-path.rs:8:48 | LL | pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } | ^^^^^^^^ + | + = note: `impl Trait` is only allowed in arguments and return types of functions and methods error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0667`. +For more information about this error, try `rustc --explain E0562`.