Skip to content

Commit 4b0f874

Browse files
committed
Auto merge of rust-lang#2823 - oli-obk:rustup, r=oli-obk
Rustup
2 parents d8795fa + 8c8fc36 commit 4b0f874

File tree

255 files changed

+2430
-1703
lines changed

Some content is hidden

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

255 files changed

+2430
-1703
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5294,6 +5294,7 @@ name = "rustc_span"
52945294
version = "0.0.0"
52955295
dependencies = [
52965296
"cfg-if",
5297+
"indexmap",
52975298
"md-5",
52985299
"rustc_arena",
52995300
"rustc_data_structures",

compiler/rustc_ast/src/attr/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ impl Attribute {
180180
self.doc_str().map_or(false, |s| comments::may_have_doc_links(s.as_str()))
181181
}
182182

183+
pub fn is_proc_macro_attr(&self) -> bool {
184+
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
185+
.iter()
186+
.any(|kind| self.has_name(*kind))
187+
}
188+
183189
/// Extracts the MetaItem from inside this Attribute.
184190
pub fn meta(&self) -> Option<MetaItem> {
185191
match &self.kind {
@@ -627,6 +633,22 @@ pub fn mk_attr_name_value_str(
627633
mk_attr(g, style, path, args, span)
628634
}
629635

636+
pub fn filter_by_name(attrs: &[Attribute], name: Symbol) -> impl Iterator<Item = &Attribute> {
637+
attrs.iter().filter(move |attr| attr.has_name(name))
638+
}
639+
640+
pub fn find_by_name(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> {
641+
filter_by_name(attrs, name).next()
642+
}
643+
644+
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: Symbol) -> Option<Symbol> {
645+
find_by_name(attrs, name).and_then(|attr| attr.value_str())
646+
}
647+
648+
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {
649+
find_by_name(attrs, name).is_some()
650+
}
651+
630652
pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
631653
items.iter().any(|item| item.has_name(name))
632654
}

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21852185
def_id: self.local_def_id(param.id),
21862186
name,
21872187
span: self.lower_span(param.span()),
2188-
pure_wrt_drop: self.tcx.sess.contains_name(&param.attrs, sym::may_dangle),
2188+
pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
21892189
kind,
21902190
colon_span: param.colon_span.map(|s| self.lower_span(s)),
21912191
source,

compiler/rustc_ast_passes/src/ast_validation.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
799799
}
800800

801801
fn visit_item(&mut self, item: &'a Item) {
802-
if item.attrs.iter().any(|attr| self.session.is_proc_macro_attr(attr)) {
802+
if item.attrs.iter().any(|attr| attr.is_proc_macro_attr()) {
803803
self.has_proc_macro_decls = true;
804804
}
805805

806-
if self.session.contains_name(&item.attrs, sym::no_mangle) {
806+
if attr::contains_name(&item.attrs, sym::no_mangle) {
807807
self.check_nomangle_item_asciionly(item.ident, item.span);
808808
}
809809

@@ -973,7 +973,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
973973
}
974974
// Ensure that `path` attributes on modules are recorded as used (cf. issue #35584).
975975
if !matches!(mod_kind, ModKind::Loaded(_, Inline::Yes, _))
976-
&& !self.session.contains_name(&item.attrs, sym::path)
976+
&& !attr::contains_name(&item.attrs, sym::path)
977977
{
978978
self.check_mod_file_item_asciionly(item.ident);
979979
}
@@ -1248,7 +1248,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12481248
}
12491249

12501250
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
1251-
if self.session.contains_name(&item.attrs, sym::no_mangle) {
1251+
if attr::contains_name(&item.attrs, sym::no_mangle) {
12521252
self.check_nomangle_item_asciionly(item.ident, item.span);
12531253
}
12541254

compiler/rustc_ast_passes/src/feature_gate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
3-
use rustc_ast::{AssocConstraint, AssocConstraintKind, NodeId};
3+
use rustc_ast::{attr, AssocConstraint, AssocConstraintKind, NodeId};
44
use rustc_ast::{PatKind, RangeEnd};
55
use rustc_errors::{Applicability, StashKey};
66
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
@@ -232,7 +232,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
232232
}
233233

234234
ast::ItemKind::Fn(..) => {
235-
if self.sess.contains_name(&i.attrs, sym::start) {
235+
if attr::contains_name(&i.attrs, sym::start) {
236236
gate_feature_post!(
237237
&self,
238238
start,
@@ -245,7 +245,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
245245
}
246246

247247
ast::ItemKind::Struct(..) => {
248-
for attr in self.sess.filter_by_name(&i.attrs, sym::repr) {
248+
for attr in attr::filter_by_name(&i.attrs, sym::repr) {
249249
for item in attr.meta_item_list().unwrap_or_else(ThinVec::new) {
250250
if item.has_name(sym::simd) {
251251
gate_feature_post!(
@@ -306,7 +306,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
306306
fn visit_foreign_item(&mut self, i: &'a ast::ForeignItem) {
307307
match i.kind {
308308
ast::ForeignItemKind::Fn(..) | ast::ForeignItemKind::Static(..) => {
309-
let link_name = self.sess.first_attr_value_str_by_name(&i.attrs, sym::link_name);
309+
let link_name = attr::first_attr_value_str_by_name(&i.attrs, sym::link_name);
310310
let links_to_llvm =
311311
link_name.map_or(false, |val| val.as_str().starts_with("llvm."));
312312
if links_to_llvm {

compiler/rustc_attr/src/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Parsing and validation of builtin attributes
22
3-
use rustc_ast as ast;
3+
use rustc_ast::{self as ast, attr};
44
use rustc_ast::{Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NodeId};
55
use rustc_ast_pretty::pprust;
66
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
@@ -556,8 +556,8 @@ where
556556
(stab, const_stab, body_stab)
557557
}
558558

559-
pub fn find_crate_name(sess: &Session, attrs: &[Attribute]) -> Option<Symbol> {
560-
sess.first_attr_value_str_by_name(attrs, sym::crate_name)
559+
pub fn find_crate_name(attrs: &[Attribute]) -> Option<Symbol> {
560+
attr::first_attr_value_str_by_name(attrs, sym::crate_name)
561561
}
562562

563563
#[derive(Clone, Debug)]
@@ -1177,7 +1177,7 @@ fn allow_unstable<'a>(
11771177
attrs: &'a [Attribute],
11781178
symbol: Symbol,
11791179
) -> impl Iterator<Item = Symbol> + 'a {
1180-
let attrs = sess.filter_by_name(attrs, symbol);
1180+
let attrs = attr::filter_by_name(attrs, symbol);
11811181
let list = attrs
11821182
.filter_map(move |attr| {
11831183
attr.meta_item_list().or_else(|| {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
120120
&& !self.upvars.is_empty()
121121
{
122122
item_msg = access_place_desc;
123-
debug_assert!(
124-
self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_region_ptr()
125-
);
123+
debug_assert!(self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_ref());
126124
debug_assert!(is_closure_or_generator(
127125
Place::ty_from(
128126
the_place_err.local,
@@ -470,11 +468,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
470468
{
471469
let local_decl = &self.body.local_decls[local];
472470

473-
let (pointer_sigil, pointer_desc) = if local_decl.ty.is_region_ptr() {
474-
("&", "reference")
475-
} else {
476-
("*const", "pointer")
477-
};
471+
let (pointer_sigil, pointer_desc) =
472+
if local_decl.ty.is_ref() { ("&", "reference") } else { ("*const", "pointer") };
478473

479474
match self.local_names[local] {
480475
Some(name) if !local_decl.from_compiler_desugaring() => {
@@ -1258,7 +1253,7 @@ fn suggest_ampmut<'tcx>(
12581253
(
12591254
suggestability,
12601255
highlight_span,
1261-
if local_decl.ty.is_region_ptr() {
1256+
if local_decl.ty.is_ref() {
12621257
format!("&mut {}", ty_mut.ty)
12631258
} else {
12641259
format!("*mut {}", ty_mut.ty)

compiler/rustc_borrowck/src/lib.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extern crate tracing;
1919

2020
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2121
use rustc_data_structures::graph::dominators::Dominators;
22-
use rustc_data_structures::vec_map::VecMap;
2322
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, SubdiagnosticMessage};
2423
use rustc_hir as hir;
2524
use rustc_hir::def_id::LocalDefId;
@@ -141,7 +140,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &Bor
141140
debug!("Skipping borrowck because of injected body");
142141
// Let's make up a borrowck result! Fun times!
143142
let result = BorrowCheckResult {
144-
concrete_opaque_types: VecMap::new(),
143+
concrete_opaque_types: FxIndexMap::default(),
145144
closure_requirements: None,
146145
used_mut_upvars: SmallVec::new(),
147146
tainted_by_errors: None,
@@ -511,16 +510,11 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
511510
.as_var()
512511
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
513512

514-
if cfg!(debug_assertions) {
513+
if cfg!(debug_assertions) && !self.inside_canonicalization_ctxt() {
515514
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
516515
let ctxt = get_ctxt_fn();
517516
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
518-
let prev = var_to_origin.insert(vid, ctxt);
519-
520-
// This only makes sense if not called in a canonicalization context. If this
521-
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
522-
// or modify how we track nll region vars for that map.
523-
assert!(matches!(prev, None));
517+
var_to_origin.insert(vid, ctxt);
524518
}
525519

526520
next_region
@@ -540,16 +534,11 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
540534
.as_var()
541535
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
542536

543-
if cfg!(debug_assertions) {
537+
if cfg!(debug_assertions) && !self.inside_canonicalization_ctxt() {
544538
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
545539
let ctxt = get_ctxt_fn();
546540
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
547-
let prev = var_to_origin.insert(vid, ctxt);
548-
549-
// This only makes sense if not called in a canonicalization context. If this
550-
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
551-
// or modify how we track nll region vars for that map.
552-
assert!(matches!(prev, None));
541+
var_to_origin.insert(vid, ctxt);
553542
}
554543

555544
next_region

compiler/rustc_borrowck/src/nll.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![deny(rustc::diagnostic_outside_of_impl)]
33
//! The entry point of the NLL borrow checker.
44
5-
use rustc_data_structures::vec_map::VecMap;
5+
use rustc_data_structures::fx::FxIndexMap;
66
use rustc_hir::def_id::LocalDefId;
77
use rustc_index::vec::IndexVec;
88
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
@@ -44,7 +44,7 @@ pub type PoloniusOutput = Output<RustcFacts>;
4444
/// closure requirements to propagate, and any generated errors.
4545
pub(crate) struct NllOutput<'tcx> {
4646
pub regioncx: RegionInferenceContext<'tcx>,
47-
pub opaque_type_values: VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
47+
pub opaque_type_values: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
4848
pub polonius_input: Option<Box<AllFacts>>,
4949
pub polonius_output: Option<Rc<PoloniusOutput>>,
5050
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
@@ -377,7 +377,7 @@ pub(super) fn dump_annotation<'tcx>(
377377
body: &Body<'tcx>,
378378
regioncx: &RegionInferenceContext<'tcx>,
379379
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
380-
opaque_type_values: &VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
380+
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
381381
errors: &mut crate::error::BorrowckErrors<'tcx>,
382382
) {
383383
let tcx = infcx.tcx;

compiler/rustc_borrowck/src/region_infer/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,12 @@ fn sccs_info<'cx, 'tcx>(
256256

257257
let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
258258
var_to_origin_sorted.sort_by_key(|vto| vto.0);
259-
let mut debug_str = "region variables to origins:\n".to_string();
259+
260+
let mut reg_vars_to_origins_str = "region variables to origins:\n".to_string();
260261
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
261-
debug_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
262+
reg_vars_to_origins_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
262263
}
263-
debug!(debug_str);
264+
debug!("{}", reg_vars_to_origins_str);
264265

265266
let num_components = sccs.scc_data().ranges().len();
266267
let mut components = vec![FxIndexSet::default(); num_components];
@@ -275,12 +276,12 @@ fn sccs_info<'cx, 'tcx>(
275276
for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
276277
let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
277278
components_str.push_str(&format!(
278-
"{:?}: {:?})",
279+
"{:?}: {:?},\n)",
279280
ConstraintSccIndex::from_usize(scc_idx),
280281
regions_info,
281282
))
282283
}
283-
debug!(components_str);
284+
debug!("{}", components_str);
284285

285286
// calculate the best representative for each component
286287
let components_representatives = components

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2-
use rustc_data_structures::vec_map::VecMap;
32
use rustc_errors::ErrorGuaranteed;
43
use rustc_hir::def_id::LocalDefId;
54
use rustc_hir::OpaqueTyOrigin;
@@ -61,9 +60,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6160
pub(crate) fn infer_opaque_types(
6261
&self,
6362
infcx: &InferCtxt<'tcx>,
64-
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
65-
) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
66-
let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();
63+
opaque_ty_decls: FxIndexMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
64+
) -> FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> {
65+
let mut result: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> = FxIndexMap::default();
6766

6867
let member_constraints: FxIndexMap<_, _> = self
6968
.member_constraints

compiler/rustc_borrowck/src/type_check/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use either::Either;
1010
use hir::OpaqueTyOrigin;
1111
use rustc_data_structures::frozen::Frozen;
1212
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
13-
use rustc_data_structures::vec_map::VecMap;
1413
use rustc_hir as hir;
1514
use rustc_hir::def::DefKind;
1615
use rustc_hir::def_id::LocalDefId;
@@ -894,7 +893,7 @@ pub(crate) struct MirTypeckResults<'tcx> {
894893
pub(crate) constraints: MirTypeckRegionConstraints<'tcx>,
895894
pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
896895
pub(crate) opaque_type_values:
897-
VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
896+
FxIndexMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
898897
}
899898

900899
/// A collection of region constraints that must be satisfied for the

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,12 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
132132

133133
let reg_var =
134134
reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
135-
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
136-
let prev = var_to_origin.insert(reg_var, RegionCtxt::Placeholder(reg_info));
137-
assert!(matches!(prev, None));
135+
136+
if cfg!(debug_assertions) && !self.type_checker.infcx.inside_canonicalization_ctxt() {
137+
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
138+
debug!(?reg_var);
139+
var_to_origin.insert(reg_var, RegionCtxt::Placeholder(reg_info));
140+
}
138141

139142
reg
140143
}
@@ -149,14 +152,9 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
149152
let reg_var =
150153
reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
151154

152-
if cfg!(debug_assertions) {
155+
if cfg!(debug_assertions) && !self.type_checker.infcx.inside_canonicalization_ctxt() {
153156
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
154-
let prev = var_to_origin.insert(reg_var, RegionCtxt::Existential(None));
155-
156-
// It only makes sense to track region vars in non-canonicalization contexts. If this
157-
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
158-
// or modify how we track nll region vars for that map.
159-
assert!(matches!(prev, None));
157+
var_to_origin.insert(reg_var, RegionCtxt::Existential(None));
160158
}
161159

162160
reg

0 commit comments

Comments
 (0)