Skip to content

Commit

Permalink
Auto merge of #96214 - Dylan-DPC:rollup-a5b4fow, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #94493 (Improved diagnostic on failure to meet send bound on future in a foreign crate)
 - #95809 (Fix typo in bootstrap.py)
 - #96086 (Remove `--extern-location` and all associated code)
 - #96089 (`alloc`: make `vec!` unavailable under `no_global_oom_handling`)
 - #96122 (Fix an invalid error for a suggestion to add a slice in pattern-matching)
 - #96142 (Stop using CRATE_DEF_INDEX outside of metadata encoding.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 19, 2022
2 parents c102c5c + 9fad214 commit 4ca19e0
Show file tree
Hide file tree
Showing 79 changed files with 461 additions and 769 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Expand Up @@ -3934,7 +3934,6 @@ dependencies = [
"rustc_infer",
"rustc_middle",
"rustc_parse_format",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
Expand Down
17 changes: 2 additions & 15 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
@@ -1,12 +1,10 @@
use std::collections::hash_map::Entry::*;

use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
use rustc_hir::Node;
use rustc_index::vec::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::middle::exported_symbols::{
metadata_symbol_name, ExportedSymbol, SymbolExportLevel,
Expand Down Expand Up @@ -277,17 +275,6 @@ fn upstream_monomorphizations_provider(

let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default();

let cnum_stable_ids: IndexVec<CrateNum, Fingerprint> = {
let mut cnum_stable_ids = IndexVec::from_elem_n(Fingerprint::ZERO, cnums.len() + 1);

for &cnum in cnums.iter() {
cnum_stable_ids[cnum] =
tcx.def_path_hash(DefId { krate: cnum, index: CRATE_DEF_INDEX }).0;
}

cnum_stable_ids
};

let drop_in_place_fn_def_id = tcx.lang_items().drop_in_place_fn();

for &cnum in cnums.iter() {
Expand Down Expand Up @@ -316,7 +303,7 @@ fn upstream_monomorphizations_provider(
// If there are multiple monomorphizations available,
// we select one deterministically.
let other_cnum = *e.get();
if cnum_stable_ids[other_cnum] > cnum_stable_ids[cnum] {
if tcx.stable_crate_id(other_cnum) > tcx.stable_crate_id(cnum) {
e.insert(cnum);
}
}
Expand Down
25 changes: 1 addition & 24 deletions compiler/rustc_errors/src/diagnostic.rs
@@ -1,12 +1,11 @@
use crate::snippet::Style;
use crate::{
CodeSuggestion, DiagnosticMessage, Level, MultiSpan, Substitution, SubstitutionPart,
SuggestionStyle, ToolMetadata,
SuggestionStyle,
};
use rustc_data_structures::stable_map::FxHashMap;
use rustc_error_messages::FluentValue;
use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_serialize::json::Json;
use rustc_span::edition::LATEST_STABLE_EDITION;
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -554,7 +553,6 @@ impl Diagnostic {
msg: msg.into(),
style,
applicability,
tool_metadata: Default::default(),
});
self
}
Expand Down Expand Up @@ -582,7 +580,6 @@ impl Diagnostic {
msg: msg.into(),
style: SuggestionStyle::CompletelyHidden,
applicability,
tool_metadata: Default::default(),
});
self
}
Expand Down Expand Up @@ -637,7 +634,6 @@ impl Diagnostic {
msg: msg.into(),
style,
applicability,
tool_metadata: Default::default(),
});
self
}
Expand Down Expand Up @@ -680,7 +676,6 @@ impl Diagnostic {
msg: msg.into(),
style: SuggestionStyle::ShowCode,
applicability,
tool_metadata: Default::default(),
});
self
}
Expand All @@ -705,7 +700,6 @@ impl Diagnostic {
msg: msg.into(),
style: SuggestionStyle::ShowCode,
applicability,
tool_metadata: Default::default(),
});
self
}
Expand Down Expand Up @@ -774,23 +768,6 @@ impl Diagnostic {
self
}

/// Adds a suggestion intended only for a tool. The intent is that the metadata encodes
/// the suggestion in a tool-specific way, as it may not even directly involve Rust code.
pub fn tool_only_suggestion_with_metadata(
&mut self,
msg: impl Into<DiagnosticMessage>,
applicability: Applicability,
tool_metadata: Json,
) {
self.push_suggestion(CodeSuggestion {
substitutions: vec![],
msg: msg.into(),
style: SuggestionStyle::CompletelyHidden,
applicability,
tool_metadata: ToolMetadata::new(tool_metadata),
})
}

pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
self.span = sp.into();
if let Some(span) = self.span.primary_span() {
Expand Down
67 changes: 1 addition & 66 deletions compiler/rustc_errors/src/json.rs
Expand Up @@ -14,7 +14,6 @@ use rustc_span::source_map::{FilePathMapping, SourceMap};
use crate::emitter::{Emitter, HumanReadableErrorType};
use crate::registry::Registry;
use crate::DiagnosticId;
use crate::ToolMetadata;
use crate::{
CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel, SubDiagnostic,
};
Expand All @@ -30,7 +29,6 @@ use std::sync::{Arc, Mutex};
use std::vec;

use rustc_serialize::json::{as_json, as_pretty_json};
use rustc_serialize::{Encodable, Encoder};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -205,8 +203,7 @@ impl Emitter for JsonEmitter {

// The following data types are provided just for serialisation.

// NOTE: this has a manual implementation of Encodable which needs to be updated in
// parallel.
#[derive(Encodable)]
struct Diagnostic {
/// The primary error message.
message: String,
Expand All @@ -218,65 +215,6 @@ struct Diagnostic {
children: Vec<Diagnostic>,
/// The message as rustc would render it.
rendered: Option<String>,
/// Extra tool metadata
tool_metadata: ToolMetadata,
}

macro_rules! encode_fields {
(
$enc:expr, // encoder
$idx:expr, // starting field index
$struct:expr, // struct we're serializing
$struct_name:ident, // struct name
[ $($name:ident),+$(,)? ], // fields to encode
[ $($ignore:ident),+$(,)? ] // fields we're skipping
) => {
{
// Pattern match to make sure all fields are accounted for
let $struct_name { $($name,)+ $($ignore: _,)+ } = $struct;
let mut idx = $idx;
$(
$enc.emit_struct_field(
stringify!($name),
idx == 0,
|enc| $name.encode(enc),
)?;
idx += 1;
)+
idx
}
};
}

// Special-case encoder to skip tool_metadata if not set
impl<E: Encoder> Encodable<E> for Diagnostic {
fn encode(&self, s: &mut E) -> Result<(), E::Error> {
s.emit_struct(false, |s| {
let mut idx = 0;

idx = encode_fields!(
s,
idx,
self,
Self,
[message, code, level, spans, children, rendered],
[tool_metadata]
);
if self.tool_metadata.is_set() {
idx = encode_fields!(
s,
idx,
self,
Self,
[tool_metadata],
[message, code, level, spans, children, rendered]
);
}

let _ = idx;
Ok(())
})
}
}

#[derive(Encodable)]
Expand Down Expand Up @@ -380,7 +318,6 @@ impl Diagnostic {
spans: DiagnosticSpan::from_suggestion(sugg, &args, je),
children: vec![],
rendered: None,
tool_metadata: sugg.tool_metadata.clone(),
}
});

Expand Down Expand Up @@ -428,7 +365,6 @@ impl Diagnostic {
.chain(sugg)
.collect(),
rendered: Some(output),
tool_metadata: ToolMetadata::default(),
}
}

Expand All @@ -449,7 +385,6 @@ impl Diagnostic {
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, args, je)),
children: vec![],
rendered: None,
tool_metadata: ToolMetadata::default(),
}
}
}
Expand Down
39 changes: 1 addition & 38 deletions compiler/rustc_errors/src/lib.rs
Expand Up @@ -36,13 +36,11 @@ pub use rustc_error_messages::{
LazyFallbackBundle, MultiSpan, SpanLabel, DEFAULT_LOCALE_RESOURCES,
};
pub use rustc_lint_defs::{pluralize, Applicability};
use rustc_serialize::json::Json;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_span::source_map::SourceMap;
use rustc_span::{Loc, Span};

use std::borrow::Cow;
use std::hash::{Hash, Hasher};
use std::hash::Hash;
use std::num::NonZeroUsize;
use std::panic;
use std::path::Path;
Expand Down Expand Up @@ -93,39 +91,6 @@ impl SuggestionStyle {
}
}

#[derive(Clone, Debug, PartialEq, Default)]
pub struct ToolMetadata(pub Option<Json>);

impl ToolMetadata {
fn new(json: Json) -> Self {
ToolMetadata(Some(json))
}

fn is_set(&self) -> bool {
self.0.is_some()
}
}

impl Hash for ToolMetadata {
fn hash<H: Hasher>(&self, _state: &mut H) {}
}

// Doesn't really need to round-trip
impl<D: Decoder> Decodable<D> for ToolMetadata {
fn decode(_d: &mut D) -> Self {
ToolMetadata(None)
}
}

impl<S: Encoder> Encodable<S> for ToolMetadata {
fn encode(&self, e: &mut S) -> Result<(), S::Error> {
match &self.0 {
None => e.emit_unit(),
Some(json) => json.encode(e),
}
}
}

#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
pub struct CodeSuggestion {
/// Each substitute can have multiple variants due to multiple
Expand Down Expand Up @@ -159,8 +124,6 @@ pub struct CodeSuggestion {
/// which are useful for users but not useful for
/// tools like rustfix
pub applicability: Applicability,
/// Tool-specific metadata
pub tool_metadata: ToolMetadata,
}

#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_hir/src/def.rs
@@ -1,4 +1,4 @@
use crate::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::def_id::DefId;
use crate::hir;

use rustc_ast as ast;
Expand Down Expand Up @@ -124,9 +124,7 @@ impl DefKind {
pub fn descr(self, def_id: DefId) -> &'static str {
match self {
DefKind::Fn => "function",
DefKind::Mod if def_id.index == CRATE_DEF_INDEX && def_id.krate != LOCAL_CRATE => {
"crate"
}
DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
DefKind::Mod => "module",
DefKind::Static(..) => "static",
DefKind::Enum => "enum",
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_hir/src/definitions.rs
Expand Up @@ -353,11 +353,6 @@ impl Definitions {
}
}

/// Retrieves the root definition.
pub fn get_root_def(&self) -> LocalDefId {
LocalDefId { local_def_index: CRATE_DEF_INDEX }
}

/// Adds a definition with a parent definition.
pub fn create_def(
&mut self,
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_hir/src/hir_id.rs
@@ -1,4 +1,4 @@
use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
use crate::def_id::{LocalDefId, CRATE_DEF_ID};
use std::fmt;

/// Uniquely identifies a node in the HIR of the current crate. It is
Expand Down Expand Up @@ -84,8 +84,5 @@ impl ItemLocalId {
pub const INVALID: ItemLocalId = ItemLocalId::MAX;
}

/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`.
pub const CRATE_HIR_ID: HirId = HirId {
owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
local_id: ItemLocalId::from_u32(0),
};
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
pub const CRATE_HIR_ID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::from_u32(0) };
1 change: 0 additions & 1 deletion compiler/rustc_lint/Cargo.toml
Expand Up @@ -18,7 +18,6 @@ rustc_data_structures = { path = "../rustc_data_structures" }
rustc_feature = { path = "../rustc_feature" }
rustc_index = { path = "../rustc_index" }
rustc_session = { path = "../rustc_session" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_parse_format = { path = "../rustc_parse_format" }
rustc_infer = { path = "../rustc_infer" }

0 comments on commit 4ca19e0

Please sign in to comment.