Skip to content

Commit

Permalink
Auto merge of rust-lang#87095 - JohnTitor:rollup-mn7ggy2, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - rust-lang#86344 (Split MaybeUninit::write into new feature gate and stabilize it)
 - rust-lang#86811 (Remove unstable `io::Cursor::remaining`)
 - rust-lang#86846 (stdio_locked: add tracking issue)
 - rust-lang#86887 (rustdoc: remove dead code in `clean`)
 - rust-lang#87007 (Fix rust-analyzer install when not available.)
 - rust-lang#87035 (Fix implementors display)
 - rust-lang#87065 (Fix ICE with unsized type in const pattern)
 - rust-lang#87070 (Simplify future incompatible reporting.)
 - rust-lang#87077 (:arrow_up: rust-analyzer)
 - rust-lang#87078 (Rustdoc: suggest removing disambiguator if linking to field)
 - rust-lang#87089 (CTFE engine: small cleanups)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 13, 2021
2 parents aa06edb + e46b790 commit 14c0c3e
Show file tree
Hide file tree
Showing 37 changed files with 316 additions and 204 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ __pycache__/
**node_modules
**package-lock.json

## Rustdoc GUI tests
src/test/rustdoc-gui/src/**.lock

# Before adding new lines, see the comment at the top.
3 changes: 1 addition & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Destination::*;

use rustc_lint_defs::FutureBreakage;
use rustc_span::source_map::SourceMap;
use rustc_span::{MultiSpan, SourceFile, Span};

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

fn emit_future_breakage_report(&mut self, _diags: Vec<(FutureBreakage, Diagnostic)>) {}
fn emit_future_breakage_report(&mut self, _diags: Vec<Diagnostic>) {}

/// Emit list of unused externs
fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {}
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::registry::Registry;
use crate::DiagnosticId;
use crate::ToolMetadata;
use crate::{CodeSuggestion, SubDiagnostic};
use rustc_lint_defs::{Applicability, FutureBreakage};
use rustc_lint_defs::Applicability;

use rustc_data_structures::sync::Lrc;
use rustc_span::hygiene::ExpnData;
Expand Down Expand Up @@ -134,17 +134,14 @@ impl Emitter for JsonEmitter {
}
}

fn emit_future_breakage_report(&mut self, diags: Vec<(FutureBreakage, crate::Diagnostic)>) {
fn emit_future_breakage_report(&mut self, diags: Vec<crate::Diagnostic>) {
let data: Vec<FutureBreakageItem> = diags
.into_iter()
.map(|(breakage, mut diag)| {
.map(|mut diag| {
if diag.level == crate::Level::Allow {
diag.level = crate::Level::Warning;
}
FutureBreakageItem {
future_breakage_date: breakage.date,
diagnostic: Diagnostic::from_errors_diagnostic(&diag, self),
}
FutureBreakageItem { diagnostic: Diagnostic::from_errors_diagnostic(&diag, self) }
})
.collect();
let report = FutureIncompatReport { future_incompat_report: data };
Expand Down Expand Up @@ -326,7 +323,6 @@ struct ArtifactNotification<'a> {

#[derive(Encodable)]
struct FutureBreakageItem {
future_breakage_date: Option<&'static str>,
diagnostic: Diagnostic,
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_data_structures::sync::{self, Lock, Lrc};
use rustc_data_structures::AtomicRef;
use rustc_lint_defs::FutureBreakage;
pub use rustc_lint_defs::{pluralize, Applicability};
use rustc_serialize::json::Json;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
Expand Down Expand Up @@ -790,7 +789,7 @@ impl Handler {
self.inner.borrow_mut().emit_artifact_notification(path, artifact_type)
}

pub fn emit_future_breakage_report(&self, diags: Vec<(FutureBreakage, Diagnostic)>) {
pub fn emit_future_breakage_report(&self, diags: Vec<Diagnostic>) {
self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
}

Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.
use crate::{declare_lint, declare_lint_pass, FutureBreakage, FutureIncompatibilityReason};
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
use rustc_span::edition::Edition;

declare_lint! {
Expand Down Expand Up @@ -3176,9 +3176,7 @@ declare_lint! {
"detects usage of old versions of certain proc-macro crates",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
future_breakage: Some(FutureBreakage {
date: None
})
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}

Expand Down
13 changes: 3 additions & 10 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ pub struct FutureIncompatibleInfo {
/// Set to false for lints that already include a more detailed
/// explanation.
pub explain_reason: bool,
/// Information about a future breakage, which will
/// be emitted in JSON messages to be displayed by Cargo
/// for upstream deps
pub future_breakage: Option<FutureBreakage>,
}

/// The reason for future incompatibility
Expand All @@ -164,6 +160,9 @@ pub enum FutureIncompatibilityReason {
/// This will be an error in a future release
/// for all editions
FutureReleaseError,
/// This will be an error in a future release, and
/// Cargo should create a report even for dependencies
FutureReleaseErrorReportNow,
/// Previously accepted code that will become an
/// error in the provided edition
EditionError(Edition),
Expand All @@ -182,18 +181,12 @@ impl FutureIncompatibilityReason {
}
}

#[derive(Copy, Clone, Debug)]
pub struct FutureBreakage {
pub date: Option<&'static str>,
}

impl FutureIncompatibleInfo {
pub const fn default_fields_for_macro() -> Self {
FutureIncompatibleInfo {
reference: "",
reason: FutureIncompatibilityReason::FutureReleaseError,
explain_reason: true,
future_breakage: None,
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hir::HirId;
use rustc_index::vec::IndexVec;
use rustc_session::lint::{
builtin::{self, FORBIDDEN_LINT_GROUPS},
FutureIncompatibilityReason, Level, Lint, LintId,
FutureIncompatibilityReason, FutureIncompatibleInfo, Level, Lint, LintId,
};
use rustc_session::{DiagnosticMessageId, Session};
use rustc_span::hygiene::MacroKind;
Expand Down Expand Up @@ -223,8 +223,13 @@ pub fn struct_lint_level<'s, 'd>(
let lint_id = LintId::of(lint);
let future_incompatible = lint.future_incompatible;

let has_future_breakage =
future_incompatible.map_or(false, |incompat| incompat.future_breakage.is_some());
let has_future_breakage = matches!(
future_incompatible,
Some(FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
..
})
);

let mut err = match (level, span) {
(Level::Allow, span) => {
Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl InitMaskCompressed {
/// Transferring the initialization mask to other allocations.
impl<Tag, Extra> Allocation<Tag, Extra> {
/// Creates a run-length encoding of the initialization mask.
pub fn compress_uninit_range(&self, src: Pointer<Tag>, size: Size) -> InitMaskCompressed {
pub fn compress_uninit_range(&self, range: AllocRange) -> InitMaskCompressed {
// Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`),
// a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from
// the source and write it to the destination. Even if we optimized the memory accesses,
Expand All @@ -526,13 +526,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
// where each element toggles the state.

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

for i in 1..size.bytes() {
for i in 1..range.size.bytes() {
// FIXME: optimize to bitshift the current uninitialized block's bits and read the top bit.
if self.init_mask.get(src.offset + Size::from_bytes(i)) == cur {
if self.init_mask.get(range.start + Size::from_bytes(i)) == cur {
cur_len += 1;
} else {
ranges.push(cur_len);
Expand All @@ -550,24 +550,23 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
pub fn mark_compressed_init_range(
&mut self,
defined: &InitMaskCompressed,
dest: Pointer<Tag>,
size: Size,
range: AllocRange,
repeat: u64,
) {
// An optimization where we can just overwrite an entire range of initialization
// bits if they are going to be uniformly `1` or `0`.
if defined.ranges.len() <= 1 {
self.init_mask.set_range_inbounds(
dest.offset,
dest.offset + size * repeat, // `Size` operations
range.start,
range.start + range.size * repeat, // `Size` operations
defined.initial,
);
return;
}

for mut j in 0..repeat {
j *= size.bytes();
j += dest.offset.bytes();
j *= range.size.bytes();
j += range.start.bytes();
let mut cur = defined.initial;
for range in &defined.ranges {
let old_j = j;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use rustc_span::{Pos, Span};
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};

use super::{
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, Operand, Place, PlaceTy,
ScalarMaybeUninit, StackPopJump,
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, MemoryKind, Operand, Place,
PlaceTy, ScalarMaybeUninit, StackPopJump,
};
use crate::transform::validate::equal_up_to_regions;
use crate::util::storage::AlwaysLiveLocals;
Expand Down Expand Up @@ -900,7 +900,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// due to the local having ZST type.
let ptr = ptr.assert_ptr();
trace!("deallocating local: {:?}", self.memory.dump_alloc(ptr.alloc_id));
self.memory.deallocate_local(ptr)?;
self.memory.deallocate(ptr, None, MemoryKind::Stack)?;
};
Ok(())
}
Expand Down
19 changes: 6 additions & 13 deletions compiler/rustc_mir/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
Ok(new_ptr)
}

/// Deallocate a local, or do nothing if that local has been made into a global.
pub fn deallocate_local(&mut self, ptr: Pointer<M::PointerTag>) -> InterpResult<'tcx> {
// The allocation might be already removed by global interning.
// This can only really happen in the CTFE instance, not in miri.
if self.alloc_map.contains_key(&ptr.alloc_id) {
self.deallocate(ptr, None, MemoryKind::Stack)
} else {
Ok(())
}
}

pub fn deallocate(
&mut self,
ptr: Pointer<M::PointerTag>,
Expand Down Expand Up @@ -1049,7 +1038,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
num_copies,
);
// Prepare a copy of the initialization mask.
let compressed = src_alloc.compress_uninit_range(src, size);
let compressed = src_alloc.compress_uninit_range(alloc_range(src.offset, size));
// This checks relocation edges on the src.
let src_bytes = src_alloc
.get_bytes_with_uninit_and_ptr(&tcx, alloc_range(src.offset, size))
Expand Down Expand Up @@ -1110,7 +1099,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
}

// now fill in all the "init" data
dest_alloc.mark_compressed_init_range(&compressed, dest, size, num_copies);
dest_alloc.mark_compressed_init_range(
&compressed,
alloc_range(dest.offset, size),
num_copies,
);
// copy the relocations to the destination
dest_alloc.mark_relocation_range(relocations);

Expand Down
34 changes: 23 additions & 11 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,29 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
// convert the dereferenced constant to a pattern that is the sub-pattern of the
// deref pattern.
_ => {
let old = self.behind_reference.replace(true);
// In case there are structural-match violations somewhere in this subpattern,
// we fall back to a const pattern. If we do not do this, we may end up with
// a !structural-match constant that is not of reference type, which makes it
// very hard to invoke `PartialEq::eq` on it as a fallback.
let val = match self.recur(tcx.deref_const(self.param_env.and(cv)), false) {
Ok(subpattern) => PatKind::Deref { subpattern },
Err(_) => PatKind::Constant { value: cv },
};
self.behind_reference.set(old);
val
if !pointee_ty.is_sized(tcx.at(span), param_env) {
// `tcx.deref_const()` below will ICE with an unsized type
// (except slices, which are handled in a separate arm above).
let msg = format!("cannot use unsized non-slice type `{}` in constant patterns", pointee_ty);
if self.include_lint_checks {
tcx.sess.span_err(span, &msg);
} else {
tcx.sess.delay_span_bug(span, &msg);
}
PatKind::Wild
} else {
let old = self.behind_reference.replace(true);
// In case there are structural-match violations somewhere in this subpattern,
// we fall back to a const pattern. If we do not do this, we may end up with
// a !structural-match constant that is not of reference type, which makes it
// very hard to invoke `PartialEq::eq` on it as a fallback.
let val = match self.recur(tcx.deref_const(self.param_env.and(cv)), false) {
Ok(subpattern) => PatKind::Deref { subpattern },
Err(_) => PatKind::Constant { value: cv },
};
self.behind_reference.set(old);
val
}
}
},
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::FnDef(..) => {
Expand Down
21 changes: 2 additions & 19 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
use rustc_errors::json::JsonEmitter;
use rustc_errors::registry::Registry;
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
use rustc_lint_defs::FutureBreakage;
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorReported};
use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId;
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
Expand Down Expand Up @@ -317,23 +316,7 @@ impl Session {
if diags.is_empty() {
return;
}
// If any future-breakage lints were registered, this lint store
// should be available
let lint_store = self.lint_store.get().expect("`lint_store` not initialized!");
let diags_and_breakage: Vec<(FutureBreakage, Diagnostic)> = diags
.into_iter()
.map(|diag| {
let lint_name = match &diag.code {
Some(DiagnosticId::Lint { name, has_future_breakage: true, .. }) => name,
_ => panic!("Unexpected code in diagnostic {:?}", diag),
};
let lint = lint_store.name_to_lint(&lint_name);
let future_breakage =
lint.lint.future_incompatible.unwrap().future_breakage.unwrap();
(future_breakage, diag)
})
.collect();
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags_and_breakage);
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags);
}

pub fn local_stable_crate_id(&self) -> StableCrateId {
Expand Down
Loading

0 comments on commit 14c0c3e

Please sign in to comment.