Skip to content

Commit

Permalink
Auto merge of rust-lang#91159 - matthiaskrgr:rollup-91mgg5v, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#90856 (Suggestion to wrap inner types using 'allocator_api' in tuple)
 - rust-lang#91103 (Inhibit clicks on summary's children)
 - rust-lang#91137 (Give people a single link they can click in the contributing guide)
 - rust-lang#91140 (Split inline const to two feature gates and mark expression position inline const complete)
 - rust-lang#91148 (Use `derive_default_enum` in the compiler)
 - rust-lang#91153 (kernel_copy: avoid panic on unexpected OS error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 23, 2021
2 parents 7b3cd07 + 3dc0011 commit 65c55bf
Show file tree
Hide file tree
Showing 51 changed files with 234 additions and 90 deletions.
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
Thank you for your interest in contributing to Rust! There are many ways to contribute
and we appreciate all of them.

The best way to get started is by asking for help in the [#new
members](https://rust-lang.zulipchat.com/#narrow/stream/122652-new-members)
Zulip stream. We have lots of docs below of how to get started on your own, but
the Zulip stream is the best place to *ask* for help.

Documentation for contributing to Rust is located in the [Guide to Rustc Development](https://rustc-dev-guide.rust-lang.org/),
commonly known as the [rustc-dev-guide]. Despite the name, this guide documents
not just how to develop rustc (the Rust compiler), but also how to contribute to any part
of the Rust project.

To get started with contributing, please read the [Contributing to Rust] chapter of the guide.
That chapter explains how to get your development environment set up and how to get help.
not just how to develop rustc (the Rust compiler), but also how to contribute to the standard library and rustdoc.

## About the [rustc-dev-guide]

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ standard library, and documentation.

**Note: this README is for _users_ rather than _contributors_.
If you wish to _contribute_ to the compiler, you should read the
[Getting Started][gettingstarted] section of the rustc-dev-guide instead.**
[Getting Started][gettingstarted] section of the rustc-dev-guide instead.
You can ask for help in the [#new members Zulip stream][new-members].**

[new-members]: https://rust-lang.zulipchat.com/#narrow/stream/122652-new-members

## Quick Start

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
gate_all!(inline_const, "inline-const is experimental");
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
gate_all!(
const_generics_defaults,
"default values for const generic parameters are experimental"
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ declare_features! (
/// Allows associated types in inherent impls.
(incomplete, inherent_associated_types, "1.52.0", Some(8995), None),
/// Allow anonymous constants from an inline `const` block
(incomplete, inline_const, "1.49.0", Some(76001), None),
(active, inline_const, "1.49.0", Some(76001), None),
/// Allow anonymous constants from an inline `const` block in pattern position
(incomplete, inline_const_pat, "1.58.0", Some(76001), None),
/// Allows using `pointer` and `reference` in intra-doc links
(active, intra_doc_pointers, "1.51.0", Some(80896), None),
/// Allows `#[instruction_set(_)]` attribute
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable<
/// This is used so that the region values inferred by HIR region solving are
/// not exposed, and so that we can avoid doing work in HIR typeck that MIR
/// typeck will also do.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Default)]
pub enum RegionckMode {
/// The default mode: report region errors, don't erase regions.
#[default]
Solve,
/// Erase the results of region after solving.
Erase {
Expand All @@ -108,12 +109,6 @@ pub enum RegionckMode {
},
}

impl Default for RegionckMode {
fn default() -> Self {
RegionckMode::Solve
}
}

impl RegionckMode {
/// Indicates that the MIR borrowck will repeat these region
/// checks, so we should ignore errors if NLL is (unconditionally)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(derive_default_enum)]
#![feature(extend_one)]
#![feature(iter_zip)]
#![feature(let_else)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(core_intrinsics)]
#![feature(derive_default_enum)]
#![feature(discriminant_kind)]
#![feature(exhaustive_patterns)]
#![feature(if_let_guard)]
Expand Down
61 changes: 53 additions & 8 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pub use self::StabilityLevel::*;

use crate::ty::{self, TyCtxt};
use crate::ty::{self, DefIdTree, TyCtxt};
use rustc_ast::NodeId;
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -90,6 +90,7 @@ pub fn report_unstable(
feature: Symbol,
reason: Option<Symbol>,
issue: Option<NonZeroU32>,
suggestion: Option<(Span, String, String, Applicability)>,
is_soft: bool,
span: Span,
soft_handler: impl FnOnce(&'static Lint, Span, &str),
Expand All @@ -116,8 +117,12 @@ pub fn report_unstable(
if is_soft {
soft_handler(SOFT_UNSTABLE, span, &msg)
} else {
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
.emit();
let mut err =
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg);
if let Some((inner_types, ref msg, sugg, applicability)) = suggestion {
err.span_suggestion(inner_types, msg, sugg, applicability);
}
err.emit();
}
}
}
Expand Down Expand Up @@ -271,7 +276,13 @@ pub enum EvalResult {
Allow,
/// We cannot use the item because it is unstable and we did not provide the
/// corresponding feature gate.
Deny { feature: Symbol, reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
Deny {
feature: Symbol,
reason: Option<Symbol>,
issue: Option<NonZeroU32>,
suggestion: Option<(Span, String, String, Applicability)>,
is_soft: bool,
},
/// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
Unmarked,
}
Expand All @@ -292,6 +303,32 @@ fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
}
}

// See issue #83250.
fn suggestion_for_allocator_api(
tcx: TyCtxt<'_>,
def_id: DefId,
span: Span,
feature: Symbol,
) -> Option<(Span, String, String, Applicability)> {
if feature == sym::allocator_api {
if let Some(trait_) = tcx.parent(def_id) {
if tcx.is_diagnostic_item(sym::Vec, trait_) {
let sm = tcx.sess.parse_sess.source_map();
let inner_types = sm.span_extend_to_prev_char(span, '<', true);
if let Ok(snippet) = sm.span_to_snippet(inner_types) {
return Some((
inner_types,
"consider wrapping the inner types in tuple".to_string(),
format!("({})", snippet),
Applicability::MaybeIncorrect,
));
}
}
}
}
None
}

impl<'tcx> TyCtxt<'tcx> {
/// Evaluates the stability of an item.
///
Expand Down Expand Up @@ -406,7 +443,8 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

EvalResult::Deny { feature, reason, issue, is_soft }
let suggestion = suggestion_for_allocator_api(self, def_id, span, feature);
EvalResult::Deny { feature, reason, issue, suggestion, is_soft }
}
Some(_) => {
// Stable APIs are always ok to call and deprecated APIs are
Expand Down Expand Up @@ -457,9 +495,16 @@ impl<'tcx> TyCtxt<'tcx> {
};
match self.eval_stability(def_id, id, span, method_span) {
EvalResult::Allow => {}
EvalResult::Deny { feature, reason, issue, is_soft } => {
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)
}
EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => report_unstable(
self.sess,
feature,
reason,
issue,
suggestion,
is_soft,
span,
soft_handler,
),
EvalResult::Unmarked => unmarked(span, def_id),
}
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2263,10 +2263,11 @@ impl<'tcx> TyS<'tcx> {
/// a miscompilation or unsoundness.
///
/// When in doubt, use `VarianceDiagInfo::default()`
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum VarianceDiagInfo<'tcx> {
/// No additional information - this is the default.
/// We will not add any additional information to error messages.
#[default]
None,
/// We switched our variance because a type occurs inside
/// the generic argument of a mutable reference or pointer
Expand Down Expand Up @@ -2301,9 +2302,3 @@ impl<'tcx> VarianceDiagInfo<'tcx> {
}
}
}

impl<'tcx> Default for VarianceDiagInfo<'tcx> {
fn default() -> Self {
Self::None
}
}
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 @@ -1243,7 +1243,7 @@ impl<'a> Parser<'a> {
} else if self.eat_keyword(kw::Unsafe) {
self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs)
} else if self.check_inline_const(0) {
self.parse_const_block(lo.to(self.token.span))
self.parse_const_block(lo.to(self.token.span), false)
} else if self.is_do_catch_block() {
self.recover_do_catch(attrs)
} else if self.is_try_block() {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,12 @@ impl<'a> Parser<'a> {
}

/// Parses inline const expressions.
fn parse_const_block(&mut self, span: Span) -> PResult<'a, P<Expr>> {
self.sess.gated_spans.gate(sym::inline_const, span);
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
if pat {
self.sess.gated_spans.gate(sym::inline_const_pat, span);
} else {
self.sess.gated_spans.gate(sym::inline_const, span);
}
self.eat_keyword(kw::Const);
let blk = self.parse_block()?;
let anon_const = AnonConst {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl<'a> Parser<'a> {
PatKind::Box(pat)
} else if self.check_inline_const(0) {
// Parse `const pat`
let const_expr = self.parse_const_block(lo.to(self.token.span))?;
let const_expr = self.parse_const_block(lo.to(self.token.span), true)?;

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

fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
if self.check_inline_const(0) {
self.parse_const_block(self.token.span)
self.parse_const_block(self.token.span, true)
} else if self.check_path() {
let lo = self.token.span;
let (qself, path) = if self.eat_lt() {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ impl<'a> Resolver<'a> {
feature,
reason,
issue,
None,
is_soft,
span,
soft_handler,
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,22 +335,17 @@ impl Default for ErrorOutputType {
}

/// Parameter to control path trimming.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum TrimmedDefPaths {
/// `try_print_trimmed_def_path` never prints a trimmed path and never calls the expensive query
#[default]
Never,
/// `try_print_trimmed_def_path` calls the expensive query, the query doesn't call `delay_good_path_bug`
Always,
/// `try_print_trimmed_def_path` calls the expensive query, the query calls `delay_good_path_bug`
GoodPath,
}

impl Default for TrimmedDefPaths {
fn default() -> Self {
Self::Never
}
}

/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
/// dependency tracking for command-line arguments. Also only hash keys, since tracking
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_session/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(crate_visibility_modifier)]
#![feature(derive_default_enum)]
#![feature(min_specialization)]
#![feature(once_cell)]
#![recursion_limit = "256"]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ symbols! {
alloc_layout,
alloc_zeroed,
allocator,
allocator_api,
allocator_internals,
allow,
allow_fail,
Expand Down Expand Up @@ -731,6 +732,7 @@ symbols! {
inlateout,
inline,
inline_const,
inline_const_pat,
inout,
instruction_set,
intel,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(drain_filter)]
#![feature(derive_default_enum)]
#![feature(hash_drain_filter)]
#![feature(in_band_lifetimes)]
#![feature(iter_zip)]
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ pub use self::chalk_fulfill::FulfillmentContext as ChalkFulfillmentContext;
pub use rustc_infer::traits::*;

/// Whether to skip the leak check, as part of a future compatibility warning step.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
///
/// The "default" for skip-leak-check corresponds to the current
/// behavior (do not skip the leak check) -- not the behavior we are
/// transitioning into.
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum SkipLeakCheck {
Yes,
#[default]
No,
}

Expand All @@ -94,15 +99,6 @@ impl SkipLeakCheck {
}
}

/// The "default" for skip-leak-check corresponds to the current
/// behavior (do not skip the leak check) -- not the behavior we are
/// transitioning into.
impl Default for SkipLeakCheck {
fn default() -> Self {
SkipLeakCheck::No
}
}

/// The mode that trait queries run in.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum TraitQueryMode {
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
#![cfg_attr(bootstrap, feature(const_raw_ptr_deref))]
#![feature(const_refs_to_cell)]
#![feature(decl_macro)]
#![feature(derive_default_enum)]
#![feature(doc_cfg)]
#![feature(doc_notable_trait)]
#![feature(doc_primitive)]
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/sys/unix/kernel_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,20 +576,22 @@ pub(super) fn copy_regular_files(reader: RawFd, writer: RawFd, max_len: u64) ->
return match err.raw_os_error() {
// when file offset + max_length > u64::MAX
Some(EOVERFLOW) => CopyResult::Fallback(written),
Some(ENOSYS | EXDEV | EINVAL | EPERM | EOPNOTSUPP | EBADF) => {
Some(ENOSYS | EXDEV | EINVAL | EPERM | EOPNOTSUPP | EBADF) if written == 0 => {
// Try fallback io::copy if either:
// - Kernel version is < 4.5 (ENOSYS¹)
// - Files are mounted on different fs (EXDEV)
// - copy_file_range is broken in various ways on RHEL/CentOS 7 (EOPNOTSUPP)
// - copy_file_range file is immutable or syscall is blocked by seccomp¹ (EPERM)
// - copy_file_range cannot be used with pipes or device nodes (EINVAL)
// - the writer fd was opened with O_APPEND (EBADF²)
// and no bytes were written successfully yet. (All these errnos should
// not be returned if something was already written, but they happen in
// the wild, see #91152.)
//
// ¹ these cases should be detected by the initial probe but we handle them here
// anyway in case syscall interception changes during runtime
// ² actually invalid file descriptors would cause this too, but in that case
// the fallback code path is expected to encounter the same error again
assert_eq!(written, 0);
CopyResult::Fallback(0)
}
_ => CopyResult::Error(err, written),
Expand Down
Loading

0 comments on commit 65c55bf

Please sign in to comment.