diff options
| author | bors <bors@rust-lang.org> | 2021-08-31 16:47:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-31 16:47:06 +0000 |
| commit | 0a84708edca7c275cb99ad080317fbc7637516d8 (patch) | |
| tree | e2cc9552e3d5ae365f6c373b60e6f6d87080c1f4 /src | |
| parent | 76d18cfb8945f824c8777e04981e930d2037954e (diff) | |
| parent | f5cf9678c23bea8a9a865f0ced879714ec107871 (diff) | |
| download | rust-0a84708edca7c275cb99ad080317fbc7637516d8.tar.gz rust-0a84708edca7c275cb99ad080317fbc7637516d8.zip | |
Auto merge of #88535 - m-ou-se:rollup-jeusxbo, r=m-ou-se
Rollup of 10 pull requests Successful merges: - #85017 (Add carrying_add, borrowing_sub, widening_mul, carrying_mul methods to integers) - #86362 (Avoid cloning LocalDecls) - #88391 (Fix json tuple struct enum variant ) - #88399 (Disallow the aapcs CC on Aarch64) - #88418 (Allow `~const` bounds on trait assoc functions) - #88445 (Clean up the lowering of AST items) - #88495 (Add `TcpStream::set_linger` and `TcpStream::linger`) - #88501 (Use right span in prelude collision suggestions with macros. ) - #88504 (Keep turbofish in prelude collision lint.) - #88524 (Remove unnecessary `mut` from udp doctests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src')
24 files changed, 552 insertions, 62 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 640acffb114..b566239423e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1702,12 +1702,28 @@ impl Clean<VariantStruct> for rustc_hir::VariantData<'_> { } } +impl Clean<Vec<Item>> for hir::VariantData<'_> { + fn clean(&self, cx: &mut DocContext<'_>) -> Vec<Item> { + self.fields().iter().map(|x| x.clean(cx)).collect() + } +} + impl Clean<Item> 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, @@ -1737,13 +1753,7 @@ impl Clean<Variant> 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<Type>), + Tuple(Vec<Item>), 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("</code>"); @@ -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, "<h3>{extra}Fields of <b>{name}</b></h3><div>", - 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<clean::Variant> 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 819d7d323fd..a93880453ba 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -94,8 +94,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, }; 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), +} 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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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<Item: ~const T> { 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<Item: ~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:20:15 @@ -36,7 +36,7 @@ error: `~const` is not allowed here LL | fn generic<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` 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<P>() 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-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 { + <Self as 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: Foo>() { + T::bar(); +} + +const fn qux<T: ~const Foo>() { + 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 new file mode 100644 index 00000000000..d64822d7ce8 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs @@ -0,0 +1,40 @@ +#![feature(const_fn_trait_bound)] +#![feature(const_trait_impl)] + +trait Bar {} + +trait Foo { + fn a(); + fn b() where Self: ~const Bar; + fn c<T: ~const Bar>(); +} + +const fn test1<T: ~const Foo + Bar>() { + T::a(); + T::b(); + //~^ ERROR the trait bound + T::c::<T>(); + //~^ ERROR the trait bound +} + +const fn test2<T: ~const Foo + ~const Bar>() { + T::a(); + T::b(); + T::c::<T>(); +} + +fn test3<T: Foo>() { + T::a(); + T::b(); + //~^ ERROR the trait bound + T::c::<T>(); + //~^ ERROR the trait bound +} + +fn test4<T: Foo + Bar>() { + T::a(); + T::b(); + T::c::<T>(); +} + +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..fffb91f9870 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -0,0 +1,67 @@ +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:14: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<T: ~const Foo + Bar + Bar>() { + | +++++ + +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:16:5 + | +LL | T::c::<T>(); + | ^^^^^^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::c` + --> $DIR/trait-where-clause.rs:9:5 + | +LL | fn c<T: ~const Bar>(); + | ^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | const fn test1<T: ~const Foo + Bar + Bar>() { + | +++++ + +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` + | +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<T: Foo + Bar>() { + | +++++ + +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:30:5 + | +LL | T::c::<T>(); + | ^^^^^^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::c` + --> $DIR/trait-where-clause.rs:9:5 + | +LL | fn c<T: ~const Bar>(); + | ^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | fn test3<T: Foo + Bar>() { + | +++++ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. 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<T> { + fn try_into(self, _: u8); +} + +struct S; + +impl MyTry<i32> 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 + <bar!() as TryFromU8>::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<T> { + fn try_into(self, _: u8); +} + +struct S; + +impl MyTry<i32> 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 + <bar!()>::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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> + +warning: trait-associated function `try_from` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-macros.rs:42:5 + | +LL | <bar!()>::try_from(0); + | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<bar!() as TryFromU8>::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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> + +warning: 2 warnings emitted + 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<T>(self) -> Result<T, Self::Error> + where Self: std::convert::TryInto<T> { + std::convert::TryInto::try_into(self) + } +} + +impl<T> AnnotatableTryInto for T where T: From<u8> {} + +fn main() -> Result<(), &'static str> { + let x: u64 = 1; + AnnotatableTryInto::try_into::<usize>(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::<usize>(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<T>(self) -> Result<T, Self::Error> + where Self: std::convert::TryInto<T> { + std::convert::TryInto::try_into(self) + } +} + +impl<T> AnnotatableTryInto for T where T: From<u8> {} + +fn main() -> Result<(), &'static str> { + let x: u64 = 1; + x.try_into::<usize>().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::<usize>().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::<usize>().or(Err("foo"))?.checked_sub(1); + | ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `AnnotatableTryInto::try_into::<usize>(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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> + +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-turbofish.rs:23:5 + | +LL | x.try_into::<usize>().or(Err("foo"))?; + | ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `AnnotatableTryInto::try_into::<usize>(x)` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> + +warning: 2 warnings emitted + |
