mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Add ~const bounds trait bounds when using derive_const
This commit is contained in:
parent
56bf28d4f4
commit
7a4505900d
@ -153,7 +153,10 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
|
||||
let path_debug = cx.path_global(span, cx.std_path(&[sym::fmt, sym::Debug]));
|
||||
let ty_dyn_debug = cx.ty(
|
||||
span,
|
||||
ast::TyKind::TraitObject(vec![cx.trait_bound(path_debug)], ast::TraitObjectSyntax::Dyn),
|
||||
ast::TyKind::TraitObject(
|
||||
vec![cx.trait_bound(path_debug, false)],
|
||||
ast::TraitObjectSyntax::Dyn,
|
||||
),
|
||||
);
|
||||
let ty_slice = cx.ty(
|
||||
span,
|
||||
|
@ -605,18 +605,26 @@ impl<'a> TraitDef<'a> {
|
||||
let bounds: Vec<_> = self
|
||||
.additional_bounds
|
||||
.iter()
|
||||
.map(|p| cx.trait_bound(p.to_path(cx, self.span, type_ident, generics)))
|
||||
.map(|p| {
|
||||
cx.trait_bound(
|
||||
p.to_path(cx, self.span, type_ident, generics),
|
||||
self.is_const,
|
||||
)
|
||||
})
|
||||
.chain(
|
||||
// Add a bound for the current trait.
|
||||
self.skip_path_as_bound
|
||||
.not()
|
||||
.then(|| cx.trait_bound(trait_path.clone())),
|
||||
.then(|| cx.trait_bound(trait_path.clone(), self.is_const)),
|
||||
)
|
||||
.chain({
|
||||
// Add a `Copy` bound if required.
|
||||
if is_packed && self.needs_copy_as_bound_if_packed {
|
||||
let p = deriving::path_std!(marker::Copy);
|
||||
Some(cx.trait_bound(p.to_path(cx, self.span, type_ident, generics)))
|
||||
Some(cx.trait_bound(
|
||||
p.to_path(cx, self.span, type_ident, generics),
|
||||
self.is_const,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -694,18 +702,24 @@ impl<'a> TraitDef<'a> {
|
||||
let mut bounds: Vec<_> = self
|
||||
.additional_bounds
|
||||
.iter()
|
||||
.map(|p| cx.trait_bound(p.to_path(cx, self.span, type_ident, generics)))
|
||||
.map(|p| {
|
||||
cx.trait_bound(
|
||||
p.to_path(cx, self.span, type_ident, generics),
|
||||
self.is_const,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Require the current trait.
|
||||
bounds.push(cx.trait_bound(trait_path.clone()));
|
||||
bounds.push(cx.trait_bound(trait_path.clone(), self.is_const));
|
||||
|
||||
// Add a `Copy` bound if required.
|
||||
if is_packed && self.needs_copy_as_bound_if_packed {
|
||||
let p = deriving::path_std!(marker::Copy);
|
||||
bounds.push(
|
||||
cx.trait_bound(p.to_path(cx, self.span, type_ident, generics)),
|
||||
);
|
||||
bounds.push(cx.trait_bound(
|
||||
p.to_path(cx, self.span, type_ident, generics),
|
||||
self.is_const,
|
||||
));
|
||||
}
|
||||
|
||||
let predicate = ast::WhereBoundPredicate {
|
||||
|
@ -154,7 +154,7 @@ fn mk_ty_param(
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let path = b.to_path(cx, span, self_ident, self_generics);
|
||||
cx.trait_bound(path)
|
||||
cx.trait_bound(path, false)
|
||||
})
|
||||
.collect();
|
||||
cx.typaram(span, Ident::new(name, span), bounds, None)
|
||||
|
@ -131,10 +131,14 @@ impl<'a> ExtCtxt<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trait_bound(&self, path: ast::Path) -> ast::GenericBound {
|
||||
pub fn trait_bound(&self, path: ast::Path, is_const: bool) -> ast::GenericBound {
|
||||
ast::GenericBound::Trait(
|
||||
self.poly_trait_ref(path.span, path),
|
||||
ast::TraitBoundModifier::None,
|
||||
if is_const {
|
||||
ast::TraitBoundModifier::MaybeConst
|
||||
} else {
|
||||
ast::TraitBoundModifier::None
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(derive_const)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
#[derive_const(PartialEq)]
|
||||
pub struct Reverse<T>(T);
|
||||
|
||||
const fn foo(a: Reverse<i32>, b: Reverse<i32>) -> bool {
|
||||
a == b
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user