Skip to content

Rollup of 9 pull requests #139336

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

Merged
merged 26 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2d2307e
Dedup `&mut *` reborrow suggestion in loops
ShE3py Mar 13, 2025
2feb911
io: Avoid marking buffer as uninit when copying to `BufWriter`
a1phyr Mar 28, 2025
8787868
io: Avoid Avoid marking bytes as uninit in `BufReader::peek`
a1phyr Mar 28, 2025
1d6ddd6
Remove unused variables generated in merged doctests
GuillaumeGomez Apr 2, 2025
2dd4501
Put Noratrieb on vacation
Noratrieb Apr 2, 2025
f798c46
Map myself
RossSmyth Mar 4, 2025
076cccd
Remove `Op` type.
nnethercote Dec 19, 2024
ac8ccf0
Use `BinOpKind` instead of `BinOp` for function args where possible.
nnethercote Dec 19, 2024
ddcb370
Tighten up assignment operator representations.
nnethercote Dec 19, 2024
f3eaf16
Split ExpectationLintId off Level
oli-obk Mar 18, 2025
c51816e
Make LevelAndSource a struct
oli-obk Mar 19, 2025
805f389
Remove `LintExpectationId` from `Level` variants
oli-obk Mar 19, 2025
0795b3d
Upvars HirIds always have the same owner, thus just use an ItemLocalId
oli-obk Mar 17, 2025
5a4e7eb
impl !PartialOrd for UpvarMigrationInfo
oli-obk Mar 17, 2025
57c4ab7
impl !PartialOrd for HirId
oli-obk Mar 17, 2025
3df2acd
Allow boolean literals in `check-cfg`
clubby789 Mar 21, 2025
b310e8c
add Marco Ieni to mailmap
marcoieni Apr 3, 2025
e5c7451
Rollup merge of #138017 - nnethercote:tighten-assignment-op, r=spasto…
matthiaskrgr Apr 3, 2025
731ce84
Rollup merge of #138462 - ShE3py:mut-borrow-in-loop, r=oli-obk
matthiaskrgr Apr 3, 2025
48a3919
Rollup merge of #138610 - oli-obk:no-sort-hir-ids, r=compiler-errors
matthiaskrgr Apr 3, 2025
9d733ec
Rollup merge of #138767 - clubby789:check-cfg-bool, r=Urgau
matthiaskrgr Apr 3, 2025
ff8f2ef
Rollup merge of #139068 - a1phyr:less_uninit, r=joboet
matthiaskrgr Apr 3, 2025
ed6efe6
Rollup merge of #139255 - GuillaumeGomez:unused-var-merged-doctest, r…
matthiaskrgr Apr 3, 2025
ec9aa8c
Rollup merge of #139270 - RossSmyth:mailmap, r=Noratrieb
matthiaskrgr Apr 3, 2025
42aef0c
Rollup merge of #139303 - Noratrieb:Noratrieb-patch-3, r=Noratrieb
matthiaskrgr Apr 3, 2025
4cf6c21
Rollup merge of #139312 - marcoieni:marco-mailmap, r=Kobzol
matthiaskrgr Apr 3, 2025
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
6 changes: 5 additions & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Jacob Greenfield <[email protected]>
Jacob Pratt <[email protected]> <[email protected]>
Jacob Pratt <[email protected]> <[email protected]>
Jake Goulding <[email protected]>
Jake Goulding <[email protected]> <[email protected]>
Jake Goulding <[email protected]> <[email protected]>
Jake Goulding <[email protected]> <[email protected]>
Jake Vossen <[email protected]>
Jakob Degen <[email protected]> <[email protected]>
Expand Down Expand Up @@ -412,6 +412,7 @@ Malo Jaffré <[email protected]>
Manish Goregaokar <[email protected]>
Mara Bos <[email protected]>
Marcell Pardavi <[email protected]>
Marco Ieni <[email protected]>
Marcus Klaas de Vries <[email protected]>
Margaret Meyerhofer <[email protected]> <mmeyerho@andrew>
Mark Mansi <[email protected]>
Expand Down Expand Up @@ -565,6 +566,9 @@ Robert Habermeier <[email protected]>
Robert Millar <[email protected]>
Roc Yu <[email protected]>
Rohit Joshi <[email protected]> Rohit Joshi <[email protected]>
Ross Smyth <[email protected]>
Ross Smyth <[email protected]> <[email protected]>
Ross Smyth <[email protected]> <[email protected]>
Roxane Fruytier <[email protected]>
Rui <[email protected]>
Russell Johnston <[email protected]>
Expand Down
71 changes: 70 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,75 @@ impl BinOpKind {

pub type BinOp = Spanned<BinOpKind>;

// Sometimes `BinOpKind` and `AssignOpKind` need the same treatment. The
// operations covered by `AssignOpKind` are a subset of those covered by
// `BinOpKind`, so it makes sense to convert `AssignOpKind` to `BinOpKind`.
impl From<AssignOpKind> for BinOpKind {
fn from(op: AssignOpKind) -> BinOpKind {
match op {
AssignOpKind::AddAssign => BinOpKind::Add,
AssignOpKind::SubAssign => BinOpKind::Sub,
AssignOpKind::MulAssign => BinOpKind::Mul,
AssignOpKind::DivAssign => BinOpKind::Div,
AssignOpKind::RemAssign => BinOpKind::Rem,
AssignOpKind::BitXorAssign => BinOpKind::BitXor,
AssignOpKind::BitAndAssign => BinOpKind::BitAnd,
AssignOpKind::BitOrAssign => BinOpKind::BitOr,
AssignOpKind::ShlAssign => BinOpKind::Shl,
AssignOpKind::ShrAssign => BinOpKind::Shr,
}
}
}

#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
pub enum AssignOpKind {
/// The `+=` operator (addition)
AddAssign,
/// The `-=` operator (subtraction)
SubAssign,
/// The `*=` operator (multiplication)
MulAssign,
/// The `/=` operator (division)
DivAssign,
/// The `%=` operator (modulus)
RemAssign,
/// The `^=` operator (bitwise xor)
BitXorAssign,
/// The `&=` operator (bitwise and)
BitAndAssign,
/// The `|=` operator (bitwise or)
BitOrAssign,
/// The `<<=` operator (shift left)
ShlAssign,
/// The `>>=` operator (shift right)
ShrAssign,
}

impl AssignOpKind {
pub fn as_str(&self) -> &'static str {
use AssignOpKind::*;
match self {
AddAssign => "+=",
SubAssign => "-=",
MulAssign => "*=",
DivAssign => "/=",
RemAssign => "%=",
BitXorAssign => "^=",
BitAndAssign => "&=",
BitOrAssign => "|=",
ShlAssign => "<<=",
ShrAssign => ">>=",
}
}

/// AssignOps are always by value.
pub fn is_by_value(self) -> bool {
true
}
}

pub type AssignOp = Spanned<AssignOpKind>;

/// Unary operator.
///
/// Note that `&data` is not an operator, it's an `AddrOf` expression.
Expand Down Expand Up @@ -1593,7 +1662,7 @@ pub enum ExprKind {
/// An assignment with an operator.
///
/// E.g., `a += 1`.
AssignOp(BinOp, P<Expr>, P<Expr>),
AssignOp(AssignOp, P<Expr>, P<Expr>),
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
Field(P<Expr>, Ident),
/// An indexing operation (e.g., `foo[2]`).
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@ impl MetaItemInner {
}
}

/// Returns the bool if `self` is a boolean `MetaItemInner::Literal`.
pub fn boolean_literal(&self) -> Option<bool> {
match self {
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => Some(*b),
_ => None,
}
}

/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem` or if it's
/// `MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
pub fn meta_item_or_bool(&self) -> Option<&MetaItemInner> {
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_ast/src/util/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_span::kw;

use crate::ast::{self, BinOpKind, RangeLimits};
use crate::ast::{self, AssignOpKind, BinOpKind, RangeLimits};
use crate::token::{self, Token};

/// Associative operator.
Expand All @@ -9,7 +9,7 @@ pub enum AssocOp {
/// A binary op.
Binary(BinOpKind),
/// `?=` where ? is one of the assignable BinOps
AssignOp(BinOpKind),
AssignOp(AssignOpKind),
/// `=`
Assign,
/// `as`
Expand Down Expand Up @@ -44,16 +44,16 @@ impl AssocOp {
token::Or => Some(Binary(BinOpKind::BitOr)),
token::Shl => Some(Binary(BinOpKind::Shl)),
token::Shr => Some(Binary(BinOpKind::Shr)),
token::PlusEq => Some(AssignOp(BinOpKind::Add)),
token::MinusEq => Some(AssignOp(BinOpKind::Sub)),
token::StarEq => Some(AssignOp(BinOpKind::Mul)),
token::SlashEq => Some(AssignOp(BinOpKind::Div)),
token::PercentEq => Some(AssignOp(BinOpKind::Rem)),
token::CaretEq => Some(AssignOp(BinOpKind::BitXor)),
token::AndEq => Some(AssignOp(BinOpKind::BitAnd)),
token::OrEq => Some(AssignOp(BinOpKind::BitOr)),
token::ShlEq => Some(AssignOp(BinOpKind::Shl)),
token::ShrEq => Some(AssignOp(BinOpKind::Shr)),
token::PlusEq => Some(AssignOp(AssignOpKind::AddAssign)),
token::MinusEq => Some(AssignOp(AssignOpKind::SubAssign)),
token::StarEq => Some(AssignOp(AssignOpKind::MulAssign)),
token::SlashEq => Some(AssignOp(AssignOpKind::DivAssign)),
token::PercentEq => Some(AssignOp(AssignOpKind::RemAssign)),
token::CaretEq => Some(AssignOp(AssignOpKind::BitXorAssign)),
token::AndEq => Some(AssignOp(AssignOpKind::BitAndAssign)),
token::OrEq => Some(AssignOp(AssignOpKind::BitOrAssign)),
token::ShlEq => Some(AssignOp(AssignOpKind::ShlAssign)),
token::ShrEq => Some(AssignOp(AssignOpKind::ShrAssign)),
token::Lt => Some(Binary(BinOpKind::Lt)),
token::Le => Some(Binary(BinOpKind::Le)),
token::Ge => Some(Binary(BinOpKind::Ge)),
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ExprKind::Assign(el, er, span) => self.lower_expr_assign(el, er, *span, e.span),
ExprKind::AssignOp(op, el, er) => hir::ExprKind::AssignOp(
self.lower_binop(*op),
self.lower_assign_op(*op),
self.lower_expr(el),
self.lower_expr(er),
),
Expand Down Expand Up @@ -443,6 +443,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
Spanned { node: b.node, span: self.lower_span(b.span) }
}

fn lower_assign_op(&mut self, a: AssignOp) -> AssignOp {
Spanned { node: a.node, span: self.lower_span(a.span) }
}

fn lower_legacy_const_generics(
&mut self,
mut f: Expr,
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,22 +274,22 @@ impl<'a> State<'a> {

fn print_expr_binary(
&mut self,
op: ast::BinOp,
op: ast::BinOpKind,
lhs: &ast::Expr,
rhs: &ast::Expr,
fixup: FixupContext,
) {
let binop_prec = op.node.precedence();
let binop_prec = op.precedence();
let left_prec = lhs.precedence();
let right_prec = rhs.precedence();

let (mut left_needs_paren, right_needs_paren) = match op.node.fixity() {
let (mut left_needs_paren, right_needs_paren) = match op.fixity() {
Fixity::Left => (left_prec < binop_prec, right_prec <= binop_prec),
Fixity::Right => (left_prec <= binop_prec, right_prec < binop_prec),
Fixity::None => (left_prec <= binop_prec, right_prec <= binop_prec),
};

match (&lhs.kind, op.node) {
match (&lhs.kind, op) {
// These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is
// the beginning of a path type. It starts trying to parse `x as (i32 < y ...` instead
// of `(x as i32) < ...`. We need to convince it _not_ to do that.
Expand All @@ -312,7 +312,7 @@ impl<'a> State<'a> {

self.print_expr_cond_paren(lhs, left_needs_paren, fixup.leftmost_subexpression());
self.space();
self.word_space(op.node.as_str());
self.word_space(op.as_str());
self.print_expr_cond_paren(rhs, right_needs_paren, fixup.subsequent_subexpression());
}

Expand Down Expand Up @@ -410,7 +410,7 @@ impl<'a> State<'a> {
self.print_expr_method_call(seg, receiver, args, fixup);
}
ast::ExprKind::Binary(op, lhs, rhs) => {
self.print_expr_binary(*op, lhs, rhs, fixup);
self.print_expr_binary(op.node, lhs, rhs, fixup);
}
ast::ExprKind::Unary(op, expr) => {
self.print_expr_unary(*op, expr, fixup);
Expand Down Expand Up @@ -605,8 +605,7 @@ impl<'a> State<'a> {
fixup.leftmost_subexpression(),
);
self.space();
self.word(op.node.as_str());
self.word_space("=");
self.word_space(op.node.as_str());
self.print_expr_cond_paren(
rhs,
rhs.precedence() < ExprPrecedence::Assign,
Expand Down
13 changes: 0 additions & 13 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let closure = self.add_moved_or_invoked_closure_note(location, used_place, &mut err);

let mut is_loop_move = false;
let mut in_pattern = false;
let mut seen_spans = FxIndexSet::default();

for move_site in &move_site_vec {
Expand All @@ -204,7 +203,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
self.suggest_ref_or_clone(
mpi,
&mut err,
&mut in_pattern,
move_spans,
moved_place.as_ref(),
&mut has_suggest_reborrow,
Expand Down Expand Up @@ -256,15 +254,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let place = &self.move_data.move_paths[mpi].place;
let ty = place.ty(self.body, self.infcx.tcx).ty;

// If we're in pattern, we do nothing in favor of the previous suggestion (#80913).
// Same for if we're in a loop, see #101119.
if is_loop_move & !in_pattern && !matches!(use_spans, UseSpans::ClosureUse { .. }) {
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
// We have a `&mut` ref, we need to reborrow on each iteration (#62112).
self.suggest_reborrow(&mut err, span, moved_place);
}
}

if self.infcx.param_env.caller_bounds().iter().any(|c| {
c.as_trait_clause().is_some_and(|pred| {
pred.skip_binder().self_ty() == ty && self.infcx.tcx.is_fn_trait(pred.def_id())
Expand Down Expand Up @@ -330,7 +319,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
&self,
mpi: MovePathIndex,
err: &mut Diag<'infcx>,
in_pattern: &mut bool,
move_spans: UseSpans<'tcx>,
moved_place: PlaceRef<'tcx>,
has_suggest_reborrow: &mut bool,
Expand Down Expand Up @@ -545,7 +533,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
&& !move_span.is_dummy()
&& !self.infcx.tcx.sess.source_map().is_imported(move_span)
{
*in_pattern = true;
let mut sugg = vec![(pat.span.shrink_to_lo(), "ref ".to_string())];
if let Some(pat) = finder.parent_pat {
sugg.insert(0, (pat.span.shrink_to_lo(), "ref ".to_string()));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,9 +959,9 @@ fn link_natively(
}
}

let (level, src) = codegen_results.crate_info.lint_levels.linker_messages;
let level = codegen_results.crate_info.lint_levels.linker_messages;
let lint = |msg| {
lint_level(sess, LINKER_MESSAGES, level, src, None, |diag| {
lint_level(sess, LINKER_MESSAGES, level, None, |diag| {
LinkerOutput { inner: msg }.decorate_lint(diag)
})
};
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rustc_hir::CRATE_HIR_ID;
use rustc_hir::def_id::CrateNum;
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::lint::LintLevelSource;
use rustc_middle::lint::LevelAndSource;
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
Expand All @@ -45,7 +45,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_session::Session;
use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT};
use rustc_session::cstore::{self, CrateSource};
use rustc_session::lint::Level;
use rustc_session::lint::builtin::LINKER_MESSAGES;
use rustc_session::utils::NativeLibKind;
use rustc_span::Symbol;
Expand Down Expand Up @@ -341,7 +340,7 @@ impl CodegenResults {
/// Instead, encode exactly the information we need.
#[derive(Copy, Clone, Debug, Encodable, Decodable)]
pub struct CodegenLintLevels {
linker_messages: (Level, LintLevelSource),
linker_messages: LevelAndSource,
}

impl CodegenLintLevels {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
hir_id,
)
.0
.level
.is_error();
let span = ecx.cur_span();
ecx.tcx.emit_node_span_lint(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ fn print_crate_info(
// lint is unstable and feature gate isn't active, don't print
continue;
}
let level = lint_levels.lint_level(lint).0;
let level = lint_levels.lint_level(lint).level;
println_info!("{}={}", lint.name_lower(), level.as_str());
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ fn annotation_level_for_level(level: Level) -> annotate_snippets::Level {
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => {
annotate_snippets::Level::Error
}
Level::ForceWarning(_) | Level::Warning => annotate_snippets::Level::Warning,
Level::ForceWarning | Level::Warning => annotate_snippets::Level::Warning,
Level::Note | Level::OnceNote => annotate_snippets::Level::Note,
Level::Help | Level::OnceHelp => annotate_snippets::Level::Help,
// FIXME(#59346): Not sure how to map this level
Level::FailureNote => annotate_snippets::Level::Error,
Level::Allow => panic!("Should not call with Allow"),
Level::Expect(_) => panic!("Should not call with Expect"),
Level::Expect => panic!("Should not call with Expect"),
}
}

Expand Down
Loading
Loading