Skip to content

Commit 14c0c3e

Browse files
committed
Auto merge of #87095 - JohnTitor:rollup-mn7ggy2, r=JohnTitor
Rollup of 11 pull requests Successful merges: - #86344 (Split MaybeUninit::write into new feature gate and stabilize it) - #86811 (Remove unstable `io::Cursor::remaining`) - #86846 (stdio_locked: add tracking issue) - #86887 (rustdoc: remove dead code in `clean`) - #87007 (Fix rust-analyzer install when not available.) - #87035 (Fix implementors display) - #87065 (Fix ICE with unsized type in const pattern) - #87070 (Simplify future incompatible reporting.) - #87077 (:arrow_up: rust-analyzer) - #87078 (Rustdoc: suggest removing disambiguator if linking to field) - #87089 (CTFE engine: small cleanups) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents aa06edb + e46b790 commit 14c0c3e

File tree

37 files changed

+316
-204
lines changed

37 files changed

+316
-204
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,7 @@ __pycache__/
7272
**node_modules
7373
**package-lock.json
7474

75+
## Rustdoc GUI tests
76+
src/test/rustdoc-gui/src/**.lock
77+
7578
# Before adding new lines, see the comment at the top.

compiler/rustc_errors/src/emitter.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
1010
use Destination::*;
1111

12-
use rustc_lint_defs::FutureBreakage;
1312
use rustc_span::source_map::SourceMap;
1413
use rustc_span::{MultiSpan, SourceFile, Span};
1514

@@ -193,7 +192,7 @@ pub trait Emitter {
193192
/// other formats can, and will, simply ignore it.
194193
fn emit_artifact_notification(&mut self, _path: &Path, _artifact_type: &str) {}
195194

196-
fn emit_future_breakage_report(&mut self, _diags: Vec<(FutureBreakage, Diagnostic)>) {}
195+
fn emit_future_breakage_report(&mut self, _diags: Vec<Diagnostic>) {}
197196

198197
/// Emit list of unused externs
199198
fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {}

compiler/rustc_errors/src/json.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::registry::Registry;
1616
use crate::DiagnosticId;
1717
use crate::ToolMetadata;
1818
use crate::{CodeSuggestion, SubDiagnostic};
19-
use rustc_lint_defs::{Applicability, FutureBreakage};
19+
use rustc_lint_defs::Applicability;
2020

2121
use rustc_data_structures::sync::Lrc;
2222
use rustc_span::hygiene::ExpnData;
@@ -134,17 +134,14 @@ impl Emitter for JsonEmitter {
134134
}
135135
}
136136

137-
fn emit_future_breakage_report(&mut self, diags: Vec<(FutureBreakage, crate::Diagnostic)>) {
137+
fn emit_future_breakage_report(&mut self, diags: Vec<crate::Diagnostic>) {
138138
let data: Vec<FutureBreakageItem> = diags
139139
.into_iter()
140-
.map(|(breakage, mut diag)| {
140+
.map(|mut diag| {
141141
if diag.level == crate::Level::Allow {
142142
diag.level = crate::Level::Warning;
143143
}
144-
FutureBreakageItem {
145-
future_breakage_date: breakage.date,
146-
diagnostic: Diagnostic::from_errors_diagnostic(&diag, self),
147-
}
144+
FutureBreakageItem { diagnostic: Diagnostic::from_errors_diagnostic(&diag, self) }
148145
})
149146
.collect();
150147
let report = FutureIncompatReport { future_incompat_report: data };
@@ -326,7 +323,6 @@ struct ArtifactNotification<'a> {
326323

327324
#[derive(Encodable)]
328325
struct FutureBreakageItem {
329-
future_breakage_date: Option<&'static str>,
330326
diagnostic: Diagnostic,
331327
}
332328

compiler/rustc_errors/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2323
use rustc_data_structures::stable_hasher::StableHasher;
2424
use rustc_data_structures::sync::{self, Lock, Lrc};
2525
use rustc_data_structures::AtomicRef;
26-
use rustc_lint_defs::FutureBreakage;
2726
pub use rustc_lint_defs::{pluralize, Applicability};
2827
use rustc_serialize::json::Json;
2928
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
@@ -790,7 +789,7 @@ impl Handler {
790789
self.inner.borrow_mut().emit_artifact_notification(path, artifact_type)
791790
}
792791

793-
pub fn emit_future_breakage_report(&self, diags: Vec<(FutureBreakage, Diagnostic)>) {
792+
pub fn emit_future_breakage_report(&self, diags: Vec<Diagnostic>) {
794793
self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
795794
}
796795

compiler/rustc_lint_defs/src/builtin.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! compiler code, rather than using their own custom pass. Those
77
//! lints are all available in `rustc_lint::builtin`.
88
9-
use crate::{declare_lint, declare_lint_pass, FutureBreakage, FutureIncompatibilityReason};
9+
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
1010
use rustc_span::edition::Edition;
1111

1212
declare_lint! {
@@ -3176,9 +3176,7 @@ declare_lint! {
31763176
"detects usage of old versions of certain proc-macro crates",
31773177
@future_incompatible = FutureIncompatibleInfo {
31783178
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3179-
future_breakage: Some(FutureBreakage {
3180-
date: None
3181-
})
3179+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
31823180
};
31833181
}
31843182

compiler/rustc_lint_defs/src/lib.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ pub struct FutureIncompatibleInfo {
152152
/// Set to false for lints that already include a more detailed
153153
/// explanation.
154154
pub explain_reason: bool,
155-
/// Information about a future breakage, which will
156-
/// be emitted in JSON messages to be displayed by Cargo
157-
/// for upstream deps
158-
pub future_breakage: Option<FutureBreakage>,
159155
}
160156

161157
/// The reason for future incompatibility
@@ -164,6 +160,9 @@ pub enum FutureIncompatibilityReason {
164160
/// This will be an error in a future release
165161
/// for all editions
166162
FutureReleaseError,
163+
/// This will be an error in a future release, and
164+
/// Cargo should create a report even for dependencies
165+
FutureReleaseErrorReportNow,
167166
/// Previously accepted code that will become an
168167
/// error in the provided edition
169168
EditionError(Edition),
@@ -182,18 +181,12 @@ impl FutureIncompatibilityReason {
182181
}
183182
}
184183

185-
#[derive(Copy, Clone, Debug)]
186-
pub struct FutureBreakage {
187-
pub date: Option<&'static str>,
188-
}
189-
190184
impl FutureIncompatibleInfo {
191185
pub const fn default_fields_for_macro() -> Self {
192186
FutureIncompatibleInfo {
193187
reference: "",
194188
reason: FutureIncompatibilityReason::FutureReleaseError,
195189
explain_reason: true,
196-
future_breakage: None,
197190
}
198191
}
199192
}

compiler/rustc_middle/src/lint.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::HirId;
88
use rustc_index::vec::IndexVec;
99
use rustc_session::lint::{
1010
builtin::{self, FORBIDDEN_LINT_GROUPS},
11-
FutureIncompatibilityReason, Level, Lint, LintId,
11+
FutureIncompatibilityReason, FutureIncompatibleInfo, Level, Lint, LintId,
1212
};
1313
use rustc_session::{DiagnosticMessageId, Session};
1414
use rustc_span::hygiene::MacroKind;
@@ -223,8 +223,13 @@ pub fn struct_lint_level<'s, 'd>(
223223
let lint_id = LintId::of(lint);
224224
let future_incompatible = lint.future_incompatible;
225225

226-
let has_future_breakage =
227-
future_incompatible.map_or(false, |incompat| incompat.future_breakage.is_some());
226+
let has_future_breakage = matches!(
227+
future_incompatible,
228+
Some(FutureIncompatibleInfo {
229+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
230+
..
231+
})
232+
);
228233

229234
let mut err = match (level, span) {
230235
(Level::Allow, span) => {

compiler/rustc_middle/src/mir/interpret/allocation.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl InitMaskCompressed {
512512
/// Transferring the initialization mask to other allocations.
513513
impl<Tag, Extra> Allocation<Tag, Extra> {
514514
/// Creates a run-length encoding of the initialization mask.
515-
pub fn compress_uninit_range(&self, src: Pointer<Tag>, size: Size) -> InitMaskCompressed {
515+
pub fn compress_uninit_range(&self, range: AllocRange) -> InitMaskCompressed {
516516
// Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`),
517517
// a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from
518518
// the source and write it to the destination. Even if we optimized the memory accesses,
@@ -526,13 +526,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
526526
// where each element toggles the state.
527527

528528
let mut ranges = smallvec::SmallVec::<[u64; 1]>::new();
529-
let initial = self.init_mask.get(src.offset);
529+
let initial = self.init_mask.get(range.start);
530530
let mut cur_len = 1;
531531
let mut cur = initial;
532532

533-
for i in 1..size.bytes() {
533+
for i in 1..range.size.bytes() {
534534
// FIXME: optimize to bitshift the current uninitialized block's bits and read the top bit.
535-
if self.init_mask.get(src.offset + Size::from_bytes(i)) == cur {
535+
if self.init_mask.get(range.start + Size::from_bytes(i)) == cur {
536536
cur_len += 1;
537537
} else {
538538
ranges.push(cur_len);
@@ -550,24 +550,23 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
550550
pub fn mark_compressed_init_range(
551551
&mut self,
552552
defined: &InitMaskCompressed,
553-
dest: Pointer<Tag>,
554-
size: Size,
553+
range: AllocRange,
555554
repeat: u64,
556555
) {
557556
// An optimization where we can just overwrite an entire range of initialization
558557
// bits if they are going to be uniformly `1` or `0`.
559558
if defined.ranges.len() <= 1 {
560559
self.init_mask.set_range_inbounds(
561-
dest.offset,
562-
dest.offset + size * repeat, // `Size` operations
560+
range.start,
561+
range.start + range.size * repeat, // `Size` operations
563562
defined.initial,
564563
);
565564
return;
566565
}
567566

568567
for mut j in 0..repeat {
569-
j *= size.bytes();
570-
j += dest.offset.bytes();
568+
j *= range.size.bytes();
569+
j += range.start.bytes();
571570
let mut cur = defined.initial;
572571
for range in &defined.ranges {
573572
let old_j = j;

compiler/rustc_mir/src/interpret/eval_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use rustc_span::{Pos, Span};
1818
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};
1919

2020
use super::{
21-
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, Operand, Place, PlaceTy,
22-
ScalarMaybeUninit, StackPopJump,
21+
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, MemoryKind, Operand, Place,
22+
PlaceTy, ScalarMaybeUninit, StackPopJump,
2323
};
2424
use crate::transform::validate::equal_up_to_regions;
2525
use crate::util::storage::AlwaysLiveLocals;
@@ -900,7 +900,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
900900
// due to the local having ZST type.
901901
let ptr = ptr.assert_ptr();
902902
trace!("deallocating local: {:?}", self.memory.dump_alloc(ptr.alloc_id));
903-
self.memory.deallocate_local(ptr)?;
903+
self.memory.deallocate(ptr, None, MemoryKind::Stack)?;
904904
};
905905
Ok(())
906906
}

compiler/rustc_mir/src/interpret/memory.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
276276
Ok(new_ptr)
277277
}
278278

279-
/// Deallocate a local, or do nothing if that local has been made into a global.
280-
pub fn deallocate_local(&mut self, ptr: Pointer<M::PointerTag>) -> InterpResult<'tcx> {
281-
// The allocation might be already removed by global interning.
282-
// This can only really happen in the CTFE instance, not in miri.
283-
if self.alloc_map.contains_key(&ptr.alloc_id) {
284-
self.deallocate(ptr, None, MemoryKind::Stack)
285-
} else {
286-
Ok(())
287-
}
288-
}
289-
290279
pub fn deallocate(
291280
&mut self,
292281
ptr: Pointer<M::PointerTag>,
@@ -1049,7 +1038,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
10491038
num_copies,
10501039
);
10511040
// Prepare a copy of the initialization mask.
1052-
let compressed = src_alloc.compress_uninit_range(src, size);
1041+
let compressed = src_alloc.compress_uninit_range(alloc_range(src.offset, size));
10531042
// This checks relocation edges on the src.
10541043
let src_bytes = src_alloc
10551044
.get_bytes_with_uninit_and_ptr(&tcx, alloc_range(src.offset, size))
@@ -1110,7 +1099,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
11101099
}
11111100

11121101
// now fill in all the "init" data
1113-
dest_alloc.mark_compressed_init_range(&compressed, dest, size, num_copies);
1102+
dest_alloc.mark_compressed_init_range(
1103+
&compressed,
1104+
alloc_range(dest.offset, size),
1105+
num_copies,
1106+
);
11141107
// copy the relocations to the destination
11151108
dest_alloc.mark_relocation_range(relocations);
11161109

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,29 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
490490
// convert the dereferenced constant to a pattern that is the sub-pattern of the
491491
// deref pattern.
492492
_ => {
493-
let old = self.behind_reference.replace(true);
494-
// In case there are structural-match violations somewhere in this subpattern,
495-
// we fall back to a const pattern. If we do not do this, we may end up with
496-
// a !structural-match constant that is not of reference type, which makes it
497-
// very hard to invoke `PartialEq::eq` on it as a fallback.
498-
let val = match self.recur(tcx.deref_const(self.param_env.and(cv)), false) {
499-
Ok(subpattern) => PatKind::Deref { subpattern },
500-
Err(_) => PatKind::Constant { value: cv },
501-
};
502-
self.behind_reference.set(old);
503-
val
493+
if !pointee_ty.is_sized(tcx.at(span), param_env) {
494+
// `tcx.deref_const()` below will ICE with an unsized type
495+
// (except slices, which are handled in a separate arm above).
496+
let msg = format!("cannot use unsized non-slice type `{}` in constant patterns", pointee_ty);
497+
if self.include_lint_checks {
498+
tcx.sess.span_err(span, &msg);
499+
} else {
500+
tcx.sess.delay_span_bug(span, &msg);
501+
}
502+
PatKind::Wild
503+
} else {
504+
let old = self.behind_reference.replace(true);
505+
// In case there are structural-match violations somewhere in this subpattern,
506+
// we fall back to a const pattern. If we do not do this, we may end up with
507+
// a !structural-match constant that is not of reference type, which makes it
508+
// very hard to invoke `PartialEq::eq` on it as a fallback.
509+
let val = match self.recur(tcx.deref_const(self.param_env.and(cv)), false) {
510+
Ok(subpattern) => PatKind::Deref { subpattern },
511+
Err(_) => PatKind::Constant { value: cv },
512+
};
513+
self.behind_reference.set(old);
514+
val
515+
}
504516
}
505517
},
506518
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::FnDef(..) => {

compiler/rustc_session/src/session.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
2020
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
2121
use rustc_errors::json::JsonEmitter;
2222
use rustc_errors::registry::Registry;
23-
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
24-
use rustc_lint_defs::FutureBreakage;
23+
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorReported};
2524
use rustc_macros::HashStable_Generic;
2625
pub use rustc_span::def_id::StableCrateId;
2726
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
@@ -317,23 +316,7 @@ impl Session {
317316
if diags.is_empty() {
318317
return;
319318
}
320-
// If any future-breakage lints were registered, this lint store
321-
// should be available
322-
let lint_store = self.lint_store.get().expect("`lint_store` not initialized!");
323-
let diags_and_breakage: Vec<(FutureBreakage, Diagnostic)> = diags
324-
.into_iter()
325-
.map(|diag| {
326-
let lint_name = match &diag.code {
327-
Some(DiagnosticId::Lint { name, has_future_breakage: true, .. }) => name,
328-
_ => panic!("Unexpected code in diagnostic {:?}", diag),
329-
};
330-
let lint = lint_store.name_to_lint(&lint_name);
331-
let future_breakage =
332-
lint.lint.future_incompatible.unwrap().future_breakage.unwrap();
333-
(future_breakage, diag)
334-
})
335-
.collect();
336-
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags_and_breakage);
319+
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags);
337320
}
338321

339322
pub fn local_stable_crate_id(&self) -> StableCrateId {

0 commit comments

Comments
 (0)