Implement the `!` type by canndrew · Pull Request #35162 · rust-lang/rust

OK so @eddyb and I chatted a bunch on IRC. In general, I'm feeling nervous about how the "never-to-any" adjustment is different from other adjustments. For one thing, it's applied eagerly, in write_ty, and we want it to be reflected in expr_ty (which until now was basically an alias for node_ty). This also seems to suggest that some of the other logic for applying adjustments may be wrong -- although it seems like we already in some cases apply coercions even when another coerce exists, and the code is handling that case.

I can see various ways to go forward:

  • Just merge it. Typeck is messy, gets a bit messier, up the priority on some kind of cleanup rewriting. I feel nervous about this, but it'd probably be ok.
  • Rename expr_ty to expr_ty_adjusted and have it apply all adjustments. Rewrite uses of expr_ty to use that. This...would probably be more-or-less the same as now, because in general the adjustments haven't been applied (I think?) at the places where expr_ty is called (or, if they have, maybe we actually want to be seeing them?).
  • Rewrite to return a Ty<'tcx> out of the "check expr" routine and instead of calling expr_ty everywhere, actually use the (adjusted) return value.

Honestly without trying to work through either of those latter two options, I'm not quite sure how easy/hard they would be, but it seems like option 3 probably leaves us with a cleaner setup than we started with overall (presuming it works), so maybe worth a try.