From 620feadb38165877836400d6a6451437e46ab42f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 15 Jan 2025 09:21:51 +0100 Subject: [PATCH 1/6] remove some known-bug that do not seem to make sense --- tests/ui/consts/const-block-const-bound.rs | 4 +--- tests/ui/consts/const-block-const-bound.stderr | 4 ++-- tests/ui/consts/issue-94675.rs | 6 +----- tests/ui/consts/issue-94675.stderr | 2 +- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/ui/consts/const-block-const-bound.rs b/tests/ui/consts/const-block-const-bound.rs index 596aac09b3114..b4b89a93e759f 100644 --- a/tests/ui/consts/const-block-const-bound.rs +++ b/tests/ui/consts/const-block-const-bound.rs @@ -1,5 +1,3 @@ -//@ known-bug: #103507 - #![allow(unused)] #![feature(const_trait_impl, negative_impls, const_destruct)] @@ -16,6 +14,6 @@ impl Drop for UnconstDrop { fn main() { const { f(UnconstDrop); - //FIXME ~^ ERROR can't drop + //~^ ERROR trait bound `UnconstDrop: const Destruct` is not satisfied } } diff --git a/tests/ui/consts/const-block-const-bound.stderr b/tests/ui/consts/const-block-const-bound.stderr index 0931eff2175bc..14c62fb4d2573 100644 --- a/tests/ui/consts/const-block-const-bound.stderr +++ b/tests/ui/consts/const-block-const-bound.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `UnconstDrop: const Destruct` is not satisfied - --> $DIR/const-block-const-bound.rs:18:11 + --> $DIR/const-block-const-bound.rs:16:11 | LL | f(UnconstDrop); | - ^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | f(UnconstDrop); | required by a bound introduced by this call | note: required by a bound in `f` - --> $DIR/const-block-const-bound.rs:8:15 + --> $DIR/const-block-const-bound.rs:6:15 | LL | const fn f(x: T) {} | ^^^^^^ required by this bound in `f` diff --git a/tests/ui/consts/issue-94675.rs b/tests/ui/consts/issue-94675.rs index 2e30eebb07b2e..e1c6861c5103b 100644 --- a/tests/ui/consts/issue-94675.rs +++ b/tests/ui/consts/issue-94675.rs @@ -1,5 +1,3 @@ -//@ known-bug: #103507 - #![feature(const_trait_impl, const_vec_string_slice)] struct Foo<'a> { @@ -9,9 +7,7 @@ struct Foo<'a> { impl<'a> Foo<'a> { const fn spam(&mut self, baz: &mut Vec) { self.bar[0] = baz.len(); - //FIXME ~^ ERROR: cannot call - //FIXME ~| ERROR: cannot call - //FIXME ~| ERROR: the trait bound + //~^ ERROR: cannot call } } diff --git a/tests/ui/consts/issue-94675.stderr b/tests/ui/consts/issue-94675.stderr index 8cad13724f20e..63a86b456332f 100644 --- a/tests/ui/consts/issue-94675.stderr +++ b/tests/ui/consts/issue-94675.stderr @@ -1,5 +1,5 @@ error[E0015]: cannot call non-const operator in constant functions - --> $DIR/issue-94675.rs:11:17 + --> $DIR/issue-94675.rs:9:17 | LL | self.bar[0] = baz.len(); | ^^^ From 67a07e01cf8db40d30cea7489d78413bb3b79b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 15 Jan 2025 08:06:03 +0000 Subject: [PATCH 2/6] add test for issue 135514 --- ...apping-impls-in-new-solver-issue-135514.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/incremental/overlapping-impls-in-new-solver-issue-135514.rs diff --git a/tests/incremental/overlapping-impls-in-new-solver-issue-135514.rs b/tests/incremental/overlapping-impls-in-new-solver-issue-135514.rs new file mode 100644 index 0000000000000..8fcc913fa3719 --- /dev/null +++ b/tests/incremental/overlapping-impls-in-new-solver-issue-135514.rs @@ -0,0 +1,40 @@ +// Regression test for #135514 where the new solver didn't properly record deps for incremental +// compilation, similarly to `track-deps-in-new-solver.rs`. +// +// In this specially crafted example, @steffahn was able to trigger unsoundness with an overlapping +// impl that was accepted during the incremental rebuild. + +//@ revisions: cpass1 cfail2 +//@ compile-flags: -Znext-solver + +pub trait Trait {} + +pub struct S0(T); + +pub struct S(T); +impl Trait for S where S0: Trait {} + +pub struct W; + +pub trait Other { + type Choose; +} + +// first impl +impl Other for T { + type Choose = L; +} + +// second impl +impl Other for S { + //[cfail2]~^ ERROR conflicting implementations of trait + type Choose = R; +} + +#[cfg(cpass1)] +impl Trait for W {} + +#[cfg(cfail2)] +impl Trait for S {} + +fn main() {} From 0922c191d5ce113fed345eeb21e8f5e4130efb2d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 15 Jan 2025 09:32:30 +0100 Subject: [PATCH 3/6] fix known-bug link in normalize-tait-in-const --- tests/ui/impl-trait/normalize-tait-in-const.rs | 3 ++- tests/ui/impl-trait/normalize-tait-in-const.stderr | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/ui/impl-trait/normalize-tait-in-const.rs b/tests/ui/impl-trait/normalize-tait-in-const.rs index 1fd543b72e7cc..a735ef766737b 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.rs +++ b/tests/ui/impl-trait/normalize-tait-in-const.rs @@ -1,4 +1,5 @@ -//@ known-bug: #103507 +//! This is a regression test for . +//@ known-bug: #110395 #![feature(type_alias_impl_trait)] #![feature(const_trait_impl, const_destruct)] diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index f4e8a872cec12..c6cd1b139c5b0 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -1,5 +1,5 @@ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:26:35 + --> $DIR/normalize-tait-in-const.rs:27:35 | LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { | ^^^^^^ can't be applied to `Fn` @@ -8,7 +8,7 @@ note: `Fn` can't be used with `~const` because it isn't annotated with `#[const_ --> $SRC_DIR/core/src/ops/function.rs:LL:COL error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:26:35 + --> $DIR/normalize-tait-in-const.rs:27:35 | LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { | ^^^^^^ can't be applied to `Fn` @@ -18,7 +18,7 @@ note: `Fn` can't be used with `~const` because it isn't annotated with `#[const_ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0015]: cannot call non-const closure in constant functions - --> $DIR/normalize-tait-in-const.rs:27:5 + --> $DIR/normalize-tait-in-const.rs:28:5 | LL | fun(filter_positive()); | ^^^^^^^^^^^^^^^^^^^^^^ From 0128c910f487e010a0c5693080a680f0d0a56a74 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Jan 2025 15:42:20 +0100 Subject: [PATCH 4/6] Add GUI test for #135499 --- tests/rustdoc-gui/links-color.goml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/rustdoc-gui/links-color.goml b/tests/rustdoc-gui/links-color.goml index ad1b5e801ca32..8d26b826479dc 100644 --- a/tests/rustdoc-gui/links-color.goml +++ b/tests/rustdoc-gui/links-color.goml @@ -5,6 +5,7 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" // This is needed so that the text color is computed. show-text: true +// First we check the links of the different items. define-function: ( "check-colors", [theme, mod, macro, struct, enum, trait, fn, type, union, keyword, @@ -36,6 +37,11 @@ define-function: ( }, ALL, ) + move-cursor-to: ".desc a[href='long_code_block_link/index.html']" + assert-css: ( + ".desc a[href='long_code_block_link/index.html']", + {"text-decoration": "underline solid " + |mod|}, + ) }, ) From a61cd86a4e0d88abfc19a13a7959d397e4dd148b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 15 Jan 2025 10:50:07 +0000 Subject: [PATCH 5/6] Methods of const traits are const --- .../src/const_eval/fn_queries.rs | 20 +++++++++++-------- .../src/const_eval/machine.rs | 5 +---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs index 8af17d01b0a36..35c3e3ed3150e 100644 --- a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs @@ -4,14 +4,18 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; -fn parent_impl_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness { +fn parent_impl_or_trait_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness { let parent_id = tcx.local_parent(def_id); - if matches!(tcx.def_kind(parent_id), DefKind::Impl { .. }) - && let Some(header) = tcx.impl_trait_header(parent_id) - { - header.constness - } else { - hir::Constness::NotConst + match tcx.def_kind(parent_id) { + DefKind::Impl { of_trait: true } => tcx.impl_trait_header(parent_id).unwrap().constness, + DefKind::Trait => { + if tcx.is_const_trait(parent_id.into()) { + hir::Constness::Const + } else { + hir::Constness::NotConst + } + } + _ => hir::Constness::NotConst, } } @@ -34,7 +38,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness { // If the function itself is not annotated with `const`, it may still be a `const fn` // if it resides in a const trait impl. - parent_impl_constness(tcx, def_id) + parent_impl_or_trait_constness(tcx, def_id) } else { tcx.dcx().span_bug( tcx.def_span(def_id), diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index ba7fbb254c66d..cfdfbdb7880b2 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -360,10 +360,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { // sensitive check here. But we can at least rule out functions that are not const at // all. That said, we have to allow calling functions inside a trait marked with // #[const_trait]. These *are* const-checked! - // FIXME(const_trait_impl): why does `is_const_fn` not classify them as const? - if (!ecx.tcx.is_const_fn(def) && !ecx.tcx.is_const_default_method(def)) - || ecx.tcx.has_attr(def, sym::rustc_do_not_const_check) - { + if !ecx.tcx.is_const_fn(def) || ecx.tcx.has_attr(def, sym::rustc_do_not_const_check) { // We certainly do *not* want to actually call the fn // though, so be sure we return here. throw_unsup_format!("calling non-const function `{}`", instance) From b535a1dd654fd538776249d951593a8712d1b32a Mon Sep 17 00:00:00 2001 From: DJMrTV Date: Tue, 14 Jan 2025 19:26:28 +0100 Subject: [PATCH 6/6] fix typo in typenames of pin documentation --- library/core/src/pin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 83730285636fb..71044190f0c88 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -331,7 +331,7 @@ //! //! Note that this invariant is enforced by simply making it impossible to call code that would //! perform a move on the pinned value. This is the case since the only way to access that pinned -//! value is through the pinning [Pin]<[&mut] T>>, which in turn restricts our access. +//! value is through the pinning [Pin]<[&mut] T>, which in turn restricts our access. //! //! ## [`Unpin`] //! @@ -379,7 +379,7 @@ //! //! Exposing access to the inner field which you want to remain pinned must then be carefully //! considered as well! Remember, exposing a method that gives access to a -//! [Pin]<[&mut] InnerT>> where InnerT: [Unpin] would allow safe code to +//! [Pin]<[&mut] InnerT> where InnerT: [Unpin] would allow safe code to //! trivially move the inner value out of that pinning pointer, which is precisely what you're //! seeking to prevent! Exposing a field of a pinned value through a pinning pointer is called //! "projecting" a pin, and the more general case of deciding in which cases a pin should be able