Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13.2.2 491页 “step1函数第一个参数&val生命周期本来是'a,因为协变而变成'static,所以借用检查就正常通过了” #335

Open
lidanyang opened this issue Jan 15, 2023 · 1 comment
Milestone

Comments

@lidanyang
Copy link

lidanyang commented Jan 15, 2023

“step1函数第一个参数&val生命周期本来是'a,因为协变而变成'static,所以借用检查就正常通过了”这句话没看懂:
1、 “&val声明周期本来是'a”,这个'a是指step1函数生命周期参数的那个'a吗?如果是的话,是不是指函数内部的局部变量会默认继承函数自身的生命周期参数?
2. “协变而变成'static”。这里的“协变成”的意义是啥?
3. step1的生命周期参数'a不是会单态化成'static吗,为啥会有协变呢,从传参那一刻‘a不就单态化了么?
已经看了这一节一天了,卡在这里,查了各种资料、文档,虽然明白了协变、逆变、不变这些概念什么意思,但是还是没搞懂这里说的啥意思,没搞懂为啥能骗过借用检查,希望能得到一点解答。

@lidanyang lidanyang changed the title 13.2.2 491页 “step1函数第一个参数&val生命周期本来是'a,因为协变而变成'static” 13.2.2 491页 “step1函数第一个参数&val生命周期本来是'a,因为协变而变成'static,所以借用检查就正常通过了” Jan 15, 2023
@ZhangHanDong
Copy link
Owner

@lidanyang
“step1的生命周期参数'a不是会单态化成'static吗,为啥会有协变呢” -> 这个过程就是协变 , 'static: 'a 是父子关系
如果还不懂就暂时保留疑问吧,不影响你使用 Rust 。这部分内容在第二版中也会更加详细描述。

@ZhangHanDong ZhangHanDong added this to the 第二版 milestone Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants