Skip to content

Commit 65c55bf

Browse files
committed
Auto merge of #91159 - matthiaskrgr:rollup-91mgg5v, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #90856 (Suggestion to wrap inner types using 'allocator_api' in tuple) - #91103 (Inhibit clicks on summary's children) - #91137 (Give people a single link they can click in the contributing guide) - #91140 (Split inline const to two feature gates and mark expression position inline const complete) - #91148 (Use `derive_default_enum` in the compiler) - #91153 (kernel_copy: avoid panic on unexpected OS error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7b3cd07 + 3dc0011 commit 65c55bf

Some content is hidden

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

51 files changed

+234
-90
lines changed

CONTRIBUTING.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
Thank you for your interest in contributing to Rust! There are many ways to contribute
44
and we appreciate all of them.
55

6+
The best way to get started is by asking for help in the [#new
7+
members](https://rust-lang.zulipchat.com/#narrow/stream/122652-new-members)
8+
Zulip stream. We have lots of docs below of how to get started on your own, but
9+
the Zulip stream is the best place to *ask* for help.
10+
611
Documentation for contributing to Rust is located in the [Guide to Rustc Development](https://rustc-dev-guide.rust-lang.org/),
712
commonly known as the [rustc-dev-guide]. Despite the name, this guide documents
8-
not just how to develop rustc (the Rust compiler), but also how to contribute to any part
9-
of the Rust project.
10-
11-
To get started with contributing, please read the [Contributing to Rust] chapter of the guide.
12-
That chapter explains how to get your development environment set up and how to get help.
13+
not just how to develop rustc (the Rust compiler), but also how to contribute to the standard library and rustdoc.
1314

1415
## About the [rustc-dev-guide]
1516

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ standard library, and documentation.
77

88
**Note: this README is for _users_ rather than _contributors_.
99
If you wish to _contribute_ to the compiler, you should read the
10-
[Getting Started][gettingstarted] section of the rustc-dev-guide instead.**
10+
[Getting Started][gettingstarted] section of the rustc-dev-guide instead.
11+
You can ask for help in the [#new members Zulip stream][new-members].**
12+
13+
[new-members]: https://rust-lang.zulipchat.com/#narrow/stream/122652-new-members
1114

1215
## Quick Start
1316

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
719719
gate_all!(const_trait_impl, "const trait impls are experimental");
720720
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
721721
gate_all!(inline_const, "inline-const is experimental");
722+
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
722723
gate_all!(
723724
const_generics_defaults,
724725
"default values for const generic parameters are experimental"

compiler/rustc_feature/src/active.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ declare_features! (
409409
/// Allows associated types in inherent impls.
410410
(incomplete, inherent_associated_types, "1.52.0", Some(8995), None),
411411
/// Allow anonymous constants from an inline `const` block
412-
(incomplete, inline_const, "1.49.0", Some(76001), None),
412+
(active, inline_const, "1.49.0", Some(76001), None),
413+
/// Allow anonymous constants from an inline `const` block in pattern position
414+
(incomplete, inline_const_pat, "1.58.0", Some(76001), None),
413415
/// Allows using `pointer` and `reference` in intra-doc links
414416
(active, intra_doc_pointers, "1.51.0", Some(80896), None),
415417
/// Allows `#[instruction_set(_)]` attribute

compiler/rustc_infer/src/infer/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable<
9595
/// This is used so that the region values inferred by HIR region solving are
9696
/// not exposed, and so that we can avoid doing work in HIR typeck that MIR
9797
/// typeck will also do.
98-
#[derive(Copy, Clone, Debug)]
98+
#[derive(Copy, Clone, Debug, Default)]
9999
pub enum RegionckMode {
100100
/// The default mode: report region errors, don't erase regions.
101+
#[default]
101102
Solve,
102103
/// Erase the results of region after solving.
103104
Erase {
@@ -108,12 +109,6 @@ pub enum RegionckMode {
108109
},
109110
}
110111

111-
impl Default for RegionckMode {
112-
fn default() -> Self {
113-
RegionckMode::Solve
114-
}
115-
}
116-
117112
impl RegionckMode {
118113
/// Indicates that the MIR borrowck will repeat these region
119114
/// checks, so we should ignore errors if NLL is (unconditionally)

compiler/rustc_infer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1616
#![feature(bool_to_option)]
1717
#![feature(box_patterns)]
18+
#![feature(derive_default_enum)]
1819
#![feature(extend_one)]
1920
#![feature(iter_zip)]
2021
#![feature(let_else)]

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![feature(bool_to_option)]
3131
#![feature(box_patterns)]
3232
#![feature(core_intrinsics)]
33+
#![feature(derive_default_enum)]
3334
#![feature(discriminant_kind)]
3435
#![feature(exhaustive_patterns)]
3536
#![feature(if_let_guard)]

compiler/rustc_middle/src/middle/stability.rs

+53-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
pub use self::StabilityLevel::*;
55

6-
use crate::ty::{self, TyCtxt};
6+
use crate::ty::{self, DefIdTree, TyCtxt};
77
use rustc_ast::NodeId;
88
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -90,6 +90,7 @@ pub fn report_unstable(
9090
feature: Symbol,
9191
reason: Option<Symbol>,
9292
issue: Option<NonZeroU32>,
93+
suggestion: Option<(Span, String, String, Applicability)>,
9394
is_soft: bool,
9495
span: Span,
9596
soft_handler: impl FnOnce(&'static Lint, Span, &str),
@@ -116,8 +117,12 @@ pub fn report_unstable(
116117
if is_soft {
117118
soft_handler(SOFT_UNSTABLE, span, &msg)
118119
} else {
119-
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
120-
.emit();
120+
let mut err =
121+
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg);
122+
if let Some((inner_types, ref msg, sugg, applicability)) = suggestion {
123+
err.span_suggestion(inner_types, msg, sugg, applicability);
124+
}
125+
err.emit();
121126
}
122127
}
123128
}
@@ -271,7 +276,13 @@ pub enum EvalResult {
271276
Allow,
272277
/// We cannot use the item because it is unstable and we did not provide the
273278
/// corresponding feature gate.
274-
Deny { feature: Symbol, reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
279+
Deny {
280+
feature: Symbol,
281+
reason: Option<Symbol>,
282+
issue: Option<NonZeroU32>,
283+
suggestion: Option<(Span, String, String, Applicability)>,
284+
is_soft: bool,
285+
},
275286
/// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
276287
Unmarked,
277288
}
@@ -292,6 +303,32 @@ fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
292303
}
293304
}
294305

306+
// See issue #83250.
307+
fn suggestion_for_allocator_api(
308+
tcx: TyCtxt<'_>,
309+
def_id: DefId,
310+
span: Span,
311+
feature: Symbol,
312+
) -> Option<(Span, String, String, Applicability)> {
313+
if feature == sym::allocator_api {
314+
if let Some(trait_) = tcx.parent(def_id) {
315+
if tcx.is_diagnostic_item(sym::Vec, trait_) {
316+
let sm = tcx.sess.parse_sess.source_map();
317+
let inner_types = sm.span_extend_to_prev_char(span, '<', true);
318+
if let Ok(snippet) = sm.span_to_snippet(inner_types) {
319+
return Some((
320+
inner_types,
321+
"consider wrapping the inner types in tuple".to_string(),
322+
format!("({})", snippet),
323+
Applicability::MaybeIncorrect,
324+
));
325+
}
326+
}
327+
}
328+
}
329+
None
330+
}
331+
295332
impl<'tcx> TyCtxt<'tcx> {
296333
/// Evaluates the stability of an item.
297334
///
@@ -406,7 +443,8 @@ impl<'tcx> TyCtxt<'tcx> {
406443
}
407444
}
408445

409-
EvalResult::Deny { feature, reason, issue, is_soft }
446+
let suggestion = suggestion_for_allocator_api(self, def_id, span, feature);
447+
EvalResult::Deny { feature, reason, issue, suggestion, is_soft }
410448
}
411449
Some(_) => {
412450
// Stable APIs are always ok to call and deprecated APIs are
@@ -457,9 +495,16 @@ impl<'tcx> TyCtxt<'tcx> {
457495
};
458496
match self.eval_stability(def_id, id, span, method_span) {
459497
EvalResult::Allow => {}
460-
EvalResult::Deny { feature, reason, issue, is_soft } => {
461-
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)
462-
}
498+
EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => report_unstable(
499+
self.sess,
500+
feature,
501+
reason,
502+
issue,
503+
suggestion,
504+
is_soft,
505+
span,
506+
soft_handler,
507+
),
463508
EvalResult::Unmarked => unmarked(span, def_id),
464509
}
465510
}

compiler/rustc_middle/src/ty/sty.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -2263,10 +2263,11 @@ impl<'tcx> TyS<'tcx> {
22632263
/// a miscompilation or unsoundness.
22642264
///
22652265
/// When in doubt, use `VarianceDiagInfo::default()`
2266-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
2266+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
22672267
pub enum VarianceDiagInfo<'tcx> {
22682268
/// No additional information - this is the default.
22692269
/// We will not add any additional information to error messages.
2270+
#[default]
22702271
None,
22712272
/// We switched our variance because a type occurs inside
22722273
/// the generic argument of a mutable reference or pointer
@@ -2301,9 +2302,3 @@ impl<'tcx> VarianceDiagInfo<'tcx> {
23012302
}
23022303
}
23032304
}
2304-
2305-
impl<'tcx> Default for VarianceDiagInfo<'tcx> {
2306-
fn default() -> Self {
2307-
Self::None
2308-
}
2309-
}

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ impl<'a> Parser<'a> {
12431243
} else if self.eat_keyword(kw::Unsafe) {
12441244
self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs)
12451245
} else if self.check_inline_const(0) {
1246-
self.parse_const_block(lo.to(self.token.span))
1246+
self.parse_const_block(lo.to(self.token.span), false)
12471247
} else if self.is_do_catch_block() {
12481248
self.recover_do_catch(attrs)
12491249
} else if self.is_try_block() {

compiler/rustc_parse/src/parser/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,12 @@ impl<'a> Parser<'a> {
10951095
}
10961096

10971097
/// Parses inline const expressions.
1098-
fn parse_const_block(&mut self, span: Span) -> PResult<'a, P<Expr>> {
1099-
self.sess.gated_spans.gate(sym::inline_const, span);
1098+
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
1099+
if pat {
1100+
self.sess.gated_spans.gate(sym::inline_const_pat, span);
1101+
} else {
1102+
self.sess.gated_spans.gate(sym::inline_const, span);
1103+
}
11001104
self.eat_keyword(kw::Const);
11011105
let blk = self.parse_block()?;
11021106
let anon_const = AnonConst {

compiler/rustc_parse/src/parser/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a> Parser<'a> {
437437
PatKind::Box(pat)
438438
} else if self.check_inline_const(0) {
439439
// Parse `const pat`
440-
let const_expr = self.parse_const_block(lo.to(self.token.span))?;
440+
let const_expr = self.parse_const_block(lo.to(self.token.span), true)?;
441441

442442
if let Some(re) = self.parse_range_end() {
443443
self.parse_pat_range_begin_with(const_expr, re)?
@@ -884,7 +884,7 @@ impl<'a> Parser<'a> {
884884

885885
fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
886886
if self.check_inline_const(0) {
887-
self.parse_const_block(self.token.span)
887+
self.parse_const_block(self.token.span, true)
888888
} else if self.check_path() {
889889
let lo = self.token.span;
890890
let (qself, path) = if self.eat_lt() {

compiler/rustc_resolve/src/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ impl<'a> Resolver<'a> {
11331133
feature,
11341134
reason,
11351135
issue,
1136+
None,
11361137
is_soft,
11371138
span,
11381139
soft_handler,

compiler/rustc_session/src/config.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -335,22 +335,17 @@ impl Default for ErrorOutputType {
335335
}
336336

337337
/// Parameter to control path trimming.
338-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
338+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
339339
pub enum TrimmedDefPaths {
340340
/// `try_print_trimmed_def_path` never prints a trimmed path and never calls the expensive query
341+
#[default]
341342
Never,
342343
/// `try_print_trimmed_def_path` calls the expensive query, the query doesn't call `delay_good_path_bug`
343344
Always,
344345
/// `try_print_trimmed_def_path` calls the expensive query, the query calls `delay_good_path_bug`
345346
GoodPath,
346347
}
347348

348-
impl Default for TrimmedDefPaths {
349-
fn default() -> Self {
350-
Self::Never
351-
}
352-
}
353-
354349
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
355350
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
356351
/// dependency tracking for command-line arguments. Also only hash keys, since tracking

compiler/rustc_session/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(crate_visibility_modifier)]
2+
#![feature(derive_default_enum)]
23
#![feature(min_specialization)]
34
#![feature(once_cell)]
45
#![recursion_limit = "256"]

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ symbols! {
307307
alloc_layout,
308308
alloc_zeroed,
309309
allocator,
310+
allocator_api,
310311
allocator_internals,
311312
allow,
312313
allow_fail,
@@ -731,6 +732,7 @@ symbols! {
731732
inlateout,
732733
inline,
733734
inline_const,
735+
inline_const_pat,
734736
inout,
735737
instruction_set,
736738
intel,

compiler/rustc_trait_selection/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(bool_to_option)]
1515
#![feature(box_patterns)]
1616
#![feature(drain_filter)]
17+
#![feature(derive_default_enum)]
1718
#![feature(hash_drain_filter)]
1819
#![feature(in_band_lifetimes)]
1920
#![feature(iter_zip)]

compiler/rustc_trait_selection/src/traits/mod.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ pub use self::chalk_fulfill::FulfillmentContext as ChalkFulfillmentContext;
8282
pub use rustc_infer::traits::*;
8383

8484
/// Whether to skip the leak check, as part of a future compatibility warning step.
85-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
85+
///
86+
/// The "default" for skip-leak-check corresponds to the current
87+
/// behavior (do not skip the leak check) -- not the behavior we are
88+
/// transitioning into.
89+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
8690
pub enum SkipLeakCheck {
8791
Yes,
92+
#[default]
8893
No,
8994
}
9095

@@ -94,15 +99,6 @@ impl SkipLeakCheck {
9499
}
95100
}
96101

97-
/// The "default" for skip-leak-check corresponds to the current
98-
/// behavior (do not skip the leak check) -- not the behavior we are
99-
/// transitioning into.
100-
impl Default for SkipLeakCheck {
101-
fn default() -> Self {
102-
SkipLeakCheck::No
103-
}
104-
}
105-
106102
/// The mode that trait queries run in.
107103
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
108104
pub enum TraitQueryMode {

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
#![cfg_attr(bootstrap, feature(const_raw_ptr_deref))]
164164
#![feature(const_refs_to_cell)]
165165
#![feature(decl_macro)]
166+
#![feature(derive_default_enum)]
166167
#![feature(doc_cfg)]
167168
#![feature(doc_notable_trait)]
168169
#![feature(doc_primitive)]

library/std/src/sys/unix/kernel_copy.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -576,20 +576,22 @@ pub(super) fn copy_regular_files(reader: RawFd, writer: RawFd, max_len: u64) ->
576576
return match err.raw_os_error() {
577577
// when file offset + max_length > u64::MAX
578578
Some(EOVERFLOW) => CopyResult::Fallback(written),
579-
Some(ENOSYS | EXDEV | EINVAL | EPERM | EOPNOTSUPP | EBADF) => {
579+
Some(ENOSYS | EXDEV | EINVAL | EPERM | EOPNOTSUPP | EBADF) if written == 0 => {
580580
// Try fallback io::copy if either:
581581
// - Kernel version is < 4.5 (ENOSYS¹)
582582
// - Files are mounted on different fs (EXDEV)
583583
// - copy_file_range is broken in various ways on RHEL/CentOS 7 (EOPNOTSUPP)
584584
// - copy_file_range file is immutable or syscall is blocked by seccomp¹ (EPERM)
585585
// - copy_file_range cannot be used with pipes or device nodes (EINVAL)
586586
// - the writer fd was opened with O_APPEND (EBADF²)
587+
// and no bytes were written successfully yet. (All these errnos should
588+
// not be returned if something was already written, but they happen in
589+
// the wild, see #91152.)
587590
//
588591
// ¹ these cases should be detected by the initial probe but we handle them here
589592
// anyway in case syscall interception changes during runtime
590593
// ² actually invalid file descriptors would cause this too, but in that case
591594
// the fallback code path is expected to encounter the same error again
592-
assert_eq!(written, 0);
593595
CopyResult::Fallback(0)
594596
}
595597
_ => CopyResult::Error(err, written),

0 commit comments

Comments
 (0)