Pull to refresh

Comments 5

Очень интересно (но не настолько чтобы рыться в обсуждениях) насчёт static/cost Drop: как оно работать будет?

Если коротко из RFC:
Allow types with destructors to be used in static items and in const functions, as long as the destructor never needs to run in const context.

  • Lift the restriction on types with destructors being used in statics.
  • statics containing Drop-types will not run the destructor upon program/thread exit.
  • (Optionally adding a lint that warn about the possibility of resource leak)
  • Alloc instantiating structures with destructors in constant expressions,
  • Continue to prevent const items from holding types with destructors.
  • Allow const fn to return types with destructors.
  • Disallow constant expressions which would result in the destructor being called (if the code were run at runtime).

В общем, lazy_static пора на покой наконец.

Спасибо, стало понятнее. Собственно, понятно всё, кроме последнего пункта:


Disallow constant expressions which would result in the destructor being called (if the code were run at runtime).

Может есть пример?

Думаю речь про это:
const fn sample(_v: Vec<u8>) -> usize {
	0	// Discards the input vector, dropping it
}

Т.е. если бы при обычном вызове в runtime в процессе вычисления выражения вызвался бы деструктор, то такое выражение не может быть const.
Only those users with full accounts are able to leave comments. Log in, please.

Articles