Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #106544

Merged
merged 27 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0047e25
Add some docs to `bug`, `span_bug` and `delay_span_bug`
Noratrieb Dec 30, 2022
04b9038
refactor: clean up `errors.rs` and `error_codes_check.rs`
Ezrashaw Dec 29, 2022
9618f64
docs: revert removal of `E0729`
Ezrashaw Jan 1, 2023
24671b7
use more paths in error codes
Ezrashaw Jan 1, 2023
def1b7c
fix CI error
Ezrashaw Jan 1, 2023
fafb18e
fixup warnings
Ezrashaw Jan 1, 2023
1f1dd5f
pattern destructure `has_test`
Ezrashaw Jan 2, 2023
b7341db
fix CI
Ezrashaw Jan 2, 2023
c00ab4b
print highest error code
Ezrashaw Jan 2, 2023
0c43b42
Improve include macro documentation
coastalwhite Jan 4, 2023
eb2980c
Tidy up whitespace
coastalwhite Jan 4, 2023
c30f7c9
Better phrasing for hygiene of include macro
coastalwhite Jan 5, 2023
0edca66
Tiny formatting fix
estebank Jan 6, 2023
ae667be
Remove HTML tags around warning
coastalwhite Jan 6, 2023
f67aa04
Update browser-ui-test version
GuillaumeGomez Jan 6, 2023
4a68f7e
Correctly render sidebar for relative module paths
clubby789 Jan 4, 2023
d5d1c57
Update tests
clubby789 Jan 5, 2023
009064f
Use new block syntax for define-function in goml scripts
GuillaumeGomez Jan 6, 2023
5cda0a2
Add default and latest stable edition to --edition in rustc
sigaloid Jan 6, 2023
893938f
Update compiler/rustc_session/src/config.rs
sigaloid Jan 6, 2023
7568c49
Rollup merge of #106287 - Nilstrieb:its-bugging-me-how-we-dont-have-d…
matthiaskrgr Jan 6, 2023
498216e
Rollup merge of #106341 - Ezrashaw:refactor-error-code-tidy-check, r=…
matthiaskrgr Jan 6, 2023
72d650f
Rollup merge of #106453 - coastalwhite:master, r=GuillaumeGomez
matthiaskrgr Jan 6, 2023
eb27b61
Rollup merge of #106466 - clubby789:relative-module-fix, r=notriddle
matthiaskrgr Jan 6, 2023
9a090ed
Rollup merge of #106528 - estebank:quick-fix, r=TaKO8Ki
matthiaskrgr Jan 6, 2023
92d812d
Rollup merge of #106534 - GuillaumeGomez:block-syntax, r=notriddle
matthiaskrgr Jan 6, 2023
a1b3393
Rollup merge of #106542 - sigaloid:master, r=bjorn3
matthiaskrgr Jan 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0729.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#### Note: this error code is no longer emitted by the compiler

Support for Non-Lexical Lifetimes (NLL) has been included in the Rust compiler
since 1.31, and has been enabled on the 2015 edition since 1.36. The new borrow
checker for NLL uncovered some bugs in the old borrow checker, which in some
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ impl Handler {
self.inner.borrow_mut().span_bug(span, msg)
}

/// For documentation on this, see `Session::delay_span_bug`.
#[track_caller]
pub fn delay_span_bug(
&self,
Expand Down Expand Up @@ -1529,6 +1530,7 @@ impl HandlerInner {
self.emit_diagnostic(diag.set_span(sp));
}

/// For documentation on this, see `Session::delay_span_bug`.
#[track_caller]
fn delay_span_bug(
&mut self,
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_middle/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/// A macro for triggering an ICE.
/// Calling `bug` instead of panicking will result in a nicer error message and should
/// therefore be prefered over `panic`/`unreachable` or others.
///
/// If you have a span available, you should use [`span_bug`] instead.
///
/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
///
/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
/// [`span_bug`]: crate::span_bug
#[macro_export]
macro_rules! bug {
() => ( $crate::bug!("impossible case reached") );
Expand All @@ -8,6 +18,14 @@ macro_rules! bug {
});
}

/// A macro for triggering an ICE with a span.
/// Calling `span_bug!` instead of panicking will result in a nicer error message and point
/// at the code the compiler was compiling when it ICEd. This is the preferred way to trigger
/// ICEs.
///
/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
///
/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
#[macro_export]
macro_rules! span_bug {
($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) });
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/util/bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
(None, _) => panic_any(msg),
}
});
unreachable!();
})
}

/// A query to trigger a `delay_span_bug`. Clearly, if one has a `tcx` one can already trigger a
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,12 +1503,13 @@ impl<'a> Parser<'a> {
prior_type_ascription: self.last_type_ascription,
});
(lo.to(self.prev_token.span), ExprKind::MacCall(mac))
} else if self.check(&token::OpenDelim(Delimiter::Brace)) &&
let Some(expr) = self.maybe_parse_struct_expr(&qself, &path) {
if qself.is_some() {
self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
}
return expr;
} else if self.check(&token::OpenDelim(Delimiter::Brace))
&& let Some(expr) = self.maybe_parse_struct_expr(&qself, &path)
{
if qself.is_some() {
self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
}
return expr;
} else {
(path.span, ExprKind::Path(qself, path))
};
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::hash::Hash;
use std::iter;
use std::path::{Path, PathBuf};
use std::str::{self, FromStr};
use std::sync::LazyLock;

pub mod sigpipe;

Expand Down Expand Up @@ -1322,7 +1323,12 @@ mod opt {
unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
}
}

static EDITION_STRING: LazyLock<String> = LazyLock::new(|| {
format!(
"Specify which edition of the compiler to use when compiling code. \
The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE_EDITION}."
)
});
/// Returns the "short" subset of the rustc command line options,
/// including metadata for each option, such as whether the option is
/// part of the stable long-term interface for rustc.
Expand Down Expand Up @@ -1355,7 +1361,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
opt::opt_s(
"",
"edition",
"Specify which edition of the compiler to use when compiling code.",
&*EDITION_STRING,
EDITION_NAME_LIST,
),
opt::multi_s(
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,19 @@ impl Session {
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
self.diagnostic().warn(msg)
}
/// Delay a span_bug() call until abort_if_errors()

/// Ensures that compilation cannot succeed.
///
/// If this function has been called but no errors have been emitted and
/// compilation succeeds, it will cause an internal compiler error (ICE).
///
/// This can be used in code paths that should never run on successful compilations.
/// For example, it can be used to create an [`ErrorGuaranteed`]
/// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission directly).
///
/// If no span is available, use [`DUMMY_SP`].
///
/// [`DUMMY_SP`]: rustc_span::DUMMY_SP
#[track_caller]
pub fn delay_span_bug<S: Into<MultiSpan>>(
&self,
Expand Down
43 changes: 31 additions & 12 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,22 +1315,41 @@ pub(crate) mod builtin {

/// Parses a file as an expression or an item according to the context.
///
/// The file is located relative to the current file (similarly to how
/// modules are found). The provided path is interpreted in a platform-specific
/// way at compile time. So, for instance, an invocation with a Windows path
/// containing backslashes `\` would not compile correctly on Unix.
/// **Warning**: For multi-file Rust projects, the `include!` macro is probably not what you
/// are looking for. Usually, multi-file Rust projects use
/// [modules](https://doc.rust-lang.org/reference/items/modules.html). Multi-file projects and
/// modules are explained in the Rust-by-Example book
/// [here](https://doc.rust-lang.org/rust-by-example/mod/split.html) and the module system is
/// explained in the Rust Book
/// [here](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html).
///
/// The included file is placed in the surrounding code
/// [unhygienically](https://doc.rust-lang.org/reference/macros-by-example.html#hygiene). If
/// the included file is parsed as an expression and variables or functions share names across
/// both files, it could result in variables or functions being different from what the
/// included file expected.
///
/// The included file is located relative to the current file (similarly to how modules are
/// found). The provided path is interpreted in a platform-specific way at compile time. So,
/// for instance, an invocation with a Windows path containing backslashes `\` would not
/// compile correctly on Unix.
///
/// Using this macro is often a bad idea, because if the file is
/// parsed as an expression, it is going to be placed in the
/// surrounding code unhygienically. This could result in variables
/// or functions being different from what the file expected if
/// there are variables or functions that have the same name in
/// the current file.
/// # Uses
///
/// The `include!` macro is primarily used for two purposes. It is used to include
/// documentation that is written in a separate file and it is used to include [build artifacts
/// usually as a result from the `build.rs`
/// script](https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script).
///
/// When using the `include` macro to include stretches of documentation, remember that the
/// included file still needs to be a valid rust syntax. It is also possible to
/// use the [`include_str`] macro as `#![doc = include_str!("...")]` (at the module level) or
/// `#[doc = include_str!("...")]` (at the item level) to include documentation from a plain
/// text or markdown file.
///
/// # Examples
///
/// Assume there are two files in the same directory with the following
/// contents:
/// Assume there are two files in the same directory with the following contents:
///
/// File 'monkeys.in':
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.4
0.14.1
22 changes: 18 additions & 4 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'tcx> Context<'tcx> {

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

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

sources::clean_path(&src_root, file, false, |component| {
path.push_str(&component.to_string_lossy());
let href = RefCell::new(PathBuf::new());
sources::clean_path(
&src_root,
file,
|component| {
href.borrow_mut().push(component);
},
|| {
href.borrow_mut().pop();
},
);

path = href.into_inner().to_string_lossy().to_string();

if let Some(c) = path.as_bytes().last() && *c != b'/' {
path.push('/');
});
}

let mut fname = file.file_name().expect("source has no filename").to_os_string();
fname.push(".html");
path.push_str(&fname.to_string_lossy());
Expand Down
62 changes: 41 additions & 21 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::cell::RefCell;
use std::fs::{self, File};
use std::io::prelude::*;
use std::io::{self, BufReader};
use std::path::{Component, Path};
use std::rc::Rc;
use std::rc::{Rc, Weak};

use itertools::Itertools;
use rustc_data_structures::flock;
Expand Down Expand Up @@ -184,23 +185,26 @@ pub(super) fn write_shared(

use std::ffi::OsString;

#[derive(Debug)]
#[derive(Debug, Default)]
struct Hierarchy {
parent: Weak<Self>,
elem: OsString,
children: FxHashMap<OsString, Hierarchy>,
elems: FxHashSet<OsString>,
children: RefCell<FxHashMap<OsString, Rc<Self>>>,
elems: RefCell<FxHashSet<OsString>>,
}

impl Hierarchy {
fn new(elem: OsString) -> Hierarchy {
Hierarchy { elem, children: FxHashMap::default(), elems: FxHashSet::default() }
fn with_parent(elem: OsString, parent: &Rc<Self>) -> Self {
Self { elem, parent: Rc::downgrade(parent), ..Self::default() }
}

fn to_json_string(&self) -> String {
let mut subs: Vec<&Hierarchy> = self.children.values().collect();
let borrow = self.children.borrow();
let mut subs: Vec<_> = borrow.values().collect();
subs.sort_unstable_by(|a, b| a.elem.cmp(&b.elem));
let mut files = self
.elems
.borrow()
.iter()
.map(|s| format!("\"{}\"", s.to_str().expect("invalid osstring conversion")))
.collect::<Vec<_>>();
Expand All @@ -220,36 +224,52 @@ pub(super) fn write_shared(
files = files
)
}
}

if cx.include_sources {
let mut hierarchy = Hierarchy::new(OsString::new());
for source in cx
.shared
.local_sources
.iter()
.filter_map(|p| p.0.strip_prefix(&cx.shared.src_root).ok())
{
let mut h = &mut hierarchy;
let mut elems = source
fn add_path(self: &Rc<Self>, path: &Path) {
let mut h = Rc::clone(&self);
let mut elems = path
.components()
.filter_map(|s| match s {
Component::Normal(s) => Some(s.to_owned()),
Component::ParentDir => Some(OsString::from("..")),
_ => None,
})
.peekable();
loop {
let cur_elem = elems.next().expect("empty file path");
if cur_elem == ".." {
if let Some(parent) = h.parent.upgrade() {
h = parent;
}
continue;
}
if elems.peek().is_none() {
h.elems.insert(cur_elem);
h.elems.borrow_mut().insert(cur_elem);
break;
} else {
let e = cur_elem.clone();
h = h.children.entry(cur_elem.clone()).or_insert_with(|| Hierarchy::new(e));
let entry = Rc::clone(
h.children
.borrow_mut()
.entry(cur_elem.clone())
.or_insert_with(|| Rc::new(Self::with_parent(cur_elem, &h))),
);
h = entry;
}
}
}
}

if cx.include_sources {
let hierarchy = Rc::new(Hierarchy::default());
for source in cx
.shared
.local_sources
.iter()
.filter_map(|p| p.0.strip_prefix(&cx.shared.src_root).ok())
{
hierarchy.add_path(source);
}
let hierarchy = Rc::try_unwrap(hierarchy).unwrap();
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
let make_sources = || {
let (mut all_sources, _krates) =
Expand Down
Loading