Skip to content

Commit 00ebeb8

Browse files
committed
Auto merge of rust-lang#98612 - Dylan-DPC:rollup-7tasikc, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - rust-lang#97346 (Remove a back-compat hack on lazy TAIT) - rust-lang#98261 (Remove `MAX_SUGGESTION_HIGHLIGHT_LINES`) - rust-lang#98337 ([RFC 2011] Optimize non-consuming operators) - rust-lang#98384 (Fix RSS reporting on macOS) - rust-lang#98420 (translation: lint fix + more migration) - rust-lang#98430 (Refactor iter adapters with less macros) - rust-lang#98555 (Hermit: Fix initializing lazy locks) - rust-lang#98595 (Implement `Send` and `Sync` for `ThinBox<T>`) - rust-lang#98597 (Remove unstable CStr/CString change from 1.62 release note) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents baf382e + 66b8060 commit 00ebeb8

File tree

42 files changed

+651
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+651
-445
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4280,6 +4280,7 @@ dependencies = [
42804280
"rustc_data_structures",
42814281
"rustc_errors",
42824282
"rustc_hir",
4283+
"rustc_macros",
42834284
"rustc_middle",
42844285
"rustc_session",
42854286
"rustc_span",

RELEASES.md

-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Compiler
2929
Libraries
3030
---------
3131

32-
- [Move `CStr` to libcore, and `CString` to liballoc][94079]
3332
- [Windows: Use a pipe relay for chaining pipes][95841]
3433
- [Replace Linux Mutex and Condvar with futex based ones.][95035]
3534
- [Replace RwLock by a futex based one on Linux][95801]
@@ -90,7 +89,6 @@ and related tools.
9089

9190
[93313]: https://github.com/rust-lang/rust/pull/93313/
9291
[93969]: https://github.com/rust-lang/rust/pull/93969/
93-
[94079]: https://github.com/rust-lang/rust/pull/94079/
9492
[94206]: https://github.com/rust-lang/rust/pull/94206/
9593
[94457]: https://github.com/rust-lang/rust/pull/94457/
9694
[94775]: https://github.com/rust-lang/rust/pull/94775/

compiler/rustc_borrowck/src/borrowck_errors.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed, MultiSpan};
1+
use rustc_errors::{
2+
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
3+
};
24
use rustc_middle::ty::{self, Ty, TyCtxt};
35
use rustc_span::Span;
46

@@ -476,10 +478,11 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
476478
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
477479
}
478480

481+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
479482
fn struct_span_err_with_code<S: Into<MultiSpan>>(
480483
&self,
481484
sp: S,
482-
msg: &str,
485+
msg: impl Into<DiagnosticMessage>,
483486
code: DiagnosticId,
484487
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
485488
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)

compiler/rustc_borrowck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(let_else)]
77
#![feature(min_specialization)]
88
#![feature(never_type)]
9+
#![feature(rustc_attrs)]
910
#![feature(stmt_expr_attributes)]
1011
#![feature(trusted_step)]
1112
#![feature(try_blocks)]

compiler/rustc_builtin_macros/src/assert/context.rs

+81-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::assert::expr_if_not;
21
use rustc_ast::{
32
attr,
43
ptr::P,
54
token,
65
tokenstream::{DelimSpan, TokenStream, TokenTree},
7-
BorrowKind, Expr, ExprKind, ItemKind, MacArgs, MacCall, MacDelimiter, Mutability, Path,
8-
PathSegment, Stmt, StructRest, UseTree, UseTreeKind, DUMMY_NODE_ID,
6+
BinOpKind, BorrowKind, Expr, ExprKind, ItemKind, MacArgs, MacCall, MacDelimiter, Mutability,
7+
Path, PathSegment, Stmt, StructRest, UnOp, UseTree, UseTreeKind, DUMMY_NODE_ID,
98
};
109
use rustc_ast_pretty::pprust;
1110
use rustc_data_structures::fx::FxHashSet;
@@ -16,11 +15,19 @@ use rustc_span::{
1615
};
1716

1817
pub(super) struct Context<'cx, 'a> {
18+
// An optimization.
19+
//
20+
// Elements that aren't consumed (PartialEq, PartialOrd, ...) can be copied **after** the
21+
// `assert!` expression fails rather than copied on-the-fly.
22+
best_case_captures: Vec<Stmt>,
1923
// Top-level `let captureN = Capture::new()` statements
2024
capture_decls: Vec<Capture>,
2125
cx: &'cx ExtCtxt<'a>,
2226
// Formatting string used for debugging
2327
fmt_string: String,
28+
// If the current expression being visited consumes itself. Used to construct
29+
// `best_case_captures`.
30+
is_consumed: bool,
2431
// Top-level `let __local_bindN = &expr` statements
2532
local_bind_decls: Vec<Stmt>,
2633
// Used to avoid capturing duplicated paths
@@ -36,9 +43,11 @@ pub(super) struct Context<'cx, 'a> {
3643
impl<'cx, 'a> Context<'cx, 'a> {
3744
pub(super) fn new(cx: &'cx ExtCtxt<'a>, span: Span) -> Self {
3845
Self {
46+
best_case_captures: <_>::default(),
3947
capture_decls: <_>::default(),
4048
cx,
4149
fmt_string: <_>::default(),
50+
is_consumed: true,
4251
local_bind_decls: <_>::default(),
4352
paths: <_>::default(),
4453
span,
@@ -69,14 +78,22 @@ impl<'cx, 'a> Context<'cx, 'a> {
6978
self.manage_cond_expr(&mut cond_expr);
7079
let initial_imports = self.build_initial_imports();
7180
let panic = self.build_panic(&expr_str, panic_path);
81+
let cond_expr_with_unlikely = self.build_unlikely(cond_expr);
82+
83+
let Self { best_case_captures, capture_decls, cx, local_bind_decls, span, .. } = self;
7284

73-
let Self { capture_decls, cx, local_bind_decls, span, .. } = self;
85+
let mut assert_then_stmts = Vec::with_capacity(2);
86+
assert_then_stmts.extend(best_case_captures);
87+
assert_then_stmts.push(self.cx.stmt_expr(panic));
88+
let assert_then = self.cx.block(span, assert_then_stmts);
7489

7590
let mut stmts = Vec::with_capacity(4);
7691
stmts.push(initial_imports);
7792
stmts.extend(capture_decls.into_iter().map(|c| c.decl));
7893
stmts.extend(local_bind_decls);
79-
stmts.push(cx.stmt_expr(expr_if_not(cx, span, cond_expr, panic, None)));
94+
stmts.push(
95+
cx.stmt_expr(cx.expr(span, ExprKind::If(cond_expr_with_unlikely, assert_then, None))),
96+
);
8097
cx.expr_block(cx.block(span, stmts))
8198
}
8299

@@ -115,6 +132,16 @@ impl<'cx, 'a> Context<'cx, 'a> {
115132
)
116133
}
117134

135+
/// Takes the conditional expression of `assert!` and then wraps it inside `unlikely`
136+
fn build_unlikely(&self, cond_expr: P<Expr>) -> P<Expr> {
137+
let unlikely_path = self.cx.std_path(&[sym::intrinsics, sym::unlikely]);
138+
self.cx.expr_call(
139+
self.span,
140+
self.cx.expr_path(self.cx.path(self.span, unlikely_path)),
141+
vec![self.cx.expr(self.span, ExprKind::Unary(UnOp::Not, cond_expr))],
142+
)
143+
}
144+
118145
/// The necessary custom `panic!(...)` expression.
119146
///
120147
/// panic!(
@@ -167,17 +194,39 @@ impl<'cx, 'a> Context<'cx, 'a> {
167194
/// See [Self::manage_initial_capture] and [Self::manage_try_capture]
168195
fn manage_cond_expr(&mut self, expr: &mut P<Expr>) {
169196
match (*expr).kind {
170-
ExprKind::AddrOf(_, _, ref mut local_expr) => {
171-
self.manage_cond_expr(local_expr);
197+
ExprKind::AddrOf(_, mutability, ref mut local_expr) => {
198+
self.with_is_consumed_management(
199+
matches!(mutability, Mutability::Mut),
200+
|this| this.manage_cond_expr(local_expr)
201+
);
172202
}
173203
ExprKind::Array(ref mut local_exprs) => {
174204
for local_expr in local_exprs {
175205
self.manage_cond_expr(local_expr);
176206
}
177207
}
178-
ExprKind::Binary(_, ref mut lhs, ref mut rhs) => {
179-
self.manage_cond_expr(lhs);
180-
self.manage_cond_expr(rhs);
208+
ExprKind::Binary(ref op, ref mut lhs, ref mut rhs) => {
209+
self.with_is_consumed_management(
210+
matches!(
211+
op.node,
212+
BinOpKind::Add
213+
| BinOpKind::And
214+
| BinOpKind::BitAnd
215+
| BinOpKind::BitOr
216+
| BinOpKind::BitXor
217+
| BinOpKind::Div
218+
| BinOpKind::Mul
219+
| BinOpKind::Or
220+
| BinOpKind::Rem
221+
| BinOpKind::Shl
222+
| BinOpKind::Shr
223+
| BinOpKind::Sub
224+
),
225+
|this| {
226+
this.manage_cond_expr(lhs);
227+
this.manage_cond_expr(rhs);
228+
}
229+
);
181230
}
182231
ExprKind::Call(_, ref mut local_exprs) => {
183232
for local_expr in local_exprs {
@@ -228,8 +277,11 @@ impl<'cx, 'a> Context<'cx, 'a> {
228277
self.manage_cond_expr(local_expr);
229278
}
230279
}
231-
ExprKind::Unary(_, ref mut local_expr) => {
232-
self.manage_cond_expr(local_expr);
280+
ExprKind::Unary(un_op, ref mut local_expr) => {
281+
self.with_is_consumed_management(
282+
matches!(un_op, UnOp::Neg | UnOp::Not),
283+
|this| this.manage_cond_expr(local_expr)
284+
);
233285
}
234286
// Expressions that are not worth or can not be captured.
235287
//
@@ -337,9 +389,23 @@ impl<'cx, 'a> Context<'cx, 'a> {
337389
))
338390
.add_trailing_semicolon();
339391
let local_bind_path = self.cx.expr_path(Path::from_ident(local_bind));
340-
let ret = self.cx.stmt_expr(local_bind_path);
341-
let block = self.cx.expr_block(self.cx.block(self.span, vec![try_capture_call, ret]));
342-
*expr = self.cx.expr_deref(self.span, block);
392+
let rslt = if self.is_consumed {
393+
let ret = self.cx.stmt_expr(local_bind_path);
394+
self.cx.expr_block(self.cx.block(self.span, vec![try_capture_call, ret]))
395+
} else {
396+
self.best_case_captures.push(try_capture_call);
397+
local_bind_path
398+
};
399+
*expr = self.cx.expr_deref(self.span, rslt);
400+
}
401+
402+
// Calls `f` with the internal `is_consumed` set to `curr_is_consumed` and then
403+
// sets the internal `is_consumed` back to its original value.
404+
fn with_is_consumed_management(&mut self, curr_is_consumed: bool, f: impl FnOnce(&mut Self)) {
405+
let prev_is_consumed = self.is_consumed;
406+
self.is_consumed = curr_is_consumed;
407+
f(self);
408+
self.is_consumed = prev_is_consumed;
343409
}
344410
}
345411

compiler/rustc_data_structures/src/profiling.rs

+18
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,24 @@ cfg_if! {
826826
}
827827
}
828828
}
829+
} else if #[cfg(target_os = "macos")] {
830+
pub fn get_resident_set_size() -> Option<usize> {
831+
use libc::{c_int, c_void, getpid, proc_pidinfo, proc_taskinfo, PROC_PIDTASKINFO};
832+
use std::mem;
833+
const PROC_TASKINFO_SIZE: c_int = mem::size_of::<proc_taskinfo>() as c_int;
834+
835+
unsafe {
836+
let mut info: proc_taskinfo = mem::zeroed();
837+
let info_ptr = &mut info as *mut proc_taskinfo as *mut c_void;
838+
let pid = getpid() as c_int;
839+
let ret = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, info_ptr, PROC_TASKINFO_SIZE);
840+
if ret == PROC_TASKINFO_SIZE {
841+
Some(info.pti_resident_size as usize)
842+
} else {
843+
None
844+
}
845+
}
846+
}
829847
} else if #[cfg(unix)] {
830848
pub fn get_resident_set_size() -> Option<usize> {
831849
let field = 1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
privacy-field-is-private = field `{$field_name}` of {$variant_descr} `{$def_path_str}` is private
2+
privacy-field-is-private-is-update-syntax-label = field `{$field_name}` is private
3+
privacy-field-is-private-label = private field
4+
5+
privacy-item-is-private = {$kind} `{$descr}` is private
6+
.label = private {$kind}
7+
privacy-unnamed-item-is-private = {$kind} is private
8+
.label = private {$kind}
9+
10+
privacy-in-public-interface = {$vis_descr} {$kind} `{$descr}` in public interface
11+
.label = can't leak {$vis_descr} {$kind}
12+
.visibility-label = `{$descr}` declared as {$vis_descr}

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
3232
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
3333
fluent_messages! {
3434
parser => "../locales/en-US/parser.ftl",
35+
privacy => "../locales/en-US/privacy.ftl",
3536
typeck => "../locales/en-US/typeck.ftl",
3637
builtin_macros => "../locales/en-US/builtin_macros.ftl",
3738
}

compiler/rustc_errors/src/emitter.rs

-5
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,6 @@ impl Emitter for SilentEmitter {
656656
}
657657
}
658658

659-
/// Maximum number of lines we will print for a multiline suggestion; arbitrary.
660-
///
661-
/// This should be replaced with a more involved mechanism to output multiline suggestions that
662-
/// more closely mimics the regular diagnostic output, where irrelevant code lines are elided.
663-
pub const MAX_SUGGESTION_HIGHLIGHT_LINES: usize = 6;
664659
/// Maximum number of suggestions to be shown
665660
///
666661
/// Arbitrary, but taken from trait import suggestion limit

compiler/rustc_expand/src/base.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ impl<'a> ExtCtxt<'a> {
10771077
self.current_expansion.id.expansion_cause()
10781078
}
10791079

1080+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
10801081
pub fn struct_span_err<S: Into<MultiSpan>>(
10811082
&self,
10821083
sp: S,
@@ -1101,9 +1102,11 @@ impl<'a> ExtCtxt<'a> {
11011102
///
11021103
/// Compilation will be stopped in the near future (at the end of
11031104
/// the macro expansion phase).
1105+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11041106
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
11051107
self.sess.parse_sess.span_diagnostic.span_err(sp, msg);
11061108
}
1109+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11071110
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
11081111
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
11091112
}

compiler/rustc_expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(proc_macro_diagnostic)]
1010
#![feature(proc_macro_internals)]
1111
#![feature(proc_macro_span)]
12+
#![feature(rustc_attrs)]
1213
#![feature(try_blocks)]
1314
#![recursion_limit = "256"]
1415

compiler/rustc_infer/src/infer/opaque_types.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,19 @@ pub struct OpaqueTypeDecl<'tcx> {
3939
}
4040

4141
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
42-
/// This is a backwards compatibility hack to prevent breaking changes from
43-
/// lazy TAIT around RPIT handling.
44-
pub fn replace_opaque_types_with_inference_vars<T: TypeFoldable<'tcx>>(
42+
pub fn replace_opaque_types_with_inference_vars(
4543
&self,
46-
value: T,
44+
ty: Ty<'tcx>,
4745
body_id: HirId,
4846
span: Span,
4947
code: ObligationCauseCode<'tcx>,
5048
param_env: ty::ParamEnv<'tcx>,
51-
) -> InferOk<'tcx, T> {
52-
if !value.has_opaque_types() {
53-
return InferOk { value, obligations: vec![] };
49+
) -> InferOk<'tcx, Ty<'tcx>> {
50+
if !ty.has_opaque_types() {
51+
return InferOk { value: ty, obligations: vec![] };
5452
}
5553
let mut obligations = vec![];
56-
let value = value.fold_with(&mut ty::fold::BottomUpFolder {
54+
let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
5755
tcx: self.tcx,
5856
lt_op: |lt| lt,
5957
ct_op: |ct| ct,

compiler/rustc_lint/src/internal.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,12 @@ impl LateLintPass<'_> for Diagnostics {
406406
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
407407
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
408408
debug!(?span, ?def_id, ?substs);
409-
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) &&
410-
!cx.tcx.has_attr(instance.def_id(), sym::rustc_lint_diagnostics)
411-
{
409+
let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs)
410+
.ok()
411+
.and_then(|inst| inst)
412+
.map(|inst| cx.tcx.has_attr(inst.def_id(), sym::rustc_lint_diagnostics))
413+
.unwrap_or(false);
414+
if !has_attr {
412415
return;
413416
}
414417

compiler/rustc_parse/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(let_chains)]
77
#![feature(let_else)]
88
#![feature(never_type)]
9+
#![feature(rustc_attrs)]
910
#![recursion_limit = "256"]
1011

1112
#[macro_use]

compiler/rustc_parse/src/parser/diagnostics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'a> DerefMut for SnapshotParser<'a> {
357357
}
358358

359359
impl<'a> Parser<'a> {
360+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
360361
pub(super) fn span_err<S: Into<MultiSpan>>(
361362
&self,
362363
sp: S,
@@ -365,6 +366,7 @@ impl<'a> Parser<'a> {
365366
err.span_err(sp, self.diagnostic())
366367
}
367368

369+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
368370
pub fn struct_span_err<S: Into<MultiSpan>>(
369371
&self,
370372
sp: S,

compiler/rustc_privacy/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
rustc_middle = { path = "../rustc_middle" }
87
rustc_ast = { path = "../rustc_ast" }
98
rustc_attr = { path = "../rustc_attr" }
9+
rustc_data_structures = { path = "../rustc_data_structures" }
1010
rustc_errors = { path = "../rustc_errors" }
1111
rustc_hir = { path = "../rustc_hir" }
12-
rustc_typeck = { path = "../rustc_typeck" }
12+
rustc_macros = { path = "../rustc_macros" }
13+
rustc_middle = { path = "../rustc_middle" }
1314
rustc_session = { path = "../rustc_session" }
1415
rustc_span = { path = "../rustc_span" }
15-
rustc_data_structures = { path = "../rustc_data_structures" }
1616
rustc_trait_selection = { path = "../rustc_trait_selection" }
17+
rustc_typeck = { path = "../rustc_typeck" }
1718
tracing = "0.1"

0 commit comments

Comments
 (0)