Skip to content

Commit

Permalink
rustdoc: Add a primitive page for raw pointers
Browse files Browse the repository at this point in the history
Closes #15318
  • Loading branch information
alexcrichton committed Apr 8, 2015
1 parent c9c7be7 commit 9ad133b
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ fn document(config: &Config, props: &TestProps,
testfile: &Path, extra_args: &[String]) -> (ProcRes, PathBuf) {
let aux_dir = aux_output_dir_name(config, testfile);
let out_dir = output_base_name(config, testfile);
let _ = fs::remove_dir_all(&out_dir);
ensure_dir(&out_dir);
let mut args = vec!["-L".to_string(),
aux_dir.to_str().unwrap().to_string(),
Expand Down
3 changes: 2 additions & 1 deletion src/etc/htmldocck.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def concat_multi_lines(f):

firstlineno = firstlineno or lineno
if line.endswith('\\'):
lastline = line[:-1]
if lastline is None:
lastline = line[:-1]
catenated += line[:-1]
else:
yield firstlineno, catenated + line
Expand Down
1 change: 1 addition & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
//! of unsafe pointers in Rust.
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "pointer")]

use mem;
use clone::Clone;
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ pub enum PrimitiveType {
Slice,
Array,
PrimitiveTuple,
PrimitiveRawPointer,
}

#[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)]
Expand Down Expand Up @@ -1404,6 +1405,7 @@ impl PrimitiveType {
"array" => Some(Array),
"slice" => Some(Slice),
"tuple" => Some(PrimitiveTuple),
"pointer" => Some(PrimitiveRawPointer),
_ => None,
}
}
Expand Down Expand Up @@ -1449,6 +1451,7 @@ impl PrimitiveType {
Array => "array",
Slice => "slice",
PrimitiveTuple => "tuple",
PrimitiveRawPointer => "pointer",
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ impl fmt::Display for clean::Type {
}
clean::Bottom => f.write_str("!"),
clean::RawPointer(m, ref t) => {
write!(f, "*{}{}", RawMutableSpace(m), **t)
primitive_link(f, clean::PrimitiveType::PrimitiveRawPointer,
&format!("*{}{}", RawMutableSpace(m), **t))
}
clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
let lt = match *l {
Expand Down
12 changes: 9 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,8 @@ impl DocFolder for Cache {
clean::Item{ attrs, inner: clean::ImplItem(i), .. } => {
use clean::{Primitive, Vector, ResolvedPath, BorrowedRef};
use clean::PrimitiveType::{Array, Slice, PrimitiveTuple};
use clean::{FixedVector, Tuple};
use clean::PrimitiveType::{PrimitiveRawPointer};
use clean::{FixedVector, Tuple, RawPointer};

// extract relevant documentation for this impl
let dox = match attrs.into_iter().find(|a| {
Expand Down Expand Up @@ -1064,8 +1065,8 @@ impl DocFolder for Cache {
Some(ast_util::local_def(Array.to_node_id()))
}

// In a DST world, we may only need Vector, but for now we
// also pick up borrowed references
// In a DST world, we may only need Vector, but for
// now we also pick up borrowed references
Vector(..) |
BorrowedRef{ type_: box Vector(..), .. } =>
{
Expand All @@ -1077,6 +1078,11 @@ impl DocFolder for Cache {
Some(ast_util::local_def(id))
}

RawPointer(..) => {
let id = PrimitiveRawPointer.to_node_id();
Some(ast_util::local_def(id))
}

_ => None,
};

Expand Down
15 changes: 15 additions & 0 deletions src/test/auxiliary/issue-15318.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![doc(html_root_url = "http://example.com/")]

/// dox
#[doc(primitive = "pointer")]
pub mod ptr {}
21 changes: 21 additions & 0 deletions src/test/rustdoc/issue-15318-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:issue-15318.rs

extern crate issue_15318;

pub use issue_15318::ptr;

// @has issue_15318_2/fn.bar.html \
// '//*[@href="primitive.pointer.html"]' \
// '*mut T'
pub fn bar<T>(ptr: *mut T) {}

15 changes: 15 additions & 0 deletions src/test/rustdoc/issue-15318-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// @has issue_15318_3/primitive.pointer.html

/// dox
#[doc(primitive = "pointer")]
pub mod ptr {}
21 changes: 21 additions & 0 deletions src/test/rustdoc/issue-15318.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:issue-15318.rs

#![feature(no_std)]
#![no_std]

extern crate issue_15318;

// @has issue_15318/fn.bar.html \
// '//*[@href="http://example.com/issue_15318/primitive.pointer.html"]' \
// '*mut T'
pub fn bar<T>(ptr: *mut T) {}

0 comments on commit 9ad133b

Please sign in to comment.