Skip to content

Commit 22297bd

Browse files
committed
Rollup merge of #35037 - ollie27:rustdoc_tuple_struct_where, r=alexcrichton
rustdoc: Fix tuple struct where clause rendering For tuple structs the where clause comes after the definition. Fixes #34928
2 parents be6b73f + 5c0ce87 commit 22297bd

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/librustdoc/html/render.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -2409,10 +2409,13 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
24092409
if structhead {"struct "} else {""},
24102410
it.name.as_ref().unwrap())?;
24112411
if let Some(g) = g {
2412-
write!(w, "{}{}", *g, WhereClause(g))?
2412+
write!(w, "{}", g)?
24132413
}
24142414
match ty {
24152415
doctree::Plain => {
2416+
if let Some(g) = g {
2417+
write!(w, "{}", WhereClause(g))?
2418+
}
24162419
write!(w, " {{\n{}", tab)?;
24172420
for field in fields {
24182421
if let clean::StructFieldItem(ref ty) = field.inner {
@@ -2445,9 +2448,17 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
24452448
_ => unreachable!()
24462449
}
24472450
}
2448-
write!(w, ");")?;
2451+
write!(w, ")")?;
2452+
if let Some(g) = g {
2453+
write!(w, "{}", WhereClause(g))?
2454+
}
2455+
write!(w, ";")?;
24492456
}
24502457
doctree::Unit => {
2458+
// Needed for PhantomData.
2459+
if let Some(g) = g {
2460+
write!(w, "{}", WhereClause(g))?
2461+
}
24512462
write!(w, ";")?;
24522463
}
24532464
}

src/test/rustdoc/issue-34928.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
pub trait Bar {}
14+
15+
// @has foo/struct.Foo.html '//pre' 'pub struct Foo<T>(pub T) where T: Bar;'
16+
pub struct Foo<T>(pub T) where T: Bar;

src/test/rustdoc/where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
pub trait MyTrait { fn dummy(&self) { } }
1414

15-
// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A> where A: MyTrait"
15+
// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A>(_) where A: MyTrait"
1616
pub struct Alpha<A>(A) where A: MyTrait;
1717
// @has foo/trait.Bravo.html '//pre' "pub trait Bravo<B> where B: MyTrait"
1818
pub trait Bravo<B> where B: MyTrait { fn get(&self, B: B); }

0 commit comments

Comments
 (0)