Skip to content

Commit d98a5da

Browse files
committed
Auto merge of #143459 - matthiaskrgr:rollup-gsv6uzl, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #141532 (std: sys: net: uefi: tcp4: Implement write) - #143085 (Port `#[non_exhaustive]` to the new attribute parsing infrastructure) - #143372 (Remove names_imported_by_glob_use query.) - #143386 (Assign dependency bump PRs to me) - #143406 (Remove some unnecessary `unsafe` in VecCache) - #143408 (mbe: Gracefully handle macro rules that end after `=>`) - #143414 (remove special-casing of boxes from match exhaustiveness/usefulness analysis) - #143444 (clean up GVN TypeId test) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e384365 + 1ff6e44 commit d98a5da

File tree

39 files changed

+385
-180
lines changed

39 files changed

+385
-180
lines changed

.github/workflows/dependencies.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ env:
1919
PR_TITLE: Weekly `cargo update`
2020
PR_MESSAGE: |
2121
Automation to keep dependencies in `Cargo.lock` current.
22+
r? dep-bumps
2223
2324
The following is the output from `cargo update`:
2425
COMMIT_MESSAGE: "cargo update \n\n"

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ pub enum AttributeKind {
284284
/// Represents `#[no_mangle]`
285285
NoMangle(Span),
286286

287+
/// Represents `#[non_exhaustive]`
288+
NonExhaustive(Span),
289+
287290
/// Represents `#[optimize(size|speed)]`
288291
Optimize(OptimizeAttr, Span),
289292

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl AttributeKind {
3636
Naked(..) => No,
3737
NoImplicitPrelude(..) => No,
3838
NoMangle(..) => No,
39+
NonExhaustive(..) => Yes,
3940
Optimize(..) => No,
4041
PassByValue(..) => Yes,
4142
PubTransparent(..) => Yes,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub(crate) mod lint_helpers;
3636
pub(crate) mod loop_match;
3737
pub(crate) mod must_use;
3838
pub(crate) mod no_implicit_prelude;
39+
pub(crate) mod non_exhaustive;
3940
pub(crate) mod repr;
4041
pub(crate) mod rustc_internal;
4142
pub(crate) mod semantics;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_span::{Span, Symbol, sym};
3+
4+
use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
5+
use crate::context::Stage;
6+
7+
pub(crate) struct NonExhaustiveParser;
8+
9+
impl<S: Stage> NoArgsAttributeParser<S> for NonExhaustiveParser {
10+
const PATH: &[Symbol] = &[sym::non_exhaustive];
11+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
12+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NonExhaustive;
13+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::attributes::lint_helpers::{AsPtrParser, PassByValueParser, PubTranspa
2727
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2828
use crate::attributes::must_use::MustUseParser;
2929
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
30+
use crate::attributes::non_exhaustive::NonExhaustiveParser;
3031
use crate::attributes::repr::{AlignParser, ReprParser};
3132
use crate::attributes::rustc_internal::{
3233
RustcLayoutScalarValidRangeEnd, RustcLayoutScalarValidRangeStart,
@@ -144,6 +145,7 @@ attribute_parsers!(
144145
Single<WithoutArgs<MayDangleParser>>,
145146
Single<WithoutArgs<NoImplicitPreludeParser>>,
146147
Single<WithoutArgs<NoMangleParser>>,
148+
Single<WithoutArgs<NonExhaustiveParser>>,
147149
Single<WithoutArgs<PassByValueParser>>,
148150
Single<WithoutArgs<PubTransparentParser>>,
149151
Single<WithoutArgs<TrackCallerParser>>,

compiler/rustc_data_structures/src/vec_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl SlotIndex {
7676
index_in_bucket: idx as usize,
7777
};
7878
}
79-
// SAFETY: We already ruled out idx 0, so `checked_ilog2` can't return `None`.
80-
let bucket = unsafe { idx.checked_ilog2().unwrap_unchecked() as usize };
79+
// We already ruled out idx 0, so this `ilog2` never panics (and the check optimizes away)
80+
let bucket = idx.ilog2() as usize;
8181
let entries = 1 << bucket;
8282
SlotIndex {
8383
bucket_idx: bucket - FIRST_BUCKET_SHIFT + 1,

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,15 @@ pub fn compile_declarative_macro(
411411
if let Err(e) = p.expect(exp!(FatArrow)) {
412412
return dummy_syn_ext(e.emit());
413413
}
414+
if p.token == token::Eof {
415+
let err_sp = p.token.span.shrink_to_hi();
416+
let guar = sess
417+
.dcx()
418+
.struct_span_err(err_sp, "macro definition ended unexpectedly")
419+
.with_span_label(err_sp, "expected right-hand side of macro rule")
420+
.emit();
421+
return dummy_syn_ext(guar);
422+
}
414423
let rhs_tt = p.parse_token_tree();
415424
let rhs_tt = mbe::quoted::parse(
416425
&TokenStream::new(vec![rhs_tt]),

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,11 @@ fn lower_variant<'tcx>(
779779
fields,
780780
parent_did.to_def_id(),
781781
recovered,
782-
adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive)
783-
|| variant_did
784-
.is_some_and(|variant_did| tcx.has_attr(variant_did, sym::non_exhaustive)),
782+
adt_kind == AdtKind::Struct
783+
&& find_attr!(tcx.get_all_attrs(parent_did), AttributeKind::NonExhaustive(..))
784+
|| variant_did.is_some_and(|variant_did| {
785+
find_attr!(tcx.get_all_attrs(variant_did), AttributeKind::NonExhaustive(..))
786+
}),
785787
)
786788
}
787789

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,9 +2264,6 @@ rustc_queries! {
22642264
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
22652265
desc { "fetching potentially unused trait imports" }
22662266
}
2267-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxIndexSet<Symbol> {
2268-
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
2269-
}
22702267

22712268
query stability_index(_: ()) -> &'tcx stability::Index {
22722269
arena_cache

0 commit comments

Comments
 (0)