Skip to content

Commit 7f54d68

Browse files
committed
Add a note for unsatisfied ~const Drop bounds
1 parent e745b4d commit 7f54d68

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
439439
}
440440
}
441441

442+
if Some(trait_ref.def_id()) == tcx.lang_items().drop_trait()
443+
&& predicate_is_const
444+
{
445+
err.note("`~const Drop` was renamed to `~const Destruct`");
446+
err.note("See <https://github.com/rust-lang/rust/pull/94901> for more details");
447+
}
448+
442449
let explanation = if let ObligationCauseCode::MainFunctionType =
443450
obligation.cause.code()
444451
{

Diff for: src/librustdoc/clean/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -302,23 +302,13 @@ impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> {
302302

303303
impl<'a> Clean<Option<WherePredicate>> for ty::PolyTraitPredicate<'a> {
304304
fn clean(&self, cx: &mut DocContext<'_>) -> Option<WherePredicate> {
305-
// `T: ~const Drop` is not equivalent to `T: Drop`, and we don't currently document `~const` bounds
306-
// because of its experimental status, so just don't show these.
307305
// `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
308306
if self.skip_binder().constness == ty::BoundConstness::ConstIfConst
309-
&& [cx.tcx.lang_items().drop_trait(), cx.tcx.lang_items().destruct_trait()]
310-
.iter()
311-
.any(|tr| *tr == Some(self.skip_binder().def_id()))
307+
&& Some(self.skip_binder().def_id()) == cx.tcx.lang_items().destruct_trait()
312308
{
313309
return None;
314310
}
315311

316-
#[cfg(bootstrap)]
317-
{
318-
// FIXME: remove `lang_items().drop_trait()` from above logic,
319-
// as well as the comment about `~const Drop` because it was renamed to `Destruct`.
320-
}
321-
322312
let poly_trait_ref = self.map_bound(|pred| pred.trait_ref);
323313
Some(WherePredicate::BoundPredicate {
324314
ty: poly_trait_ref.skip_binder().self_ty().clean(cx),

Diff for: src/test/rustdoc/rfc-2632-const-trait-impl.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Test that we do not currently display `~const` in rustdoc
2-
// as that syntax is currently provisional; `~const Drop` has
2+
// as that syntax is currently provisional; `~const Destruct` has
33
// no effect on stable code so it should be hidden as well.
44
//
55
// To future blessers: make sure that `const_trait_impl` is
@@ -8,6 +8,8 @@
88
#![feature(const_trait_impl)]
99
#![crate_name = "foo"]
1010

11+
use std::marker::Destruct;
12+
1113
pub struct S<T>(T);
1214

1315
// @!has foo/trait.Tr.html '//pre[@class="rust trait"]/code/a[@class="trait"]' '~const'
@@ -20,22 +22,36 @@ pub trait Tr<T> {
2022
// @!has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
2123
// @has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
2224
#[default_method_body_is_const]
23-
fn a<A: ~const Clone>() where Option<A>: ~const Clone {}
25+
fn a<A: ~const Clone + ~const Destruct>()
26+
where
27+
Option<A>: ~const Clone + ~const Destruct,
28+
{
29+
}
2430
}
2531

2632
// @!has - '//section[@id="impl-Tr%3CT%3E"]/h3[@class="code-header in-band"]' '~const'
2733
// @has - '//section[@id="impl-Tr%3CT%3E"]/h3[@class="code-header in-band"]/a[@class="trait"]' 'Clone'
2834
// @!has - '//section[@id="impl-Tr%3CT%3E"]/h3[@class="code-header in-band"]/span[@class="where"]' '~const'
2935
// @has - '//section[@id="impl-Tr%3CT%3E"]/h3[@class="code-header in-band"]/span[@class="where fmt-newline"]' ': Clone'
30-
impl<T: ~const Clone> const Tr<T> for T where Option<T>: ~const Clone {
31-
fn a<A: ~const Clone>() where Option<A>: ~const Clone {}
36+
impl<T: ~const Clone + ~const Destruct> const Tr<T> for T
37+
where
38+
Option<T>: ~const Clone + ~const Destruct,
39+
{
40+
fn a<A: ~const Clone + ~const Destruct>()
41+
where
42+
Option<A>: ~const Clone + ~const Destruct,
43+
{
44+
}
3245
}
3346

3447
// @!has foo/fn.foo.html '//pre[@class="rust fn"]/code/a[@class="trait"]' '~const'
3548
// @has - '//pre[@class="rust fn"]/code/a[@class="trait"]' 'Clone'
3649
// @!has - '//pre[@class="rust fn"]/code/span[@class="where fmt-newline"]' '~const'
3750
// @has - '//pre[@class="rust fn"]/code/span[@class="where fmt-newline"]' ': Clone'
38-
pub const fn foo<F: ~const Clone>() where Option<F>: ~const Clone {
51+
pub const fn foo<F: ~const Clone + ~const Destruct>()
52+
where
53+
Option<F>: ~const Clone + ~const Destruct,
54+
{
3955
F::a()
4056
}
4157

@@ -44,7 +60,10 @@ impl<T> S<T> {
4460
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone'
4561
// @!has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where"]' '~const'
4662
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
47-
pub const fn foo<B: ~const Clone>() where B: ~const Clone {
63+
pub const fn foo<B: ~const Clone + ~const Destruct>()
64+
where
65+
B: ~const Clone + ~const Destruct,
66+
{
4867
B::a()
4968
}
5069
}

0 commit comments

Comments
 (0)