diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index dbbb7f926bc..ef6a6ae23dc 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -454,7 +454,6 @@ impl<'a> LoweringContext<'a> { | ItemKind::Union(_, ref generics) | ItemKind::Enum(_, ref generics) | ItemKind::TyAlias(_, ref generics) - | ItemKind::OpaqueTy(_, ref generics) | ItemKind::Trait(_, _, ref generics, ..) => { let def_id = self.lctx.resolver.definitions().local_def_id(item.id); let count = generics diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 137d21c3580..4cd42927868 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -337,20 +337,22 @@ impl LoweringContext<'_> { ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)), ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)), ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)), - ItemKind::TyAlias(ref t, ref generics) => hir::ItemKind::TyAlias( - self.lower_ty(t, ImplTraitContext::disallowed()), - self.lower_generics(generics, ImplTraitContext::disallowed()), - ), - ItemKind::OpaqueTy(ref b, ref generics) => hir::ItemKind::OpaqueTy( - hir::OpaqueTy { - generics: self.lower_generics(generics, - ImplTraitContext::OpaqueTy(None)), - bounds: self.lower_param_bounds(b, - ImplTraitContext::OpaqueTy(None)), - impl_trait_fn: None, - origin: hir::OpaqueTyOrigin::TypeAlias, + ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() { + None => { + let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); + hir::ItemKind::TyAlias(ty, generics) }, - ), + Some(bounds) => { + let ty = hir::OpaqueTy { + generics: self.lower_generics(generics, ImplTraitContext::OpaqueTy(None)), + bounds: self.lower_param_bounds(bounds, ImplTraitContext::OpaqueTy(None)), + impl_trait_fn: None, + origin: hir::OpaqueTyOrigin::TypeAlias, + }; + hir::ItemKind::OpaqueTy(ty) + } + } ItemKind::Enum(ref enum_definition, ref generics) => { hir::ItemKind::Enum( hir::EnumDef { @@ -916,16 +918,20 @@ impl LoweringContext<'_> { (generics, hir::ImplItemKind::Method(sig, body_id)) } - ImplItemKind::TyAlias(ref ty) => ( - self.lower_generics(&i.generics, ImplTraitContext::disallowed()), - hir::ImplItemKind::TyAlias(self.lower_ty(ty, ImplTraitContext::disallowed())), - ), - ImplItemKind::OpaqueTy(ref bounds) => ( - self.lower_generics(&i.generics, ImplTraitContext::disallowed()), - hir::ImplItemKind::OpaqueTy( - self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), - ), - ), + ImplItemKind::TyAlias(ref ty) => { + let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed()); + let kind = match ty.kind.opaque_top_hack() { + None => { + let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + hir::ImplItemKind::TyAlias(ty) + } + Some(bs) => { + let bounds = self.lower_param_bounds(bs, ImplTraitContext::disallowed()); + hir::ImplItemKind::OpaqueTy(bounds) + } + }; + (generics, kind) + }, ImplItemKind::Macro(..) => bug!("`TyMac` should have been expanded by now"), }; @@ -950,11 +956,13 @@ impl LoweringContext<'_> { span: i.span, vis: self.lower_visibility(&i.vis, Some(i.id)), defaultness: self.lower_defaultness(i.defaultness, true /* [1] */), - kind: match i.kind { + kind: match &i.kind { ImplItemKind::Const(..) => hir::AssocItemKind::Const, - ImplItemKind::TyAlias(..) => hir::AssocItemKind::Type, - ImplItemKind::OpaqueTy(..) => hir::AssocItemKind::OpaqueTy, - ImplItemKind::Method(ref sig, _) => hir::AssocItemKind::Method { + ImplItemKind::TyAlias(ty) => match ty.kind.opaque_top_hack() { + None => hir::AssocItemKind::Type, + Some(_) => hir::AssocItemKind::OpaqueTy, + }, + ImplItemKind::Method(sig, _) => hir::AssocItemKind::Method { has_self: sig.decl.has_self(), }, ImplItemKind::Macro(..) => unimplemented!(), diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index d858e00a2e9..cfd90f50b1b 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -107,7 +107,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { } ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | - ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | + ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name), ItemKind::Fn(sig, generics, body) if sig.header.asyncness.node.is_async() => { return self.visit_async_fn( @@ -239,8 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { } ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name), - ImplItemKind::TyAlias(..) | - ImplItemKind::OpaqueTy(..) => DefPathData::TypeNs(ii.ident.name), + ImplItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name), ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id), }; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 82631ce7435..c7e51ff3217 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -2176,15 +2176,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { err.note(&format!("required by cast to type `{}`", self.ty_to_string(target))); } - ObligationCauseCode::RepeatVec(suggest_const_in_array_repeat_expression) => { + ObligationCauseCode::RepeatVec(suggest_const_in_array_repeat_expressions) => { err.note("the `Copy` trait is required because the \ repeated element will be copied"); - if suggest_const_in_array_repeat_expression { + if suggest_const_in_array_repeat_expressions { err.note("this array initializer can be evaluated at compile-time, for more \ information, see issue \ https://github.com/rust-lang/rust/issues/49147"); if tcx.sess.opts.unstable_features.is_nightly_build() { - err.help("add `#![feature(const_in_array_repeat_expression)]` to the \ + err.help("add `#![feature(const_in_array_repeat_expressions)]` to the \ crate attributes to enable"); } } diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index a29d8c66d81..e052ba44781 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -206,7 +206,7 @@ pub enum ObligationCauseCode<'tcx> { SizedReturnType, /// Yield type must be Sized SizedYieldType, - /// [T,..n] --> T must be Copy. If `true`, suggest `const_in_array_repeat_expression` feature + /// [T,..n] --> T must be Copy. If `true`, suggest `const_in_array_repeat_expressions` feature /// flag. RepeatVec(bool), diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 5e6d5ce159d..ffefe51f854 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -1,6 +1,11 @@ // Error messages for EXXXX errors. Each message should start and end with a // new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and // use `gq` to wrap paragraphs. Use `:set tw=0` to disable. +// +// /!\ IMPORTANT /!\ +// +// Error messages' format must follow the RFC 1567 available here: +// https://github.com/rust-lang/rfcs/pull/1567 crate::register_diagnostics! { diff --git a/src/librustc_error_codes/error_codes/E0023.md b/src/librustc_error_codes/error_codes/E0023.md index 92cae460c81..23a9d22a60d 100644 --- a/src/librustc_error_codes/error_codes/E0023.md +++ b/src/librustc_error_codes/error_codes/E0023.md @@ -1,6 +1,6 @@ -A pattern used to match against an enum variant must provide a sub-pattern for -each field of the enum variant. This error indicates that a pattern attempted to -extract an incorrect number of fields from a variant. +A pattern attempted to extract an incorrect number of fields from a variant. + +Erroneous code example: ``` enum Fruit { @@ -9,6 +9,9 @@ enum Fruit { } ``` +A pattern used to match against an enum variant must provide a sub-pattern for +each field of the enum variant. + Here the `Apple` variant has two fields, and should be matched against like so: ``` diff --git a/src/librustc_error_codes/error_codes/E0025.md b/src/librustc_error_codes/error_codes/E0025.md index 51073babd01..a85dc8c1978 100644 --- a/src/librustc_error_codes/error_codes/E0025.md +++ b/src/librustc_error_codes/error_codes/E0025.md @@ -1,5 +1,6 @@ -Each field of a struct can only be bound once in a pattern. Erroneous code -example: +Each field of a struct can only be bound once in a pattern. + +Erroneous code example: ```compile_fail,E0025 struct Foo { diff --git a/src/librustc_error_codes/error_codes/E0026.md b/src/librustc_error_codes/error_codes/E0026.md index 9327b31ac4b..72c575aabb6 100644 --- a/src/librustc_error_codes/error_codes/E0026.md +++ b/src/librustc_error_codes/error_codes/E0026.md @@ -1,51 +1,34 @@ -This error indicates that a struct pattern attempted to extract a non-existent -field from a struct. Struct fields are identified by the name used before the -colon `:` so struct patterns should resemble the declaration of the struct type -being matched. +A struct pattern attempted to extract a non-existent field from a struct. -``` -// Correct matching. -struct Thing { - x: u32, - y: u32 -} - -let thing = Thing { x: 1, y: 2 }; - -match thing { - Thing { x: xfield, y: yfield } => {} -} -``` - -If you are using shorthand field patterns but want to refer to the struct field -by a different name, you should rename it explicitly. - -Change this: +Erroneous code example: ```compile_fail,E0026 struct Thing { x: u32, - y: u32 + y: u32, } let thing = Thing { x: 0, y: 0 }; match thing { - Thing { x, z } => {} + Thing { x, z } => {} // error: `Thing::z` field doesn't exist } ``` -To this: +If you are using shorthand field patterns but want to refer to the struct field +by a different name, you should rename it explicitly. Struct fields are +identified by the name used before the colon `:` so struct patterns should +resemble the declaration of the struct type being matched. ``` struct Thing { x: u32, - y: u32 + y: u32, } let thing = Thing { x: 0, y: 0 }; match thing { - Thing { x, y: z } => {} + Thing { x, y: z } => {} // we renamed `y` to `z` } ``` diff --git a/src/librustc_error_codes/error_codes/E0027.md b/src/librustc_error_codes/error_codes/E0027.md index ab2a20fe9e5..a8b1340ca0c 100644 --- a/src/librustc_error_codes/error_codes/E0027.md +++ b/src/librustc_error_codes/error_codes/E0027.md @@ -1,8 +1,7 @@ -This error indicates that a pattern for a struct fails to specify a sub-pattern -for every one of the struct's fields. Ensure that each field from the struct's -definition is mentioned in the pattern, or use `..` to ignore unwanted fields. +A pattern for a struct fails to specify a sub-pattern for every one of the +struct's fields. -For example: +Erroneous code example: ```compile_fail,E0027 struct Dog { @@ -18,7 +17,8 @@ match d { } ``` -This is correct (explicit): +To fix this error, ensure that each field from the struct's definition is +mentioned in the pattern, or use `..` to ignore unwanted fields. Example: ``` struct Dog { diff --git a/src/librustc_error_codes/error_codes/E0029.md b/src/librustc_error_codes/error_codes/E0029.md index fadfda0a80c..d12d85b9b4c 100644 --- a/src/librustc_error_codes/error_codes/E0029.md +++ b/src/librustc_error_codes/error_codes/E0029.md @@ -1,8 +1,6 @@ -In a match expression, only numbers and characters can be matched against a -range. This is because the compiler checks that the range is non-empty at -compile-time, and is unable to evaluate arbitrary comparison functions. If you -want to capture values of an orderable type between two end-points, you can use -a guard. +Something other than numbers and characters has been used for a range. + +Erroneous code example: ```compile_fail,E0029 let string = "salutations !"; @@ -20,3 +18,9 @@ match string { _ => {} } ``` + +In a match expression, only numbers and characters can be matched against a +range. This is because the compiler checks that the range is non-empty at +compile-time, and is unable to evaluate arbitrary comparison functions. If you +want to capture values of an orderable type between two end-points, you can use +a guard. diff --git a/src/librustc_error_codes/error_codes/E0033.md b/src/librustc_error_codes/error_codes/E0033.md index 0bb70e89f3d..c49cedf2d58 100644 --- a/src/librustc_error_codes/error_codes/E0033.md +++ b/src/librustc_error_codes/error_codes/E0033.md @@ -1,8 +1,6 @@ -This error indicates that a pointer to a trait type cannot be implicitly -dereferenced by a pattern. Every trait defines a type, but because the -size of trait implementers isn't fixed, this type has no compile-time size. -Therefore, all accesses to trait types must be through pointers. If you -encounter this error you should try to avoid dereferencing the pointer. +A trait type has been dereferenced. + +Erroneous code example: ```compile_fail,E0033 # trait SomeTrait { fn method_one(&self){} fn method_two(&self){} } @@ -17,7 +15,13 @@ trait_obj.method_one(); trait_obj.method_two(); ``` +A pointer to a trait type cannot be implicitly dereferenced by a pattern. Every +trait defines a type, but because the size of trait implementers isn't fixed, +this type has no compile-time size. Therefore, all accesses to trait types must +be through pointers. If you encounter this error you should try to avoid +dereferencing the pointer. + You can read more about trait objects in the [Trait Objects] section of the Reference. -[Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects +[Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects \ No newline at end of file diff --git a/src/librustc_error_codes/error_codes/E0034.md b/src/librustc_error_codes/error_codes/E0034.md index bc804b7faef..2a21f3441c6 100644 --- a/src/librustc_error_codes/error_codes/E0034.md +++ b/src/librustc_error_codes/error_codes/E0034.md @@ -1,5 +1,7 @@ The compiler doesn't know what method to call because more than one method -has the same prototype. Erroneous code example: +has the same prototype. + +Erroneous code example: ```compile_fail,E0034 struct Test; diff --git a/src/librustc_error_codes/error_codes/E0040.md b/src/librustc_error_codes/error_codes/E0040.md index fb262018c35..1373f8340d8 100644 --- a/src/librustc_error_codes/error_codes/E0040.md +++ b/src/librustc_error_codes/error_codes/E0040.md @@ -1,8 +1,6 @@ -It is not allowed to manually call destructors in Rust. It is also not -necessary to do this since `drop` is called automatically whenever a value goes -out of scope. +It is not allowed to manually call destructors in Rust. -Here's an example of this error: +Erroneous code example: ```compile_fail,E0040 struct Foo { @@ -20,3 +18,22 @@ fn main() { x.drop(); // error: explicit use of destructor method } ``` + +It is unnecessary to do this since `drop` is called automatically whenever a +value goes out of scope. However, if you really need to drop a value by hand, +you can use the `std::mem::drop` function: + +``` +struct Foo { + x: i32, +} +impl Drop for Foo { + fn drop(&mut self) { + println!("kaboom"); + } +} +fn main() { + let mut x = Foo { x: -7 }; + drop(x); // ok! +} +``` diff --git a/src/librustc_error_codes/error_codes/E0044.md b/src/librustc_error_codes/error_codes/E0044.md index 8e877e71859..635ff953290 100644 --- a/src/librustc_error_codes/error_codes/E0044.md +++ b/src/librustc_error_codes/error_codes/E0044.md @@ -1,4 +1,5 @@ You cannot use type or const parameters on foreign items. + Example of erroneous code: ```compile_fail,E0044 diff --git a/src/librustc_error_codes/error_codes/E0045.md b/src/librustc_error_codes/error_codes/E0045.md index 537490eb4cf..143c693bf7c 100644 --- a/src/librustc_error_codes/error_codes/E0045.md +++ b/src/librustc_error_codes/error_codes/E0045.md @@ -1,18 +1,18 @@ -Rust only supports variadic parameters for interoperability with C code in its -FFI. As such, variadic parameters can only be used with functions which are -using the C ABI. Examples of erroneous code: +Variadic parameters have been used on a non-C ABI function. -```compile_fail +Erroneous code example: + +```compile_fail,E0045 #![feature(unboxed_closures)] -extern "rust-call" { fn foo(x: u8, ...); } - -// or - -fn foo(x: u8, ...) {} +extern "rust-call" { + fn foo(x: u8, ...); // error! +} ``` -To fix such code, put them in an extern "C" block: +Rust only supports variadic parameters for interoperability with C code in its +FFI. As such, variadic parameters can only be used with functions which are +using the C ABI. To fix such code, put them in an extern "C" block: ``` extern "C" { diff --git a/src/librustc_error_codes/error_codes/E0046.md b/src/librustc_error_codes/error_codes/E0046.md index 2d0bb0863e8..d8f95330c36 100644 --- a/src/librustc_error_codes/error_codes/E0046.md +++ b/src/librustc_error_codes/error_codes/E0046.md @@ -1,4 +1,6 @@ -Items are missing in a trait implementation. Erroneous code example: +Items are missing in a trait implementation. + +Erroneous code example: ```compile_fail,E0046 trait Foo { diff --git a/src/librustc_error_codes/error_codes/E0049.md b/src/librustc_error_codes/error_codes/E0049.md index 721a7fd57a5..a2034a3428b 100644 --- a/src/librustc_error_codes/error_codes/E0049.md +++ b/src/librustc_error_codes/error_codes/E0049.md @@ -1,8 +1,7 @@ -This error indicates that an attempted implementation of a trait method -has the wrong number of type or const parameters. +An attempted implementation of a trait method has the wrong number of type or +const parameters. -For example, the trait below has a method `foo` with a type parameter `T`, -but the implementation of `foo` for the type `Bar` is missing this parameter: +Erroneous code example: ```compile_fail,E0049 trait Foo { @@ -17,3 +16,21 @@ impl Foo for Bar { fn foo(x: bool) -> Self { Bar } } ``` + +For example, the `Foo` trait has a method `foo` with a type parameter `T`, +but the implementation of `foo` for the type `Bar` is missing this parameter. +To fix this error, they must have the same type parameters: + +``` +trait Foo { + fn foo(x: T) -> Self; +} + +struct Bar; + +impl Foo for Bar { + fn foo(x: T) -> Self { // ok! + Bar + } +} +``` diff --git a/src/librustc_error_codes/error_codes/E0050.md b/src/librustc_error_codes/error_codes/E0050.md index 79d070802d3..7b84c480073 100644 --- a/src/librustc_error_codes/error_codes/E0050.md +++ b/src/librustc_error_codes/error_codes/E0050.md @@ -1,9 +1,7 @@ -This error indicates that an attempted implementation of a trait method -has the wrong number of function parameters. +An attempted implementation of a trait method has the wrong number of function +parameters. -For example, the trait below has a method `foo` with two function parameters -(`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits -the `u8` parameter: +Erroneous code example: ```compile_fail,E0050 trait Foo { @@ -18,3 +16,21 @@ impl Foo for Bar { fn foo(&self) -> bool { true } } ``` + +For example, the `Foo` trait has a method `foo` with two function parameters +(`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits +the `u8` parameter. To fix this error, they must have the same parameters: + +``` +trait Foo { + fn foo(&self, x: u8) -> bool; +} + +struct Bar; + +impl Foo for Bar { + fn foo(&self, x: u8) -> bool { // ok! + true + } +} +``` diff --git a/src/librustc_error_codes/error_codes/E0053.md b/src/librustc_error_codes/error_codes/E0053.md index 822d1f0094d..cb2a8638a29 100644 --- a/src/librustc_error_codes/error_codes/E0053.md +++ b/src/librustc_error_codes/error_codes/E0053.md @@ -1,7 +1,7 @@ The parameters of any trait method must match between a trait implementation and the trait definition. -Here are a couple examples of this error: +Erroneous code example: ```compile_fail,E0053 trait Foo { diff --git a/src/librustc_error_codes/error_codes/E0054.md b/src/librustc_error_codes/error_codes/E0054.md index af71cb44462..c3eb375fbcc 100644 --- a/src/librustc_error_codes/error_codes/E0054.md +++ b/src/librustc_error_codes/error_codes/E0054.md @@ -1,5 +1,6 @@ -It is not allowed to cast to a bool. If you are trying to cast a numeric type -to a bool, you can compare it with zero instead: +It is not allowed to cast to a bool. + +Erroneous code example: ```compile_fail,E0054 let x = 5; @@ -8,6 +9,9 @@ let x = 5; let x_is_nonzero = x as bool; ``` +If you are trying to cast a numeric type to a bool, you can compare it with +zero instead: + ``` let x = 5; diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 6e9e8abbeff..9f20a24a183 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1987,7 +1987,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let span = body.source_info(location).span; let ty = operand.ty(body, tcx); if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) { - // To determine if `const_in_array_repeat_expression` feature gate should + // To determine if `const_in_array_repeat_expressions` feature gate should // be mentioned, need to check if the rvalue is promotable. let should_suggest = should_suggest_const_in_array_repeat_expressions_attribute( diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index a7f48162f9b..b4da437279d 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -1185,7 +1185,7 @@ pub fn promote_candidates<'tcx>( promotions } -/// This function returns `true` if the `const_in_array_repeat_expression` feature attribute should +/// This function returns `true` if the `const_in_array_repeat_expressions` feature attribute should /// be suggested. This function is probably quite expensive, it shouldn't be run in the happy path. /// Feature attribute should be suggested if `operand` can be promoted and the feature is not /// enabled. diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index cb496f2ecbe..73099169879 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -7,7 +7,7 @@ use syntax::ast::{self, Abi, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyl use syntax::ast::{ItemKind, ImplItem, ImplItemKind, TraitItem, TraitItemKind, UseTree, UseTreeKind}; use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness}; use syntax::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind}; -use syntax::ast::{Ty, TyKind, Generics, GenericBounds, TraitRef, EnumDef, VariantData, StructField}; +use syntax::ast::{Ty, TyKind, Generics, TraitRef, EnumDef, VariantData, StructField}; use syntax::ast::{Mac, MacDelimiter, Block, BindingMode, FnDecl, FnSig, SelfKind, Param}; use syntax::ptr::P; use syntax::ThinVec; @@ -24,15 +24,6 @@ use log::debug; use std::mem; use errors::{PResult, Applicability, DiagnosticBuilder, StashKey}; -/// Whether the type alias or associated type is a concrete type or an opaque type. -#[derive(Debug)] -pub(super) enum AliasKind { - /// Just a new name for the same type. - Weak(P), - /// Only trait impls of the type will be usable, not the actual type itself. - OpaqueTy(GenericBounds), -} - pub(super) type ItemInfo = (Ident, ItemKind, Option>); impl<'a> Parser<'a> { @@ -269,15 +260,11 @@ impl<'a> Parser<'a> { return self.mk_item_with_info(attrs, lo, vis, info); } - if let Some(type_) = self.eat_type() { - let (ident, alias, generics) = type_?; + if self.eat_keyword(kw::Type) { // TYPE ITEM - let item_ = match alias { - AliasKind::Weak(ty) => ItemKind::TyAlias(ty, generics), - AliasKind::OpaqueTy(bounds) => ItemKind::OpaqueTy(bounds, generics), - }; - let span = lo.to(self.prev_span); - return Ok(Some(self.mk_item(span, ident, item_, vis, attrs))); + let (ident, ty, generics) = self.parse_type_alias()?; + let kind = ItemKind::TyAlias(ty, generics); + return self.mk_item_with_info(attrs, lo, vis, (ident, kind, None)); } if self.eat_keyword(kw::Enum) { @@ -711,13 +698,9 @@ impl<'a> Parser<'a> { let lo = self.token.span; let vis = self.parse_visibility(false)?; let defaultness = self.parse_defaultness(); - let (name, kind, generics) = if let Some(type_) = self.eat_type() { - let (name, alias, generics) = type_?; - let kind = match alias { - AliasKind::Weak(typ) => ast::ImplItemKind::TyAlias(typ), - AliasKind::OpaqueTy(bounds) => ast::ImplItemKind::OpaqueTy(bounds), - }; - (name, kind, generics) + let (name, kind, generics) = if self.eat_keyword(kw::Type) { + let (name, ty, generics) = self.parse_type_alias()?; + (name, ast::ImplItemKind::TyAlias(ty), generics) } else if self.is_const_item() { self.parse_impl_const()? } else if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(&vis), at_end)? { @@ -1322,34 +1305,16 @@ impl<'a> Parser<'a> { }) } - /// Parses `type Foo = Bar;` or returns `None` - /// without modifying the parser state. - fn eat_type(&mut self) -> Option> { - // This parses the grammar: - // Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";" - if self.eat_keyword(kw::Type) { - Some(self.parse_type_alias()) - } else { - None - } - } - - /// Parses a type alias or opaque type. - fn parse_type_alias(&mut self) -> PResult<'a, (Ident, AliasKind, Generics)> { + /// Parses the grammar: + /// Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";" + fn parse_type_alias(&mut self) -> PResult<'a, (Ident, P, Generics)> { let ident = self.parse_ident()?; let mut tps = self.parse_generics()?; tps.where_clause = self.parse_where_clause()?; self.expect(&token::Eq)?; - let alias = if self.check_keyword(kw::Impl) { - self.bump(); - let bounds = self.parse_generic_bounds(Some(self.prev_span))?; - AliasKind::OpaqueTy(bounds) - } else { - let ty = self.parse_ty()?; - AliasKind::Weak(ty) - }; + let ty = self.parse_ty()?; self.expect_semi()?; - Ok((ident, alias, tps)) + Ok((ident, ty, tps)) } /// Parses an enum declaration. diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index c48d2c61e65..edb91d5bf18 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -20,7 +20,7 @@ use syntax::source_map::Spanned; use syntax::symbol::{kw, sym}; use syntax::visit::{self, Visitor}; use syntax::{span_err, struct_span_err, walk_list}; -use syntax_pos::{Span, MultiSpan}; +use syntax_pos::Span; use errors::{Applicability, FatalError}; use rustc_error_codes::*; @@ -586,14 +586,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> { "unions cannot have zero fields"); } } - ItemKind::OpaqueTy(ref bounds, _) => { - if !bounds.iter() - .any(|b| if let GenericBound::Trait(..) = *b { true } else { false }) { - let msp = MultiSpan::from_spans(bounds.iter() - .map(|bound| bound.span()).collect()); - self.err_handler().span_err(msp, "at least one trait must be specified"); - } - } _ => {} } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index fa7c2cdda68..fd401fde204 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -701,13 +701,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { } // These items live in the type namespace. - ItemKind::TyAlias(..) => { - let res = Res::Def(DefKind::TyAlias, self.r.definitions.local_def_id(item.id)); - self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); - } - - ItemKind::OpaqueTy(_, _) => { - let res = Res::Def(DefKind::OpaqueTy, self.r.definitions.local_def_id(item.id)); + ItemKind::TyAlias(ref ty, _) => { + let def_kind = match ty.kind.opaque_top_hack() { + None => DefKind::TyAlias, + Some(_) => DefKind::OpaqueTy, + }; + let res = Res::Def(def_kind, self.r.definitions.local_def_id(item.id)); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); } diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 6b068387974..8d11c7224c7 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -732,7 +732,6 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { match item.kind { ItemKind::TyAlias(_, ref generics) | - ItemKind::OpaqueTy(_, ref generics) | ItemKind::Fn(_, ref generics, _) => { self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| visit::walk_item(this, item)); @@ -1087,18 +1086,6 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { this.visit_ty(ty); } - ImplItemKind::OpaqueTy(ref bounds) => { - // If this is a trait impl, ensure the type - // exists in trait - this.check_trait_item(impl_item.ident, - TypeNS, - impl_item.span, - |n, s| TypeNotMemberOfTrait(n, s)); - - for bound in bounds { - this.visit_param_bound(bound); - } - } ImplItemKind::Macro(_) => panic!("unexpanded macro in resolve!"), } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 92c391fb4a3..5bec5b5eb6b 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1133,12 +1133,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> { // trait. self.visit_ty(ty) } - ast::ImplItemKind::OpaqueTy(ref bounds) => { - // FIXME: uses of the assoc type should ideally point to this - // 'def' and the name here should be a ref to the def in the - // trait. - self.process_bounds(&bounds); - } ast::ImplItemKind::Macro(_) => {} } } @@ -1384,38 +1378,6 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> { self.visit_ty(&ty); self.process_generic_params(ty_params, &qualname, item.id); } - OpaqueTy(ref bounds, ref ty_params) => { - let qualname = format!("::{}", - self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))); - - let value = String::new(); - if !self.span.filter_generated(item.ident.span) { - let span = self.span_from_span(item.ident.span); - let id = id_from_node_id(item.id, &self.save_ctxt); - let hir_id = self.tcx.hir().node_to_hir_id(item.id); - - self.dumper.dump_def( - &access_from!(self.save_ctxt, item, hir_id), - Def { - kind: DefKind::Type, - id, - span, - name: item.ident.to_string(), - qualname: qualname.clone(), - value, - parent: None, - children: vec![], - decl_id: None, - docs: self.save_ctxt.docs_for_attrs(&item.attrs), - sig: sig::item_signature(item, &self.save_ctxt), - attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt), - }, - ); - } - - self.process_bounds(bounds); - self.process_generic_params(ty_params, &qualname, item.id); - } Mac(_) => (), _ => visit::walk_item(self, item), } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index d1b9b8ff44d..50dfac62024 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -447,16 +447,6 @@ impl Sig for ast::Item { Ok(merge_sigs(sig.text.clone(), vec![sig, ty])) } - ast::ItemKind::OpaqueTy(ref bounds, ref generics) => { - let text = "type ".to_owned(); - let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?; - - sig.text.push_str(" = impl "); - sig.text.push_str(&pprust::bounds_to_string(bounds)); - sig.text.push(';'); - - Ok(sig) - } ast::ItemKind::Enum(_, ref generics) => { let text = "enum ".to_owned(); let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 13bf6752ba2..d358efbe543 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1579,7 +1579,6 @@ pub enum ImplItemKind { Const(P, P), Method(FnSig, P), TyAlias(P), - OpaqueTy(GenericBounds), Macro(Mac), } @@ -1816,6 +1815,15 @@ impl TyKind { false } } + + /// HACK(type_alias_impl_trait, Centril): A temporary crutch used + /// in lowering to avoid making larger changes there and beyond. + pub fn opaque_top_hack(&self) -> Option<&GenericBounds> { + match self { + Self::ImplTrait(_, bounds) => Some(bounds), + _ => None, + } + } } /// Syntax used to declare a trait object. @@ -2483,10 +2491,6 @@ pub enum ItemKind { /// /// E.g., `type Foo = Bar;`. TyAlias(P, Generics), - /// An opaque `impl Trait` type alias. - /// - /// E.g., `type Foo = impl Bar + Boo;`. - OpaqueTy(GenericBounds, Generics), /// An enum definition (`enum`). /// /// E.g., `enum Foo { C, D }`. @@ -2540,7 +2544,6 @@ impl ItemKind { ItemKind::ForeignMod(..) => "foreign module", ItemKind::GlobalAsm(..) => "global asm", ItemKind::TyAlias(..) => "type alias", - ItemKind::OpaqueTy(..) => "opaque type", ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index d95dac9bf52..bd836eee42a 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -321,6 +321,27 @@ impl<'a> PostExpansionVisitor<'a> { ); } } + + /// Feature gate `impl Trait` inside `type Alias = $type_expr;`. + fn check_impl_trait(&self, ty: &ast::Ty) { + struct ImplTraitVisitor<'a> { + vis: &'a PostExpansionVisitor<'a>, + } + impl Visitor<'_> for ImplTraitVisitor<'_> { + fn visit_ty(&mut self, ty: &ast::Ty) { + if let ast::TyKind::ImplTrait(..) = ty.kind { + gate_feature_post!( + &self.vis, + type_alias_impl_trait, + ty.span, + "`impl Trait` in type aliases is unstable" + ); + } + visit::walk_ty(self, ty); + } + } + ImplTraitVisitor { vis: self }.visit_ty(ty); + } } impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { @@ -455,14 +476,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { gate_feature_post!(&self, decl_macro, i.span, msg); } - ast::ItemKind::OpaqueTy(..) => { - gate_feature_post!( - &self, - type_alias_impl_trait, - i.span, - "`impl Trait` in type aliases is unstable" - ); - } + ast::ItemKind::TyAlias(ref ty, ..) => self.check_impl_trait(&ty), _ => {} } @@ -636,9 +650,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } ast::TraitItemKind::Type(_, ref default) => { - // We use three if statements instead of something like match guards so that all - // of these errors can be emitted if all cases apply. - if default.is_some() { + if let Some(ty) = default { + self.check_impl_trait(ty); gate_feature_post!(&self, associated_type_defaults, ti.span, "associated type defaults are unstable"); } @@ -663,15 +676,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "C-variadic functions are unstable"); } } - ast::ImplItemKind::OpaqueTy(..) => { - gate_feature_post!( - &self, - type_alias_impl_trait, - ii.span, - "`impl Trait` in type aliases is unstable" - ); - } - ast::ImplItemKind::TyAlias(_) => { + ast::ImplItemKind::TyAlias(ref ty) => { + self.check_impl_trait(ty); self.check_gat(&ii.generics, ii.span); } _ => {} diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 376323a83ea..f4ef993edb9 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -887,10 +887,6 @@ pub fn noop_visit_item_kind(kind: &mut ItemKind, vis: &mut T) { vis.visit_ty(ty); vis.visit_generics(generics); } - ItemKind::OpaqueTy(bounds, generics) => { - visit_bounds(bounds, vis); - vis.visit_generics(generics); - } ItemKind::Enum(EnumDef { variants }, generics) => { variants.flat_map_in_place(|variant| vis.flat_map_variant(variant)); vis.visit_generics(generics); @@ -970,7 +966,6 @@ pub fn noop_flat_map_impl_item(mut item: ImplItem, visitor: &mut visitor.visit_block(body); } ImplItemKind::TyAlias(ty) => visitor.visit_ty(ty), - ImplItemKind::OpaqueTy(bounds) => visit_bounds(bounds, visitor), ImplItemKind::Macro(mac) => visitor.visit_mac(mac), } visitor.visit_span(span); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f154b7bde98..ef65a744e83 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1255,19 +1255,6 @@ impl<'a> State<'a> { self.s.word(";"); self.end(); // end the outer ibox } - ast::ItemKind::OpaqueTy(ref bounds, ref generics) => { - self.head(visibility_qualified(&item.vis, "type")); - self.print_ident(item.ident); - self.word_space("= impl"); - self.print_generic_params(&generics.params); - self.end(); // end the inner ibox - - self.print_where_clause(&generics.where_clause); - self.s.space(); - self.print_type_bounds(":", bounds); - self.s.word(";"); - self.end(); // end the outer ibox - } ast::ItemKind::Enum(ref enum_definition, ref params) => { self.print_enum_def( enum_definition, @@ -1620,13 +1607,6 @@ impl<'a> State<'a> { ast::ImplItemKind::TyAlias(ref ty) => { self.print_associated_type(ii.ident, None, Some(ty)); } - ast::ImplItemKind::OpaqueTy(ref bounds) => { - self.word_space("type"); - self.print_ident(ii.ident); - self.word_space("= impl"); - self.print_type_bounds(":", bounds); - self.s.word(";"); - } ast::ImplItemKind::Macro(ref mac) => { self.print_mac(mac); match mac.delim { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ea2dc357e6e..2597ffd750d 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -263,10 +263,6 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_ty(typ); visitor.visit_generics(generics) } - ItemKind::OpaqueTy(ref bounds, ref generics) => { - walk_list!(visitor, visit_param_bound, bounds); - visitor.visit_generics(generics) - } ItemKind::Enum(ref enum_definition, ref generics) => { visitor.visit_generics(generics); visitor.visit_enum_def(enum_definition, generics, item.id, item.span) @@ -628,9 +624,6 @@ pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplIt ImplItemKind::TyAlias(ref ty) => { visitor.visit_ty(ty); } - ImplItemKind::OpaqueTy(ref bounds) => { - walk_list!(visitor, visit_param_bound, bounds); - } ImplItemKind::Macro(ref mac) => { visitor.visit_mac(mac); } diff --git a/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr b/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr index cd9242de88f..08d9ada884a 100644 --- a/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr +++ b/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr @@ -8,7 +8,7 @@ LL | let arr: [Option; 2] = [None::; 2]; as std::marker::Copy> = note: the `Copy` trait is required because the repeated element will be copied = note: this array initializer can be evaluated at compile-time, for more information, see issue https://github.com/rust-lang/rust/issues/49147 - = help: add `#![feature(const_in_array_repeat_expression)]` to the crate attributes to enable + = help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable error[E0277]: the trait bound `std::option::Option: std::marker::Copy` is not satisfied --> $DIR/feature-gate-const_in_array_repeat_expressions.rs:14:36 diff --git a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs index 4a0c8c52c4e..6088331cded 100644 --- a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs +++ b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs @@ -1,15 +1,45 @@ -type Foo = impl std::fmt::Debug; //~ ERROR `impl Trait` in type aliases is unstable +use std::fmt::Debug; + +type Foo = impl Debug; //~ ERROR `impl Trait` in type aliases is unstable trait Bar { - type Baa: std::fmt::Debug; + type Baa: Debug; fn define() -> Self::Baa; } impl Bar for () { - type Baa = impl std::fmt::Debug; //~ ERROR `impl Trait` in type aliases is unstable + type Baa = impl Debug; //~ ERROR `impl Trait` in type aliases is unstable fn define() -> Self::Baa { 0 } } fn define() -> Foo { 0 } +trait TraitWithDefault { + type Assoc = impl Debug; + //~^ ERROR associated type defaults are unstable + //~| ERROR `impl Trait` not allowed outside of function + //~| ERROR `impl Trait` in type aliases is unstable +} + +type NestedFree = (Vec, impl Debug, impl Iterator); +//~^ ERROR `impl Trait` in type aliases is unstable +//~| ERROR `impl Trait` in type aliases is unstable +//~| ERROR `impl Trait` in type aliases is unstable +//~| ERROR `impl Trait` in type aliases is unstable +//~| ERROR `impl Trait` not allowed outside of function +//~| ERROR `impl Trait` not allowed outside of function +//~| ERROR `impl Trait` not allowed outside of function + +impl Bar for u8 { + type Baa = (Vec, impl Debug, impl Iterator); + //~^ ERROR `impl Trait` in type aliases is unstable + //~| ERROR `impl Trait` in type aliases is unstable + //~| ERROR `impl Trait` in type aliases is unstable + //~| ERROR `impl Trait` in type aliases is unstable + //~| ERROR `impl Trait` not allowed outside of function + //~| ERROR `impl Trait` not allowed outside of function + //~| ERROR `impl Trait` not allowed outside of function + fn define() -> Self::Baa { (vec![true], 0u8, 0i32..1) } +} + fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr index 2d0710ea37c..d9ebcdecb9b 100644 --- a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr +++ b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr @@ -1,21 +1,154 @@ error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/feature-gate-type_alias_impl_trait.rs:1:1 + --> $DIR/feature-gate-type_alias_impl_trait.rs:3:12 | -LL | type Foo = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type Foo = impl Debug; + | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/63063 = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/feature-gate-type_alias_impl_trait.rs:9:5 + --> $DIR/feature-gate-type_alias_impl_trait.rs:11:16 | -LL | type Baa = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type Baa = impl Debug; + | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/63063 = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable -error: aborting due to 2 previous errors +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:18:18 + | +LL | type Assoc = impl Debug; + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable -For more information about this error, try `rustc --explain E0658`. +error[E0658]: associated type defaults are unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:18:5 + | +LL | type Assoc = impl Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29661 + = help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:24:24 + | +LL | type NestedFree = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:24:37 + | +LL | type NestedFree = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:24:49 + | +LL | type NestedFree = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:24:70 + | +LL | type NestedFree = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:34:21 + | +LL | type Baa = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:34:34 + | +LL | type Baa = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:34:46 + | +LL | type Baa = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:34:67 + | +LL | type Baa = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types + --> $DIR/feature-gate-type_alias_impl_trait.rs:18:18 + | +LL | type Assoc = impl Debug; + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types + --> $DIR/feature-gate-type_alias_impl_trait.rs:24:24 + | +LL | type NestedFree = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types + --> $DIR/feature-gate-type_alias_impl_trait.rs:24:37 + | +LL | type NestedFree = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types + --> $DIR/feature-gate-type_alias_impl_trait.rs:24:49 + | +LL | type NestedFree = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types + --> $DIR/feature-gate-type_alias_impl_trait.rs:34:21 + | +LL | type Baa = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types + --> $DIR/feature-gate-type_alias_impl_trait.rs:34:34 + | +LL | type Baa = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types + --> $DIR/feature-gate-type_alias_impl_trait.rs:34:46 + | +LL | type Baa = (Vec, impl Debug, impl Iterator); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 19 previous errors + +Some errors have detailed explanations: E0562, E0658. +For more information about an error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/where-allowed.rs b/src/test/ui/impl-trait/where-allowed.rs index 65c4b78bf6a..5ab74e02e0e 100644 --- a/src/test/ui/impl-trait/where-allowed.rs +++ b/src/test/ui/impl-trait/where-allowed.rs @@ -163,6 +163,7 @@ type InTypeAlias = impl Debug; type InReturnInTypeAlias = fn() -> impl Debug; //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~| ERROR `impl Trait` in type aliases is unstable // Disallowed in impl headers impl PartialEq for () { diff --git a/src/test/ui/impl-trait/where-allowed.stderr b/src/test/ui/impl-trait/where-allowed.stderr index b01095f15a9..fcd4c357afd 100644 --- a/src/test/ui/impl-trait/where-allowed.stderr +++ b/src/test/ui/impl-trait/where-allowed.stderr @@ -17,19 +17,28 @@ LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic | outer `impl Trait` error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/where-allowed.rs:124:5 + --> $DIR/where-allowed.rs:124:16 | LL | type Out = impl Debug; - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/63063 = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/where-allowed.rs:160:1 + --> $DIR/where-allowed.rs:160:23 | LL | type InTypeAlias = impl Debug; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/where-allowed.rs:164:39 + | +LL | type InReturnInTypeAlias = fn() -> impl Debug; + | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/63063 = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable @@ -179,61 +188,61 @@ LL | type InReturnInTypeAlias = fn() -> impl Debug; | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:168:16 + --> $DIR/where-allowed.rs:169:16 | LL | impl PartialEq for () { | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:173:24 + --> $DIR/where-allowed.rs:174:24 | LL | impl PartialEq<()> for impl Debug { | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:178:6 + --> $DIR/where-allowed.rs:179:6 | LL | impl impl Debug { | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:184:24 + --> $DIR/where-allowed.rs:185:24 | LL | impl InInherentImplAdt { | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:190:11 + --> $DIR/where-allowed.rs:191:11 | LL | where impl Debug: Debug | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:197:15 + --> $DIR/where-allowed.rs:198:15 | LL | where Vec: Debug | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:204:24 + --> $DIR/where-allowed.rs:205:24 | LL | where T: PartialEq | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:211:17 + --> $DIR/where-allowed.rs:212:17 | LL | where T: Fn(impl Debug) | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:218:22 + --> $DIR/where-allowed.rs:219:22 | LL | where T: Fn() -> impl Debug | ^^^^^^^^^^ error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:224:29 + --> $DIR/where-allowed.rs:225:29 | LL | let _in_local_variable: impl Fn() = || {}; | ^^^^^^^^^ @@ -241,7 +250,7 @@ LL | let _in_local_variable: impl Fn() = || {}; = help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable error[E0562]: `impl Trait` not allowed outside of function and inherent method return types - --> $DIR/where-allowed.rs:226:46 + --> $DIR/where-allowed.rs:227:46 | LL | let _in_return_in_local_variable = || -> impl Fn() { || {} }; | ^^^^^^^^^ @@ -270,7 +279,7 @@ error: could not find defining uses LL | type Out = impl Debug; | ^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 43 previous errors +error: aborting due to 44 previous errors Some errors have detailed explanations: E0282, E0562, E0658, E0666. For more information about an error, try `rustc --explain E0282`. diff --git a/src/test/ui/parser/issue-62524.rs b/src/test/ui/parser/issue-62524.rs new file mode 100644 index 00000000000..57de4b87b0f --- /dev/null +++ b/src/test/ui/parser/issue-62524.rs @@ -0,0 +1,4 @@ +// ignore-tidy-trailing-newlines +// error-pattern: aborting due to 3 previous errors +y![ +Ϥ, \ No newline at end of file diff --git a/src/test/ui/parser/issue-62524.stderr b/src/test/ui/parser/issue-62524.stderr new file mode 100644 index 00000000000..229768f4959 --- /dev/null +++ b/src/test/ui/parser/issue-62524.stderr @@ -0,0 +1,34 @@ +error: this file contains an un-closed delimiter + --> $DIR/issue-62524.rs:4:3 + | +LL | y![ + | - un-closed delimiter +LL | Ϥ, + | ^ + +error: macros that expand to items must be delimited with braces or followed by a semicolon + --> $DIR/issue-62524.rs:3:3 + | +LL | y![ + | ___^ +LL | | Ϥ, + | |__^ + | +help: change the delimiters to curly braces + | +LL | y!{ +LL | Ϥ} + | +help: add a semicolon + | +LL | Ϥ,; + | ^ + +error: cannot find macro `y` in this scope + --> $DIR/issue-62524.rs:3:1 + | +LL | y![ + | ^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr index d98d349be3c..c31d3912d97 100644 --- a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr @@ -1,8 +1,8 @@ error: at least one trait must be specified - --> $DIR/generic_nondefining_use.rs:5:20 + --> $DIR/generic_nondefining_use.rs:5:15 | LL | type Cmp = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error: defining opaque type use does not fully define opaque type --> $DIR/generic_nondefining_use.rs:11:1 diff --git a/src/test/ui/type-alias-impl-trait/generic_not_used.stderr b/src/test/ui/type-alias-impl-trait/generic_not_used.stderr index fe353f6e3d2..8015ff7eded 100644 --- a/src/test/ui/type-alias-impl-trait/generic_not_used.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_not_used.stderr @@ -1,8 +1,8 @@ error: at least one trait must be specified - --> $DIR/generic_not_used.rs:5:38 + --> $DIR/generic_not_used.rs:5:33 | LL | type WrongGeneric = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error: type parameter `V` is part of concrete type but not used in parameter list for the `impl Trait` type alias --> $DIR/generic_not_used.rs:8:73 diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr index 3f25d5fbd9c..b4ecf81ad88 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr @@ -1,8 +1,8 @@ error: at least one trait must be specified - --> $DIR/generic_type_does_not_live_long_enough.rs:9:29 + --> $DIR/generic_type_does_not_live_long_enough.rs:9:24 | LL | type WrongGeneric = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr index 12569211df3..d9600f1d1d6 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr @@ -1,8 +1,8 @@ error: at least one trait must be specified - --> $DIR/generic_type_does_not_live_long_enough.rs:9:29 + --> $DIR/generic_type_does_not_live_long_enough.rs:9:24 | LL | type WrongGeneric = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr b/src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr index 63c07224353..5f04391d753 100644 --- a/src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr @@ -1,8 +1,8 @@ error: at least one trait must be specified - --> $DIR/generic_underconstrained.rs:6:40 + --> $DIR/generic_underconstrained.rs:6:35 | LL | type Underconstrained = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error[E0277]: the trait bound `T: Trait` is not satisfied --> $DIR/generic_underconstrained.rs:6:1 diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr b/src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr index ba892f6ed7c..d4c7c7c7452 100644 --- a/src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr @@ -1,14 +1,14 @@ error: at least one trait must be specified - --> $DIR/generic_underconstrained2.rs:5:50 + --> $DIR/generic_underconstrained2.rs:5:45 | LL | type Underconstrained = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error: at least one trait must be specified - --> $DIR/generic_underconstrained2.rs:14:51 + --> $DIR/generic_underconstrained2.rs:14:46 | LL | type Underconstrained2 = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error[E0277]: `U` doesn't implement `std::fmt::Debug` --> $DIR/generic_underconstrained2.rs:5:1 diff --git a/src/test/ui/type-alias-impl-trait/issue-60371.stderr b/src/test/ui/type-alias-impl-trait/issue-60371.stderr index 1e9b12ebc39..cb35706a51e 100644 --- a/src/test/ui/type-alias-impl-trait/issue-60371.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-60371.stderr @@ -1,8 +1,8 @@ error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/issue-60371.rs:8:5 + --> $DIR/issue-60371.rs:8:17 | LL | type Item = impl Bug; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/63063 = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr index 58028bd0861..3f7acd33830 100644 --- a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr @@ -1,8 +1,8 @@ error: at least one trait must be specified - --> $DIR/type-alias-impl-trait-with-no-traits.rs:3:17 + --> $DIR/type-alias-impl-trait-with-no-traits.rs:3:12 | LL | type Foo = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error: at least one trait must be specified --> $DIR/type-alias-impl-trait-with-no-traits.rs:10:13 diff --git a/src/test/ui/type-alias-impl-trait/unused_generic_param.stderr b/src/test/ui/type-alias-impl-trait/unused_generic_param.stderr index 23105026964..9c63701ed33 100644 --- a/src/test/ui/type-alias-impl-trait/unused_generic_param.stderr +++ b/src/test/ui/type-alias-impl-trait/unused_generic_param.stderr @@ -1,14 +1,14 @@ error: at least one trait must be specified - --> $DIR/unused_generic_param.rs:6:33 + --> $DIR/unused_generic_param.rs:6:28 | LL | type PartiallyDefined = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error: at least one trait must be specified - --> $DIR/unused_generic_param.rs:13:34 + --> $DIR/unused_generic_param.rs:13:29 | LL | type PartiallyDefined2 = impl 'static; - | ^^^^^^^ + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors