[Rust] 1.47.0 업데이트 발표 (번역)
원문
https://blog.rust-lang.org/2020/10/08/Rust-1.47.html
우리 러스트 팀은 새 버전 [1.47.0]을 발표하게 돼서 정말 기쁩니다!
러스트는 누구든 믿음직하고 효과적인 소프트웨어를 만들 수 있게 도와주는 끝내주는 언어입니다.
만약 rustup을 통해서 Rust의 이전버전을 설치해놓은 상대라면, 업데이트는 아주 쉽습니다. 그냥 이렇게 치면 돼요.
rustup update stable
rustup을 설치한 적이 없다면, 우리 웹사이트의 설치 페이지에서 받을 수 있습니다. 그리고 깃허브에서 이번 버전에 대한 릴리즈 노트를 참조해보세요.
1.47.0엔 무엇이 있나요?
이번 릴리즈는 새 언어 기능을 포함하지 않습니다. 오랫동안 지연됐던 표준 라이브러리 기능들이 추가되긴 했지만요.
이번 릴리즈는 대부분 삶의 질 개선, 라이브러리 안정화, const화(const-ifications), 툴체인 개선을 포함합니다.
이 포스트에서 다루지 않은 기타 변경점은 상세 릴리즈 노트를 참조하세요.
더 큰 배열에서의 트레잇
Rust는 현재로서는 정수값에 대해 제너릭한 방법을 갖고있지 않습니다.
이건 배열과 관련한 오랜 문제를 가지는데요. 배열은 그 타입의 일부에 정수가 들어가기 때문입니다.
가령 [T; N]는 타입이 T이며 길이가 N인 배열의 타입이죠.
그래서, N에 대해 제너릭할 수 있는 방법이 없기 때문에. 지원하려는 모든 N에 대한 배열의 트레잇을 수동으로 구현해야 했습니다.
표준 라이브러리는 32개의 N을 제공하기로 했고요.
우린 "const generics"이라 불리는 기능을 작업하고 있는데요. 이건 N을 제너릭하게 다루는 것일 가능케 해줍니다.
하지만 이 기능에 대한 전체적인 설명은 이 포스트의 범위를 벗어납니다. const generics도 아직 stable이 되진 않았고요.
어쨌든. 이 기능의 핵심은 컴파일러에서 구현됩니다. 그리고 모든 길이의 배열에 대한 트레잇을 구현하는 데 사용한 표준 라이브러리로도 괜찮을 거라 판단했어요.
그리고 표준 라이브러리를 사용하여 모든 길이의 배열에 트레잇을 구현해도 괜찮다는 판단으로 이 기능이 충분히 적용된다는 결론을 내렸습니다.
->However, the core of this feature has been implemented in the compiler, and it has been decided that the feature is far enough along that we are okay with the standard library using it to implement traits on arrays of any length.
이게 뭘 의미할까요?
1.46에서 이러한 행동을 시도해봅시다.
**fn main() **
{
** let xs = [0; 34]; **
** println!("{:?}", xs); **
**} **
이 코드는 이런 오류를 던졌을 겁니다.
error[E0277]: arrays only have std trait implementations for lengths 0..=32 --> src/main.rs:4:22 | 4 | println!("{:?}", xs); | ^^ the trait std::array::LengthAtMost32 is not implemented for [{integer}; 34] | = note: required because of the requirements on the impl of std::fmt::Debug for [{integer}; 34] = note: required by std::fmt::Debug::fmt = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
하지만 Rust 1.47에서는 정상적으로 출력이 됩니다.
이건 배열을 사람들이 사용하기 더 좋게 해줄거에요. 하지만 라이브러리들이 스스로의 trait에 대해 이런 종류의 구현을 할 수 있도록 하기 위해서는 const generics 기능이 stable이 될때까지 기다려야 할 겁니다.
->This should make arrays significantly more useful to folks, though it will take until the const generics feature stabilizes for libraries to be able to do this kind of implementation for their own traits.
const generic을 언제 stable에 올릴지는 정해진 바 없습니다.
더 짧은 backtraces
Rust 1.18로 돌아가보면. panic 시 rustc가 출력하는 backtrace를 일부 변경한 적이 있습니다.
대부분의 경우에, backtrace를 보면 쓸만한 것보다 쓸모없는 텍스트가 훨씬 많죠. 원하는 정보를 찾기가 힘듭니다.
어느 순간 이런 것들이 퇴보했습니다. 1.47.0에서 그 범인이 발견되었고, 이제 고쳐졌습니다.
->However, at some point, these regressed. In Rust 1.47.0, the culprit was found, and this has now been fixed.
이전의 프로그램.
**fn main() **
**{ **
** panic!(); **
**} **
는 이런 backtrace를 보여줬을 겁니다.
thread 'main' panicked at 'explicit panic', src/main.rs:2:5 stack backtrace: 0: backtrace::backtrace::libunwind::trace at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86 1: backtrace::backtrace::trace_unsynchronized at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66 2: std::sys_common::backtrace::_print_fmt at src/libstd/sys_common/backtrace.rs:78 3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt at src/libstd/sys_common/backtrace.rs:59 4: core::fmt::write at src/libcore/fmt/mod.rs:1076 5: std::io::Write::write_fmt at src/libstd/io/mod.rs:1537 6: std::sys_common::backtrace::_print at src/libstd/sys_common/backtrace.rs:62 7: std::sys_common::backtrace::print at src/libstd/sys_common/backtrace.rs:49 8: std::panicking::default_hook::{{closure}} at src/libstd/panicking.rs:198 9: std::panicking::default_hook at src/libstd/panicking.rs:217 10: std::panicking::rust_panic_with_hook at src/libstd/panicking.rs:526 11: std::panicking::begin_panic at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libstd/panicking.rs:456 12: playground::main at src/main.rs:2 13: std::rt::lang_start::{{closure}} at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libstd/rt.rs:67 14: std::rt::lang_start_internal::{{closure}} at src/libstd/rt.rs:52 15: std::panicking::try::do_call at src/libstd/panicking.rs:348 16: std::panicking::try at src/libstd/panicking.rs:325 17: std::panic::catch_unwind at src/libstd/panic.rs:394 18: std::rt::lang_start_internal at src/libstd/rt.rs:51 19: std::rt::lang_start at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libstd/rt.rs:67 20: main 21: __libc_start_main 22: _start
이제, 1.47에서는 대신 이러한 것을 볼 수 있습니다.
thread 'main' panicked at 'explicit panic', src/main.rs:2:5 stack backtrace: 0: std::panicking::begin_panic at /rustc/d6646f64790018719caebeafd352a92adfa1d75a/library/std/src/panicking.rs:497 1: playground::main at ./src/main.rs:2 2: core::ops::function::FnOnce::call_once at /rustc/d6646f64790018719caebeafd352a92adfa1d75a/library/core/src/ops/function.rs:227
이건 panic의 실제 발생지를 더 보기 쉽게 만들어줍니다.
이전처럼 모든걸 다 보고싶다면 환경변수로 RUST_BACKTRACE=full를 깔아주면 됩니다.
LLVM 11
LLVM 11으로 업그레이드가 되었습니다.
컴파일러는 여전히 이전버전인 8로도 컴파일을 지원하겠지만. 11이 디폴트로 동작할 겁니다.
->The compiler still supports being compiled with LLVM versions as old as 8, but by default, 11 is what you'll be getting.
Windows에서의 Control Flow Guard
rustc가 이제 -C control-flow-guard를 지원합니다. 이 옵션은 윈도우즈에서 Control Flow Guard를 켜줍니다. 다른 플랫폼에선 무시되고요.
라이브러리 변경점
추가로. 9개의 API가 stable이 되었습니다.
Ident::new_raw
Range::is_empty
RangeInclusive::is_empty
Result::as_deref
Result::as_deref_mut
Vec::leak
pointer::offset_from
f32::TAU
f64::TAU
그리고 다음의 기존 stable API들이 const 함수가 되었습니다.
checked_add,
checked_sub,
checked_mul,
checked_neg,
checked_shl,
checked_shr,
saturating_add,
saturating_sub,
모든 정수에 대한 saturating_mul 메서드
checked_abs,
saturating_abs,
saturating_neg,
모든 부호있는 정수에 대한 signum
is_ascii_alphabetic,
is_ascii_uppercase,
is_ascii_lowercase,
is_ascii_alphanumeric,
is_ascii_digit,
is_ascii_hexdigit,
is_ascii_punctuation,
is_ascii_graphic,
is_ascii_whitespace,
char과 u8의 is_ascii_control 메서드
더 많은 정보를 원한다면 자세한 릴리즈 노트를 참조하세요
기타 변경점
Rustdoc이 Ayu theme에 대한 지원을 얻었습니다.
1.47 릴리즈에는 이외의 기타 변경점들도 있습니다.
Rust, Cargo, Clippy에서 무엇이 바뀌었는지 확인해보세요.
1.47.0의 컨트리뷰터들
1.47의 완성엔 수많은 사람들이 함께했습니다. 전부 여러분이 없었다면 불가능했을 거에요.
고마워요!