Skip to content

Commit edeb631

Browse files
committed
Auto merge of #81113 - m-ou-se:rollup-a1unz4x, r=m-ou-se
Rollup of 13 pull requests Successful merges: - #79298 (correctly deal with late-bound lifetimes in anon consts) - #80031 (resolve: Reject ambiguity built-in attr vs different built-in attr) - #80201 (Add benchmark and fast path for BufReader::read_exact) - #80635 (Improve diagnostics when closure doesn't meet trait bound) - #80765 (resolve: Simplify collection of traits in scope) - #80932 (Allow downloading LLVM on Windows and MacOS) - #80983 (Remove is_dllimport_foreign_item definition from cg_ssa) - #81064 (Support non-stage0 check) - #81080 (Force vec![] to expression position only) - #81082 (BTreeMap: clean up a few more comments) - #81084 (Use Option::map instead of open-coding it) - #81095 (Use Option::unwrap_or instead of open-coding it) - #81107 (Add NonZeroUn::is_power_of_two) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7d38181 + 8016846 commit edeb631

File tree

60 files changed

+812
-399
lines changed

Some content is hidden

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

60 files changed

+812
-399
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ fn handle_native(name: &str) -> &str {
214214
}
215215

216216
pub fn target_cpu(sess: &Session) -> &str {
217-
let name = match sess.opts.cg.target_cpu {
218-
Some(ref s) => &**s,
219-
None => &*sess.target.cpu,
220-
};
221-
217+
let name = sess.opts.cg.target_cpu.as_ref().unwrap_or(&sess.target.cpu);
222218
handle_native(name)
223219
}
224220

@@ -254,8 +250,6 @@ pub fn handle_native_features(sess: &Session) -> Vec<String> {
254250
}
255251

256252
pub fn tune_cpu(sess: &Session) -> Option<&str> {
257-
match sess.opts.debugging_opts.tune_cpu {
258-
Some(ref s) => Some(handle_native(&**s)),
259-
None => None,
260-
}
253+
let name = sess.opts.debugging_opts.tune_cpu.as_ref()?;
254+
Some(handle_native(name))
261255
}

compiler/rustc_codegen_ssa/src/base.rs

-27
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_middle::ty::query::Providers;
2929
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
3030
use rustc_session::cgu_reuse_tracker::CguReuse;
3131
use rustc_session::config::{self, EntryFnType};
32-
use rustc_session::utils::NativeLibKind;
3332
use rustc_session::Session;
3433
use rustc_target::abi::{Align, LayoutOf, VariantIdx};
3534

@@ -817,32 +816,6 @@ pub fn provide_both(providers: &mut Providers) {
817816
}
818817
tcx.sess.opts.optimize
819818
};
820-
821-
providers.dllimport_foreign_items = |tcx, krate| {
822-
let module_map = tcx.foreign_modules(krate);
823-
824-
let dllimports = tcx
825-
.native_libraries(krate)
826-
.iter()
827-
.filter(|lib| {
828-
if !matches!(lib.kind, NativeLibKind::Dylib | NativeLibKind::Unspecified) {
829-
return false;
830-
}
831-
let cfg = match lib.cfg {
832-
Some(ref cfg) => cfg,
833-
None => return true,
834-
};
835-
attr::cfg_matches(cfg, &tcx.sess.parse_sess, None)
836-
})
837-
.filter_map(|lib| lib.foreign_module)
838-
.map(|id| &module_map[&id])
839-
.flat_map(|module| module.foreign_items.iter().cloned())
840-
.collect();
841-
dllimports
842-
};
843-
844-
providers.is_dllimport_foreign_item =
845-
|tcx, def_id| tcx.dllimport_foreign_items(def_id.krate).contains(&def_id);
846819
}
847820

848821
fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse {

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,11 @@ crate fn annotate_err_with_kind(
5656
};
5757
}
5858

59-
/// Instead of e.g. `vec![a, b, c]` in a pattern context, suggest `[a, b, c]`.
60-
fn suggest_slice_pat(e: &mut DiagnosticBuilder<'_>, site_span: Span, parser: &Parser<'_>) {
61-
let mut suggestion = None;
62-
if let Ok(code) = parser.sess.source_map().span_to_snippet(site_span) {
63-
if let Some(bang) = code.find('!') {
64-
suggestion = Some(code[bang + 1..].to_string());
65-
}
66-
}
67-
if let Some(suggestion) = suggestion {
68-
e.span_suggestion(
69-
site_span,
70-
"use a slice pattern here instead",
71-
suggestion,
72-
Applicability::MachineApplicable,
73-
);
74-
} else {
75-
e.span_label(site_span, "use a slice pattern here instead");
76-
}
77-
e.help(
78-
"for more information, see https://doc.rust-lang.org/edition-guide/\
79-
rust-2018/slice-patterns.html",
80-
);
81-
}
82-
8359
fn emit_frag_parse_err(
8460
mut e: DiagnosticBuilder<'_>,
8561
parser: &Parser<'_>,
8662
orig_parser: &mut Parser<'_>,
8763
site_span: Span,
88-
macro_ident: Ident,
8964
arm_span: Span,
9065
kind: AstFragmentKind,
9166
) {
@@ -113,9 +88,6 @@ fn emit_frag_parse_err(
11388
e.span_label(site_span, "in this macro invocation");
11489
}
11590
match kind {
116-
AstFragmentKind::Pat if macro_ident.name == sym::vec => {
117-
suggest_slice_pat(&mut e, site_span, parser);
118-
}
11991
// Try a statement if an expression is wanted but failed and suggest adding `;` to call.
12092
AstFragmentKind::Expr => match parse_ast_fragment(orig_parser, AstFragmentKind::Stmts) {
12193
Err(mut err) => err.cancel(),
@@ -143,7 +115,7 @@ impl<'a> ParserAnyMacro<'a> {
143115
let fragment = match parse_ast_fragment(parser, kind) {
144116
Ok(f) => f,
145117
Err(err) => {
146-
emit_frag_parse_err(err, parser, snapshot, site_span, macro_ident, arm_span, kind);
118+
emit_frag_parse_err(err, parser, snapshot, site_span, arm_span, kind);
147119
return kind.dummy(site_span);
148120
}
149121
};

compiler/rustc_hir/src/def.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_ast as ast;
55
use rustc_ast::NodeId;
66
use rustc_macros::HashStable_Generic;
77
use rustc_span::hygiene::MacroKind;
8+
use rustc_span::Symbol;
89

910
use std::array::IntoIter;
1011
use std::fmt::Debug;
@@ -34,7 +35,7 @@ pub enum CtorKind {
3435
#[derive(HashStable_Generic)]
3536
pub enum NonMacroAttrKind {
3637
/// Single-segment attribute defined by the language (`#[inline]`)
37-
Builtin,
38+
Builtin(Symbol),
3839
/// Multi-segment custom attribute living in a "tool module" (`#[rustfmt::skip]`).
3940
Tool,
4041
/// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`).
@@ -371,7 +372,7 @@ impl CtorKind {
371372
impl NonMacroAttrKind {
372373
pub fn descr(self) -> &'static str {
373374
match self {
374-
NonMacroAttrKind::Builtin => "built-in attribute",
375+
NonMacroAttrKind::Builtin(..) => "built-in attribute",
375376
NonMacroAttrKind::Tool => "tool attribute",
376377
NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
377378
"derive helper attribute"
@@ -393,7 +394,7 @@ impl NonMacroAttrKind {
393394
NonMacroAttrKind::Tool
394395
| NonMacroAttrKind::DeriveHelper
395396
| NonMacroAttrKind::DeriveHelperCompat => true,
396-
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false,
397+
NonMacroAttrKind::Builtin(..) | NonMacroAttrKind::Registered => false,
397398
}
398399
}
399400
}

compiler/rustc_middle/src/query/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1281,11 +1281,6 @@ rustc_queries! {
12811281
}
12821282

12831283
Other {
1284-
query dllimport_foreign_items(_: CrateNum)
1285-
-> FxHashSet<DefId> {
1286-
storage(ArenaCacheSelector<'tcx>)
1287-
desc { "dllimport_foreign_items" }
1288-
}
12891284
query is_dllimport_foreign_item(def_id: DefId) -> bool {
12901285
desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
12911286
}
@@ -1316,7 +1311,7 @@ rustc_queries! {
13161311
desc { "looking up a named region" }
13171312
}
13181313
query is_late_bound_map(_: LocalDefId) ->
1319-
Option<&'tcx FxHashSet<ItemLocalId>> {
1314+
Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
13201315
desc { "testing if a region is late bound" }
13211316
}
13221317
query object_lifetime_defaults_map(_: LocalDefId)

compiler/rustc_middle/src/ty/context.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::arena::Arena;
44
use crate::dep_graph::DepGraph;
55
use crate::hir::exports::ExportMap;
6+
use crate::hir::place::Place as HirPlace;
67
use crate::ich::{NodeIdHashingMode, StableHashingContext};
78
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
89
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
@@ -379,7 +380,7 @@ pub struct TypeckResults<'tcx> {
379380

380381
/// Records the reasons that we picked the kind of each closure;
381382
/// not all closures are present in the map.
382-
closure_kind_origins: ItemLocalMap<(Span, Symbol)>,
383+
closure_kind_origins: ItemLocalMap<(Span, HirPlace<'tcx>)>,
383384

384385
/// For each fn, records the "liberated" types of its arguments
385386
/// and return type. Liberated means that all bound regions
@@ -642,11 +643,13 @@ impl<'tcx> TypeckResults<'tcx> {
642643
self.upvar_capture_map[&upvar_id]
643644
}
644645

645-
pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, Symbol)> {
646+
pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, HirPlace<'tcx>)> {
646647
LocalTableInContext { hir_owner: self.hir_owner, data: &self.closure_kind_origins }
647648
}
648649

649-
pub fn closure_kind_origins_mut(&mut self) -> LocalTableInContextMut<'_, (Span, Symbol)> {
650+
pub fn closure_kind_origins_mut(
651+
&mut self,
652+
) -> LocalTableInContextMut<'_, (Span, HirPlace<'tcx>)> {
650653
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.closure_kind_origins }
651654
}
652655

@@ -2578,7 +2581,8 @@ impl<'tcx> TyCtxt<'tcx> {
25782581
}
25792582

25802583
pub fn is_late_bound(self, id: HirId) -> bool {
2581-
self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id))
2584+
self.is_late_bound_map(id.owner)
2585+
.map_or(false, |(owner, set)| owner == id.owner && set.contains(&id.local_id))
25822586
}
25832587

25842588
pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {

compiler/rustc_middle/src/ty/mod.rs

+40-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ pub use self::IntVarValue::*;
1717
pub use self::Variance::*;
1818

1919
use crate::hir::exports::ExportMap;
20-
use crate::hir::place::Place as HirPlace;
20+
use crate::hir::place::{
21+
Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
22+
};
2123
use crate::ich::StableHashingContext;
2224
use crate::middle::cstore::CrateStoreDyn;
2325
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
@@ -734,6 +736,43 @@ pub struct CapturedPlace<'tcx> {
734736
pub info: CaptureInfo<'tcx>,
735737
}
736738

739+
pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {
740+
let name = match place.base {
741+
HirPlaceBase::Upvar(upvar_id) => tcx.hir().name(upvar_id.var_path.hir_id).to_string(),
742+
_ => bug!("Capture_information should only contain upvars"),
743+
};
744+
let mut curr_string = name;
745+
746+
for (i, proj) in place.projections.iter().enumerate() {
747+
match proj.kind {
748+
HirProjectionKind::Deref => {
749+
curr_string = format!("*{}", curr_string);
750+
}
751+
HirProjectionKind::Field(idx, variant) => match place.ty_before_projection(i).kind() {
752+
ty::Adt(def, ..) => {
753+
curr_string = format!(
754+
"{}.{}",
755+
curr_string,
756+
def.variants[variant].fields[idx as usize].ident.name.as_str()
757+
);
758+
}
759+
ty::Tuple(_) => {
760+
curr_string = format!("{}.{}", curr_string, idx);
761+
}
762+
_ => {
763+
bug!(
764+
"Field projection applied to a type other than Adt or Tuple: {:?}.",
765+
place.ty_before_projection(i).kind()
766+
)
767+
}
768+
},
769+
proj => bug!("{:?} unexpected because it isn't captured", proj),
770+
}
771+
}
772+
773+
curr_string.to_string()
774+
}
775+
737776
/// Part of `MinCaptureInformationMap`; describes the capture kind (&, &mut, move)
738777
/// for a particular capture as well as identifying the part of the source code
739778
/// that triggered this capture to occur.

compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
103103
let did = did.expect_local();
104104
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);
105105

106-
if let Some((span, name)) =
106+
if let Some((span, hir_place)) =
107107
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
108108
{
109109
diag.span_note(
110110
*span,
111111
&format!(
112112
"closure cannot be invoked more than once because it moves the \
113113
variable `{}` out of its environment",
114-
name,
114+
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
115115
),
116116
);
117117
return;
@@ -127,15 +127,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
127127
let did = did.expect_local();
128128
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);
129129

130-
if let Some((span, name)) =
130+
if let Some((span, hir_place)) =
131131
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
132132
{
133133
diag.span_note(
134134
*span,
135135
&format!(
136136
"closure cannot be moved more than once as it is not `Copy` due to \
137137
moving the variable `{}` out of its environment",
138-
name
138+
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
139139
),
140140
);
141141
}

compiler/rustc_mir/src/borrow_check/type_check/input_output.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3939
user_provided_sig = None;
4040
} else {
4141
let typeck_results = self.tcx().typeck(mir_def_id);
42-
user_provided_sig = match typeck_results.user_provided_sigs.get(&mir_def_id.to_def_id())
43-
{
44-
None => None,
45-
Some(user_provided_poly_sig) => {
42+
user_provided_sig = typeck_results.user_provided_sigs.get(&mir_def_id.to_def_id()).map(
43+
|user_provided_poly_sig| {
4644
// Instantiate the canonicalized variables from
4745
// user-provided signature (e.g., the `_` in the code
4846
// above) with fresh variables.
@@ -54,18 +52,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
5452
// Replace the bound items in the fn sig with fresh
5553
// variables, so that they represent the view from
5654
// "inside" the closure.
57-
Some(
58-
self.infcx
59-
.replace_bound_vars_with_fresh_vars(
60-
body.span,
61-
LateBoundRegionConversionTime::FnCall,
62-
poly_sig,
63-
)
64-
.0,
65-
)
66-
}
67-
}
68-
};
55+
self.infcx
56+
.replace_bound_vars_with_fresh_vars(
57+
body.span,
58+
LateBoundRegionConversionTime::FnCall,
59+
poly_sig,
60+
)
61+
.0
62+
},
63+
);
64+
}
6965

7066
debug!(
7167
"equate_inputs_and_outputs: normalized_input_tys = {:?}, local_decls = {:?}",

compiler/rustc_mir/src/borrow_check/universal_regions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,13 @@ fn for_each_late_bound_region_defined_on<'tcx>(
788788
fn_def_id: DefId,
789789
mut f: impl FnMut(ty::Region<'tcx>),
790790
) {
791-
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
792-
for late_bound in late_bounds.iter() {
793-
let hir_id = HirId { owner: fn_def_id.expect_local(), local_id: *late_bound };
791+
if let Some((owner, late_bounds)) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
792+
for &late_bound in late_bounds.iter() {
793+
let hir_id = HirId { owner, local_id: late_bound };
794794
let name = tcx.hir().name(hir_id);
795795
let region_def_id = tcx.hir().local_def_id(hir_id);
796796
let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion {
797-
scope: fn_def_id,
797+
scope: owner.to_def_id(),
798798
bound_region: ty::BoundRegionKind::BrNamed(region_def_id.to_def_id(), name),
799799
}));
800800
f(liberated_region);

compiler/rustc_resolve/src/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a> Resolver<'a> {
115115
self.get_module(parent_id)
116116
}
117117

118-
crate fn get_module(&mut self, def_id: DefId) -> Module<'a> {
118+
pub fn get_module(&mut self, def_id: DefId) -> Module<'a> {
119119
// If this is a local module, it will be in `module_map`, no need to recalculate it.
120120
if let Some(def_id) = def_id.as_local() {
121121
return self.module_map[&def_id];

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl<'a> Resolver<'a> {
683683
));
684684
}
685685
Scope::BuiltinAttrs => {
686-
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin);
686+
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin(kw::Empty));
687687
if filter_fn(res) {
688688
suggestions.extend(
689689
BUILTIN_ATTRIBUTES

0 commit comments

Comments
 (0)