Skip to content

Commit 71e4c00

Browse files
committed
Auto merge of #143287 - GuillaumeGomez:rollup-fdjcti9, r=GuillaumeGomez
Rollup of 12 pull requests Successful merges: - #136801 (Implement `Random` for tuple) - #141867 (Describe Future invariants more precisely) - #142760 (docs(fs): Touch up grammar on lock api) - #143181 (Improve testing and error messages for malformed attributes) - #143210 (`tests/ui`: A New Order [19/N] ) - #143212 (`tests/ui`: A New Order [20/N]) - #143230 ([COMPILETEST-UNTANGLE 2/N] Make some compiletest errors/warnings/help more visually obvious) - #143240 (Port `#[rustc_object_lifetime_default]` to the new attribute parsing …) - #143255 (Do not enable LLD by default in the dist profile) - #143262 (mir: Mark `Statement` and `BasicBlockData` as `#[non_exhaustive]`) - #143269 (bootstrap: make comment more clear) - #143279 (Remove `ItemKind::descr` method) Failed merges: - #143237 (Port `#[no_implicit_prelude]` to the new attribute parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4e97337 + 189bfc1 commit 71e4c00

File tree

89 files changed

+1573
-574
lines changed

Some content is hidden

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

89 files changed

+1573
-574
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ pub enum AttributeKind {
296296
/// Represents `#[rustc_layout_scalar_valid_range_start]`.
297297
RustcLayoutScalarValidRangeStart(Box<u128>, Span),
298298

299+
/// Represents `#[rustc_object_lifetime_default]`.
300+
RustcObjectLifetimeDefault,
301+
299302
/// Represents `#[rustc_skip_during_method_dispatch]`.
300303
SkipDuringMethodDispatch { array: bool, boxed_slice: bool, span: Span },
301304

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl AttributeKind {
4040
PubTransparent(..) => Yes,
4141
RustcLayoutScalarValidRangeEnd(..) => Yes,
4242
RustcLayoutScalarValidRangeStart(..) => Yes,
43+
RustcObjectLifetimeDefault => No,
4344
SkipDuringMethodDispatch { .. } => No,
4445
TrackCaller(..) => Yes,
4546
Used { .. } => No,

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
2121
span: cx.attr_span,
2222
reason: match args {
2323
ArgParser::NoArgs => None,
24-
ArgParser::NameValue(name_value) => name_value.value_as_str(),
24+
ArgParser::NameValue(name_value) => {
25+
let Some(value_str) = name_value.value_as_str() else {
26+
cx.expected_string_literal(
27+
name_value.value_span,
28+
Some(&name_value.value_as_lit()),
29+
);
30+
return None;
31+
};
32+
Some(value_str)
33+
}
2534
ArgParser::List(_) => {
2635
let suggestions =
2736
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "must_use");

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@ fn parse_rustc_layout_scalar_valid_range<S: Stage>(
5757
};
5858
Some(Box::new(num.0))
5959
}
60+
61+
pub(crate) struct RustcObjectLifetimeDefaultParser;
62+
63+
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {
64+
const PATH: &[rustc_span::Symbol] = &[sym::rustc_object_lifetime_default];
65+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
66+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
67+
const TEMPLATE: AttributeTemplate = template!(Word);
68+
69+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
70+
if let Err(span) = args.no_args() {
71+
cx.expected_no_args(span);
72+
return None;
73+
}
74+
75+
Some(AttributeKind::RustcObjectLifetimeDefault)
76+
}
77+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::attributes::must_use::MustUseParser;
2929
use crate::attributes::repr::{AlignParser, ReprParser};
3030
use crate::attributes::rustc_internal::{
3131
RustcLayoutScalarValidRangeEnd, RustcLayoutScalarValidRangeStart,
32+
RustcObjectLifetimeDefaultParser,
3233
};
3334
use crate::attributes::semantics::MayDangleParser;
3435
use crate::attributes::stability::{
@@ -136,6 +137,7 @@ attribute_parsers!(
136137
Single<RustcForceInlineParser>,
137138
Single<RustcLayoutScalarValidRangeEnd>,
138139
Single<RustcLayoutScalarValidRangeStart>,
140+
Single<RustcObjectLifetimeDefaultParser>,
139141
Single<SkipDuringMethodDispatchParser>,
140142
Single<TrackCallerParser>,
141143
Single<TransparencyParser>,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
577577
diag.code(E0565);
578578
}
579579
AttributeParseErrorReason::ExpectedNameValue(None) => {
580-
diag.span_label(
581-
self.span,
582-
format!("expected this to be of the form `{name} = \"...\"`"),
583-
);
580+
// The suggestion we add below this match already contains enough information
584581
}
585582
AttributeParseErrorReason::ExpectedNameValue(Some(name)) => {
586583
diag.span_label(

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11681168
_,
11691169
mir::Rvalue::Use(mir::Operand::Copy(place)),
11701170
)),
1171+
..
11711172
}) = self.body[location.block].statements.get(location.statement_index)
11721173
{
11731174
self.body.local_decls[place.local].source_info.span

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4400,27 +4400,6 @@ impl ItemKind<'_> {
44004400
_ => return None,
44014401
})
44024402
}
4403-
4404-
pub fn descr(&self) -> &'static str {
4405-
match self {
4406-
ItemKind::ExternCrate(..) => "extern crate",
4407-
ItemKind::Use(..) => "`use` import",
4408-
ItemKind::Static(..) => "static item",
4409-
ItemKind::Const(..) => "constant item",
4410-
ItemKind::Fn { .. } => "function",
4411-
ItemKind::Macro(..) => "macro",
4412-
ItemKind::Mod(..) => "module",
4413-
ItemKind::ForeignMod { .. } => "extern block",
4414-
ItemKind::GlobalAsm { .. } => "global asm item",
4415-
ItemKind::TyAlias(..) => "type alias",
4416-
ItemKind::Enum(..) => "enum",
4417-
ItemKind::Struct(..) => "struct",
4418-
ItemKind::Union(..) => "union",
4419-
ItemKind::Trait(..) => "trait",
4420-
ItemKind::TraitAlias(..) => "trait alias",
4421-
ItemKind::Impl(..) => "implementation",
4422-
}
4423-
}
44244403
}
44254404

44264405
/// A reference from an trait to one of its associated items. This

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ impl BasicBlock {
13361336
///
13371337
/// See [`BasicBlock`] for documentation on what basic blocks are at a high level.
13381338
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
1339+
#[non_exhaustive]
13391340
pub struct BasicBlockData<'tcx> {
13401341
/// List of statements in this block.
13411342
pub statements: Vec<Statement<'tcx>>,

compiler/rustc_middle/src/mir/statement.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::ty::CoroutineArgsExt;
1111

1212
/// A statement in a basic block, including information about its source code.
1313
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
14+
#[non_exhaustive]
1415
pub struct Statement<'tcx> {
1516
pub source_info: SourceInfo,
1617
pub kind: StatementKind<'tcx>,

compiler/rustc_mir_transform/src/check_enums.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ fn split_block(
230230
let block_data = &mut basic_blocks[location.block];
231231

232232
// Drain every statement after this one and move the current terminator to a new basic block.
233-
let new_block = BasicBlockData {
234-
statements: block_data.statements.split_off(location.statement_index),
235-
terminator: block_data.terminator.take(),
236-
is_cleanup: block_data.is_cleanup,
237-
};
233+
let new_block = BasicBlockData::new_stmts(
234+
block_data.statements.split_off(location.statement_index),
235+
block_data.terminator.take(),
236+
block_data.is_cleanup,
237+
);
238238

239239
basic_blocks.push(new_block)
240240
}
@@ -270,10 +270,9 @@ fn insert_discr_cast_to_u128<'tcx>(
270270
let mu_array =
271271
local_decls.push(LocalDecl::with_source_info(mu_array_ty, source_info)).into();
272272
let rvalue = Rvalue::Cast(CastKind::Transmute, source_op, mu_array_ty);
273-
block_data.statements.push(Statement {
274-
source_info,
275-
kind: StatementKind::Assign(Box::new((mu_array, rvalue))),
276-
});
273+
block_data
274+
.statements
275+
.push(Statement::new(source_info, StatementKind::Assign(Box::new((mu_array, rvalue)))));
277276

278277
// Index into the array of MaybeUninit to get something that is actually
279278
// as wide as the discriminant.
@@ -294,10 +293,10 @@ fn insert_discr_cast_to_u128<'tcx>(
294293
let op_as_int =
295294
local_decls.push(LocalDecl::with_source_info(operand_int_ty, source_info)).into();
296295
let rvalue = Rvalue::Cast(CastKind::Transmute, source_op, operand_int_ty);
297-
block_data.statements.push(Statement {
296+
block_data.statements.push(Statement::new(
298297
source_info,
299-
kind: StatementKind::Assign(Box::new((op_as_int, rvalue))),
300-
});
298+
StatementKind::Assign(Box::new((op_as_int, rvalue))),
299+
));
301300

302301
(CastKind::IntToInt, Operand::Copy(op_as_int))
303302
};
@@ -306,18 +305,18 @@ fn insert_discr_cast_to_u128<'tcx>(
306305
let rvalue = Rvalue::Cast(cast_kind, discr_ty_bits, discr.ty);
307306
let discr_in_discr_ty =
308307
local_decls.push(LocalDecl::with_source_info(discr.ty, source_info)).into();
309-
block_data.statements.push(Statement {
308+
block_data.statements.push(Statement::new(
310309
source_info,
311-
kind: StatementKind::Assign(Box::new((discr_in_discr_ty, rvalue))),
312-
});
310+
StatementKind::Assign(Box::new((discr_in_discr_ty, rvalue))),
311+
));
313312

314313
// Cast the discriminant to a u128 (base for comparisions of enum discriminants).
315314
let const_u128 = Ty::new_uint(tcx, ty::UintTy::U128);
316315
let rvalue = Rvalue::Cast(CastKind::IntToInt, Operand::Copy(discr_in_discr_ty), const_u128);
317316
let discr = local_decls.push(LocalDecl::with_source_info(const_u128, source_info)).into();
318317
block_data
319318
.statements
320-
.push(Statement { source_info, kind: StatementKind::Assign(Box::new((discr, rvalue))) });
319+
.push(Statement::new(source_info, StatementKind::Assign(Box::new((discr, rvalue)))));
321320

322321
discr
323322
}
@@ -390,17 +389,17 @@ fn insert_uninhabited_enum_check<'tcx>(
390389
) {
391390
let is_ok: Place<'_> =
392391
local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
393-
block_data.statements.push(Statement {
392+
block_data.statements.push(Statement::new(
394393
source_info,
395-
kind: StatementKind::Assign(Box::new((
394+
StatementKind::Assign(Box::new((
396395
is_ok,
397396
Rvalue::Use(Operand::Constant(Box::new(ConstOperand {
398397
span: source_info.span,
399398
user_ty: None,
400399
const_: Const::Val(ConstValue::from_bool(false), tcx.types.bool),
401400
}))),
402401
))),
403-
});
402+
));
404403

405404
block_data.terminator = Some(Terminator {
406405
source_info,
@@ -463,27 +462,27 @@ fn insert_niche_check<'tcx>(
463462

464463
let discr_diff: Place<'_> =
465464
local_decls.push(LocalDecl::with_source_info(tcx.types.u128, source_info)).into();
466-
block_data.statements.push(Statement {
465+
block_data.statements.push(Statement::new(
467466
source_info,
468-
kind: StatementKind::Assign(Box::new((
467+
StatementKind::Assign(Box::new((
469468
discr_diff,
470469
Rvalue::BinaryOp(BinOp::Sub, Box::new((Operand::Copy(discr), start_const))),
471470
))),
472-
});
471+
));
473472

474473
let is_ok: Place<'_> =
475474
local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
476-
block_data.statements.push(Statement {
475+
block_data.statements.push(Statement::new(
477476
source_info,
478-
kind: StatementKind::Assign(Box::new((
477+
StatementKind::Assign(Box::new((
479478
is_ok,
480479
Rvalue::BinaryOp(
481480
// This is a `WrappingRange`, so make sure to get the wrapping right.
482481
BinOp::Le,
483482
Box::new((Operand::Copy(discr_diff), end_start_diff_const)),
484483
),
485484
))),
486-
});
485+
));
487486

488487
block_data.terminator = Some(Terminator {
489488
source_info,

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ fn emit_malformed_attribute(
303303
| sym::must_use
304304
| sym::track_caller
305305
| sym::link_name
306+
| sym::export_name
307+
| sym::rustc_macro_transparency
308+
| sym::link_section
309+
| sym::rustc_layout_scalar_valid_range_start
310+
| sym::rustc_layout_scalar_valid_range_end
306311
) {
307312
return;
308313
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
164164
}
165165
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
166166
}
167-
167+
Attribute::Parsed(AttributeKind::RustcObjectLifetimeDefault) => {
168+
self.check_object_lifetime_default(hir_id);
169+
}
168170
&Attribute::Parsed(AttributeKind::PubTransparent(attr_span)) => {
169171
self.check_rustc_pub_transparent(attr_span, span, attrs)
170172
}
@@ -303,7 +305,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
303305
[sym::no_implicit_prelude, ..] => {
304306
self.check_generic_attr(hir_id, attr, target, Target::Mod)
305307
}
306-
[sym::rustc_object_lifetime_default, ..] => self.check_object_lifetime_default(hir_id),
307308
[sym::proc_macro, ..] => {
308309
self.check_proc_macro(hir_id, target, ProcMacroKind::FunctionLike)
309310
}
@@ -2831,7 +2832,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
28312832
.find(|item| !item.span.is_dummy()) // Skip prelude `use`s
28322833
.map(|item| errors::ItemFollowingInnerAttr {
28332834
span: if let Some(ident) = item.kind.ident() { ident.span } else { item.span },
2834-
kind: item.kind.descr(),
2835+
kind: tcx.def_descr(item.owner_id.to_def_id()),
28352836
});
28362837
let err = tcx.dcx().create_err(errors::InvalidAttrAtCrateLevel {
28372838
span,

library/core/src/future/future.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::ops;
44
use crate::pin::Pin;
55
use crate::task::{Context, Poll};
66

7-
/// A future represents an asynchronous computation obtained by use of [`async`].
7+
/// A future represents an asynchronous computation, commonly obtained by use of
8+
/// [`async`].
89
///
910
/// A future is a value that might not have finished computing yet. This kind of
1011
/// "asynchronous value" makes it possible for a thread to continue doing useful
@@ -68,13 +69,21 @@ pub trait Future {
6869
///
6970
/// # Runtime characteristics
7071
///
71-
/// Futures alone are *inert*; they must be *actively* `poll`ed to make
72-
/// progress, meaning that each time the current task is woken up, it should
73-
/// actively re-`poll` pending futures that it still has an interest in.
72+
/// Futures alone are *inert*; they must be *actively* `poll`ed for the
73+
/// underlying computation to make progress, meaning that each time the
74+
/// current task is woken up, it should actively re-`poll` pending futures
75+
/// that it still has an interest in.
7476
///
75-
/// The `poll` function is not called repeatedly in a tight loop -- instead,
76-
/// it should only be called when the future indicates that it is ready to
77-
/// make progress (by calling `wake()`). If you're familiar with the
77+
/// Having said that, some Futures may represent a value that is being
78+
/// computed in a different task. In this case, the future's underlying
79+
/// computation is simply acting as a conduit for a value being computed
80+
/// by that other task, which will proceed independently of the Future.
81+
/// Futures of this kind are typically obtained when spawning a new task into an
82+
/// async runtime.
83+
///
84+
/// The `poll` function should not be called repeatedly in a tight loop --
85+
/// instead, it should only be called when the future indicates that it is
86+
/// ready to make progress (by calling `wake()`). If you're familiar with the
7887
/// `poll(2)` or `select(2)` syscalls on Unix it's worth noting that futures
7988
/// typically do *not* suffer the same problems of "all wakeups must poll
8089
/// all events"; they are more like `epoll(4)`.

library/core/src/primitive_docs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,11 +1083,13 @@ mod prim_str {}
10831083
/// * [`Debug`]
10841084
/// * [`Default`]
10851085
/// * [`Hash`]
1086+
/// * [`Random`]
10861087
/// * [`From<[T; N]>`][from]
10871088
///
10881089
/// [from]: convert::From
10891090
/// [`Debug`]: fmt::Debug
10901091
/// [`Hash`]: hash::Hash
1092+
/// [`Random`]: random::Random
10911093
///
10921094
/// The following traits are implemented for tuples of any length. These traits have
10931095
/// implementations that are automatically generated by the compiler, so are not limited by

library/core/src/tuple.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::cmp::Ordering::{self, *};
44
use crate::marker::{ConstParamTy_, PointeeSized, StructuralPartialEq, UnsizedConstParamTy};
55
use crate::ops::ControlFlow::{self, Break, Continue};
6+
use crate::random::{Random, RandomSource};
67

78
// Recursive macro for implementing n-ary tuple functions and operations
89
//
@@ -139,6 +140,16 @@ macro_rules! tuple_impls {
139140
}
140141
}
141142

143+
maybe_tuple_doc! {
144+
$($T)+ @
145+
#[unstable(feature = "random", issue = "130703")]
146+
impl<$($T: Random),+> Random for ($($T,)+) {
147+
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
148+
($({ let x: $T = Random::random(source); x},)+)
149+
}
150+
}
151+
}
152+
142153
maybe_tuple_doc! {
143154
$($T)+ @
144155
#[stable(feature = "array_tuple_conv", since = "1.71.0")]

0 commit comments

Comments
 (0)