Skip to content

Commit f392479

Browse files
committed
Auto merge of #78350 - JohnTitor:rollup-vbbm5wf, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #77984 (Compute proper module parent during resolution) - #78085 (MIR validation should check `SwitchInt` values are valid for the type) - #78208 (replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s) - #78209 (Update `compiler_builtins` to 0.1.36) - #78276 (Bump backtrace-rs to enable Mach-O support on iOS.) - #78320 (Link to cargo's `build-std` feature instead of `xargo` in custom target docs) - #78322 (BTreeMap: stop mistaking node::MIN_LEN for a node level constraint) - #78326 (Split out statement attributes changes from #78306) Failed merges: r? `@ghost`
2 parents 5171cc7 + 0a26e4b commit f392479

Some content is hidden

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

58 files changed

+427
-131
lines changed

Diff for: Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,9 @@ dependencies = [
636636

637637
[[package]]
638638
name = "compiler_builtins"
639-
version = "0.1.35"
639+
version = "0.1.36"
640640
source = "registry+https://github.com/rust-lang/crates.io-index"
641-
checksum = "e3fcd8aba10d17504c87ef12d4f62ef404c6a4703d16682a9eb5543e6cf24455"
641+
checksum = "7cd0782e0a7da7598164153173e5a5d4d9b1da094473c98dce0ff91406112369"
642642
dependencies = [
643643
"cc",
644644
"rustc-std-workspace-core",

Diff for: compiler/rustc_ast/src/attr/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ impl HasAttrs for StmtKind {
629629
match *self {
630630
StmtKind::Local(ref local) => local.attrs(),
631631
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
632-
StmtKind::Empty | StmtKind::Item(..) => &[],
632+
StmtKind::Item(ref item) => item.attrs(),
633+
StmtKind::Empty => &[],
633634
StmtKind::MacCall(ref mac) => mac.attrs.attrs(),
634635
}
635636
}
@@ -638,7 +639,8 @@ impl HasAttrs for StmtKind {
638639
match self {
639640
StmtKind::Local(local) => local.visit_attrs(f),
640641
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
641-
StmtKind::Empty | StmtKind::Item(..) => {}
642+
StmtKind::Item(item) => item.visit_attrs(f),
643+
StmtKind::Empty => {}
642644
StmtKind::MacCall(mac) => {
643645
mac.attrs.visit_attrs(f);
644646
}

Diff for: compiler/rustc_attr/src/builtin.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,28 @@ pub fn allow_internal_unstable<'a>(
10131013
sess: &'a Session,
10141014
attrs: &'a [Attribute],
10151015
) -> Option<impl Iterator<Item = Symbol> + 'a> {
1016-
let attrs = sess.filter_by_name(attrs, sym::allow_internal_unstable);
1016+
allow_unstable(sess, attrs, sym::allow_internal_unstable)
1017+
}
1018+
1019+
pub fn rustc_allow_const_fn_unstable<'a>(
1020+
sess: &'a Session,
1021+
attrs: &'a [Attribute],
1022+
) -> Option<impl Iterator<Item = Symbol> + 'a> {
1023+
allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable)
1024+
}
1025+
1026+
fn allow_unstable<'a>(
1027+
sess: &'a Session,
1028+
attrs: &'a [Attribute],
1029+
symbol: Symbol,
1030+
) -> Option<impl Iterator<Item = Symbol> + 'a> {
1031+
let attrs = sess.filter_by_name(attrs, symbol);
10171032
let list = attrs
10181033
.filter_map(move |attr| {
10191034
attr.meta_item_list().or_else(|| {
10201035
sess.diagnostic().span_err(
10211036
attr.span,
1022-
"`allow_internal_unstable` expects a list of feature names",
1037+
&format!("`{}` expects a list of feature names", symbol.to_ident_string()),
10231038
);
10241039
None
10251040
})
@@ -1029,8 +1044,10 @@ pub fn allow_internal_unstable<'a>(
10291044
Some(list.into_iter().filter_map(move |it| {
10301045
let name = it.ident().map(|ident| ident.name);
10311046
if name.is_none() {
1032-
sess.diagnostic()
1033-
.span_err(it.span(), "`allow_internal_unstable` expects feature names");
1047+
sess.diagnostic().span_err(
1048+
it.span(),
1049+
&format!("`{}` expects feature names", symbol.to_ident_string()),
1050+
);
10341051
}
10351052
name
10361053
}))

Diff for: compiler/rustc_expand/src/expand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,8 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13571357
// we'll expand attributes on expressions separately
13581358
if !stmt.is_expr() {
13591359
let (attr, derives, after_derive) = if stmt.is_item() {
1360-
self.classify_item(&mut stmt)
1360+
// FIXME: Handle custom attributes on statements (#15701)
1361+
(None, vec![], false)
13611362
} else {
13621363
// ignore derives on non-item statements so it falls through
13631364
// to the unused-attributes lint

Diff for: compiler/rustc_feature/src/active.rs

+5
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ declare_features! (
210210
/// it is not on path for eventual stabilization).
211211
(active, no_niche, "1.42.0", None, None),
212212

213+
/// Allows using `#[rustc_allow_const_fn_unstable]`.
214+
/// This is an attribute on `const fn` for the same
215+
/// purpose as `#[allow_internal_unstable]`.
216+
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
217+
213218
// no-tracking-issue-end
214219

215220
// -------------------------------------------------------------------------

Diff for: compiler/rustc_feature/src/builtin_attrs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
379379
allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
380380
"allow_internal_unstable side-steps feature gating and stability checks",
381381
),
382+
gated!(
383+
rustc_allow_const_fn_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
384+
"rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
385+
),
382386
gated!(
383387
allow_internal_unsafe, Normal, template!(Word),
384388
"allow_internal_unsafe side-steps the unsafe_code lint",

Diff for: compiler/rustc_hir/src/hir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,11 @@ pub enum StmtKind<'hir> {
11011101
Semi(&'hir Expr<'hir>),
11021102
}
11031103

1104-
impl StmtKind<'hir> {
1105-
pub fn attrs(&self) -> &'hir [Attribute] {
1104+
impl<'hir> StmtKind<'hir> {
1105+
pub fn attrs(&self, get_item: impl FnOnce(ItemId) -> &'hir Item<'hir>) -> &'hir [Attribute] {
11061106
match *self {
11071107
StmtKind::Local(ref l) => &l.attrs,
1108-
StmtKind::Item(_) => &[],
1108+
StmtKind::Item(ref item_id) => &get_item(*item_id).attrs,
11091109
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => &e.attrs,
11101110
}
11111111
}

Diff for: compiler/rustc_lint/src/builtin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,8 @@ impl EarlyLintPass for UnusedDocComment {
994994
fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) {
995995
let kind = match stmt.kind {
996996
ast::StmtKind::Local(..) => "statements",
997-
ast::StmtKind::Item(..) => "inner items",
997+
// Disabled pending discussion in #78306
998+
ast::StmtKind::Item(..) => return,
998999
// expressions will be reported by `check_expr`.
9991000
ast::StmtKind::Empty
10001001
| ast::StmtKind::Semi(_)

Diff for: compiler/rustc_lint/src/early.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::context::{EarlyContext, LintContext, LintStore};
1818
use crate::passes::{EarlyLintPass, EarlyLintPassObject};
1919
use rustc_ast as ast;
2020
use rustc_ast::visit as ast_visit;
21+
use rustc_attr::HasAttrs;
2122
use rustc_session::lint::{BufferedEarlyLint, LintBuffer, LintPass};
2223
use rustc_session::Session;
2324
use rustc_span::symbol::Ident;
@@ -119,8 +120,22 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
119120
}
120121

121122
fn visit_stmt(&mut self, s: &'a ast::Stmt) {
122-
run_early_pass!(self, check_stmt, s);
123-
self.check_id(s.id);
123+
// Add the statement's lint attributes to our
124+
// current state when checking the statement itself.
125+
// This allows us to handle attributes like
126+
// `#[allow(unused_doc_comments)]`, which apply to
127+
// sibling attributes on the same target
128+
//
129+
// Note that statements get their attributes from
130+
// the AST struct that they wrap (e.g. an item)
131+
self.with_lint_attrs(s.id, s.attrs(), |cx| {
132+
run_early_pass!(cx, check_stmt, s);
133+
cx.check_id(s.id);
134+
});
135+
// The visitor for the AST struct wrapped
136+
// by the statement (e.g. `Item`) will call
137+
// `with_lint_attrs`, so do this walk
138+
// outside of the above `with_lint_attrs` call
124139
ast_visit::walk_stmt(self, s);
125140
}
126141

Diff for: compiler/rustc_lint/src/late.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
174174
}
175175

176176
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
177-
// statement attributes are actually just attributes on one of
178-
// - item
179-
// - local
180-
// - expression
181-
// so we keep track of lint levels there
182-
lint_callback!(self, check_stmt, s);
177+
let get_item = |id: hir::ItemId| self.context.tcx.hir().item(id.id);
178+
let attrs = &s.kind.attrs(get_item);
179+
// See `EarlyContextAndPass::visit_stmt` for an explanation
180+
// of why we call `walk_stmt` outside of `with_lint_attrs`
181+
self.with_lint_attrs(s.hir_id, attrs, |cx| {
182+
lint_callback!(cx, check_stmt, s);
183+
});
183184
hir_visit::walk_stmt(self, s);
184185
}
185186

Diff for: compiler/rustc_lint/src/levels.rs

+7
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
562562
})
563563
}
564564

565+
fn visit_stmt(&mut self, e: &'tcx hir::Stmt<'tcx>) {
566+
// We will call `with_lint_attrs` when we walk
567+
// the `StmtKind`. The outer statement itself doesn't
568+
// define the lint levels.
569+
intravisit::walk_stmt(self, e);
570+
}
571+
565572
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
566573
self.with_lint_attrs(e.hir_id, &e.attrs, |builder| {
567574
intravisit::walk_expr(builder, e);

Diff for: compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast as ast;
88
use rustc_ast::expand::allocator::AllocatorKind;
99
use rustc_data_structures::svh::Svh;
1010
use rustc_hir as hir;
11+
use rustc_hir::def::DefKind;
1112
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
1213
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
1314
use rustc_middle::hir::exports::Export;
@@ -487,6 +488,10 @@ impl CrateStore for CStore {
487488
self.get_crate_data(def.krate).def_key(def.index)
488489
}
489490

491+
fn def_kind(&self, def: DefId) -> DefKind {
492+
self.get_crate_data(def.krate).def_kind(def.index)
493+
}
494+
490495
fn def_path(&self, def: DefId) -> DefPath {
491496
self.get_crate_data(def.krate).def_path(def.index)
492497
}

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ impl<'hir> Map<'hir> {
816816
Some(Node::Variant(ref v)) => Some(&v.attrs[..]),
817817
Some(Node::Field(ref f)) => Some(&f.attrs[..]),
818818
Some(Node::Expr(ref e)) => Some(&*e.attrs),
819-
Some(Node::Stmt(ref s)) => Some(s.kind.attrs()),
819+
Some(Node::Stmt(ref s)) => Some(s.kind.attrs(|id| self.item(id.id))),
820820
Some(Node::Arm(ref a)) => Some(&*a.attrs),
821821
Some(Node::GenericParam(param)) => Some(&param.attrs[..]),
822822
// Unit/tuple structs/variants take the attributes straight from

Diff for: compiler/rustc_middle/src/middle/cstore.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast as ast;
88
use rustc_ast::expand::allocator::AllocatorKind;
99
use rustc_data_structures::svh::Svh;
1010
use rustc_data_structures::sync::{self, MetadataRef};
11+
use rustc_hir::def::DefKind;
1112
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1213
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
1314
use rustc_macros::HashStable;
@@ -185,6 +186,7 @@ pub trait CrateStore {
185186

186187
// resolve
187188
fn def_key(&self, def: DefId) -> DefKey;
189+
fn def_kind(&self, def: DefId) -> DefKind;
188190
fn def_path(&self, def: DefId) -> DefPath;
189191
fn def_path_hash(&self, def: DefId) -> DefPathHash;
190192
fn all_def_path_hashes_and_def_ids(&self, cnum: CrateNum) -> Vec<(DefPathHash, DefId)>;

Diff for: compiler/rustc_mir/src/transform/check_consts/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
7979
|| Some(def_id) == tcx.lang_items().begin_panic_fn()
8080
}
8181

82-
pub fn allow_internal_unstable(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
82+
pub fn rustc_allow_const_fn_unstable(
83+
tcx: TyCtxt<'tcx>,
84+
def_id: DefId,
85+
feature_gate: Symbol,
86+
) -> bool {
8387
let attrs = tcx.get_attrs(def_id);
84-
attr::allow_internal_unstable(&tcx.sess, attrs)
88+
attr::rustc_allow_const_fn_unstable(&tcx.sess, attrs)
8589
.map_or(false, |mut features| features.any(|name| name == feature_gate))
8690
}
8791

Diff for: compiler/rustc_mir/src/transform/check_consts/validation.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ impl Validator<'mir, 'tcx> {
292292

293293
Status::Unstable(gate) if self.tcx.features().enabled(gate) => {
294294
let unstable_in_stable = self.ccx.is_const_stable_const_fn()
295-
&& !super::allow_internal_unstable(self.tcx, self.def_id().to_def_id(), gate);
295+
&& !super::rustc_allow_const_fn_unstable(
296+
self.tcx,
297+
self.def_id().to_def_id(),
298+
gate,
299+
);
296300
if unstable_in_stable {
297301
emit_unstable_in_stable_error(self.ccx, span, gate);
298302
}
@@ -807,7 +811,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
807811
}
808812

809813
// Calling an unstable function *always* requires that the corresponding gate
810-
// be enabled, even if the function has `#[allow_internal_unstable(the_gate)]`.
814+
// be enabled, even if the function has `#[rustc_allow_const_fn_unstable(the_gate)]`.
811815
if !tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate) {
812816
self.check_op(ops::FnCallUnstable(callee, Some(gate)));
813817
return;
@@ -821,7 +825,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
821825

822826
// Otherwise, we are something const-stable calling a const-unstable fn.
823827

824-
if super::allow_internal_unstable(tcx, caller, gate) {
828+
if super::rustc_allow_const_fn_unstable(tcx, caller, gate) {
825829
return;
826830
}
827831

@@ -967,8 +971,8 @@ fn emit_unstable_in_stable_error(ccx: &ConstCx<'_, '_>, span: Span, gate: Symbol
967971
)
968972
.span_suggestion(
969973
attr_span,
970-
"otherwise `#[allow_internal_unstable]` can be used to bypass stability checks",
971-
format!("#[allow_internal_unstable({})]\n", gate),
974+
"otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks",
975+
format!("#[rustc_allow_const_fn_unstable({})]\n", gate),
972976
Applicability::MaybeIncorrect,
973977
)
974978
.emit();

Diff for: compiler/rustc_mir/src/transform/validate.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ use crate::dataflow::{Analysis, ResultsCursor};
55
use crate::util::storage::AlwaysLiveLocals;
66

77
use super::MirPass;
8-
use rustc_middle::mir::visit::{PlaceContext, Visitor};
8+
use rustc_middle::mir::{
9+
interpret::Scalar,
10+
visit::{PlaceContext, Visitor},
11+
};
912
use rustc_middle::mir::{
1013
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, Rvalue,
1114
SourceScope, Statement, StatementKind, Terminator, TerminatorKind, VarDebugInfo,
1215
};
1316
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
1417
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
18+
use rustc_target::abi::Size;
1519

1620
#[derive(Copy, Clone, Debug)]
1721
enum EdgeKind {
@@ -346,7 +350,25 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
346350
),
347351
);
348352
}
349-
for (_, target) in targets.iter() {
353+
354+
let target_width = self.tcx.sess.target.pointer_width;
355+
356+
let size = Size::from_bits(match switch_ty.kind() {
357+
ty::Uint(uint) => uint.normalize(target_width).bit_width().unwrap(),
358+
ty::Int(int) => int.normalize(target_width).bit_width().unwrap(),
359+
ty::Char => 32,
360+
ty::Bool => 1,
361+
other => bug!("unhandled type: {:?}", other),
362+
});
363+
364+
for (value, target) in targets.iter() {
365+
if Scalar::<()>::try_from_uint(value, size).is_none() {
366+
self.fail(
367+
location,
368+
format!("the value {:#x} is not a proper {:?}", value, switch_ty),
369+
)
370+
}
371+
350372
self.check_edge(location, target, EdgeKind::Normal);
351373
}
352374
self.check_edge(location, targets.otherwise(), EdgeKind::Normal);

0 commit comments

Comments
 (0)