cleanup Binder fields #49814
Labels
A-trait-system
Area: Trait system
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-traits
Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804
Part of #49810.
The
Binder
type is used to represent higher-ranked regions:rust/src/librustc/ty/sty.rs
Lines 645 to 653 in 4b9b70c
I have long wanted to make that field private and thus to force users of
Binder
to go through the more "high-level" methods (as an aside, it might be nice to move binder to its own module too, so thatty
can't use its private fields).Right now, when we do
ty::Binder(value)
, that means that any things with a debruijn-index of 1 (soon to be zero) invalue
will be bound by this binder. Maybe we can add aty::Binder::bind(value)
for this.On the other hand, there are times when we do not expect
value
to have any bound regions in it -- for those cases we often usety::Binder(value)
today, but it'd be better if usedty::Binder::dummy(value)
, which adds an assertion.Similarly, any attempt to directly access the "bound" value (
binder.0
) is better written withbinder.skip_binder()
, which makes it more clear what's happening. Better yet is to add an accessor, somewhat like thedef_id
function defined onBinder<TraitRef<'tcx>>
. This is currently written to access the field0
directly, which is bad, but the good part is that it is "safe" to do, becauseDefId
is a type that never contains a bound name:rust/src/librustc/ty/sty.rs
Lines 573 to 575 in 4b9b70c
Note that accessing fields which may have bound names should ideally preserve the binding level, like the
inputs
function onBinder<FnSig<'tcx>>
:rust/src/librustc/ty/sty.rs
Lines 841 to 843 in 4b9b70c
This is saying, given a function like
for<'a> fn(&'a u32) -> &'a u32
, we get back a list of input types likefor<'a> [&'a u32]
. Note that the binder is preserved. (Internally, though, it could be rewritten to use the helperBinder::map_bound
:rust/src/librustc/ty/sty.rs
Lines 697 to 701 in 4b9b70c
The text was updated successfully, but these errors were encountered: