Skip to content

Commit 84f22e4

Browse files
committed
Auto merge of rust-lang#106544 - matthiaskrgr:rollup-e9prjed, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#106287 (Add some docs to `bug`, `span_bug` and `delay_span_bug`) - rust-lang#106341 (refactor: clean up `errors.rs` and `error_codes_check.rs`) - rust-lang#106453 (Improve include macro documentation) - rust-lang#106466 (Fix rustdoc source code rendering for `#[path = "../path/to/mod.rs"]` links) - rust-lang#106528 (Tiny formatting fix) - rust-lang#106534 (rustdoc-gui: Use new block syntax for define-function in goml scripts) - rust-lang#106542 (Add default and latest stable edition to --edition in rustc (attempt 2)) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7ac9572 + a1b3393 commit 84f22e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1149
-1042
lines changed

compiler/rustc_error_codes/src/error_codes/E0729.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#### Note: this error code is no longer emitted by the compiler
2+
13
Support for Non-Lexical Lifetimes (NLL) has been included in the Rust compiler
24
since 1.31, and has been enabled on the 2015 edition since 1.36. The new borrow
35
checker for NLL uncovered some bugs in the old borrow checker, which in some

compiler/rustc_errors/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ impl Handler {
978978
self.inner.borrow_mut().span_bug(span, msg)
979979
}
980980

981+
/// For documentation on this, see `Session::delay_span_bug`.
981982
#[track_caller]
982983
pub fn delay_span_bug(
983984
&self,
@@ -1529,6 +1530,7 @@ impl HandlerInner {
15291530
self.emit_diagnostic(diag.set_span(sp));
15301531
}
15311532

1533+
/// For documentation on this, see `Session::delay_span_bug`.
15321534
#[track_caller]
15331535
fn delay_span_bug(
15341536
&mut self,

compiler/rustc_middle/src/macros.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/// A macro for triggering an ICE.
2+
/// Calling `bug` instead of panicking will result in a nicer error message and should
3+
/// therefore be prefered over `panic`/`unreachable` or others.
4+
///
5+
/// If you have a span available, you should use [`span_bug`] instead.
6+
///
7+
/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
8+
///
9+
/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
10+
/// [`span_bug`]: crate::span_bug
111
#[macro_export]
212
macro_rules! bug {
313
() => ( $crate::bug!("impossible case reached") );
@@ -8,6 +18,14 @@ macro_rules! bug {
818
});
919
}
1020

21+
/// A macro for triggering an ICE with a span.
22+
/// Calling `span_bug!` instead of panicking will result in a nicer error message and point
23+
/// at the code the compiler was compiling when it ICEd. This is the preferred way to trigger
24+
/// ICEs.
25+
///
26+
/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
27+
///
28+
/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
1129
#[macro_export]
1230
macro_rules! span_bug {
1331
($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) });

compiler/rustc_middle/src/util/bug.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
3535
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
3636
(None, _) => panic_any(msg),
3737
}
38-
});
39-
unreachable!();
38+
})
4039
}
4140

4241
/// A query to trigger a `delay_span_bug`. Clearly, if one has a `tcx` one can already trigger a

compiler/rustc_parse/src/parser/expr.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1503,12 +1503,13 @@ impl<'a> Parser<'a> {
15031503
prior_type_ascription: self.last_type_ascription,
15041504
});
15051505
(lo.to(self.prev_token.span), ExprKind::MacCall(mac))
1506-
} else if self.check(&token::OpenDelim(Delimiter::Brace)) &&
1507-
let Some(expr) = self.maybe_parse_struct_expr(&qself, &path) {
1508-
if qself.is_some() {
1509-
self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
1510-
}
1511-
return expr;
1506+
} else if self.check(&token::OpenDelim(Delimiter::Brace))
1507+
&& let Some(expr) = self.maybe_parse_struct_expr(&qself, &path)
1508+
{
1509+
if qself.is_some() {
1510+
self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
1511+
}
1512+
return expr;
15121513
} else {
15131514
(path.span, ExprKind::Path(qself, path))
15141515
};

compiler/rustc_session/src/config.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::hash::Hash;
3535
use std::iter;
3636
use std::path::{Path, PathBuf};
3737
use std::str::{self, FromStr};
38+
use std::sync::LazyLock;
3839

3940
pub mod sigpipe;
4041

@@ -1322,7 +1323,12 @@ mod opt {
13221323
unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
13231324
}
13241325
}
1325-
1326+
static EDITION_STRING: LazyLock<String> = LazyLock::new(|| {
1327+
format!(
1328+
"Specify which edition of the compiler to use when compiling code. \
1329+
The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE_EDITION}."
1330+
)
1331+
});
13261332
/// Returns the "short" subset of the rustc command line options,
13271333
/// including metadata for each option, such as whether the option is
13281334
/// part of the stable long-term interface for rustc.
@@ -1355,7 +1361,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
13551361
opt::opt_s(
13561362
"",
13571363
"edition",
1358-
"Specify which edition of the compiler to use when compiling code.",
1364+
&*EDITION_STRING,
13591365
EDITION_NAME_LIST,
13601366
),
13611367
opt::multi_s(

compiler/rustc_session/src/session.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,19 @@ impl Session {
590590
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
591591
self.diagnostic().warn(msg)
592592
}
593-
/// Delay a span_bug() call until abort_if_errors()
593+
594+
/// Ensures that compilation cannot succeed.
595+
///
596+
/// If this function has been called but no errors have been emitted and
597+
/// compilation succeeds, it will cause an internal compiler error (ICE).
598+
///
599+
/// This can be used in code paths that should never run on successful compilations.
600+
/// For example, it can be used to create an [`ErrorGuaranteed`]
601+
/// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission directly).
602+
///
603+
/// If no span is available, use [`DUMMY_SP`].
604+
///
605+
/// [`DUMMY_SP`]: rustc_span::DUMMY_SP
594606
#[track_caller]
595607
pub fn delay_span_bug<S: Into<MultiSpan>>(
596608
&self,

library/core/src/macros/mod.rs

+31-12
Original file line numberDiff line numberDiff line change
@@ -1315,22 +1315,41 @@ pub(crate) mod builtin {
13151315

13161316
/// Parses a file as an expression or an item according to the context.
13171317
///
1318-
/// The file is located relative to the current file (similarly to how
1319-
/// modules are found). The provided path is interpreted in a platform-specific
1320-
/// way at compile time. So, for instance, an invocation with a Windows path
1321-
/// containing backslashes `\` would not compile correctly on Unix.
1318+
/// **Warning**: For multi-file Rust projects, the `include!` macro is probably not what you
1319+
/// are looking for. Usually, multi-file Rust projects use
1320+
/// [modules](https://doc.rust-lang.org/reference/items/modules.html). Multi-file projects and
1321+
/// modules are explained in the Rust-by-Example book
1322+
/// [here](https://doc.rust-lang.org/rust-by-example/mod/split.html) and the module system is
1323+
/// explained in the Rust Book
1324+
/// [here](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html).
1325+
///
1326+
/// The included file is placed in the surrounding code
1327+
/// [unhygienically](https://doc.rust-lang.org/reference/macros-by-example.html#hygiene). If
1328+
/// the included file is parsed as an expression and variables or functions share names across
1329+
/// both files, it could result in variables or functions being different from what the
1330+
/// included file expected.
1331+
///
1332+
/// The included file is located relative to the current file (similarly to how modules are
1333+
/// found). The provided path is interpreted in a platform-specific way at compile time. So,
1334+
/// for instance, an invocation with a Windows path containing backslashes `\` would not
1335+
/// compile correctly on Unix.
13221336
///
1323-
/// Using this macro is often a bad idea, because if the file is
1324-
/// parsed as an expression, it is going to be placed in the
1325-
/// surrounding code unhygienically. This could result in variables
1326-
/// or functions being different from what the file expected if
1327-
/// there are variables or functions that have the same name in
1328-
/// the current file.
1337+
/// # Uses
1338+
///
1339+
/// The `include!` macro is primarily used for two purposes. It is used to include
1340+
/// documentation that is written in a separate file and it is used to include [build artifacts
1341+
/// usually as a result from the `build.rs`
1342+
/// script](https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script).
1343+
///
1344+
/// When using the `include` macro to include stretches of documentation, remember that the
1345+
/// included file still needs to be a valid rust syntax. It is also possible to
1346+
/// use the [`include_str`] macro as `#![doc = include_str!("...")]` (at the module level) or
1347+
/// `#[doc = include_str!("...")]` (at the item level) to include documentation from a plain
1348+
/// text or markdown file.
13291349
///
13301350
/// # Examples
13311351
///
1332-
/// Assume there are two files in the same directory with the following
1333-
/// contents:
1352+
/// Assume there are two files in the same directory with the following contents:
13341353
///
13351354
/// File 'monkeys.in':
13361355
///
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.13.4
1+
0.14.1

src/librustdoc/html/render/context.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'tcx> Context<'tcx> {
309309

310310
pub(crate) fn href_from_span(&self, span: clean::Span, with_lines: bool) -> Option<String> {
311311
let mut root = self.root_path();
312-
let mut path = String::new();
312+
let mut path: String;
313313
let cnum = span.cnum(self.sess());
314314

315315
// We can safely ignore synthetic `SourceFile`s.
@@ -340,10 +340,24 @@ impl<'tcx> Context<'tcx> {
340340
ExternalLocation::Unknown => return None,
341341
};
342342

343-
sources::clean_path(&src_root, file, false, |component| {
344-
path.push_str(&component.to_string_lossy());
343+
let href = RefCell::new(PathBuf::new());
344+
sources::clean_path(
345+
&src_root,
346+
file,
347+
|component| {
348+
href.borrow_mut().push(component);
349+
},
350+
|| {
351+
href.borrow_mut().pop();
352+
},
353+
);
354+
355+
path = href.into_inner().to_string_lossy().to_string();
356+
357+
if let Some(c) = path.as_bytes().last() && *c != b'/' {
345358
path.push('/');
346-
});
359+
}
360+
347361
let mut fname = file.file_name().expect("source has no filename").to_os_string();
348362
fname.push(".html");
349363
path.push_str(&fname.to_string_lossy());

src/librustdoc/html/render/write_shared.rs

+41-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use std::cell::RefCell;
12
use std::fs::{self, File};
23
use std::io::prelude::*;
34
use std::io::{self, BufReader};
45
use std::path::{Component, Path};
5-
use std::rc::Rc;
6+
use std::rc::{Rc, Weak};
67

78
use itertools::Itertools;
89
use rustc_data_structures::flock;
@@ -184,23 +185,26 @@ pub(super) fn write_shared(
184185

185186
use std::ffi::OsString;
186187

187-
#[derive(Debug)]
188+
#[derive(Debug, Default)]
188189
struct Hierarchy {
190+
parent: Weak<Self>,
189191
elem: OsString,
190-
children: FxHashMap<OsString, Hierarchy>,
191-
elems: FxHashSet<OsString>,
192+
children: RefCell<FxHashMap<OsString, Rc<Self>>>,
193+
elems: RefCell<FxHashSet<OsString>>,
192194
}
193195

194196
impl Hierarchy {
195-
fn new(elem: OsString) -> Hierarchy {
196-
Hierarchy { elem, children: FxHashMap::default(), elems: FxHashSet::default() }
197+
fn with_parent(elem: OsString, parent: &Rc<Self>) -> Self {
198+
Self { elem, parent: Rc::downgrade(parent), ..Self::default() }
197199
}
198200

199201
fn to_json_string(&self) -> String {
200-
let mut subs: Vec<&Hierarchy> = self.children.values().collect();
202+
let borrow = self.children.borrow();
203+
let mut subs: Vec<_> = borrow.values().collect();
201204
subs.sort_unstable_by(|a, b| a.elem.cmp(&b.elem));
202205
let mut files = self
203206
.elems
207+
.borrow()
204208
.iter()
205209
.map(|s| format!("\"{}\"", s.to_str().expect("invalid osstring conversion")))
206210
.collect::<Vec<_>>();
@@ -220,36 +224,52 @@ pub(super) fn write_shared(
220224
files = files
221225
)
222226
}
223-
}
224227

225-
if cx.include_sources {
226-
let mut hierarchy = Hierarchy::new(OsString::new());
227-
for source in cx
228-
.shared
229-
.local_sources
230-
.iter()
231-
.filter_map(|p| p.0.strip_prefix(&cx.shared.src_root).ok())
232-
{
233-
let mut h = &mut hierarchy;
234-
let mut elems = source
228+
fn add_path(self: &Rc<Self>, path: &Path) {
229+
let mut h = Rc::clone(&self);
230+
let mut elems = path
235231
.components()
236232
.filter_map(|s| match s {
237233
Component::Normal(s) => Some(s.to_owned()),
234+
Component::ParentDir => Some(OsString::from("..")),
238235
_ => None,
239236
})
240237
.peekable();
241238
loop {
242239
let cur_elem = elems.next().expect("empty file path");
240+
if cur_elem == ".." {
241+
if let Some(parent) = h.parent.upgrade() {
242+
h = parent;
243+
}
244+
continue;
245+
}
243246
if elems.peek().is_none() {
244-
h.elems.insert(cur_elem);
247+
h.elems.borrow_mut().insert(cur_elem);
245248
break;
246249
} else {
247-
let e = cur_elem.clone();
248-
h = h.children.entry(cur_elem.clone()).or_insert_with(|| Hierarchy::new(e));
250+
let entry = Rc::clone(
251+
h.children
252+
.borrow_mut()
253+
.entry(cur_elem.clone())
254+
.or_insert_with(|| Rc::new(Self::with_parent(cur_elem, &h))),
255+
);
256+
h = entry;
249257
}
250258
}
251259
}
260+
}
252261

262+
if cx.include_sources {
263+
let hierarchy = Rc::new(Hierarchy::default());
264+
for source in cx
265+
.shared
266+
.local_sources
267+
.iter()
268+
.filter_map(|p| p.0.strip_prefix(&cx.shared.src_root).ok())
269+
{
270+
hierarchy.add_path(source);
271+
}
272+
let hierarchy = Rc::try_unwrap(hierarchy).unwrap();
253273
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
254274
let make_sources = || {
255275
let (mut all_sources, _krates) =

0 commit comments

Comments
 (0)