rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
95.34k stars 12.28k forks source link

When a trait is missing items, there are many follow-up errors distracting from the root cause #125603

Open RalfJung opened 1 month ago

RalfJung commented 1 month ago

To reproduce, check out commit cdc509f7c09361466d543fc8311ce7066b10cc4f of rustc and remove this line:

https://github.com/rust-lang/rust/blob/7a5d814a047376223da9331061d9642dd33b3f9a/compiler/rustc_const_eval/src/const_eval/machine.rs#L375

I would expect some complaints about missing trait items. Those do show up, but they are drowned in tons of other errors like:

error[E0599]: the method `allocate` exists for struct `InterpCx<'_, '_, CompileTimeInterpreter<'_, '_>>`, but its trait bounds were not satisfied
   --> compiler/rustc_const_eval/src/util/check_validity_requirement.rs:53:10
    |
52  |       let allocated = cx
    |  _____________________-
53  | |         .allocate(ty, MemoryKind::Machine(crate::const_eval::MemoryKind::Heap))
    | |_________-^^^^^^^^
    |
   ::: compiler/rustc_const_eval/src/interpret/eval_context.rs:37:1
    |
37  |   pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
    |   ------------------------------------------------------- method `allocate` not found for this struct
    |
note: trait bound `{type error}: std::marker::Sized` was not satisfied
   --> compiler/rustc_const_eval/src/interpret/place.rs:386:24
    |
386 | impl<'mir, 'tcx: 'mir, Prov, M> InterpCx<'mir, 'tcx, M>
    |                        ^^^^     -----------------------
    |                        |
    |                        unsatisfied trait bound introduced here
help: consider relaxing the type parameter's implicit `Sized` bound
   --> compiler/rustc_const_eval/src/interpret/place.rs:386:28
    |
386 | impl<'mir, 'tcx: 'mir, Prov: ?Sized, M> InterpCx<'mir, 'tcx, M>
    |                            ++++++++

Seems like somewhere we are going on compiling too far, and then showing errors that have nothing to do with the root cause of the problem.

So far I have not managed to reproduce this with a smaller example.

Cc @oli-obk is this a consequence of your recent work to keep compiling in more cases?

oli-obk commented 1 month ago

note: trait bound {type error}: std::marker::Sized was not satisfied

That's horrible and should def not happen