Skip to content

Commit e012a19

Browse files
committed
Auto merge of rust-lang#92627 - matthiaskrgr:rollup-xmz0rib, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#91055 (return the correct type for closures in `type_of`) - rust-lang#92207 (Delay remaining `span_bug`s in drop elaboration) - rust-lang#92417 (Fix spacing and ordering of words in pretty printed Impl) - rust-lang#92504 (Exit nonzero on rustc -Wall) - rust-lang#92559 (RustWrapper: adapt to new AttributeMask API) - rust-lang#92589 (Break the loop) - rust-lang#92607 (rustc_metadata: Some minor cleanups and optimizations) - rust-lang#92620 (Remove unused `ExtendDefault` struct) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cfa4ac6 + fcae1d6 commit e012a19

File tree

22 files changed

+215
-141
lines changed

22 files changed

+215
-141
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1287,14 +1287,17 @@ impl<'a> State<'a> {
12871287
self.print_visibility(&item.vis);
12881288
self.print_defaultness(defaultness);
12891289
self.print_unsafety(unsafety);
1290-
self.word_nbsp("impl");
1291-
self.print_constness(constness);
1290+
self.word("impl");
12921291

1293-
if !generics.params.is_empty() {
1292+
if generics.params.is_empty() {
1293+
self.nbsp();
1294+
} else {
12941295
self.print_generic_params(&generics.params);
12951296
self.space();
12961297
}
12971298

1299+
self.print_constness(constness);
1300+
12981301
if let ast::ImplPolarity::Negative(_) = polarity {
12991302
self.word("!");
13001303
}

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10401040
let wall = matches.opt_strs("W");
10411041
if wall.iter().any(|x| *x == "all") {
10421042
print_wall_help();
1043-
return None;
1043+
rustc_errors::FatalError.raise();
10441044
}
10451045

10461046
// Don't handle -W help here, because we might first load plugins.

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,12 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
341341
unsigned Index,
342342
LLVMRustAttribute RustAttr) {
343343
Function *F = unwrap<Function>(Fn);
344-
Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr));
345-
AttrBuilder B(Attr);
346-
auto PAL = F->getAttributes();
344+
AttributeList PAL = F->getAttributes();
347345
AttributeList PALNew;
348346
#if LLVM_VERSION_LT(14, 0)
349-
PALNew = PAL.removeAttributes(F->getContext(), Index, B);
347+
PALNew = PAL.removeAttribute(F->getContext(), Index, fromRust(RustAttr));
350348
#else
351-
PALNew = PAL.removeAttributesAtIndex(F->getContext(), Index, B);
349+
PALNew = PAL.removeAttributeAtIndex(F->getContext(), Index, fromRust(RustAttr));
352350
#endif
353351
F->setAttributes(PALNew);
354352
}

compiler/rustc_metadata/src/rmeta/decoder.rs

+64-71
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
2727
use rustc_middle::mir::{self, Body, Promoted};
2828
use rustc_middle::thir;
2929
use rustc_middle::ty::codec::TyDecoder;
30+
use rustc_middle::ty::fast_reject::SimplifiedType;
3031
use rustc_middle::ty::{self, Ty, TyCtxt, Visibility};
3132
use rustc_serialize::{opaque, Decodable, Decoder};
3233
use rustc_session::cstore::{
@@ -92,8 +93,7 @@ crate struct CrateMetadata {
9293
/// Trait impl data.
9394
/// FIXME: Used only from queries and can use query cache,
9495
/// so pre-decoding can probably be avoided.
95-
trait_impls:
96-
FxHashMap<(u32, DefIndex), Lazy<[(DefIndex, Option<ty::fast_reject::SimplifiedType>)]>>,
96+
trait_impls: FxHashMap<(u32, DefIndex), Lazy<[(DefIndex, Option<SimplifiedType>)]>>,
9797
/// Proc macro descriptions for this crate, if it's a proc macro crate.
9898
raw_proc_macros: Option<&'static [ProcMacro]>,
9999
/// Source maps for code from the crate.
@@ -722,25 +722,24 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
722722
&self.raw_proc_macros.unwrap()[pos]
723723
}
724724

725-
fn try_item_ident(&self, item_index: DefIndex, sess: &Session) -> Result<Ident, String> {
726-
let name = self
727-
.def_key(item_index)
728-
.disambiguated_data
729-
.data
730-
.get_opt_name()
731-
.ok_or_else(|| format!("Missing opt name for {:?}", item_index))?;
732-
let span = self
733-
.root
734-
.tables
735-
.ident_span
736-
.get(self, item_index)
737-
.ok_or_else(|| format!("Missing ident span for {:?} ({:?})", name, item_index))?
738-
.decode((self, sess));
739-
Ok(Ident::new(name, span))
725+
fn opt_item_ident(&self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
726+
let name = self.def_key(item_index).disambiguated_data.data.get_opt_name()?;
727+
let span = match self.root.tables.ident_span.get(self, item_index) {
728+
Some(lazy_span) => lazy_span.decode((self, sess)),
729+
None => {
730+
// FIXME: this weird case of a name with no span is specific to `extern crate`
731+
// items, which are supposed to be treated like `use` items and only be encoded
732+
// to metadata as `Export`s, return `None` because that's what all the callers
733+
// expect in this case.
734+
assert_eq!(self.def_kind(item_index), DefKind::ExternCrate);
735+
return None;
736+
}
737+
};
738+
Some(Ident::new(name, span))
740739
}
741740

742741
fn item_ident(&self, item_index: DefIndex, sess: &Session) -> Ident {
743-
self.try_item_ident(item_index, sess).unwrap()
742+
self.opt_item_ident(item_index, sess).expect("no encoded ident for item")
744743
}
745744

746745
fn maybe_kind(&self, item_id: DefIndex) -> Option<EntryKind> {
@@ -1102,27 +1101,19 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11021101
// Iterate over all children.
11031102
if let Some(children) = self.root.tables.children.get(self, id) {
11041103
for child_index in children.decode((self, sess)) {
1105-
// FIXME: Merge with the logic below.
1106-
if let None | Some(EntryKind::ForeignMod | EntryKind::Impl(_)) =
1107-
self.maybe_kind(child_index)
1108-
{
1109-
continue;
1110-
}
1111-
1112-
let def_key = self.def_key(child_index);
1113-
if def_key.disambiguated_data.data.get_opt_name().is_some() {
1114-
let span = self.get_span(child_index, sess);
1104+
if let Some(ident) = self.opt_item_ident(child_index, sess) {
11151105
let kind = self.def_kind(child_index);
1116-
let ident = self.item_ident(child_index, sess);
1117-
let vis = self.get_visibility(child_index);
1106+
if matches!(kind, DefKind::Macro(..)) {
1107+
// FIXME: Macros are currently encoded twice, once as items and once as
1108+
// reexports. We ignore the items here and only use the reexports.
1109+
continue;
1110+
}
11181111
let def_id = self.local_def_id(child_index);
11191112
let res = Res::Def(kind, def_id);
1113+
let vis = self.get_visibility(child_index);
1114+
let span = self.get_span(child_index, sess);
11201115

1121-
// FIXME: Macros are currently encoded twice, once as items and once as
1122-
// reexports. We ignore the items here and only use the reexports.
1123-
if !matches!(kind, DefKind::Macro(..)) {
1124-
callback(Export { res, ident, vis, span });
1125-
}
1116+
callback(Export { ident, res, vis, span });
11261117

11271118
// For non-re-export structs and variants add their constructors to children.
11281119
// Re-export lists automatically contain constructors when necessary.
@@ -1309,24 +1300,26 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13091300

13101301
fn get_item_attrs(
13111302
&'a self,
1312-
node_id: DefIndex,
1303+
id: DefIndex,
13131304
sess: &'a Session,
13141305
) -> impl Iterator<Item = ast::Attribute> + 'a {
1315-
// The attributes for a tuple struct/variant are attached to the definition, not the ctor;
1316-
// we assume that someone passing in a tuple struct ctor is actually wanting to
1317-
// look at the definition
1318-
let def_key = self.def_key(node_id);
1319-
let item_id = if def_key.disambiguated_data.data == DefPathData::Ctor {
1320-
def_key.parent.unwrap()
1321-
} else {
1322-
node_id
1323-
};
1324-
13251306
self.root
13261307
.tables
13271308
.attributes
1328-
.get(self, item_id)
1329-
.unwrap_or_else(Lazy::empty)
1309+
.get(self, id)
1310+
.unwrap_or_else(|| {
1311+
// Structure and variant constructors don't have any attributes encoded for them,
1312+
// but we assume that someone passing a constructor ID actually wants to look at
1313+
// the attributes on the corresponding struct or variant.
1314+
let def_key = self.def_key(id);
1315+
assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
1316+
let parent_id = def_key.parent.expect("no parent for a constructor");
1317+
self.root
1318+
.tables
1319+
.attributes
1320+
.get(self, parent_id)
1321+
.expect("no encoded attributes for a structure or variant")
1322+
})
13301323
.decode((self, sess))
13311324
}
13321325

@@ -1372,39 +1365,39 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13721365
self.root.traits.decode(self).map(|index| self.local_def_id(index))
13731366
}
13741367

1375-
fn get_implementations_for_trait(
1368+
fn get_trait_impls(&'a self) -> impl Iterator<Item = (DefId, Option<SimplifiedType>)> + 'a {
1369+
self.trait_impls.values().flat_map(move |impls| {
1370+
impls
1371+
.decode(self)
1372+
.map(|(idx, simplified_self_ty)| (self.local_def_id(idx), simplified_self_ty))
1373+
})
1374+
}
1375+
1376+
fn get_implementations_of_trait(
13761377
&self,
13771378
tcx: TyCtxt<'tcx>,
1378-
filter: Option<DefId>,
1379-
) -> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1379+
trait_def_id: DefId,
1380+
) -> &'tcx [(DefId, Option<SimplifiedType>)] {
13801381
if self.root.is_proc_macro_crate() {
13811382
// proc-macro crates export no trait impls.
13821383
return &[];
13831384
}
13841385

1385-
if let Some(def_id) = filter {
1386-
// Do a reverse lookup beforehand to avoid touching the crate_num
1387-
// hash map in the loop below.
1388-
let filter = match self.reverse_translate_def_id(def_id) {
1389-
Some(def_id) => (def_id.krate.as_u32(), def_id.index),
1390-
None => return &[],
1391-
};
1386+
// Do a reverse lookup beforehand to avoid touching the crate_num
1387+
// hash map in the loop below.
1388+
let key = match self.reverse_translate_def_id(trait_def_id) {
1389+
Some(def_id) => (def_id.krate.as_u32(), def_id.index),
1390+
None => return &[],
1391+
};
13921392

1393-
if let Some(impls) = self.trait_impls.get(&filter) {
1394-
tcx.arena.alloc_from_iter(
1395-
impls.decode(self).map(|(idx, simplified_self_ty)| {
1396-
(self.local_def_id(idx), simplified_self_ty)
1397-
}),
1398-
)
1399-
} else {
1400-
&[]
1401-
}
1402-
} else {
1403-
tcx.arena.alloc_from_iter(self.trait_impls.values().flat_map(|impls| {
1393+
if let Some(impls) = self.trait_impls.get(&key) {
1394+
tcx.arena.alloc_from_iter(
14041395
impls
14051396
.decode(self)
1406-
.map(|(idx, simplified_self_ty)| (self.local_def_id(idx), simplified_self_ty))
1407-
}))
1397+
.map(|(idx, simplified_self_ty)| (self.local_def_id(idx), simplified_self_ty)),
1398+
)
1399+
} else {
1400+
&[]
14081401
}
14091402
}
14101403

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
133133
generator_kind => { cdata.generator_kind(def_id.index) }
134134
opt_def_kind => { Some(cdata.def_kind(def_id.index)) }
135135
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
136-
def_ident_span => {
137-
cdata.try_item_ident(def_id.index, &tcx.sess).ok().map(|ident| ident.span)
138-
}
136+
def_ident_span => { cdata.opt_item_ident(def_id.index, &tcx.sess).map(|ident| ident.span) }
139137
lookup_stability => {
140138
cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s))
141139
}
@@ -145,9 +143,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
145143
lookup_deprecation_entry => {
146144
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
147145
}
148-
item_attrs => { tcx.arena.alloc_from_iter(
149-
cdata.get_item_attrs(def_id.index, tcx.sess)
150-
) }
146+
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
151147
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
152148
rendered_const => { cdata.get_rendered_const(def_id.index) }
153149
impl_parent => { cdata.get_parent_impl(def_id.index) }
@@ -196,14 +192,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
196192
extra_filename => { cdata.root.extra_filename.clone() }
197193

198194
traits_in_crate => { tcx.arena.alloc_from_iter(cdata.get_traits()) }
195+
all_trait_implementations => { tcx.arena.alloc_from_iter(cdata.get_trait_impls()) }
199196

200-
implementations_of_trait => {
201-
cdata.get_implementations_for_trait(tcx, Some(other))
202-
}
203-
204-
all_trait_implementations => {
205-
cdata.get_implementations_for_trait(tcx, None)
206-
}
197+
implementations_of_trait => { cdata.get_implementations_of_trait(tcx, other) }
207198

208199
visibility => { cdata.get_visibility(def_id.index) }
209200
dep_kind => {
@@ -470,7 +461,7 @@ impl CStore {
470461
self.get_crate_data(cnum).num_def_ids()
471462
}
472463

473-
pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
464+
pub fn item_attrs_untracked(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
474465
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
475466
}
476467

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::mir::interpret;
2626
use rustc_middle::thir;
2727
use rustc_middle::traits::specialization_graph;
2828
use rustc_middle::ty::codec::TyEncoder;
29-
use rustc_middle::ty::fast_reject::{self, SimplifyParams, StripReferences};
29+
use rustc_middle::ty::fast_reject::{self, SimplifiedType, SimplifyParams, StripReferences};
3030
use rustc_middle::ty::query::Providers;
3131
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
3232
use rustc_serialize::{opaque, Encodable, Encoder};
@@ -2055,7 +2055,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20552055

20562056
struct ImplsVisitor<'tcx> {
20572057
tcx: TyCtxt<'tcx>,
2058-
impls: FxHashMap<DefId, Vec<(DefIndex, Option<fast_reject::SimplifiedType>)>>,
2058+
impls: FxHashMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>>,
20592059
}
20602060

20612061
impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplsVisitor<'tcx> {

compiler/rustc_metadata/src/rmeta/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_middle::hir::exports::Export;
1616
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
1717
use rustc_middle::mir;
1818
use rustc_middle::thir;
19+
use rustc_middle::ty::fast_reject::SimplifiedType;
1920
use rustc_middle::ty::query::Providers;
2021
use rustc_middle::ty::{self, ReprOptions, Ty};
2122
use rustc_serialize::opaque::Encoder;
@@ -261,7 +262,7 @@ crate struct CrateDep {
261262
#[derive(MetadataEncodable, MetadataDecodable)]
262263
crate struct TraitImpls {
263264
trait_id: (u32, DefIndex),
264-
impls: Lazy<[(DefIndex, Option<ty::fast_reject::SimplifiedType>)]>,
265+
impls: Lazy<[(DefIndex, Option<SimplifiedType>)]>,
265266
}
266267

267268
/// Define `LazyTables` and `TableBuilders` at the same time.

compiler/rustc_middle/src/query/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1411,16 +1411,14 @@ rustc_queries! {
14111411

14121412
/// Given a crate and a trait, look up all impls of that trait in the crate.
14131413
/// Return `(impl_id, self_ty)`.
1414-
query implementations_of_trait(_: (CrateNum, DefId))
1415-
-> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1414+
query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
14161415
desc { "looking up implementations of a trait in a crate" }
14171416
separate_provide_extern
14181417
}
14191418

14201419
/// Given a crate, look up all trait impls in that crate.
14211420
/// Return `(impl_id, self_ty)`.
1422-
query all_trait_implementations(_: CrateNum)
1423-
-> &'tcx [(DefId, Option<ty::fast_reject::SimplifiedType>)] {
1421+
query all_trait_implementations(_: CrateNum) -> &'tcx [(DefId, Option<SimplifiedType>)] {
14241422
desc { "looking up all (?) trait implementations" }
14251423
separate_provide_extern
14261424
}

compiler/rustc_middle/src/ty/fast_reject.rs

+12
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ pub fn simplify_type(
143143
}
144144

145145
impl<D: Copy + Debug + Ord + Eq> SimplifiedTypeGen<D> {
146+
pub fn def(self) -> Option<D> {
147+
match self {
148+
AdtSimplifiedType(d)
149+
| ForeignSimplifiedType(d)
150+
| TraitSimplifiedType(d)
151+
| ClosureSimplifiedType(d)
152+
| GeneratorSimplifiedType(d)
153+
| OpaqueSimplifiedType(d) => Some(d),
154+
_ => None,
155+
}
156+
}
157+
146158
pub fn map_def<U, F>(self, map: F) -> SimplifiedTypeGen<U>
147159
where
148160
F: Fn(D) -> U,

compiler/rustc_middle/src/ty/query.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::traits::query::{
2828
};
2929
use crate::traits::specialization_graph;
3030
use crate::traits::{self, ImplSource};
31+
use crate::ty::fast_reject::SimplifiedType;
3132
use crate::ty::subst::{GenericArg, SubstsRef};
3233
use crate::ty::util::AlwaysRequiresDrop;
3334
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};

compiler/rustc_middle/src/ty/trait_def.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::traits::specialization_graph;
2-
use crate::ty::fast_reject::{self, SimplifyParams, StripReferences};
2+
use crate::ty::fast_reject::{self, SimplifiedType, SimplifyParams, StripReferences};
33
use crate::ty::fold::TypeFoldable;
44
use crate::ty::{Ty, TyCtxt};
55
use rustc_hir as hir;
@@ -68,7 +68,7 @@ pub enum TraitSpecializationKind {
6868
pub struct TraitImpls {
6969
blanket_impls: Vec<DefId>,
7070
/// Impls indexed by their simplified self type, for fast lookup.
71-
non_blanket_impls: FxIndexMap<fast_reject::SimplifiedType, Vec<DefId>>,
71+
non_blanket_impls: FxIndexMap<SimplifiedType, Vec<DefId>>,
7272
}
7373

7474
impl TraitImpls {

0 commit comments

Comments
 (0)