Rust: λͺ…μ‹œμ  μœ ν˜• 선언이 μ—†μœΌλ©΄ 평생 μƒλž΅μ΄ λ„ˆλ¬΄ νƒμš•μŠ€λŸ½μŠ΅λ‹ˆλ‹€.

에 λ§Œλ“  2017λ…„ 02μ›” 19일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: rust-lang/rust

λ‹€μŒ μ˜ˆμ—μ„œ ν΄λ‘œμ €λŠ” ν•„μš”ν•œ 것보닀 더 였래 값을 μ°¨μš©ν•©λ‹ˆλ‹€:

fn main () {
    let f = |y| { println!("{}", y); };
    let x = 4u8;
    f(&x);
}

컴파일 였λ₯˜κ°€ λ°œμƒν•˜λŠ” 원인:

error: `x` does not live long enough
 --> ./test.rs:5:1
  |
4 |     f(&x);
  |        - borrow occurs here
5 | }
  | ^ `x` dropped here while still borrowed
  |
  = note: values in a scope are dropped in the opposite order they are created

κ·ΈλŸ¬λ‚˜ 인수 μœ ν˜•μ„ λͺ…μ‹œμ μœΌλ‘œ μ„ μ–Έν•˜λ©΄ μ˜ˆμƒλŒ€λ‘œ μž‘λ™ν•©λ‹ˆλ‹€.

fn main () {
    let f = |y: &u8| { println!("{}", y); };
    let x = 4u8;
    f(&x);
}

그것이 버그인지 μ˜ˆμƒλ˜λŠ” λ™μž‘μΈμ§€ ν™•μ‹€ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ¬Έμ„œμ—μ„œ 이 νš¨κ³Όμ— λŒ€ν•œ μ„€λͺ…도 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.

메타

rustc --version --verbose :

rustc 1.17.0-nightly (24a70eb59 2017-02-09)
binary: rustc
commit-hash: 24a70eb598a76edb0941f628a87946b40f2a1c83
commit-date: 2017-02-09
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9
A-closures A-inference A-lifetimes C-bug NLL-fixed-by-NLL T-compiler

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

Triage: 이제 2018년에 μ»΄νŒŒμΌλ©λ‹ˆλ‹€.
2015λ…„ 였λ₯˜:

error[E0597]: `x` does not live long enough
 --> src/main.rs:4:8
  |
4 |     f(&x);
  |        ^ borrowed value does not live long enough
5 | }
  | - `x` dropped here while still borrowed
  |
  = note: values in a scope are dropped in the opposite order they are created

rustc: 1.32.0

λͺ¨λ“  3 λŒ“κΈ€

검색 엔진에 λŒ€ν•œ μš©μ–΄λ₯Ό μ‚­μ œν•˜κΈ° μœ„ν•΄: 였늘 μ‚¬μš©μž ν¬λŸΌμ—μ„œ 이것을 νƒμƒ‰ν•˜λ©΄μ„œ |x: &u8| μž‘λ™ν•˜λŠ” μ΄μœ κ°€ HRTB에 λŒ€ν•œ 힌트 역할을 ν•˜λŠ” 것과 관련이 μžˆμ„ 수 μžˆλ‹€λŠ” κ°•ν•œ 인상을 λ°›μ•˜μŠ΅λ‹ˆλ‹€.

관련이 μžˆμ„ 수 있음: λ‚˜λŠ” 이것(특히 huon의 10μ›” 예제)도 λ§Œλ‚¬μŠ΅λ‹ˆλ‹€. 즉, λͺ…μ‹œμ  주석 없이 _만 μž‘λ™ν•©λ‹ˆλ‹€. https://github.com/rust-lang/rust/issues/22557

Triage: 이제 2018년에 μ»΄νŒŒμΌλ©λ‹ˆλ‹€.
2015λ…„ 였λ₯˜:

error[E0597]: `x` does not live long enough
 --> src/main.rs:4:8
  |
4 |     f(&x);
  |        ^ borrowed value does not live long enough
5 | }
  | - `x` dropped here while still borrowed
  |
  = note: values in a scope are dropped in the opposite order they are created

rustc: 1.32.0

이것은 더 이상 두 μ—λ””μ…˜ λͺ¨λ‘μ—μ„œ nightlyμ—μ„œ λ¬Έμ œκ°€ λ˜μ§€ μ•ŠμœΌλ―€λ‘œ μ’…λ£Œν•©λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰