Skip to content

Rollup of 13 pull requests #88461

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

Merged
merged 35 commits into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9c7dbe8
Notify when an `I-prioritize` issue is closed
LeSeulArtichaut Dec 31, 2020
39ef8ea
Refactor Markdown length-limited summary implementation
camelid Jul 22, 2021
09f0876
Clarify wording in docs
camelid Aug 21, 2021
74147b8
Use the length limit as the initial capacity
camelid Aug 21, 2021
d18936a
Use `write!`
camelid Aug 22, 2021
4fcae2c
Add const and static TAIT tests
spastorino Aug 25, 2021
f8ca576
Add tests for `HtmlWithLimit`
camelid Aug 22, 2021
d932e62
Assert that `tag_name` is alphabetic
camelid Aug 25, 2021
4478ecc
Don't panic if `close_tag()` is called without tags to close
camelid Aug 26, 2021
bee13d1
add unsized coercion test
lcnr Aug 26, 2021
e663728
Remove vestigial rustfix tests.
ehuss Aug 27, 2021
5eb960c
add rustc-demangle assertion on mangled symbol
csmoe May 21, 2021
92e30f6
crossbeam-deque v0.7.3 -> v0.7.4:
klensy Aug 27, 2021
7a46ff5
Fix formatting in release notes from 52a988344bce118347d6a6567e67e20b…
nebkor Aug 27, 2021
0d1d978
Handle stack_t.ss_sp type change for DragonFlyBSD
rtzoeller Aug 27, 2021
672d370
Remove `Session.if_let_suggestions`
Aaron1011 Aug 27, 2021
2de6c14
RELEASES.md: fix broken link
xu-cheng Aug 28, 2021
1c3aedd
Fix code blocks color in ayu theme
GuillaumeGomez Aug 28, 2021
261ee26
Add test for code blocks color
GuillaumeGomez Aug 28, 2021
e4368de
Suggestion for call on immutable binding of mutable type
estebank Mar 18, 2021
a6af6d6
Provide structured suggestion for removal of `&mut`
estebank Aug 9, 2021
5b6f4b9
rebase: fix test output
estebank Aug 29, 2021
8eb50ce
Rollup merge of #80543 - LeSeulArtichaut:notify-close, r=spastorino
GuillaumeGomez Aug 29, 2021
22973a8
Rollup merge of #83251 - estebank:issue-83241, r=oli-obk
GuillaumeGomez Aug 29, 2021
63cfbf5
Rollup merge of #85534 - csmoe:demagnle-assert, r=michaelwoerister
GuillaumeGomez Aug 29, 2021
aa61575
Rollup merge of #88173 - camelid:refactor-markdown-length-limit, r=Gu…
GuillaumeGomez Aug 29, 2021
3e1a15b
Rollup merge of #88349 - spastorino:const-static-types-tait-test, r=o…
GuillaumeGomez Aug 29, 2021
fdb4b7c
Rollup merge of #88357 - lcnr:stabilize-relaxed_struct_unsize, r=Mark…
GuillaumeGomez Aug 29, 2021
281dfac
Rollup merge of #88381 - rtzoeller:dfly_stack_t_ss_sp_void, r=dtolnay
GuillaumeGomez Aug 29, 2021
1a6e8d7
Rollup merge of #88387 - ehuss:remove-rustfix-tests, r=Mark-Simulacrum
GuillaumeGomez Aug 29, 2021
efed604
Rollup merge of #88396 - klensy:bump-deps-vuln, r=Mark-Simulacrum
GuillaumeGomez Aug 29, 2021
9ffbd50
Rollup merge of #88407 - nebkor:release-note-1.55x2, r=Mark-Simulacrum
GuillaumeGomez Aug 29, 2021
b738802
Rollup merge of #88411 - Aaron1011:remove-session-if-let, r=estebank
GuillaumeGomez Aug 29, 2021
7248ff2
Rollup merge of #88417 - xu-cheng:rel-fix-link, r=jyn514
GuillaumeGomez Aug 29, 2021
26feefd
Rollup merge of #88419 - GuillaumeGomez:code-blocks-colors, r=camelid…
GuillaumeGomez Aug 29, 2021
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
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ dependencies = [

[[package]]
name = "crossbeam-deque"
version = "0.7.3"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils 0.7.2",
Expand Down Expand Up @@ -2368,9 +2368,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"

[[package]]
name = "openssl-src"
version = "111.15.0+1.1.1k"
version = "111.16.0+1.1.1l"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a5f6ae2ac04393b217ea9f700cd04fa9bf3d93fae2872069f3d15d908af70a"
checksum = "7ab2173f69416cf3ec12debb5823d244127d23a9b127d5a5189aa97c5fa2859f"
dependencies = [
"cc",
]
Expand Down Expand Up @@ -4968,9 +4968,9 @@ dependencies = [

[[package]]
name = "tar"
version = "0.4.35"
version = "0.4.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d779dc6aeff029314570f666ec83f19df7280bb36ef338442cfa8c604021b80"
checksum = "d6f5515d3add52e0bbdcad7b83c388bb36ba7b754dda3b5f5bc2d38640cdba5c"
dependencies = [
"filetime",
"libc",
Expand Down
5 changes: 4 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Cargo
- [The package definition in `cargo metadata` now includes the `"default_run"`
field from the manifest.][cargo/9550]
- [Added `cargo d` as an alias for `cargo doc`.][cargo/9680]
- [Added `{lib}` as formatting option for `cargo tree` to print the "lib_name" of packages.][cargo/9663]
- [Added `{lib}` as formatting option for `cargo tree` to print the `"lib_name"`
of packages.][cargo/9663]

Rustdoc
-------
Expand Down Expand Up @@ -116,9 +117,11 @@ Compatibility Notes
[79965]: https://github.com/rust-lang/rust/pull/79965
[87370]: https://github.com/rust-lang/rust/pull/87370
[87298]: https://github.com/rust-lang/rust/pull/87298
[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663
[cargo/9675]: https://github.com/rust-lang/cargo/pull/9675
[cargo/9550]: https://github.com/rust-lang/cargo/pull/9550
[cargo/9680]: https://github.com/rust-lang/cargo/pull/9680
[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663
[`array::map`]: https://doc.rust-lang.org/stable/std/primitive.array.html#method.map
[`Bound::cloned`]: https://doc.rust-lang.org/stable/std/ops/enum.Bound.html#method.cloned
[`Drain::as_str`]: https://doc.rust-lang.org/stable/std/string/struct.Drain.html#method.as_str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{
hir::place::PlaceBase,
mir::{self, ClearCrossCrate, Local, LocalDecl, LocalInfo, LocalKind, Location},
mir::{
self, BindingForm, ClearCrossCrate, ImplicitSelfKind, Local, LocalDecl, LocalInfo,
LocalKind, Location,
},
};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::{kw, Symbol};
use rustc_span::Span;
use rustc_span::{BytePos, Span};

use crate::borrow_check::diagnostics::BorrowedContentSource;
use crate::borrow_check::MirBorrowckCtxt;
Expand Down Expand Up @@ -241,13 +244,74 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
.map(|l| mut_borrow_of_mutable_ref(l, self.local_names[local]))
.unwrap_or(false) =>
{
let decl = &self.body.local_decls[local];
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_suggestion(
span,
"try removing `&mut` here",
String::new(),
Applicability::MaybeIncorrect,
);
if let Some(mir::Statement {
source_info,
kind:
mir::StatementKind::Assign(box (
_,
mir::Rvalue::Ref(
_,
mir::BorrowKind::Mut { allow_two_phase_borrow: false },
_,
),
)),
..
}) = &self.body[location.block].statements.get(location.statement_index)
{
match decl.local_info {
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
mir::VarBindingForm {
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
opt_ty_info: Some(sp),
opt_match_place: _,
pat_span: _,
},
)))) => {
err.span_note(sp, "the binding is already a mutable borrow");
}
_ => {
err.span_note(
decl.source_info.span,
"the binding is already a mutable borrow",
);
}
}
if let Ok(snippet) =
self.infcx.tcx.sess.source_map().span_to_snippet(source_info.span)
{
if snippet.starts_with("&mut ") {
// We don't have access to the HIR to get accurate spans, but we can
// give a best effort structured suggestion.
err.span_suggestion_verbose(
source_info.span.with_hi(source_info.span.lo() + BytePos(5)),
"try removing `&mut` here",
String::new(),
Applicability::MachineApplicable,
);
} else {
// This can occur with things like `(&mut self).foo()`.
err.span_help(source_info.span, "try removing `&mut` here");
}
} else {
err.span_help(source_info.span, "try removing `&mut` here");
}
} else if decl.mutability == Mutability::Not
&& !matches!(
decl.local_info,
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
ImplicitSelfKind::MutRef
))))
)
{
err.span_suggestion_verbose(
decl.source_info.span.shrink_to_lo(),
"consider making the binding mutable",
"mut ".to_string(),
Applicability::MachineApplicable,
);
}
}

// We want to suggest users use `let mut` for local (user
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
"let ".to_string(),
Applicability::MaybeIncorrect,
);
self.r.session.if_let_suggestions.borrow_mut().insert(*span);
}
_ => {}
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ pub struct Session {

/// Set of enabled features for the current target.
pub target_features: FxHashSet<Symbol>,

/// `Span`s for `if` conditions that we have suggested turning into `if let`.
pub if_let_suggestions: Lock<FxHashSet<Span>>,
}

pub struct PerfStats {
Expand Down Expand Up @@ -1328,7 +1325,6 @@ pub fn build_session(
miri_unleashed_features: Lock::new(Default::default()),
asm_arch,
target_features: FxHashSet::default(),
if_let_suggestions: Default::default(),
};

validate_commandline_args_with_session_available(&sess);
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_symbol_mangling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,18 @@ fn compute_symbol_name(
tcx.symbol_mangling_version(mangling_version_crate)
};

match mangling_version {
let symbol = match mangling_version {
SymbolManglingVersion::Legacy => legacy::mangle(tcx, instance, instantiating_crate),
SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate),
}
};

debug_assert!(
rustc_demangle::try_demangle(&symbol).is_ok(),
"compute_symbol_name: `{}` cannot be demangled",
symbol
);

symbol
}

fn is_generic(substs: SubstsRef<'_>) -> bool {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

if self.sess().if_let_suggestions.borrow().get(&expr.span).is_some() {
// We already emitted an `if let` suggestion due to an identifier not found.
err.delay_as_bug();
// If the assignment expression itself is ill-formed, don't
// bother emitting another error
if lhs_ty.references_error() || rhs_ty.references_error() {
err.delay_as_bug()
} else {
err.emit();
}
Expand Down
14 changes: 0 additions & 14 deletions library/std/src/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,10 @@ mod imp {
stackp.add(page_size())
}

#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_os = "illumos"
))]
unsafe fn get_stack() -> libc::stack_t {
libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ }
}

#[cfg(target_os = "dragonfly")]
unsafe fn get_stack() -> libc::stack_t {
libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ }
}

pub unsafe fn make_handler() -> Handler {
if !NEED_ALTSTACK.load(Ordering::Relaxed) {
return Handler::null();
Expand Down
119 changes: 119 additions & 0 deletions src/librustdoc/html/length_limit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//! See [`HtmlWithLimit`].

use std::fmt::Write;
use std::ops::ControlFlow;

use crate::html::escape::Escape;

/// A buffer that allows generating HTML with a length limit.
///
/// This buffer ensures that:
///
/// * all tags are closed,
/// * tags are closed in the reverse order of when they were opened (i.e., the correct HTML order),
/// * no tags are left empty (e.g., `<em></em>`) due to the length limit being reached,
/// * all text is escaped.
#[derive(Debug)]
pub(super) struct HtmlWithLimit {
buf: String,
len: usize,
limit: usize,
/// A list of tags that have been requested to be opened via [`Self::open_tag()`]
/// but have not actually been pushed to `buf` yet. This ensures that tags are not
/// left empty (e.g., `<em></em>`) due to the length limit being reached.
queued_tags: Vec<&'static str>,
/// A list of all tags that have been opened but not yet closed.
unclosed_tags: Vec<&'static str>,
}

impl HtmlWithLimit {
/// Create a new buffer, with a limit of `length_limit`.
pub(super) fn new(length_limit: usize) -> Self {
let buf = if length_limit > 1000 {
// If the length limit is really large, don't preallocate tons of memory.
String::new()
} else {
// The length limit is actually a good heuristic for initial allocation size.
// Measurements showed that using it as the initial capacity ended up using less memory
// than `String::new`.
// See https://github.com/rust-lang/rust/pull/88173#discussion_r692531631 for more.
String::with_capacity(length_limit)
};
Self {
buf,
len: 0,
limit: length_limit,
unclosed_tags: Vec::new(),
queued_tags: Vec::new(),
}
}

/// Finish using the buffer and get the written output.
/// This function will close all unclosed tags for you.
pub(super) fn finish(mut self) -> String {
self.close_all_tags();
self.buf
}

/// Write some plain text to the buffer, escaping as needed.
///
/// This function skips writing the text if the length limit was reached
/// and returns [`ControlFlow::Break`].
pub(super) fn push(&mut self, text: &str) -> ControlFlow<(), ()> {
if self.len + text.len() > self.limit {
return ControlFlow::BREAK;
}

self.flush_queue();
write!(self.buf, "{}", Escape(text)).unwrap();
self.len += text.len();

ControlFlow::CONTINUE
}

/// Open an HTML tag.
///
/// **Note:** HTML attributes have not yet been implemented.
/// This function will panic if called with a non-alphabetic `tag_name`.
pub(super) fn open_tag(&mut self, tag_name: &'static str) {
assert!(
tag_name.chars().all(|c| ('a'..='z').contains(&c)),
"tag_name contained non-alphabetic chars: {:?}",
tag_name
);
self.queued_tags.push(tag_name);
}

/// Close the most recently opened HTML tag.
pub(super) fn close_tag(&mut self) {
match self.unclosed_tags.pop() {
// Close the most recently opened tag.
Some(tag_name) => write!(self.buf, "</{}>", tag_name).unwrap(),
// There are valid cases where `close_tag()` is called without
// there being any tags to close. For example, this occurs when
// a tag is opened after the length limit is exceeded;
// `flush_queue()` will never be called, and thus, the tag will
// not end up being added to `unclosed_tags`.
None => {}
}
}

/// Write all queued tags and add them to the `unclosed_tags` list.
fn flush_queue(&mut self) {
for tag_name in self.queued_tags.drain(..) {
write!(self.buf, "<{}>", tag_name).unwrap();

self.unclosed_tags.push(tag_name);
}
}

/// Close all unclosed tags.
fn close_all_tags(&mut self) {
while !self.unclosed_tags.is_empty() {
self.close_tag();
}
}
}

#[cfg(test)]
mod tests;
Loading