This CL makes a number of small changes to dyn compatibility errors: - "object safety" has been renamed to "dyn-compatibility" throughout - "Convert to enum" suggestions are no longer generated when there exists a type-generic impl of the trait or an impl for `dyn OtherTrait` - Several error messages are reorganized for user readability Additionally, the dyn compatibility error creation code has been split out into functions. cc #132713 cc #133267
45 lines
1009 B
Rust
45 lines
1009 B
Rust
// Regression test for #22040.
|
|
|
|
use std::fmt::Debug;
|
|
|
|
trait Expr: Debug + PartialEq {
|
|
fn print_element_count(&self);
|
|
}
|
|
|
|
//#[derive(PartialEq)]
|
|
#[derive(Debug)]
|
|
struct SExpr<'x> {
|
|
elements: Vec<Box<dyn Expr + 'x>>,
|
|
//~^ ERROR E0038
|
|
}
|
|
|
|
impl<'x> PartialEq for SExpr<'x> {
|
|
fn eq(&self, other:&SExpr<'x>) -> bool {
|
|
println!("L1: {} L2: {}", self.elements.len(), other.elements.len());
|
|
|
|
let result = self.elements.len() == other.elements.len();
|
|
|
|
println!("Got compare {}", result);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
impl <'x> SExpr<'x> {
|
|
fn new() -> SExpr<'x> { return SExpr{elements: Vec::new(),}; }
|
|
}
|
|
|
|
impl <'x> Expr for SExpr<'x> {
|
|
fn print_element_count(&self) {
|
|
println!("element count: {}", self.elements.len());
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let a: Box<dyn Expr> = Box::new(SExpr::new());
|
|
//~^ ERROR: `Expr` is not dyn compatible
|
|
let b: Box<dyn Expr> = Box::new(SExpr::new());
|
|
//~^ ERROR: `Expr` is not dyn compatible
|
|
|
|
// assert_eq!(a , b);
|
|
}
|