Skip to content

Commit bfd0487

Browse files
committed
Auto merge of #68126 - Centril:rollup-cz5u7xx, r=Centril
Rollup of 8 pull requests Successful merges: - #67756 (Collector tweaks) - #67889 (Compile some CGUs in parallel at the start of codegen) - #67930 (Rename Result::as_deref_ok to as_deref) - #68018 (feature_gate: Remove `GateStrength`) - #68070 (clean up E0185 explanation) - #68072 (Fix ICE #68058) - #68114 (Don't require `allow_internal_unstable` unless `staged_api` is enabled.) - #68120 (Ban `...X` pats, harden tests, and improve diagnostics) Failed merges: r? @ghost
2 parents 543b7d9 + 4eee796 commit bfd0487

File tree

57 files changed

+528
-407
lines changed

Some content is hidden

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

57 files changed

+528
-407
lines changed

src/libcore/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
#![feature(bound_cloned)]
7171
#![feature(cfg_target_has_atomic)]
7272
#![feature(concat_idents)]
73-
#![feature(const_fn)]
7473
#![feature(const_if_match)]
7574
#![feature(const_panic)]
7675
#![feature(const_fn_union)]

src/libcore/result.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ impl<T: Deref, E> Result<T, E> {
11361136
///
11371137
/// Leaves the original `Result` in-place, creating a new one containing a reference to the
11381138
/// `Ok` type's `Deref::Target` type.
1139-
pub fn as_deref_ok(&self) -> Result<&T::Target, &E> {
1139+
pub fn as_deref(&self) -> Result<&T::Target, &E> {
11401140
self.as_ref().map(|t| t.deref())
11411141
}
11421142
}
@@ -1152,24 +1152,13 @@ impl<T, E: Deref> Result<T, E> {
11521152
}
11531153
}
11541154

1155-
#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
1156-
impl<T: Deref, E: Deref> Result<T, E> {
1157-
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&T::Target, &E::Target>`.
1158-
///
1159-
/// Leaves the original `Result` in-place, creating a new one containing a reference to both
1160-
/// the `Ok` and `Err` types' `Deref::Target` types.
1161-
pub fn as_deref(&self) -> Result<&T::Target, &E::Target> {
1162-
self.as_ref().map(|t| t.deref()).map_err(|e| e.deref())
1163-
}
1164-
}
1165-
11661155
#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
11671156
impl<T: DerefMut, E> Result<T, E> {
11681157
/// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut T::Target, &mut E>`.
11691158
///
11701159
/// Leaves the original `Result` in-place, creating a new one containing a mutable reference to
11711160
/// the `Ok` type's `Deref::Target` type.
1172-
pub fn as_deref_mut_ok(&mut self) -> Result<&mut T::Target, &mut E> {
1161+
pub fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> {
11731162
self.as_mut().map(|t| t.deref_mut())
11741163
}
11751164
}
@@ -1185,18 +1174,6 @@ impl<T, E: DerefMut> Result<T, E> {
11851174
}
11861175
}
11871176

1188-
#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
1189-
impl<T: DerefMut, E: DerefMut> Result<T, E> {
1190-
/// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to
1191-
/// `Result<&mut T::Target, &mut E::Target>`.
1192-
///
1193-
/// Leaves the original `Result` in-place, creating a new one containing a mutable reference to
1194-
/// both the `Ok` and `Err` types' `Deref::Target` types.
1195-
pub fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E::Target> {
1196-
self.as_mut().map(|t| t.deref_mut()).map_err(|e| e.deref_mut())
1197-
}
1198-
}
1199-
12001177
impl<T, E> Result<Option<T>, E> {
12011178
/// Transposes a `Result` of an `Option` into an `Option` of a `Result`.
12021179
///

src/libcore/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#![feature(slice_internals)]
3232
#![feature(slice_partition_dedup)]
3333
#![feature(int_error_matching)]
34-
#![feature(const_fn)]
3534
#![feature(array_value_iter)]
3635
#![feature(iter_partition_in_place)]
3736
#![feature(iter_is_partitioned)]

src/libcore/tests/result.rs

+27-58
Original file line numberDiff line numberDiff line change
@@ -236,31 +236,17 @@ fn test_try() {
236236

237237
#[test]
238238
fn test_result_as_deref() {
239-
// &Result<T: Deref, E>::Ok(T).as_deref_ok() ->
239+
// &Result<T: Deref, E>::Ok(T).as_deref() ->
240240
// Result<&T::Deref::Target, &E>::Ok(&*T)
241241
let ref_ok = &Result::Ok::<&i32, u8>(&42);
242242
let expected_result = Result::Ok::<&i32, &u8>(&42);
243-
assert_eq!(ref_ok.as_deref_ok(), expected_result);
244-
245-
let ref_ok = &Result::Ok::<String, u32>(String::from("a result"));
246-
let expected_result = Result::Ok::<&str, &u32>("a result");
247-
assert_eq!(ref_ok.as_deref_ok(), expected_result);
248-
249-
let ref_ok = &Result::Ok::<Vec<i32>, u32>(vec![1, 2, 3, 4, 5]);
250-
let expected_result = Result::Ok::<&[i32], &u32>([1, 2, 3, 4, 5].as_slice());
251-
assert_eq!(ref_ok.as_deref_ok(), expected_result);
252-
253-
// &Result<T: Deref, E: Deref>::Ok(T).as_deref() ->
254-
// Result<&T::Deref::Target, &E::Deref::Target>::Ok(&*T)
255-
let ref_ok = &Result::Ok::<&i32, &u8>(&42);
256-
let expected_result = Result::Ok::<&i32, &u8>(&42);
257243
assert_eq!(ref_ok.as_deref(), expected_result);
258244

259-
let ref_ok = &Result::Ok::<String, &u32>(String::from("a result"));
245+
let ref_ok = &Result::Ok::<String, u32>(String::from("a result"));
260246
let expected_result = Result::Ok::<&str, &u32>("a result");
261247
assert_eq!(ref_ok.as_deref(), expected_result);
262248

263-
let ref_ok = &Result::Ok::<Vec<i32>, &u32>(vec![1, 2, 3, 4, 5]);
249+
let ref_ok = &Result::Ok::<Vec<i32>, u32>(vec![1, 2, 3, 4, 5]);
264250
let expected_result = Result::Ok::<&[i32], &u32>([1, 2, 3, 4, 5].as_slice());
265251
assert_eq!(ref_ok.as_deref(), expected_result);
266252

@@ -281,19 +267,21 @@ fn test_result_as_deref() {
281267
// &Result<T: Deref, E: Deref>::Err(T).as_deref_err() ->
282268
// Result<&T, &E::Deref::Target>::Err(&*E)
283269
let ref_err = &Result::Err::<&u8, &i32>(&41);
284-
let expected_result = Result::Err::<&u8, &i32>(&41);
270+
let expected_result = Result::Err::<&u8, &&i32>(&&41);
285271
assert_eq!(ref_err.as_deref(), expected_result);
286272

287-
let ref_err = &Result::Err::<&u32, String>(String::from("an error"));
288-
let expected_result = Result::Err::<&u32, &str>("an error");
273+
let s = String::from("an error");
274+
let ref_err = &Result::Err::<&u32, String>(s.clone());
275+
let expected_result = Result::Err::<&u32, &String>(&s);
289276
assert_eq!(ref_err.as_deref(), expected_result);
290277

291-
let ref_err = &Result::Err::<&u32, Vec<i32>>(vec![5, 4, 3, 2, 1]);
292-
let expected_result = Result::Err::<&u32, &[i32]>([5, 4, 3, 2, 1].as_slice());
278+
let v = vec![5, 4, 3, 2, 1];
279+
let ref_err = &Result::Err::<&u32, Vec<i32>>(v.clone());
280+
let expected_result = Result::Err::<&u32, &Vec<i32>>(&v);
293281
assert_eq!(ref_err.as_deref(), expected_result);
294282

295283
// The following cases test calling `as_deref_*` with the wrong variant (i.e.
296-
// `as_deref_ok()` with a `Result::Err()`, or `as_deref_err()` with a `Result::Ok()`.
284+
// `as_deref()` with a `Result::Err()`, or `as_deref_err()` with a `Result::Ok()`.
297285
// While uncommon, these cases are supported to ensure that an `as_deref_*`
298286
// call can still be made even when one of the Result types does not implement
299287
// `Deref` (for example, std::io::Error).
@@ -312,56 +300,38 @@ fn test_result_as_deref() {
312300
let expected_result = Result::Ok::<&[i32; 5], &u32>(&[1, 2, 3, 4, 5]);
313301
assert_eq!(ref_ok.as_deref_err(), expected_result);
314302

315-
// &Result<T: Deref, E>::Err(E).as_deref_ok() ->
303+
// &Result<T: Deref, E>::Err(E).as_deref() ->
316304
// Result<&T::Deref::Target, &E>::Err(&E)
317305
let ref_err = &Result::Err::<&u8, i32>(41);
318306
let expected_result = Result::Err::<&u8, &i32>(&41);
319-
assert_eq!(ref_err.as_deref_ok(), expected_result);
307+
assert_eq!(ref_err.as_deref(), expected_result);
320308

321309
let ref_err = &Result::Err::<&u32, &str>("an error");
322310
let expected_result = Result::Err::<&u32, &&str>(&"an error");
323-
assert_eq!(ref_err.as_deref_ok(), expected_result);
311+
assert_eq!(ref_err.as_deref(), expected_result);
324312

325313
let ref_err = &Result::Err::<&u32, [i32; 5]>([5, 4, 3, 2, 1]);
326314
let expected_result = Result::Err::<&u32, &[i32; 5]>(&[5, 4, 3, 2, 1]);
327-
assert_eq!(ref_err.as_deref_ok(), expected_result);
315+
assert_eq!(ref_err.as_deref(), expected_result);
328316
}
329317

330318
#[test]
331319
fn test_result_as_deref_mut() {
332-
// &mut Result<T: Deref, E>::Ok(T).as_deref_mut_ok() ->
320+
// &mut Result<T: Deref, E>::Ok(T).as_deref_mut() ->
333321
// Result<&mut T::Deref::Target, &mut E>::Ok(&mut *T)
334322
let mut val = 42;
335323
let mut expected_val = 42;
336324
let mut_ok = &mut Result::Ok::<&mut i32, u8>(&mut val);
337325
let expected_result = Result::Ok::<&mut i32, &mut u8>(&mut expected_val);
338-
assert_eq!(mut_ok.as_deref_mut_ok(), expected_result);
339-
340-
let mut expected_string = String::from("a result");
341-
let mut_ok = &mut Result::Ok::<String, u32>(expected_string.clone());
342-
let expected_result = Result::Ok::<&mut str, &mut u32>(expected_string.deref_mut());
343-
assert_eq!(mut_ok.as_deref_mut_ok(), expected_result);
344-
345-
let mut expected_vec = vec![1, 2, 3, 4, 5];
346-
let mut_ok = &mut Result::Ok::<Vec<i32>, u32>(expected_vec.clone());
347-
let expected_result = Result::Ok::<&mut [i32], &mut u32>(expected_vec.as_mut_slice());
348-
assert_eq!(mut_ok.as_deref_mut_ok(), expected_result);
349-
350-
// &mut Result<T: Deref, E: Deref>::Ok(T).as_deref_mut() ->
351-
// Result<&mut T::Deref::Target, &mut E::Deref::Target>::Ok(&mut *T)
352-
let mut val = 42;
353-
let mut expected_val = 42;
354-
let mut_ok = &mut Result::Ok::<&mut i32, &mut u8>(&mut val);
355-
let expected_result = Result::Ok::<&mut i32, &mut u8>(&mut expected_val);
356326
assert_eq!(mut_ok.as_deref_mut(), expected_result);
357327

358328
let mut expected_string = String::from("a result");
359-
let mut_ok = &mut Result::Ok::<String, &mut u32>(expected_string.clone());
329+
let mut_ok = &mut Result::Ok::<String, u32>(expected_string.clone());
360330
let expected_result = Result::Ok::<&mut str, &mut u32>(expected_string.deref_mut());
361331
assert_eq!(mut_ok.as_deref_mut(), expected_result);
362332

363333
let mut expected_vec = vec![1, 2, 3, 4, 5];
364-
let mut_ok = &mut Result::Ok::<Vec<i32>, &mut u32>(expected_vec.clone());
334+
let mut_ok = &mut Result::Ok::<Vec<i32>, u32>(expected_vec.clone());
365335
let expected_result = Result::Ok::<&mut [i32], &mut u32>(expected_vec.as_mut_slice());
366336
assert_eq!(mut_ok.as_deref_mut(), expected_result);
367337

@@ -386,23 +356,22 @@ fn test_result_as_deref_mut() {
386356
// &mut Result<T: Deref, E: Deref>::Err(T).as_deref_mut_err() ->
387357
// Result<&mut T, &mut E::Deref::Target>::Err(&mut *E)
388358
let mut val = 41;
389-
let mut expected_val = 41;
390-
let mut_err = &mut Result::Err::<&mut u8, &mut i32>(&mut val);
391-
let expected_result = Result::Err::<&mut u8, &mut i32>(&mut expected_val);
359+
let mut_err = &mut Result::Err::<&mut u8, i32>(val);
360+
let expected_result = Result::Err::<&mut u8, &mut i32>(&mut val);
392361
assert_eq!(mut_err.as_deref_mut(), expected_result);
393362

394363
let mut expected_string = String::from("an error");
395364
let mut_err = &mut Result::Err::<&mut u32, String>(expected_string.clone());
396-
let expected_result = Result::Err::<&mut u32, &mut str>(expected_string.as_mut_str());
365+
let expected_result = Result::Err::<&mut u32, &mut String>(&mut expected_string);
397366
assert_eq!(mut_err.as_deref_mut(), expected_result);
398367

399368
let mut expected_vec = vec![5, 4, 3, 2, 1];
400369
let mut_err = &mut Result::Err::<&mut u32, Vec<i32>>(expected_vec.clone());
401-
let expected_result = Result::Err::<&mut u32, &mut [i32]>(expected_vec.as_mut_slice());
370+
let expected_result = Result::Err::<&mut u32, &mut Vec<i32>>(&mut expected_vec);
402371
assert_eq!(mut_err.as_deref_mut(), expected_result);
403372

404373
// The following cases test calling `as_deref_mut_*` with the wrong variant (i.e.
405-
// `as_deref_mut_ok()` with a `Result::Err()`, or `as_deref_mut_err()` with a `Result::Ok()`.
374+
// `as_deref_mut()` with a `Result::Err()`, or `as_deref_mut_err()` with a `Result::Ok()`.
406375
// While uncommon, these cases are supported to ensure that an `as_deref_mut_*`
407376
// call can still be made even when one of the Result types does not implement
408377
// `Deref` (for example, std::io::Error).
@@ -426,22 +395,22 @@ fn test_result_as_deref_mut() {
426395
let expected_result = Result::Ok::<&mut [i32; 5], &mut u32>(&mut expected_arr);
427396
assert_eq!(mut_ok.as_deref_mut_err(), expected_result);
428397

429-
// &mut Result<T: Deref, E>::Err(E).as_deref_mut_ok() ->
398+
// &mut Result<T: Deref, E>::Err(E).as_deref_mut() ->
430399
// Result<&mut T::Deref::Target, &mut E>::Err(&mut E)
431400
let mut expected_val = 41;
432401
let mut_err = &mut Result::Err::<&mut u8, i32>(expected_val.clone());
433402
let expected_result = Result::Err::<&mut u8, &mut i32>(&mut expected_val);
434-
assert_eq!(mut_err.as_deref_mut_ok(), expected_result);
403+
assert_eq!(mut_err.as_deref_mut(), expected_result);
435404

436405
let string = String::from("an error");
437406
let expected_string = string.clone();
438407
let mut ref_str = expected_string.as_ref();
439408
let mut_err = &mut Result::Err::<&mut u32, &str>(string.as_str());
440409
let expected_result = Result::Err::<&mut u32, &mut &str>(&mut ref_str);
441-
assert_eq!(mut_err.as_deref_mut_ok(), expected_result);
410+
assert_eq!(mut_err.as_deref_mut(), expected_result);
442411

443412
let mut expected_arr = [5, 4, 3, 2, 1];
444413
let mut_err = &mut Result::Err::<&mut u32, [i32; 5]>(expected_arr.clone());
445414
let expected_result = Result::Err::<&mut u32, &mut [i32; 5]>(&mut expected_arr);
446-
assert_eq!(mut_err.as_deref_mut_ok(), expected_result);
415+
assert_eq!(mut_err.as_deref_mut(), expected_result);
447416
}

src/libproc_macro/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#![feature(nll)]
2222
#![feature(staged_api)]
2323
#![feature(allow_internal_unstable)]
24-
#![feature(const_fn)]
2524
#![feature(decl_macro)]
2625
#![feature(extern_types)]
2726
#![feature(in_band_lifetimes)]

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#![feature(bool_to_option)]
3232
#![feature(box_patterns)]
3333
#![feature(box_syntax)]
34-
#![feature(const_fn)]
3534
#![feature(const_transmute)]
3635
#![feature(core_intrinsics)]
3736
#![feature(drain_filter)]

src/librustc_ast_lowering/expr.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
202202
ExprKind::Mac(_) => panic!("Shouldn't exist here"),
203203
};
204204

205-
hir::Expr { hir_id: self.lower_node_id(e.id), kind, span: e.span, attrs: e.attrs.clone() }
205+
hir::Expr {
206+
hir_id: self.lower_node_id(e.id),
207+
kind,
208+
span: e.span,
209+
attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
210+
}
206211
}
207212

208213
fn lower_unop(&mut self, u: UnOp) -> hir::UnOp {

src/librustc_ast_passes/feature_gate.rs

+10-37
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,25 @@ use rustc_span::Span;
88
use syntax::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId};
99
use syntax::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
1010
use syntax::attr;
11-
use syntax::sess::{feature_err, leveled_feature_err, GateStrength, ParseSess};
11+
use syntax::sess::{feature_err, feature_err_issue, ParseSess};
1212
use syntax::visit::{self, FnKind, Visitor};
1313

1414
use log::debug;
1515

1616
macro_rules! gate_feature_fn {
17-
($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $level: expr) => {{
18-
let (cx, has_feature, span, name, explain, level) =
19-
(&*$cx, $has_feature, $span, $name, $explain, $level);
17+
($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
18+
let (cx, has_feature, span, name, explain) = (&*$cx, $has_feature, $span, $name, $explain);
2019
let has_feature: bool = has_feature(&$cx.features);
2120
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
2221
if !has_feature && !span.allows_unstable($name) {
23-
leveled_feature_err(cx.parse_sess, name, span, GateIssue::Language, explain, level)
24-
.emit();
22+
feature_err_issue(cx.parse_sess, name, span, GateIssue::Language, explain).emit();
2523
}
2624
}};
2725
}
2826

29-
macro_rules! gate_feature {
27+
macro_rules! gate_feature_post {
3028
($cx: expr, $feature: ident, $span: expr, $explain: expr) => {
31-
gate_feature_fn!(
32-
$cx,
33-
|x: &Features| x.$feature,
34-
$span,
35-
sym::$feature,
36-
$explain,
37-
GateStrength::Hard
38-
)
39-
};
40-
($cx: expr, $feature: ident, $span: expr, $explain: expr, $level: expr) => {
41-
gate_feature_fn!($cx, |x: &Features| x.$feature, $span, sym::$feature, $explain, $level)
29+
gate_feature_fn!($cx, |x: &Features| x.$feature, $span, sym::$feature, $explain)
4230
};
4331
}
4432

@@ -51,21 +39,6 @@ struct PostExpansionVisitor<'a> {
5139
features: &'a Features,
5240
}
5341

54-
macro_rules! gate_feature_post {
55-
($cx: expr, $feature: ident, $span: expr, $explain: expr) => {{
56-
let (cx, span) = ($cx, $span);
57-
if !span.allows_unstable(sym::$feature) {
58-
gate_feature!(cx, $feature, span, $explain)
59-
}
60-
}};
61-
($cx: expr, $feature: ident, $span: expr, $explain: expr, $level: expr) => {{
62-
let (cx, span) = ($cx, $span);
63-
if !span.allows_unstable(sym::$feature) {
64-
gate_feature!(cx, $feature, span, $explain, $level)
65-
}
66-
}};
67-
}
68-
6942
impl<'a> PostExpansionVisitor<'a> {
7043
fn check_abi(&self, abi: ast::StrLit) {
7144
let ast::StrLit { symbol_unescaped, span, .. } = abi;
@@ -257,15 +230,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
257230
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
258231
// Check feature gates for built-in attributes.
259232
if let Some((.., AttributeGate::Gated(_, name, descr, has_feature))) = attr_info {
260-
gate_feature_fn!(self, has_feature, attr.span, name, descr, GateStrength::Hard);
233+
gate_feature_fn!(self, has_feature, attr.span, name, descr);
261234
}
262235
// Check unstable flavors of the `#[doc]` attribute.
263236
if attr.check_name(sym::doc) {
264237
for nested_meta in attr.meta_item_list().unwrap_or_default() {
265238
macro_rules! gate_doc { ($($name:ident => $feature:ident)*) => {
266239
$(if nested_meta.check_name(sym::$name) {
267240
let msg = concat!("`#[doc(", stringify!($name), ")]` is experimental");
268-
gate_feature!(self, $feature, attr.span, msg);
241+
gate_feature_post!(self, $feature, attr.span, msg);
269242
})*
270243
}}
271244

@@ -666,7 +639,7 @@ pub fn check_crate(
666639
macro_rules! gate_all {
667640
($gate:ident, $msg:literal) => {
668641
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
669-
gate_feature!(&visitor, $gate, *span, $msg);
642+
gate_feature_post!(&visitor, $gate, *span, $msg);
670643
}
671644
};
672645
}
@@ -688,7 +661,7 @@ pub fn check_crate(
688661
// disabling these uses of early feature-gatings.
689662
if false {
690663
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
691-
gate_feature!(&visitor, $gate, *span, $msg);
664+
gate_feature_post!(&visitor, $gate, *span, $msg);
692665
}
693666
}
694667
};

0 commit comments

Comments
 (0)