Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Manishearth/rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: doc-resolve-syntax
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 9 commits
  • 9 files changed
  • 2 contributors

Commits on Dec 25, 2017

  1. Copy the full SHA
    604333f View commit details
  2. add RenderType to DocContext

    QuietMisdreavus authored and Manishearth committed Dec 25, 2017
    Copy the full SHA
    d20d4e8 View commit details
  3. Copy the full SHA
    8c020b3 View commit details
  4. Copy the full SHA
    77bcfec View commit details
  5. Copy the full SHA
    38b265f View commit details
  6. Copy the full SHA
    0dddf48 View commit details
  7. bad lint

    Manishearth committed Dec 25, 2017
    Copy the full SHA
    8f1e1c1 View commit details
  8. pass it down to rustdoc

    Manishearth committed Dec 25, 2017
    Copy the full SHA
    c0372a3 View commit details
  9. Copy the full SHA
    0bb8c93 View commit details
7 changes: 5 additions & 2 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
@@ -9,9 +9,10 @@
// except according to those terms.

use rustc::dep_graph::DepGraph;
use rustc::hir::{self, map as hir_map};
use rustc::hir::{self, def as hir_def, map as hir_map};
use rustc::hir::lowering::lower_crate;
use rustc::ich::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_mir as mir;
use rustc::session::{Session, CompileResult, CrateDisambiguator};
@@ -158,7 +159,7 @@ pub fn compile_input(sess: &Session,

let crate_name =
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest, .. } = {
phase_2_configure_and_expand(
sess,
&cstore,
@@ -617,6 +618,7 @@ pub struct ExpansionResult {
pub analysis: ty::CrateAnalysis,
pub resolutions: Resolutions,
pub hir_forest: hir_map::Forest,
pub doc_link_map: FxHashMap<String, hir_def::Def>,
}

/// Run the "early phases" of the compiler: initial `cfg` processing,
@@ -931,6 +933,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
maybe_unused_extern_crates: resolver.maybe_unused_extern_crates,
},
hir_forest,
doc_link_map: resolver.doc_link_map,
})
}

2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
@@ -358,7 +358,7 @@ impl MissingDoc {

if let Some(list) = attr.meta_item_list() {
for meta in list {
if meta.check_name("include") {
if meta.check_name("include") || meta.check_name("text") {
return true;
}
}
55 changes: 52 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -1354,6 +1354,8 @@ pub struct Resolver<'a> {
current_type_ascription: Vec<Span>,

injected_crate: Option<Module<'a>>,

pub doc_link_map: FxHashMap<String, Def>,
}

pub struct ResolverArenas<'a> {
@@ -1554,6 +1556,8 @@ impl<'a> Resolver<'a> {
unused_macros: FxHashSet(),
current_type_ascription: Vec::new(),
injected_crate: None,

doc_link_map: FxHashMap(),
}
}

@@ -1881,7 +1885,7 @@ impl<'a> Resolver<'a> {

debug!("(resolving item) resolving {}", name);

self.check_proc_macro_attrs(&item.attrs);
self.handle_item_attrs(&item.attrs);

match item.node {
ItemKind::Enum(_, ref generics) |
@@ -1915,7 +1919,7 @@ impl<'a> Resolver<'a> {
walk_list!(this, visit_ty_param_bound, bounds);

for trait_item in trait_items {
this.check_proc_macro_attrs(&trait_item.attrs);
this.handle_item_attrs(&trait_item.attrs);

let type_parameters = HasTypeParameters(&trait_item.generics,
TraitOrImplItemRibKind);
@@ -2164,7 +2168,7 @@ impl<'a> Resolver<'a> {
this.visit_generics(generics);
this.with_current_self_type(self_type, |this| {
for impl_item in impl_items {
this.check_proc_macro_attrs(&impl_item.attrs);
this.handle_item_attrs(&impl_item.attrs);
this.resolve_visibility(&impl_item.vis);

// We also need a new scope for the impl item type parameters.
@@ -3927,6 +3931,12 @@ impl<'a> Resolver<'a> {
self.session.buffer_lint(lint::builtin::LEGACY_IMPORTS, id, span, msg);
}

fn handle_item_attrs(&mut self, attrs: &[ast::Attribute]) {
// XXXManishearth we should only loop once
self.check_proc_macro_attrs(attrs);
self.resolve_doc_link_attrs(attrs);
}

fn check_proc_macro_attrs(&mut self, attrs: &[ast::Attribute]) {
if self.proc_macro_enabled { return; }

@@ -3954,6 +3964,45 @@ impl<'a> Resolver<'a> {
}
}
}

fn resolve_doc_link_attrs(&mut self, attrs: &[ast::Attribute]) {
// FIXME(Manishearth) bail early when not in rustdoc mode

for attr in attrs {
if !attr.check_name("doc") {
return;
}
if let Some(list) = attr.meta_item_list() {
if list.get(1).map(|l| l.check_name("link")).unwrap_or(false) {
for link in list {
if let Some(innerlist) = link.meta_item_list() {
let (text, id) = if let Some((name, val)) = innerlist.get(0).and_then(|item| item.name_value_literal()) {
let val = if let ast::LitKind::Str(val, ..) = val.node {
val
} else { continue };
(name, val)
} else {
continue;
};
let path: Vec<_> = text.as_str().split("::").skip(1)
.map(|seg| respan(DUMMY_SP, Ident::with_empty_ctxt(seg.into()))).collect();
let namespace = TypeNS;
let def = match self.resolve_path(&path, Some(namespace), false, DUMMY_SP) {
PathResult::Module(module) => module.def().unwrap(),
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 =>
path_res.base_def(),
_ => continue,
};
// FIXME(Manishearth) probably should store these as u32 directly
// since otherwise it's possible to trigger UB by manually writing one of these
// doc attrs
self.doc_link_map.insert(String::from(&*id.as_str()), def);
}
}
}
}
}
}
}

fn is_struct_like(def: Def) -> bool {
33 changes: 32 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
@@ -635,6 +635,7 @@ pub struct Attributes {
pub other_attrs: Vec<ast::Attribute>,
pub cfg: Option<Rc<Cfg>>,
pub span: Option<syntax_pos::Span>,
pub links: HashMap<String, String>,
}

impl Attributes {
@@ -661,6 +662,33 @@ impl Attributes {
None
}

fn extract_doc_str(mi: &ast::MetaItem, map: &mut HashMap<String, String>) -> Option<&str> {
if let Some(value) = mi.value_str() {
Some(value);
} else if let Some(list) = mi.meta_item_list() {
if let Some((n, v)) = list.get(0).and_then(|li| li.name_value_literal()) {
if n == "text" {
let ret = if let ast::LitKind::String(s, _) = v.node {
Some(s)
} else { return None };
for link in list.iter().skip(1) {
let list = link.meta_item_list()?;
let link = list.get(0)?.name_value_literal()?;
let id = list.get(1)?.name_value_literal()?;
if let (ast::LitKind::String(link, _), ast::LitKind::String(id, _)) = (link.1, id.1) {
map.insert(link.to_string(), id.to_string())
}
}

ret
}
None
}
} else {
None
}
}

/// Reads a `MetaItem` from within an attribute, looks for whether it is a
/// `#[doc(include="file")]`, and returns the filename and contents of the file as loaded from
/// its expansion.
@@ -722,12 +750,13 @@ impl Attributes {
let mut sp = None;
let mut cfg = Cfg::True;
let mut doc_line = 0;
let mut links = HashMap::new();

let other_attrs = attrs.iter().filter_map(|attr| {
attr.with_desugared_doc(|attr| {
if attr.check_name("doc") {
if let Some(mi) = attr.meta() {
if let Some(value) = mi.value_str() {
if let Some(value) = Attributes::extract_doc_str(&mi, &mut links) {
// Extracted #[doc = "..."]
let value = value.to_string();
let line = doc_line;
@@ -759,6 +788,7 @@ impl Attributes {
filename,
contents));
}

}
}
Some(attr.clone())
@@ -769,6 +799,7 @@ impl Attributes {
other_attrs,
cfg: if cfg == Cfg::True { None } else { Some(Rc::new(cfg)) },
span: sp,
links
}
}

7 changes: 6 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ use std::path::PathBuf;
use visit_ast::RustdocVisitor;
use clean;
use clean::Clean;
use html::markdown::RenderType;
use html::render::RenderInfo;

pub use rustc::session::config::Input;
@@ -55,6 +56,8 @@ pub struct DocContext<'a, 'tcx: 'a> {
pub renderinfo: RefCell<RenderInfo>,
/// Later on moved through `clean::Crate` into `html::render::CACHE_KEY`
pub external_traits: RefCell<FxHashMap<DefId, clean::Trait>>,
/// Which markdown renderer to use when extracting links.
pub render_type: RenderType,

// The current set of type and lifetime substitutions,
// for expanding type aliases at the HIR level:
@@ -105,7 +108,8 @@ pub fn run_core(search_paths: SearchPaths,
triple: Option<String>,
maybe_sysroot: Option<PathBuf>,
allow_warnings: bool,
force_unstable_if_unmarked: bool) -> (clean::Crate, RenderInfo)
force_unstable_if_unmarked: bool,
render_type: RenderType) -> (clean::Crate, RenderInfo)
{
// Parse, resolve, and typecheck the given crate.

@@ -207,6 +211,7 @@ pub fn run_core(search_paths: SearchPaths,
access_levels: RefCell::new(access_levels),
external_traits: Default::default(),
renderinfo: Default::default(),
render_type,
ty_substs: Default::default(),
lt_substs: Default::default(),
};
Loading