Skip to content

Commit 42a4673

Browse files
committed
Auto merge of rust-lang#82153 - jonas-schievink:rollup-ls5r943, r=jonas-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
2 parents d1206f9 + a105280 commit 42a4673

File tree

50 files changed

+350
-135
lines changed

Some content is hidden

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

50 files changed

+350
-135
lines changed

compiler/rustc_arena/src/lib.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,13 @@ impl Drop for DropType {
568568
}
569569

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

609612
let mut destructors = self.destructors.borrow_mut();
610-
// Reserve space for the destructors so we can't panic while adding them
613+
// Reserve space for the destructors so we can't panic while adding them.
611614
destructors.reserve(len);
612615

613616
// Move the content to the arena by copying it and then forgetting
614-
// the content of the SmallVec
617+
// the content of the SmallVec.
615618
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
616619
mem::forget(vec.drain(..));
617620

618621
// Record the destructors after doing the allocation as that may panic
619-
// and would cause `object`'s destructor to run twice if it was recorded before
622+
// and would cause `object`'s destructor to run twice if it was recorded before.
620623
for i in 0..len {
621624
destructors
622625
.push(DropType { drop_fn: drop_for_type::<T>, obj: start_ptr.add(i) as *mut u8 });

compiler/rustc_codegen_llvm/src/asm.rs

+3
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>)
487487
} else if reg == InlineAsmReg::AArch64(AArch64InlineAsmReg::x30) {
488488
// LLVM doesn't recognize x30
489489
"{lr}".to_string()
490+
} else if reg == InlineAsmReg::Arm(ArmInlineAsmReg::r14) {
491+
// LLVM doesn't recognize r14
492+
"{lr}".to_string()
490493
} else {
491494
format!("{{{}}}", reg.name())
492495
}

compiler/rustc_expand/src/expand.rs

+5-25
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
10671067
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
10681068
self.cfg.configure_expr(expr);
10691069
visit_clobber(expr.deref_mut(), |mut expr| {
1070-
self.cfg.configure_expr_kind(&mut expr.kind);
1071-
10721070
if let Some(attr) = self.take_first_attr(&mut expr) {
10731071
// Collect the invoc regardless of whether or not attributes are permitted here
10741072
// expansion will eat the attribute so it won't error later.
@@ -1166,8 +1164,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
11661164
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
11671165
let expr = configure!(self, expr);
11681166
expr.filter_map(|mut expr| {
1169-
self.cfg.configure_expr_kind(&mut expr.kind);
1170-
11711167
if let Some(attr) = self.take_first_attr(&mut expr) {
11721168
self.cfg.maybe_emit_expr_attr_err(&attr.0);
11731169

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

11941190
fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
1195-
self.cfg.configure_pat(pat);
11961191
match pat.kind {
11971192
PatKind::MacCall(_) => {}
11981193
_ => return noop_visit_pat(pat, self),
@@ -1406,15 +1401,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
14061401
});
14071402
}
14081403

1409-
fn visit_foreign_mod(&mut self, foreign_mod: &mut ast::ForeignMod) {
1410-
self.cfg.configure_foreign_mod(foreign_mod);
1411-
noop_visit_foreign_mod(foreign_mod, self);
1412-
}
1413-
14141404
fn flat_map_foreign_item(
14151405
&mut self,
1416-
mut foreign_item: P<ast::ForeignItem>,
1406+
foreign_item: P<ast::ForeignItem>,
14171407
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
1408+
let mut foreign_item = configure!(self, foreign_item);
1409+
14181410
if let Some(attr) = self.take_first_attr(&mut foreign_item) {
14191411
return self
14201412
.collect_attr(
@@ -1439,11 +1431,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
14391431
}
14401432
}
14411433

1442-
fn visit_item_kind(&mut self, item: &mut ast::ItemKind) {
1443-
self.cfg.configure_item_kind(item);
1444-
noop_visit_item_kind(item, self);
1445-
}
1446-
14471434
fn flat_map_generic_param(
14481435
&mut self,
14491436
param: ast::GenericParam,
@@ -1602,21 +1589,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
16021589
*id = self.cx.resolver.next_node_id()
16031590
}
16041591
}
1605-
1606-
fn visit_fn_decl(&mut self, mut fn_decl: &mut P<ast::FnDecl>) {
1607-
self.cfg.configure_fn_decl(&mut fn_decl);
1608-
noop_visit_fn_decl(fn_decl, self);
1609-
}
16101592
}
16111593

16121594
pub struct ExpansionConfig<'feat> {
16131595
pub crate_name: String,
16141596
pub features: Option<&'feat Features>,
16151597
pub recursion_limit: Limit,
16161598
pub trace_mac: bool,
1617-
pub should_test: bool, // If false, strip `#[test]` nodes
1618-
pub keep_macs: bool,
1619-
pub span_debug: bool, // If true, use verbose debugging for `proc_macro::Span`
1599+
pub should_test: bool, // If false, strip `#[test]` nodes
1600+
pub span_debug: bool, // If true, use verbose debugging for `proc_macro::Span`
16201601
pub proc_macro_backtrace: bool, // If true, show backtraces for proc-macro panics
16211602
}
16221603

@@ -1628,7 +1609,6 @@ impl<'feat> ExpansionConfig<'feat> {
16281609
recursion_limit: Limit::new(1024),
16291610
trace_mac: false,
16301611
should_test: false,
1631-
keep_macs: false,
16321612
span_debug: false,
16331613
proc_macro_backtrace: false,
16341614
}

compiler/rustc_expand/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(bool_to_option)]
21
#![feature(crate_visibility_modifier)]
32
#![feature(decl_macro)]
43
#![feature(or_patterns)]

compiler/rustc_expand/src/placeholders.rs

-8
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,4 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
371371
}
372372
}
373373
}
374-
375-
fn visit_mod(&mut self, module: &mut ast::Mod) {
376-
noop_visit_mod(module, self);
377-
// remove macro definitions
378-
module.items.retain(
379-
|item| !matches!(item.kind, ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs),
380-
);
381-
}
382374
}

compiler/rustc_infer/src/infer/canonical/query_response.rs

+4
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,10 @@ struct QueryTypeRelatingDelegate<'a, 'tcx> {
639639
}
640640

641641
impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
642+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
643+
self.param_env
644+
}
645+
642646
fn create_next_universe(&mut self) -> ty::UniverseIndex {
643647
self.infcx.create_next_universe()
644648
}

compiler/rustc_infer/src/infer/combine.rs

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
221221
/// As `3 + 4` contains `N` in its substs, this must not succeed.
222222
///
223223
/// See `src/test/ui/const-generics/occurs-check/` for more examples where this is relevant.
224+
#[instrument(level = "debug", skip(self))]
224225
fn unify_const_variable(
225226
&self,
226227
param_env: ty::ParamEnv<'tcx>,

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ where
7272
}
7373

7474
pub trait TypeRelatingDelegate<'tcx> {
75+
fn param_env(&self) -> ty::ParamEnv<'tcx>;
76+
7577
/// Push a constraint `sup: sub` -- this constraint must be
7678
/// satisfied for the two types to be related. `sub` and `sup` may
7779
/// be regions from the type or new variables created through the
@@ -473,9 +475,8 @@ where
473475
self.infcx.tcx
474476
}
475477

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

481482
fn tag(&self) -> &'static str {
@@ -819,9 +820,8 @@ where
819820
self.infcx.tcx
820821
}
821822

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

827827
fn tag(&self) -> &'static str {

compiler/rustc_middle/src/mir/interpret/queries.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl<'tcx> TyCtxt<'tcx> {
3131
/// constant `bar::<T>()` requires a substitution for `T`, if the substitution for `T` is still
3232
/// too generic for the constant to be evaluated then `Err(ErrorHandled::TooGeneric)` is
3333
/// returned.
34+
#[instrument(level = "debug", skip(self))]
3435
pub fn const_eval_resolve(
3536
self,
3637
param_env: ty::ParamEnv<'tcx>,

compiler/rustc_middle/src/traits/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ pub enum ObligationCauseCode<'tcx> {
228228
/// Inline asm operand type must be `Sized`.
229229
InlineAsmSized,
230230
/// `[T, ..n]` implies that `T` must be `Copy`.
231-
RepeatVec,
231+
/// If the function in the array repeat expression is a `const fn`,
232+
/// display a help message suggesting to move the function call to a
233+
/// new `const` item while saying that `T` doesn't implement `Copy`.
234+
RepeatVec(bool),
232235

233236
/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
234237
FieldSized {

compiler/rustc_middle/src/ty/error.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,17 @@ impl<'tcx> ty::TyS<'tcx> {
228228
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
229229
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
230230
ty::Array(t, n) => {
231+
if t.is_simple_ty() {
232+
return format!("array `{}`", self).into();
233+
}
234+
231235
let n = tcx.lift(n).unwrap();
232-
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
233-
_ if t.is_simple_ty() => format!("array `{}`", self).into(),
234-
Some(n) => format!("array of {} element{}", n, pluralize!(n)).into(),
235-
None => "array".into(),
236+
if let ty::ConstKind::Value(v) = n.val {
237+
if let Some(n) = v.try_to_machine_usize(tcx) {
238+
return format!("array of {} element{}", n, pluralize!(n)).into();
239+
}
236240
}
241+
"array".into()
237242
}
238243
ty::Slice(ty) if ty.is_simple_ty() => format!("slice `{}`", self).into(),
239244
ty::Slice(_) => "slice".into(),

compiler/rustc_middle/src/ty/instance.rs

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ impl<'tcx> Instance<'tcx> {
347347
}
348348

349349
// This should be kept up to date with `resolve`.
350+
#[instrument(level = "debug", skip(tcx))]
350351
pub fn resolve_opt_const_arg(
351352
tcx: TyCtxt<'tcx>,
352353
param_env: ty::ParamEnv<'tcx>,

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations}
4343
use crate::dataflow::impls::MaybeInitializedPlaces;
4444
use crate::dataflow::move_paths::MoveData;
4545
use crate::dataflow::ResultsCursor;
46+
use crate::transform::{
47+
check_consts::ConstCx, promote_consts::is_const_fn_in_array_repeat_expression,
48+
};
4649

4750
use crate::borrow_check::{
4851
borrow_set::BorrowSet,
@@ -1098,6 +1101,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10981101
) -> Fallible<()> {
10991102
relate_tys::relate_types(
11001103
self.infcx,
1104+
self.param_env,
11011105
a,
11021106
v,
11031107
b,
@@ -1988,18 +1992,24 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19881992
Operand::Copy(..) | Operand::Constant(..) => {
19891993
// These are always okay: direct use of a const, or a value that can evidently be copied.
19901994
}
1991-
Operand::Move(_) => {
1995+
Operand::Move(place) => {
19921996
// Make sure that repeated elements implement `Copy`.
19931997
let span = body.source_info(location).span;
19941998
let ty = operand.ty(body, tcx);
19951999
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
2000+
let ccx = ConstCx::new_with_param_env(tcx, body, self.param_env);
2001+
let is_const_fn =
2002+
is_const_fn_in_array_repeat_expression(&ccx, &place, &body);
2003+
2004+
debug!("check_rvalue: is_const_fn={:?}", is_const_fn);
2005+
19962006
let def_id = body.source.def_id().expect_local();
19972007
self.infcx.report_selection_error(
19982008
&traits::Obligation::new(
19992009
ObligationCause::new(
20002010
span,
20012011
self.tcx().hir().local_def_id_to_hir_id(def_id),
2002-
traits::ObligationCauseCode::RepeatVec,
2012+
traits::ObligationCauseCode::RepeatVec(is_const_fn),
20032013
),
20042014
self.param_env,
20052015
ty::Binder::bind(ty::TraitRef::new(

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::borrow_check::type_check::{BorrowCheckContext, Locations};
1818
/// variables, but not the type `b`.
1919
pub(super) fn relate_types<'tcx>(
2020
infcx: &InferCtxt<'_, 'tcx>,
21+
param_env: ty::ParamEnv<'tcx>,
2122
a: Ty<'tcx>,
2223
v: ty::Variance,
2324
b: Ty<'tcx>,
@@ -28,7 +29,7 @@ pub(super) fn relate_types<'tcx>(
2829
debug!("relate_types(a={:?}, v={:?}, b={:?}, locations={:?})", a, v, b, locations);
2930
TypeRelating::new(
3031
infcx,
31-
NllTypeRelatingDelegate::new(infcx, borrowck_context, locations, category),
32+
NllTypeRelatingDelegate::new(infcx, borrowck_context, param_env, locations, category),
3233
v,
3334
)
3435
.relate(a, b)?;
@@ -39,6 +40,8 @@ struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
3940
infcx: &'me InferCtxt<'me, 'tcx>,
4041
borrowck_context: Option<&'me mut BorrowCheckContext<'bccx, 'tcx>>,
4142

43+
param_env: ty::ParamEnv<'tcx>,
44+
4245
/// Where (and why) is this relation taking place?
4346
locations: Locations,
4447

@@ -50,14 +53,19 @@ impl NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
5053
fn new(
5154
infcx: &'me InferCtxt<'me, 'tcx>,
5255
borrowck_context: Option<&'me mut BorrowCheckContext<'bccx, 'tcx>>,
56+
param_env: ty::ParamEnv<'tcx>,
5357
locations: Locations,
5458
category: ConstraintCategory,
5559
) -> Self {
56-
Self { infcx, borrowck_context, locations, category }
60+
Self { infcx, borrowck_context, param_env, locations, category }
5761
}
5862
}
5963

6064
impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
65+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
66+
self.param_env
67+
}
68+
6169
fn create_next_universe(&mut self) -> ty::UniverseIndex {
6270
self.infcx.create_next_universe()
6371
}

compiler/rustc_mir/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
208208
tcx: TyCtxt<'tcx>,
209209
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
210210
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
211-
// see comment in const_eval_raw_provider for what we're doing here
211+
// see comment in eval_to_allocation_raw_provider for what we're doing here
212212
if key.param_env.reveal() == Reveal::All {
213213
let mut key = key;
214214
key.param_env = key.param_env.with_user_facing();

0 commit comments

Comments
 (0)