Skip to content

Commit 95101a5

Browse files
committed
Don't add Drop clauses to some more marker traits
1 parent 5c2d83b commit 95101a5

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

frontend/exporter/src/traits/utils.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
//! benefit of reducing the size of signatures. Moreover, the rules on which bounds are required vs
2828
//! implied are subtle. We may change this if this proves to be a problem.
2929
use rustc_hir::def::DefKind;
30+
use rustc_hir::LangItem;
3031
use rustc_middle::ty::*;
3132
use rustc_span::def_id::DefId;
3233
use rustc_span::{Span, DUMMY_SP};
@@ -92,11 +93,21 @@ pub fn required_predicates<'tcx>(
9293
predicates.to_mut().insert(0, (self_clause, DUMMY_SP));
9394
}
9495
if add_drop {
95-
// Add a `T: Drop` bound for every generic, unless the current trait is `Drop` itself, or
96-
// `Sized`.
97-
let drop_trait = tcx.lang_items().drop_trait().unwrap();
98-
let sized_trait = tcx.lang_items().sized_trait().unwrap();
99-
if def_id != drop_trait && def_id != sized_trait {
96+
// Add a `T: Drop` bound for every generic, unless the current trait is `Drop` itself, or a
97+
// built-in marker trait that we know doesn't need the bound.
98+
let lang_item = tcx.as_lang_item(def_id);
99+
if !matches!(
100+
lang_item,
101+
Some(
102+
LangItem::Drop
103+
| LangItem::Sized
104+
| LangItem::MetaSized
105+
| LangItem::PointeeSized
106+
| LangItem::DiscriminantKind
107+
| LangItem::PointeeTrait
108+
)
109+
) {
110+
let drop_trait = tcx.lang_items().drop_trait().unwrap();
100111
let extra_bounds = tcx
101112
.generics_of(def_id)
102113
.own_params

0 commit comments

Comments
 (0)