Skip to content

Commit 5fab31e

Browse files
committed
Auto merge of rust-lang#79070 - jonas-schievink:rollup-wacn2b8, r=jonas-schievink
Rollup of 13 pull requests Successful merges: - rust-lang#77802 (Allow making `RUSTC_BOOTSTRAP` conditional on the crate name) - rust-lang#79004 (Add `--color` support to bootstrap) - rust-lang#79005 (cleanup: Remove `ParseSess::injected_crate_name`) - rust-lang#79016 (Make `_` an expression, to discard values in destructuring assignments) - rust-lang#79019 (astconv: extract closures into a separate trait) - rust-lang#79026 (Implement BTreeMap::retain and BTreeSet::retain) - rust-lang#79031 (Validate that locals have a corresponding `LocalDecl`) - rust-lang#79034 (rustc_resolve: Make `macro_rules` scope chain compression lazy) - rust-lang#79036 (Move Steal to rustc_data_structures.) - rust-lang#79041 (Rename clean::{ItemEnum -> ItemKind}, clean::Item::{inner -> kind}) - rust-lang#79058 (Move likely/unlikely argument outside of invisible unsafe block) - rust-lang#79059 (Print 'checking cranelift artifacts' to easily separate it from other artifacts) - rust-lang#79063 (Update rustfmt to v1.4.26) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0468845 + 568354f commit 5fab31e

File tree

100 files changed

+972
-516
lines changed

Some content is hidden

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

100 files changed

+972
-516
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4337,7 +4337,7 @@ dependencies = [
43374337

43384338
[[package]]
43394339
name = "rustfmt-nightly"
4340-
version = "1.4.25"
4340+
version = "1.4.26"
43414341
dependencies = [
43424342
"annotate-snippets 0.6.1",
43434343
"anyhow",

compiler/rustc_ast/src/ast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ impl Expr {
11921192
ExprKind::Field(..) => ExprPrecedence::Field,
11931193
ExprKind::Index(..) => ExprPrecedence::Index,
11941194
ExprKind::Range(..) => ExprPrecedence::Range,
1195+
ExprKind::Underscore => ExprPrecedence::Path,
11951196
ExprKind::Path(..) => ExprPrecedence::Path,
11961197
ExprKind::AddrOf(..) => ExprPrecedence::AddrOf,
11971198
ExprKind::Break(..) => ExprPrecedence::Break,
@@ -1324,6 +1325,8 @@ pub enum ExprKind {
13241325
Index(P<Expr>, P<Expr>),
13251326
/// A range (e.g., `1..2`, `1..`, `..2`, `1..=2`, `..=2`; and `..` in destructuring assingment).
13261327
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits),
1328+
/// An underscore, used in destructuring assignment to ignore a value.
1329+
Underscore,
13271330

13281331
/// Variable reference, possibly containing `::` and/or type
13291332
/// parameters (e.g., `foo::bar::<baz>`).

compiler/rustc_ast/src/mut_visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
12321232
visit_opt(e1, |e1| vis.visit_expr(e1));
12331233
visit_opt(e2, |e2| vis.visit_expr(e2));
12341234
}
1235+
ExprKind::Underscore => {}
12351236
ExprKind::Path(qself, path) => {
12361237
vis.visit_qself(qself);
12371238
vis.visit_path(path);

compiler/rustc_ast/src/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
806806
walk_list!(visitor, visit_expr, start);
807807
walk_list!(visitor, visit_expr, end);
808808
}
809+
ExprKind::Underscore => {}
809810
ExprKind::Path(ref maybe_qself, ref path) => {
810811
if let Some(ref qself) = *maybe_qself {
811812
visitor.visit_ty(&qself.ty);

compiler/rustc_ast_lowering/src/expr.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
164164
ExprKind::Range(ref e1, ref e2, lims) => {
165165
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), lims)
166166
}
167+
ExprKind::Underscore => {
168+
self.sess
169+
.struct_span_err(
170+
e.span,
171+
"in expressions, `_` can only be used on the left-hand side of an assignment",
172+
)
173+
.span_label(e.span, "`_` not allowed here")
174+
.emit();
175+
hir::ExprKind::Err
176+
}
167177
ExprKind::Path(ref qself, ref path) => {
168178
let qpath = self.lower_qpath(
169179
e.id,
@@ -863,7 +873,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
863873
// Return early in case of an ordinary assignment.
864874
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool {
865875
match &lhs.kind {
866-
ExprKind::Array(..) | ExprKind::Struct(..) | ExprKind::Tup(..) => false,
876+
ExprKind::Array(..)
877+
| ExprKind::Struct(..)
878+
| ExprKind::Tup(..)
879+
| ExprKind::Underscore => false,
867880
// Check for tuple struct constructor.
868881
ExprKind::Call(callee, ..) => lower_ctx.extract_tuple_struct_path(callee).is_none(),
869882
ExprKind::Paren(e) => {
@@ -943,6 +956,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
943956
assignments: &mut Vec<hir::Stmt<'hir>>,
944957
) -> &'hir hir::Pat<'hir> {
945958
match &lhs.kind {
959+
// Underscore pattern.
960+
ExprKind::Underscore => {
961+
return self.pat_without_dbm(lhs.span, hir::PatKind::Wild);
962+
}
946963
// Slice patterns.
947964
ExprKind::Array(elements) => {
948965
let (pats, rest) =

compiler/rustc_ast_lowering/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
5353
use rustc_hir::intravisit;
5454
use rustc_hir::{ConstArg, GenericArg, ParamName};
5555
use rustc_index::vec::{Idx, IndexVec};
56-
use rustc_session::config::nightly_options;
5756
use rustc_session::lint::{builtin::BARE_TRAIT_OBJECTS, BuiltinLintDiagnostics, LintBuffer};
5857
use rustc_session::parse::ParseSess;
5958
use rustc_session::Session;
@@ -1398,8 +1397,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13981397
"`impl Trait` not allowed outside of {}",
13991398
allowed_in,
14001399
);
1401-
if pos == ImplTraitPosition::Binding && nightly_options::is_nightly_build()
1402-
{
1400+
if pos == ImplTraitPosition::Binding && self.sess.is_nightly_build() {
14031401
err.help(
14041402
"add `#![feature(impl_trait_in_bindings)]` to the crate \
14051403
attributes to enable",

compiler/rustc_ast_passes/src/feature_gate.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,11 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
630630
gate_all!(const_trait_impl, "const trait impls are experimental");
631631
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
632632
gate_all!(inline_const, "inline-const is experimental");
633-
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
633+
if sess.parse_sess.span_diagnostic.err_count() == 0 {
634+
// Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
635+
// involved, so we only emit errors where there are no other parsing errors.
636+
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
637+
}
634638

635639
// All uses of `gate_all!` below this point were added in #65742,
636640
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ pub fn print_crate<'a>(
109109
ann: &'a dyn PpAnn,
110110
is_expanded: bool,
111111
edition: Edition,
112-
has_injected_crate: bool,
113112
) -> String {
114113
let mut s = State {
115114
s: pp::mk_printer(),
@@ -119,7 +118,7 @@ pub fn print_crate<'a>(
119118
insert_extra_parens: true,
120119
};
121120

122-
if is_expanded && has_injected_crate {
121+
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
123122
// We need to print `#![no_std]` (and its feature gate) so that
124123
// compiling pretty-printed source won't inject libstd again.
125124
// However, we don't want these attributes in the AST because
@@ -2068,6 +2067,7 @@ impl<'a> State<'a> {
20682067
self.print_expr_maybe_paren(e, fake_prec);
20692068
}
20702069
}
2070+
ast::ExprKind::Underscore => self.s.word("_"),
20712071
ast::ExprKind::Path(None, ref path) => self.print_path(path, true, 0),
20722072
ast::ExprKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, true),
20732073
ast::ExprKind::Break(opt_label, ref opt_expr) => {

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pub fn inject(
1313
resolver: &mut dyn ResolverExpand,
1414
sess: &Session,
1515
alt_std_name: Option<Symbol>,
16-
) -> (ast::Crate, Option<Symbol>) {
16+
) -> ast::Crate {
1717
let rust_2018 = sess.parse_sess.edition >= Edition::Edition2018;
1818

1919
// the first name in this list is the crate name of the crate with the prelude
2020
let names: &[Symbol] = if sess.contains_name(&krate.attrs, sym::no_core) {
21-
return (krate, None);
21+
return krate;
2222
} else if sess.contains_name(&krate.attrs, sym::no_std) {
2323
if sess.contains_name(&krate.attrs, sym::compiler_builtins) {
2424
&[sym::core]
@@ -81,5 +81,5 @@ pub fn inject(
8181

8282
krate.module.items.insert(0, use_item);
8383

84-
(krate, Some(name))
84+
krate
8585
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::llvm;
33
use libc::c_int;
44
use rustc_codegen_ssa::target_features::supported_target_features;
55
use rustc_data_structures::fx::FxHashSet;
6-
use rustc_feature::UnstableFeatures;
76
use rustc_middle::bug;
87
use rustc_session::config::PrintRequest;
98
use rustc_session::Session;
@@ -147,13 +146,11 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
147146
let target_machine = create_informational_target_machine(sess);
148147
supported_target_features(sess)
149148
.iter()
150-
.filter_map(|&(feature, gate)| {
151-
if UnstableFeatures::from_environment().is_nightly_build() || gate.is_none() {
152-
Some(feature)
153-
} else {
154-
None
155-
}
156-
})
149+
.filter_map(
150+
|&(feature, gate)| {
151+
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
152+
},
153+
)
157154
.filter(|feature| {
158155
let llvm_feature = to_llvm_feature(sess, feature);
159156
let cstr = CString::new(llvm_feature).unwrap();

compiler/rustc_data_structures/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
4747
#[macro_export]
4848
macro_rules! likely {
4949
($e:expr) => {
50-
#[allow(unused_unsafe)]
51-
{
52-
unsafe { std::intrinsics::likely($e) }
50+
match $e {
51+
#[allow(unused_unsafe)]
52+
e => unsafe { std::intrinsics::likely(e) },
5353
}
5454
};
5555
}
5656

5757
#[macro_export]
5858
macro_rules! unlikely {
5959
($e:expr) => {
60-
#[allow(unused_unsafe)]
61-
{
62-
unsafe { std::intrinsics::unlikely($e) }
60+
match $e {
61+
#[allow(unused_unsafe)]
62+
e => unsafe { std::intrinsics::unlikely(e) },
6363
}
6464
};
6565
}
@@ -102,6 +102,7 @@ pub mod work_queue;
102102
pub use atomic_ref::AtomicRef;
103103
pub mod frozen;
104104
pub mod sso;
105+
pub mod steal;
105106
pub mod tagged_ptr;
106107
pub mod temp_dir;
107108
pub mod unhash;

compiler/rustc_middle/src/ty/steal.rs compiler/rustc_data_structures/src/steal.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use rustc_data_structures::sync::{MappedReadGuard, ReadGuard, RwLock};
1+
use crate::stable_hasher::{HashStable, StableHasher};
2+
use crate::sync::{MappedReadGuard, ReadGuard, RwLock};
23

34
/// The `Steal` struct is intended to used as the value for a query.
45
/// Specifically, we sometimes have queries (*cough* MIR *cough*)
@@ -31,7 +32,7 @@ impl<T> Steal<T> {
3132

3233
pub fn borrow(&self) -> MappedReadGuard<'_, T> {
3334
ReadGuard::map(self.value.borrow(), |opt| match *opt {
34-
None => bug!("attempted to read from stolen value"),
35+
None => panic!("attempted to read from stolen value"),
3536
Some(ref v) => v,
3637
})
3738
}
@@ -42,3 +43,9 @@ impl<T> Steal<T> {
4243
value.expect("attempt to read from stolen value")
4344
}
4445
}
46+
47+
impl<CTX, T: HashStable<CTX>> HashStable<CTX> for Steal<T> {
48+
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
49+
self.borrow().hash_stable(hcx, hasher);
50+
}
51+
}

compiler/rustc_driver/src/lib.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_data_structures::profiling::print_time_passes_entry;
2020
use rustc_data_structures::sync::SeqCst;
2121
use rustc_errors::registry::{InvalidErrorCode, Registry};
2222
use rustc_errors::{ErrorReported, PResult};
23-
use rustc_feature::{find_gated_cfg, UnstableFeatures};
23+
use rustc_feature::find_gated_cfg;
2424
use rustc_hir::def_id::LOCAL_CRATE;
2525
use rustc_interface::util::{self, collect_crate_types, get_builtin_codegen_backend};
2626
use rustc_interface::{interface, Queries};
@@ -746,9 +746,6 @@ impl RustcDefaultCalls {
746746
}
747747
}
748748
Cfg => {
749-
let allow_unstable_cfg =
750-
UnstableFeatures::from_environment().is_nightly_build();
751-
752749
let mut cfgs = sess
753750
.parse_sess
754751
.config
@@ -763,7 +760,7 @@ impl RustcDefaultCalls {
763760
// it, this is intended to get into Cargo and then go
764761
// through to build scripts.
765762
if (name != sym::target_feature || value != Some(sym::crt_dash_static))
766-
&& !allow_unstable_cfg
763+
&& !sess.is_nightly_build()
767764
&& find_gated_cfg(|cfg_sym| cfg_sym == name).is_some()
768765
{
769766
return None;
@@ -814,14 +811,14 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
814811
}
815812
}
816813

817-
fn usage(verbose: bool, include_unstable_options: bool) {
814+
fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) {
818815
let groups = if verbose { config::rustc_optgroups() } else { config::rustc_short_optgroups() };
819816
let mut options = getopts::Options::new();
820817
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
821818
(option.apply)(&mut options);
822819
}
823820
let message = "Usage: rustc [OPTIONS] INPUT";
824-
let nightly_help = if nightly_options::is_nightly_build() {
821+
let nightly_help = if nightly_build {
825822
"\n -Z help Print unstable compiler options"
826823
} else {
827824
""
@@ -831,7 +828,7 @@ fn usage(verbose: bool, include_unstable_options: bool) {
831828
} else {
832829
"\n --help -v Print the full set of options rustc accepts"
833830
};
834-
let at_path = if verbose && nightly_options::is_nightly_build() {
831+
let at_path = if verbose && nightly_build {
835832
" @path Read newline separated options from `path`\n"
836833
} else {
837834
""
@@ -1034,7 +1031,9 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10341031
if args.is_empty() {
10351032
// user did not write `-v` nor `-Z unstable-options`, so do not
10361033
// include that extra information.
1037-
usage(false, false);
1034+
let nightly_build =
1035+
rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build();
1036+
usage(false, false, nightly_build);
10381037
return None;
10391038
}
10401039

@@ -1063,7 +1062,9 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10631062

10641063
if matches.opt_present("h") || matches.opt_present("help") {
10651064
// Only show unstable options in --help if we accept unstable options.
1066-
usage(matches.opt_present("verbose"), nightly_options::is_unstable_enabled(&matches));
1065+
let unstable_enabled = nightly_options::is_unstable_enabled(&matches);
1066+
let nightly_build = nightly_options::match_is_nightly_build(&matches);
1067+
usage(matches.opt_present("verbose"), unstable_enabled, nightly_build);
10671068
return None;
10681069
}
10691070

compiler/rustc_driver/src/pretty.rs

-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ pub fn print_after_parsing(
404404
annotation.pp_ann(),
405405
false,
406406
parse.edition,
407-
parse.injected_crate_name.get().is_some(),
408407
)
409408
})
410409
} else {
@@ -446,7 +445,6 @@ pub fn print_after_hir_lowering<'tcx>(
446445
annotation.pp_ann(),
447446
true,
448447
parse.edition,
449-
parse.injected_crate_name.get().is_some(),
450448
)
451449
})
452450
}

0 commit comments

Comments
 (0)