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

+1-1
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

+1-1
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

+3-2
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

+2-2
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

+3-1
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

+56-25
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

-15
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

+6-3
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

+2-2
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

+2-2
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

src/librustdoc/html/render.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3809,7 +3809,6 @@ const ATTRIBUTE_WHITELIST: &'static [Symbol] = &[
38093809
sym::must_use,
38103810
sym::no_mangle,
38113811
sym::repr,
3812-
sym::unsafe_destructor_blind_to_params,
38133812
sym::non_exhaustive
38143813
];
38153814

src/libstd/keyword_docs.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mod continue_keyword { }
119119
/// The `as` keyword can be used to change what the crate is referred to as in your project. If a
120120
/// crate name includes a dash, it is implicitly imported with the dashes replaced by underscores.
121121
///
122-
/// `crate` is also used as in conjunction with `pub` to signify that the item it's attached to
122+
/// `crate` can also be used as in conjunction with `pub` to signify that the item it's attached to
123123
/// is public only to other members of the same crate it's in.
124124
///
125125
/// ```rust
@@ -131,6 +131,10 @@ mod continue_keyword { }
131131
/// }
132132
/// ```
133133
///
134+
/// `crate` is also used to represent the absolute path of a module, where `crate` refers to the
135+
/// root of the current crate. For instance, `crate::foo::bar` refers to the name `bar` inside the
136+
/// module `foo`, from anywhere else in the same crate.
137+
///
134138
/// [Reference]: ../reference/items/extern-crates.html
135139
mod crate_keyword { }
136140

src/libsyntax/feature_gate.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ declare_features! (
199199

200200
// no-tracking-issue-end
201201

202-
// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
203-
(active, dropck_parametricity, "1.3.0", Some(28498), None),
204-
205202
// no-tracking-issue-start
206203

207204
// Allows using `#[omit_gdb_pretty_printer_section]`.
@@ -641,6 +638,8 @@ declare_features! (
641638
(removed, extern_in_paths, "1.33.0", Some(55600), None,
642639
Some("subsumed by `::foo::bar` paths")),
643640
(removed, quote, "1.33.0", Some(29601), None, None),
641+
// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
642+
(removed, dropck_parametricity, "1.38.0", Some(28498), None, None),
644643

645644
// -------------------------------------------------------------------------
646645
// feature-group-end: removed features
@@ -1447,15 +1446,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
14471446
cfg_fn!(omit_gdb_pretty_printer_section)
14481447
)
14491448
),
1450-
(sym::unsafe_destructor_blind_to_params,
1451-
Normal,
1452-
template!(Word),
1453-
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761",
1454-
Some("replace this attribute with `#[may_dangle]`")),
1455-
sym::dropck_parametricity,
1456-
"unsafe_destructor_blind_to_params has been replaced by \
1457-
may_dangle and will be removed in the future",
1458-
cfg_fn!(dropck_parametricity))),
14591449
(sym::may_dangle,
14601450
Normal,
14611451
template!(Word),

src/libsyntax/parse/parser.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,9 @@ impl<'a> Parser<'a> {
46294629
fn parse_block_tail(&mut self, lo: Span, s: BlockCheckMode) -> PResult<'a, P<Block>> {
46304630
let mut stmts = vec![];
46314631
while !self.eat(&token::CloseDelim(token::Brace)) {
4632+
if self.token == token::Eof {
4633+
break;
4634+
}
46324635
let stmt = match self.parse_full_stmt(false) {
46334636
Err(mut err) => {
46344637
err.emit();
@@ -4643,8 +4646,6 @@ impl<'a> Parser<'a> {
46434646
};
46444647
if let Some(stmt) = stmt {
46454648
stmts.push(stmt);
4646-
} else if self.token == token::Eof {
4647-
break;
46484649
} else {
46494650
// Found only `;` or `}`.
46504651
continue;
@@ -6666,12 +6667,13 @@ impl<'a> Parser<'a> {
66666667
}
66676668

66686669
/// Reads a module from a source file.
6669-
fn eval_src_mod(&mut self,
6670-
path: PathBuf,
6671-
directory_ownership: DirectoryOwnership,
6672-
name: String,
6673-
id_sp: Span)
6674-
-> PResult<'a, (ast::Mod, Vec<Attribute> )> {
6670+
fn eval_src_mod(
6671+
&mut self,
6672+
path: PathBuf,
6673+
directory_ownership: DirectoryOwnership,
6674+
name: String,
6675+
id_sp: Span,
6676+
) -> PResult<'a, (ast::Mod, Vec<Attribute>)> {
66756677
let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut();
66766678
if let Some(i) = included_mod_stack.iter().position(|p| *p == path) {
66776679
let mut err = String::from("circular modules: ");

0 commit comments

Comments
 (0)