Skip to content

Commit e13fe7f

Browse files
committed
Auto merge of #62635 - Centril:rollup-potvfnk, r=Centril
Rollup of 12 pull requests Successful merges: - #61535 (Coherence test when a generic type param has a default value from an associated type) - #62274 (rustc_mir: follow FalseUnwind's real_target edge in qualify_consts.) - #62431 (Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*`) - #62453 (in which we suggest anonymizing single-use lifetimes in paths ) - #62568 (Replace unsafe_destructor_blind_to_params with may_dangle) - #62578 (Add test for #49919) - #62595 (Document that the crate keyword refers to the project root) - #62599 (move mem::uninitialized deprecation back by 1 release, to 1.39) - #62605 (Emit dropped unemitted errors to aid in ICE debugging) - #62607 (Correctly break out of recovery loop) - #62608 (`async unsafe fn` tests) - #62623 (downgrade indirect_structural_match lint to allow) Failed merges: r? @ghost
2 parents 71f9384 + fe4e32a commit e13fe7f

File tree

69 files changed

+502
-241
lines changed

Some content is hidden

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

69 files changed

+502
-241
lines changed

RELEASES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Misc
6262
Compatibility Notes
6363
-------------------
6464
- With the stabilisation of `mem::MaybeUninit`, `mem::uninitialized` use is no
65-
longer recommended, and will be deprecated in 1.38.0.
65+
longer recommended, and will be deprecated in 1.39.0.
6666

6767
[60318]: https://github.com/rust-lang/rust/pull/60318/
6868
[60364]: https://github.com/rust-lang/rust/pull/60364/

src/libcore/mem/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub unsafe fn zeroed<T>() -> T {
472472
/// [`MaybeUninit<T>`]: union.MaybeUninit.html
473473
/// [inv]: union.MaybeUninit.html#initialization-invariant
474474
#[inline]
475-
#[rustc_deprecated(since = "1.38.0", reason = "use `mem::MaybeUninit` instead")]
475+
#[rustc_deprecated(since = "1.39.0", reason = "use `mem::MaybeUninit` instead")]
476476
#[stable(feature = "rust1", since = "1.0.0")]
477477
pub unsafe fn uninitialized<T>() -> T {
478478
MaybeUninit::uninit().assume_init()

src/libcore/option.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<T> Option<T> {
178178
/// ```
179179
///
180180
/// [`Some`]: #variant.Some
181-
#[must_use]
181+
#[must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead"]
182182
#[inline]
183183
#[stable(feature = "rust1", since = "1.0.0")]
184184
pub fn is_some(&self) -> bool {
@@ -201,7 +201,8 @@ impl<T> Option<T> {
201201
/// ```
202202
///
203203
/// [`None`]: #variant.None
204-
#[must_use]
204+
#[must_use = "if you intended to assert that this doesn't have a value, consider \
205+
`.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"]
205206
#[inline]
206207
#[stable(feature = "rust1", since = "1.0.0")]
207208
pub fn is_none(&self) -> bool {

src/libcore/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<T, E> Result<T, E> {
277277
/// let x: Result<i32, &str> = Err("Some error message");
278278
/// assert_eq!(x.is_ok(), false);
279279
/// ```
280-
#[must_use]
280+
#[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
281281
#[inline]
282282
#[stable(feature = "rust1", since = "1.0.0")]
283283
pub fn is_ok(&self) -> bool {
@@ -302,7 +302,7 @@ impl<T, E> Result<T, E> {
302302
/// let x: Result<i32, &str> = Err("Some error message");
303303
/// assert_eq!(x.is_err(), true);
304304
/// ```
305-
#[must_use]
305+
#[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
306306
#[inline]
307307
#[stable(feature = "rust1", since = "1.0.0")]
308308
pub fn is_err(&self) -> bool {

src/librustc/lint/builtin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ declare_lint! {
350350

351351
declare_lint! {
352352
pub INDIRECT_STRUCTURAL_MATCH,
353-
Warn,
353+
// defaulting to allow until rust-lang/rust#62614 is fixed.
354+
Allow,
354355
"pattern with const indirectly referencing non-`#[structural_match]` type"
355356
}
356357

@@ -451,6 +452,7 @@ declare_lint_pass! {
451452
AMBIGUOUS_ASSOCIATED_ITEMS,
452453
NESTED_IMPL_TRAIT,
453454
MUTABLE_BORROW_RESERVATION_CONFLICT,
455+
INDIRECT_STRUCTURAL_MATCH,
454456
]
455457
}
456458

src/librustc/middle/resolve_lifetime.rs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::hir::def::{Res, DefKind};
99
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1010
use crate::hir::map::Map;
1111
use crate::hir::ptr::P;
12-
use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName};
12+
use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName, QPath};
1313
use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
1414

1515
use crate::rustc::lint;
@@ -1458,10 +1458,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14581458
}
14591459

14601460
// helper method to issue suggestions from `fn rah<'a>(&'a T)` to `fn rah(&T)`
1461+
// or from `fn rah<'a>(T<'a>)` to `fn rah(T<'_>)`
14611462
fn suggest_eliding_single_use_lifetime(
14621463
&self, err: &mut DiagnosticBuilder<'_>, def_id: DefId, lifetime: &hir::Lifetime
14631464
) {
1464-
// FIXME: future work: also suggest `impl Foo<'_>` for `impl<'a> Foo<'a>`
14651465
let name = lifetime.name.ident();
14661466
let mut remove_decl = None;
14671467
if let Some(parent_def_id) = self.tcx.parent(def_id) {
@@ -1471,18 +1471,38 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14711471
}
14721472

14731473
let mut remove_use = None;
1474+
let mut elide_use = None;
14741475
let mut find_arg_use_span = |inputs: &hir::HirVec<hir::Ty>| {
14751476
for input in inputs {
1476-
if let hir::TyKind::Rptr(lt, _) = input.node {
1477-
if lt.name.ident() == name {
1478-
// include the trailing whitespace between the ampersand and the type name
1479-
let lt_through_ty_span = lifetime.span.to(input.span.shrink_to_hi());
1480-
remove_use = Some(
1481-
self.tcx.sess.source_map()
1482-
.span_until_non_whitespace(lt_through_ty_span)
1483-
);
1484-
break;
1477+
match input.node {
1478+
hir::TyKind::Rptr(lt, _) => {
1479+
if lt.name.ident() == name {
1480+
// include the trailing whitespace between the lifetime and type names
1481+
let lt_through_ty_span = lifetime.span.to(input.span.shrink_to_hi());
1482+
remove_use = Some(
1483+
self.tcx.sess.source_map()
1484+
.span_until_non_whitespace(lt_through_ty_span)
1485+
);
1486+
break;
1487+
}
14851488
}
1489+
hir::TyKind::Path(ref qpath) => {
1490+
if let QPath::Resolved(_, path) = qpath {
1491+
1492+
let last_segment = &path.segments[path.segments.len()-1];
1493+
let generics = last_segment.generic_args();
1494+
for arg in generics.args.iter() {
1495+
if let GenericArg::Lifetime(lt) = arg {
1496+
if lt.name.ident() == name {
1497+
elide_use = Some(lt.span);
1498+
break;
1499+
}
1500+
}
1501+
}
1502+
break;
1503+
}
1504+
},
1505+
_ => {}
14861506
}
14871507
}
14881508
};
@@ -1506,24 +1526,35 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15061526
}
15071527
}
15081528

1509-
if let (Some(decl_span), Some(use_span)) = (remove_decl, remove_use) {
1510-
// if both declaration and use deletion spans start at the same
1511-
// place ("start at" because the latter includes trailing
1512-
// whitespace), then this is an in-band lifetime
1513-
if decl_span.shrink_to_lo() == use_span.shrink_to_lo() {
1514-
err.span_suggestion(
1515-
use_span,
1516-
"elide the single-use lifetime",
1517-
String::new(),
1518-
Applicability::MachineApplicable,
1519-
);
1520-
} else {
1529+
let msg = "elide the single-use lifetime";
1530+
match (remove_decl, remove_use, elide_use) {
1531+
(Some(decl_span), Some(use_span), None) => {
1532+
// if both declaration and use deletion spans start at the same
1533+
// place ("start at" because the latter includes trailing
1534+
// whitespace), then this is an in-band lifetime
1535+
if decl_span.shrink_to_lo() == use_span.shrink_to_lo() {
1536+
err.span_suggestion(
1537+
use_span,
1538+
msg,
1539+
String::new(),
1540+
Applicability::MachineApplicable,
1541+
);
1542+
} else {
1543+
err.multipart_suggestion(
1544+
msg,
1545+
vec![(decl_span, String::new()), (use_span, String::new())],
1546+
Applicability::MachineApplicable,
1547+
);
1548+
}
1549+
}
1550+
(Some(decl_span), None, Some(use_span)) => {
15211551
err.multipart_suggestion(
1522-
"elide the single-use lifetime",
1523-
vec![(decl_span, String::new()), (use_span, String::new())],
1552+
msg,
1553+
vec![(decl_span, String::new()), (use_span, "'_".to_owned())],
15241554
Applicability::MachineApplicable,
15251555
);
15261556
}
1557+
_ => {}
15271558
}
15281559
}
15291560

src/librustc/ty/util.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_macros::HashStable;
2222
use std::{cmp, fmt};
2323
use syntax::ast;
2424
use syntax::attr::{self, SignedInt, UnsignedInt};
25-
use syntax::symbol::sym;
2625
use syntax_pos::{Span, DUMMY_SP};
2726

2827
#[derive(Copy, Clone, Debug)]
@@ -435,20 +434,6 @@ impl<'tcx> TyCtxt<'tcx> {
435434
Some(dtor) => dtor.did
436435
};
437436

438-
// RFC 1238: if the destructor method is tagged with the
439-
// attribute `unsafe_destructor_blind_to_params`, then the
440-
// compiler is being instructed to *assume* that the
441-
// destructor will not access borrowed data,
442-
// even if such data is otherwise reachable.
443-
//
444-
// Such access can be in plain sight (e.g., dereferencing
445-
// `*foo.0` of `Foo<'a>(&'a u32)`) or indirectly hidden
446-
// (e.g., calling `foo.0.clone()` of `Foo<T:Clone>`).
447-
if self.has_attr(dtor, sym::unsafe_destructor_blind_to_params) {
448-
debug!("destructor_constraint({:?}) - blind", def.did);
449-
return vec![];
450-
}
451-
452437
let impl_def_id = self.associated_item(dtor).container.id();
453438
let impl_generics = self.generics_of(impl_def_id);
454439

src/librustc_errors/diagnostic_builder.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,13 @@ impl<'a> Debug for DiagnosticBuilder<'a> {
380380
impl<'a> Drop for DiagnosticBuilder<'a> {
381381
fn drop(&mut self) {
382382
if !panicking() && !self.cancelled() {
383-
let mut db = DiagnosticBuilder::new(self.handler,
384-
Level::Bug,
385-
"Error constructed but not emitted");
383+
let mut db = DiagnosticBuilder::new(
384+
self.handler,
385+
Level::Bug,
386+
"the following error was constructed but not emitted",
387+
);
386388
db.emit();
389+
self.emit();
387390
panic!();
388391
}
389392
}

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
890890

891891
let target = match body[bb].terminator().kind {
892892
TerminatorKind::Goto { target } |
893+
TerminatorKind::FalseUnwind { real_target: target, .. } |
893894
TerminatorKind::Drop { target, .. } |
894895
TerminatorKind::DropAndReplace { target, .. } |
895896
TerminatorKind::Assert { target, .. } |
@@ -908,8 +909,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
908909
TerminatorKind::GeneratorDrop |
909910
TerminatorKind::Yield { .. } |
910911
TerminatorKind::Unreachable |
911-
TerminatorKind::FalseEdges { .. } |
912-
TerminatorKind::FalseUnwind { .. } => None,
912+
TerminatorKind::FalseEdges { .. } => None,
913913

914914
TerminatorKind::Return => {
915915
break;

src/librustc_typeck/check/dropck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
246246
///
247247
/// * (1.) `D` has a lifetime- or type-parametric Drop implementation,
248248
/// (where that `Drop` implementation does not opt-out of
249-
/// this check via the `unsafe_destructor_blind_to_params`
249+
/// this check via the `may_dangle`
250250
/// attribute), and
251251
/// * (2.) the structure of `D` can reach a reference of type `&'a _`,
252252
///
@@ -279,7 +279,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
279279
/// instead Drop-Check now simply assumes that if a destructor has
280280
/// access (direct or indirect) to a lifetime parameter, then that
281281
/// lifetime must be forced to outlive that destructor's dynamic
282-
/// extent. We then provide the `unsafe_destructor_blind_to_params`
282+
/// extent. We then provide the `may_dangle`
283283
/// attribute as a way for destructor implementations to opt-out of
284284
/// this conservative assumption (and thus assume the obligation of
285285
/// ensuring that they do not access data nor invoke methods of

0 commit comments

Comments
 (0)