Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #120121

Merged
merged 41 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
17edbe7
Use AtomicU8 instead of AtomicUsize in backtrace.rs
GnomedDev Dec 10, 2023
1c5b2ce
Docs: Use non-SeqCst in module example of atomics
AngelicosPhosphoros Dec 19, 2023
46ad131
update fn pointer trait impl docs
asquared31415 Jan 12, 2024
56df3bb
Move nonzero_integers macro call to bottom of module
dtolnay Dec 6, 2023
54cb822
Define only a single NonZero type per macro call
dtolnay Dec 6, 2023
9196d2a
Unindent nonzero_integer macro body
dtolnay Dec 6, 2023
a6152cd
Format nonzero_integer macro calls same way we do the primitive int i…
dtolnay Dec 6, 2023
3de0af1
Move 'impl FromStr for NonZero' into nonzero_integer macro
dtolnay Dec 6, 2023
81e1a7c
Move impl Div and Rem into nonzero_integer macro
dtolnay Dec 6, 2023
a78d9a6
Unindent nonzero_integer_impl_div_rem macro body
dtolnay Dec 6, 2023
f846ed5
Move leading_zeros and trailing_zeros methods into nonzero_integer macro
dtolnay Dec 6, 2023
757ed25
Move Neg impl into the macro that generates Div and Rem
dtolnay Dec 6, 2023
4291b3f
Move signedness dependent methods into the omnibus impl block
dtolnay Dec 6, 2023
b21b9cc
Unindent nonzero_integer_signedness_dependent_methods macro body
dtolnay Dec 6, 2023
c6d776e
Work around rustfmt doc attribute indentation bug
dtolnay Dec 6, 2023
63256af
Move nonzero_unsigned_signed_operations methods into the omnibus impl…
dtolnay Dec 6, 2023
4419136
Move is_power_of_two into unsigned part of signedness_dependent_methods
dtolnay Dec 6, 2023
7f7c5af
Move unsigned MIN and MAX into signedness_dependent_methods
dtolnay Dec 6, 2023
66cda3b
Move signed MIN and MAX into signedness_dependent_methods
dtolnay Dec 6, 2023
c537132
Move BITS into omnibus impl block
dtolnay Dec 6, 2023
cdee1fe
Unbreak tidy's feature parser
dtolnay Dec 6, 2023
c1c7707
Deny braced macro invocations in let-else
compiler-errors Dec 18, 2023
ec263df
Suggest wrapping mac args in parens rather than the whole expression
compiler-errors Dec 18, 2023
0373ce6
Warn when no profiler runtime means coverage tests won't be run/blessed
Zalathar Jan 18, 2024
d95d6ce
`dead_code` treats `#[repr(transparent)]` the same as `#[repr(C)]`
shepmaster Jan 18, 2024
fb7762b
Remove no-longer-needed `allow(dead_code)` from the standard library
shepmaster Jan 18, 2024
92cc57b
Remove no-longer-needed `allow(dead_code)` from the tests
shepmaster Jan 18, 2024
aeeaed9
Remove no-longer-needed `allow(dead_code)` from Miri tests
shepmaster Jan 18, 2024
7fead95
Remove myself from review rotation
WaffleLapkin Jan 18, 2024
35a9fc3
Clarify docs for Vec::into_boxed_slice, Vec::shrink_to_fit
invpt Jan 18, 2024
1a34342
Fix typo in documentation in base.rs
kapilsinha Jan 19, 2024
122b3f9
Rollup merge of #118665 - dtolnay:signedness, r=Nilstrieb
matthiaskrgr Jan 19, 2024
2d828cd
Rollup merge of #118798 - GnomedDev:use-atomicu8-backtrace, r=Nilstrieb
matthiaskrgr Jan 19, 2024
2e4c6fc
Rollup merge of #119062 - compiler-errors:asm-in-let-else, r=davidtwc…
matthiaskrgr Jan 19, 2024
f9076bb
Rollup merge of #119138 - AngelicosPhosphoros:use_proper_atomics_in_s…
matthiaskrgr Jan 19, 2024
48ba721
Rollup merge of #119907 - asquared31415:fn_trait_docs, r=Nilstrieb
matthiaskrgr Jan 19, 2024
987445c
Rollup merge of #120083 - Zalathar:no-profiler, r=wesleywiser
matthiaskrgr Jan 19, 2024
332f8f7
Rollup merge of #120107 - shepmaster:dead-code-repr-transparent, r=Ni…
matthiaskrgr Jan 19, 2024
7219bd2
Rollup merge of #120110 - invpt:patch-1, r=the8472
matthiaskrgr Jan 19, 2024
e35dfed
Rollup merge of #120113 - WaffleLapkin:🔥-1, r=compiler-errors
matthiaskrgr Jan 19, 2024
b4616f5
Rollup merge of #120118 - kapilsinha:patch-1, r=Nilstrieb
matthiaskrgr Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions compiler/rustc_ast/src/util/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Predicates on exprs and stmts that the pretty-printer and parser use

use crate::ast;
use crate::{ast, token::Delimiter};

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

// FIXME: These can end in `}`, but changing these would break stable code.
InlineAsm(_) | OffsetOf(_, _) | MacCall(_) | IncludedBytes(_) | FormatArgs(_) => {
MacCall(mac) => {
break (mac.args.delim == Delimiter::Brace).then_some(expr);
}

InlineAsm(_) | OffsetOf(_, _) | IncludedBytes(_) | FormatArgs(_) => {
// These should have been denied pre-expansion.
break None;
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ pub enum SyntaxExtensionKind {
/// A token-based attribute macro.
Attr(
/// An expander with signature (TokenStream, TokenStream) -> TokenStream.
/// The first TokenSteam is the attribute itself, the second is the annotated item.
/// The produced TokenSteam replaces the input TokenSteam.
/// The first TokenStream is the attribute itself, the second is the annotated item.
/// The produced TokenStream replaces the input TokenStream.
Box<dyn AttrProcMacro + sync::DynSync + sync::DynSend>,
),

Expand All @@ -685,7 +685,7 @@ pub enum SyntaxExtensionKind {
/// A token-based derive macro.
Derive(
/// An expander with signature TokenStream -> TokenStream.
/// The produced TokenSteam is appended to the input TokenSteam.
/// The produced TokenStream is appended to the input TokenStream.
///
/// FIXME: The text above describes how this should work. Currently it
/// is handled identically to `LegacyDerive`. It should be migrated to
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ parse_sugg_turbofish_syntax = use `::<...>` instead of `<...>` to specify lifeti

parse_sugg_wrap_expression_in_parentheses = wrap the expression in parentheses

parse_sugg_wrap_macro_in_parentheses = use parentheses instead of braces for this macro

parse_sugg_wrap_pattern_in_parens = wrap the pattern in parentheses

parse_switch_mut_let_order =
Expand Down
37 changes: 25 additions & 12 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,19 +722,32 @@ pub(crate) struct LabeledLoopInBreak {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sub: WrapExpressionInParentheses,
pub sub: WrapInParentheses,
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_sugg_wrap_expression_in_parentheses,
applicability = "machine-applicable"
)]
pub(crate) struct WrapExpressionInParentheses {
#[suggestion_part(code = "(")]
pub left: Span,
#[suggestion_part(code = ")")]
pub right: Span,

pub(crate) enum WrapInParentheses {
#[multipart_suggestion(
parse_sugg_wrap_expression_in_parentheses,
applicability = "machine-applicable"
)]
Expression {
#[suggestion_part(code = "(")]
left: Span,
#[suggestion_part(code = ")")]
right: Span,
},
#[multipart_suggestion(
parse_sugg_wrap_macro_in_parentheses,
applicability = "machine-applicable"
)]
MacroArgs {
#[suggestion_part(code = "(")]
left: Span,
#[suggestion_part(code = ")")]
right: Span,
},
}

#[derive(Diagnostic)]
Expand Down Expand Up @@ -936,7 +949,7 @@ pub(crate) struct InvalidExpressionInLetElse {
pub span: Span,
pub operator: &'static str,
#[subdiagnostic]
pub sugg: WrapExpressionInParentheses,
pub sugg: WrapInParentheses,
}

#[derive(Diagnostic)]
Expand All @@ -945,7 +958,7 @@ pub(crate) struct InvalidCurlyInLetElse {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sugg: WrapExpressionInParentheses,
pub sugg: WrapInParentheses,
}

#[derive(Diagnostic)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ impl<'a> Parser<'a> {
let lexpr = self.parse_expr_labeled(label, true)?;
self.dcx().emit_err(errors::LabeledLoopInBreak {
span: lexpr.span,
sub: errors::WrapExpressionInParentheses {
sub: errors::WrapInParentheses::Expression {
left: lexpr.span.shrink_to_lo(),
right: lexpr.span.shrink_to_hi(),
},
Expand Down
15 changes: 11 additions & 4 deletions compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl<'a> Parser<'a> {
self.dcx().emit_err(errors::InvalidExpressionInLetElse {
span: init.span,
operator: op.node.as_str(),
sugg: errors::WrapExpressionInParentheses {
sugg: errors::WrapInParentheses::Expression {
left: init.span.shrink_to_lo(),
right: init.span.shrink_to_hi(),
},
Expand All @@ -400,12 +400,19 @@ impl<'a> Parser<'a> {

fn check_let_else_init_trailing_brace(&self, init: &ast::Expr) {
if let Some(trailing) = classify::expr_trailing_brace(init) {
self.dcx().emit_err(errors::InvalidCurlyInLetElse {
span: trailing.span.with_lo(trailing.span.hi() - BytePos(1)),
sugg: errors::WrapExpressionInParentheses {
let sugg = match &trailing.kind {
ExprKind::MacCall(mac) => errors::WrapInParentheses::MacroArgs {
left: mac.args.dspan.open,
right: mac.args.dspan.close,
},
_ => errors::WrapInParentheses::Expression {
left: trailing.span.shrink_to_lo(),
right: trailing.span.shrink_to_hi(),
},
};
self.dcx().emit_err(errors::InvalidCurlyInLetElse {
span: trailing.span.with_lo(trailing.span.hi() - BytePos(1)),
sugg,
});
}
}
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct MarkSymbolVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>,
live_symbols: LocalDefIdSet,
repr_has_repr_c: bool,
repr_unconditionally_treats_fields_as_live: bool,
repr_has_repr_simd: bool,
in_pat: bool,
ignore_variant_stack: Vec<DefId>,
Expand Down Expand Up @@ -365,15 +365,17 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
return;
}

let had_repr_c = self.repr_has_repr_c;
let unconditionally_treated_fields_as_live =
self.repr_unconditionally_treats_fields_as_live;
let had_repr_simd = self.repr_has_repr_simd;
self.repr_has_repr_c = false;
self.repr_unconditionally_treats_fields_as_live = false;
self.repr_has_repr_simd = false;
match node {
Node::Item(item) => match item.kind {
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
let def = self.tcx.adt_def(item.owner_id);
self.repr_has_repr_c = def.repr().c();
self.repr_unconditionally_treats_fields_as_live =
def.repr().c() || def.repr().transparent();
self.repr_has_repr_simd = def.repr().simd();

intravisit::walk_item(self, item)
Expand Down Expand Up @@ -411,7 +413,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
_ => {}
}
self.repr_has_repr_simd = had_repr_simd;
self.repr_has_repr_c = had_repr_c;
self.repr_unconditionally_treats_fields_as_live = unconditionally_treated_fields_as_live;
}

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

fn visit_variant_data(&mut self, def: &'tcx hir::VariantData<'tcx>) {
let tcx = self.tcx;
let has_repr_c = self.repr_has_repr_c;
let unconditionally_treat_fields_as_live = self.repr_unconditionally_treats_fields_as_live;
let has_repr_simd = self.repr_has_repr_simd;
let live_fields = def.fields().iter().filter_map(|f| {
let def_id = f.def_id;
if has_repr_c || (f.is_positional() && has_repr_simd) {
if unconditionally_treat_fields_as_live || (f.is_positional() && has_repr_simd) {
return Some(def_id);
}
if !tcx.visibility(f.hir_id.owner.def_id).is_public() {
Expand Down Expand Up @@ -741,7 +743,7 @@ fn live_symbols_and_ignored_derived_traits(
tcx,
maybe_typeck_results: None,
live_symbols: Default::default(),
repr_has_repr_c: false,
repr_unconditionally_treats_fields_as_live: false,
repr_has_repr_simd: false,
in_pat: false,
ignore_variant_stack: vec![],
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/boxed/thin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ struct WithHeader<H>(NonNull<u8>, PhantomData<H>);
/// An opaque representation of `WithHeader<H>` to avoid the
/// projection invariance of `<T as Pointee>::Metadata`.
#[repr(transparent)]
#[allow(dead_code)] // Field only used through `WithHeader` type above.
struct WithOpaqueHeader(NonNull<u8>);

impl WithOpaqueHeader {
Expand Down
19 changes: 12 additions & 7 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ mod spec_extend;
///
/// `vec![x; n]`, `vec![a, b, c, d]`, and
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
/// with exactly the requested capacity. If <code>[len] == [capacity]</code>,
/// with at least the requested capacity. If <code>[len] == [capacity]</code>,
/// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
///
Expand Down Expand Up @@ -1023,8 +1023,11 @@ impl<T, A: Allocator> Vec<T, A> {

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

/// Converts the vector into [`Box<[T]>`][owned slice].
///
/// If the vector has excess capacity, its items will be moved into a
/// newly-allocated buffer with exactly the right capacity.
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
///
/// [owned slice]: Box
/// [`shrink_to_fit`]: Vec::shrink_to_fit
///
/// # Examples
///
Expand Down Expand Up @@ -3290,8 +3293,10 @@ impl<T, A: Allocator> From<Box<[T], A>> for Vec<T, A> {
impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
/// Convert a vector into a boxed slice.
///
/// If `v` has excess capacity, its items will be moved into a
/// newly-allocated buffer with exactly the right capacity.
/// Before doing the conversion, this method discards excess capacity like [`Vec::shrink_to_fit`].
///
/// [owned slice]: Box
/// [`Vec::shrink_to_fit`]: Vec::shrink_to_fit
///
/// # Examples
///
Expand Down
Loading
Loading