Skip to content

Commit 6fc8a27

Browse files
committed
Auto merge of rust-lang#135555 - matthiaskrgr:rollup-jnqdbuu, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#135497 (fix typo in typenames of pin documentation) - rust-lang#135522 (add incremental test for issue 135514) - rust-lang#135523 (const traits: remove some known-bug that do not seem to make sense) - rust-lang#135535 (Add GUI test for rust-lang#135499) - rust-lang#135541 (Methods of const traits are const) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 419b3e2 + 2ea07de commit 6fc8a27

11 files changed

+71
-29
lines changed

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ use rustc_hir::def_id::{DefId, LocalDefId};
44
use rustc_middle::query::Providers;
55
use rustc_middle::ty::TyCtxt;
66

7-
fn parent_impl_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
7+
fn parent_impl_or_trait_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
88
let parent_id = tcx.local_parent(def_id);
9-
if matches!(tcx.def_kind(parent_id), DefKind::Impl { .. })
10-
&& let Some(header) = tcx.impl_trait_header(parent_id)
11-
{
12-
header.constness
13-
} else {
14-
hir::Constness::NotConst
9+
match tcx.def_kind(parent_id) {
10+
DefKind::Impl { of_trait: true } => tcx.impl_trait_header(parent_id).unwrap().constness,
11+
DefKind::Trait => {
12+
if tcx.is_const_trait(parent_id.into()) {
13+
hir::Constness::Const
14+
} else {
15+
hir::Constness::NotConst
16+
}
17+
}
18+
_ => hir::Constness::NotConst,
1519
}
1620
}
1721

@@ -34,7 +38,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
3438

3539
// If the function itself is not annotated with `const`, it may still be a `const fn`
3640
// if it resides in a const trait impl.
37-
parent_impl_constness(tcx, def_id)
41+
parent_impl_or_trait_constness(tcx, def_id)
3842
} else {
3943
tcx.dcx().span_bug(
4044
tcx.def_span(def_id),

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
360360
// sensitive check here. But we can at least rule out functions that are not const at
361361
// all. That said, we have to allow calling functions inside a trait marked with
362362
// #[const_trait]. These *are* const-checked!
363-
// FIXME(const_trait_impl): why does `is_const_fn` not classify them as const?
364-
if (!ecx.tcx.is_const_fn(def) && !ecx.tcx.is_const_default_method(def))
365-
|| ecx.tcx.has_attr(def, sym::rustc_do_not_const_check)
366-
{
363+
if !ecx.tcx.is_const_fn(def) || ecx.tcx.has_attr(def, sym::rustc_do_not_const_check) {
367364
// We certainly do *not* want to actually call the fn
368365
// though, so be sure we return here.
369366
throw_unsup_format!("calling non-const function `{}`", instance)

library/core/src/pin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
//!
332332
//! Note that this invariant is enforced by simply making it impossible to call code that would
333333
//! perform a move on the pinned value. This is the case since the only way to access that pinned
334-
//! value is through the pinning <code>[Pin]<[&mut] T>></code>, which in turn restricts our access.
334+
//! value is through the pinning <code>[Pin]<[&mut] T></code>, which in turn restricts our access.
335335
//!
336336
//! ## [`Unpin`]
337337
//!
@@ -379,7 +379,7 @@
379379
//!
380380
//! Exposing access to the inner field which you want to remain pinned must then be carefully
381381
//! considered as well! Remember, exposing a method that gives access to a
382-
//! <code>[Pin]<[&mut] InnerT>></code> where <code>InnerT: [Unpin]</code> would allow safe code to
382+
//! <code>[Pin]<[&mut] InnerT></code> where <code>InnerT: [Unpin]</code> would allow safe code to
383383
//! trivially move the inner value out of that pinning pointer, which is precisely what you're
384384
//! seeking to prevent! Exposing a field of a pinned value through a pinning pointer is called
385385
//! "projecting" a pin, and the more general case of deciding in which cases a pin should be able
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Regression test for #135514 where the new solver didn't properly record deps for incremental
2+
// compilation, similarly to `track-deps-in-new-solver.rs`.
3+
//
4+
// In this specially crafted example, @steffahn was able to trigger unsoundness with an overlapping
5+
// impl that was accepted during the incremental rebuild.
6+
7+
//@ revisions: cpass1 cfail2
8+
//@ compile-flags: -Znext-solver
9+
10+
pub trait Trait {}
11+
12+
pub struct S0<T>(T);
13+
14+
pub struct S<T>(T);
15+
impl<T> Trait for S<T> where S0<T>: Trait {}
16+
17+
pub struct W;
18+
19+
pub trait Other {
20+
type Choose<L, R>;
21+
}
22+
23+
// first impl
24+
impl<T: Trait> Other for T {
25+
type Choose<L, R> = L;
26+
}
27+
28+
// second impl
29+
impl<T> Other for S<T> {
30+
//[cfail2]~^ ERROR conflicting implementations of trait
31+
type Choose<L, R> = R;
32+
}
33+
34+
#[cfg(cpass1)]
35+
impl Trait for W {}
36+
37+
#[cfg(cfail2)]
38+
impl Trait for S<W> {}
39+
40+
fn main() {}

tests/rustdoc-gui/links-color.goml

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
55
// This is needed so that the text color is computed.
66
show-text: true
77

8+
// First we check the links of the different items.
89
define-function: (
910
"check-colors",
1011
[theme, mod, macro, struct, enum, trait, fn, type, union, keyword,
@@ -36,6 +37,11 @@ define-function: (
3637
},
3738
ALL,
3839
)
40+
move-cursor-to: ".desc a[href='long_code_block_link/index.html']"
41+
assert-css: (
42+
".desc a[href='long_code_block_link/index.html']",
43+
{"text-decoration": "underline solid " + |mod|},
44+
)
3945
},
4046
)
4147

tests/ui/consts/const-block-const-bound.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ known-bug: #103507
2-
31
#![allow(unused)]
42
#![feature(const_trait_impl, negative_impls, const_destruct)]
53

@@ -16,6 +14,6 @@ impl Drop for UnconstDrop {
1614
fn main() {
1715
const {
1816
f(UnconstDrop);
19-
//FIXME ~^ ERROR can't drop
17+
//~^ ERROR trait bound `UnconstDrop: const Destruct` is not satisfied
2018
}
2119
}

tests/ui/consts/const-block-const-bound.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0277]: the trait bound `UnconstDrop: const Destruct` is not satisfied
2-
--> $DIR/const-block-const-bound.rs:18:11
2+
--> $DIR/const-block-const-bound.rs:16:11
33
|
44
LL | f(UnconstDrop);
55
| - ^^^^^^^^^^^
66
| |
77
| required by a bound introduced by this call
88
|
99
note: required by a bound in `f`
10-
--> $DIR/const-block-const-bound.rs:8:15
10+
--> $DIR/const-block-const-bound.rs:6:15
1111
|
1212
LL | const fn f<T: ~const Destruct>(x: T) {}
1313
| ^^^^^^ required by this bound in `f`

tests/ui/consts/issue-94675.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ known-bug: #103507
2-
31
#![feature(const_trait_impl, const_vec_string_slice)]
42

53
struct Foo<'a> {
@@ -9,9 +7,7 @@ struct Foo<'a> {
97
impl<'a> Foo<'a> {
108
const fn spam(&mut self, baz: &mut Vec<u32>) {
119
self.bar[0] = baz.len();
12-
//FIXME ~^ ERROR: cannot call
13-
//FIXME ~| ERROR: cannot call
14-
//FIXME ~| ERROR: the trait bound
10+
//~^ ERROR: cannot call
1511
}
1612
}
1713

tests/ui/consts/issue-94675.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0015]: cannot call non-const operator in constant functions
2-
--> $DIR/issue-94675.rs:11:17
2+
--> $DIR/issue-94675.rs:9:17
33
|
44
LL | self.bar[0] = baz.len();
55
| ^^^

tests/ui/impl-trait/normalize-tait-in-const.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//@ known-bug: #103507
1+
//! This is a regression test for <https://github.com/rust-lang/rust/issues/103507>.
2+
//@ known-bug: #110395
23

34
#![feature(type_alias_impl_trait)]
45
#![feature(const_trait_impl, const_destruct)]

tests/ui/impl-trait/normalize-tait-in-const.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `~const` can only be applied to `#[const_trait]` traits
2-
--> $DIR/normalize-tait-in-const.rs:26:35
2+
--> $DIR/normalize-tait-in-const.rs:27:35
33
|
44
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
55
| ^^^^^^ 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_
88
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
99

1010
error: `~const` can only be applied to `#[const_trait]` traits
11-
--> $DIR/normalize-tait-in-const.rs:26:35
11+
--> $DIR/normalize-tait-in-const.rs:27:35
1212
|
1313
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
1414
| ^^^^^^ 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_
1818
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1919

2020
error[E0015]: cannot call non-const closure in constant functions
21-
--> $DIR/normalize-tait-in-const.rs:27:5
21+
--> $DIR/normalize-tait-in-const.rs:28:5
2222
|
2323
LL | fun(filter_positive());
2424
| ^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)