From 523490e94ad6aabcc53a30919889ce60b4f327ee Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sat, 28 Aug 2021 07:37:30 +0000 Subject: Allow `~const` bounds on trait assoc functions --- .../tilde-const-invalid-places.stderr | 12 ++++---- .../trait-where-clause.rs | 33 ++++++++++++++++++++ .../trait-where-clause.stderr | 35 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr (limited to 'src') diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr index b026099f682..033ec21ba84 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr @@ -4,7 +4,7 @@ error: `~const` is not allowed here LL | fn rpit() -> impl ~const T { S } | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:11:17 @@ -12,7 +12,7 @@ error: `~const` is not allowed here LL | fn apit(_: impl ~const T) {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:14:50 @@ -20,7 +20,7 @@ error: `~const` is not allowed here LL | fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:17:48 @@ -28,7 +28,7 @@ error: `~const` is not allowed here LL | fn apit_assoc_bound(_: impl IntoIterator) {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:20:15 @@ -36,7 +36,7 @@ error: `~const` is not allowed here LL | fn generic() {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:23:31 @@ -44,7 +44,7 @@ error: `~const` is not allowed here LL | fn where_clause

() where P: ~const T {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions error: `~const` and `?` are mutually exclusive --> $DIR/tilde-const-invalid-places.rs:26:25 diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs new file mode 100644 index 00000000000..7fcd791e722 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs @@ -0,0 +1,33 @@ +#![feature(const_fn_trait_bound)] +#![feature(const_trait_impl)] + +trait Bar {} + +trait Foo { + fn a(); + fn b() where Self: ~const Bar; +} + +const fn test1() { + T::a(); + T::b(); + //~^ ERROR the trait bound +} + +const fn test2() { + T::a(); + T::b(); +} + +fn test3() { + T::a(); + T::b(); + //~^ ERROR the trait bound +} + +fn test4() { + T::a(); + T::b(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr new file mode 100644 index 00000000000..f70792ba55a --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -0,0 +1,35 @@ +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:13:5 + | +LL | T::b(); + | ^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::b` + --> $DIR/trait-where-clause.rs:8:5 + | +LL | fn b() where Self: ~const Bar; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | const fn test1() { + | +++++ + +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:24:5 + | +LL | T::b(); + | ^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::b` + --> $DIR/trait-where-clause.rs:8:5 + | +LL | fn b() where Self: ~const Bar; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | fn test3() { + | +++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From ee02c8e20a5098e77251bb07cca5fe9b932c84d7 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sat, 28 Aug 2021 15:53:26 +0000 Subject: Add test cases --- .../trait-where-clause-run.rs | 41 ++++++++++++++++++++++ .../trait-where-clause-self-referential.rs | 24 +++++++++++++ .../trait-where-clause.rs | 7 ++++ .../trait-where-clause.stderr | 38 ++++++++++++++++++-- 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs (limited to 'src') diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs new file mode 100644 index 00000000000..0cde5b6f842 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs @@ -0,0 +1,41 @@ +// run-pass + +#![feature(const_trait_impl)] +#![feature(const_fn_trait_bound)] + +trait Bar { + fn bar() -> u8; +} + +trait Foo { + #[default_method_body_is_const] + fn foo() -> u8 where Self: ~const Bar { + ::bar() * 6 + } +} + +struct NonConst; +struct Const; + +impl Bar for NonConst { + fn bar() -> u8 { + 3 + } +} + +impl Foo for NonConst {} + +impl const Bar for Const { + fn bar() -> u8 { + 4 + } +} + +impl const Foo for Const {} + +fn main() { + const ANS1: u8 = Const::foo(); + let ans2 = NonConst::foo(); + + assert_eq!(ANS1 + ans2, 42); +} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs new file mode 100644 index 00000000000..ae9ab26cdc0 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs @@ -0,0 +1,24 @@ +// check-pass + +#![feature(const_trait_impl)] +#![feature(const_fn_trait_bound)] + +trait Foo { + fn bar() where Self: ~const Foo; +} + +struct S; + +impl Foo for S { + fn bar() {} +} + +fn baz() { + T::bar(); +} + +const fn qux() { + T::bar(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs index 7fcd791e722..d64822d7ce8 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs @@ -6,28 +6,35 @@ trait Bar {} trait Foo { fn a(); fn b() where Self: ~const Bar; + fn c(); } const fn test1() { T::a(); T::b(); //~^ ERROR the trait bound + T::c::(); + //~^ ERROR the trait bound } const fn test2() { T::a(); T::b(); + T::c::(); } fn test3() { T::a(); T::b(); //~^ ERROR the trait bound + T::c::(); + //~^ ERROR the trait bound } fn test4() { T::a(); T::b(); + T::c::(); } fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr index f70792ba55a..fffb91f9870 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Bar` is not satisfied - --> $DIR/trait-where-clause.rs:13:5 + --> $DIR/trait-where-clause.rs:14:5 | LL | T::b(); | ^^^^ the trait `Bar` is not implemented for `T` @@ -15,7 +15,23 @@ LL | const fn test1() { | +++++ error[E0277]: the trait bound `T: Bar` is not satisfied - --> $DIR/trait-where-clause.rs:24:5 + --> $DIR/trait-where-clause.rs:16:5 + | +LL | T::c::(); + | ^^^^^^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::c` + --> $DIR/trait-where-clause.rs:9:5 + | +LL | fn c(); + | ^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | const fn test1() { + | +++++ + +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:28:5 | LL | T::b(); | ^^^^ the trait `Bar` is not implemented for `T` @@ -30,6 +46,22 @@ help: consider further restricting this bound LL | fn test3() { | +++++ -error: aborting due to 2 previous errors +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:30:5 + | +LL | T::c::(); + | ^^^^^^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::c` + --> $DIR/trait-where-clause.rs:9:5 + | +LL | fn c(); + | ^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | fn test3() { + | +++++ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From ed30993456224998db3a8f347a286f8234cd75c8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 Aug 2021 14:43:22 +0200 Subject: Use the correct type for Enum variant tuples --- src/librustdoc/clean/mod.rs | 26 +++++++++++++------- src/librustdoc/clean/types.rs | 3 ++- src/librustdoc/fold.rs | 4 ++++ src/librustdoc/html/render/print_item.rs | 41 +++++++++++++++++++------------- src/librustdoc/json/conversions.rs | 13 +++++++++- src/librustdoc/passes/stripper.rs | 4 ++-- 6 files changed, 62 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b6ff3890c58..5b4a1a3d849 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1703,12 +1703,28 @@ impl Clean for rustc_hir::VariantData<'_> { } } +impl Clean> for hir::VariantData<'_> { + fn clean(&self, cx: &mut DocContext<'_>) -> Vec { + self.fields().iter().map(|x| x.clean(cx)).collect() + } +} + impl Clean for ty::VariantDef { fn clean(&self, cx: &mut DocContext<'_>) -> Item { let kind = match self.ctor_kind { CtorKind::Const => Variant::CLike, CtorKind::Fn => Variant::Tuple( - self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(), + self.fields + .iter() + .map(|field| { + let name = Some(field.ident.name); + let kind = StructFieldItem(cx.tcx.type_of(field.did).clean(cx)); + let what_rustc_thinks = + Item::from_def_id_and_parts(field.did, name, kind, cx); + // don't show `pub` for fields, which are always public + Item { visibility: Visibility::Inherited, ..what_rustc_thinks } + }) + .collect(), ), CtorKind::Fictive => Variant::Struct(VariantStruct { struct_type: CtorKind::Fictive, @@ -1738,13 +1754,7 @@ impl Clean for hir::VariantData<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> Variant { match self { hir::VariantData::Struct(..) => Variant::Struct(self.clean(cx)), - // Important note here: `Variant::Tuple` is used on tuple structs which are not in an - // enum (so where converting from `ty::VariantDef`). In case we are in an enum, the kind - // is provided by the `Variant` wrapper directly, and since we need the fields' name - // (even for a tuple struct variant!), it's simpler to just store it as a - // `Variant::Struct` instead of a `Variant::Tuple` (otherwise it would force us to make - // a lot of changes when rendering them to generate the name as well). - hir::VariantData::Tuple(..) => Variant::Struct(self.clean(cx)), + hir::VariantData::Tuple(..) => Variant::Tuple(self.clean(cx)), hir::VariantData::Unit(..) => Variant::CLike, } } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 70255749143..4194c99c0ba 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -715,6 +715,7 @@ impl ItemKind { StructItem(s) => s.fields.iter(), UnionItem(u) => u.fields.iter(), VariantItem(Variant::Struct(v)) => v.fields.iter(), + VariantItem(Variant::Tuple(v)) => v.iter(), EnumItem(e) => e.variants.iter(), TraitItem(t) => t.items.iter(), ImplItem(i) => i.items.iter(), @@ -1937,7 +1938,7 @@ crate struct Enum { #[derive(Clone, Debug)] crate enum Variant { CLike, - Tuple(Vec), + Tuple(Vec), Struct(VariantStruct), } diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index 45aae71d2dc..b4859e4c9c7 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -56,6 +56,10 @@ crate trait DocFolder: Sized { || j.fields.iter().any(|f| f.is_stripped()); VariantItem(Variant::Struct(j)) } + Variant::Tuple(fields) => { + let fields = fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); + VariantItem(Variant::Tuple(fields)) + } _ => VariantItem(i2), } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 8f4857a6939..722cfc97a8d 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -937,6 +937,19 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni document_type_layout(w, cx, def_id); } +fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]) { + for (i, ty) in s + .iter() + .map(|f| if let clean::StructFieldItem(ref ty) = *f.kind { ty } else { unreachable!() }) + .enumerate() + { + if i > 0 { + w.write_str(", "); + } + write!(w, "{}", ty.print(cx)); + } +} + fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum) { wrap_into_docblock(w, |w| { wrap_item(w, "enum", |w| { @@ -964,14 +977,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum match *v.kind { clean::VariantItem(ref var) => match var { clean::Variant::CLike => write!(w, "{}", name), - clean::Variant::Tuple(ref tys) => { + clean::Variant::Tuple(ref s) => { write!(w, "{}(", name); - for (i, ty) in tys.iter().enumerate() { - if i > 0 { - w.write_str(", ") - } - write!(w, "{}", ty.print(cx)); - } + print_tuple_struct_fields(w, cx, s); w.write_str(")"); } clean::Variant::Struct(ref s) => { @@ -1024,14 +1032,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum id = id, name = variant.name.as_ref().unwrap() ); - if let clean::VariantItem(clean::Variant::Tuple(ref tys)) = *variant.kind { + if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind { w.write_str("("); - for (i, ty) in tys.iter().enumerate() { - if i > 0 { - w.write_str(", "); - } - write!(w, "{}", ty.print(cx)); - } + print_tuple_struct_fields(w, cx, s); w.write_str(")"); } w.write_str(""); @@ -1041,7 +1044,11 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum document_non_exhaustive(w, variant); use crate::clean::Variant; - if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind { + if let Some((extra, fields)) = match *variant.kind { + clean::VariantItem(Variant::Struct(ref s)) => Some(("", &s.fields)), + clean::VariantItem(Variant::Tuple(ref fields)) => Some(("Tuple ", fields)), + _ => None, + } { let variant_id = cx.derive_id(format!( "{}.{}.fields", ItemType::Variant, @@ -1051,10 +1058,10 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum write!( w, "

{extra}Fields of {name}

", - extra = if s.struct_type == CtorKind::Fn { "Tuple " } else { "" }, + extra = extra, name = variant.name.as_ref().unwrap(), ); - for field in &s.fields { + for field in fields { use crate::clean::StructFieldItem; if let StructFieldItem(ref ty) = *field.kind { let id = cx.derive_id(format!( diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index f3eeea6c6ae..9453e6d35ee 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -569,7 +569,18 @@ impl FromWithTcx for Variant { use clean::Variant::*; match variant { CLike => Variant::Plain, - Tuple(t) => Variant::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()), + Tuple(fields) => Variant::Tuple( + fields + .into_iter() + .map(|f| { + if let clean::StructFieldItem(ty) = *f.kind { + ty.into_tcx(tcx) + } else { + unreachable!() + } + }) + .collect(), + ), Struct(s) => Variant::Struct(ids(s.fields)), } } diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 4305268c9aa..a717c53d9d3 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -93,8 +93,8 @@ impl<'a> DocFolder for Stripper<'a> { // implementations of traits are always public. clean::ImplItem(ref imp) if imp.trait_.is_some() => true, - // Struct variant fields have inherited visibility - clean::VariantItem(clean::Variant::Struct(..)) => true, + // Variant fields have inherited visibility + clean::VariantItem(clean::Variant::Struct(..) | clean::Variant::Tuple(..)) => true, _ => false, }; -- cgit 1.4.1-3-g733a5 From a5213888e04b6bacda5198dc41026b604fe410ef Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 Aug 2021 14:58:50 +0200 Subject: Add rustdonc-json tests for enum variants --- src/test/rustdoc-json/enums/variant_struct.rs | 11 +++++++++++ src/test/rustdoc-json/enums/variant_tuple_struct.rs | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 src/test/rustdoc-json/enums/variant_struct.rs create mode 100644 src/test/rustdoc-json/enums/variant_tuple_struct.rs (limited to 'src') diff --git a/src/test/rustdoc-json/enums/variant_struct.rs b/src/test/rustdoc-json/enums/variant_struct.rs new file mode 100644 index 00000000000..246e6a09007 --- /dev/null +++ b/src/test/rustdoc-json/enums/variant_struct.rs @@ -0,0 +1,11 @@ +// @has variant_struct.json "$.index[*][?(@.name=='EnumStruct')].visibility" \"public\" +// @has - "$.index[*][?(@.name=='EnumStruct')].kind" \"enum\" +pub enum EnumStruct { + // @has - "$.index[*][?(@.name=='VariantS')].inner.variant_kind" \"struct\" + // @has - "$.index[*][?(@.name=='x')]" + // @has - "$.index[*][?(@.name=='y')]" + VariantS { + x: u32, + y: String, + }, +} diff --git a/src/test/rustdoc-json/enums/variant_tuple_struct.rs b/src/test/rustdoc-json/enums/variant_tuple_struct.rs new file mode 100644 index 00000000000..d948dc552cd --- /dev/null +++ b/src/test/rustdoc-json/enums/variant_tuple_struct.rs @@ -0,0 +1,6 @@ +// @has variant_tuple_struct.json "$.index[*][?(@.name=='EnumTupleStruct')].visibility" \"public\" +// @has - "$.index[*][?(@.name=='EnumTupleStruct')].kind" \"enum\" +pub enum EnumTupleStruct { + // @has - "$.index[*][?(@.name=='VariantA')].inner.variant_kind" \"tuple\" + VariantA(u32, String), +} -- cgit 1.4.1-3-g733a5 From 748a089acdfc17d2837cd8ae3a18f577f2f764b7 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Fri, 27 Aug 2021 19:36:18 +0300 Subject: Disallow the aapcs CC on Aarch64 This never really worked and makes LLVM assert. --- compiler/rustc_target/src/spec/mod.rs | 3 +- src/test/ui/abi/unsupported.aarch64.stderr | 24 ++++++++----- src/test/ui/abi/unsupported.arm.stderr | 58 ++++++++++++++++++++++++++++++ src/test/ui/abi/unsupported.i686.stderr | 12 +++---- src/test/ui/abi/unsupported.rs | 16 ++++++--- src/test/ui/abi/unsupported.x64.stderr | 16 ++++----- 6 files changed, 101 insertions(+), 28 deletions(-) create mode 100644 src/test/ui/abi/unsupported.arm.stderr (limited to 'src') diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 911956859b8..4d0cad80764 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1501,7 +1501,8 @@ impl Target { | Cdecl | EfiApi => true, X86Interrupt => ["x86", "x86_64"].contains(&&self.arch[..]), - Aapcs | CCmseNonSecureCall => ["arm", "aarch64"].contains(&&self.arch[..]), + Aapcs => "arm" == self.arch, + CCmseNonSecureCall => ["arm", "aarch64"].contains(&&self.arch[..]), Win64 | SysV64 => self.arch == "x86_64", PtxKernel => self.arch == "nvptx64", Msp430Interrupt => self.arch == "msp430", diff --git a/src/test/ui/abi/unsupported.aarch64.stderr b/src/test/ui/abi/unsupported.aarch64.stderr index fdeb79f93e9..225d49e05a3 100644 --- a/src/test/ui/abi/unsupported.aarch64.stderr +++ b/src/test/ui/abi/unsupported.aarch64.stderr @@ -1,41 +1,47 @@ error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:24:1 + --> $DIR/unsupported.rs:26:1 | LL | extern "ptx-kernel" fn ptx() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:26:1 + --> $DIR/unsupported.rs:28:1 | LL | extern "amdgpu-kernel" fn amdgpu() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"wasm"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:28:1 + --> $DIR/unsupported.rs:30:1 | LL | extern "wasm" fn wasm() {} | ^^^^^^^^^^^^^^^^^^^^^^^ +error[E0570]: `"aapcs"` is not a supported ABI for the current target + --> $DIR/unsupported.rs:32:1 + | +LL | extern "aapcs" fn aapcs() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:33:1 + --> $DIR/unsupported.rs:36:1 | LL | extern "msp430-interrupt" fn msp430() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:35:1 + --> $DIR/unsupported.rs:38:1 | LL | extern "avr-interrupt" fn avr() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"x86-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:37:1 + --> $DIR/unsupported.rs:40:1 | LL | extern "x86-interrupt" fn x86() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of calling convention not supported on this target - --> $DIR/unsupported.rs:39:1 + --> $DIR/unsupported.rs:43:1 | LL | extern "stdcall" fn stdcall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +51,7 @@ LL | extern "stdcall" fn stdcall() {} = note: for more information, see issue #87678 warning: use of calling convention not supported on this target - --> $DIR/unsupported.rs:44:1 + --> $DIR/unsupported.rs:50:1 | LL | extern "thiscall" fn thiscall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,6 +59,6 @@ LL | extern "thiscall" fn thiscall() {} = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #87678 -error: aborting due to 6 previous errors; 2 warnings emitted +error: aborting due to 7 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0570`. diff --git a/src/test/ui/abi/unsupported.arm.stderr b/src/test/ui/abi/unsupported.arm.stderr new file mode 100644 index 00000000000..b050ee0aa31 --- /dev/null +++ b/src/test/ui/abi/unsupported.arm.stderr @@ -0,0 +1,58 @@ +error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target + --> $DIR/unsupported.rs:26:1 + | +LL | extern "ptx-kernel" fn ptx() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target + --> $DIR/unsupported.rs:28:1 + | +LL | extern "amdgpu-kernel" fn amdgpu() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0570]: `"wasm"` is not a supported ABI for the current target + --> $DIR/unsupported.rs:30:1 + | +LL | extern "wasm" fn wasm() {} + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target + --> $DIR/unsupported.rs:36:1 + | +LL | extern "msp430-interrupt" fn msp430() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target + --> $DIR/unsupported.rs:38:1 + | +LL | extern "avr-interrupt" fn avr() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0570]: `"x86-interrupt"` is not a supported ABI for the current target + --> $DIR/unsupported.rs:40:1 + | +LL | extern "x86-interrupt" fn x86() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: use of calling convention not supported on this target + --> $DIR/unsupported.rs:43:1 + | +LL | extern "stdcall" fn stdcall() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unsupported_calling_conventions)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #87678 + +warning: use of calling convention not supported on this target + --> $DIR/unsupported.rs:50:1 + | +LL | extern "thiscall" fn thiscall() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #87678 + +error: aborting due to 6 previous errors; 2 warnings emitted + +For more information about this error, try `rustc --explain E0570`. diff --git a/src/test/ui/abi/unsupported.i686.stderr b/src/test/ui/abi/unsupported.i686.stderr index 81b12653d2e..7ca93516db9 100644 --- a/src/test/ui/abi/unsupported.i686.stderr +++ b/src/test/ui/abi/unsupported.i686.stderr @@ -1,35 +1,35 @@ error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:24:1 + --> $DIR/unsupported.rs:26:1 | LL | extern "ptx-kernel" fn ptx() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:26:1 + --> $DIR/unsupported.rs:28:1 | LL | extern "amdgpu-kernel" fn amdgpu() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"wasm"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:28:1 + --> $DIR/unsupported.rs:30:1 | LL | extern "wasm" fn wasm() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"aapcs"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:30:1 + --> $DIR/unsupported.rs:32:1 | LL | extern "aapcs" fn aapcs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:33:1 + --> $DIR/unsupported.rs:36:1 | LL | extern "msp430-interrupt" fn msp430() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:35:1 + --> $DIR/unsupported.rs:38:1 | LL | extern "avr-interrupt" fn avr() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/abi/unsupported.rs b/src/test/ui/abi/unsupported.rs index f0debdcf621..9319eac8d30 100644 --- a/src/test/ui/abi/unsupported.rs +++ b/src/test/ui/abi/unsupported.rs @@ -1,11 +1,13 @@ -// revisions: x64 i686 aarch64 +// revisions: x64 i686 aarch64 arm // // [x64] needs-llvm-components: x86 -// [x64]compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib +// [x64] compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib // [i686] needs-llvm-components: x86 -// [i686]compile-flags: --target=i686-unknown-linux-gnu --crate-type=rlib +// [i686] compile-flags: --target=i686-unknown-linux-gnu --crate-type=rlib // [aarch64] needs-llvm-components: aarch64 -// [aarch64]compile-flags: --target=aarch64-unknown-linux-gnu --crate-type=rlib +// [aarch64] compile-flags: --target=aarch64-unknown-linux-gnu --crate-type=rlib +// [arm] needs-llvm-components: arm +// [arm] compile-flags: --target=armv7-unknown-linux-gnueabihf --crate-type=rlib #![no_core] #![feature( no_core, @@ -30,19 +32,25 @@ extern "wasm" fn wasm() {} extern "aapcs" fn aapcs() {} //[x64]~^ ERROR is not a supported ABI //[i686]~^^ ERROR is not a supported ABI +//[aarch64]~^^^ ERROR is not a supported ABI extern "msp430-interrupt" fn msp430() {} //~^ ERROR is not a supported ABI extern "avr-interrupt" fn avr() {} //~^ ERROR is not a supported ABI extern "x86-interrupt" fn x86() {} //[aarch64]~^ ERROR is not a supported ABI +//[arm]~^^ ERROR is not a supported ABI extern "stdcall" fn stdcall() {} //[x64]~^ WARN use of calling convention not supported //[x64]~^^ WARN this was previously accepted //[aarch64]~^^^ WARN use of calling convention not supported //[aarch64]~^^^^ WARN this was previously accepted +//[arm]~^^^^^ WARN use of calling convention not supported +//[arm]~^^^^^^ WARN this was previously accepted extern "thiscall" fn thiscall() {} //[x64]~^ WARN use of calling convention not supported //[x64]~^^ WARN this was previously accepted //[aarch64]~^^^ WARN use of calling convention not supported //[aarch64]~^^^^ WARN this was previously accepted +//[arm]~^^^^^ WARN use of calling convention not supported +//[arm]~^^^^^^ WARN this was previously accepted diff --git a/src/test/ui/abi/unsupported.x64.stderr b/src/test/ui/abi/unsupported.x64.stderr index 60d067acf17..f2f52683324 100644 --- a/src/test/ui/abi/unsupported.x64.stderr +++ b/src/test/ui/abi/unsupported.x64.stderr @@ -1,41 +1,41 @@ error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:24:1 + --> $DIR/unsupported.rs:26:1 | LL | extern "ptx-kernel" fn ptx() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:26:1 + --> $DIR/unsupported.rs:28:1 | LL | extern "amdgpu-kernel" fn amdgpu() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"wasm"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:28:1 + --> $DIR/unsupported.rs:30:1 | LL | extern "wasm" fn wasm() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"aapcs"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:30:1 + --> $DIR/unsupported.rs:32:1 | LL | extern "aapcs" fn aapcs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:33:1 + --> $DIR/unsupported.rs:36:1 | LL | extern "msp430-interrupt" fn msp430() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:35:1 + --> $DIR/unsupported.rs:38:1 | LL | extern "avr-interrupt" fn avr() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of calling convention not supported on this target - --> $DIR/unsupported.rs:39:1 + --> $DIR/unsupported.rs:43:1 | LL | extern "stdcall" fn stdcall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | extern "stdcall" fn stdcall() {} = note: for more information, see issue #87678 warning: use of calling convention not supported on this target - --> $DIR/unsupported.rs:44:1 + --> $DIR/unsupported.rs:50:1 | LL | extern "thiscall" fn thiscall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- cgit 1.4.1-3-g733a5 From 532be287c9ce0dff490983bbf3f809506469a4d1 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 21:55:30 +0200 Subject: Test that turbofish does not swim away in prelude collusion suggestion. --- .../future-prelude-collision-turbofish.fixed | 28 ++++++++++++++++++++++ .../future-prelude-collision-turbofish.rs | 28 ++++++++++++++++++++++ .../future-prelude-collision-turbofish.stderr | 25 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/test/ui/rust-2021/future-prelude-collision-turbofish.fixed create mode 100644 src/test/ui/rust-2021/future-prelude-collision-turbofish.rs create mode 100644 src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr (limited to 'src') diff --git a/src/test/ui/rust-2021/future-prelude-collision-turbofish.fixed b/src/test/ui/rust-2021/future-prelude-collision-turbofish.fixed new file mode 100644 index 00000000000..3e76fced774 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-turbofish.fixed @@ -0,0 +1,28 @@ +// See https://github.com/rust-lang/rust/issues/88442 +// run-rustfix +// edition:2018 +// check-pass +#![allow(unused)] +#![warn(rust_2021_prelude_collisions)] + +trait AnnotatableTryInto { + fn try_into(self) -> Result + where Self: std::convert::TryInto { + std::convert::TryInto::try_into(self) + } +} + +impl AnnotatableTryInto for T where T: From {} + +fn main() -> Result<(), &'static str> { + let x: u64 = 1; + AnnotatableTryInto::try_into::(x).or(Err("foo"))?.checked_sub(1); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + + AnnotatableTryInto::try_into::(x).or(Err("foo"))?; + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + + Ok(()) +} diff --git a/src/test/ui/rust-2021/future-prelude-collision-turbofish.rs b/src/test/ui/rust-2021/future-prelude-collision-turbofish.rs new file mode 100644 index 00000000000..abb292ef992 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-turbofish.rs @@ -0,0 +1,28 @@ +// See https://github.com/rust-lang/rust/issues/88442 +// run-rustfix +// edition:2018 +// check-pass +#![allow(unused)] +#![warn(rust_2021_prelude_collisions)] + +trait AnnotatableTryInto { + fn try_into(self) -> Result + where Self: std::convert::TryInto { + std::convert::TryInto::try_into(self) + } +} + +impl AnnotatableTryInto for T where T: From {} + +fn main() -> Result<(), &'static str> { + let x: u64 = 1; + x.try_into::().or(Err("foo"))?.checked_sub(1); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + + x.try_into::().or(Err("foo"))?; + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + + Ok(()) +} diff --git a/src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr b/src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr new file mode 100644 index 00000000000..2de9020bce7 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr @@ -0,0 +1,25 @@ +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-turbofish.rs:19:5 + | +LL | x.try_into::().or(Err("foo"))?.checked_sub(1); + | ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `AnnotatableTryInto::try_into::(x)` + | +note: the lint level is defined here + --> $DIR/future-prelude-collision-turbofish.rs:6:9 + | +LL | #![warn(rust_2021_prelude_collisions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-turbofish.rs:23:5 + | +LL | x.try_into::().or(Err("foo"))?; + | ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `AnnotatableTryInto::try_into::(x)` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +warning: 2 warnings emitted + -- cgit 1.4.1-3-g733a5 From fc0fb38b19809e6f134a3409863b445216ae9c61 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 20:37:07 +0200 Subject: Add macro test for prelude collision suggestions. --- .../future-prelude-collision-macros.fixed | 45 ++++++++++++++++++++++ .../rust-2021/future-prelude-collision-macros.rs | 45 ++++++++++++++++++++++ .../future-prelude-collision-macros.stderr | 25 ++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 src/test/ui/rust-2021/future-prelude-collision-macros.fixed create mode 100644 src/test/ui/rust-2021/future-prelude-collision-macros.rs create mode 100644 src/test/ui/rust-2021/future-prelude-collision-macros.stderr (limited to 'src') diff --git a/src/test/ui/rust-2021/future-prelude-collision-macros.fixed b/src/test/ui/rust-2021/future-prelude-collision-macros.fixed new file mode 100644 index 00000000000..a97dc176e1b --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-macros.fixed @@ -0,0 +1,45 @@ +// run-rustfix +// edition:2018 +// check-pass +#![warn(rust_2021_prelude_collisions)] +#![allow(unreachable_code)] + +macro_rules! foo { + () => {{ + 123; + S + }}; +} + +trait MyTry { + fn try_into(self, _: u8); +} + +struct S; + +impl MyTry for S { + fn try_into(self, _: u8) {} +} + +trait TryFromU8: Sized { + fn try_from(_: u8); +} + +impl TryFromU8 for u32 { + fn try_from(_: u8) {} +} + +macro_rules! bar { + () => { + u32 + }; +} + +fn main() { + MyTry::try_into(foo!(), todo!()); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition + ::try_from(0); + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition +} diff --git a/src/test/ui/rust-2021/future-prelude-collision-macros.rs b/src/test/ui/rust-2021/future-prelude-collision-macros.rs new file mode 100644 index 00000000000..82484b5b368 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-macros.rs @@ -0,0 +1,45 @@ +// run-rustfix +// edition:2018 +// check-pass +#![warn(rust_2021_prelude_collisions)] +#![allow(unreachable_code)] + +macro_rules! foo { + () => {{ + 123; + S + }}; +} + +trait MyTry { + fn try_into(self, _: u8); +} + +struct S; + +impl MyTry for S { + fn try_into(self, _: u8) {} +} + +trait TryFromU8: Sized { + fn try_from(_: u8); +} + +impl TryFromU8 for u32 { + fn try_from(_: u8) {} +} + +macro_rules! bar { + () => { + u32 + }; +} + +fn main() { + foo!().try_into(todo!()); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition + ::try_from(0); + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~| WARNING this is accepted in the current edition +} diff --git a/src/test/ui/rust-2021/future-prelude-collision-macros.stderr b/src/test/ui/rust-2021/future-prelude-collision-macros.stderr new file mode 100644 index 00000000000..4c3543ca782 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-macros.stderr @@ -0,0 +1,25 @@ +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-macros.rs:39:5 + | +LL | foo!().try_into(todo!()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `MyTry::try_into(foo!(), todo!())` + | +note: the lint level is defined here + --> $DIR/future-prelude-collision-macros.rs:4:9 + | +LL | #![warn(rust_2021_prelude_collisions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +warning: trait-associated function `try_from` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-macros.rs:42:5 + | +LL | ::try_from(0); + | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `::try_from` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +warning: 2 warnings emitted + -- cgit 1.4.1-3-g733a5