Skip to content

Commit 0c1748c

Browse files
committed
Auto merge of #158124 - JonathanBrouwer:rollup-UKcnc05, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - #157878 (`impl [const] Default for BTreeMap`) - #158040 (Codegen ctors in Runtime mir phase) - #141266 (Stabilize `substr_range` and `subslice_range`) - #158109 (Change `EarlyCheckNode` from a trait to an enum.) - #158118 (Convert '.' to '_' in bootstrap envify)
2 parents 8e15021 + 4c7560c commit 0c1748c

14 files changed

Lines changed: 69 additions & 47 deletions

File tree

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ pub struct InferCtxt<'tcx> {
251251
/// Whether this inference context should care about region obligations in
252252
/// the root universe. Most notably, this is used during HIR typeck as region
253253
/// solving is left to borrowck instead.
254+
///
255+
/// This is used in the old solver to enable the generation of regions constraints.
256+
/// In the new solver its only used inside the InferCtxt's `Drop` implementation:
257+
/// if we're considering regions, and new opaques are registered, we panic.
254258
pub considering_regions: bool,
255259
/// `-Znext-solver`: Whether this inference context is used by HIR typeck. If so, we
256260
/// need to make sure we don't rely on region identity in the trait solver or when

compiler/rustc_interface/src/passes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn pre_expansion_lint<'a>(
8989
features: &Features,
9090
lint_store: &LintStore,
9191
registered_tools: &RegisteredTools,
92-
check_node: impl EarlyCheckNode<'a>,
92+
check_node: EarlyCheckNode<'a>,
9393
node_name: Symbol,
9494
) {
9595
sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", node_name.as_str()).run(
@@ -122,7 +122,8 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
122122
items: &[Box<ast::Item>],
123123
name: Symbol,
124124
) {
125-
pre_expansion_lint(sess, features, self.0, registered_tools, (node_id, attrs, items), name);
125+
let check_node = EarlyCheckNode::LoadedMod(node_id, attrs, items);
126+
pre_expansion_lint(sess, features, self.0, registered_tools, check_node, name);
126127
}
127128
}
128129

@@ -141,13 +142,12 @@ fn configure_and_expand(
141142
let features = tcx.features();
142143
let lint_store = unerased_lint_store(sess);
143144
let crate_name = tcx.crate_name(LOCAL_CRATE);
144-
let lint_check_node = (&krate, pre_configured_attrs);
145145
pre_expansion_lint(
146146
sess,
147147
features,
148148
lint_store,
149149
tcx.registered_tools(()),
150-
lint_check_node,
150+
EarlyCheckNode::CrateRoot(&krate, pre_configured_attrs),
151151
crate_name,
152152
);
153153
rustc_builtin_macros::register_builtin_macros(resolver);
@@ -480,7 +480,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
480480
tcx.registered_tools(()),
481481
Some(lint_buffer),
482482
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
483-
(&*krate, &*krate.attrs),
483+
EarlyCheckNode::CrateRoot(&*krate, &*krate.attrs),
484484
)
485485
}
486486

compiler/rustc_lint/src/early.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
2727

2828
/// Implements the AST traversal for early lint passes. `T` provides the
2929
/// `check_*` methods.
30-
pub struct EarlyContextAndPass<'ecx, T: EarlyLintPass> {
30+
struct EarlyContextAndPass<'ecx, T: EarlyLintPass> {
3131
context: EarlyContext<'ecx>,
3232
pass: T,
3333
}
@@ -276,36 +276,36 @@ crate::early_lint_methods!(impl_early_lint_pass, []);
276276

277277
/// Early lints work on different nodes - either on the crate root, or on freshly loaded modules.
278278
/// This trait generalizes over those nodes.
279-
pub trait EarlyCheckNode<'a>: Copy {
280-
fn id(self) -> ast::NodeId;
281-
fn attrs(self) -> &'a [ast::Attribute];
282-
fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>);
279+
pub enum EarlyCheckNode<'a> {
280+
CrateRoot(&'a ast::Crate, &'a [ast::Attribute]),
281+
LoadedMod(ast::NodeId, &'a [ast::Attribute], &'a [Box<ast::Item>]),
283282
}
284283

285-
impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) {
286-
fn id(self) -> ast::NodeId {
287-
ast::CRATE_NODE_ID
288-
}
289-
fn attrs(self) -> &'a [ast::Attribute] {
290-
self.1
291-
}
292-
fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) {
293-
lint_callback!(cx, check_crate, self.0);
294-
ast_visit::walk_crate(cx, self.0);
295-
lint_callback!(cx, check_crate_post, self.0);
296-
}
297-
}
298-
299-
impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [Box<ast::Item>]) {
300-
fn id(self) -> ast::NodeId {
301-
self.0
284+
impl<'a> EarlyCheckNode<'a> {
285+
fn id(&self) -> ast::NodeId {
286+
match self {
287+
EarlyCheckNode::CrateRoot(_crate, _attrs) => ast::CRATE_NODE_ID,
288+
EarlyCheckNode::LoadedMod(id, _attrs, _items) => *id,
289+
}
302290
}
303-
fn attrs(self) -> &'a [ast::Attribute] {
304-
self.1
291+
fn attrs(&self) -> &'a [ast::Attribute] {
292+
match self {
293+
EarlyCheckNode::CrateRoot(_crate, attrs) => attrs,
294+
EarlyCheckNode::LoadedMod(_id, attrs, _items) => attrs,
295+
}
305296
}
306-
fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) {
307-
walk_list!(cx, visit_attribute, self.1);
308-
walk_list!(cx, visit_item, self.2);
297+
fn check<'ecx, T: EarlyLintPass>(&self, cx: &mut EarlyContextAndPass<'ecx, T>) {
298+
match self {
299+
EarlyCheckNode::CrateRoot(crate_, _attrs) => {
300+
lint_callback!(cx, check_crate, crate_);
301+
ast_visit::walk_crate(cx, crate_);
302+
lint_callback!(cx, check_crate_post, crate_);
303+
}
304+
EarlyCheckNode::LoadedMod(_id, attrs, items) => {
305+
walk_list!(cx, visit_attribute, *attrs);
306+
walk_list!(cx, visit_item, *items);
307+
}
308+
}
309309
}
310310
}
311311

@@ -317,7 +317,7 @@ pub fn check_ast_node<'a>(
317317
registered_tools: &RegisteredTools,
318318
lint_buffer: Option<LintBuffer>,
319319
builtin_lints: impl EarlyLintPass + 'static,
320-
check_node: impl EarlyCheckNode<'a>,
320+
check_node: EarlyCheckNode<'a>,
321321
) {
322322
let context = EarlyContext::new(
323323
sess,
@@ -345,7 +345,7 @@ pub fn check_ast_node<'a>(
345345

346346
fn check_ast_node_inner<'a, T: EarlyLintPass>(
347347
sess: &Session,
348-
check_node: impl EarlyCheckNode<'a>,
348+
check_node: EarlyCheckNode<'a>,
349349
context: EarlyContext<'_>,
350350
pass: T,
351351
) {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub use self::typeck_results::{
118118
use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
119119
use crate::metadata::{AmbigModChild, ModChild};
120120
use crate::middle::privacy::EffectiveVisibilities;
121-
use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, SourceInfo};
121+
use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, MirPhase, SourceInfo};
122122
use crate::query::{IntoQueryKey, Providers};
123123
use crate::ty;
124124
use crate::ty::codec::{TyDecoder, TyEncoder};
@@ -1777,7 +1777,7 @@ impl<'tcx> TyCtxt<'tcx> {
17771777
/// Returns the possibly-auto-generated MIR of a [`ty::InstanceKind`].
17781778
#[instrument(skip(self), level = "debug")]
17791779
pub fn instance_mir(self, instance: ty::InstanceKind<'tcx>) -> &'tcx Body<'tcx> {
1780-
match instance {
1780+
let body = match instance {
17811781
ty::InstanceKind::Item(def) => {
17821782
debug!("calling def_kind on def: {:?}", def);
17831783
let def_kind = self.def_kind(def);
@@ -1816,7 +1816,15 @@ impl<'tcx> TyCtxt<'tcx> {
18161816
| ty::InstanceKind::FnPtrAddrShim(..)
18171817
| ty::InstanceKind::AsyncDropGlueCtorShim(..)
18181818
| ty::InstanceKind::AsyncDropGlue(..) => self.mir_shims(instance),
1819-
}
1819+
};
1820+
1821+
assert!(
1822+
matches!(body.phase, MirPhase::Runtime(_)),
1823+
"body: {body:?} instance: {instance:?} {:?}",
1824+
if let ty::InstanceKind::Item(d) = instance { Some(self.def_kind(d)) } else { None },
1825+
);
1826+
1827+
body
18201828
}
18211829

18221830
/// Gets all attributes with the given name.

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,12 @@ pub(super) fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
10741074
// so this would otherwise not get filled).
10751075
body.set_mentioned_items(Vec::new());
10761076

1077-
crate::pass_manager::dump_mir_for_phase_change(tcx, &body);
1077+
pm::run_passes_no_validate(
1078+
tcx,
1079+
&mut body,
1080+
&[],
1081+
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
1082+
);
10781083

10791084
body
10801085
}

compiler/rustc_traits/src/normalize_erasing_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Par
2222
goal: PseudoCanonicalInput<'tcx, T>,
2323
) -> Result<T, NoSolution> {
2424
let PseudoCanonicalInput { typing_env, value } = goal;
25-
let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
25+
let (infcx, param_env) = tcx.infer_ctxt().ignoring_regions().build_with_typing_env(typing_env);
2626
let cause = ObligationCause::dummy();
2727
match infcx.at(&cause, param_env).query_normalize(value) {
2828
Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => {

library/alloc/src/collections/btree/map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,8 @@ impl<K: Hash, V: Hash, A: Allocator + Clone> Hash for BTreeMap<K, V, A> {
25942594
}
25952595

25962596
#[stable(feature = "rust1", since = "1.0.0")]
2597-
impl<K, V> Default for BTreeMap<K, V> {
2597+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
2598+
const impl<K, V> Default for BTreeMap<K, V> {
25982599
/// Creates an empty `BTreeMap`.
25992600
fn default() -> BTreeMap<K, V> {
26002601
BTreeMap::new()

library/alloctests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(const_alloc_error)]
2121
#![feature(const_cmp)]
2222
#![feature(const_convert)]
23+
#![feature(const_default)]
2324
#![feature(const_destruct)]
2425
#![feature(const_heap)]
2526
#![feature(const_option_ops)]

library/core/src/slice/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5298,7 +5298,6 @@ impl<T> [T] {
52985298
/// # Examples
52995299
/// Basic usage:
53005300
/// ```
5301-
/// #![feature(substr_range)]
53025301
/// use core::range::Range;
53035302
///
53045303
/// let nums = &[0, 5, 10, 0, 0, 5];
@@ -5313,7 +5312,7 @@ impl<T> [T] {
53135312
/// assert_eq!(iter.next(), Some(Range { start: 5, end: 6 }));
53145313
/// ```
53155314
#[must_use]
5316-
#[unstable(feature = "substr_range", issue = "126769")]
5315+
#[stable(feature = "substr_range", since = "CURRENT_RUSTC_VERSION")]
53175316
pub fn subslice_range(&self, subslice: &[T]) -> Option<core::range::Range<usize>> {
53185317
if T::IS_ZST {
53195318
panic!("elements are zero-sized");

library/core/src/str/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,7 +3193,6 @@ impl str {
31933193
///
31943194
/// # Examples
31953195
/// ```
3196-
/// #![feature(substr_range)]
31973196
/// use core::range::Range;
31983197
///
31993198
/// let data = "a, b, b, a";
@@ -3205,7 +3204,7 @@ impl str {
32053204
/// assert_eq!(iter.next(), Some(Range { start: 9, end: 10 }));
32063205
/// ```
32073206
#[must_use]
3208-
#[unstable(feature = "substr_range", issue = "126769")]
3207+
#[stable(feature = "substr_range", since = "CURRENT_RUSTC_VERSION")]
32093208
pub fn substr_range(&self, substr: &str) -> Option<Range<usize>> {
32103209
self.as_bytes().subslice_range(substr.as_bytes())
32113210
}

0 commit comments

Comments
 (0)