Skip to content

Commit daa4dc9

Browse files
committed
Auto merge of #88461 - GuillaumeGomez:rollup-khgu0eb, r=GuillaumeGomez
Rollup of 13 pull requests Successful merges: - #80543 (Notify when an `I-prioritize` issue is closed or reopened) - #83251 (Suggestion for call on immutable binding of mutable type) - #85534 (add rustc-demangle assertion on mangled symbol) - #88173 (Refactor Markdown length-limited summary implementation) - #88349 (Add const and static TAIT tests) - #88357 (add unsized coercion test) - #88381 (Handle stack_t.ss_sp type change for DragonFlyBSD) - #88387 (Remove vestigial rustfix tests.) - #88396 (Bump vulnerable crates) - #88407 (Fix formatting in release notes from 52a9883) - #88411 (Remove `Session.if_let_suggestions`) - #88417 (RELEASES.md: fix broken link) - #88419 (Fix code blocks color in Ayu theme) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ef52471 + 26feefd commit daa4dc9

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

+626
-214
lines changed

Diff for: Cargo.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,9 @@ dependencies = [
765765

766766
[[package]]
767767
name = "crossbeam-deque"
768-
version = "0.7.3"
768+
version = "0.7.4"
769769
source = "registry+https://github.com/rust-lang/crates.io-index"
770-
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
770+
checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed"
771771
dependencies = [
772772
"crossbeam-epoch",
773773
"crossbeam-utils 0.7.2",
@@ -2368,9 +2368,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
23682368

23692369
[[package]]
23702370
name = "openssl-src"
2371-
version = "111.15.0+1.1.1k"
2371+
version = "111.16.0+1.1.1l"
23722372
source = "registry+https://github.com/rust-lang/crates.io-index"
2373-
checksum = "b1a5f6ae2ac04393b217ea9f700cd04fa9bf3d93fae2872069f3d15d908af70a"
2373+
checksum = "7ab2173f69416cf3ec12debb5823d244127d23a9b127d5a5189aa97c5fa2859f"
23742374
dependencies = [
23752375
"cc",
23762376
]
@@ -4968,9 +4968,9 @@ dependencies = [
49684968

49694969
[[package]]
49704970
name = "tar"
4971-
version = "0.4.35"
4971+
version = "0.4.37"
49724972
source = "registry+https://github.com/rust-lang/crates.io-index"
4973-
checksum = "7d779dc6aeff029314570f666ec83f19df7280bb36ef338442cfa8c604021b80"
4973+
checksum = "d6f5515d3add52e0bbdcad7b83c388bb36ba7b754dda3b5f5bc2d38640cdba5c"
49744974
dependencies = [
49754975
"filetime",
49764976
"libc",

Diff for: RELEASES.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ Cargo
7070
- [The package definition in `cargo metadata` now includes the `"default_run"`
7171
field from the manifest.][cargo/9550]
7272
- [Added `cargo d` as an alias for `cargo doc`.][cargo/9680]
73-
- [Added `{lib}` as formatting option for `cargo tree` to print the "lib_name" of packages.][cargo/9663]
73+
- [Added `{lib}` as formatting option for `cargo tree` to print the `"lib_name"`
74+
of packages.][cargo/9663]
7475

7576
Rustdoc
7677
-------
@@ -116,9 +117,11 @@ Compatibility Notes
116117
[79965]: https://github.com/rust-lang/rust/pull/79965
117118
[87370]: https://github.com/rust-lang/rust/pull/87370
118119
[87298]: https://github.com/rust-lang/rust/pull/87298
120+
[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663
119121
[cargo/9675]: https://github.com/rust-lang/cargo/pull/9675
120122
[cargo/9550]: https://github.com/rust-lang/cargo/pull/9550
121123
[cargo/9680]: https://github.com/rust-lang/cargo/pull/9680
124+
[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663
122125
[`array::map`]: https://doc.rust-lang.org/stable/std/primitive.array.html#method.map
123126
[`Bound::cloned`]: https://doc.rust-lang.org/stable/std/ops/enum.Bound.html#method.cloned
124127
[`Drain::as_str`]: https://doc.rust-lang.org/stable/std/string/struct.Drain.html#method.as_str

Diff for: compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs

+72-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
55
use rustc_middle::ty::{self, Ty, TyCtxt};
66
use rustc_middle::{
77
hir::place::PlaceBase,
8-
mir::{self, ClearCrossCrate, Local, LocalDecl, LocalInfo, LocalKind, Location},
8+
mir::{
9+
self, BindingForm, ClearCrossCrate, ImplicitSelfKind, Local, LocalDecl, LocalInfo,
10+
LocalKind, Location,
11+
},
912
};
1013
use rustc_span::source_map::DesugaringKind;
1114
use rustc_span::symbol::{kw, Symbol};
12-
use rustc_span::Span;
15+
use rustc_span::{BytePos, Span};
1316

1417
use crate::borrow_check::diagnostics::BorrowedContentSource;
1518
use crate::borrow_check::MirBorrowckCtxt;
@@ -241,13 +244,74 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
241244
.map(|l| mut_borrow_of_mutable_ref(l, self.local_names[local]))
242245
.unwrap_or(false) =>
243246
{
247+
let decl = &self.body.local_decls[local];
244248
err.span_label(span, format!("cannot {ACT}", ACT = act));
245-
err.span_suggestion(
246-
span,
247-
"try removing `&mut` here",
248-
String::new(),
249-
Applicability::MaybeIncorrect,
250-
);
249+
if let Some(mir::Statement {
250+
source_info,
251+
kind:
252+
mir::StatementKind::Assign(box (
253+
_,
254+
mir::Rvalue::Ref(
255+
_,
256+
mir::BorrowKind::Mut { allow_two_phase_borrow: false },
257+
_,
258+
),
259+
)),
260+
..
261+
}) = &self.body[location.block].statements.get(location.statement_index)
262+
{
263+
match decl.local_info {
264+
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
265+
mir::VarBindingForm {
266+
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
267+
opt_ty_info: Some(sp),
268+
opt_match_place: _,
269+
pat_span: _,
270+
},
271+
)))) => {
272+
err.span_note(sp, "the binding is already a mutable borrow");
273+
}
274+
_ => {
275+
err.span_note(
276+
decl.source_info.span,
277+
"the binding is already a mutable borrow",
278+
);
279+
}
280+
}
281+
if let Ok(snippet) =
282+
self.infcx.tcx.sess.source_map().span_to_snippet(source_info.span)
283+
{
284+
if snippet.starts_with("&mut ") {
285+
// We don't have access to the HIR to get accurate spans, but we can
286+
// give a best effort structured suggestion.
287+
err.span_suggestion_verbose(
288+
source_info.span.with_hi(source_info.span.lo() + BytePos(5)),
289+
"try removing `&mut` here",
290+
String::new(),
291+
Applicability::MachineApplicable,
292+
);
293+
} else {
294+
// This can occur with things like `(&mut self).foo()`.
295+
err.span_help(source_info.span, "try removing `&mut` here");
296+
}
297+
} else {
298+
err.span_help(source_info.span, "try removing `&mut` here");
299+
}
300+
} else if decl.mutability == Mutability::Not
301+
&& !matches!(
302+
decl.local_info,
303+
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
304+
ImplicitSelfKind::MutRef
305+
))))
306+
)
307+
{
308+
err.span_suggestion_verbose(
309+
decl.source_info.span.shrink_to_lo(),
310+
"consider making the binding mutable",
311+
"mut ".to_string(),
312+
Applicability::MachineApplicable,
313+
);
314+
}
251315
}
252316

253317
// We want to suggest users use `let mut` for local (user

Diff for: compiler/rustc_resolve/src/late/diagnostics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
215215
"let ".to_string(),
216216
Applicability::MaybeIncorrect,
217217
);
218-
self.r.session.if_let_suggestions.borrow_mut().insert(*span);
219218
}
220219
_ => {}
221220
}

Diff for: compiler/rustc_session/src/session.rs

-4
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ pub struct Session {
209209

210210
/// Set of enabled features for the current target.
211211
pub target_features: FxHashSet<Symbol>,
212-
213-
/// `Span`s for `if` conditions that we have suggested turning into `if let`.
214-
pub if_let_suggestions: Lock<FxHashSet<Span>>,
215212
}
216213

217214
pub struct PerfStats {
@@ -1328,7 +1325,6 @@ pub fn build_session(
13281325
miri_unleashed_features: Lock::new(Default::default()),
13291326
asm_arch,
13301327
target_features: FxHashSet::default(),
1331-
if_let_suggestions: Default::default(),
13321328
};
13331329

13341330
validate_commandline_args_with_session_available(&sess);

Diff for: compiler/rustc_symbol_mangling/src/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,18 @@ fn compute_symbol_name(
246246
tcx.symbol_mangling_version(mangling_version_crate)
247247
};
248248

249-
match mangling_version {
249+
let symbol = match mangling_version {
250250
SymbolManglingVersion::Legacy => legacy::mangle(tcx, instance, instantiating_crate),
251251
SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate),
252-
}
252+
};
253+
254+
debug_assert!(
255+
rustc_demangle::try_demangle(&symbol).is_ok(),
256+
"compute_symbol_name: `{}` cannot be demangled",
257+
symbol
258+
);
259+
260+
symbol
253261
}
254262

255263
fn is_generic(substs: SubstsRef<'_>) -> bool {

Diff for: compiler/rustc_typeck/src/check/expr.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -919,9 +919,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
919919
);
920920
}
921921

922-
if self.sess().if_let_suggestions.borrow().get(&expr.span).is_some() {
923-
// We already emitted an `if let` suggestion due to an identifier not found.
924-
err.delay_as_bug();
922+
// If the assignment expression itself is ill-formed, don't
923+
// bother emitting another error
924+
if lhs_ty.references_error() || rhs_ty.references_error() {
925+
err.delay_as_bug()
925926
} else {
926927
err.emit();
927928
}

Diff for: library/std/src/sys/unix/stack_overflow.rs

-14
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,10 @@ mod imp {
161161
stackp.add(page_size())
162162
}
163163

164-
#[cfg(any(
165-
target_os = "linux",
166-
target_os = "macos",
167-
target_os = "freebsd",
168-
target_os = "netbsd",
169-
target_os = "openbsd",
170-
target_os = "solaris",
171-
target_os = "illumos"
172-
))]
173164
unsafe fn get_stack() -> libc::stack_t {
174165
libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ }
175166
}
176167

177-
#[cfg(target_os = "dragonfly")]
178-
unsafe fn get_stack() -> libc::stack_t {
179-
libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ }
180-
}
181-
182168
pub unsafe fn make_handler() -> Handler {
183169
if !NEED_ALTSTACK.load(Ordering::Relaxed) {
184170
return Handler::null();

Diff for: src/librustdoc/html/length_limit.rs

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//! See [`HtmlWithLimit`].
2+
3+
use std::fmt::Write;
4+
use std::ops::ControlFlow;
5+
6+
use crate::html::escape::Escape;
7+
8+
/// A buffer that allows generating HTML with a length limit.
9+
///
10+
/// This buffer ensures that:
11+
///
12+
/// * all tags are closed,
13+
/// * tags are closed in the reverse order of when they were opened (i.e., the correct HTML order),
14+
/// * no tags are left empty (e.g., `<em></em>`) due to the length limit being reached,
15+
/// * all text is escaped.
16+
#[derive(Debug)]
17+
pub(super) struct HtmlWithLimit {
18+
buf: String,
19+
len: usize,
20+
limit: usize,
21+
/// A list of tags that have been requested to be opened via [`Self::open_tag()`]
22+
/// but have not actually been pushed to `buf` yet. This ensures that tags are not
23+
/// left empty (e.g., `<em></em>`) due to the length limit being reached.
24+
queued_tags: Vec<&'static str>,
25+
/// A list of all tags that have been opened but not yet closed.
26+
unclosed_tags: Vec<&'static str>,
27+
}
28+
29+
impl HtmlWithLimit {
30+
/// Create a new buffer, with a limit of `length_limit`.
31+
pub(super) fn new(length_limit: usize) -> Self {
32+
let buf = if length_limit > 1000 {
33+
// If the length limit is really large, don't preallocate tons of memory.
34+
String::new()
35+
} else {
36+
// The length limit is actually a good heuristic for initial allocation size.
37+
// Measurements showed that using it as the initial capacity ended up using less memory
38+
// than `String::new`.
39+
// See https://github.com/rust-lang/rust/pull/88173#discussion_r692531631 for more.
40+
String::with_capacity(length_limit)
41+
};
42+
Self {
43+
buf,
44+
len: 0,
45+
limit: length_limit,
46+
unclosed_tags: Vec::new(),
47+
queued_tags: Vec::new(),
48+
}
49+
}
50+
51+
/// Finish using the buffer and get the written output.
52+
/// This function will close all unclosed tags for you.
53+
pub(super) fn finish(mut self) -> String {
54+
self.close_all_tags();
55+
self.buf
56+
}
57+
58+
/// Write some plain text to the buffer, escaping as needed.
59+
///
60+
/// This function skips writing the text if the length limit was reached
61+
/// and returns [`ControlFlow::Break`].
62+
pub(super) fn push(&mut self, text: &str) -> ControlFlow<(), ()> {
63+
if self.len + text.len() > self.limit {
64+
return ControlFlow::BREAK;
65+
}
66+
67+
self.flush_queue();
68+
write!(self.buf, "{}", Escape(text)).unwrap();
69+
self.len += text.len();
70+
71+
ControlFlow::CONTINUE
72+
}
73+
74+
/// Open an HTML tag.
75+
///
76+
/// **Note:** HTML attributes have not yet been implemented.
77+
/// This function will panic if called with a non-alphabetic `tag_name`.
78+
pub(super) fn open_tag(&mut self, tag_name: &'static str) {
79+
assert!(
80+
tag_name.chars().all(|c| ('a'..='z').contains(&c)),
81+
"tag_name contained non-alphabetic chars: {:?}",
82+
tag_name
83+
);
84+
self.queued_tags.push(tag_name);
85+
}
86+
87+
/// Close the most recently opened HTML tag.
88+
pub(super) fn close_tag(&mut self) {
89+
match self.unclosed_tags.pop() {
90+
// Close the most recently opened tag.
91+
Some(tag_name) => write!(self.buf, "</{}>", tag_name).unwrap(),
92+
// There are valid cases where `close_tag()` is called without
93+
// there being any tags to close. For example, this occurs when
94+
// a tag is opened after the length limit is exceeded;
95+
// `flush_queue()` will never be called, and thus, the tag will
96+
// not end up being added to `unclosed_tags`.
97+
None => {}
98+
}
99+
}
100+
101+
/// Write all queued tags and add them to the `unclosed_tags` list.
102+
fn flush_queue(&mut self) {
103+
for tag_name in self.queued_tags.drain(..) {
104+
write!(self.buf, "<{}>", tag_name).unwrap();
105+
106+
self.unclosed_tags.push(tag_name);
107+
}
108+
}
109+
110+
/// Close all unclosed tags.
111+
fn close_all_tags(&mut self) {
112+
while !self.unclosed_tags.is_empty() {
113+
self.close_tag();
114+
}
115+
}
116+
}
117+
118+
#[cfg(test)]
119+
mod tests;

0 commit comments

Comments
 (0)