https://github.com/rust-lang/rust/pull/39361 μ κΈ°λ°μΌλ‘ μ¬μ©μκ° fn νΈμΆμ λͺ μμ μ ν 맀κ°λ³μλ₯Ό μΆκ°ν΄μΌ νλ κ²½μ°λ₯Ό κ³ λ €ν μ μμ΅λλ€. λλ λ€μκ³Ό κ°μ μλ₯Ό μμνκ³ μμ΅λλ€.
fn foo<T>() { }
fn main() {
foo();
}
μ¬μ©μκ° λͺ
μμ μΈ T
$ μ λν΄ foo::<T>
λ₯Ό μμ±νλλ‘ μ μνλ κ²μ΄ μ’μ΅λλ€. μ΄κ²μ μ½κ°μ μκ°μ΄ νμν©λλ€:
μ§μ λ³μμ μ£Όμμ λ¬κΈ°λ³΄λ€ μΈμ μ΄κ²μ μ μνκ³ μΆμ΅λκΉ? μ§μ λ³μμ μ£Όμμ 첨λΆνλ κ²μ μ νΈνμ§λ§ μ§μ λ³μμ μ νμ΄ λ΄λΆ κΉμμ΄ μ μΆλμ§ μμ μ νμ μΈκΈνλ 볡μ‘ν κ²μΈ κ²½μ°μλ κ·Έλ μ§ μμ μλ μμ΅λλ€. λ°λ©΄μ ν¨μμ μ£Όμμ μΆκ°νλ©΄ μ μΆλμ§ μμ μ νμ μ§μ μ§μ ν μ μμ΅λλ€. .
μ:
fn foo<T>() -> Option<T> { }
fn main() {
let x = foo();
}
x: Option<T>
λλ foo::<T>
λ μ΄λΈμ μ μν΄μΌ ν©λκΉ? μ΄ κ²½μ°λ κ²½κ³μ μ΄μ§λ§ Option
λ₯Ό μ’ λ 볡μ‘ν μ νμΌλ‘ λ°κΎΈλ©΄ κ· νμ΄ λ κΈ°μΈμ΄μ§λλ€.
fnμ΄ λ§μ μ νμ μ·¨νκ³ λΆλΆμ μΌλ‘ μκ³ μμ λ μ°λ¦¬λ 무μμ ν©λκΉ? μ°λ¦¬λ μΌλΆ μ λ³΄κ° μμ§λ§ μ λΆλ μλ λ 무μμ ν΄μΌ νλμ§μ λν λ¬Έμ λ₯Ό ννΌνμ΅λλ€. νμ§λ§ μ¬κΈ°κ° λ μ€μν κ² κ°μ΅λλ€. μ:
fn foo<T, U>() -> T { }
fn main() {
let x: i32 = foo();
}
μ¬κΈ°μ μ°λ¦¬λ T
λ₯Ό μκ³ μμ§λ§ U
λ λͺ¨λ¦
λλ€. foo::<_, XXX>
λ₯Ό μ μν΄μΌ ν©λκΉ? μ¬μ©μκ° μ 곡ν΄μΌ νλ νλͺ©μμ λνλ΄κΈ° μν΄ XXX
λ₯Ό μ΄λ»κ² ννν©λκΉ?
cc @cengizIO -- μΆκ΅¬νλ κ²μ΄ μ¬λ―Έμμ΅λκΉ?
cc @estebank @jonathandturner -- νν λ°©λ²μ λν μκ°μ?
μλ νμΈμ @nikomatsakis
μ΄ μμ μ μννκ² μ΅λλ€.
λ€μ νλ² κ°μ¬ν©λλ€!
μ λ₯ μΆλ ₯:
error[E0282]: type annotations needed
--> $DIR/xxx.rs:xx:xx
|
14 | let x: i32 = foo();
| ^^^ cannot infer type for `U`
|
= note: type annotations or generic parameter binding required
μΌλΆ μ΅μ :
error[E0282]: type annotations needed
--> $DIR/xxx.rs:xx:xx
|
14 | let x: i32 = foo();
| ^^^ cannot infer type for `U`
|
= note: type annotations or generic parameter binding required
= note: generic parameter `U` needs to be specified for foo::<T, U>()
error[E0282]: type annotations needed
--> $DIR/xxx.rs:xx:xx
|
14 | let x: i32 = foo();
| ^^^ cannot infer type for `U`
| |
| you can specify the generic parameter here using `foo::<_, U>()`
|
= note: generic parameter `U` needs to be specified for `fn foo::<T, U>() -> T`
error[E0282]: type annotations needed
--> $DIR/xxx.rs:xx:xx
|
14 | let x: i32 = foo();
| ^^^ cannot infer type for `U` in `fn foo<T, U>() -> T`
| |
| specify `U` using `foo::<_, U>()`
|
μ΄ λ©λͺ¨λ νΉν λ΄ λμ λ°μ§κ±°λ¦¬κ² λ§λλλ€.
= note: type annotations or generic parameter binding required
νμ€ν μ κ±°ν©μλ€. :)
κ°μ₯ μ μ©ν λκΈ
μ λ₯ μΆλ ₯:
μΌλΆ μ΅μ :