Skip to content

Method call resolution behavioral changes on custom DSTs in Rust 1.70 -> 1.71 #114928

Closed
@ZhennanWu

Description

@ZhennanWu

I tried this code:

use std::any::TypeId;
use std::any::Any;
use std::hint::black_box;
struct A<T:?Sized+'static> {
    a: i32,
    b: T
}

impl<T:?Sized+'static> A<T> {
    fn bb(&self) -> TypeId {
        self.b.type_id()
    }
}

pub fn main() {
    let mut a0 = A{a: 8, b: 9 as i32};
    let mut a: &mut A<dyn Any> = &mut a0;
    println!("{:?}",a.bb());
    println!("{:?}",a.b.type_id());
    println!("{:?}",std::any::TypeId::of::<i32>());
}

I expected to see this happen: The three printed TypeIds should be identical, as with the behavior in Rust <=1.70

Instead, this happened:

Program returned: 0
TypeId { t: 2368704253749761200 }
TypeId { t: 5817408772836814867 }
TypeId { t: 5817408772836814867 }

Meta

https://godbolt.org/z/8vvr37Ynf switch between rust versions.

I could not find reference in the 1.71 RELEASES that could explain such behavioral changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-opt-inliningArea: MIR inliningC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions