Skip to content

Commit 8728c7a

Browse files
committed
Auto merge of #49542 - GuillaumeGomez:intra-link-resolution-error, r=GuillaumeGomez
Add warning if a resolution failed r? @QuietMisdreavus
2 parents 6b12d36 + 05275da commit 8728c7a

File tree

20 files changed

+224
-58
lines changed

20 files changed

+224
-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,
@@ -126,7 +127,8 @@ pub fn run_core(search_paths: SearchPaths,
126127
crate_name: Option<String>,
127128
force_unstable_if_unmarked: bool,
128129
edition: Edition,
129-
cg: CodegenOptions) -> (clean::Crate, RenderInfo)
130+
cg: CodegenOptions,
131+
error_format: ErrorOutputType) -> (clean::Crate, RenderInfo)
130132
{
131133
// Parse, resolve, and typecheck the given crate.
132134

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

140142
let host_triple = TargetTriple::from_triple(config::host_triple());
143+
// plays with error output here!
141144
let sessopts = config::Options {
142145
maybe_sysroot,
143146
search_paths,
@@ -155,14 +158,42 @@ pub fn run_core(search_paths: SearchPaths,
155158
edition,
156159
..config::basic_debugging_options()
157160
},
161+
error_format,
158162
..config::basic_options().clone()
159163
};
160164

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

167198
let mut sess = session::build_session_(
168199
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

+51-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;
@@ -279,6 +282,21 @@ pub fn opts() -> Vec<RustcOptGroup> {
279282
"edition to use when compiling rust code (default: 2015)",
280283
"EDITION")
281284
}),
285+
unstable("color", |o| {
286+
o.optopt("",
287+
"color",
288+
"Configure coloring of output:
289+
auto = colorize, if output goes to a tty (default);
290+
always = always colorize output;
291+
never = never colorize output",
292+
"auto|always|never")
293+
}),
294+
unstable("error-format", |o| {
295+
o.optopt("",
296+
"error-format",
297+
"How errors and other messages are produced",
298+
"human|json|short")
299+
}),
282300
]
283301
}
284302

@@ -363,9 +381,33 @@ pub fn main_args(args: &[String]) -> isize {
363381
}
364382
let input = &matches.free[0];
365383

384+
let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
385+
Some("auto") => ColorConfig::Auto,
386+
Some("always") => ColorConfig::Always,
387+
Some("never") => ColorConfig::Never,
388+
None => ColorConfig::Auto,
389+
Some(arg) => {
390+
print_error(&format!("argument for --color must be `auto`, `always` or `never` \
391+
(instead was `{}`)", arg));
392+
return 1;
393+
}
394+
};
395+
let error_format = match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
396+
Some("human") => ErrorOutputType::HumanReadable(color),
397+
Some("json") => ErrorOutputType::Json(false),
398+
Some("pretty-json") => ErrorOutputType::Json(true),
399+
Some("short") => ErrorOutputType::Short(color),
400+
None => ErrorOutputType::HumanReadable(color),
401+
Some(arg) => {
402+
print_error(&format!("argument for --error-format must be `human`, `json` or \
403+
`short` (instead was `{}`)", arg));
404+
return 1;
405+
}
406+
};
407+
366408
let mut libs = SearchPaths::new();
367409
for s in &matches.opt_strs("L") {
368-
libs.add_path(s, ErrorOutputType::default());
410+
libs.add_path(s, error_format);
369411
}
370412
let externs = match parse_externs(&matches) {
371413
Ok(ex) => ex,
@@ -465,7 +507,9 @@ pub fn main_args(args: &[String]) -> isize {
465507
}
466508

467509
let output_format = matches.opt_str("w");
468-
let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, move |out| {
510+
511+
let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, error_format,
512+
move |out| {
469513
let Output { krate, passes, renderinfo } = out;
470514
info!("going to format");
471515
match output_format.as_ref().map(|s| &**s) {
@@ -509,13 +553,14 @@ fn acquire_input<R, F>(input: PathBuf,
509553
edition: Edition,
510554
cg: CodegenOptions,
511555
matches: &getopts::Matches,
556+
error_format: ErrorOutputType,
512557
f: F)
513558
-> Result<R, String>
514559
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
515560
match matches.opt_str("r").as_ref().map(|s| &**s) {
516-
Some("rust") => Ok(rust_input(input, externs, edition, cg, matches, f)),
561+
Some("rust") => Ok(rust_input(input, externs, edition, cg, matches, error_format, f)),
517562
Some(s) => Err(format!("unknown input format: {}", s)),
518-
None => Ok(rust_input(input, externs, edition, cg, matches, f))
563+
None => Ok(rust_input(input, externs, edition, cg, matches, error_format, f))
519564
}
520565
}
521566

@@ -546,6 +591,7 @@ fn rust_input<R, F>(cratefile: PathBuf,
546591
edition: Edition,
547592
cg: CodegenOptions,
548593
matches: &getopts::Matches,
594+
error_format: ErrorOutputType,
549595
f: F) -> R
550596
where R: 'static + Send,
551597
F: 'static + Send + FnOnce(Output) -> R
@@ -598,7 +644,7 @@ where R: 'static + Send,
598644
let (mut krate, renderinfo) =
599645
core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot,
600646
display_warnings, crate_name.clone(),
601-
force_unstable_if_unmarked, edition, cg);
647+
force_unstable_if_unmarked, edition, cg, error_format);
602648

603649
info!("finished with rustc");
604650

0 commit comments

Comments
 (0)