Skip to content

Commit

Permalink
Auto merge of #135555 - matthiaskrgr:rollup-jnqdbuu, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #135497 (fix typo in typenames of pin documentation)
 - #135522 (add incremental test for issue 135514)
 - #135523 (const traits: remove some known-bug that do not seem to make sense)
 - #135535 (Add GUI test for #135499)
 - #135541 (Methods of const traits are const)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 15, 2025
2 parents 419b3e2 + 2ea07de commit 6fc8a27
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 29 deletions.
20 changes: 12 additions & 8 deletions compiler/rustc_const_eval/src/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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),
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>[Pin]<[&mut] T>></code>, which in turn restricts our access.
//! value is through the pinning <code>[Pin]<[&mut] T></code>, which in turn restricts our access.
//!
//! ## [`Unpin`]
//!
Expand Down Expand Up @@ -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
//! <code>[Pin]<[&mut] InnerT>></code> where <code>InnerT: [Unpin]</code> would allow safe code to
//! <code>[Pin]<[&mut] InnerT></code> where <code>InnerT: [Unpin]</code> 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
Expand Down
40 changes: 40 additions & 0 deletions tests/incremental/overlapping-impls-in-new-solver-issue-135514.rs
Original file line number Diff line number Diff line change
@@ -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>(T);

pub struct S<T>(T);
impl<T> Trait for S<T> where S0<T>: Trait {}

pub struct W;

pub trait Other {
type Choose<L, R>;
}

// first impl
impl<T: Trait> Other for T {
type Choose<L, R> = L;
}

// second impl
impl<T> Other for S<T> {
//[cfail2]~^ ERROR conflicting implementations of trait
type Choose<L, R> = R;
}

#[cfg(cpass1)]
impl Trait for W {}

#[cfg(cfail2)]
impl Trait for S<W> {}

fn main() {}
6 changes: 6 additions & 0 deletions tests/rustdoc-gui/links-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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|},
)
},
)

Expand Down
4 changes: 1 addition & 3 deletions tests/ui/consts/const-block-const-bound.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ known-bug: #103507

#![allow(unused)]
#![feature(const_trait_impl, negative_impls, const_destruct)]

Expand All @@ -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
}
}
4 changes: 2 additions & 2 deletions tests/ui/consts/const-block-const-bound.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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);
| - ^^^^^^^^^^^
| |
| 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<T: ~const Destruct>(x: T) {}
| ^^^^^^ required by this bound in `f`
Expand Down
6 changes: 1 addition & 5 deletions tests/ui/consts/issue-94675.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ known-bug: #103507

#![feature(const_trait_impl, const_vec_string_slice)]

struct Foo<'a> {
Expand All @@ -9,9 +7,7 @@ struct Foo<'a> {
impl<'a> Foo<'a> {
const fn spam(&mut self, baz: &mut Vec<u32>) {
self.bar[0] = baz.len();
//FIXME ~^ ERROR: cannot call
//FIXME ~| ERROR: cannot call
//FIXME ~| ERROR: the trait bound
//~^ ERROR: cannot call
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/issue-94675.stderr
Original file line number Diff line number Diff line change
@@ -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();
| ^^^
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/impl-trait/normalize-tait-in-const.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ known-bug: #103507
//! This is a regression test for <https://github.com/rust-lang/rust/issues/103507>.
//@ known-bug: #110395

#![feature(type_alias_impl_trait)]
#![feature(const_trait_impl, const_destruct)]
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/impl-trait/normalize-tait-in-const.stderr
Original file line number Diff line number Diff line change
@@ -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<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^ can't be applied to `Fn`
Expand All @@ -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<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^ can't be applied to `Fn`
Expand All @@ -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());
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 6fc8a27

Please sign in to comment.