Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 13 pull requests #81111

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b498870
use hir::Place instead of Symbol in closure_kind_origin
roxelo Dec 3, 2020
b7071b2
resolve: Simplify collection of traits in scope
petrochenkov Jan 6, 2021
7aca2fa
Remove is_dllimport_foreign_item def from cg_ssa
bjorn3 Jan 13, 2021
6766070
Allow downloading LLVM on Windows
jyn514 Jan 12, 2021
5c4adbe
Add all tier 1 platforms to supported platforms for "if-available"
jyn514 Jan 13, 2021
8b702e0
Support non-stage0 check
Mark-Simulacrum Jan 16, 2021
c17ed34
Print which stage is being checked (now that it may not be stage0)
jyn514 Jan 16, 2021
53989e4
Allow configuring the default stage for `x.py check`
jyn514 Jan 16, 2021
50ee0b2
BTreeMap: clean up a few more comments
ssomers Nov 18, 2020
28501c0
rustc_parse_format: Fix character indices in find_skips
osa1 Jan 16, 2021
15f0921
correctly deal with late-bound lifetimes in anon consts
lcnr Nov 22, 2020
76003f3
Use Option::map instead of open-coding it
LingMan Dec 30, 2020
5a706cf
Use Option::unwrap_or instead of open-coding it
LingMan Jan 16, 2021
7f9a2cf
resolve: Reject ambiguity built-in attr vs different built-in attr
petrochenkov Dec 13, 2020
4e27ed3
Add benchmark and fast path for BufReader::read_exact
saethlin Dec 19, 2020
3e16e92
Add NonZeroUn::is_power_of_two
scottmcm Jan 17, 2021
5451592
Rollup merge of #79298 - lcnr:new-elysium, r=matthewjasper
m-ou-se Jan 17, 2021
ea81a28
Rollup merge of #80031 - petrochenkov:builtina, r=estebank
m-ou-se Jan 17, 2021
1448a76
Rollup merge of #80201 - saethlin:bufreader-read-exact, r=KodrAus
m-ou-se Jan 17, 2021
343b860
Rollup merge of #80635 - sexxi-goose:use-place-instead-of-symbol, r=n…
m-ou-se Jan 17, 2021
b0dca9b
Rollup merge of #80765 - petrochenkov:traitsinscope, r=matthewjasper
m-ou-se Jan 17, 2021
98cc8ae
Rollup merge of #80932 - jyn514:download-windows-llvm, r=Mark-Simulacrum
m-ou-se Jan 17, 2021
0686e85
Rollup merge of #80983 - bjorn3:no_dup_is_dllimport_foreign_item, r=n…
m-ou-se Jan 17, 2021
ed10e8f
Rollup merge of #81064 - Mark-Simulacrum:support-stage1-check, r=jyn514
m-ou-se Jan 17, 2021
c36acae
Rollup merge of #81071 - osa1:fix_81006, r=estebank
m-ou-se Jan 17, 2021
fde7956
Rollup merge of #81082 - ssomers:btree_cleanup_comments, r=Mark-Simul…
m-ou-se Jan 17, 2021
076c019
Rollup merge of #81084 - LingMan:map, r=oli-obk
m-ou-se Jan 17, 2021
24b606d
Rollup merge of #81095 - LingMan:unwrap, r=oli-obk
m-ou-se Jan 17, 2021
94ec9f9
Rollup merge of #81107 - scottmcm:nonzero-is_power_of_two, r=kennytm
m-ou-se Jan 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ fn handle_native(name: &str) -> &str {
}

pub fn target_cpu(sess: &Session) -> &str {
let name = match sess.opts.cg.target_cpu {
Some(ref s) => &**s,
None => &*sess.target.cpu,
};

let name = sess.opts.cg.target_cpu.as_ref().unwrap_or(&sess.target.cpu);
handle_native(name)
}

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

pub fn tune_cpu(sess: &Session) -> Option<&str> {
match sess.opts.debugging_opts.tune_cpu {
Some(ref s) => Some(handle_native(&**s)),
None => None,
}
let name = sess.opts.debugging_opts.tune_cpu.as_ref()?;
Some(handle_native(name))
}
27 changes: 0 additions & 27 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_session::config::{self, EntryFnType};
use rustc_session::utils::NativeLibKind;
use rustc_session::Session;
use rustc_target::abi::{Align, LayoutOf, VariantIdx};

Expand Down Expand Up @@ -817,32 +816,6 @@ pub fn provide_both(providers: &mut Providers) {
}
tcx.sess.opts.optimize
};

providers.dllimport_foreign_items = |tcx, krate| {
let module_map = tcx.foreign_modules(krate);

let dllimports = tcx
.native_libraries(krate)
.iter()
.filter(|lib| {
if !matches!(lib.kind, NativeLibKind::Dylib | NativeLibKind::Unspecified) {
return false;
}
let cfg = match lib.cfg {
Some(ref cfg) => cfg,
None => return true,
};
attr::cfg_matches(cfg, &tcx.sess.parse_sess, None)
})
.filter_map(|lib| lib.foreign_module)
.map(|id| &module_map[&id])
.flat_map(|module| module.foreign_items.iter().cloned())
.collect();
dllimports
};

providers.is_dllimport_foreign_item =
|tcx, def_id| tcx.dllimport_foreign_items(def_id.krate).contains(&def_id);
}

fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustc_ast as ast;
use rustc_ast::NodeId;
use rustc_macros::HashStable_Generic;
use rustc_span::hygiene::MacroKind;
use rustc_span::Symbol;

use std::array::IntoIter;
use std::fmt::Debug;
Expand Down Expand Up @@ -34,7 +35,7 @@ pub enum CtorKind {
#[derive(HashStable_Generic)]
pub enum NonMacroAttrKind {
/// Single-segment attribute defined by the language (`#[inline]`)
Builtin,
Builtin(Symbol),
/// Multi-segment custom attribute living in a "tool module" (`#[rustfmt::skip]`).
Tool,
/// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`).
Expand Down Expand Up @@ -371,7 +372,7 @@ impl CtorKind {
impl NonMacroAttrKind {
pub fn descr(self) -> &'static str {
match self {
NonMacroAttrKind::Builtin => "built-in attribute",
NonMacroAttrKind::Builtin(..) => "built-in attribute",
NonMacroAttrKind::Tool => "tool attribute",
NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
"derive helper attribute"
Expand All @@ -393,7 +394,7 @@ impl NonMacroAttrKind {
NonMacroAttrKind::Tool
| NonMacroAttrKind::DeriveHelper
| NonMacroAttrKind::DeriveHelperCompat => true,
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false,
NonMacroAttrKind::Builtin(..) | NonMacroAttrKind::Registered => false,
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,11 +1281,6 @@ rustc_queries! {
}

Other {
query dllimport_foreign_items(_: CrateNum)
-> FxHashSet<DefId> {
storage(ArenaCacheSelector<'tcx>)
desc { "dllimport_foreign_items" }
}
query is_dllimport_foreign_item(def_id: DefId) -> bool {
desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
}
Expand Down Expand Up @@ -1316,7 +1311,7 @@ rustc_queries! {
desc { "looking up a named region" }
}
query is_late_bound_map(_: LocalDefId) ->
Option<&'tcx FxHashSet<ItemLocalId>> {
Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
desc { "testing if a region is late bound" }
}
query object_lifetime_defaults_map(_: LocalDefId)
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::arena::Arena;
use crate::dep_graph::DepGraph;
use crate::hir::exports::ExportMap;
use crate::hir::place::Place as HirPlace;
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
Expand Down Expand Up @@ -379,7 +380,7 @@ pub struct TypeckResults<'tcx> {

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

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

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

pub fn closure_kind_origins_mut(&mut self) -> LocalTableInContextMut<'_, (Span, Symbol)> {
pub fn closure_kind_origins_mut(
&mut self,
) -> LocalTableInContextMut<'_, (Span, HirPlace<'tcx>)> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.closure_kind_origins }
}

Expand Down Expand Up @@ -2578,7 +2581,8 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn is_late_bound(self, id: HirId) -> bool {
self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id))
self.is_late_bound_map(id.owner)
.map_or(false, |(owner, set)| owner == id.owner && set.contains(&id.local_id))
}

pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {
Expand Down
41 changes: 40 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub use self::IntVarValue::*;
pub use self::Variance::*;

use crate::hir::exports::ExportMap;
use crate::hir::place::Place as HirPlace;
use crate::hir::place::{
Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
};
use crate::ich::StableHashingContext;
use crate::middle::cstore::CrateStoreDyn;
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
Expand Down Expand Up @@ -734,6 +736,43 @@ pub struct CapturedPlace<'tcx> {
pub info: CaptureInfo<'tcx>,
}

pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {
let name = match place.base {
HirPlaceBase::Upvar(upvar_id) => tcx.hir().name(upvar_id.var_path.hir_id).to_string(),
_ => bug!("Capture_information should only contain upvars"),
};
let mut curr_string = name;

for (i, proj) in place.projections.iter().enumerate() {
match proj.kind {
HirProjectionKind::Deref => {
curr_string = format!("*{}", curr_string);
}
HirProjectionKind::Field(idx, variant) => match place.ty_before_projection(i).kind() {
ty::Adt(def, ..) => {
curr_string = format!(
"{}.{}",
curr_string,
def.variants[variant].fields[idx as usize].ident.name.as_str()
);
}
ty::Tuple(_) => {
curr_string = format!("{}.{}", curr_string, idx);
}
_ => {
bug!(
"Field projection applied to a type other than Adt or Tuple: {:?}.",
place.ty_before_projection(i).kind()
)
}
},
proj => bug!("{:?} unexpected because it isn't captured", proj),
}
}

curr_string.to_string()
}

/// Part of `MinCaptureInformationMap`; describes the capture kind (&, &mut, move)
/// for a particular capture as well as identifying the part of the source code
/// that triggered this capture to occur.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let did = did.expect_local();
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);

if let Some((span, name)) =
if let Some((span, hir_place)) =
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
{
diag.span_note(
*span,
&format!(
"closure cannot be invoked more than once because it moves the \
variable `{}` out of its environment",
name,
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
),
);
return;
Expand All @@ -127,15 +127,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let did = did.expect_local();
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);

if let Some((span, name)) =
if let Some((span, hir_place)) =
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
{
diag.span_note(
*span,
&format!(
"closure cannot be moved more than once as it is not `Copy` due to \
moving the variable `{}` out of its environment",
name
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
),
);
}
Expand Down
28 changes: 12 additions & 16 deletions compiler/rustc_mir/src/borrow_check/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
user_provided_sig = None;
} else {
let typeck_results = self.tcx().typeck(mir_def_id);
user_provided_sig = match typeck_results.user_provided_sigs.get(&mir_def_id.to_def_id())
{
None => None,
Some(user_provided_poly_sig) => {
user_provided_sig = typeck_results.user_provided_sigs.get(&mir_def_id.to_def_id()).map(
|user_provided_poly_sig| {
// Instantiate the canonicalized variables from
// user-provided signature (e.g., the `_` in the code
// above) with fresh variables.
Expand All @@ -54,18 +52,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Replace the bound items in the fn sig with fresh
// variables, so that they represent the view from
// "inside" the closure.
Some(
self.infcx
.replace_bound_vars_with_fresh_vars(
body.span,
LateBoundRegionConversionTime::FnCall,
poly_sig,
)
.0,
)
}
}
};
self.infcx
.replace_bound_vars_with_fresh_vars(
body.span,
LateBoundRegionConversionTime::FnCall,
poly_sig,
)
.0
},
);
}

debug!(
"equate_inputs_and_outputs: normalized_input_tys = {:?}, local_decls = {:?}",
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir/src/borrow_check/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,13 @@ fn for_each_late_bound_region_defined_on<'tcx>(
fn_def_id: DefId,
mut f: impl FnMut(ty::Region<'tcx>),
) {
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
for late_bound in late_bounds.iter() {
let hir_id = HirId { owner: fn_def_id.expect_local(), local_id: *late_bound };
if let Some((owner, late_bounds)) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
for &late_bound in late_bounds.iter() {
let hir_id = HirId { owner, local_id: late_bound };
let name = tcx.hir().name(hir_id);
let region_def_id = tcx.hir().local_def_id(hir_id);
let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion {
scope: fn_def_id,
scope: owner.to_def_id(),
bound_region: ty::BoundRegionKind::BrNamed(region_def_id.to_def_id(), name),
}));
f(liberated_region);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ fn find_skips_from_snippet(

fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
let mut eat_ws = false;
let mut s = snippet.chars().enumerate().peekable();
let mut s = snippet.char_indices().peekable();
let mut skips = vec![];
while let Some((pos, c)) = s.next() {
match (c, s.peek()) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a> Resolver<'a> {
self.get_module(parent_id)
}

crate fn get_module(&mut self, def_id: DefId) -> Module<'a> {
pub fn get_module(&mut self, def_id: DefId) -> Module<'a> {
// If this is a local module, it will be in `module_map`, no need to recalculate it.
if let Some(def_id) = def_id.as_local() {
return self.module_map[&def_id];
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl<'a> Resolver<'a> {
));
}
Scope::BuiltinAttrs => {
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin);
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin(kw::Empty));
if filter_fn(res) {
suggestions.extend(
BUILTIN_ATTRIBUTES
Expand Down
Loading