From ac76882bf3ea97bc32f0381ab962782f5740074c Mon Sep 17 00:00:00 2001 From: Georgii Rylov Date: Wed, 23 Aug 2023 14:49:35 +0100 Subject: [PATCH 01/12] MCP661: Move wasm32-wasi-preview1-threads to Tier2 --- .../build-wasi-threads-toolchain.sh | 2 +- .../dist-various-2/build-wasi-toolchain.sh | 2 +- src/doc/rustc/src/platform-support.md | 2 +- .../wasm32-wasi-preview1-threads.md | 33 ++++++++++++------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-threads-toolchain.sh b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-threads-toolchain.sh index 7dae90f4403bb..689fe52863e07 100755 --- a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-threads-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-threads-toolchain.sh @@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin" git clone https://github.com/WebAssembly/wasi-libc cd wasi-libc -git reset --hard 7018e24d8fe248596819d2e884761676f3542a04 +git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087 make -j$(nproc) \ CC="$bin/clang" \ NM="$bin/llvm-nm" \ diff --git a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh index 45174e708dcf1..4b0d360686f12 100755 --- a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh @@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin" git clone https://github.com/WebAssembly/wasi-libc cd wasi-libc -git reset --hard 7018e24d8fe248596819d2e884761676f3542a04 +git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087 make -j$(nproc) \ CC="$bin/clang" \ NM="$bin/llvm-nm" \ diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 7cc17e11bdb86..9684060498a16 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -179,6 +179,7 @@ target | std | notes `wasm32-unknown-emscripten` | ✓ | WebAssembly via Emscripten `wasm32-unknown-unknown` | ✓ | WebAssembly `wasm32-wasi` | ✓ | WebAssembly with WASI +[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | | WebAssembly with WASI Preview 1 and threads `x86_64-apple-ios` | ✓ | 64-bit x86 iOS [`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX `x86_64-fuchsia` | ✓ | Alias for `x86_64-unknown-fuchsia` @@ -321,7 +322,6 @@ target | std | host | notes `thumbv7a-pc-windows-msvc` | ? | | `thumbv7a-uwp-windows-msvc` | ✓ | | `thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7-A Linux with NEON, MUSL -[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | | WebAssembly with WASI Preview 1 and threads [`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly `x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64 [`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS diff --git a/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md b/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md index b3eb34de63817..23b9992489973 100644 --- a/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md +++ b/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md @@ -1,6 +1,6 @@ # `wasm32-wasi-preview1-threads` -**Tier: 3** +**Tier: 2** The `wasm32-wasi-preview1-threads` target is a new and still (as of July 2023) an experimental target. This target is an extension to `wasm32-wasi-preview1` target, @@ -70,12 +70,6 @@ compile `wasm32-wasi-preview1-threads` binaries straight out of the box. You can reliably interoperate with C code in this mode (yet). -This target is not a stable target. This means that there are not many engines -which implement the `wasi-threads` feature and if they do they're likely behind a -flag, for example: - -* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads` - Also note that at this time the `wasm32-wasi-preview1-threads` target assumes the presence of other merged wasm proposals such as (with their LLVM feature flags): @@ -94,6 +88,17 @@ The target intends to match the corresponding Clang target for its `"C"` ABI. > found it's recommended to open an issue either with rust-lang/rust or ideally > with LLVM itself. +## Platform requirements + +The runtime should support the same set of APIs as any other supported wasi target for interacting with the host environment through the WASI standard. The runtime also should have implemetation of [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads). + +This target is not a stable target. This means that there are a few engines +which implement the `wasi-threads` feature and if they do they're likely behind a +flag, for example: + +* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads` +* [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime) - needs to be built with WAMR_BUILD_LIB_WASI_THREADS=1 + ## Building the target Users need to install or built wasi-sdk since release 20.0 @@ -110,12 +115,16 @@ After that users can build this by adding it to the `target` list in ## Building Rust programs -Since it is Tier 3, rust doesn't ship pre-compiled artifacts for this target. +From Rust Nightly 1.71.1 (2023-08-03) on the artifacts are shipped pre-compiled: + +```text +rustup target add wasm32-wasi-preview1-threads --toolchain nightly +``` + +Rust programs can be built for that target: -Specify `wasi-root` as explained in the previous section and then use the `build-std` -nightly cargo feature to build the standard library: -```shell -cargo +nightly build --target=wasm32-wasi-preview1-threads -Zbuild-std +```text +rustc --target wasm32-wasi-preview1-threads your-code.rs ``` ## Cross-compilation From 1abbd4cd4fa1c18c706505b71ed49cf0fda0ebee Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 24 Apr 2023 17:42:39 +0000 Subject: [PATCH 02/12] Render missing fields in tuple struct/enum as /* private fields */ --- src/librustdoc/html/render/print_item.rs | 44 +++++++++++++------ .../const-generics/const-generic-defaults.rs | 2 +- .../const-generics/const-generics-docs.rs | 4 +- tests/rustdoc/issue-88600.rs | 4 +- .../rustdoc/where.SWhere_Simd_item-decl.html | 2 +- tests/rustdoc/where.alpha_trait_decl.html | 2 +- tests/rustdoc/where.rs | 2 +- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index cb78f903462c1..066b5d6b36c8c 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1315,6 +1315,12 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>( s: &'a [clean::Item], ) -> impl fmt::Display + 'a + Captures<'cx> { display_fn(|f| { + if s.iter() + .all(|field| matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))) + { + return f.write_str("/* private fields */"); + } + for (i, ty) in s.iter().enumerate() { if i > 0 { f.write_str(", ")?; @@ -1936,21 +1942,31 @@ fn render_struct( } Some(CtorKind::Fn) => { w.write_str("("); - for (i, field) in fields.iter().enumerate() { - if i > 0 { - w.write_str(", "); - } - match *field.kind { - clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"), - clean::StructFieldItem(ref ty) => { - write!( - w, - "{}{}", - visibility_print_with_space(field.visibility(tcx), field.item_id, cx), - ty.print(cx), - ) + if fields.iter().all(|field| { + matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) + }) { + write!(w, "/* private fields */"); + } else { + for (i, field) in fields.iter().enumerate() { + if i > 0 { + w.write_str(", "); + } + match *field.kind { + clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"), + clean::StructFieldItem(ref ty) => { + write!( + w, + "{}{}", + visibility_print_with_space( + field.visibility(tcx), + field.item_id, + cx + ), + ty.print(cx), + ) + } + _ => unreachable!(), } - _ => unreachable!(), } } w.write_str(")"); diff --git a/tests/rustdoc/const-generics/const-generic-defaults.rs b/tests/rustdoc/const-generics/const-generic-defaults.rs index f781c6a62f24b..7a0a794112d2d 100644 --- a/tests/rustdoc/const-generics/const-generic-defaults.rs +++ b/tests/rustdoc/const-generics/const-generic-defaults.rs @@ -1,5 +1,5 @@ #![crate_name = "foo"] // @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \ -// 'pub struct Foo(_);' +// 'pub struct Foo(' pub struct Foo(T); diff --git a/tests/rustdoc/const-generics/const-generics-docs.rs b/tests/rustdoc/const-generics/const-generics-docs.rs index 828486a41d465..70a9518f05b40 100644 --- a/tests/rustdoc/const-generics/const-generics-docs.rs +++ b/tests/rustdoc/const-generics/const-generics-docs.rs @@ -33,7 +33,7 @@ impl Trait for [u8; N] {} // @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \ // 'pub struct Foo where u8: Trait' pub struct Foo where u8: Trait; -// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar(_)' +// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar(' pub struct Bar([T; N]); // @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header"]' 'impl Foowhere u8: Trait' @@ -92,7 +92,7 @@ macro_rules! define_me { } // @has foo/struct.Foz.html '//pre[@class="rust item-decl"]' \ -// 'pub struct Foz(_);' +// 'pub struct Foz(/* private fields */);' define_me!(Foz); trait Q { diff --git a/tests/rustdoc/issue-88600.rs b/tests/rustdoc/issue-88600.rs index db0d102b74184..f89af472f6e42 100644 --- a/tests/rustdoc/issue-88600.rs +++ b/tests/rustdoc/issue-88600.rs @@ -8,10 +8,10 @@ pub struct S; // @has issue_88600/enum.FooEnum.html pub enum FooEnum { - // @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(_)' + // @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(/* private fields */)' // @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0 HiddenTupleItem(#[doc(hidden)] H), - // @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(_, _)' + // @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(/* private fields */)' // @count - '//*[@id="variant.MultipleHidden.field.0"]' 0 // @count - '//*[@id="variant.MultipleHidden.field.1"]' 0 MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H), diff --git a/tests/rustdoc/where.SWhere_Simd_item-decl.html b/tests/rustdoc/where.SWhere_Simd_item-decl.html index 3e72ba2b74fe2..46708b9e4e925 100644 --- a/tests/rustdoc/where.SWhere_Simd_item-decl.html +++ b/tests/rustdoc/where.SWhere_Simd_item-decl.html @@ -1,3 +1,3 @@ -
pub struct Simd<T>(_)
+
pub struct Simd<T>(/* private fields */)
 where
     T: MyTrait;
diff --git a/tests/rustdoc/where.alpha_trait_decl.html b/tests/rustdoc/where.alpha_trait_decl.html index a7700055c9a74..0c0b2d1ceca9d 100644 --- a/tests/rustdoc/where.alpha_trait_decl.html +++ b/tests/rustdoc/where.alpha_trait_decl.html @@ -1,3 +1,3 @@ -pub struct Alpha<A>(_) +pub struct Alpha<A>(/* private fields */) where A: MyTrait; \ No newline at end of file diff --git a/tests/rustdoc/where.rs b/tests/rustdoc/where.rs index 2aa9c8b546193..aea02c1403927 100644 --- a/tests/rustdoc/where.rs +++ b/tests/rustdoc/where.rs @@ -4,7 +4,7 @@ use std::io::Lines; pub trait MyTrait { fn dummy(&self) { } } -// @has foo/struct.Alpha.html '//pre' "pub struct Alpha(_) where A: MyTrait" +// @has foo/struct.Alpha.html '//pre' "pub struct Alpha(/* private fields */) where A: MyTrait" // @snapshot alpha_trait_decl - '//*[@class="rust item-decl"]/code' pub struct Alpha(A) where A: MyTrait; // @has foo/trait.Bravo.html '//pre' "pub trait Bravowhere B: MyTrait" From c4bb70f51b545d87a29bfb68898e5f4169345f8e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 6 Sep 2023 13:26:56 +0200 Subject: [PATCH 03/12] Add regression test for private fields in tuple struct --- tests/rustdoc/private-fields-tuple-struct.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/rustdoc/private-fields-tuple-struct.rs diff --git a/tests/rustdoc/private-fields-tuple-struct.rs b/tests/rustdoc/private-fields-tuple-struct.rs new file mode 100644 index 0000000000000..c6989dd8cdfc8 --- /dev/null +++ b/tests/rustdoc/private-fields-tuple-struct.rs @@ -0,0 +1,15 @@ +// This test checks the diplay of "/* private fields */" sentence in tuple structs. +#![crate_name = "foo"] + +// @has 'foo/struct.A.html' '//*[@class="rust item-decl"]/code' 'pub struct A(pub u8, _);' +pub struct A(pub u8, u8); +// @has 'foo/struct.B.html' '//*[@class="rust item-decl"]/code' 'pub struct B(_, pub u8);' +pub struct B(u8, pub u8); +// @has 'foo/struct.C.html' '//*[@class="rust item-decl"]/code' 'pub struct C(_, pub u8, _);' +pub struct C(u8, pub u8, u8); +// @has 'foo/struct.D.html' '//*[@class="rust item-decl"]/code' 'pub struct D(pub u8, _, pub u8);' +pub struct D(pub u8, u8, pub u8); +// @has 'foo/struct.E.html' '//*[@class="rust item-decl"]/code' 'pub struct E(/* private fields */);' +pub struct E(u8); +// @has 'foo/struct.F.html' '//*[@class="rust item-decl"]/code' 'pub struct F(/* private fields */);' +pub struct F(u8, u8); From 748476d94d0fd87a0ee149e49ab3b196bbb08420 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 7 Sep 2023 01:20:43 +0000 Subject: [PATCH 04/12] Print the path of an RPITIT in RTN --- compiler/rustc_middle/src/ty/print/pretty.rs | 11 ++++++++ .../return-type-notation/basic.without.stderr | 4 +-- ...elf-auto-trait-issue-109924.current.stderr | 27 +++++++++++++++++++ ...g-self-auto-trait-issue-109924.next.stderr | 11 ++++++++ ...ormalizing-self-auto-trait-issue-109924.rs | 24 +++++++++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.current.stderr create mode 100644 tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next.stderr create mode 100644 tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ac0c88468faa5..7191ed7a0f6fa 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1123,6 +1123,17 @@ pub trait PrettyPrinter<'tcx>: } } + if self.tcx().features().return_type_notation + && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = self.tcx().opt_rpitit_info(def_id) + && let ty::Alias(_, alias_ty) = self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind() + && alias_ty.def_id == def_id + { + let num_args = self.tcx().generics_of(fn_def_id).count(); + write!(self, " {{ ")?; + self = self.print_def_path(fn_def_id, &args[..num_args])?; + write!(self, "() }}")?; + } + Ok(self) } diff --git a/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr b/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr index c2da4f57696f5..edce1045e245f 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr @@ -13,12 +13,12 @@ error: future cannot be sent between threads safely LL | is_send(foo::()); | ^^^^^^^^^^ future returned by `foo` is not `Send` | - = help: within `impl Future>`, the trait `Send` is not implemented for `impl Future>` + = help: within `impl Future>`, the trait `Send` is not implemented for `impl Future> { ::method() }` note: future is not `Send` as it awaits another future which is not `Send` --> $DIR/basic.rs:13:5 | LL | T::method().await?; - | ^^^^^^^^^^^ await occurs here on type `impl Future>`, which is not `Send` + | ^^^^^^^^^^^ await occurs here on type `impl Future> { ::method() }`, which is not `Send` note: required by a bound in `is_send` --> $DIR/basic.rs:17:20 | diff --git a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.current.stderr b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.current.stderr new file mode 100644 index 0000000000000..3b63ec45804ea --- /dev/null +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.current.stderr @@ -0,0 +1,27 @@ +warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:8:12 + | +LL | #![feature(return_type_notation)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #109417 for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0277]: `impl Future { <_ as Foo>::bar() }` cannot be sent between threads safely + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:23:11 + | +LL | build(Bar); + | ----- ^^^ `impl Future { <_ as Foo>::bar() }` cannot be sent between threads safely + | | + | required by a bound introduced by this call + | + = help: the trait `for<'a> Send` is not implemented for `impl Future { <_ as Foo>::bar() }` +note: required by a bound in `build` + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:20:39 + | +LL | fn build(_: T) where T: Foo {} + | ^^^^ required by this bound in `build` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next.stderr b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next.stderr new file mode 100644 index 0000000000000..6fab71787679b --- /dev/null +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next.stderr @@ -0,0 +1,11 @@ +warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:8:12 + | +LL | #![feature(return_type_notation)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #109417 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs new file mode 100644 index 0000000000000..b2cd9707db99f --- /dev/null +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs @@ -0,0 +1,24 @@ +// revisions: current next +//[current] known-bug: #109924 +//[next] check-pass +//[next] compile-flags: -Ztrait-solver=next +// edition:2021 + +#![feature(async_fn_in_trait)] +#![feature(return_type_notation)] +//[next]~^ WARN the feature `return_type_notation` is incomplete + +trait Foo { + async fn bar(&self); +} + +struct Bar; +impl Foo for Bar { + async fn bar(&self) {} +} + +fn build(_: T) where T: Foo {} + +fn main() { + build(Bar); +} From ee9727e263f32d1bc3aa5b8fdbe42098e84aa923 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 7 Sep 2023 04:51:36 +0000 Subject: [PATCH 05/12] Don't suggest dereferencing to unsized type --- .../src/traits/error_reporting/suggestions.rs | 15 ++++++++++++- .../dont-suggest-unsize-deref.rs | 15 +++++++++++++ .../dont-suggest-unsize-deref.stderr | 22 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.rs create mode 100644 tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 611ec6b00ef60..32fb10ce4a676 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -838,7 +838,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { obligation.param_env, real_trait_pred_and_base_ty, ); - if self.predicate_may_hold(&obligation) { + let sized_obligation = Obligation::new( + self.tcx, + obligation.cause.clone(), + obligation.param_env, + ty::TraitRef::from_lang_item( + self.tcx, + hir::LangItem::Sized, + obligation.cause.span, + [base_ty], + ), + ); + if self.predicate_may_hold(&obligation) + && self.predicate_must_hold_modulo_regions(&sized_obligation) + { let call_node = self.tcx.hir().get(*call_hir_id); let msg = "consider dereferencing here"; let is_receiver = matches!( diff --git a/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.rs b/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.rs new file mode 100644 index 0000000000000..8133036991c2b --- /dev/null +++ b/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.rs @@ -0,0 +1,15 @@ +fn use_iterator(itr: I) +where + I: IntoIterator, +{ +} + +fn pass_iterator(i: &dyn IntoIterator) +where + I: Iterator, +{ + use_iterator(i); + //~^ ERROR `&dyn IntoIterator` is not an iterator +} + +fn main() {} diff --git a/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.stderr b/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.stderr new file mode 100644 index 0000000000000..18ce9939eb26b --- /dev/null +++ b/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.stderr @@ -0,0 +1,22 @@ +error[E0277]: `&dyn IntoIterator` is not an iterator + --> $DIR/dont-suggest-unsize-deref.rs:11:18 + | +LL | use_iterator(i); + | ------------ ^ `&dyn IntoIterator` is not an iterator + | | + | required by a bound introduced by this call + | + = help: the trait `Iterator` is not implemented for `&dyn IntoIterator` + = note: required for `&dyn IntoIterator` to implement `IntoIterator` +note: required by a bound in `use_iterator` + --> $DIR/dont-suggest-unsize-deref.rs:3:8 + | +LL | fn use_iterator(itr: I) + | ------------ required by a bound in this function +LL | where +LL | I: IntoIterator, + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `use_iterator` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From 67e7d85ad2c01376c5fe2de5f98f2b4fb4109bb7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 7 Sep 2023 04:52:17 +0000 Subject: [PATCH 06/12] Rename folder typo --- .../dont-suggest-unsize-deref.rs | 0 .../dont-suggest-unsize-deref.stderr | 0 .../issue-39029.fixed | 0 .../{suggest-deferences => suggest-dereferences}/issue-39029.rs | 0 .../issue-39029.stderr | 0 .../issue-62530.fixed | 0 .../{suggest-deferences => suggest-dereferences}/issue-62530.rs | 0 .../issue-62530.stderr | 0 .../{suggest-deferences => suggest-dereferences}/multiple-0.fixed | 0 .../{suggest-deferences => suggest-dereferences}/multiple-0.rs | 0 .../multiple-0.stderr | 0 .../{suggest-deferences => suggest-dereferences}/multiple-1.rs | 0 .../multiple-1.stderr | 0 .../root-obligation.fixed | 0 .../root-obligation.rs | 0 .../root-obligation.stderr | 0 .../suggest-dereferencing-receiver-argument.fixed | 0 .../suggest-dereferencing-receiver-argument.rs | 0 .../suggest-dereferencing-receiver-argument.stderr | 0 19 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/dont-suggest-unsize-deref.rs (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/dont-suggest-unsize-deref.stderr (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/issue-39029.fixed (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/issue-39029.rs (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/issue-39029.stderr (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/issue-62530.fixed (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/issue-62530.rs (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/issue-62530.stderr (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/multiple-0.fixed (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/multiple-0.rs (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/multiple-0.stderr (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/multiple-1.rs (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/multiple-1.stderr (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/root-obligation.fixed (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/root-obligation.rs (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/root-obligation.stderr (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/suggest-dereferencing-receiver-argument.fixed (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/suggest-dereferencing-receiver-argument.rs (100%) rename tests/ui/traits/{suggest-deferences => suggest-dereferences}/suggest-dereferencing-receiver-argument.stderr (100%) diff --git a/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.rs b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs similarity index 100% rename from tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.rs rename to tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs diff --git a/tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.stderr b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr similarity index 100% rename from tests/ui/traits/suggest-deferences/dont-suggest-unsize-deref.stderr rename to tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr diff --git a/tests/ui/traits/suggest-deferences/issue-39029.fixed b/tests/ui/traits/suggest-dereferences/issue-39029.fixed similarity index 100% rename from tests/ui/traits/suggest-deferences/issue-39029.fixed rename to tests/ui/traits/suggest-dereferences/issue-39029.fixed diff --git a/tests/ui/traits/suggest-deferences/issue-39029.rs b/tests/ui/traits/suggest-dereferences/issue-39029.rs similarity index 100% rename from tests/ui/traits/suggest-deferences/issue-39029.rs rename to tests/ui/traits/suggest-dereferences/issue-39029.rs diff --git a/tests/ui/traits/suggest-deferences/issue-39029.stderr b/tests/ui/traits/suggest-dereferences/issue-39029.stderr similarity index 100% rename from tests/ui/traits/suggest-deferences/issue-39029.stderr rename to tests/ui/traits/suggest-dereferences/issue-39029.stderr diff --git a/tests/ui/traits/suggest-deferences/issue-62530.fixed b/tests/ui/traits/suggest-dereferences/issue-62530.fixed similarity index 100% rename from tests/ui/traits/suggest-deferences/issue-62530.fixed rename to tests/ui/traits/suggest-dereferences/issue-62530.fixed diff --git a/tests/ui/traits/suggest-deferences/issue-62530.rs b/tests/ui/traits/suggest-dereferences/issue-62530.rs similarity index 100% rename from tests/ui/traits/suggest-deferences/issue-62530.rs rename to tests/ui/traits/suggest-dereferences/issue-62530.rs diff --git a/tests/ui/traits/suggest-deferences/issue-62530.stderr b/tests/ui/traits/suggest-dereferences/issue-62530.stderr similarity index 100% rename from tests/ui/traits/suggest-deferences/issue-62530.stderr rename to tests/ui/traits/suggest-dereferences/issue-62530.stderr diff --git a/tests/ui/traits/suggest-deferences/multiple-0.fixed b/tests/ui/traits/suggest-dereferences/multiple-0.fixed similarity index 100% rename from tests/ui/traits/suggest-deferences/multiple-0.fixed rename to tests/ui/traits/suggest-dereferences/multiple-0.fixed diff --git a/tests/ui/traits/suggest-deferences/multiple-0.rs b/tests/ui/traits/suggest-dereferences/multiple-0.rs similarity index 100% rename from tests/ui/traits/suggest-deferences/multiple-0.rs rename to tests/ui/traits/suggest-dereferences/multiple-0.rs diff --git a/tests/ui/traits/suggest-deferences/multiple-0.stderr b/tests/ui/traits/suggest-dereferences/multiple-0.stderr similarity index 100% rename from tests/ui/traits/suggest-deferences/multiple-0.stderr rename to tests/ui/traits/suggest-dereferences/multiple-0.stderr diff --git a/tests/ui/traits/suggest-deferences/multiple-1.rs b/tests/ui/traits/suggest-dereferences/multiple-1.rs similarity index 100% rename from tests/ui/traits/suggest-deferences/multiple-1.rs rename to tests/ui/traits/suggest-dereferences/multiple-1.rs diff --git a/tests/ui/traits/suggest-deferences/multiple-1.stderr b/tests/ui/traits/suggest-dereferences/multiple-1.stderr similarity index 100% rename from tests/ui/traits/suggest-deferences/multiple-1.stderr rename to tests/ui/traits/suggest-dereferences/multiple-1.stderr diff --git a/tests/ui/traits/suggest-deferences/root-obligation.fixed b/tests/ui/traits/suggest-dereferences/root-obligation.fixed similarity index 100% rename from tests/ui/traits/suggest-deferences/root-obligation.fixed rename to tests/ui/traits/suggest-dereferences/root-obligation.fixed diff --git a/tests/ui/traits/suggest-deferences/root-obligation.rs b/tests/ui/traits/suggest-dereferences/root-obligation.rs similarity index 100% rename from tests/ui/traits/suggest-deferences/root-obligation.rs rename to tests/ui/traits/suggest-dereferences/root-obligation.rs diff --git a/tests/ui/traits/suggest-deferences/root-obligation.stderr b/tests/ui/traits/suggest-dereferences/root-obligation.stderr similarity index 100% rename from tests/ui/traits/suggest-deferences/root-obligation.stderr rename to tests/ui/traits/suggest-dereferences/root-obligation.stderr diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.fixed similarity index 100% rename from tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed rename to tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.fixed diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.rs similarity index 100% rename from tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs rename to tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.rs diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.stderr similarity index 100% rename from tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr rename to tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.stderr From 14e59bb317c3c901bce83deb16ee9bfa5cc90e28 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 7 Sep 2023 06:27:10 +0000 Subject: [PATCH 07/12] Lint node for PRIVATE_BOUNDS is the item which has the bounds --- compiler/rustc_privacy/src/lib.rs | 7 ++++--- tests/ui/privacy/private-bounds-locally-allowed.rs | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/ui/privacy/private-bounds-locally-allowed.rs diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 906a36cdb25d1..aedc7b22725aa 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1463,14 +1463,15 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { }; let vis = self.tcx.local_visibility(local_def_id); - let hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id); let span = self.tcx.def_span(self.item_def_id.to_def_id()); let vis_span = self.tcx.def_span(def_id); if self.in_assoc_ty && !vis.is_at_least(self.required_visibility, self.tcx) { let vis_descr = match vis { ty::Visibility::Public => "public", ty::Visibility::Restricted(vis_def_id) => { - if vis_def_id == self.tcx.parent_module(hir_id).to_local_def_id() { + if vis_def_id + == self.tcx.parent_module_from_def_id(local_def_id).to_local_def_id() + { "private" } else if vis_def_id.is_top_level_module() { "crate-private" @@ -1504,7 +1505,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { }; self.tcx.emit_spanned_lint( lint, - hir_id, + self.tcx.hir().local_def_id_to_hir_id(self.item_def_id), span, PrivateInterfacesOrBoundsLint { item_span: span, diff --git a/tests/ui/privacy/private-bounds-locally-allowed.rs b/tests/ui/privacy/private-bounds-locally-allowed.rs new file mode 100644 index 0000000000000..96a007a64f630 --- /dev/null +++ b/tests/ui/privacy/private-bounds-locally-allowed.rs @@ -0,0 +1,7 @@ +// check-pass +// compile-flags: --crate-type=lib + +#[allow(private_bounds)] +pub trait Foo: FooImpl {} + +trait FooImpl {} From 3bf3dadbc02736c66f56754769dcc001b040862b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 7 Sep 2023 06:57:08 +0000 Subject: [PATCH 08/12] Ensure that dyn trait bounds stay sorted --- compiler/rustc_middle/src/ty/print/pretty.rs | 19 ++++++++----------- .../object/enforce-supertrait-projection.rs | 2 +- .../enforce-supertrait-projection.stderr | 2 +- .../dont-suggest-unsize-deref.rs | 2 +- .../dont-suggest-unsize-deref.stderr | 8 ++++---- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ac0c88468faa5..83c9269f24e36 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1239,21 +1239,18 @@ pub trait PrettyPrinter<'tcx>: .generics_of(principal.def_id) .own_args_no_defaults(cx.tcx(), principal.args); - let mut projections = predicates.projection_bounds(); - - let mut args = args.iter().cloned(); - let arg0 = args.next(); - let projection0 = projections.next(); - if arg0.is_some() || projection0.is_some() { - let args = arg0.into_iter().chain(args); - let projections = projection0.into_iter().chain(projections); + let mut projections: Vec<_> = predicates.projection_bounds().collect(); + projections.sort_by_cached_key(|proj| { + cx.tcx().item_name(proj.item_def_id()).to_string() + }); + if !args.is_empty() || !projections.is_empty() { p!(generic_delimiters(|mut cx| { - cx = cx.comma_sep(args)?; - if arg0.is_some() && projection0.is_some() { + cx = cx.comma_sep(args.iter().copied())?; + if !args.is_empty() && !projections.is_empty() { write!(cx, ", ")?; } - cx.comma_sep(projections) + cx.comma_sep(projections.iter().copied()) })); } } diff --git a/tests/ui/traits/object/enforce-supertrait-projection.rs b/tests/ui/traits/object/enforce-supertrait-projection.rs index 2c9b41eea2abe..0ea944ec2df55 100644 --- a/tests/ui/traits/object/enforce-supertrait-projection.rs +++ b/tests/ui/traits/object/enforce-supertrait-projection.rs @@ -7,7 +7,7 @@ trait Trait: SuperTrait::B> {} fn transmute(x: A) -> B { foo::>(x) - //~^ ERROR type mismatch resolving ` as SuperTrait>::A == B` + //~^ ERROR type mismatch resolving ` as SuperTrait>::A == B` } fn foo(x: T::A) -> B diff --git a/tests/ui/traits/object/enforce-supertrait-projection.stderr b/tests/ui/traits/object/enforce-supertrait-projection.stderr index 848b4e69a4bb8..2fb94d348966a 100644 --- a/tests/ui/traits/object/enforce-supertrait-projection.stderr +++ b/tests/ui/traits/object/enforce-supertrait-projection.stderr @@ -1,4 +1,4 @@ -error[E0271]: type mismatch resolving ` as SuperTrait>::A == B` +error[E0271]: type mismatch resolving ` as SuperTrait>::A == B` --> $DIR/enforce-supertrait-projection.rs:9:17 | LL | fn transmute(x: A) -> B { diff --git a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs index 8133036991c2b..c6f9e3456186c 100644 --- a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs +++ b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs @@ -9,7 +9,7 @@ where I: Iterator, { use_iterator(i); - //~^ ERROR `&dyn IntoIterator` is not an iterator + //~^ ERROR `&dyn IntoIterator` is not an iterator } fn main() {} diff --git a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr index 18ce9939eb26b..bd0e7ca2c02e5 100644 --- a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr +++ b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr @@ -1,13 +1,13 @@ -error[E0277]: `&dyn IntoIterator` is not an iterator +error[E0277]: `&dyn IntoIterator` is not an iterator --> $DIR/dont-suggest-unsize-deref.rs:11:18 | LL | use_iterator(i); - | ------------ ^ `&dyn IntoIterator` is not an iterator + | ------------ ^ `&dyn IntoIterator` is not an iterator | | | required by a bound introduced by this call | - = help: the trait `Iterator` is not implemented for `&dyn IntoIterator` - = note: required for `&dyn IntoIterator` to implement `IntoIterator` + = help: the trait `Iterator` is not implemented for `&dyn IntoIterator` + = note: required for `&dyn IntoIterator` to implement `IntoIterator` note: required by a bound in `use_iterator` --> $DIR/dont-suggest-unsize-deref.rs:3:8 | From a932990ed48018d60cdbf3d66dfe5eb146866002 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 7 Sep 2023 17:31:35 +1000 Subject: [PATCH 09/12] Use `newtype_index` for `IntVid` and `FloatVid`. `TyVid` already uses `newtype_index`. --- compiler/rustc_infer/src/infer/mod.rs | 4 +-- compiler/rustc_type_ir/src/lib.rs | 36 +++++++++------------------ 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index aaabf1482e2d2..dabebe0adc063 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -764,13 +764,13 @@ impl<'tcx> InferCtxt<'tcx> { .collect(); vars.extend( (0..inner.int_unification_table().len()) - .map(|i| ty::IntVid { index: i as u32 }) + .map(|i| ty::IntVid::from_u32(i as u32)) .filter(|&vid| inner.int_unification_table().probe_value(vid).is_none()) .map(|v| Ty::new_int_var(self.tcx, v)), ); vars.extend( (0..inner.float_unification_table().len()) - .map(|i| ty::FloatVid { index: i as u32 }) + .map(|i| ty::FloatVid::from_u32(i as u32)) .filter(|&vid| inner.float_unification_table().probe_value(vid).is_none()) .map(|v| Ty::new_float_var(self.tcx, v)), ); diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index e0abc7f04f575..e348591ebba2f 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -574,16 +574,16 @@ rustc_index::newtype_index! { pub struct TyVid {} } -/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] -pub struct IntVid { - pub index: u32, +rustc_index::newtype_index! { + /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**. + #[debug_format = "?{}i"] + pub struct IntVid {} } -/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] -pub struct FloatVid { - pub index: u32, +rustc_index::newtype_index! { + /// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**. + #[debug_format = "?{}f"] + pub struct FloatVid {} } /// A placeholder for a type that hasn't been inferred yet. @@ -645,11 +645,11 @@ impl UnifyKey for IntVid { type Value = Option; #[inline] // make this function eligible for inlining - it is quite hot. fn index(&self) -> u32 { - self.index + self.as_u32() } #[inline] fn from_index(i: u32) -> IntVid { - IntVid { index: i } + IntVid::from_u32(i) } fn tag() -> &'static str { "IntVid" @@ -662,11 +662,11 @@ impl UnifyKey for FloatVid { type Value = Option; #[inline] fn index(&self) -> u32 { - self.index + self.as_u32() } #[inline] fn from_index(i: u32) -> FloatVid { - FloatVid { index: i } + FloatVid::from_u32(i) } fn tag() -> &'static str { "FloatVid" @@ -770,18 +770,6 @@ impl fmt::Debug for FloatVarValue { } } -impl fmt::Debug for IntVid { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "?{}i", self.index) - } -} - -impl fmt::Debug for FloatVid { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "?{}f", self.index) - } -} - impl fmt::Debug for Variance { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(match *self { From bb6dcf5f740f6147eaf8774509ca27adc47c009b Mon Sep 17 00:00:00 2001 From: Liu Dingming Date: Thu, 7 Sep 2023 17:34:41 +0800 Subject: [PATCH 10/12] Add `RegisterCodeGenFlags` to get full codegen flags list --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 4ac739326d2dd..4b30a4fefd9d9 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -9,6 +9,7 @@ #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/CodeGen/CommandFlags.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/AssemblyAnnotationWriter.h" @@ -50,6 +51,8 @@ using namespace llvm; +static codegen::RegisterCodeGenFlags CGF; + typedef struct LLVMOpaquePass *LLVMPassRef; typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef; From 487766cef0faa12c3e744b8c754ea7c58427ec2f Mon Sep 17 00:00:00 2001 From: Liu Dingming Date: Thu, 7 Sep 2023 17:36:21 +0800 Subject: [PATCH 11/12] Using parsed codegen flags --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 4b30a4fefd9d9..194ebe6d96890 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -424,7 +424,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( return nullptr; } - TargetOptions Options; + TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip); Options.FloatABIType = FloatABI::Default; if (UseSoftFloat) { From 31e5dd3a7942b35004f3a154c55728702f3dcb3e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 7 Sep 2023 11:30:47 -0700 Subject: [PATCH 12/12] diagnostics: add test case for trait bounds diagnostic Closes #82038 It was fixed by b8e5ab20ed7a7677a998a163ccf7853764b195e6, a wide-reaching obligation tracking improvement. This commit adds a test case. --- tests/ui/trait-bounds/issue-82038.rs | 9 +++++++++ tests/ui/trait-bounds/issue-82038.stderr | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/ui/trait-bounds/issue-82038.rs create mode 100644 tests/ui/trait-bounds/issue-82038.stderr diff --git a/tests/ui/trait-bounds/issue-82038.rs b/tests/ui/trait-bounds/issue-82038.rs new file mode 100644 index 0000000000000..11de714faf014 --- /dev/null +++ b/tests/ui/trait-bounds/issue-82038.rs @@ -0,0 +1,9 @@ +// Failed bound `bool: Foo` must not point at the `Self: Clone` line + +trait Foo { + fn my_method() where Self: Clone; +} + +fn main() { + ::my_method(); //~ERROR [E0277] +} diff --git a/tests/ui/trait-bounds/issue-82038.stderr b/tests/ui/trait-bounds/issue-82038.stderr new file mode 100644 index 0000000000000..f37e3286f4bf8 --- /dev/null +++ b/tests/ui/trait-bounds/issue-82038.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `bool: Foo` is not satisfied + --> $DIR/issue-82038.rs:8:6 + | +LL | ::my_method(); + | ^^^^ the trait `Foo` is not implemented for `bool` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.