[Rust] 1.83.0 업데이트 발표 (번역)

https://blog.rust-lang.org/2024/11/28/Rust-1.83.0.html
러스트는 누구든 믿음직하고 효과적인 소프트웨어를 만들 수 있게 도와주는 끝내주는 언어입니다.

만약 rustup을 통해서 Rust의 이전버전을 설치해놓은 상대라면, 업데이트는 아주 쉽습니다. 그냥 이렇게 치면 돼요.

rustup update stable

rustup을 설치한 적이 없다면, 우리 웹사이트의 설치 페이지에서 받을 수 있습니다. 그리고 깃허브에서 이번 버전에 대한 릴리즈 노트를 참조해보세요.

미래의 릴리즈를 테스트해서 러스트 팀을 돕고 싶다면, 로컬에서 베타 채널(rustup default beta) 또는 nightly 채널(rustup default nightly)로 업데이트하는 것을 고려할 수 있습니다.

버그를 발견했다면 리포트해주세요!



1.83.0 stable에는 무엇이 있나요?



새로운 const 기능

이번 릴리스에서는 const 컨텍스트 내의 코드가 할 수 있는 일에 대해, 여러 큰 확장들이 포함됩니다.

이 변경사항으로 컴파일 시간에 컴파일러가 평가해야 하는 모든 코드가 영향을 받습니다.
const와 static item의 초기 값, 배열 길이, enum 판별(discriminant) 값, const generic argument, const 컨텍스트에서 호출 가능한 함수 등...


- static에 대한 참조.

지금까지는 static item의 initializer 표현식을 제외한 const 컨텍스트는 static item을 참조하는 것이 금지되었습니다. 이 제한은 이제 해제됩니다.

static S: i32 = 25;
const C: &i32 = &S;

그러나, const 컨텍스트에서는 변경 가능(mutable)하거나 내부 변경 가능(interior mutable)한 static 값을 읽는 것은 여전히 허용되지 않는다는 점에 유의하세요.
또한, constant의 최종 값은 변경 가능하거나 내부 변경 가능한 static을 참조하지 않을 수 있습니다.

static mut S: i32 = 0;


const C1: i32 = unsafe { S };
// error: constant accesses mutable global memory****


const C2: &i32 = unsafe { &S };
// error: encountered reference to mutable memory in const

이러한 제한은 constant가 여전히 "constant"임을 보장합니다. 평가되는 값과 패턴으로서의 의미(참조의 역참조를 생략할 수 있는)는 전체 프로그램 실행에서 같습니다.

그러니까, constant는 변경 가능(mutable)하거나 내부 변경 가능한(interior mutable) static을 가리키는 raw 포인터로 평가할 수 있습니다.

static mut S: i32 = 64;
*const C: mut i32 = &raw mut S;



- 변경 가능한 참조 및 포인터.

이제 const 컨텍스트에서 변경 가능한(mutable) 참조를 사용할 수 있습니다.

const fn inc(x: &mut i32) {
** x += 1;*
}


const C: i32 = {
** let mut c = 41;**
** inc(&mut c);**
** c**
};

mutable raw 포인터와 내부 가변성(interior mutability) 또한 지원됩니다.

use std::cell::UnsafeCell;


const C: i32 = {
** let c = UnsafeCell::new(41);**
** unsafe { c.get() += 1 };*
** c.into_inner()**
};

하지만, 변경 가능한 참조와 포인터는 constant의 계산 내부에서만 사용할 수 있으며, constant의 최종 값의 일부가 될 수는 없습니다.

const C: &mut i32 = &mut 4;
// error[E0764]: mutable references are not allowed in the final value of constants
This release also ships with a whole bag of new functions that are now stable in const contexts (see the end of the "Stabilized APIs" section).

위의 새로운 기능들과 더불어, stable이 된 API들은 이런 새 형태의 코드들을 const 컨텍스트 내에서 실행하는 것을 도와줍니다.
Rust 에코시스템이 이것들을 어떻게 활용할지 기대되네요!




Stable이 된 API

BufRead::skip_until
ControlFlow::break_value
ControlFlow::continue_value
ControlFlow::map_break
ControlFlow::map_continue
DebugList::finish_non_exhaustive
DebugMap::finish_non_exhaustive
DebugSet::finish_non_exhaustive
DebugTuple::finish_non_exhaustive
ErrorKind::ArgumentListTooLong
ErrorKind::Deadlock
ErrorKind::DirectoryNotEmpty
ErrorKind::ExecutableFileBusy
ErrorKind::FileTooLarge
ErrorKind::HostUnreachable
ErrorKind::IsADirectory
ErrorKind::NetworkDown
ErrorKind::NetworkUnreachable
ErrorKind::NotADirectory
ErrorKind::NotSeekable
ErrorKind::ReadOnlyFilesystem
ErrorKind::ResourceBusy
ErrorKind::StaleNetworkFileHandle
ErrorKind::StorageFull
ErrorKind::TooManyLinks
Option::get_or_insert_default
Waker::data
Waker::new
Waker::vtable
char::MIN
hash_map::Entry::insert_entry
hash_map::VacantEntry::insert_entry

다음 API들은 이제 const에서도 사용 가능합니다.

Cell::into_inner
Duration::as_secs_f32
Duration::as_secs_f64
Duration::div_duration_f32
Duration::div_duration_f64
MaybeUninit::as_mut_ptr
NonNull::as_mut
NonNull::copy_from
NonNull::copy_from_nonoverlapping
NonNull::copy_to
NonNull::copy_to_nonoverlapping
NonNull::slice_from_raw_parts
NonNull::write
NonNull::write_bytes
NonNull::write_unaligned
OnceCell::into_inner
Option::as_mut
Option::expect
Option::replace
Option::take
Option::unwrap
Option::unwrap_unchecked
Option::<&>::copied
Option::<&mut >::copied
Option::<Option<
>>::flatten
Option::<Result<
, >>::transpose
RefCell::into_inner
Result::as_mut
Result::<&
, _>::copied
Result::<&mut , >::copied
Result::<Option<
>, >::transpose
UnsafeCell::get_mut
UnsafeCell::into_inner
array::from_mut
char::encode_utf8
{float}::classify
{float}::is_finite
{float}::is_infinite
{float}::is_nan
{float}::is_normal
{float}::is_sign_negative
{float}::is_sign_positive
{float}::is_subnormal
{float}::from_bits
{float}::from_be_bytes
{float}::from_le_bytes
{float}::from_ne_bytes
{float}::to_bits
{float}::to_be_bytes
{float}::to_le_bytes
{float}::to_ne_bytes
mem::replace
ptr::replace
ptr::slice_from_raw_parts_mut
ptr::write
ptr::write_unaligned
<*const >::copy_to
<*const >::copy_to_nonoverlapping
<*mut >::copy_from
<*mut >::copy_from_nonoverlapping
<*mut >::copy_to
<*mut >::copy_to_nonoverlapping
<*mut >::write
<*mut >::write_bytes
<*mut >::write_unaligned
slice::from_mut
slice::from_raw_parts_mut
<[
]>::first_mut
<[
]>::last_mut
<[
]>::first_chunk_mut
<[
]>::last_chunk_mut
<[
]>::split_at_mut
<[
]>::split_at_mut_checked
<[
]>::split_at_mut_unchecked
<[
]>::split_first_mut
<[
]>::split_last_mut
<[
]>::split_first_chunk_mut
<[
]>::split_last_chunk_mut
str::as_bytes_mut
str::as_mut_ptr
str::from_utf8_unchecked_mut




기타 변경점

이외의 모든 변경사항은 각각 Rust, Cargo, Clippy에서 확인하세요.




1.83.0의 컨트리뷰터들에게

1.83.0의 완성엔 수많은 사람들이 함께했습니다. 전부 여러분이 없었다면 불가능했을 거에요.

고마워요!