From b910e977a3279460fb13e464fa4b5d563645c8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 4 Nov 2024 18:55:21 +0100 Subject: [PATCH 01/15] CI: increase timeout from 4h to 6h Our CI got a bit slower since the last time we lowered the timeout, and if e.g. Docker build cache is broken, the timeout can be triggered. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fca71716c18c..6fe257933423c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: defaults: run: shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }} - timeout-minutes: 240 + timeout-minutes: 360 env: CI_JOB_NAME: ${{ matrix.image }} CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse From 91486607e3f89180f33c4b613a955eb293400571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 21 Nov 2024 16:54:18 +0000 Subject: [PATCH 02/15] add convoluted test for issue 132920 --- .../minibevy.rs | 2 + .../minirapier.rs | 1 + .../repro.rs | 14 ++++++ .../rmake.rs | 45 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 tests/run-make/diagnostics-traits-from-duplicate-crates/minibevy.rs create mode 100644 tests/run-make/diagnostics-traits-from-duplicate-crates/minirapier.rs create mode 100644 tests/run-make/diagnostics-traits-from-duplicate-crates/repro.rs create mode 100644 tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs diff --git a/tests/run-make/diagnostics-traits-from-duplicate-crates/minibevy.rs b/tests/run-make/diagnostics-traits-from-duplicate-crates/minibevy.rs new file mode 100644 index 0000000000000..1bc8473e08e32 --- /dev/null +++ b/tests/run-make/diagnostics-traits-from-duplicate-crates/minibevy.rs @@ -0,0 +1,2 @@ +pub trait Resource {} +pub struct Ray2d; diff --git a/tests/run-make/diagnostics-traits-from-duplicate-crates/minirapier.rs b/tests/run-make/diagnostics-traits-from-duplicate-crates/minirapier.rs new file mode 100644 index 0000000000000..2b84332aa517c --- /dev/null +++ b/tests/run-make/diagnostics-traits-from-duplicate-crates/minirapier.rs @@ -0,0 +1 @@ +pub type Ray = minibevy::Ray2d; diff --git a/tests/run-make/diagnostics-traits-from-duplicate-crates/repro.rs b/tests/run-make/diagnostics-traits-from-duplicate-crates/repro.rs new file mode 100644 index 0000000000000..90a6dfc2e15f8 --- /dev/null +++ b/tests/run-make/diagnostics-traits-from-duplicate-crates/repro.rs @@ -0,0 +1,14 @@ +extern crate minibevy; +extern crate minirapier; + +use minibevy::Resource; +use minirapier::Ray; + +fn insert_resource(_resource: R) {} + +struct Res; +impl Resource for Res {} + +fn main() { + insert_resource(Res.into()); +} diff --git a/tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs b/tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs new file mode 100644 index 0000000000000..32c4cf3389647 --- /dev/null +++ b/tests/run-make/diagnostics-traits-from-duplicate-crates/rmake.rs @@ -0,0 +1,45 @@ +// Non-regression test for issue #132920 where multiple versions of the same crate are present in +// the dependency graph, and an unexpected error in a dependent crate caused an ICE in the +// unsatisfied bounds diagnostics for traits present in multiple crate versions. +// +// Setup: +// - two versions of the same crate: minibevy_a and minibevy_b +// - minirapier: depends on minibevy_a +// - repro: depends on minirapier and minibevy_b + +use run_make_support::rustc; + +fn main() { + // Prepare dependencies, mimicking a check build with cargo. + rustc() + .input("minibevy.rs") + .crate_name("minibevy") + .crate_type("lib") + .emit("metadata") + .metadata("a") + .extra_filename("-a") + .run(); + rustc() + .input("minibevy.rs") + .crate_name("minibevy") + .crate_type("lib") + .emit("metadata") + .metadata("b") + .extra_filename("-b") + .run(); + rustc() + .input("minirapier.rs") + .crate_name("minirapier") + .crate_type("lib") + .emit("metadata") + .extern_("minibevy", "libminibevy-a.rmeta") + .run(); + + // Building the main crate used to ICE here when printing the `type annotations needed` error. + rustc() + .input("repro.rs") + .extern_("minibevy", "libminibevy-b.rmeta") + .extern_("minirapier", "libminirapier.rmeta") + .run_fail() + .assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug"); +} From 764e3e264f69d8af9fa42d86ea36702584dcb36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 21 Nov 2024 16:59:40 +0000 Subject: [PATCH 03/15] Revert "Remove less relevant info from diagnostic" This reverts commit 8a568d9f15453cbfe5d6f45fa5f5bb32e58b93ed. --- .../traits/fulfillment_errors.rs | 18 -------- tests/run-make/crate-loading/rmake.rs | 46 +++++++++++-------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 4e7d7b79ff4de..a80f42d38f6d9 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1804,24 +1804,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { StringPart::highlighted("cargo tree".to_string()), StringPart::normal("` to explore your dependency tree".to_string()), ]); - - // FIXME: this is a giant hack for the benefit of this specific diagnostic. Because - // we're so nested in method calls before the error gets emitted, bubbling a single bit - // flag informing the top level caller to stop adding extra detail to the diagnostic, - // would actually be harder to follow. So we do something naughty here: we consume the - // diagnostic, emit it and leave in its place a "delayed bug" that will continue being - // modified but won't actually be printed to end users. This *is not ideal*, but allows - // us to reduce the verbosity of an error that is already quite verbose and increase its - // specificity. Below we modify the main message as well, in a way that *could* break if - // the implementation of Diagnostics change significantly, but that would be caught with - // a make test failure when this diagnostic is tested. - err.primary_message(format!( - "{} because the trait comes from a different crate version", - err.messages[0].0.as_str().unwrap(), - )); - let diag = err.clone(); - err.downgrade_to_delayed_bug(); - self.tcx.dcx().emit_diagnostic(diag); return true; } diff --git a/tests/run-make/crate-loading/rmake.rs b/tests/run-make/crate-loading/rmake.rs index 2d5913c4bcb09..544bf9ab957a4 100644 --- a/tests/run-make/crate-loading/rmake.rs +++ b/tests/run-make/crate-loading/rmake.rs @@ -18,31 +18,37 @@ fn main() { .extern_("dependency", rust_lib_name("dependency")) .extern_("dep_2_reexport", rust_lib_name("foo")) .run_fail() - .assert_stderr_contains(r#"error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied because the trait comes from a different crate version - --> multiple-dep-versions.rs:7:18 - | -7 | do_something(Type); - | ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type` - | + .assert_stderr_contains(r#"error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied + --> multiple-dep-versions.rs:7:18 + | +7 | do_something(Type); + | ------------ ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type` + | | + | required by a bound introduced by this call + | note: there are multiple different versions of crate `dependency` in the dependency graph"#) .assert_stderr_contains(r#" -3 | pub struct Type(pub i32); - | --------------- this type implements the required trait -4 | pub trait Trait { - | ^^^^^^^^^^^^^^^ this is the required trait +3 | pub struct Type(pub i32); + | --------------- this type implements the required trait +4 | pub trait Trait { + | ^^^^^^^^^^^^^^^ this is the required trait "#) .assert_stderr_contains(r#" -1 | extern crate dep_2_reexport; - | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo` -2 | extern crate dependency; - | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate"#) +1 | extern crate dep_2_reexport; + | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo` +2 | extern crate dependency; + | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate"#) .assert_stderr_contains(r#" -3 | pub struct Type; - | --------------- this type doesn't implement the required trait -4 | pub trait Trait { - | --------------- this is the found trait - = note: two types coming from two different versions of the same crate are different types even if they look the same - = help: you can use `cargo tree` to explore your dependency tree"#) +3 | pub struct Type; + | --------------- this type doesn't implement the required trait +4 | pub trait Trait { + | --------------- this is the found trait + = note: two types coming from two different versions of the same crate are different types even if they look the same + = help: you can use `cargo tree` to explore your dependency tree"#) + .assert_stderr_contains(r#"note: required by a bound in `do_something`"#) + .assert_stderr_contains(r#" +12 | pub fn do_something(_: X) {} + | ^^^^^ required by this bound in `do_something`"#) .assert_stderr_contains(r#"error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope --> multiple-dep-versions.rs:8:10 | From d0a45cfeaa5e0861f0c363cc9d07aa94b429b820 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2024 16:15:46 +0100 Subject: [PATCH 04/15] Fix `Result` and `Option` not getting a jump to def link generated --- src/librustdoc/html/highlight.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 29f6f92a6b28e..b2fc1a47f78fb 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -181,6 +181,9 @@ impl<'a, 'tcx, F: Write> TokenHandler<'a, 'tcx, F> { // current parent tag is not the same as our pending content. let close_tag = if self.pending_elems.len() > 1 && let Some(current_class) = current_class + // `PreludeTy` can never include more than an ident so it should not generate + // a wrapping `span`. + && !matches!(current_class, Class::PreludeTy(_)) { Some(enter_span(self.out, current_class, &self.href_context)) } else { @@ -333,7 +336,7 @@ enum Class { /// `Ident` isn't rendered in the HTML but we still need it for the `Span` it contains. Ident(Span), Lifetime, - PreludeTy, + PreludeTy(Span), PreludeVal, QuestionMark, Decoration(&'static str), @@ -381,7 +384,7 @@ impl Class { Class::Bool => "bool-val", Class::Ident(_) => "", Class::Lifetime => "lifetime", - Class::PreludeTy => "prelude-ty", + Class::PreludeTy(_) => "prelude-ty", Class::PreludeVal => "prelude-val", Class::QuestionMark => "question-mark", Class::Decoration(kind) => kind, @@ -392,7 +395,7 @@ impl Class { /// a "span" (a tuple representing `(lo, hi)` equivalent of `Span`). fn get_span(self) -> Option { match self { - Self::Ident(sp) | Self::Self_(sp) | Self::Macro(sp) => Some(sp), + Self::Ident(sp) | Self::Self_(sp) | Self::Macro(sp) | Self::PreludeTy(sp) => Some(sp), Self::Comment | Self::DocComment | Self::Attribute @@ -403,7 +406,6 @@ impl Class { | Self::Number | Self::Bool | Self::Lifetime - | Self::PreludeTy | Self::PreludeVal | Self::QuestionMark | Self::Decoration(_) => None, @@ -411,6 +413,7 @@ impl Class { } } +#[derive(Debug)] enum Highlight<'a> { Token { text: &'a str, class: Option }, EnterSpan { class: Class }, @@ -847,7 +850,7 @@ impl<'src> Classifier<'src> { } TokenKind::Ident => match get_real_ident_class(text, false) { None => match text { - "Option" | "Result" => Class::PreludeTy, + "Option" | "Result" => Class::PreludeTy(self.new_span(before, text)), "Some" | "None" | "Ok" | "Err" => Class::PreludeVal, // "union" is a weak keyword and is only considered as a keyword when declaring // a union type. From c8399255f3780072d1876ebed56decc7c78f378d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2024 16:33:38 +0100 Subject: [PATCH 05/15] Add regression test for prelude types --- tests/rustdoc/jump-to-def-prelude-types.rs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/rustdoc/jump-to-def-prelude-types.rs diff --git a/tests/rustdoc/jump-to-def-prelude-types.rs b/tests/rustdoc/jump-to-def-prelude-types.rs new file mode 100644 index 0000000000000..43617b1bc9df7 --- /dev/null +++ b/tests/rustdoc/jump-to-def-prelude-types.rs @@ -0,0 +1,23 @@ +// This test checks that prelude types like `Result` and `Option` still get a link generated. + +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/jump-to-def-prelude-types.rs.html' +// FIXME: would be nice to be able to check both the class and the href at the same time so +// we could check the text as well... +//@ has - '//a[@class="prelude-ty"]/@href' '{{channel}}/core/result/enum.Result.html' +//@ has - '//a[@class="prelude-ty"]/@href' '{{channel}}/core/option/enum.Option.html' +pub fn foo() -> Result, ()> { Err(()) } + +// This part is to ensure that they are not linking to the actual prelude ty. +pub mod bar { + struct Result; + struct Option; + + //@ has - '//a[@href="#16"]' 'Result' + pub fn bar() -> Result { Result } + //@ has - '//a[@href="#17"]' 'Option' + pub fn bar2() -> Option { Option } +} From bd44b632a84030138a5f0133fa2ae7ad30fe8266 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 24 Nov 2024 00:30:16 +0000 Subject: [PATCH 06/15] Constify Drop and Destruct --- library/core/src/marker.rs | 1 + library/core/src/ops/drop.rs | 2 +- .../ui/consts/const-block-const-bound.stderr | 28 +--- tests/ui/consts/fn_trait_refs.stderr | 126 ++++-------------- tests/ui/consts/promoted-const-drop.rs | 1 - tests/ui/consts/promoted-const-drop.stderr | 15 +-- tests/ui/consts/promoted_const_call.stderr | 11 +- tests/ui/dropck/const_drop_is_valid.rs | 8 -- tests/ui/dropck/const_drop_is_valid.stderr | 31 ----- .../impl-trait/normalize-tait-in-const.stderr | 29 +--- .../const-traits/const-drop-bound.stderr | 56 +------- .../const-drop-fail-2.precise.stderr | 33 ++--- .../traits/const-traits/const-drop-fail-2.rs | 11 +- .../const-traits/const-drop-fail-2.stderr | 41 ------ .../const-drop-fail-2.stock.stderr | 33 ++--- .../const-drop-fail.precise.stderr | 69 +--------- .../ui/traits/const-traits/const-drop-fail.rs | 6 +- .../const-traits/const-drop-fail.stock.stderr | 50 ++++--- .../const-traits/const-drop.precise.stderr | 100 -------------- tests/ui/traits/const-traits/const-drop.rs | 7 +- .../const-traits/const-drop.stock.stderr | 100 -------------- tests/ui/traits/const-traits/issue-92111.rs | 5 +- .../ui/traits/const-traits/issue-92111.stderr | 25 ---- 23 files changed, 113 insertions(+), 675 deletions(-) delete mode 100644 tests/ui/dropck/const_drop_is_valid.rs delete mode 100644 tests/ui/dropck/const_drop_is_valid.stderr delete mode 100644 tests/ui/traits/const-traits/const-drop-fail-2.stderr delete mode 100644 tests/ui/traits/const-traits/const-drop.precise.stderr delete mode 100644 tests/ui/traits/const-traits/const-drop.stock.stderr delete mode 100644 tests/ui/traits/const-traits/issue-92111.stderr diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index acbad07746bb9..1620b949590d0 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -957,6 +957,7 @@ marker_impls! { #[lang = "destruct"] #[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)] #[rustc_deny_explicit_impl(implement_via_object = false)] +#[cfg_attr(not(bootstrap), const_trait)] pub trait Destruct {} /// A marker for tuple types. diff --git a/library/core/src/ops/drop.rs b/library/core/src/ops/drop.rs index a6f63ad68d695..f3314364e5428 100644 --- a/library/core/src/ops/drop.rs +++ b/library/core/src/ops/drop.rs @@ -203,7 +203,7 @@ /// [nomicon]: ../../nomicon/phantom-data.html#an-exception-the-special-case-of-the-standard-library-and-its-unstable-may_dangle #[lang = "drop"] #[stable(feature = "rust1", since = "1.0.0")] -// FIXME(const_trait_impl) #[const_trait] +#[cfg_attr(not(bootstrap), const_trait)] pub trait Drop { /// Executes the destructor for this type. /// diff --git a/tests/ui/consts/const-block-const-bound.stderr b/tests/ui/consts/const-block-const-bound.stderr index 5e24959146b83..b2b2f62c58f27 100644 --- a/tests/ui/consts/const-block-const-bound.stderr +++ b/tests/ui/consts/const-block-const-bound.stderr @@ -1,25 +1,9 @@ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-block-const-bound.rs:8:15 +error[E0277]: the trait bound `UnconstDrop: const Destruct` is not satisfied + --> $DIR/const-block-const-bound.rs:18:9 | -LL | const fn f(x: T) {} - | ^^^^^^ +LL | f(UnconstDrop); + | ^^^^^^^^^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-block-const-bound.rs:8:15 - | -LL | const fn f(x: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-block-const-bound.rs:8:32 - | -LL | const fn f(x: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0493`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/consts/fn_trait_refs.stderr b/tests/ui/consts/fn_trait_refs.stderr index dc601fbe48897..108500217139e 100644 --- a/tests/ui/consts/fn_trait_refs.stderr +++ b/tests/ui/consts/fn_trait_refs.stderr @@ -16,12 +16,6 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | T: ~const Fn<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:14:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:14:8 | @@ -38,26 +32,12 @@ LL | T: ~const Fn<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:14:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:21:8 | LL | T: ~const FnMut<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:21:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:21:8 | @@ -74,14 +54,6 @@ LL | T: ~const FnMut<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:21:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:28:8 | @@ -110,12 +82,6 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | T: ~const Fn<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:35:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:35:8 | @@ -132,26 +98,12 @@ LL | T: ~const Fn<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:35:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:49:8 | LL | T: ~const FnMut<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:49:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:49:8 | @@ -168,29 +120,35 @@ LL | T: ~const FnMut<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:49:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ +error[E0277]: the trait bound `fn() -> i32 {one}: const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:70:24 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +LL | let test_one = test_fn(one); + | ^^^^^^^^^^^^ -error[E0015]: cannot call non-const operator in constants - --> $DIR/fn_trait_refs.rs:71:17 +error[E0277]: the trait bound `fn() -> i32 {two}: const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:73:24 | -LL | assert!(test_one == (1, 1, 1)); - | ^^^^^^^^^^^^^^^^^^^^^ +LL | let test_two = test_fn_mut(two); + | ^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `&T: ~const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:39:9 | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | tester_fn(&f), + | ^^^^^^^^^^^^^ -error[E0015]: cannot call non-const operator in constants - --> $DIR/fn_trait_refs.rs:74:17 +error[E0277]: the trait bound `&T: ~const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:41:9 | -LL | assert!(test_two == (2, 2)); - | ^^^^^^^^^^^^^^^^^^ +LL | tester_fn_mut(&f), + | ^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `&mut T: ~const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:53:9 | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | tester_fn_mut(&mut f), + | ^^^^^^^^^^^^^^^^^^^^^ error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:16:5 @@ -204,15 +162,6 @@ help: consider further restricting this bound LL | T: ~const Fn<()> + ~const Destruct + ~const Fn(), | +++++++++++++ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:12:23 - | -LL | const fn tester_fn(f: T) -> T::Output - | ^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:23:5 | @@ -225,15 +174,6 @@ help: consider further restricting this bound LL | T: ~const FnMut<()> + ~const Destruct + ~const FnMut(), | ++++++++++++++++ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:19:27 - | -LL | const fn tester_fn_mut(mut f: T) -> T::Output - | ^^^^^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:30:5 | @@ -246,25 +186,7 @@ help: consider further restricting this bound LL | T: ~const FnOnce<()> + ~const FnOnce(), | +++++++++++++++++ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:33:21 - | -LL | const fn test_fn(mut f: T) -> (T::Output, T::Output, T::Output) - | ^^^^^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:47:25 - | -LL | const fn test_fn_mut(mut f: T) -> (T::Output, T::Output) - | ^^^^^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - -error: aborting due to 34 previous errors +error: aborting due to 25 previous errors -Some errors have detailed explanations: E0015, E0493, E0635. +Some errors have detailed explanations: E0015, E0277, E0635. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/consts/promoted-const-drop.rs b/tests/ui/consts/promoted-const-drop.rs index c6ea0d0c924da..e09c30ea7857b 100644 --- a/tests/ui/consts/promoted-const-drop.rs +++ b/tests/ui/consts/promoted-const-drop.rs @@ -3,7 +3,6 @@ struct A(); impl const Drop for A { - //~^ ERROR const `impl` for trait `Drop` which is not marked with `#[const_trait]` fn drop(&mut self) {} } diff --git a/tests/ui/consts/promoted-const-drop.stderr b/tests/ui/consts/promoted-const-drop.stderr index e015f75620690..3f2182e7d4105 100644 --- a/tests/ui/consts/promoted-const-drop.stderr +++ b/tests/ui/consts/promoted-const-drop.stderr @@ -1,14 +1,5 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/promoted-const-drop.rs:5:12 - | -LL | impl const Drop for A { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - error[E0716]: temporary value dropped while borrowed - --> $DIR/promoted-const-drop.rs:13:26 + --> $DIR/promoted-const-drop.rs:12:26 | LL | let _: &'static A = &A(); | ---------- ^^^ creates a temporary value which is freed while still in use @@ -19,7 +10,7 @@ LL | } | - temporary value is freed at the end of this statement error[E0716]: temporary value dropped while borrowed - --> $DIR/promoted-const-drop.rs:14:28 + --> $DIR/promoted-const-drop.rs:13:28 | LL | let _: &'static [A] = &[C]; | ------------ ^^^ creates a temporary value which is freed while still in use @@ -28,6 +19,6 @@ LL | let _: &'static [A] = &[C]; LL | } | - temporary value is freed at the end of this statement -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0716`. diff --git a/tests/ui/consts/promoted_const_call.stderr b/tests/ui/consts/promoted_const_call.stderr index 7a96b6e770582..dd70bb601c47d 100644 --- a/tests/ui/consts/promoted_const_call.stderr +++ b/tests/ui/consts/promoted_const_call.stderr @@ -1,12 +1,3 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/promoted_const_call.rs:6:12 - | -LL | impl const Drop for Panic { fn drop(&mut self) { panic!(); } } - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - error[E0493]: destructor of `Panic` cannot be evaluated at compile-time --> $DIR/promoted_const_call.rs:10:30 | @@ -57,7 +48,7 @@ LL | let _: &'static _ = &&(Panic, 0).1; LL | } | - temporary value is freed at the end of this statement -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0493, E0716. For more information about an error, try `rustc --explain E0493`. diff --git a/tests/ui/dropck/const_drop_is_valid.rs b/tests/ui/dropck/const_drop_is_valid.rs deleted file mode 100644 index 26ef2d61deb69..0000000000000 --- a/tests/ui/dropck/const_drop_is_valid.rs +++ /dev/null @@ -1,8 +0,0 @@ -struct A(); - -impl const Drop for A {} -//~^ ERROR: const trait impls are experimental -//~| const `impl` for trait `Drop` which is not marked with `#[const_trait]` -//~| not all trait items implemented, missing: `drop` - -fn main() {} diff --git a/tests/ui/dropck/const_drop_is_valid.stderr b/tests/ui/dropck/const_drop_is_valid.stderr deleted file mode 100644 index 5837e1623a170..0000000000000 --- a/tests/ui/dropck/const_drop_is_valid.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error[E0658]: const trait impls are experimental - --> $DIR/const_drop_is_valid.rs:3:6 - | -LL | impl const Drop for A {} - | ^^^^^ - | - = note: see issue #67792 for more information - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const_drop_is_valid.rs:3:12 - | -LL | impl const Drop for A {} - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error[E0046]: not all trait items implemented, missing: `drop` - --> $DIR/const_drop_is_valid.rs:3:1 - | -LL | impl const Drop for A {} - | ^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation - | - = help: implement the missing item: `fn drop(&mut self) { todo!() }` - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0046, E0658. -For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index f9142664f1b82..bb874cbe41b33 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -4,12 +4,6 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:26:62 - | -LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/normalize-tait-in-const.rs:26:35 | @@ -18,13 +12,11 @@ LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruc | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:26:62 - | -LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^ +error[E0277]: the trait bound `for<'a, 'b> fn(&'a foo::Alias<'b>) {foo}: const Destruct` is not satisfied + --> $DIR/normalize-tait-in-const.rs:33:5 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +LL | with_positive(foo); + | ^^^^^^^^^^^^^^^^^^ error[E0015]: cannot call non-const closure in constant functions --> $DIR/normalize-tait-in-const.rs:27:5 @@ -38,16 +30,7 @@ help: consider further restricting this bound LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) { | ++++++++++++++++++++++++++++ -error[E0493]: destructor of `F` cannot be evaluated at compile-time - --> $DIR/normalize-tait-in-const.rs:26:79 - | -LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^ the destructor for this type cannot be evaluated in constant functions -LL | fun(filter_positive()); -LL | } - | - value is dropped here - -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0015, E0493. +Some errors have detailed explanations: E0015, E0277. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/const-drop-bound.stderr b/tests/ui/traits/const-traits/const-drop-bound.stderr index eba39f859af52..60718cc84c101 100644 --- a/tests/ui/traits/const-traits/const-drop-bound.stderr +++ b/tests/ui/traits/const-traits/const-drop-bound.stderr @@ -1,53 +1,9 @@ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:9:61 +error[E0277]: the trait bound `Foo: ~const Destruct` is not satisfied + --> $DIR/const-drop-bound.rs:23:5 | -LL | const fn foo(res: Result) -> Option where E: ~const Destruct { - | ^^^^^^ +LL | foo(res) + | ^^^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:9:61 - | -LL | const fn foo(res: Result) -> Option where E: ~const Destruct { - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:20:8 - | -LL | T: ~const Destruct, - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:21:8 - | -LL | E: ~const Destruct, - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:20:8 - | -LL | T: ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:21:8 - | -LL | E: ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `E` cannot be evaluated at compile-time - --> $DIR/const-drop-bound.rs:12:13 - | -LL | Err(_e) => None, - | ^^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 7 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0493`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr index 7529af9293d44..bb9966c7ec393 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr @@ -1,26 +1,13 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:23:25 +error[E0277]: the trait bound `ConstDropImplWithBounds: const Destruct` is not satisfied + --> $DIR/const-drop-fail-2.rs:31:15 | -LL | impl const Drop for ConstDropImplWithBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:29:26 - | -LL | const fn check(_: T) {} - | ^^^^^^^^ - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:39:25 - | -LL | impl const Drop for ConstDropImplWithNonConstBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change +LL | const _: () = check::>( + | _______________^ +LL | | +LL | | ConstDropImplWithBounds(PhantomData) +LL | | ); + | |_^ -error: aborting due to 3 previous errors +error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.rs b/tests/ui/traits/const-traits/const-drop-fail-2.rs index ed4faa95bd049..1bcc87e907037 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.rs +++ b/tests/ui/traits/const-traits/const-drop-fail-2.rs @@ -1,6 +1,7 @@ -//@ known-bug: #110395 +//@ revisions: stock precise + #![feature(const_trait_impl, const_destruct)] -// #![cfg_attr(precise, feature(const_precise_live_drops))] +#![cfg_attr(precise, feature(const_precise_live_drops))] use std::marker::{Destruct, PhantomData}; @@ -19,9 +20,7 @@ impl A for NonTrivialDrop {} const fn check(_: T) {} - -/* FIXME(const_trait_impl) -struct ConstDropImplWithBounds(PhantomData); +struct ConstDropImplWithBounds(PhantomData); impl const Drop for ConstDropImplWithBounds { fn drop(&mut self) { @@ -30,9 +29,9 @@ impl const Drop for ConstDropImplWithBounds { } const _: () = check::>( + //~^ ERROR the trait bound ConstDropImplWithBounds(PhantomData) ); -*/ struct ConstDropImplWithNonConstBounds(PhantomData); diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.stderr deleted file mode 100644 index fde106599c236..0000000000000 --- a/tests/ui/traits/const-traits/const-drop-fail-2.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:39:25 - | -LL | impl const Drop for ConstDropImplWithNonConstBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:20:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:20:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0277]: the trait bound `T: ~const A` is not satisfied - --> $DIR/const-drop-fail-2.rs:41:9 - | -LL | T::a(); - | ^^^^^^ - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail-2.rs:20:36 - | -LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0277, E0493. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr index 7529af9293d44..bb9966c7ec393 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr @@ -1,26 +1,13 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:23:25 +error[E0277]: the trait bound `ConstDropImplWithBounds: const Destruct` is not satisfied + --> $DIR/const-drop-fail-2.rs:31:15 | -LL | impl const Drop for ConstDropImplWithBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:29:26 - | -LL | const fn check(_: T) {} - | ^^^^^^^^ - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:39:25 - | -LL | impl const Drop for ConstDropImplWithNonConstBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change +LL | const _: () = check::>( + | _______________^ +LL | | +LL | | ConstDropImplWithBounds(PhantomData) +LL | | ); + | |_^ -error: aborting due to 3 previous errors +error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail.precise.stderr b/tests/ui/traits/const-traits/const-drop-fail.precise.stderr index 91ca60b750d81..67e774fbd0597 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.precise.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail.precise.stderr @@ -1,47 +1,4 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail.rs:19:12 - | -LL | impl const Drop for ConstImplWithDropGlue { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail.rs:23:36 - | -LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0080]: evaluation of constant value failed - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | - = note: calling non-const function `::drop` - | -note: inside `std::ptr::drop_in_place:: - shim(Some(NonTrivialDrop))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `check::` - --> $DIR/const-drop-fail.rs:23:43 - | -LL | const fn check(_: T) {} - | ^ -note: inside `_` +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied --> $DIR/const-drop-fail.rs:27:23 | LL | const _: () = check($exp); @@ -52,23 +9,10 @@ LL | | NonTrivialDrop, LL | | ConstImplWithDropGlue(NonTrivialDrop), LL | | } | |_- in this macro invocation + | = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0080]: evaluation of constant value failed - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | - = note: calling non-const function `::drop` - | -note: inside `std::ptr::drop_in_place:: - shim(Some(NonTrivialDrop))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `std::ptr::drop_in_place:: - shim(Some(ConstImplWithDropGlue))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `check::` - --> $DIR/const-drop-fail.rs:23:43 - | -LL | const fn check(_: T) {} - | ^ -note: inside `_` +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied --> $DIR/const-drop-fail.rs:27:23 | LL | const _: () = check($exp); @@ -79,9 +23,10 @@ LL | | NonTrivialDrop, LL | | ConstImplWithDropGlue(NonTrivialDrop), LL | | } | |_- in this macro invocation + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 6 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0080, E0493. -For more information about an error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail.rs b/tests/ui/traits/const-traits/const-drop-fail.rs index c61afc0e17a3b..08435266e1f80 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.rs +++ b/tests/ui/traits/const-traits/const-drop-fail.rs @@ -1,6 +1,6 @@ -//@ known-bug: #110395 - +//@ compile-flags: -Znext-solver //@ revisions: stock precise + #![feature(const_trait_impl, const_destruct)] #![cfg_attr(precise, feature(const_precise_live_drops))] @@ -25,6 +25,8 @@ const fn check(_: T) {} macro_rules! check_all { ($($exp:expr),*$(,)?) => {$( const _: () = check($exp); + //~^ ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied + //~| ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied )*}; } diff --git a/tests/ui/traits/const-traits/const-drop-fail.stock.stderr b/tests/ui/traits/const-traits/const-drop-fail.stock.stderr index 20dea28922b6a..67e774fbd0597 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.stock.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail.stock.stderr @@ -1,34 +1,32 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail.rs:19:12 +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied + --> $DIR/const-drop-fail.rs:27:23 | -LL | impl const Drop for ConstImplWithDropGlue { - | ^^^^ +LL | const _: () = check($exp); + | ^^^^^^^^^^^ +... +LL | / check_all! { +LL | | NonTrivialDrop, +LL | | ConstImplWithDropGlue(NonTrivialDrop), +LL | | } + | |_- in this macro invocation | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change + = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied + --> $DIR/const-drop-fail.rs:27:23 | -LL | const fn check(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ +LL | const _: () = check($exp); + | ^^^^^^^^^^^ +... +LL | / check_all! { +LL | | NonTrivialDrop, +LL | | ConstImplWithDropGlue(NonTrivialDrop), +LL | | } + | |_- in this macro invocation | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail.rs:23:36 - | -LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0493`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop.precise.stderr b/tests/ui/traits/const-traits/const-drop.precise.stderr deleted file mode 100644 index 51a66396c4b42..0000000000000 --- a/tests/ui/traits/const-traits/const-drop.precise.stderr +++ /dev/null @@ -1,100 +0,0 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:12:16 - | -LL | impl<'a> const Drop for S<'a> { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:46:16 - | -LL | impl const Drop for ConstDrop { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:67:37 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:75:30 - | -LL | impl const Drop for ConstDropWithNonconstBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:67:46 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:68:22 - | -LL | fn drop(&mut self) { - | ^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:23:13 - | -LL | let _ = S(&mut c); - | ^^^^^^^^^- value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:18:32 - | -LL | const fn a(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:69:13 - | -LL | T::foo(); - | ^^^^^^^^ - -error: aborting due to 11 previous errors - -Some errors have detailed explanations: E0277, E0493. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop.rs b/tests/ui/traits/const-traits/const-drop.rs index 8bf1dd68b5c0a..e2d87aeff47fb 100644 --- a/tests/ui/traits/const-traits/const-drop.rs +++ b/tests/ui/traits/const-traits/const-drop.rs @@ -1,6 +1,7 @@ -// FIXME run-pass -//@ known-bug: #110395 +//@ run-pass +//@ compile-flags: -Znext-solver //@ revisions: stock precise + #![feature(const_trait_impl, const_destruct)] #![feature(never_type)] #![cfg_attr(precise, feature(const_precise_live_drops))] @@ -64,7 +65,7 @@ mod t { pub struct ConstDropWithBound(pub core::marker::PhantomData); - impl const Drop for ConstDropWithBound { + impl const Drop for ConstDropWithBound { fn drop(&mut self) { T::foo(); } diff --git a/tests/ui/traits/const-traits/const-drop.stock.stderr b/tests/ui/traits/const-traits/const-drop.stock.stderr deleted file mode 100644 index 51a66396c4b42..0000000000000 --- a/tests/ui/traits/const-traits/const-drop.stock.stderr +++ /dev/null @@ -1,100 +0,0 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:12:16 - | -LL | impl<'a> const Drop for S<'a> { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:46:16 - | -LL | impl const Drop for ConstDrop { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:67:37 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:75:30 - | -LL | impl const Drop for ConstDropWithNonconstBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:67:46 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:68:22 - | -LL | fn drop(&mut self) { - | ^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:23:13 - | -LL | let _ = S(&mut c); - | ^^^^^^^^^- value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:18:32 - | -LL | const fn a(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:69:13 - | -LL | T::foo(); - | ^^^^^^^^ - -error: aborting due to 11 previous errors - -Some errors have detailed explanations: E0277, E0493. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/issue-92111.rs b/tests/ui/traits/const-traits/issue-92111.rs index 64bf0f20e91d6..c8db5cc9e7ad8 100644 --- a/tests/ui/traits/const-traits/issue-92111.rs +++ b/tests/ui/traits/const-traits/issue-92111.rs @@ -1,7 +1,4 @@ -// Regression test for #92111. -// -//@ known-bug: #110395 -// FIXME check-pass +//@ check-pass #![feature(const_trait_impl, const_destruct)] diff --git a/tests/ui/traits/const-traits/issue-92111.stderr b/tests/ui/traits/const-traits/issue-92111.stderr deleted file mode 100644 index 51c6a22b43b3d..0000000000000 --- a/tests/ui/traits/const-traits/issue-92111.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/issue-92111.rs:20:15 - | -LL | const fn a(t: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/issue-92111.rs:20:15 - | -LL | const fn a(t: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/issue-92111.rs:20:32 - | -LL | const fn a(t: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0493`. From 58936c1d2ae3ccb65761e3bf779e79a85028029c Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 25 Nov 2024 19:41:13 +0100 Subject: [PATCH 07/15] fix gce typing_mode mismatch --- .../rustc_trait_selection/src/traits/mod.rs | 43 +++++++++-------- .../post-analysis-user-facing-param-env.rs | 18 ++++++++ ...post-analysis-user-facing-param-env.stderr | 46 +++++++++++++++++++ 3 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.stderr diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 7d6c38c11f318..069fab6a6e6b9 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -551,8 +551,18 @@ pub fn try_evaluate_const<'tcx>( | ty::ConstKind::Placeholder(_) | ty::ConstKind::Expr(_) => Err(EvaluateConstErr::HasGenericsOrInfers), ty::ConstKind::Unevaluated(uv) => { - // Postpone evaluation of constants that depend on generic parameters or inference variables. - let (args, param_env) = if tcx.features().generic_const_exprs() + // Postpone evaluation of constants that depend on generic parameters or + // inference variables. + // + // We use `TypingMode::PostAnalysis` here which is not *technically* correct + // to be revealing opaque types here as borrowcheck has not run yet. However, + // CTFE itself uses `TypingMode::PostAnalysis` unconditionally even during + // typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821). + // As a result we always use a revealed env when resolving the instance to evaluate. + // + // FIXME: `const_eval_resolve_for_typeck` should probably just modify the env itself + // instead of having this logic here + let (args, typing_env) = if tcx.features().generic_const_exprs() && uv.has_non_region_infer() { // `feature(generic_const_exprs)` causes anon consts to inherit all parent generics. This can cause @@ -568,13 +578,17 @@ pub fn try_evaluate_const<'tcx>( // the generic arguments provided for it, then we should *not* attempt to evaluate it. return Err(EvaluateConstErr::HasGenericsOrInfers); } else { - (replace_param_and_infer_args_with_placeholder(tcx, uv.args), param_env) + let args = replace_param_and_infer_args_with_placeholder(tcx, uv.args); + let typing_env = infcx + .typing_env(tcx.erase_regions(param_env)) + .with_post_analysis_normalized(tcx); + (args, typing_env) } } Err(_) | Ok(None) => { let args = GenericArgs::identity_for_item(tcx, uv.def); - let param_env = tcx.param_env(uv.def); - (args, param_env) + let typing_env = ty::TypingEnv::post_analysis(tcx, uv.def); + (args, typing_env) } } } else if tcx.def_kind(uv.def) == DefKind::AnonConst && uv.has_non_region_infer() { @@ -593,27 +607,20 @@ pub fn try_evaluate_const<'tcx>( ); let args = GenericArgs::identity_for_item(tcx, uv.def); - let param_env = tcx.param_env(uv.def); - (args, param_env) + let typing_env = ty::TypingEnv::post_analysis(tcx, uv.def); + (args, typing_env) } else { // FIXME: This codepath is reachable under `associated_const_equality` and in the // future will be reachable by `min_generic_const_args`. We should handle inference // variables and generic parameters properly instead of doing nothing. - (uv.args, param_env) + let typing_env = infcx + .typing_env(tcx.erase_regions(param_env)) + .with_post_analysis_normalized(tcx); + (uv.args, typing_env) }; let uv = ty::UnevaluatedConst::new(uv.def, args); - // It's not *technically* correct to be revealing opaque types here as borrowcheck has - // not run yet. However, CTFE itself uses `TypingMode::PostAnalysis` unconditionally even - // during typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821). - // As a result we always use a revealed env when resolving the instance to evaluate. - // - // FIXME: `const_eval_resolve_for_typeck` should probably just modify the env itself - // instead of having this logic here - let typing_env = - tcx.erase_regions(infcx.typing_env(param_env)).with_post_analysis_normalized(tcx); let erased_uv = tcx.erase_regions(uv); - use rustc_middle::mir::interpret::ErrorHandled; match tcx.const_eval_resolve_for_typeck(typing_env, erased_uv, DUMMY_SP) { Ok(Ok(val)) => Ok(ty::Const::new_value( diff --git a/tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.rs b/tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.rs new file mode 100644 index 0000000000000..e5af632da7577 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.rs @@ -0,0 +1,18 @@ +// Regression test for #133271. +#![feature(generic_const_exprs)] +//~^ WARN the feature `generic_const_exprs` is incomplete + +struct Foo; +impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo +//~^ ERROR the const parameter `NUM` is not constrained by the impl trait, self type, or predicates +where + [(); 1 + 0]: Sized, +{ + fn unimplemented(self, _: &Foo) -> Self::Output { + //~^ ERROR method `unimplemented` is not a member of trait `std::ops::Add` + //~| ERROR type annotations needed + loop {} + } +} + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.stderr b/tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.stderr new file mode 100644 index 0000000000000..ade18eb88b901 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.stderr @@ -0,0 +1,46 @@ +error[E0407]: method `unimplemented` is not a member of trait `std::ops::Add` + --> $DIR/post-analysis-user-facing-param-env.rs:11:5 + | +LL | / fn unimplemented(self, _: &Foo) -> Self::Output { +LL | | +LL | | +LL | | loop {} +LL | | } + | |_____^ not a member of trait `std::ops::Add` + +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/post-analysis-user-facing-param-env.rs:2:12 + | +LL | #![feature(generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0207]: the const parameter `NUM` is not constrained by the impl trait, self type, or predicates + --> $DIR/post-analysis-user-facing-param-env.rs:6:10 + | +LL | impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo + | ^^^^^^^^^^^^^^^^ unconstrained const parameter + | + = note: expressions using a const parameter must map each value to a distinct output value + = note: proving the result of expressions other than the parameter are unique is not supported + +error[E0284]: type annotations needed + --> $DIR/post-analysis-user-facing-param-env.rs:11:40 + | +LL | fn unimplemented(self, _: &Foo) -> Self::Output { + | ^^^^^^^^^^^^ cannot infer the value of const parameter `NUM` + | +note: required for `Foo` to implement `Add<&'a Foo>` + --> $DIR/post-analysis-user-facing-param-env.rs:6:28 + | +LL | impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo + | ---------------- ^^^^^^^^^^^^^^^^^^^^^^ ^^^ + | | + | unsatisfied trait bound introduced here + +error: aborting due to 3 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0207, E0284, E0407. +For more information about an error, try `rustc --explain E0207`. From 71789427a3b420fc4e729a748e1bf22d0a444bfa Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 22 Nov 2024 16:30:35 +1100 Subject: [PATCH 08/15] Improve `MaybeStorageLive::initialize_start_block`. We can union the two sets the easy way. This removes the need for the domain size check, because `union` does that same check itself. --- compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs index 576289e228ad0..1315d7aab4dd8 100644 --- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs @@ -28,10 +28,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageLive<'a> { } fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain) { - assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size()); - for local in self.always_live_locals.iter() { - on_entry.insert(local); - } + on_entry.union(&*self.always_live_locals); for arg in body.args_iter() { on_entry.insert(arg); From 3d12160dfcb4d95cd3f1eaa23071fb9b4e3d69ab Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 22 Nov 2024 17:52:02 +1100 Subject: [PATCH 09/15] Move `always_storage_live_locals`. It's very closely related to `MaybeStorageLive` and `MaybeStorageDead`. It's weird that it's currently in a different module. --- .../src/check_consts/check.rs | 3 +-- .../rustc_const_eval/src/interpret/stack.rs | 2 +- compiler/rustc_mir_dataflow/src/impls/mod.rs | 4 +++- .../src/impls/storage_liveness.rs | 17 ++++++++++++++++ compiler/rustc_mir_dataflow/src/lib.rs | 1 - compiler/rustc_mir_dataflow/src/storage.rs | 20 ------------------- compiler/rustc_mir_transform/src/coroutine.rs | 2 +- compiler/rustc_mir_transform/src/lint.rs | 3 +-- compiler/rustc_mir_transform/src/ref_prop.rs | 3 +-- 9 files changed, 25 insertions(+), 30 deletions(-) delete mode 100644 compiler/rustc_mir_dataflow/src/storage.rs diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 9f21c8644876f..916929b6c0bb9 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -18,8 +18,7 @@ use rustc_middle::span_bug; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::{self, Ty, TypeVisitableExt}; use rustc_mir_dataflow::Analysis; -use rustc_mir_dataflow::impls::MaybeStorageLive; -use rustc_mir_dataflow::storage::always_storage_live_locals; +use rustc_mir_dataflow::impls::{MaybeStorageLive, always_storage_live_locals}; use rustc_span::{Span, Symbol, sym}; use rustc_trait_selection::traits::{ Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt, diff --git a/compiler/rustc_const_eval/src/interpret/stack.rs b/compiler/rustc_const_eval/src/interpret/stack.rs index 8ce11c71b8bd3..a9ebf38661703 100644 --- a/compiler/rustc_const_eval/src/interpret/stack.rs +++ b/compiler/rustc_const_eval/src/interpret/stack.rs @@ -10,7 +10,7 @@ use rustc_index::IndexVec; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, mir}; -use rustc_mir_dataflow::storage::always_storage_live_locals; +use rustc_mir_dataflow::impls::always_storage_live_locals; use rustc_span::Span; use tracing::{info_span, instrument, trace}; diff --git a/compiler/rustc_mir_dataflow/src/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs index 9b5bfa9bfa00a..5b7866ace461a 100644 --- a/compiler/rustc_mir_dataflow/src/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -15,4 +15,6 @@ pub use self::initialized::{ pub use self::liveness::{ MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction, }; -pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive}; +pub use self::storage_liveness::{ + MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive, always_storage_live_locals, +}; diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs index 1315d7aab4dd8..9c18ab43bd934 100644 --- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs @@ -7,6 +7,23 @@ use rustc_middle::mir::*; use super::MaybeBorrowedLocals; use crate::{Analysis, GenKill, ResultsCursor}; +/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations. +/// +/// These locals have fixed storage for the duration of the body. +pub fn always_storage_live_locals(body: &Body<'_>) -> BitSet { + let mut always_live_locals = BitSet::new_filled(body.local_decls.len()); + + for block in &*body.basic_blocks { + for statement in &block.statements { + if let StatementKind::StorageLive(l) | StatementKind::StorageDead(l) = statement.kind { + always_live_locals.remove(l); + } + } + } + + always_live_locals +} + pub struct MaybeStorageLive<'a> { always_live_locals: Cow<'a, BitSet>, } diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index 7ef7c541173c3..e33f65ff77491 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -33,7 +33,6 @@ pub mod impls; pub mod move_paths; pub mod points; pub mod rustc_peek; -pub mod storage; pub mod un_derefer; pub mod value_analysis; diff --git a/compiler/rustc_mir_dataflow/src/storage.rs b/compiler/rustc_mir_dataflow/src/storage.rs deleted file mode 100644 index e5a0e1d312eae..0000000000000 --- a/compiler/rustc_mir_dataflow/src/storage.rs +++ /dev/null @@ -1,20 +0,0 @@ -use rustc_index::bit_set::BitSet; -use rustc_middle::mir::{self, Local}; - -/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations. -/// -/// These locals have fixed storage for the duration of the body. -pub fn always_storage_live_locals(body: &mir::Body<'_>) -> BitSet { - let mut always_live_locals = BitSet::new_filled(body.local_decls.len()); - - for block in &*body.basic_blocks { - for statement in &block.statements { - use mir::StatementKind::{StorageDead, StorageLive}; - if let StorageLive(l) | StorageDead(l) = statement.kind { - always_live_locals.remove(l); - } - } - } - - always_live_locals -} diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 8295a806d7125..f262912fab13b 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -70,8 +70,8 @@ use rustc_middle::ty::{ use rustc_middle::{bug, span_bug}; use rustc_mir_dataflow::impls::{ MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, + always_storage_live_locals, }; -use rustc_mir_dataflow::storage::always_storage_live_locals; use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor}; use rustc_span::Span; use rustc_span::def_id::{DefId, LocalDefId}; diff --git a/compiler/rustc_mir_transform/src/lint.rs b/compiler/rustc_mir_transform/src/lint.rs index d8ff1cfc90b58..29e762af8de35 100644 --- a/compiler/rustc_mir_transform/src/lint.rs +++ b/compiler/rustc_mir_transform/src/lint.rs @@ -9,8 +9,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; -use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive}; -use rustc_mir_dataflow::storage::always_storage_live_locals; +use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive, always_storage_live_locals}; use rustc_mir_dataflow::{Analysis, ResultsCursor}; pub(super) fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String) { diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs index af438ac2177ed..96bcdfa6fac47 100644 --- a/compiler/rustc_mir_transform/src/ref_prop.rs +++ b/compiler/rustc_mir_transform/src/ref_prop.rs @@ -8,8 +8,7 @@ use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use rustc_mir_dataflow::Analysis; -use rustc_mir_dataflow::impls::MaybeStorageDead; -use rustc_mir_dataflow::storage::always_storage_live_locals; +use rustc_mir_dataflow::impls::{MaybeStorageDead, always_storage_live_locals}; use tracing::{debug, instrument}; use crate::ssa::{SsaLocals, StorageLiveLocals}; From e3ef2ff05fc8e99f9a187e788713c65486f04d16 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 25 Nov 2024 06:50:55 +1100 Subject: [PATCH 10/15] Streamline a `BitSet` creation. --- compiler/rustc_mir_transform/src/coroutine.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index f262912fab13b..7fbb5d70d6692 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -697,8 +697,7 @@ fn locals_live_across_suspend_points<'tcx>( let loc = Location { block, statement_index: data.statements.len() }; liveness.seek_to_block_end(block); - let mut live_locals: BitSet<_> = BitSet::new_empty(body.local_decls.len()); - live_locals.union(liveness.get()); + let mut live_locals = liveness.get().clone(); if !movable { // The `liveness` variable contains the liveness of MIR locals ignoring borrows. From a602cb666a7362830849a9ae5308493a73839220 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 25 Nov 2024 15:38:54 +1100 Subject: [PATCH 11/15] Make some modules non-`pub`. - drop_flag_effects: `pub` items within are all re-exported in `lib.rs`. - un_derefer: doesn't contain any `pub` items. --- compiler/rustc_mir_dataflow/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index e33f65ff77491..2248972ceccb4 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -25,7 +25,7 @@ pub use self::framework::{ use self::move_paths::MoveData; pub mod debuginfo; -pub mod drop_flag_effects; +mod drop_flag_effects; pub mod elaborate_drops; mod errors; mod framework; @@ -33,7 +33,7 @@ pub mod impls; pub mod move_paths; pub mod points; pub mod rustc_peek; -pub mod un_derefer; +mod un_derefer; pub mod value_analysis; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } From 7fa021ad86fb62753576332a1a52b78acac492f9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 1 May 2023 09:56:39 +0000 Subject: [PATCH 12/15] Remove -Zfuel. --- compiler/rustc_driver_impl/src/lib.rs | 4 -- compiler/rustc_interface/src/tests.rs | 2 - compiler/rustc_middle/src/ty/context.rs | 4 -- compiler/rustc_middle/src/ty/mod.rs | 5 +- compiler/rustc_mir_transform/src/dest_prop.rs | 5 -- .../src/early_otherwise_branch.rs | 4 -- compiler/rustc_mir_transform/src/inline.rs | 6 -- .../rustc_mir_transform/src/instsimplify.rs | 71 ++++--------------- .../rustc_mir_transform/src/match_branches.rs | 5 -- .../src/multiple_return_terminators.rs | 7 +- compiler/rustc_mir_transform/src/nrvo.rs | 4 -- .../src/remove_unneeded_drops.rs | 5 -- .../rustc_mir_transform/src/remove_zsts.rs | 12 +--- .../src/unreachable_prop.rs | 6 -- compiler/rustc_session/messages.ftl | 2 - compiler/rustc_session/src/config.rs | 8 --- compiler/rustc_session/src/errors.rs | 6 -- compiler/rustc_session/src/options.rs | 20 ------ compiler/rustc_session/src/session.rs | 59 +-------------- tests/ui/fuel/optimization-fuel-0.rs | 17 ----- tests/ui/fuel/optimization-fuel-0.stderr | 4 -- tests/ui/fuel/optimization-fuel-1.rs | 18 ----- tests/ui/fuel/optimization-fuel-1.stderr | 4 -- tests/ui/fuel/print-fuel.rs | 13 ---- tests/ui/fuel/print-fuel.stderr | 1 - tests/ui/lint/issue-79546-fuel-ice.rs | 8 --- 26 files changed, 19 insertions(+), 281 deletions(-) delete mode 100644 tests/ui/fuel/optimization-fuel-0.rs delete mode 100644 tests/ui/fuel/optimization-fuel-0.stderr delete mode 100644 tests/ui/fuel/optimization-fuel-1.rs delete mode 100644 tests/ui/fuel/optimization-fuel-1.stderr delete mode 100644 tests/ui/fuel/print-fuel.rs delete mode 100644 tests/ui/fuel/print-fuel.stderr delete mode 100644 tests/ui/lint/issue-79546-fuel-ice.rs diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index c270ce16726d1..256266d2965d4 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -472,10 +472,6 @@ fn run_compiler( linker.link(sess, codegen_backend)? } - if let Some(fuel) = sess.opts.unstable_opts.print_fuel.as_deref() { - eprintln!("Fuel used by {}: {}", fuel, sess.print_fuel.load(Ordering::SeqCst)); - } - Ok(()) }) } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index e48c4d46b597c..6beae14100d9a 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -784,7 +784,6 @@ fn test_unstable_options_tracking_hash() { tracked!(flatten_format_args, false); tracked!(fmt_debug, FmtDebug::Shallow); tracked!(force_unstable_if_unmarked, true); - tracked!(fuel, Some(("abc".to_string(), 99))); tracked!(function_return, FunctionReturn::ThunkExtern); tracked!(function_sections, Some(false)); tracked!(human_readable_cgu_names, true); @@ -830,7 +829,6 @@ fn test_unstable_options_tracking_hash() { tracked!(plt, Some(true)); tracked!(polonius, Polonius::Legacy); tracked!(precise_enum_drop_elaboration, false); - tracked!(print_fuel, Some("abc".to_string())); tracked!(profile_sample_use, Some(PathBuf::from("abc"))); tracked!(profiler_runtime, "abc".to_string()); tracked!(regparm, Some(3)); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d982122e2aa4b..5bf62a17c8e08 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1566,10 +1566,6 @@ impl<'tcx> TyCtxt<'tcx> { } } - pub fn consider_optimizing String>(self, msg: T) -> bool { - self.sess.consider_optimizing(|| self.crate_name(LOCAL_CRATE), msg) - } - /// Obtain all lang items of this crate and all dependencies (recursively) pub fn lang_items(self) -> &'tcx rustc_hir::lang_items::LanguageItems { self.get_lang_items(()) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2b5327019045f..c7a2223ecd78b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1558,10 +1558,7 @@ impl<'tcx> TyCtxt<'tcx> { let is_box = self.is_lang_item(did.to_def_id(), LangItem::OwnedBox); // This is here instead of layout because the choice must make it into metadata. - if is_box - || !self - .consider_optimizing(|| format!("Reorder fields of {:?}", self.def_path_str(did))) - { + if is_box { flags.insert(ReprFlags::IS_LINEAR); } diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index 9c74b2f083943..8f977d2979ec3 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -217,11 +217,6 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation { else { continue; }; - if !tcx.consider_optimizing(|| { - format!("{} round {}", tcx.def_path_str(def_id), round_count) - }) { - break; - } // Replace `src` by `dest` everywhere. merges.insert(*src, *dest); diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index 704ed508b22a8..17c8348140a3e 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -108,10 +108,6 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { let parent = BasicBlock::from_usize(i); let Some(opt_data) = evaluate_candidate(tcx, body, parent) else { continue }; - if !tcx.consider_optimizing(|| format!("EarlyOtherwiseBranch {opt_data:?}")) { - break; - } - trace!("SUCCESS: found optimization possibility to apply: {opt_data:?}"); should_cleanup = true; diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 00f6c3845d41e..0878fa26a92c6 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -210,12 +210,6 @@ impl<'tcx> Inliner<'tcx> { let callee_body = try_instance_mir(self.tcx, callsite.callee.def)?; self.check_mir_body(callsite, callee_body, callee_attrs, cross_crate_inlinable)?; - if !self.tcx.consider_optimizing(|| { - format!("Inline {:?} into {:?}", callsite.callee, caller_body.source) - }) { - return Err("optimization fuel exhausted"); - } - let Ok(callee_body) = callsite.callee.try_instantiate_mir_and_normalize_erasing_regions( self.tcx, self.typing_env, diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index 3352d583f2ce4..a6ba2f32d32d2 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -7,8 +7,8 @@ use rustc_middle::bug; use rustc_middle::mir::*; use rustc_middle::ty::layout::ValidityRequirement; use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, layout}; -use rustc_span::sym; use rustc_span::symbol::Symbol; +use rustc_span::{DUMMY_SP, sym}; use crate::simplify::simplify_duplicate_switch_targets; use crate::take_array; @@ -43,12 +43,12 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify { match statement.kind { StatementKind::Assign(box (_place, ref mut rvalue)) => { if !preserve_ub_checks { - ctx.simplify_ub_check(&statement.source_info, rvalue); + ctx.simplify_ub_check(rvalue); } - ctx.simplify_bool_cmp(&statement.source_info, rvalue); - ctx.simplify_ref_deref(&statement.source_info, rvalue); - ctx.simplify_len(&statement.source_info, rvalue); - ctx.simplify_ptr_aggregate(&statement.source_info, rvalue); + ctx.simplify_bool_cmp(rvalue); + ctx.simplify_ref_deref(rvalue); + ctx.simplify_len(rvalue); + ctx.simplify_ptr_aggregate(rvalue); ctx.simplify_cast(rvalue); } _ => {} @@ -70,23 +70,8 @@ struct InstSimplifyContext<'a, 'tcx> { } impl<'tcx> InstSimplifyContext<'_, 'tcx> { - fn should_simplify(&self, source_info: &SourceInfo, rvalue: &Rvalue<'tcx>) -> bool { - self.should_simplify_custom(source_info, "Rvalue", rvalue) - } - - fn should_simplify_custom( - &self, - source_info: &SourceInfo, - label: &str, - value: impl std::fmt::Debug, - ) -> bool { - self.tcx.consider_optimizing(|| { - format!("InstSimplify - {label}: {value:?} SourceInfo: {source_info:?}") - }) - } - /// Transform boolean comparisons into logical operations. - fn simplify_bool_cmp(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { + fn simplify_bool_cmp(&self, rvalue: &mut Rvalue<'tcx>) { match rvalue { Rvalue::BinaryOp(op @ (BinOp::Eq | BinOp::Ne), box (a, b)) => { let new = match (op, self.try_eval_bool(a), self.try_eval_bool(b)) { @@ -117,9 +102,7 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { _ => None, }; - if let Some(new) = new - && self.should_simplify(source_info, rvalue) - { + if let Some(new) = new { *rvalue = new; } } @@ -134,17 +117,13 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { } /// Transform `&(*a)` ==> `a`. - fn simplify_ref_deref(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { + fn simplify_ref_deref(&self, rvalue: &mut Rvalue<'tcx>) { if let Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) = rvalue { if let Some((base, ProjectionElem::Deref)) = place.as_ref().last_projection() { if rvalue.ty(self.local_decls, self.tcx) != base.ty(self.local_decls, self.tcx).ty { return; } - if !self.should_simplify(source_info, rvalue) { - return; - } - *rvalue = Rvalue::Use(Operand::Copy(Place { local: base.local, projection: self.tcx.mk_place_elems(base.projection), @@ -154,36 +133,24 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { } /// Transform `Len([_; N])` ==> `N`. - fn simplify_len(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { + fn simplify_len(&self, rvalue: &mut Rvalue<'tcx>) { if let Rvalue::Len(ref place) = *rvalue { let place_ty = place.ty(self.local_decls, self.tcx).ty; if let ty::Array(_, len) = *place_ty.kind() { - if !self.should_simplify(source_info, rvalue) { - return; - } - let const_ = Const::from_ty_const(len, self.tcx.types.usize, self.tcx); - let constant = ConstOperand { span: source_info.span, const_, user_ty: None }; + let constant = ConstOperand { span: DUMMY_SP, const_, user_ty: None }; *rvalue = Rvalue::Use(Operand::Constant(Box::new(constant))); } } } /// Transform `Aggregate(RawPtr, [p, ()])` ==> `Cast(PtrToPtr, p)`. - fn simplify_ptr_aggregate(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { + fn simplify_ptr_aggregate(&self, rvalue: &mut Rvalue<'tcx>) { if let Rvalue::Aggregate(box AggregateKind::RawPtr(pointee_ty, mutability), fields) = rvalue { let meta_ty = fields.raw[1].ty(self.local_decls, self.tcx); if meta_ty.is_unit() { // The mutable borrows we're holding prevent printing `rvalue` here - if !self.should_simplify_custom( - source_info, - "Aggregate::RawPtr", - (&pointee_ty, *mutability, &fields), - ) { - return; - } - let mut fields = std::mem::take(fields); let _meta = fields.pop().unwrap(); let data = fields.pop().unwrap(); @@ -193,10 +160,10 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { } } - fn simplify_ub_check(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { + fn simplify_ub_check(&self, rvalue: &mut Rvalue<'tcx>) { if let Rvalue::NullaryOp(NullOp::UbChecks, _) = *rvalue { let const_ = Const::from_bool(self.tcx, self.tcx.sess.ub_checks()); - let constant = ConstOperand { span: source_info.span, const_, user_ty: None }; + let constant = ConstOperand { span: DUMMY_SP, const_, user_ty: None }; *rvalue = Rvalue::Use(Operand::Constant(Box::new(constant))); } } @@ -284,16 +251,6 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { return; } - if !self.tcx.consider_optimizing(|| { - format!( - "InstSimplify - Call: {:?} SourceInfo: {:?}", - (fn_def_id, fn_args), - terminator.source_info - ) - }) { - return; - } - let Ok([arg]) = take_array(args) else { return }; let Some(arg_place) = arg.node.place() else { return }; diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index ff027680c4922..20e2a65b311c5 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -18,16 +18,11 @@ impl<'tcx> crate::MirPass<'tcx> for MatchBranchSimplification { } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let def_id = body.source.def_id(); let typing_env = body.typing_env(tcx); let mut should_cleanup = false; for i in 0..body.basic_blocks.len() { let bbs = &*body.basic_blocks; let bb_idx = BasicBlock::from_usize(i); - if !tcx.consider_optimizing(|| format!("MatchBranchSimplification {def_id:?} ")) { - continue; - } - match bbs[bb_idx].terminator().kind { TerminatorKind::SwitchInt { discr: ref _discr @ (Operand::Copy(_) | Operand::Move(_)), diff --git a/compiler/rustc_mir_transform/src/multiple_return_terminators.rs b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs index b6d6ef5de1da9..a9227524ce5e5 100644 --- a/compiler/rustc_mir_transform/src/multiple_return_terminators.rs +++ b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs @@ -14,10 +14,9 @@ impl<'tcx> crate::MirPass<'tcx> for MultipleReturnTerminators { sess.mir_opt_level() >= 4 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // find basic blocks with no statement and a return terminator let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks.len()); - let def_id = body.source.def_id(); let bbs = body.basic_blocks_mut(); for idx in bbs.indices() { if bbs[idx].statements.is_empty() @@ -28,10 +27,6 @@ impl<'tcx> crate::MirPass<'tcx> for MultipleReturnTerminators { } for bb in bbs { - if !tcx.consider_optimizing(|| format!("MultipleReturnTerminators {def_id:?} ")) { - break; - } - if let TerminatorKind::Goto { target } = bb.terminator().kind { if bbs_simple_returns.contains(target) { bb.terminator_mut().kind = TerminatorKind::Return; diff --git a/compiler/rustc_mir_transform/src/nrvo.rs b/compiler/rustc_mir_transform/src/nrvo.rs index 98fa149e2bc71..cd026ed68069f 100644 --- a/compiler/rustc_mir_transform/src/nrvo.rs +++ b/compiler/rustc_mir_transform/src/nrvo.rs @@ -45,10 +45,6 @@ impl<'tcx> crate::MirPass<'tcx> for RenameReturnPlace { return; }; - if !tcx.consider_optimizing(|| format!("RenameReturnPlace {def_id:?}")) { - return; - } - debug!( "`{:?}` was eligible for NRVO, making {:?} the return place", def_id, returned_local diff --git a/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs index a535be798cd25..e335051d65644 100644 --- a/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs +++ b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs @@ -26,11 +26,6 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveUnneededDrops { if ty.ty.needs_drop(tcx, typing_env) { continue; } - if !tcx.consider_optimizing(|| { - format!("RemoveUnneededDrops {:?}", body.source.def_id()) - }) { - continue; - } debug!("SUCCESS: replacing `drop` with goto({:?})", target); terminator.kind = TerminatorKind::Goto { target }; should_simplify = true; diff --git a/compiler/rustc_mir_transform/src/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs index 6fd70fbe9b04d..64e183bcbc010 100644 --- a/compiler/rustc_mir_transform/src/remove_zsts.rs +++ b/compiler/rustc_mir_transform/src/remove_zsts.rs @@ -17,10 +17,6 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveZsts { return; } - if !tcx.consider_optimizing(|| format!("RemoveZsts - {:?}", body.source.def_id())) { - return; - } - let typing_env = body.typing_env(tcx); let local_decls = &body.local_decls; let mut replacer = Replacer { tcx, typing_env, local_decls }; @@ -94,16 +90,12 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { } } - fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) { + fn visit_operand(&mut self, operand: &mut Operand<'tcx>, _: Location) { if let Operand::Constant(_) = operand { return; } let op_ty = operand.ty(self.local_decls, self.tcx); - if self.known_to_be_zst(op_ty) - && self.tcx.consider_optimizing(|| { - format!("RemoveZsts - Operand: {operand:?} Location: {loc:?}") - }) - { + if self.known_to_be_zst(op_ty) { *operand = Operand::Constant(Box::new(self.make_zst(op_ty))) } } diff --git a/compiler/rustc_mir_transform/src/unreachable_prop.rs b/compiler/rustc_mir_transform/src/unreachable_prop.rs index 9cd32459c7b48..734703ec78b55 100644 --- a/compiler/rustc_mir_transform/src/unreachable_prop.rs +++ b/compiler/rustc_mir_transform/src/unreachable_prop.rs @@ -43,12 +43,6 @@ impl crate::MirPass<'_> for UnreachablePropagation { } } - if !tcx - .consider_optimizing(|| format!("UnreachablePropagation {:?} ", body.source.def_id())) - { - return; - } - patch.apply(body); // We do want do keep some unreachable blocks, but make them empty. diff --git a/compiler/rustc_session/messages.ftl b/compiler/rustc_session/messages.ftl index 893c532f1fbb1..8fd87893a98c2 100644 --- a/compiler/rustc_session/messages.ftl +++ b/compiler/rustc_session/messages.ftl @@ -84,8 +84,6 @@ session_not_supported = not supported session_octal_float_literal_not_supported = octal float literal is not supported -session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg} - session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C profile-sample-use` does not exist session_profile_use_file_does_not_exist = file `{$path}` passed to `-C profile-use` does not exist diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index d60c56fee756f..0124397ea46f3 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2356,14 +2356,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M early_dcx.early_warn(format!("number of threads was capped at {}", parse::MAX_THREADS_CAP)); } - let fuel = unstable_opts.fuel.is_some() || unstable_opts.print_fuel.is_some(); - if fuel && unstable_opts.threads > 1 { - early_dcx.early_fatal("optimization fuel is incompatible with multiple threads"); - } - if fuel && cg.incremental.is_some() { - early_dcx.early_fatal("optimization fuel is incompatible with incremental compilation"); - } - let incremental = cg.incremental.as_ref().map(PathBuf::from); let assert_incr_state = parse_assert_incr_state(early_dcx, &unstable_opts.assert_incr_state); diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 33f84f104474d..736a5ce07049a 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -463,12 +463,6 @@ pub fn report_lit_error( } } -#[derive(Diagnostic)] -#[diag(session_optimization_fuel_exhausted)] -pub(crate) struct OptimisationFuelExhausted { - pub(crate) msg: String, -} - #[derive(Diagnostic)] #[diag(session_incompatible_linker_flavor)] #[note] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index edee7b4468cd0..a2d75917c8266 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -394,7 +394,6 @@ mod desc { pub(crate) const parse_collapse_macro_debuginfo: &str = "one of `no`, `external`, or `yes`"; pub(crate) const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`"; pub(crate) const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavorCli::one_of(); - pub(crate) const parse_optimization_fuel: &str = "crate=integer"; pub(crate) const parse_dump_mono_stats: &str = "`markdown` (default) or `json`"; pub(crate) const parse_instrument_coverage: &str = parse_bool; pub(crate) const parse_coverage_options: &str = @@ -948,21 +947,6 @@ pub mod parse { true } - pub(crate) fn parse_optimization_fuel( - slot: &mut Option<(String, u64)>, - v: Option<&str>, - ) -> bool { - match v { - None => false, - Some(s) => { - let [crate_name, fuel] = *s.split('=').collect::>() else { return false }; - let Ok(fuel) = fuel.parse::() else { return false }; - *slot = Some((crate_name.to_string(), fuel)); - true - } - } - } - pub(crate) fn parse_unpretty(slot: &mut Option, v: Option<&str>) -> bool { match v { None => false, @@ -1794,8 +1778,6 @@ options! { `shallow` prints only type names, `none` prints nothing and disables `{:?}`. (default: `full`)"), force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED], "force all crates to be `rustc_private` unstable (default: no)"), - fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED], - "set the optimization fuel quota for a crate"), function_return: FunctionReturn = (FunctionReturn::default(), parse_function_return, [TRACKED], "replace returns with jumps to `__x86_return_thunk` (default: `keep`)"), function_sections: Option = (None, parse_opt_bool, [TRACKED], @@ -1978,8 +1960,6 @@ options! { #[rustc_lint_opt_deny_field_access("use `Session::print_codegen_stats` instead of this field")] print_codegen_stats: bool = (false, parse_bool, [UNTRACKED], "print codegen statistics (default: no)"), - print_fuel: Option = (None, parse_opt_string, [TRACKED], - "make rustc print the total optimization fuel used by a crate"), print_llvm_passes: bool = (false, parse_bool, [UNTRACKED], "print the LLVM optimization passes being run (default: no)"), print_mono_items: Option = (None, parse_opt_string, [UNTRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 29fabdd1deb8d..f585410adb97d 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -4,7 +4,6 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::Arc; use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering::SeqCst; use std::{env, fmt, io}; use rustc_data_structures::flock; @@ -12,7 +11,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_data_structures::jobserver::{self, Client}; use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef}; use rustc_data_structures::sync::{ - AtomicU64, DynSend, DynSync, Lock, Lrc, MappedReadGuard, ReadGuard, RwLock, + DynSend, DynSync, Lock, Lrc, MappedReadGuard, ReadGuard, RwLock, }; use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter; use rustc_errors::codes::*; @@ -49,13 +48,6 @@ use crate::parse::{ParseSess, add_feature_diagnostics}; use crate::search_paths::SearchPath; use crate::{errors, filesearch, lint}; -struct OptimizationFuel { - /// If `-zfuel=crate=n` is specified, initially set to `n`, otherwise `0`. - remaining: u64, - /// We're rejecting all further optimizations. - out_of_fuel: bool, -} - /// The behavior of the CTFE engine when an error occurs with regards to backtraces. #[derive(Clone, Copy)] pub enum CtfeBacktrace { @@ -163,12 +155,6 @@ pub struct Session { /// Data about code being compiled, gathered during compilation. pub code_stats: CodeStats, - /// Tracks fuel info if `-zfuel=crate=n` is specified. - optimization_fuel: Lock, - - /// Always set to zero and incremented so that we can print fuel expended by a crate. - pub print_fuel: AtomicU64, - /// Loaded up early on in the initialization of this `Session` to avoid /// false positives about a job server in our environment. pub jobserver: Client, @@ -532,41 +518,6 @@ impl Session { self.opts.incremental.as_ref().map(|_| self.incr_comp_session_dir()) } - /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n. - /// This expends fuel if applicable, and records fuel if applicable. - pub fn consider_optimizing( - &self, - get_crate_name: impl Fn() -> Symbol, - msg: impl Fn() -> String, - ) -> bool { - let mut ret = true; - if let Some((ref c, _)) = self.opts.unstable_opts.fuel { - if c == get_crate_name().as_str() { - assert_eq!(self.threads(), 1); - let mut fuel = self.optimization_fuel.lock(); - ret = fuel.remaining != 0; - if fuel.remaining == 0 && !fuel.out_of_fuel { - if self.dcx().can_emit_warnings() { - // We only call `msg` in case we can actually emit warnings. - // Otherwise, this could cause a `must_produce_diag` ICE - // (issue #79546). - self.dcx().emit_warn(errors::OptimisationFuelExhausted { msg: msg() }); - } - fuel.out_of_fuel = true; - } else if fuel.remaining > 0 { - fuel.remaining -= 1; - } - } - } - if let Some(ref c) = self.opts.unstable_opts.print_fuel { - if c == get_crate_name().as_str() { - assert_eq!(self.threads(), 1); - self.print_fuel.fetch_add(1, SeqCst); - } - } - ret - } - /// Is this edition 2015? pub fn is_rust_2015(&self) -> bool { self.edition().is_rust_2015() @@ -1097,12 +1048,6 @@ pub fn build_session( Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple)) }; - let optimization_fuel = Lock::new(OptimizationFuel { - remaining: sopts.unstable_opts.fuel.as_ref().map_or(0, |&(_, i)| i), - out_of_fuel: false, - }); - let print_fuel = AtomicU64::new(0); - let prof = SelfProfilerRef::new( self_profiler, sopts.unstable_opts.time_passes.then(|| sopts.unstable_opts.time_passes_format), @@ -1130,8 +1075,6 @@ pub fn build_session( incr_comp_session: RwLock::new(IncrCompSession::NotInitialized), prof, code_stats: Default::default(), - optimization_fuel, - print_fuel, jobserver: jobserver::client(), lint_store: None, registered_lints: false, diff --git a/tests/ui/fuel/optimization-fuel-0.rs b/tests/ui/fuel/optimization-fuel-0.rs deleted file mode 100644 index cbcb1d329a3c9..0000000000000 --- a/tests/ui/fuel/optimization-fuel-0.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ run-pass - -#![crate_name="foo"] - -use std::mem::size_of; - -//@ compile-flags: -Z fuel=foo=0 - -#[allow(dead_code)] -struct S1(u8, u16, u8); -#[allow(dead_code)] -struct S2(u8, u16, u8); - -fn main() { - assert_eq!(size_of::(), 6); - assert_eq!(size_of::(), 6); -} diff --git a/tests/ui/fuel/optimization-fuel-0.stderr b/tests/ui/fuel/optimization-fuel-0.stderr deleted file mode 100644 index f0e2ebfc37a37..0000000000000 --- a/tests/ui/fuel/optimization-fuel-0.stderr +++ /dev/null @@ -1,4 +0,0 @@ -warning: optimization-fuel-exhausted: Reorder fields of "S1" - -warning: 1 warning emitted - diff --git a/tests/ui/fuel/optimization-fuel-1.rs b/tests/ui/fuel/optimization-fuel-1.rs deleted file mode 100644 index 97edb0bd25959..0000000000000 --- a/tests/ui/fuel/optimization-fuel-1.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ run-pass - -#![crate_name="foo"] - -use std::mem::size_of; - -//@ compile-flags: -Z fuel=foo=1 - -#[allow(dead_code)] -struct S1(u8, u16, u8); -#[allow(dead_code)] -struct S2(u8, u16, u8); - -fn main() { - let optimized = (size_of::() == 4) as usize - +(size_of::() == 4) as usize; - assert_eq!(optimized, 1); -} diff --git a/tests/ui/fuel/optimization-fuel-1.stderr b/tests/ui/fuel/optimization-fuel-1.stderr deleted file mode 100644 index 53eafb05830cb..0000000000000 --- a/tests/ui/fuel/optimization-fuel-1.stderr +++ /dev/null @@ -1,4 +0,0 @@ -warning: optimization-fuel-exhausted: Reorder fields of "S2" - -warning: 1 warning emitted - diff --git a/tests/ui/fuel/print-fuel.rs b/tests/ui/fuel/print-fuel.rs deleted file mode 100644 index fd7e568bea7a0..0000000000000 --- a/tests/ui/fuel/print-fuel.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![crate_name="foo"] -#![allow(dead_code)] - -// (#55495: The --error-format is to sidestep an issue in our test harness) -//@ compile-flags: -C opt-level=0 --error-format human -Z print-fuel=foo -//@ check-pass - -struct S1(u8, u16, u8); -struct S2(u8, u16, u8); -struct S3(u8, u16, u8); - -fn main() { -} diff --git a/tests/ui/fuel/print-fuel.stderr b/tests/ui/fuel/print-fuel.stderr deleted file mode 100644 index cc88cc077bb21..0000000000000 --- a/tests/ui/fuel/print-fuel.stderr +++ /dev/null @@ -1 +0,0 @@ -Fuel used by foo: 3 diff --git a/tests/ui/lint/issue-79546-fuel-ice.rs b/tests/ui/lint/issue-79546-fuel-ice.rs deleted file mode 100644 index dbee924d26e70..0000000000000 --- a/tests/ui/lint/issue-79546-fuel-ice.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Regression test for the ICE described in #79546. - -//@ compile-flags: --cap-lints=allow -Zfuel=issue79546=0 -//@ check-pass -#![crate_name="issue79546"] - -struct S; -fn main() {} From d013c18a6f9b51b3898dc7e723f1de215e8c1dd4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 28 Aug 2023 20:23:37 +0000 Subject: [PATCH 13/15] Pacify tidy. --- src/tools/tidy/src/issues.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 932a58788e04e..ac82a17e1459f 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -2756,7 +2756,6 @@ ui/lint/issue-57410-1.rs ui/lint/issue-57410.rs ui/lint/issue-63364.rs ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs -ui/lint/issue-79546-fuel-ice.rs ui/lint/issue-79744.rs ui/lint/issue-81218.rs ui/lint/issue-83477.rs From 982cde9801e3603d944279a341fdfb94c69b125b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 31 Jul 2024 10:06:57 +0000 Subject: [PATCH 14/15] Remove extra tests. --- tests/ui/invalid-compile-flags/fuel.rs | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 tests/ui/invalid-compile-flags/fuel.rs diff --git a/tests/ui/invalid-compile-flags/fuel.rs b/tests/ui/invalid-compile-flags/fuel.rs deleted file mode 100644 index 855aa8581223a..0000000000000 --- a/tests/ui/invalid-compile-flags/fuel.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ revisions: incremental threads -//@ dont-check-compiler-stderr -// -//@ [threads] compile-flags: -Zfuel=a=1 -Zthreads=2 -//@ [threads] error-pattern:optimization fuel is incompatible with multiple threads -// -//@ [incremental] incremental -//@ [incremental] compile-flags: -Zprint-fuel=a -//@ [incremental] error-pattern:optimization fuel is incompatible with incremental compilation - -fn main() {} From 787b795d146c4a95a3177c43ad8b9ff117470dc6 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 26 Nov 2024 21:06:48 +0000 Subject: [PATCH 15/15] Only ignore windows-gnu in avr-jmp-offset --- tests/run-make/avr-rjmp-offset/rmake.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-make/avr-rjmp-offset/rmake.rs b/tests/run-make/avr-rjmp-offset/rmake.rs index 2ea7ea877d4aa..de64b724eed2d 100644 --- a/tests/run-make/avr-rjmp-offset/rmake.rs +++ b/tests/run-make/avr-rjmp-offset/rmake.rs @@ -13,7 +13,7 @@ // FIXME(#133480): this has been randomly failing on `x86_64-mingw` due to linker hangs or // crashes... so I'm going to disable this test for windows for now. -//@ ignore-windows +//@ ignore-windows-gnu use run_make_support::{llvm_objdump, rustc};