Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f392479

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

Cargo.lock

Lines changed: 2 additions & 2 deletions
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",

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 4 additions & 2 deletions
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
}

compiler/rustc_attr/src/builtin.rs

Lines changed: 21 additions & 4 deletions
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
}))

compiler/rustc_expand/src/expand.rs

Lines changed: 2 additions & 1 deletion
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

compiler/rustc_feature/src/active.rs

Lines changed: 5 additions & 0 deletions
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
// -------------------------------------------------------------------------

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 0 deletions
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",

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 3 deletions
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
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 1 deletion
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(_)

compiler/rustc_lint/src/early.rs

Lines changed: 17 additions & 2 deletions
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

compiler/rustc_lint/src/late.rs

Lines changed: 7 additions & 6 deletions
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

0 commit comments

Comments
 (0)