Skip to content

Rollup of 19 pull requests #82153

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

Merged
merged 45 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c2e849c
added a suggestion to create a `const` item if the `fn` in the array …
henryboisdequin Jan 29, 2021
bfd1ccf
Seal the CommandExt, OsStrExt and OsStringExt traits
Amanieu Feb 10, 2021
5fe8490
Add match pattern diagnostics regression test
vandenheuvel Feb 8, 2021
dd9db23
Fix typos in BTreeSet::{first, last} docs
taiki-e Feb 13, 2021
d6dcb3d
CTFE validation: catch ReadPointerAsBytes and better error
RalfJung Feb 13, 2021
a3e0795
Heat up the ICE-y error reporting
BoxyUwU Feb 13, 2021
ee9709f
Fixed minor typo in catch_unwind docs
Feb 13, 2021
68405fd
debug!("paramenv={}paramenv={}paramenv={}paramenv={}")
BoxyUwU Feb 13, 2021
b6144e7
yeet ya fixme into the void
BoxyUwU Feb 13, 2021
a419e11
a wild test has appeared uwu
BoxyUwU Feb 13, 2021
1c3841e
Edit `rustc_arena::DropArena` docs
pierwill Feb 13, 2021
64fe2c1
update message
henryboisdequin Feb 14, 2021
7bd7126
param_env debugs are instrumental to rustc's success
BoxyUwU Feb 14, 2021
ba72bc9
fix typo
TaKO8Ki Feb 14, 2021
c583860
Remove unnecessary `Option` in `default_doc`
jyn514 Feb 14, 2021
0038eae
rustc_span: Remove obsolete `allow_internal_unstable_backcompat_hack`
petrochenkov Feb 14, 2021
18c94b3
expand: Remove obsolete `ExpansionConfig::keep_macs`
petrochenkov Feb 14, 2021
6e11a8b
expand: Remove redundant calls to configure
petrochenkov Feb 14, 2021
dee5424
Add missing env!-decl variant
lukaslueg Feb 14, 2021
1aa9651
Fix typo in link to CreateSymbolicLinkW documentation.
m-ou-se Feb 14, 2021
3d7fcff
Update library/core/src/macros/mod.rs
lukaslueg Feb 14, 2021
4613b37
Stabilize Arguments::as_str
sfackler Feb 14, 2021
63806cc
Remove redundant bool_to_option feature gate
est31 Feb 15, 2021
ec77574
Update link for extern prelude.
ehuss Feb 15, 2021
fd21eb1
32-bit ARM: Emit `lr` instead of `r14` when specified as an `asm!` ou…
jrvanwhy Feb 15, 2021
6931027
:arrow_up: rust-analyzer
lnicola Feb 15, 2021
f02f7b0
Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=…
jonas-schievink Feb 15, 2021
cd27820
Rollup merge of #81897 - vandenheuvel:match_exhaustive_diagnostics_re…
jonas-schievink Feb 15, 2021
bd0e8a5
Rollup merge of #81975 - Amanieu:seal2, r=m-ou-se
jonas-schievink Feb 15, 2021
6fde3c5
Rollup merge of #82009 - BoxyUwU:idontknooow, r=varkor
jonas-schievink Feb 15, 2021
c7ebc59
Rollup merge of #82060 - taiki-e:typo, r=m-ou-se
jonas-schievink Feb 15, 2021
5e8435a
Rollup merge of #82061 - RalfJung:ctfe-read-pointer-as-bytes, r=oli-obk
jonas-schievink Feb 15, 2021
7842b5d
Rollup merge of #82063 - NULLx76:fix-minor-typo, r=jonas-schievink
jonas-schievink Feb 15, 2021
665bf9e
Rollup merge of #82067 - BoxyUwU:hahaicantthinkofabadpun, r=oli-obk
jonas-schievink Feb 15, 2021
493c6c9
Rollup merge of #82077 - pierwill:edit-droparena, r=lcnr
jonas-schievink Feb 15, 2021
db5ae6a
Rollup merge of #82096 - TaKO8Ki:fix-typo, r=GuillaumeGomez
jonas-schievink Feb 15, 2021
40d85a5
Rollup merge of #82106 - jyn514:cleanup-bootstrap, r=Mark-Simulacrum
jonas-schievink Feb 15, 2021
285ea2f
Rollup merge of #82107 - petrochenkov:minexpclean, r=Aaron1011
jonas-schievink Feb 15, 2021
b0bd056
Rollup merge of #82118 - lukaslueg:env_decl, r=m-ou-se
jonas-schievink Feb 15, 2021
2030a54
Rollup merge of #82119 - m-ou-se:typo, r=dtolnay
jonas-schievink Feb 15, 2021
c87ef21
Rollup merge of #82120 - sfackler:arguments-as-str, r=dtolnay
jonas-schievink Feb 15, 2021
1c75dfb
Rollup merge of #82129 - est31:master, r=jyn514
jonas-schievink Feb 15, 2021
1ee4a7b
Rollup merge of #82133 - ehuss:extern-prelude-link, r=jyn514
jonas-schievink Feb 15, 2021
1a2675f
Rollup merge of #82141 - jrvanwhy:issue-82052, r=sanxiyn
jonas-schievink Feb 15, 2021
a105280
Rollup merge of #82147 - lnicola:rust-analyzer-2021-02-15, r=jonas-sc…
jonas-schievink Feb 15, 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
15 changes: 9 additions & 6 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,13 @@ impl Drop for DropType {
}

/// An arena which can be used to allocate any type.
///
/// # Safety
///
/// Allocating in this arena is unsafe since the type system
/// doesn't know which types it contains. In order to
/// allocate safely, you must store a PhantomData<T>
/// alongside this arena for each type T you allocate.
/// allocate safely, you must store a `PhantomData<T>`
/// alongside this arena for each type `T` you allocate.
#[derive(Default)]
pub struct DropArena {
/// A list of destructors to run when the arena drops.
Expand All @@ -589,7 +592,7 @@ impl DropArena {
ptr::write(mem, object);
let result = &mut *mem;
// Record the destructor after doing the allocation as that may panic
// and would cause `object`'s destructor to run twice if it was recorded before
// and would cause `object`'s destructor to run twice if it was recorded before.
self.destructors
.borrow_mut()
.push(DropType { drop_fn: drop_for_type::<T>, obj: result as *mut T as *mut u8 });
Expand All @@ -607,16 +610,16 @@ impl DropArena {
let start_ptr = self.arena.alloc_raw(Layout::array::<T>(len).unwrap()) as *mut T;

let mut destructors = self.destructors.borrow_mut();
// Reserve space for the destructors so we can't panic while adding them
// Reserve space for the destructors so we can't panic while adding them.
destructors.reserve(len);

// Move the content to the arena by copying it and then forgetting
// the content of the SmallVec
// the content of the SmallVec.
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
mem::forget(vec.drain(..));

// Record the destructors after doing the allocation as that may panic
// and would cause `object`'s destructor to run twice if it was recorded before
// and would cause `object`'s destructor to run twice if it was recorded before.
for i in 0..len {
destructors
.push(DropType { drop_fn: drop_for_type::<T>, obj: start_ptr.add(i) as *mut u8 });
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>)
} else if reg == InlineAsmReg::AArch64(AArch64InlineAsmReg::x30) {
// LLVM doesn't recognize x30
"{lr}".to_string()
} else if reg == InlineAsmReg::Arm(ArmInlineAsmReg::r14) {
// LLVM doesn't recognize r14
"{lr}".to_string()
} else {
format!("{{{}}}", reg.name())
}
Expand Down
30 changes: 5 additions & 25 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
self.cfg.configure_expr(expr);
visit_clobber(expr.deref_mut(), |mut expr| {
self.cfg.configure_expr_kind(&mut expr.kind);

if let Some(attr) = self.take_first_attr(&mut expr) {
// Collect the invoc regardless of whether or not attributes are permitted here
// expansion will eat the attribute so it won't error later.
Expand Down Expand Up @@ -1166,8 +1164,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
let expr = configure!(self, expr);
expr.filter_map(|mut expr| {
self.cfg.configure_expr_kind(&mut expr.kind);

if let Some(attr) = self.take_first_attr(&mut expr) {
self.cfg.maybe_emit_expr_attr_err(&attr.0);

Expand All @@ -1192,7 +1188,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}

fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
self.cfg.configure_pat(pat);
match pat.kind {
PatKind::MacCall(_) => {}
_ => return noop_visit_pat(pat, self),
Expand Down Expand Up @@ -1406,15 +1401,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
});
}

fn visit_foreign_mod(&mut self, foreign_mod: &mut ast::ForeignMod) {
self.cfg.configure_foreign_mod(foreign_mod);
noop_visit_foreign_mod(foreign_mod, self);
}

fn flat_map_foreign_item(
&mut self,
mut foreign_item: P<ast::ForeignItem>,
foreign_item: P<ast::ForeignItem>,
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
let mut foreign_item = configure!(self, foreign_item);

if let Some(attr) = self.take_first_attr(&mut foreign_item) {
return self
.collect_attr(
Expand All @@ -1439,11 +1431,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}
}

fn visit_item_kind(&mut self, item: &mut ast::ItemKind) {
self.cfg.configure_item_kind(item);
noop_visit_item_kind(item, self);
}

fn flat_map_generic_param(
&mut self,
param: ast::GenericParam,
Expand Down Expand Up @@ -1602,21 +1589,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
*id = self.cx.resolver.next_node_id()
}
}

fn visit_fn_decl(&mut self, mut fn_decl: &mut P<ast::FnDecl>) {
self.cfg.configure_fn_decl(&mut fn_decl);
noop_visit_fn_decl(fn_decl, self);
}
}

pub struct ExpansionConfig<'feat> {
pub crate_name: String,
pub features: Option<&'feat Features>,
pub recursion_limit: Limit,
pub trace_mac: bool,
pub should_test: bool, // If false, strip `#[test]` nodes
pub keep_macs: bool,
pub span_debug: bool, // If true, use verbose debugging for `proc_macro::Span`
pub should_test: bool, // If false, strip `#[test]` nodes
pub span_debug: bool, // If true, use verbose debugging for `proc_macro::Span`
pub proc_macro_backtrace: bool, // If true, show backtraces for proc-macro panics
}

Expand All @@ -1628,7 +1609,6 @@ impl<'feat> ExpansionConfig<'feat> {
recursion_limit: Limit::new(1024),
trace_mac: false,
should_test: false,
keep_macs: false,
span_debug: false,
proc_macro_backtrace: false,
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(or_patterns)]
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_expand/src/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,4 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
}
}
}

fn visit_mod(&mut self, module: &mut ast::Mod) {
noop_visit_mod(module, self);
// remove macro definitions
module.items.retain(
|item| !matches!(item.kind, ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs),
);
}
}
4 changes: 4 additions & 0 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ struct QueryTypeRelatingDelegate<'a, 'tcx> {
}

impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}

fn create_next_universe(&mut self) -> ty::UniverseIndex {
self.infcx.create_next_universe()
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
/// As `3 + 4` contains `N` in its substs, this must not succeed.
///
/// See `src/test/ui/const-generics/occurs-check/` for more examples where this is relevant.
#[instrument(level = "debug", skip(self))]
fn unify_const_variable(
&self,
param_env: ty::ParamEnv<'tcx>,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ where
}

pub trait TypeRelatingDelegate<'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx>;

/// Push a constraint `sup: sub` -- this constraint must be
/// satisfied for the two types to be related. `sub` and `sup` may
/// be regions from the type or new variables created through the
Expand Down Expand Up @@ -473,9 +475,8 @@ where
self.infcx.tcx
}

// FIXME(oli-obk): not sure how to get the correct ParamEnv
fn param_env(&self) -> ty::ParamEnv<'tcx> {
ty::ParamEnv::empty()
self.delegate.param_env()
}

fn tag(&self) -> &'static str {
Expand Down Expand Up @@ -819,9 +820,8 @@ where
self.infcx.tcx
}

// FIXME(oli-obk): not sure how to get the correct ParamEnv
fn param_env(&self) -> ty::ParamEnv<'tcx> {
ty::ParamEnv::empty()
self.delegate.param_env()
}

fn tag(&self) -> &'static str {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/mir/interpret/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// constant `bar::<T>()` requires a substitution for `T`, if the substitution for `T` is still
/// too generic for the constant to be evaluated then `Err(ErrorHandled::TooGeneric)` is
/// returned.
#[instrument(level = "debug", skip(self))]
pub fn const_eval_resolve(
self,
param_env: ty::ParamEnv<'tcx>,
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ pub enum ObligationCauseCode<'tcx> {
/// Inline asm operand type must be `Sized`.
InlineAsmSized,
/// `[T, ..n]` implies that `T` must be `Copy`.
RepeatVec,
/// If the function in the array repeat expression is a `const fn`,
/// display a help message suggesting to move the function call to a
/// new `const` item while saying that `T` doesn't implement `Copy`.
RepeatVec(bool),

/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
FieldSized {
Expand Down
13 changes: 9 additions & 4 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,17 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
ty::Array(t, n) => {
if t.is_simple_ty() {
return format!("array `{}`", self).into();
}

let n = tcx.lift(n).unwrap();
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
_ if t.is_simple_ty() => format!("array `{}`", self).into(),
Some(n) => format!("array of {} element{}", n, pluralize!(n)).into(),
None => "array".into(),
if let ty::ConstKind::Value(v) = n.val {
if let Some(n) = v.try_to_machine_usize(tcx) {
return format!("array of {} element{}", n, pluralize!(n)).into();
}
}
"array".into()
}
ty::Slice(ty) if ty.is_simple_ty() => format!("slice `{}`", self).into(),
ty::Slice(_) => "slice".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ impl<'tcx> Instance<'tcx> {
}

// This should be kept up to date with `resolve`.
#[instrument(level = "debug", skip(tcx))]
pub fn resolve_opt_const_arg(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations}
use crate::dataflow::impls::MaybeInitializedPlaces;
use crate::dataflow::move_paths::MoveData;
use crate::dataflow::ResultsCursor;
use crate::transform::{
check_consts::ConstCx, promote_consts::is_const_fn_in_array_repeat_expression,
};

use crate::borrow_check::{
borrow_set::BorrowSet,
Expand Down Expand Up @@ -1098,6 +1101,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
) -> Fallible<()> {
relate_tys::relate_types(
self.infcx,
self.param_env,
a,
v,
b,
Expand Down Expand Up @@ -1988,18 +1992,24 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Operand::Copy(..) | Operand::Constant(..) => {
// These are always okay: direct use of a const, or a value that can evidently be copied.
}
Operand::Move(_) => {
Operand::Move(place) => {
// Make sure that repeated elements implement `Copy`.
let span = body.source_info(location).span;
let ty = operand.ty(body, tcx);
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
let ccx = ConstCx::new_with_param_env(tcx, body, self.param_env);
let is_const_fn =
is_const_fn_in_array_repeat_expression(&ccx, &place, &body);

debug!("check_rvalue: is_const_fn={:?}", is_const_fn);

let def_id = body.source.def_id().expect_local();
self.infcx.report_selection_error(
&traits::Obligation::new(
ObligationCause::new(
span,
self.tcx().hir().local_def_id_to_hir_id(def_id),
traits::ObligationCauseCode::RepeatVec,
traits::ObligationCauseCode::RepeatVec(is_const_fn),
),
self.param_env,
ty::Binder::bind(ty::TraitRef::new(
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::borrow_check::type_check::{BorrowCheckContext, Locations};
/// variables, but not the type `b`.
pub(super) fn relate_types<'tcx>(
infcx: &InferCtxt<'_, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
a: Ty<'tcx>,
v: ty::Variance,
b: Ty<'tcx>,
Expand All @@ -28,7 +29,7 @@ pub(super) fn relate_types<'tcx>(
debug!("relate_types(a={:?}, v={:?}, b={:?}, locations={:?})", a, v, b, locations);
TypeRelating::new(
infcx,
NllTypeRelatingDelegate::new(infcx, borrowck_context, locations, category),
NllTypeRelatingDelegate::new(infcx, borrowck_context, param_env, locations, category),
v,
)
.relate(a, b)?;
Expand All @@ -39,6 +40,8 @@ struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
infcx: &'me InferCtxt<'me, 'tcx>,
borrowck_context: Option<&'me mut BorrowCheckContext<'bccx, 'tcx>>,

param_env: ty::ParamEnv<'tcx>,

/// Where (and why) is this relation taking place?
locations: Locations,

Expand All @@ -50,14 +53,19 @@ impl NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
fn new(
infcx: &'me InferCtxt<'me, 'tcx>,
borrowck_context: Option<&'me mut BorrowCheckContext<'bccx, 'tcx>>,
param_env: ty::ParamEnv<'tcx>,
locations: Locations,
category: ConstraintCategory,
) -> Self {
Self { infcx, borrowck_context, locations, category }
Self { infcx, borrowck_context, param_env, locations, category }
}
}

impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}

fn create_next_universe(&mut self) -> ty::UniverseIndex {
self.infcx.create_next_universe()
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
tcx: TyCtxt<'tcx>,
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
// see comment in const_eval_raw_provider for what we're doing here
// see comment in eval_to_allocation_raw_provider for what we're doing here
if key.param_env.reveal() == Reveal::All {
let mut key = key;
key.param_env = key.param_env.with_user_facing();
Expand Down
Loading