Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7b2fd81f
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7b2fd81f
编写于
8月 10, 2023
作者:
C
Catherine Flores
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test for `&mut`
上级
beb57f07
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
1 deletion
+9
-1
tests/ui/filter_map_bool_then.fixed
tests/ui/filter_map_bool_then.fixed
+4
-0
tests/ui/filter_map_bool_then.rs
tests/ui/filter_map_bool_then.rs
+4
-0
tests/ui/filter_map_bool_then.stderr
tests/ui/filter_map_bool_then.stderr
+1
-1
未找到文件。
tests/ui/filter_map_bool_then.fixed
浏览文件 @
7b2fd81f
...
...
@@ -33,11 +33,15 @@ fn main() {
// Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
// and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
// we can lint this and still get the same input type.
// See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
let v = vec![NonCopy, NonCopy];
v.clone().iter().filter(|&i| (i == &NonCopy)).map(|i| i);
// Do not lint
let v = vec![NonCopy, NonCopy];
v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i));
// `&mut` is `!Copy`.
let v = vec![NonCopy, NonCopy];
v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i));
external! {
let v = vec![1, 2, 3, 4, 5, 6];
v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
...
...
tests/ui/filter_map_bool_then.rs
浏览文件 @
7b2fd81f
...
...
@@ -33,11 +33,15 @@ fn main() {
// Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
// and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
// we can lint this and still get the same input type.
// See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
let
v
=
vec!
[
NonCopy
,
NonCopy
];
v
.clone
()
.iter
()
.filter_map
(|
i
|
(
i
==
&
NonCopy
)
.then
(||
i
));
// Do not lint
let
v
=
vec!
[
NonCopy
,
NonCopy
];
v
.clone
()
.into_iter
()
.filter_map
(|
i
|
(
i
==
NonCopy
)
.then
(||
i
));
// `&mut` is `!Copy`.
let
v
=
vec!
[
NonCopy
,
NonCopy
];
v
.clone
()
.iter_mut
()
.filter_map
(|
i
|
(
i
==
&
mut
NonCopy
)
.then
(||
i
));
external!
{
let
v
=
vec!
[
1
,
2
,
3
,
4
,
5
,
6
];
v
.clone
()
.into_iter
()
.filter_map
(|
i
|
(
i
%
2
==
0
)
.then
(||
i
+
1
));
...
...
tests/ui/filter_map_bool_then.stderr
浏览文件 @
7b2fd81f
...
...
@@ -31,7 +31,7 @@ LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)`
error: usage of `bool::then` in `filter_map`
--> $DIR/filter_map_bool_then.rs:3
7
:22
--> $DIR/filter_map_bool_then.rs:3
8
:22
|
LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录