Skip to content

Commit

Permalink
Auto merge of rust-lang#88461 - GuillaumeGomez:rollup-khgu0eb, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

Rollup of 13 pull requests

Successful merges:

 - rust-lang#80543 (Notify when an `I-prioritize` issue is closed or reopened)
 - rust-lang#83251 (Suggestion for call on immutable binding of mutable type)
 - rust-lang#85534 (add rustc-demangle assertion on mangled symbol)
 - rust-lang#88173 (Refactor Markdown length-limited summary implementation)
 - rust-lang#88349 (Add const and static TAIT tests)
 - rust-lang#88357 (add unsized coercion test)
 - rust-lang#88381 (Handle stack_t.ss_sp type change for DragonFlyBSD)
 - rust-lang#88387 (Remove vestigial rustfix tests.)
 - rust-lang#88396 (Bump vulnerable crates)
 - rust-lang#88407 (Fix formatting in release notes from 52a9883)
 - rust-lang#88411 (Remove `Session.if_let_suggestions`)
 - rust-lang#88417 (RELEASES.md: fix broken link)
 - rust-lang#88419 (Fix code blocks color in Ayu theme)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 29, 2021
2 parents ef52471 + 26feefd commit daa4dc9
Show file tree
Hide file tree
Showing 50 changed files with 626 additions and 214 deletions.
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

0 comments on commit daa4dc9

Please sign in to comment.