On Tue, Apr 30, 2013 at 8:27 PM, Patrick Walton <[email protected]> wrote:
> On 4/30/13 11:26 AM, Gábor Lehel wrote: > >> Couldn't this be relaxed? In other words allow dynamically sized `str` >> as a type (and perhaps similarly for other dynamically sized types), but >> prohibit those things specifically which would be problematic, i.e. >> using it in ways that would require knowing its size? I think this would >> essentially mean no variables, members, or parameters of that type, but >> you *could* use it as a type argument -- including to the various >> pointer type constructors. >> > > Unfortunately that doesn't work, because opaque type variables `T` can > still be moved, including into the local stack frame. > This did actually occur to me while writing the previous, along with early thoughts about what you could do about it, but I thought I wouldn't get too far ahead of myself. My thought process so far has been: - OK, so maybe you would need a new built-in trait to track it, say StaticSized, which you would need if you want to do that kind of thing with a type variable. - But that's the *common* case. You would have to write StaticSized everywhere! Clearly that's not viable. - OK, so maybe there's a way to invert it? ...but that doesn't really make any sense, after half a minute of reflection. - What about inference? The compiler checks how the type parameter is used, and if it's used in way that requires knowing its size, the compiler puts an implicit "must be statically sized" constraint on it, after which instantiating it with a dynamically sized type produces an error at the point of instantiation. (Not having it be obvious in the source at the point of declaration whether a type variable is allowed to be dynamically sized would be an annoyance, but I think a minor one. In the generated documentation it could maybe be indicated by italics, or their absence.) So that's where I am right now. What about inference? (I recall reading that co/contravariance is also handled by inference, but I don't know if that has any parallels with this beyond the superficial.) Another thing this might allow is user-defined dynamically sized types. Putting a dynamically sized type as the last member of a struct or enum variant would be allowed (as per the common C idiom), in which case the struct or enum itself would be considered dynamically sized, and have the same rules apply. -- Your ship was destroyed in a monadic eruption.
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
