Skip to content

Commit 4ca19e0

Browse files
committed
Auto merge of #96214 - Dylan-DPC:rollup-a5b4fow, r=Dylan-DPC
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
2 parents c102c5c + 9fad214 commit 4ca19e0

File tree

79 files changed

+461
-769
lines changed

Some content is hidden

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

79 files changed

+461
-769
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3934,7 +3934,6 @@ dependencies = [
39343934
"rustc_infer",
39353935
"rustc_middle",
39363936
"rustc_parse_format",
3937-
"rustc_serialize",
39383937
"rustc_session",
39393938
"rustc_span",
39403939
"rustc_target",

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use std::collections::hash_map::Entry::*;
22

33
use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
4-
use rustc_data_structures::fingerprint::Fingerprint;
54
use rustc_data_structures::fx::FxHashMap;
65
use rustc_hir as hir;
7-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
6+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
87
use rustc_hir::Node;
9-
use rustc_index::vec::IndexVec;
108
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
119
use rustc_middle::middle::exported_symbols::{
1210
metadata_symbol_name, ExportedSymbol, SymbolExportLevel,
@@ -277,17 +275,6 @@ fn upstream_monomorphizations_provider(
277275

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

280-
let cnum_stable_ids: IndexVec<CrateNum, Fingerprint> = {
281-
let mut cnum_stable_ids = IndexVec::from_elem_n(Fingerprint::ZERO, cnums.len() + 1);
282-
283-
for &cnum in cnums.iter() {
284-
cnum_stable_ids[cnum] =
285-
tcx.def_path_hash(DefId { krate: cnum, index: CRATE_DEF_INDEX }).0;
286-
}
287-
288-
cnum_stable_ids
289-
};
290-
291278
let drop_in_place_fn_def_id = tcx.lang_items().drop_in_place_fn();
292279

293280
for &cnum in cnums.iter() {
@@ -316,7 +303,7 @@ fn upstream_monomorphizations_provider(
316303
// If there are multiple monomorphizations available,
317304
// we select one deterministically.
318305
let other_cnum = *e.get();
319-
if cnum_stable_ids[other_cnum] > cnum_stable_ids[cnum] {
306+
if tcx.stable_crate_id(other_cnum) > tcx.stable_crate_id(cnum) {
320307
e.insert(cnum);
321308
}
322309
}

compiler/rustc_errors/src/diagnostic.rs

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::snippet::Style;
22
use crate::{
33
CodeSuggestion, DiagnosticMessage, Level, MultiSpan, Substitution, SubstitutionPart,
4-
SuggestionStyle, ToolMetadata,
4+
SuggestionStyle,
55
};
66
use rustc_data_structures::stable_map::FxHashMap;
77
use rustc_error_messages::FluentValue;
88
use rustc_lint_defs::{Applicability, LintExpectationId};
9-
use rustc_serialize::json::Json;
109
use rustc_span::edition::LATEST_STABLE_EDITION;
1110
use rustc_span::symbol::{Ident, Symbol};
1211
use rustc_span::{Span, DUMMY_SP};
@@ -554,7 +553,6 @@ impl Diagnostic {
554553
msg: msg.into(),
555554
style,
556555
applicability,
557-
tool_metadata: Default::default(),
558556
});
559557
self
560558
}
@@ -582,7 +580,6 @@ impl Diagnostic {
582580
msg: msg.into(),
583581
style: SuggestionStyle::CompletelyHidden,
584582
applicability,
585-
tool_metadata: Default::default(),
586583
});
587584
self
588585
}
@@ -637,7 +634,6 @@ impl Diagnostic {
637634
msg: msg.into(),
638635
style,
639636
applicability,
640-
tool_metadata: Default::default(),
641637
});
642638
self
643639
}
@@ -680,7 +676,6 @@ impl Diagnostic {
680676
msg: msg.into(),
681677
style: SuggestionStyle::ShowCode,
682678
applicability,
683-
tool_metadata: Default::default(),
684679
});
685680
self
686681
}
@@ -705,7 +700,6 @@ impl Diagnostic {
705700
msg: msg.into(),
706701
style: SuggestionStyle::ShowCode,
707702
applicability,
708-
tool_metadata: Default::default(),
709703
});
710704
self
711705
}
@@ -774,23 +768,6 @@ impl Diagnostic {
774768
self
775769
}
776770

777-
/// Adds a suggestion intended only for a tool. The intent is that the metadata encodes
778-
/// the suggestion in a tool-specific way, as it may not even directly involve Rust code.
779-
pub fn tool_only_suggestion_with_metadata(
780-
&mut self,
781-
msg: impl Into<DiagnosticMessage>,
782-
applicability: Applicability,
783-
tool_metadata: Json,
784-
) {
785-
self.push_suggestion(CodeSuggestion {
786-
substitutions: vec![],
787-
msg: msg.into(),
788-
style: SuggestionStyle::CompletelyHidden,
789-
applicability,
790-
tool_metadata: ToolMetadata::new(tool_metadata),
791-
})
792-
}
793-
794771
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
795772
self.span = sp.into();
796773
if let Some(span) = self.span.primary_span() {

compiler/rustc_errors/src/json.rs

+1-66
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_span::source_map::{FilePathMapping, SourceMap};
1414
use crate::emitter::{Emitter, HumanReadableErrorType};
1515
use crate::registry::Registry;
1616
use crate::DiagnosticId;
17-
use crate::ToolMetadata;
1817
use crate::{
1918
CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel, SubDiagnostic,
2019
};
@@ -30,7 +29,6 @@ use std::sync::{Arc, Mutex};
3029
use std::vec;
3130

3231
use rustc_serialize::json::{as_json, as_pretty_json};
33-
use rustc_serialize::{Encodable, Encoder};
3432

3533
#[cfg(test)]
3634
mod tests;
@@ -205,8 +203,7 @@ impl Emitter for JsonEmitter {
205203

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

208-
// NOTE: this has a manual implementation of Encodable which needs to be updated in
209-
// parallel.
206+
#[derive(Encodable)]
210207
struct Diagnostic {
211208
/// The primary error message.
212209
message: String,
@@ -218,65 +215,6 @@ struct Diagnostic {
218215
children: Vec<Diagnostic>,
219216
/// The message as rustc would render it.
220217
rendered: Option<String>,
221-
/// Extra tool metadata
222-
tool_metadata: ToolMetadata,
223-
}
224-
225-
macro_rules! encode_fields {
226-
(
227-
$enc:expr, // encoder
228-
$idx:expr, // starting field index
229-
$struct:expr, // struct we're serializing
230-
$struct_name:ident, // struct name
231-
[ $($name:ident),+$(,)? ], // fields to encode
232-
[ $($ignore:ident),+$(,)? ] // fields we're skipping
233-
) => {
234-
{
235-
// Pattern match to make sure all fields are accounted for
236-
let $struct_name { $($name,)+ $($ignore: _,)+ } = $struct;
237-
let mut idx = $idx;
238-
$(
239-
$enc.emit_struct_field(
240-
stringify!($name),
241-
idx == 0,
242-
|enc| $name.encode(enc),
243-
)?;
244-
idx += 1;
245-
)+
246-
idx
247-
}
248-
};
249-
}
250-
251-
// Special-case encoder to skip tool_metadata if not set
252-
impl<E: Encoder> Encodable<E> for Diagnostic {
253-
fn encode(&self, s: &mut E) -> Result<(), E::Error> {
254-
s.emit_struct(false, |s| {
255-
let mut idx = 0;
256-
257-
idx = encode_fields!(
258-
s,
259-
idx,
260-
self,
261-
Self,
262-
[message, code, level, spans, children, rendered],
263-
[tool_metadata]
264-
);
265-
if self.tool_metadata.is_set() {
266-
idx = encode_fields!(
267-
s,
268-
idx,
269-
self,
270-
Self,
271-
[tool_metadata],
272-
[message, code, level, spans, children, rendered]
273-
);
274-
}
275-
276-
let _ = idx;
277-
Ok(())
278-
})
279-
}
280218
}
281219

282220
#[derive(Encodable)]
@@ -380,7 +318,6 @@ impl Diagnostic {
380318
spans: DiagnosticSpan::from_suggestion(sugg, &args, je),
381319
children: vec![],
382320
rendered: None,
383-
tool_metadata: sugg.tool_metadata.clone(),
384321
}
385322
});
386323

@@ -428,7 +365,6 @@ impl Diagnostic {
428365
.chain(sugg)
429366
.collect(),
430367
rendered: Some(output),
431-
tool_metadata: ToolMetadata::default(),
432368
}
433369
}
434370

@@ -449,7 +385,6 @@ impl Diagnostic {
449385
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, args, je)),
450386
children: vec![],
451387
rendered: None,
452-
tool_metadata: ToolMetadata::default(),
453388
}
454389
}
455390
}

compiler/rustc_errors/src/lib.rs

+1-38
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ pub use rustc_error_messages::{
3636
LazyFallbackBundle, MultiSpan, SpanLabel, DEFAULT_LOCALE_RESOURCES,
3737
};
3838
pub use rustc_lint_defs::{pluralize, Applicability};
39-
use rustc_serialize::json::Json;
40-
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
4139
use rustc_span::source_map::SourceMap;
4240
use rustc_span::{Loc, Span};
4341

4442
use std::borrow::Cow;
45-
use std::hash::{Hash, Hasher};
43+
use std::hash::Hash;
4644
use std::num::NonZeroUsize;
4745
use std::panic;
4846
use std::path::Path;
@@ -93,39 +91,6 @@ impl SuggestionStyle {
9391
}
9492
}
9593

96-
#[derive(Clone, Debug, PartialEq, Default)]
97-
pub struct ToolMetadata(pub Option<Json>);
98-
99-
impl ToolMetadata {
100-
fn new(json: Json) -> Self {
101-
ToolMetadata(Some(json))
102-
}
103-
104-
fn is_set(&self) -> bool {
105-
self.0.is_some()
106-
}
107-
}
108-
109-
impl Hash for ToolMetadata {
110-
fn hash<H: Hasher>(&self, _state: &mut H) {}
111-
}
112-
113-
// Doesn't really need to round-trip
114-
impl<D: Decoder> Decodable<D> for ToolMetadata {
115-
fn decode(_d: &mut D) -> Self {
116-
ToolMetadata(None)
117-
}
118-
}
119-
120-
impl<S: Encoder> Encodable<S> for ToolMetadata {
121-
fn encode(&self, e: &mut S) -> Result<(), S::Error> {
122-
match &self.0 {
123-
None => e.emit_unit(),
124-
Some(json) => json.encode(e),
125-
}
126-
}
127-
}
128-
12994
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
13095
pub struct CodeSuggestion {
13196
/// Each substitute can have multiple variants due to multiple
@@ -159,8 +124,6 @@ pub struct CodeSuggestion {
159124
/// which are useful for users but not useful for
160125
/// tools like rustfix
161126
pub applicability: Applicability,
162-
/// Tool-specific metadata
163-
pub tool_metadata: ToolMetadata,
164127
}
165128

166129
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]

compiler/rustc_hir/src/def.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1+
use crate::def_id::DefId;
22
use crate::hir;
33

44
use rustc_ast as ast;
@@ -124,9 +124,7 @@ impl DefKind {
124124
pub fn descr(self, def_id: DefId) -> &'static str {
125125
match self {
126126
DefKind::Fn => "function",
127-
DefKind::Mod if def_id.index == CRATE_DEF_INDEX && def_id.krate != LOCAL_CRATE => {
128-
"crate"
129-
}
127+
DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
130128
DefKind::Mod => "module",
131129
DefKind::Static(..) => "static",
132130
DefKind::Enum => "enum",

compiler/rustc_hir/src/definitions.rs

-5
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,6 @@ impl Definitions {
353353
}
354354
}
355355

356-
/// Retrieves the root definition.
357-
pub fn get_root_def(&self) -> LocalDefId {
358-
LocalDefId { local_def_index: CRATE_DEF_INDEX }
359-
}
360-
361356
/// Adds a definition with a parent definition.
362357
pub fn create_def(
363358
&mut self,

compiler/rustc_hir/src/hir_id.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
1+
use crate::def_id::{LocalDefId, CRATE_DEF_ID};
22
use std::fmt;
33

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

87-
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`.
88-
pub const CRATE_HIR_ID: HirId = HirId {
89-
owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
90-
local_id: ItemLocalId::from_u32(0),
91-
};
87+
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
88+
pub const CRATE_HIR_ID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::from_u32(0) };

compiler/rustc_lint/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1818
rustc_feature = { path = "../rustc_feature" }
1919
rustc_index = { path = "../rustc_index" }
2020
rustc_session = { path = "../rustc_session" }
21-
rustc_serialize = { path = "../rustc_serialize" }
2221
rustc_trait_selection = { path = "../rustc_trait_selection" }
2322
rustc_parse_format = { path = "../rustc_parse_format" }
2423
rustc_infer = { path = "../rustc_infer" }

0 commit comments

Comments
 (0)