Skip to content

Commit f3800db

Browse files
committed
Auto merge of rust-lang#80138 - Dylan-DPC:rollup-qamsfyh, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#78164 (Prefer regions with an `external_name` in `approx_universal_upper_bound`) - rust-lang#80003 (Fix overflow when converting ZST Vec to VecDeque) - rust-lang#80023 (Enhance error message when misspelled label to value in break expression) - rust-lang#80046 (Add more documentation to `Diagnostic` and `DiagnosticBuilder`) - rust-lang#80109 (Remove redundant and unreliable coverage test results) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1954756 + f44c227 commit f3800db

File tree

70 files changed

+311
-3596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+311
-3596
lines changed

compiler/rustc_errors/src/diagnostic.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub enum DiagnosticId {
3030
Lint { name: String, has_future_breakage: bool },
3131
}
3232

33-
/// For example a note attached to an error.
33+
/// A "sub"-diagnostic attached to a parent diagnostic.
34+
/// For example, a note attached to an error.
3435
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
3536
pub struct SubDiagnostic {
3637
pub level: Level,
@@ -124,6 +125,7 @@ impl Diagnostic {
124125
self.level = Level::Cancelled;
125126
}
126127

128+
/// Check if this diagnostic [was cancelled][Self::cancel()].
127129
pub fn cancelled(&self) -> bool {
128130
self.level == Level::Cancelled
129131
}
@@ -164,7 +166,7 @@ impl Diagnostic {
164166
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
165167
}
166168

167-
pub fn note_unsuccessfull_coercion(
169+
pub fn note_unsuccessful_coercion(
168170
&mut self,
169171
expected: DiagnosticStyledString,
170172
found: DiagnosticStyledString,
@@ -241,6 +243,7 @@ impl Diagnostic {
241243
self
242244
}
243245

246+
/// Add a note attached to this diagnostic.
244247
pub fn note(&mut self, msg: &str) -> &mut Self {
245248
self.sub(Level::Note, msg, MultiSpan::new(), None);
246249
self
@@ -252,33 +255,40 @@ impl Diagnostic {
252255
}
253256

254257
/// Prints the span with a note above it.
258+
/// This is like [`Diagnostic::note()`], but it gets its own span.
255259
pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
256260
self.sub(Level::Note, msg, sp.into(), None);
257261
self
258262
}
259263

264+
/// Add a warning attached to this diagnostic.
260265
pub fn warn(&mut self, msg: &str) -> &mut Self {
261266
self.sub(Level::Warning, msg, MultiSpan::new(), None);
262267
self
263268
}
264269

265-
/// Prints the span with a warn above it.
270+
/// Prints the span with a warning above it.
271+
/// This is like [`Diagnostic::warn()`], but it gets its own span.
266272
pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
267273
self.sub(Level::Warning, msg, sp.into(), None);
268274
self
269275
}
270276

277+
/// Add a help message attached to this diagnostic.
271278
pub fn help(&mut self, msg: &str) -> &mut Self {
272279
self.sub(Level::Help, msg, MultiSpan::new(), None);
273280
self
274281
}
275282

276283
/// Prints the span with some help above it.
284+
/// This is like [`Diagnostic::help()`], but it gets its own span.
277285
pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
278286
self.sub(Level::Help, msg, sp.into(), None);
279287
self
280288
}
281289

290+
/// Show a suggestion that has multiple parts to it.
291+
/// In other words, multiple changes need to be applied as part of this suggestion.
282292
pub fn multipart_suggestion(
283293
&mut self,
284294
msg: &str,
@@ -299,6 +309,8 @@ impl Diagnostic {
299309
self
300310
}
301311

312+
/// Show multiple suggestions that have multiple parts.
313+
/// See also [`Diagnostic::multipart_suggestion()`].
302314
pub fn multipart_suggestions(
303315
&mut self,
304316
msg: &str,
@@ -382,6 +394,7 @@ impl Diagnostic {
382394
self
383395
}
384396

397+
/// [`Diagnostic::span_suggestion()`] but you can set the [`SuggestionStyle`].
385398
pub fn span_suggestion_with_style(
386399
&mut self,
387400
sp: Span,
@@ -401,6 +414,7 @@ impl Diagnostic {
401414
self
402415
}
403416

417+
/// Always show the suggested change.
404418
pub fn span_suggestion_verbose(
405419
&mut self,
406420
sp: Span,
@@ -419,6 +433,7 @@ impl Diagnostic {
419433
}
420434

421435
/// Prints out a message with multiple suggested edits of the code.
436+
/// See also [`Diagnostic::span_suggestion()`].
422437
pub fn span_suggestions(
423438
&mut self,
424439
sp: Span,
@@ -458,7 +473,7 @@ impl Diagnostic {
458473
self
459474
}
460475

461-
/// Prints out a message with for a suggestion without showing the suggested code.
476+
/// Prints out a message for a suggestion without showing the suggested code.
462477
///
463478
/// This is intended to be used for suggestions that are obvious in what the changes need to
464479
/// be from the message, showing the span label inline would be visually unpleasant
@@ -481,7 +496,7 @@ impl Diagnostic {
481496
self
482497
}
483498

484-
/// Adds a suggestion to the json output, but otherwise remains silent/undisplayed in the cli.
499+
/// Adds a suggestion to the JSON output that will not be shown in the CLI.
485500
///
486501
/// This is intended to be used for suggestions that are *very* obvious in what the changes
487502
/// need to be from the message, but we still want other tools to be able to apply them.

compiler/rustc_errors/src/diagnostic_builder.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ struct DiagnosticBuilderInner<'a> {
3030
allow_suggestions: bool,
3131
}
3232

33+
/// This is a helper macro for [`forward!`] that allows automatically adding documentation
34+
/// that uses tokens from [`forward!`]'s input.
35+
macro_rules! forward_inner_docs {
36+
($e:expr => $i:item) => {
37+
#[doc = $e]
38+
$i
39+
}
40+
}
41+
3342
/// In general, the `DiagnosticBuilder` uses deref to allow access to
3443
/// the fields and methods of the embedded `diagnostic` in a
3544
/// transparent way. *However,* many of the methods are intended to
@@ -45,10 +54,11 @@ macro_rules! forward {
4554
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)?) -> &Self
4655
) => {
4756
$(#[$attrs])*
57+
forward_inner_docs!(concat!("See [`Diagnostic::", stringify!($n), "()`].") =>
4858
pub fn $n(&self, $($name: $ty),*) -> &Self {
4959
self.diagnostic.$n($($name),*);
5060
self
51-
}
61+
});
5262
};
5363

5464
// Forward pattern for &mut self -> &mut Self
@@ -57,10 +67,11 @@ macro_rules! forward {
5767
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)?) -> &mut Self
5868
) => {
5969
$(#[$attrs])*
70+
forward_inner_docs!(concat!("See [`Diagnostic::", stringify!($n), "()`].") =>
6071
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
6172
self.0.diagnostic.$n($($name),*);
6273
self
63-
}
74+
});
6475
};
6576

6677
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
@@ -74,10 +85,11 @@ macro_rules! forward {
7485
) -> &mut Self
7586
) => {
7687
$(#[$attrs])*
88+
forward_inner_docs!(concat!("See [`Diagnostic::", stringify!($n), "()`].") =>
7789
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
7890
self.0.diagnostic.$n($($name),*);
7991
self
80-
}
92+
});
8193
};
8294
}
8395

@@ -116,7 +128,7 @@ impl<'a> DiagnosticBuilder<'a> {
116128

117129
/// Stashes diagnostic for possible later improvement in a different,
118130
/// later stage of the compiler. The diagnostic can be accessed with
119-
/// the provided `span` and `key` through `.steal_diagnostic` on `Handler`.
131+
/// the provided `span` and `key` through [`Handler::steal_diagnostic()`].
120132
///
121133
/// As with `buffer`, this is unless the handler has disabled such buffering.
122134
pub fn stash(self, span: Span, key: StashKey) {
@@ -202,7 +214,7 @@ impl<'a> DiagnosticBuilder<'a> {
202214
}
203215

204216
/// Labels all the given spans with the provided label.
205-
/// See `span_label` for more information.
217+
/// See [`Diagnostic::span_label()`] for more information.
206218
pub fn span_labels(
207219
&mut self,
208220
spans: impl IntoIterator<Item = Span>,
@@ -233,7 +245,7 @@ impl<'a> DiagnosticBuilder<'a> {
233245
found_extra: &dyn fmt::Display,
234246
) -> &mut Self);
235247

236-
forward!(pub fn note_unsuccessfull_coercion(
248+
forward!(pub fn note_unsuccessful_coercion(
237249
&mut self,
238250
expected: DiagnosticStyledString,
239251
found: DiagnosticStyledString,
@@ -254,6 +266,7 @@ impl<'a> DiagnosticBuilder<'a> {
254266
msg: &str,
255267
) -> &mut Self);
256268

269+
/// See [`Diagnostic::multipart_suggestion()`].
257270
pub fn multipart_suggestion(
258271
&mut self,
259272
msg: &str,
@@ -267,6 +280,7 @@ impl<'a> DiagnosticBuilder<'a> {
267280
self
268281
}
269282

283+
/// See [`Diagnostic::multipart_suggestions()`].
270284
pub fn multipart_suggestions(
271285
&mut self,
272286
msg: &str,
@@ -280,6 +294,7 @@ impl<'a> DiagnosticBuilder<'a> {
280294
self
281295
}
282296

297+
/// See [`Diagnostic::tool_only_multipart_suggestion()`].
283298
pub fn tool_only_multipart_suggestion(
284299
&mut self,
285300
msg: &str,
@@ -293,6 +308,7 @@ impl<'a> DiagnosticBuilder<'a> {
293308
self
294309
}
295310

311+
/// See [`Diagnostic::span_suggestion()`].
296312
pub fn span_suggestion(
297313
&mut self,
298314
sp: Span,
@@ -307,6 +323,7 @@ impl<'a> DiagnosticBuilder<'a> {
307323
self
308324
}
309325

326+
/// See [`Diagnostic::span_suggestions()`].
310327
pub fn span_suggestions(
311328
&mut self,
312329
sp: Span,
@@ -321,6 +338,7 @@ impl<'a> DiagnosticBuilder<'a> {
321338
self
322339
}
323340

341+
/// See [`Diagnostic::span_suggestion_short()`].
324342
pub fn span_suggestion_short(
325343
&mut self,
326344
sp: Span,
@@ -335,6 +353,7 @@ impl<'a> DiagnosticBuilder<'a> {
335353
self
336354
}
337355

356+
/// See [`Diagnostic::span_suggestion_verbose()`].
338357
pub fn span_suggestion_verbose(
339358
&mut self,
340359
sp: Span,
@@ -349,6 +368,7 @@ impl<'a> DiagnosticBuilder<'a> {
349368
self
350369
}
351370

371+
/// See [`Diagnostic::span_suggestion_hidden()`].
352372
pub fn span_suggestion_hidden(
353373
&mut self,
354374
sp: Span,
@@ -363,6 +383,7 @@ impl<'a> DiagnosticBuilder<'a> {
363383
self
364384
}
365385

386+
/// See [`Diagnostic::tool_only_span_suggestion()`] for more information.
366387
pub fn tool_only_span_suggestion(
367388
&mut self,
368389
sp: Span,
@@ -380,19 +401,22 @@ impl<'a> DiagnosticBuilder<'a> {
380401
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
381402
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
382403

404+
/// Allow attaching suggestions this diagnostic.
405+
/// If this is set to `false`, then any suggestions attached with the `span_suggestion_*`
406+
/// methods after this is set to `false` will be ignored.
383407
pub fn allow_suggestions(&mut self, allow: bool) -> &mut Self {
384408
self.0.allow_suggestions = allow;
385409
self
386410
}
387411

388412
/// Convenience function for internal use, clients should use one of the
389-
/// struct_* methods on Handler.
413+
/// `struct_*` methods on [`Handler`].
390414
crate fn new(handler: &'a Handler, level: Level, message: &str) -> DiagnosticBuilder<'a> {
391415
DiagnosticBuilder::new_with_code(handler, level, None, message)
392416
}
393417

394418
/// Convenience function for internal use, clients should use one of the
395-
/// struct_* methods on Handler.
419+
/// `struct_*` methods on [`Handler`].
396420
crate fn new_with_code(
397421
handler: &'a Handler,
398422
level: Level,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16221622
}
16231623
}
16241624
(TypeError::ObjectUnsafeCoercion(_), _) => {
1625-
diag.note_unsuccessfull_coercion(found, expected);
1625+
diag.note_unsuccessful_coercion(found, expected);
16261626
}
16271627
(_, _) => {
16281628
debug!(

compiler/rustc_mir/src/borrow_check/region_infer/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1145,8 +1145,24 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11451145
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
11461146
let new_lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
11471147
debug!("approx_universal_upper_bound: ur={:?} lub={:?} new_lub={:?}", ur, lub, new_lub);
1148+
// The upper bound of two non-static regions is static: this
1149+
// means we know nothing about the relationship between these
1150+
// two regions. Pick a 'better' one to use when constructing
1151+
// a diagnostic
11481152
if ur != static_r && lub != static_r && new_lub == static_r {
1149-
lub = std::cmp::min(ur, lub);
1153+
// Prefer the region with an `external_name` - this
1154+
// indicates that the region is early-bound, so working with
1155+
// it can produce a nicer error.
1156+
if self.region_definition(ur).external_name.is_some() {
1157+
lub = ur;
1158+
} else if self.region_definition(lub).external_name.is_some() {
1159+
// Leave lub unchanged
1160+
} else {
1161+
// If we get here, we don't have any reason to prefer
1162+
// one region over the other. Just pick the
1163+
// one with the lower index for now.
1164+
lub = std::cmp::min(ur, lub);
1165+
}
11501166
} else {
11511167
lub = new_lub;
11521168
}

compiler/rustc_resolve/src/late/diagnostics.rs

+20
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,26 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
542542
err.span_label(base_span, fallback_label);
543543
}
544544
}
545+
if let Some(err_code) = &err.code {
546+
if err_code == &rustc_errors::error_code!(E0425) {
547+
for label_rib in &self.label_ribs {
548+
for (label_ident, _) in &label_rib.bindings {
549+
if format!("'{}", ident) == label_ident.to_string() {
550+
let msg = "a label with a similar name exists";
551+
// FIXME: consider only emitting this suggestion if a label would be valid here
552+
// which is pretty much only the case for `break` expressions.
553+
err.span_suggestion(
554+
span,
555+
&msg,
556+
label_ident.name.to_string(),
557+
Applicability::MaybeIncorrect,
558+
);
559+
}
560+
}
561+
}
562+
}
563+
}
564+
545565
(err, candidates)
546566
}
547567

library/alloc/src/collections/vec_deque/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2793,8 +2793,12 @@ impl<T> From<Vec<T>> for VecDeque<T> {
27932793
let len = other.len();
27942794

27952795
// We need to extend the buf if it's not a power of two, too small
2796-
// or doesn't have at least one free space
2797-
if !buf.capacity().is_power_of_two()
2796+
// or doesn't have at least one free space.
2797+
// We check if `T` is a ZST in the first condition,
2798+
// because `usize::MAX` (the capacity returned by `capacity()` for ZST)
2799+
// is not a power of two and thus it'll always try
2800+
// to reserve more memory which will panic for ZST (rust-lang/rust#78532)
2801+
if (!buf.capacity().is_power_of_two() && mem::size_of::<T>() != 0)
27982802
|| (buf.capacity() < (MINIMUM_CAPACITY + 1))
27992803
|| (buf.capacity() == len)
28002804
{

library/alloc/tests/vec_deque.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1728,3 +1728,10 @@ fn test_zero_sized_push() {
17281728
}
17291729
}
17301730
}
1731+
1732+
#[test]
1733+
fn test_from_zero_sized_vec() {
1734+
let v = vec![(); 100];
1735+
let queue = VecDeque::from(v);
1736+
assert_eq!(queue.len(), 100);
1737+
}

0 commit comments

Comments
 (0)