Skip to content

Commit 32ec40c

Browse files
committed
Auto merge of #120121 - matthiaskrgr:rollup-razammh, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #118665 (Consolidate all associated items on the NonZero integer types into a single impl block per type) - #118798 (Use AtomicU8 instead of AtomicUsize in backtrace.rs) - #119062 (Deny braced macro invocations in let-else) - #119138 (Docs: Use non-SeqCst in module example of atomics) - #119907 (Update `fn()` trait implementation docs) - #120083 (Warn when not having a profiler runtime means that coverage tests won't be run/blessed) - #120107 (dead_code treats #[repr(transparent)] the same as #[repr(C)]) - #120110 (Update documentation for Vec::into_boxed_slice to be more clear about excess capacity) - #120113 (Remove myself from review rotation) - #120118 (Fix typo in documentation in base.rs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 92d7277 + b4616f5 commit 32ec40c

File tree

23 files changed

+1376
-1326
lines changed

23 files changed

+1376
-1326
lines changed

compiler/rustc_ast/src/util/classify.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
// Predicates on exprs and stmts that the pretty-printer and parser use
44

5-
use crate::ast;
5+
use crate::{ast, token::Delimiter};
66

77
/// Does this expression require a semicolon to be treated
88
/// as a statement? The negation of this: 'can this expression
@@ -59,8 +59,12 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
5959
| While(..)
6060
| ConstBlock(_) => break Some(expr),
6161

62-
// FIXME: These can end in `}`, but changing these would break stable code.
63-
InlineAsm(_) | OffsetOf(_, _) | MacCall(_) | IncludedBytes(_) | FormatArgs(_) => {
62+
MacCall(mac) => {
63+
break (mac.args.delim == Delimiter::Brace).then_some(expr);
64+
}
65+
66+
InlineAsm(_) | OffsetOf(_, _) | IncludedBytes(_) | FormatArgs(_) => {
67+
// These should have been denied pre-expansion.
6468
break None;
6569
}
6670

compiler/rustc_expand/src/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ pub enum SyntaxExtensionKind {
666666
/// A token-based attribute macro.
667667
Attr(
668668
/// An expander with signature (TokenStream, TokenStream) -> TokenStream.
669-
/// The first TokenSteam is the attribute itself, the second is the annotated item.
670-
/// The produced TokenSteam replaces the input TokenSteam.
669+
/// The first TokenStream is the attribute itself, the second is the annotated item.
670+
/// The produced TokenStream replaces the input TokenStream.
671671
Box<dyn AttrProcMacro + sync::DynSync + sync::DynSend>,
672672
),
673673

@@ -687,7 +687,7 @@ pub enum SyntaxExtensionKind {
687687
/// A token-based derive macro.
688688
Derive(
689689
/// An expander with signature TokenStream -> TokenStream.
690-
/// The produced TokenSteam is appended to the input TokenSteam.
690+
/// The produced TokenStream is appended to the input TokenStream.
691691
///
692692
/// FIXME: The text above describes how this should work. Currently it
693693
/// is handled identically to `LegacyDerive`. It should be migrated to

compiler/rustc_parse/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ parse_sugg_turbofish_syntax = use `::<...>` instead of `<...>` to specify lifeti
724724
725725
parse_sugg_wrap_expression_in_parentheses = wrap the expression in parentheses
726726
727+
parse_sugg_wrap_macro_in_parentheses = use parentheses instead of braces for this macro
728+
727729
parse_sugg_wrap_pattern_in_parens = wrap the pattern in parentheses
728730
729731
parse_switch_mut_let_order =

compiler/rustc_parse/src/errors.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -722,19 +722,32 @@ pub(crate) struct LabeledLoopInBreak {
722722
#[primary_span]
723723
pub span: Span,
724724
#[subdiagnostic]
725-
pub sub: WrapExpressionInParentheses,
725+
pub sub: WrapInParentheses,
726726
}
727727

728728
#[derive(Subdiagnostic)]
729-
#[multipart_suggestion(
730-
parse_sugg_wrap_expression_in_parentheses,
731-
applicability = "machine-applicable"
732-
)]
733-
pub(crate) struct WrapExpressionInParentheses {
734-
#[suggestion_part(code = "(")]
735-
pub left: Span,
736-
#[suggestion_part(code = ")")]
737-
pub right: Span,
729+
730+
pub(crate) enum WrapInParentheses {
731+
#[multipart_suggestion(
732+
parse_sugg_wrap_expression_in_parentheses,
733+
applicability = "machine-applicable"
734+
)]
735+
Expression {
736+
#[suggestion_part(code = "(")]
737+
left: Span,
738+
#[suggestion_part(code = ")")]
739+
right: Span,
740+
},
741+
#[multipart_suggestion(
742+
parse_sugg_wrap_macro_in_parentheses,
743+
applicability = "machine-applicable"
744+
)]
745+
MacroArgs {
746+
#[suggestion_part(code = "(")]
747+
left: Span,
748+
#[suggestion_part(code = ")")]
749+
right: Span,
750+
},
738751
}
739752

740753
#[derive(Diagnostic)]
@@ -936,7 +949,7 @@ pub(crate) struct InvalidExpressionInLetElse {
936949
pub span: Span,
937950
pub operator: &'static str,
938951
#[subdiagnostic]
939-
pub sugg: WrapExpressionInParentheses,
952+
pub sugg: WrapInParentheses,
940953
}
941954

942955
#[derive(Diagnostic)]
@@ -945,7 +958,7 @@ pub(crate) struct InvalidCurlyInLetElse {
945958
#[primary_span]
946959
pub span: Span,
947960
#[subdiagnostic]
948-
pub sugg: WrapExpressionInParentheses,
961+
pub sugg: WrapInParentheses,
949962
}
950963

951964
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ impl<'a> Parser<'a> {
18441844
let lexpr = self.parse_expr_labeled(label, true)?;
18451845
self.dcx().emit_err(errors::LabeledLoopInBreak {
18461846
span: lexpr.span,
1847-
sub: errors::WrapExpressionInParentheses {
1847+
sub: errors::WrapInParentheses::Expression {
18481848
left: lexpr.span.shrink_to_lo(),
18491849
right: lexpr.span.shrink_to_hi(),
18501850
},

compiler/rustc_parse/src/parser/stmt.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'a> Parser<'a> {
389389
self.dcx().emit_err(errors::InvalidExpressionInLetElse {
390390
span: init.span,
391391
operator: op.node.as_str(),
392-
sugg: errors::WrapExpressionInParentheses {
392+
sugg: errors::WrapInParentheses::Expression {
393393
left: init.span.shrink_to_lo(),
394394
right: init.span.shrink_to_hi(),
395395
},
@@ -400,12 +400,19 @@ impl<'a> Parser<'a> {
400400

401401
fn check_let_else_init_trailing_brace(&self, init: &ast::Expr) {
402402
if let Some(trailing) = classify::expr_trailing_brace(init) {
403-
self.dcx().emit_err(errors::InvalidCurlyInLetElse {
404-
span: trailing.span.with_lo(trailing.span.hi() - BytePos(1)),
405-
sugg: errors::WrapExpressionInParentheses {
403+
let sugg = match &trailing.kind {
404+
ExprKind::MacCall(mac) => errors::WrapInParentheses::MacroArgs {
405+
left: mac.args.dspan.open,
406+
right: mac.args.dspan.close,
407+
},
408+
_ => errors::WrapInParentheses::Expression {
406409
left: trailing.span.shrink_to_lo(),
407410
right: trailing.span.shrink_to_hi(),
408411
},
412+
};
413+
self.dcx().emit_err(errors::InvalidCurlyInLetElse {
414+
span: trailing.span.with_lo(trailing.span.hi() - BytePos(1)),
415+
sugg,
409416
});
410417
}
411418
}

compiler/rustc_passes/src/dead.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct MarkSymbolVisitor<'tcx> {
5757
tcx: TyCtxt<'tcx>,
5858
maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>,
5959
live_symbols: LocalDefIdSet,
60-
repr_has_repr_c: bool,
60+
repr_unconditionally_treats_fields_as_live: bool,
6161
repr_has_repr_simd: bool,
6262
in_pat: bool,
6363
ignore_variant_stack: Vec<DefId>,
@@ -365,15 +365,17 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
365365
return;
366366
}
367367

368-
let had_repr_c = self.repr_has_repr_c;
368+
let unconditionally_treated_fields_as_live =
369+
self.repr_unconditionally_treats_fields_as_live;
369370
let had_repr_simd = self.repr_has_repr_simd;
370-
self.repr_has_repr_c = false;
371+
self.repr_unconditionally_treats_fields_as_live = false;
371372
self.repr_has_repr_simd = false;
372373
match node {
373374
Node::Item(item) => match item.kind {
374375
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
375376
let def = self.tcx.adt_def(item.owner_id);
376-
self.repr_has_repr_c = def.repr().c();
377+
self.repr_unconditionally_treats_fields_as_live =
378+
def.repr().c() || def.repr().transparent();
377379
self.repr_has_repr_simd = def.repr().simd();
378380

379381
intravisit::walk_item(self, item)
@@ -411,7 +413,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
411413
_ => {}
412414
}
413415
self.repr_has_repr_simd = had_repr_simd;
414-
self.repr_has_repr_c = had_repr_c;
416+
self.repr_unconditionally_treats_fields_as_live = unconditionally_treated_fields_as_live;
415417
}
416418

417419
fn mark_as_used_if_union(&mut self, adt: ty::AdtDef<'tcx>, fields: &[hir::ExprField<'_>]) {
@@ -435,11 +437,11 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
435437

436438
fn visit_variant_data(&mut self, def: &'tcx hir::VariantData<'tcx>) {
437439
let tcx = self.tcx;
438-
let has_repr_c = self.repr_has_repr_c;
440+
let unconditionally_treat_fields_as_live = self.repr_unconditionally_treats_fields_as_live;
439441
let has_repr_simd = self.repr_has_repr_simd;
440442
let live_fields = def.fields().iter().filter_map(|f| {
441443
let def_id = f.def_id;
442-
if has_repr_c || (f.is_positional() && has_repr_simd) {
444+
if unconditionally_treat_fields_as_live || (f.is_positional() && has_repr_simd) {
443445
return Some(def_id);
444446
}
445447
if !tcx.visibility(f.hir_id.owner.def_id).is_public() {
@@ -741,7 +743,7 @@ fn live_symbols_and_ignored_derived_traits(
741743
tcx,
742744
maybe_typeck_results: None,
743745
live_symbols: Default::default(),
744-
repr_has_repr_c: false,
746+
repr_unconditionally_treats_fields_as_live: false,
745747
repr_has_repr_simd: false,
746748
in_pat: false,
747749
ignore_variant_stack: vec![],

library/alloc/src/boxed/thin.rs

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ struct WithHeader<H>(NonNull<u8>, PhantomData<H>);
171171
/// An opaque representation of `WithHeader<H>` to avoid the
172172
/// projection invariance of `<T as Pointee>::Metadata`.
173173
#[repr(transparent)]
174-
#[allow(dead_code)] // Field only used through `WithHeader` type above.
175174
struct WithOpaqueHeader(NonNull<u8>);
176175

177176
impl WithOpaqueHeader {

library/alloc/src/vec/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ mod spec_extend;
358358
///
359359
/// `vec![x; n]`, `vec![a, b, c, d]`, and
360360
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
361-
/// with exactly the requested capacity. If <code>[len] == [capacity]</code>,
361+
/// with at least the requested capacity. If <code>[len] == [capacity]</code>,
362362
/// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to
363363
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
364364
///
@@ -1023,8 +1023,11 @@ impl<T, A: Allocator> Vec<T, A> {
10231023

10241024
/// Shrinks the capacity of the vector as much as possible.
10251025
///
1026-
/// It will drop down as close as possible to the length but the allocator
1027-
/// may still inform the vector that there is space for a few more elements.
1026+
/// The behavior of this method depends on the allocator, which may either shrink the vector
1027+
/// in-place or reallocate. The resulting vector might still have some excess capacity, just as
1028+
/// is the case for [`with_capacity`]. See [`Allocator::shrink`] for more details.
1029+
///
1030+
/// [`with_capacity`]: Vec::with_capacity
10281031
///
10291032
/// # Examples
10301033
///
@@ -1074,10 +1077,10 @@ impl<T, A: Allocator> Vec<T, A> {
10741077

10751078
/// Converts the vector into [`Box<[T]>`][owned slice].
10761079
///
1077-
/// If the vector has excess capacity, its items will be moved into a
1078-
/// newly-allocated buffer with exactly the right capacity.
1080+
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
10791081
///
10801082
/// [owned slice]: Box
1083+
/// [`shrink_to_fit`]: Vec::shrink_to_fit
10811084
///
10821085
/// # Examples
10831086
///
@@ -3290,8 +3293,10 @@ impl<T, A: Allocator> From<Box<[T], A>> for Vec<T, A> {
32903293
impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
32913294
/// Convert a vector into a boxed slice.
32923295
///
3293-
/// If `v` has excess capacity, its items will be moved into a
3294-
/// newly-allocated buffer with exactly the right capacity.
3296+
/// Before doing the conversion, this method discards excess capacity like [`Vec::shrink_to_fit`].
3297+
///
3298+
/// [owned slice]: Box
3299+
/// [`Vec::shrink_to_fit`]: Vec::shrink_to_fit
32953300
///
32963301
/// # Examples
32973302
///

0 commit comments

Comments
 (0)