Skip to content

Commit

Permalink
Auto merge of rust-lang#82153 - jonas-schievink:rollup-ls5r943, r=jon…
Browse files Browse the repository at this point in the history
…as-schievink

Rollup of 19 pull requests

Successful merges:

 - rust-lang#81503 (Suggest to create a new `const` item if the `fn` in the array is a `const fn`)
 - rust-lang#81897 (Add match pattern diagnostics regression test)
 - rust-lang#81975 (Seal the CommandExt, OsStrExt and OsStringExt traits)
 - rust-lang#82009 (const_generics: Dont evaluate array length const when handling errors)
 - rust-lang#82060 (Fix typos in BTreeSet::{first, last} docs)
 - rust-lang#82061 (CTFE validation: catch ReadPointerAsBytes and better error)
 - rust-lang#82063 (Fixed minor typo in catch_unwind docs)
 - rust-lang#82067 (const_generics: Fix incorrect ty::ParamEnv::empty() usage)
 - rust-lang#82077 (Edit `rustc_arena::DropArena` docs)
 - rust-lang#82096 (Fix a typo)
 - rust-lang#82106 (Remove unnecessary `Option` in `default_doc`)
 - rust-lang#82107 (expand: Some cleanup)
 - rust-lang#82118 (Add missing env!-decl variant)
 - rust-lang#82119 (Fix typo in link to CreateSymbolicLinkW documentation.)
 - rust-lang#82120 (Stabilize Arguments::as_str)
 - rust-lang#82129 (Remove redundant bool_to_option feature gate)
 - rust-lang#82133 (Update link for extern prelude.)
 - rust-lang#82141 (32-bit ARM: Emit `lr` instead of `r14` when specified as an `asm!` output register.)
 - rust-lang#82147 (:arrow_up: rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 16, 2021
2 parents d1206f9 + a105280 commit 42a4673
Show file tree
Hide file tree
Showing 50 changed files with 350 additions and 135 deletions.
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

0 comments on commit 42a4673

Please sign in to comment.