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 9 pull requests #98421

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
95dc353
Fix documentation for with_capacity and reserve families of methods
jmaargh Apr 9, 2022
b37a05b
rustdoc: optimize loading of source sidebar
jsha Jun 20, 2022
761c846
Add `create_err` and `emit_err` to `ExtCtxt`
beetrees Jun 21, 2022
d6072e5
Add UI test for `cfg!(foo, bar)`
beetrees Jun 21, 2022
6264ffb
Migrate `builtin-macros-requires-cfg-pattern` to `SessionDiagnostic`
beetrees Jun 21, 2022
be5337c
Migrate `builtin-macros-expected-one-cfg-pattern` to `SessionDiagnostic`
beetrees Jun 21, 2022
8e09f42
Update Emscripten's no_default_libraries handling
hoodmane Jun 21, 2022
46b2454
clarify Arc::clone overflow check comment
RalfJung Jun 22, 2022
53481a5
implement `iter_projections` function on `PlaceRef`
rosefromthedead Jun 22, 2022
8e40d93
Filter out keyword items in rustdoc JSON output
GuillaumeGomez Jun 22, 2022
75ad2f7
Add test for keywords in rustdoc JSON output
GuillaumeGomez Jun 22, 2022
96cc0c6
triagebot.toml: Allow applying nominated labels
joshtriplett Jun 22, 2022
5cf5a52
triagebot.toml: Sort and wrap the list of allowed labels
joshtriplett Jun 22, 2022
24e0c44
Update books
ehuss Jun 22, 2022
b96ae9b
Set no_default_libraries: false in wasm32_emscripten target
hoodmane Jun 23, 2022
97f582a
Rollup merge of #96173 - jmaargh:jmaargh/with-capacity-doc-fix, r=Dyl…
matthiaskrgr Jun 23, 2022
960aaea
Rollup merge of #98310 - jsha:defer-source-sidebar, r=GuillaumeGomez
matthiaskrgr Jun 23, 2022
6ed67b7
Rollup merge of #98353 - beetrees:builtin-macros-cfg-diag, r=davidtwco
matthiaskrgr Jun 23, 2022
0252df9
Rollup merge of #98355 - hoodmane:emscripten-no-default, r=petrochenkov
matthiaskrgr Jun 23, 2022
dd97d67
Rollup merge of #98364 - RalfJung:arc-clone, r=Mark-Simulacrum
matthiaskrgr Jun 23, 2022
e9638bf
Rollup merge of #98388 - rosehuds:master, r=davidtwco
matthiaskrgr Jun 23, 2022
665ec8d
Rollup merge of #98390 - GuillaumeGomez:keyword-rustdoc-json, r=notri…
matthiaskrgr Jun 23, 2022
362801a
Rollup merge of #98409 - joshtriplett:triagebot-nominated, r=Mark-Sim…
matthiaskrgr Jun 23, 2022
2ab0edf
Rollup merge of #98410 - ehuss:update-books, r=ehuss
matthiaskrgr Jun 23, 2022
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3669,6 +3669,7 @@ dependencies = [
"rustc_feature",
"rustc_lexer",
"rustc_lint_defs",
"rustc_macros",
"rustc_parse",
"rustc_parse_format",
"rustc_session",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_builtin_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
rustc_parse = { path = "../rustc_parse" }
rustc_target = { path = "../rustc_target" }
rustc_session = { path = "../rustc_session" }
Expand Down
24 changes: 19 additions & 5 deletions compiler/rustc_builtin_macros/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_attr as attr;
use rustc_errors::PResult;
use rustc_expand::base::{self, *};
use rustc_macros::SessionDiagnostic;
use rustc_span::Span;

pub fn expand_cfg(
Expand All @@ -34,21 +35,34 @@ pub fn expand_cfg(
}
}

fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
#[derive(SessionDiagnostic)]
#[error(slug = "builtin-macros-requires-cfg-pattern")]
struct RequiresCfgPattern {
#[primary_span]
#[label]
span: Span,
}

#[derive(SessionDiagnostic)]
#[error(slug = "builtin-macros-expected-one-cfg-pattern")]
struct OneCfgPattern {
#[primary_span]
span: Span,
}

fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
let mut p = cx.new_parser_from_tts(tts);

if p.token == token::Eof {
let mut err = cx.struct_span_err(sp, "macro requires a cfg-pattern as an argument");
err.span_label(sp, "cfg-pattern required");
return Err(err);
return Err(cx.create_err(RequiresCfgPattern { span }));
}

let cfg = p.parse_meta_item()?;

let _ = p.eat(&token::Comma);

if !p.eat(&token::Eof) {
return Err(cx.struct_span_err(sp, "expected 1 cfg-pattern"));
return Err(cx.create_err(OneCfgPattern { span }));
}

Ok(cfg)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ impl<'a> Linker for EmLinker<'a> {
fn no_crt_objects(&mut self) {}

fn no_default_libraries(&mut self) {
self.cmd.args(&["-s", "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]"]);
self.cmd.arg("-nodefaultlibs");
}

fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
builtin-macros-requires-cfg-pattern =
macro requires a cfg-pattern as an argument
.label = cfg-pattern required

builtin-macros-expected-one-cfg-pattern = expected 1 cfg-pattern
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
fluent_messages! {
parser => "../locales/en-US/parser.ftl",
typeck => "../locales/en-US/typeck.ftl",
builtin_macros => "../locales/en-US/builtin_macros.ftl",
}

pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::BuiltinLintDiagnostics;
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_session::{parse::ParseSess, Limit, Session, SessionDiagnostic};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
Expand Down Expand Up @@ -1085,6 +1085,17 @@ impl<'a> ExtCtxt<'a> {
self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg)
}

pub fn create_err(
&self,
err: impl SessionDiagnostic<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.sess.create_err(err)
}

pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
self.sess.emit_err(err)
}

/// Emit `msg` attached to `sp`, without immediately stopping
/// compilation.
///
Expand Down
22 changes: 18 additions & 4 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2145,10 +2145,7 @@ impl<'tcx> Place<'tcx> {
pub fn iter_projections(
self,
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
self.projection.iter().enumerate().map(move |(i, proj)| {
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
(base, proj)
})
self.as_ref().iter_projections()
}

/// Generates a new place by appending `more_projections` to the existing ones
Expand Down Expand Up @@ -2208,6 +2205,23 @@ impl<'tcx> PlaceRef<'tcx> {
None
}
}

/// Iterate over the projections in evaluation order, i.e., the first element is the base with
/// its projection and then subsequently more projections are added.
/// As a concrete example, given the place a.b.c, this would yield:
/// - (a, .b)
/// - (a.b, .c)
///
/// Given a place without projections, the iterator is empty.
#[inline]
pub fn iter_projections(
self,
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
self.projection.iter().enumerate().map(move |(i, proj)| {
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
(base, *proj)
})
}
}

impl Debug for Place<'_> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn target() -> Target {
linker: None,
is_like_emscripten: true,
panic_strategy: PanicStrategy::Unwind,
no_default_libraries: false,
post_link_args,
families: cvs!["unix", "wasm"],
..options
Expand Down
51 changes: 29 additions & 22 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,11 @@ impl<T: Ord> BinaryHeap<T> {
BinaryHeap { data: vec![] }
}

/// Creates an empty `BinaryHeap` with a specific capacity.
/// This preallocates enough memory for `capacity` elements,
/// so that the `BinaryHeap` does not have to be reallocated
/// until it contains at least that many values.
/// Creates an empty `BinaryHeap` with at least the specified capacity.
///
/// The binary heap will be able to hold at least `capacity` elements without
/// reallocating. This method is allowed to allocate for more elements than
/// `capacity`. If `capacity` is 0, the binary heap will not allocate.
///
/// # Examples
///
Expand Down Expand Up @@ -906,16 +907,18 @@ impl<T> BinaryHeap<T> {
self.data.capacity()
}

/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
/// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
/// Reserves the minimum capacity for at least `additional` elements more than
/// the current length. Unlike [`reserve`], this will not
/// deliberately over-allocate to speculatively avoid frequent allocations.
/// After calling `reserve_exact`, capacity will be greater than or equal to
/// `self.len() + additional`. Does nothing if the capacity is already
/// sufficient.
///
/// Note that the allocator may give the collection more space than it requests. Therefore
/// capacity can not be relied upon to be precisely minimal. Prefer [`reserve`] if future
/// insertions are expected.
/// [`reserve`]: BinaryHeap::reserve
///
/// # Panics
///
/// Panics if the new capacity overflows `usize`.
/// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
Expand All @@ -935,12 +938,15 @@ impl<T> BinaryHeap<T> {
self.data.reserve_exact(additional);
}

/// Reserves capacity for at least `additional` more elements to be inserted in the
/// `BinaryHeap`. The collection may reserve more space to avoid frequent reallocations.
/// Reserves capacity for at least `additional` elements more than the
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `reserve`,
/// capacity will be greater than or equal to `self.len() + additional`.
/// Does nothing if capacity is already sufficient.
///
/// # Panics
///
/// Panics if the new capacity overflows `usize`.
/// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
Expand All @@ -958,10 +964,11 @@ impl<T> BinaryHeap<T> {
self.data.reserve(additional);
}

/// Tries to reserve the minimum capacity for exactly `additional`
/// elements to be inserted in the given `BinaryHeap<T>`. After calling
/// `try_reserve_exact`, capacity will be greater than or equal to
/// `self.len() + additional` if it returns `Ok(())`.
/// Tries to reserve the minimum capacity for at least `additional` elements
/// more than the current length. Unlike [`try_reserve`], this will not
/// deliberately over-allocate to speculatively avoid frequent allocations.
/// After calling `try_reserve_exact`, capacity will be greater than or
/// equal to `self.len() + additional` if it returns `Ok(())`.
/// Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
Expand Down Expand Up @@ -999,11 +1006,11 @@ impl<T> BinaryHeap<T> {
self.data.try_reserve_exact(additional)
}

/// Tries to reserve capacity for at least `additional` more elements to be inserted
/// in the given `BinaryHeap<T>`. The collection may reserve more space to avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional`. Does nothing if
/// capacity is already sufficient.
/// Tries to reserve capacity for at least `additional` elements more than the
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
Expand Down
16 changes: 8 additions & 8 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
self.cap() - 1
}

/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
/// Reserves the minimum capacity for at least `additional` more elements to be inserted in the
/// given deque. Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it requests. Therefore
Expand Down Expand Up @@ -716,7 +716,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
}

/// Reserves capacity for at least `additional` more elements to be inserted in the given
/// deque. The collection may reserve more space to avoid frequent reallocations.
/// deque. The collection may reserve more space to speculatively avoid frequent reallocations.
///
/// # Panics
///
Expand Down Expand Up @@ -748,10 +748,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
}
}

/// Tries to reserve the minimum capacity for exactly `additional` more elements to
/// Tries to reserve the minimum capacity for at least `additional` more elements to
/// be inserted in the given deque. After calling `try_reserve_exact`,
/// capacity will be greater than or equal to `self.len() + additional`.
/// Does nothing if the capacity is already sufficient.
/// capacity will be greater than or equal to `self.len() + additional` if
/// it returns `Ok(())`. Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
Expand Down Expand Up @@ -791,10 +791,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
}

/// Tries to reserve capacity for at least `additional` more elements to be inserted
/// in the given deque. The collection may reserve more space to avoid
/// in the given deque. The collection may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional`. Does nothing if
/// capacity is already sufficient.
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
Expand Down
Loading