- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我了解版本的目标以及如何使用它们,但是 the documentation没有阐明他们的内部运作。
假设我有两个源文件:
old.rs
,针对 Rust 2015;
new.rs
,目标是 Rust 2018。
我想构建一个同时使用它们的应用程序。正在使用什么机制来确保它们可以互操作?
old.rs
和 new.rs
是否都转换为相同的 HIR 模型?或者均质化发生在之前(例如 AST 级别)还是之后(例如 MIR 级别)?
最佳答案
版本只会影响语法,不会改变编译器编译代码的方式。解析器几乎是编译器中唯一可识别版本的组件,通过对版本进行一些检查来决定如何解析内容。两个版本的 AST 是相同的,尽管 span 知道它们的版本并且编译器中的一些东西检查它们使用的是哪个版本。 HIR 和 MIR 不需要知道版本。
例如。对于 new keywords :
/// Returns `true` if the token is a keyword used in the language.
pub fn is_used_keyword(self) -> bool {
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
self.name >= kw::As && self.name <= kw::While ||
self.name.is_used_keyword_2018() && self.span.rust_2018()
}
额外的self.name.is_used_keyword_2018() && self.span.rust_2018()
会检查关键字是否是2018版新增的关键字(eg. dyn
),2015 年,它将被视为常规符号。
另一个例子是,在 2015 年,可以在 trait 声明中省略参数名称,但现在已被禁止。这是 handled transparently as well :
// We don't allow argument names to be left off in edition 2018.
let is_name_required = p.token.span.rust_2018();
p.parse_arg_general(true, false, |_| is_name_required)
然后是另外一段代码will emit an error in this case, but only for 2018 :
if require_name && (
is_trait_item ||
self.token == token::Comma ||
self.token == token::CloseDelim(token::Paren)
) { // `fn foo(a, b) {}` or `fn foo(usize, usize) {}`
err.span_suggestion(
pat.span,
"if this was a parameter name, give it a type",
format!("{}: TypeName", ident),
Applicability::HasPlaceholders,
);
err.span_suggestion(
pat.span,
"if this is a type, explicitly ignore the parameter name",
format!("_: {}", ident),
Applicability::MachineApplicable,
);
err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)");
return Some(ident);
}
对于 2015 年,a dummy name is created instead :
let ident = Ident::new(kw::Invalid, self.prev_span);
let pat = P(Pat {
id: ast::DUMMY_NODE_ID,
node: PatKind::Ident(
BindingMode::ByValue(Mutability::Immutable), ident, None),
span: ty.span,
});
编译器的其余部分不需要知道用户是否实际提供了名称。
关于rust - 允许针对不同版本的源代码进行互操作的确切机制是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57332016/
我试图找出如何访问 ClojureScript 中的 Javascript 对象属性。如果我事先知道属性(property)的名称,那就很容易了。获取foo.bar我只是做 (.-bar foo) I
我是 .NET 的新手。我想制作一个控制台应用程序,将 .pptx 文件转换为 .wmv。我已经使用 powerpoint interop 做到了这一点。但我有一些问题。首先,如果我构建应用程序并将其
我计划将我的许可系统的核心转移到 C++,但我仍然更喜欢使用 .NET 前端进行设计。无论如何,我刚刚读完互操作功能,并决定对其进行测试。问题是,它对我来说只是花花公子,但对任何其他用户都不起作用。我
系统管理员正在编写一些常用的管理 Power Shell 脚本。主要用于 AD 管理(更新交易所详细信息、在安全组中移动人员等) 我想使用 C# 中的这些脚本(我打算将其编写为库,供网站使用)。 我看
我想在我的应用程序中使用 COM 对象。 如何确保对象已在机器中注册? 我找到的唯一解决方案(也是 on SO)是在初始化周围使用 try-catch block : try { Foo.Ba
这个问题在这里已经有了答案: How to call Java code from C#? (4 个答案) 关闭 10 个月前。 您能给我一些关于使 C# 代码和 Java 代码互操作的建议吗?让我
我正在使用 Microsoft.Office.Interop.Excel 从 C# 创建一个 Excel 工作表,但我无法按照用户想要的方式获取页脚。 1) 如何将页脚文本加粗? 2)如何将页码放在页
我正在使用 F# 和 Excel Interop 将数据输出到 Excel 电子表格。我的第一种方法是单独设置每个单元格: worksheet.Range(range1).Value2 <- "=su
与来自 Silverlight 的 COM 控件进行交互的选项有哪些? 在我的特定项目中,我有一个旧的 ActiveX 身份验证控件,我想在我的 Silverlight 应用程序中利用它。没有太多无聊
我需要针对以下场景的一些建议: 我的 Uni 组有一个巨大的 SVN 存储库。我实际上对整个项目的子目录感兴趣(例如/trunk/projects/my_project)- 不知道它是否真的与 SVN
我有一个 .NET 程序集,它是通过 COM Interop 从 Delphi 主机调用的。据我所知,.NET 代码中任何未处理的异常都将由 .net com 互操作框架处理,并且相应的 HRESUL
我有一个程序可以在单击按钮时创建两个 pdf 文件。它在 WinForms 中使用 Microsoft Office 互操作,文件创建过程如下; 用户在程序中工作 点击按钮 程序根据一个带有书签的模板
我有一个第三方 DLL 用 Delphi“a.dll”(无源代码)编写。 这个 DLL 有一个带有这个签名的方法。 function GetAny(pFileName: String): String
想知道是否有人成功使用 JDEdwards XMLInterop 功能。我已经使用它有一段时间了(使用一个简单的 PInvoke,稍后将发布代码)。我正在寻找是否有更好和/或更强大的方法。 谢谢。 最
我正在尝试让 javafx2 与 Clojure 一起使用 - 在实现像 DoubleBinding 这样的抽象类时,我不确定 Clojure 中 super.bind(moo) 的等价物是什么。我正
有人有使用 Firebird 与 .NET 框架互操作的经验吗?如果有,进展如何? 最佳答案 我在商业桌面应用程序中使用了 firebird。 它的性能很好,直到您处理返回大型结果集的查询。在这些情况
我正在 Excel 工作表中复制并插入行,如下所示: while (rowsToAdd > 0) { // copy the existing row insert
我无法确保正确销毁托管窗口。 我有一个 HwndHost 派生类,正在 TabControl 中显示(尽管这可能不相关)。我试图在选项卡关闭时销毁托管内容(而不是在包含的窗口关闭时)。 我目前拥有 m
我有两个 python 类,它们都可以使用 COM 互操作机制独立于 VBA 编写脚本。但我希望一个能够以父子模式或工厂模式控制另一个的创建。 我已经尝试过,但无法开始工作,我已将其提炼为下面的 MC
我们在我们编写的 C# dll(程序集 A)中使用 Microsoft 提供的 COM DLL (dsofile.dll)。为了避免必须注册 COM dll,我已将对 dsofile.dll 的引用的
我是一名优秀的程序员,十分优秀!