Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Limitations of `min_specialization` when specializing a generic implementation?

Дата публикации: 04-10-2026 15:30:59


I'm trying to understand #![feature(specialization)] vs. #![feature(min_specialization)] to inform the design of my types, but I haven't been able to find any novice-accessible documentation. How do the two differ?
Specifically, I expected the following (playground) to be straightforward specialization, but it does not work with min_specialization. Why not?
#![feature(min_specialization)]
trait A {}
trait B: A {}
struct Sa;
impl A for Sa {}
struct Sb;
impl A for Sb {}
impl B for Sb {}
trait X {
fn method(&self);
}
impl<T: A> X for T {
default fn method(&self) {
println!("default");
}
}
// error: cannot specialize on trait `B`
// --> src/main.rs:29:13
// |
// 29 | impl<T: A + B> X for T {
// | ^
impl<T: A + B> X for T {
fn method(&self) {
println!("specialized");
}
}
fn main() {
Sa.method();
Sb.method();
}
4 posts - 3 participants
Read full topic

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1Trait object with associated types in field - requires generic param?011.0807-10-2026
2Strategies for dyn trait objects with optional behavior?07.1206-10-2026
3Optimization of inlined functions returning Result?07.3606-10-2026
4Type erasure and dyn lifetime in a NonNull/Box struct field08.5504-10-2026
5Why no Dependent Matrix Type?05.1608-10-2026
6Чудеса nightly, часть 1: на чём тайком держится stable Rust08.5529-09-2026
7Rust Derive Macros: Why the Compiler Automatically Inlines Them09.2907-10-2026
8Architecture review of a Hyper/Tower-based web framework (Toxi)015.4606-10-2026
9Does my lockfree stack impl look correct?06.0605-10-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 9. Тональность: 0. Информативность: 9.38. Источник: users.rust-lang.org.