Skip to content

Commit f6d0bfd

Browse files
committed
Auto merge of #49542 - GuillaumeGomez:intra-link-resolution-error, r=Mark-Simulacrum
Add warning if a resolution failed r? @QuietMisdreavus
2 parents 7360d6d + 4b7f4cc commit f6d0bfd

File tree

20 files changed

+223
-58
lines changed

20 files changed

+223
-58
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'a> Builder<'a> {
326326
test::TheBook, test::UnstableBook,
327327
test::Rustfmt, test::Miri, test::Clippy, test::RustdocJS, test::RustdocTheme,
328328
// Run run-make last, since these won't pass without make on Windows
329-
test::RunMake),
329+
test::RunMake, test::RustdocUi),
330330
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
331331
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
332332
doc::Standalone, doc::Std, doc::Test, doc::WhitelistedRustc, doc::Rustc,

src/bootstrap/test.rs

+52-7
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,41 @@ impl Step for RustdocJS {
514514
}
515515
}
516516

517+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
518+
pub struct RustdocUi {
519+
pub host: Interned<String>,
520+
pub target: Interned<String>,
521+
pub compiler: Compiler,
522+
}
523+
524+
impl Step for RustdocUi {
525+
type Output = ();
526+
const DEFAULT: bool = true;
527+
const ONLY_HOSTS: bool = true;
528+
529+
fn should_run(run: ShouldRun) -> ShouldRun {
530+
run.path("src/test/rustdoc-ui")
531+
}
532+
533+
fn make_run(run: RunConfig) {
534+
let compiler = run.builder.compiler(run.builder.top_stage, run.host);
535+
run.builder.ensure(RustdocUi {
536+
host: run.host,
537+
target: run.target,
538+
compiler,
539+
});
540+
}
541+
542+
fn run(self, builder: &Builder) {
543+
builder.ensure(Compiletest {
544+
compiler: self.compiler,
545+
target: self.target,
546+
mode: "ui",
547+
suite: "rustdoc-ui",
548+
})
549+
}
550+
}
551+
517552
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
518553
pub struct Tidy;
519554

@@ -851,8 +886,12 @@ impl Step for Compiletest {
851886
cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
852887
cmd.arg("--rustc-path").arg(builder.rustc(compiler));
853888

889+
let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
890+
854891
// Avoid depending on rustdoc when we don't need it.
855-
if mode == "rustdoc" || (mode == "run-make" && suite.ends_with("fulldeps")) {
892+
if mode == "rustdoc" ||
893+
(mode == "run-make" && suite.ends_with("fulldeps")) ||
894+
(mode == "ui" && is_rustdoc_ui) {
856895
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
857896
}
858897

@@ -868,12 +907,18 @@ impl Step for Compiletest {
868907
cmd.arg("--nodejs").arg(nodejs);
869908
}
870909

871-
let mut flags = vec!["-Crpath".to_string()];
872-
if build.config.rust_optimize_tests {
873-
flags.push("-O".to_string());
874-
}
875-
if build.config.rust_debuginfo_tests {
876-
flags.push("-g".to_string());
910+
let mut flags = if is_rustdoc_ui {
911+
Vec::new()
912+
} else {
913+
vec!["-Crpath".to_string()]
914+
};
915+
if !is_rustdoc_ui {
916+
if build.config.rust_optimize_tests {
917+
flags.push("-O".to_string());
918+
}
919+
if build.config.rust_debuginfo_tests {
920+
flags.push("-g".to_string());
921+
}
877922
}
878923
flags.push("-Zunstable-options".to_string());
879924
flags.push(build.config.cmd.rustc_args().join(" "));

src/libcore/iter/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ pub trait Iterator {
998998
/// an extra layer of indirection. `flat_map()` will remove this extra layer
999999
/// on its own.
10001000
///
1001-
/// You can think of [`flat_map(f)`][flat_map] as the semantic equivalent
1001+
/// You can think of `flat_map(f)` as the semantic equivalent
10021002
/// of [`map`]ping, and then [`flatten`]ing as in `map(f).flatten()`.
10031003
///
10041004
/// Another way of thinking about `flat_map()`: [`map`]'s closure returns

src/libcore/str/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub struct CharSearcher<'a> {
258258

259259
/// `finger` is the current byte index of the forward search.
260260
/// Imagine that it exists before the byte at its index, i.e.
261-
/// haystack[finger] is the first byte of the slice we must inspect during
261+
/// `haystack[finger]` is the first byte of the slice we must inspect during
262262
/// forward searching
263263
finger: usize,
264264
/// `finger_back` is the current byte index of the reverse search.

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
15501550
}
15511551
}
15521552

1553-
/// Returns the type of ty[i]
1553+
/// Returns the type of `ty[i]`.
15541554
pub fn builtin_index(&self) -> Option<Ty<'tcx>> {
15551555
match self.sty {
15561556
TyArray(ty, _) | TySlice(ty) => Some(ty),

src/librustdoc/clean/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,10 @@ enum PathKind {
11781178
Type,
11791179
}
11801180

1181+
fn resolution_failure(cx: &DocContext, path_str: &str) {
1182+
cx.sess().warn(&format!("[{}] cannot be resolved, ignoring it...", path_str));
1183+
}
1184+
11811185
impl Clean<Attributes> for [ast::Attribute] {
11821186
fn clean(&self, cx: &DocContext) -> Attributes {
11831187
let mut attrs = Attributes::from_ast(cx.sess().diagnostic(), self);
@@ -1228,6 +1232,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12281232
if let Ok(def) = resolve(cx, path_str, true) {
12291233
def
12301234
} else {
1235+
resolution_failure(cx, path_str);
12311236
// this could just be a normal link or a broken link
12321237
// we could potentially check if something is
12331238
// "intra-doc-link-like" and warn in that case
@@ -1238,6 +1243,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12381243
if let Ok(def) = resolve(cx, path_str, false) {
12391244
def
12401245
} else {
1246+
resolution_failure(cx, path_str);
12411247
// this could just be a normal link
12421248
continue;
12431249
}
@@ -1282,6 +1288,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12821288
} else if let Ok(value_def) = resolve(cx, path_str, true) {
12831289
value_def
12841290
} else {
1291+
resolution_failure(cx, path_str);
12851292
// this could just be a normal link
12861293
continue;
12871294
}
@@ -1290,6 +1297,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12901297
if let Some(def) = macro_resolve(cx, path_str) {
12911298
(def, None)
12921299
} else {
1300+
resolution_failure(cx, path_str);
12931301
continue
12941302
}
12951303
}

src/librustdoc/core.rs

+38-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc::middle::privacy::AccessLevels;
1818
use rustc::ty::{self, TyCtxt, AllArenas};
1919
use rustc::hir::map as hir_map;
2020
use rustc::lint;
21+
use rustc::session::config::ErrorOutputType;
2122
use rustc::util::nodemap::{FxHashMap, FxHashSet};
2223
use rustc_resolve as resolve;
2324
use rustc_metadata::creader::CrateLoader;
@@ -28,8 +29,9 @@ use syntax::ast::NodeId;
2829
use syntax::codemap;
2930
use syntax::edition::Edition;
3031
use syntax::feature_gate::UnstableFeatures;
32+
use syntax::json::JsonEmitter;
3133
use errors;
32-
use errors::emitter::ColorConfig;
34+
use errors::emitter::{Emitter, EmitterWriter};
3335

3436
use std::cell::{RefCell, Cell};
3537
use std::mem;
@@ -115,7 +117,6 @@ impl DocAccessLevels for AccessLevels<DefId> {
115117
}
116118
}
117119

118-
119120
pub fn run_core(search_paths: SearchPaths,
120121
cfgs: Vec<String>,
121122
externs: config::Externs,
@@ -125,7 +126,8 @@ pub fn run_core(search_paths: SearchPaths,
125126
allow_warnings: bool,
126127
crate_name: Option<String>,
127128
force_unstable_if_unmarked: bool,
128-
edition: Edition) -> (clean::Crate, RenderInfo)
129+
edition: Edition,
130+
error_format: ErrorOutputType) -> (clean::Crate, RenderInfo)
129131
{
130132
// Parse, resolve, and typecheck the given crate.
131133

@@ -137,6 +139,7 @@ pub fn run_core(search_paths: SearchPaths,
137139
let warning_lint = lint::builtin::WARNINGS.name_lower();
138140

139141
let host_triple = TargetTriple::from_triple(config::host_triple());
142+
// plays with error output here!
140143
let sessopts = config::Options {
141144
maybe_sysroot,
142145
search_paths,
@@ -153,14 +156,42 @@ pub fn run_core(search_paths: SearchPaths,
153156
edition,
154157
..config::basic_debugging_options()
155158
},
159+
error_format,
156160
..config::basic_options().clone()
157161
};
158162

159163
let codemap = Lrc::new(codemap::CodeMap::new(sessopts.file_path_mapping()));
160-
let diagnostic_handler = errors::Handler::with_tty_emitter(ColorConfig::Auto,
161-
true,
162-
false,
163-
Some(codemap.clone()));
164+
let emitter: Box<dyn Emitter> = match error_format {
165+
ErrorOutputType::HumanReadable(color_config) => Box::new(
166+
EmitterWriter::stderr(
167+
color_config,
168+
Some(codemap.clone()),
169+
false,
170+
sessopts.debugging_opts.teach,
171+
).ui_testing(sessopts.debugging_opts.ui_testing)
172+
),
173+
ErrorOutputType::Json(pretty) => Box::new(
174+
JsonEmitter::stderr(
175+
None,
176+
codemap.clone(),
177+
pretty,
178+
sessopts.debugging_opts.approximate_suggestions,
179+
).ui_testing(sessopts.debugging_opts.ui_testing)
180+
),
181+
ErrorOutputType::Short(color_config) => Box::new(
182+
EmitterWriter::stderr(color_config, Some(codemap.clone()), true, false)
183+
),
184+
};
185+
186+
let diagnostic_handler = errors::Handler::with_emitter_and_flags(
187+
emitter,
188+
errors::HandlerFlags {
189+
can_emit_warnings: true,
190+
treat_err_as_bug: false,
191+
external_macro_backtrace: false,
192+
..Default::default()
193+
},
194+
);
164195

165196
let mut sess = session::build_session_(
166197
sessopts, cpath, diagnostic_handler, codemap,

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct SharedContext {
107107
/// This describes the layout of each page, and is not modified after
108108
/// creation of the context (contains info like the favicon and added html).
109109
pub layout: layout::Layout,
110-
/// This flag indicates whether [src] links should be generated or not. If
110+
/// This flag indicates whether `[src]` links should be generated or not. If
111111
/// the source files are present in the html rendering, then this will be
112112
/// `true`.
113113
pub include_sources: bool,

src/librustdoc/lib.rs

+50-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(test)]
2424
#![feature(vec_remove_item)]
2525
#![feature(entry_and_modify)]
26+
#![feature(dyn_trait)]
2627

2728
extern crate arena;
2829
extern crate getopts;
@@ -48,6 +49,8 @@ extern crate tempdir;
4849

4950
extern crate serialize as rustc_serialize; // used by deriving
5051

52+
use errors::ColorConfig;
53+
5154
use std::collections::{BTreeMap, BTreeSet};
5255
use std::default::Default;
5356
use std::env;
@@ -274,6 +277,21 @@ pub fn opts() -> Vec<RustcOptGroup> {
274277
"edition to use when compiling rust code (default: 2015)",
275278
"EDITION")
276279
}),
280+
unstable("color", |o| {
281+
o.optopt("",
282+
"color",
283+
"Configure coloring of output:
284+
auto = colorize, if output goes to a tty (default);
285+
always = always colorize output;
286+
never = never colorize output",
287+
"auto|always|never")
288+
}),
289+
unstable("error-format", |o| {
290+
o.optopt("",
291+
"error-format",
292+
"How errors and other messages are produced",
293+
"human|json|short")
294+
}),
277295
]
278296
}
279297

@@ -358,9 +376,33 @@ pub fn main_args(args: &[String]) -> isize {
358376
}
359377
let input = &matches.free[0];
360378

379+
let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
380+
Some("auto") => ColorConfig::Auto,
381+
Some("always") => ColorConfig::Always,
382+
Some("never") => ColorConfig::Never,
383+
None => ColorConfig::Auto,
384+
Some(arg) => {
385+
print_error(&format!("argument for --color must be `auto`, `always` or `never` \
386+
(instead was `{}`)", arg));
387+
return 1;
388+
}
389+
};
390+
let error_format = match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
391+
Some("human") => ErrorOutputType::HumanReadable(color),
392+
Some("json") => ErrorOutputType::Json(false),
393+
Some("pretty-json") => ErrorOutputType::Json(true),
394+
Some("short") => ErrorOutputType::Short(color),
395+
None => ErrorOutputType::HumanReadable(color),
396+
Some(arg) => {
397+
print_error(&format!("argument for --error-format must be `human`, `json` or \
398+
`short` (instead was `{}`)", arg));
399+
return 1;
400+
}
401+
};
402+
361403
let mut libs = SearchPaths::new();
362404
for s in &matches.opt_strs("L") {
363-
libs.add_path(s, ErrorOutputType::default());
405+
libs.add_path(s, error_format);
364406
}
365407
let externs = match parse_externs(&matches) {
366408
Ok(ex) => ex,
@@ -458,7 +500,8 @@ pub fn main_args(args: &[String]) -> isize {
458500
}
459501

460502
let output_format = matches.opt_str("w");
461-
let res = acquire_input(PathBuf::from(input), externs, edition, &matches, move |out| {
503+
let res = acquire_input(PathBuf::from(input), externs, edition, &matches, error_format,
504+
move |out| {
462505
let Output { krate, passes, renderinfo } = out;
463506
info!("going to format");
464507
match output_format.as_ref().map(|s| &**s) {
@@ -501,13 +544,14 @@ fn acquire_input<R, F>(input: PathBuf,
501544
externs: Externs,
502545
edition: Edition,
503546
matches: &getopts::Matches,
547+
error_format: ErrorOutputType,
504548
f: F)
505549
-> Result<R, String>
506550
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
507551
match matches.opt_str("r").as_ref().map(|s| &**s) {
508-
Some("rust") => Ok(rust_input(input, externs, edition, matches, f)),
552+
Some("rust") => Ok(rust_input(input, externs, edition, matches, error_format, f)),
509553
Some(s) => Err(format!("unknown input format: {}", s)),
510-
None => Ok(rust_input(input, externs, edition, matches, f))
554+
None => Ok(rust_input(input, externs, edition, matches, error_format, f))
511555
}
512556
}
513557

@@ -537,6 +581,7 @@ fn rust_input<R, F>(cratefile: PathBuf,
537581
externs: Externs,
538582
edition: Edition,
539583
matches: &getopts::Matches,
584+
error_format: ErrorOutputType,
540585
f: F) -> R
541586
where R: 'static + Send,
542587
F: 'static + Send + FnOnce(Output) -> R
@@ -589,7 +634,7 @@ where R: 'static + Send,
589634
let (mut krate, renderinfo) =
590635
core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot,
591636
display_warnings, crate_name.clone(),
592-
force_unstable_if_unmarked, edition);
637+
force_unstable_if_unmarked, edition, error_format);
593638

594639
info!("finished with rustc");
595640

0 commit comments

Comments
 (0)