Skip to content

Commit d2f71bf

Browse files
committed
Auto merge of #44860 - kennytm:fix-44731, r=alexcrichton
Fix issue #44731. Also excludes `impl Trait` from everybody_loops if it appears in the path. Fixes #44731.
2 parents cce9343 + 16c110f commit d2f71bf

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/librustc_driver/pretty.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,26 @@ impl ReplaceBodyWithLoop {
659659
ast::TyKind::Ptr(ast::MutTy { ty: ref subty, .. }) |
660660
ast::TyKind::Rptr(_, ast::MutTy { ty: ref subty, .. }) |
661661
ast::TyKind::Paren(ref subty) => involves_impl_trait(subty),
662-
ast::TyKind::Tup(ref tys) => tys.iter().any(|subty| involves_impl_trait(subty)),
662+
ast::TyKind::Tup(ref tys) => any_involves_impl_trait(tys.iter()),
663+
ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| {
664+
match seg.parameters.as_ref().map(|p| &**p) {
665+
None => false,
666+
Some(&ast::PathParameters::AngleBracketed(ref data)) =>
667+
any_involves_impl_trait(data.types.iter()) ||
668+
any_involves_impl_trait(data.bindings.iter().map(|b| &b.ty)),
669+
Some(&ast::PathParameters::Parenthesized(ref data)) =>
670+
any_involves_impl_trait(data.inputs.iter()) ||
671+
any_involves_impl_trait(data.output.iter()),
672+
}
673+
}),
663674
_ => false,
664675
}
665676
}
677+
678+
fn any_involves_impl_trait<'a, I: Iterator<Item = &'a P<ast::Ty>>>(mut it: I) -> bool {
679+
it.any(|subty| involves_impl_trait(subty))
680+
}
681+
666682
involves_impl_trait(ty)
667683
} else {
668684
false

src/test/rustdoc/issue-43869.rs

+51
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,58 @@ pub fn j() -> impl Iterator<Item=u8> + Clone {
2626
Some(1u8).into_iter()
2727
}
2828

29+
pub fn k() -> [impl Clone; 2] {
30+
[123u32, 456u32]
31+
}
32+
33+
pub fn l() -> (impl Clone, impl Default) {
34+
(789u32, -123i32)
35+
}
36+
37+
pub fn m() -> &'static impl Clone {
38+
&1u8
39+
}
40+
41+
pub fn n() -> *const impl Clone {
42+
&1u8
43+
}
44+
45+
pub fn o() -> &'static [impl Clone] {
46+
b":)"
47+
}
48+
49+
// issue #44731
50+
pub fn test_44731_0() -> Box<impl Iterator<Item=u8>> {
51+
Box::new(g())
52+
}
53+
54+
pub fn test_44731_1() -> Result<Box<impl Clone>, ()> {
55+
Ok(Box::new(j()))
56+
}
57+
58+
pub fn test_44731_2() -> Box<Fn(impl Clone)> {
59+
Box::new(|_: u32| {})
60+
}
61+
62+
pub fn test_44731_3() -> Box<Fn() -> impl Clone> {
63+
Box::new(|| 0u32)
64+
}
65+
66+
pub fn test_44731_4() -> Box<Iterator<Item=impl Clone>> {
67+
Box::new(g())
68+
}
69+
2970
// @has issue_43869/fn.g.html
3071
// @has issue_43869/fn.h.html
3172
// @has issue_43869/fn.i.html
3273
// @has issue_43869/fn.j.html
74+
// @has issue_43869/fn.k.html
75+
// @has issue_43869/fn.l.html
76+
// @has issue_43869/fn.m.html
77+
// @has issue_43869/fn.n.html
78+
// @has issue_43869/fn.o.html
79+
// @has issue_43869/fn.test_44731_0.html
80+
// @has issue_43869/fn.test_44731_1.html
81+
// @has issue_43869/fn.test_44731_2.html
82+
// @has issue_43869/fn.test_44731_3.html
83+
// @has issue_43869/fn.test_44731_4.html

0 commit comments

Comments
 (0)