Skip to content

Commit f6840f3

Browse files
committed
Auto merge of #67060 - Centril:rollup-hwhdx4h, r=Centril
Rollup of 9 pull requests Successful merges: - #66710 (weak-into-raw: Clarify some details in Safety) - #66863 (Check break target availability when checking breaks with values) - #67002 (Fix documentation of pattern for str::matches()) - #67005 (capitalize Rust) - #67010 (Accurately portray raw identifiers in error messages) - #67011 (Include a span in more `expected...found` notes) - #67044 (E0023: handle expected != tuple pattern type) - #67045 (rustc_parser: cleanup imports) - #67055 (Make const-qualification look at more `const fn`s) Failed merges: r? @ghost
2 parents 710a362 + a008aff commit f6840f3

File tree

75 files changed

+636
-256
lines changed

Some content is hidden

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

75 files changed

+636
-256
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3806,7 +3806,6 @@ dependencies = [
38063806
"rustc_errors",
38073807
"rustc_feature",
38083808
"rustc_lexer",
3809-
"rustc_target",
38103809
"smallvec 1.0.0",
38113810
"syntax",
38123811
"syntax_pos",

src/liballoc/rc.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,10 +1648,8 @@ impl<T> Weak<T> {
16481648

16491649
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
16501650
///
1651-
/// It is up to the caller to ensure that the object is still alive when accessing it through
1652-
/// the pointer.
1653-
///
1654-
/// The pointer may be [`null`] or be dangling in case the object has already been destroyed.
1651+
/// The pointer is valid only if there are some strong references. The pointer may be dangling
1652+
/// or even [`null`] otherwise.
16551653
///
16561654
/// # Examples
16571655
///
@@ -1731,14 +1729,18 @@ impl<T> Weak<T> {
17311729
/// This can be used to safely get a strong reference (by calling [`upgrade`]
17321730
/// later) or to deallocate the weak count by dropping the `Weak<T>`.
17331731
///
1734-
/// It takes ownership of one weak count. In case a [`null`] is passed, a dangling [`Weak`] is
1735-
/// returned.
1732+
/// It takes ownership of one weak count (with the exception of pointers created by [`new`],
1733+
/// as these don't have any corresponding weak count).
17361734
///
17371735
/// # Safety
17381736
///
1739-
/// The pointer must represent one valid weak count. In other words, it must point to `T` which
1740-
/// is or *was* managed by an [`Rc`] and the weak count of that [`Rc`] must not have reached
1741-
/// 0. It is allowed for the strong count to be 0.
1737+
/// The pointer must have originated from the [`into_raw`] (or [`as_raw`], provided there was
1738+
/// a corresponding [`forget`] on the `Weak<T>`) and must still own its potential weak reference
1739+
/// count.
1740+
///
1741+
/// It is allowed for the strong count to be 0 at the time of calling this, but the weak count
1742+
/// must be non-zero or the pointer must have originated from a dangling `Weak<T>` (one created
1743+
/// by [`new`]).
17421744
///
17431745
/// # Examples
17441746
///
@@ -1763,11 +1765,13 @@ impl<T> Weak<T> {
17631765
/// assert!(unsafe { Weak::from_raw(raw_2) }.upgrade().is_none());
17641766
/// ```
17651767
///
1766-
/// [`null`]: ../../std/ptr/fn.null.html
17671768
/// [`into_raw`]: struct.Weak.html#method.into_raw
17681769
/// [`upgrade`]: struct.Weak.html#method.upgrade
17691770
/// [`Rc`]: struct.Rc.html
17701771
/// [`Weak`]: struct.Weak.html
1772+
/// [`as_raw`]: struct.Weak.html#method.as_raw
1773+
/// [`new`]: struct.Weak.html#method.new
1774+
/// [`forget`]: ../../std/mem/fn.forget.html
17711775
#[unstable(feature = "weak_into_raw", issue = "60728")]
17721776
pub unsafe fn from_raw(ptr: *const T) -> Self {
17731777
if ptr.is_null() {

src/liballoc/sync.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,10 +1324,8 @@ impl<T> Weak<T> {
13241324

13251325
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
13261326
///
1327-
/// It is up to the caller to ensure that the object is still alive when accessing it through
1328-
/// the pointer.
1329-
///
1330-
/// The pointer may be [`null`] or be dangling in case the object has already been destroyed.
1327+
/// The pointer is valid only if there are some strong references. The pointer may be dangling
1328+
/// or even [`null`] otherwise.
13311329
///
13321330
/// # Examples
13331331
///
@@ -1408,14 +1406,18 @@ impl<T> Weak<T> {
14081406
/// This can be used to safely get a strong reference (by calling [`upgrade`]
14091407
/// later) or to deallocate the weak count by dropping the `Weak<T>`.
14101408
///
1411-
/// It takes ownership of one weak count. In case a [`null`] is passed, a dangling [`Weak`] is
1412-
/// returned.
1409+
/// It takes ownership of one weak count (with the exception of pointers created by [`new`],
1410+
/// as these don't have any corresponding weak count).
14131411
///
14141412
/// # Safety
14151413
///
1416-
/// The pointer must represent one valid weak count. In other words, it must point to `T` which
1417-
/// is or *was* managed by an [`Arc`] and the weak count of that [`Arc`] must not have reached
1418-
/// 0. It is allowed for the strong count to be 0.
1414+
/// The pointer must have originated from the [`into_raw`] (or [`as_raw'], provided there was
1415+
/// a corresponding [`forget`] on the `Weak<T>`) and must still own its potential weak reference
1416+
/// count.
1417+
///
1418+
/// It is allowed for the strong count to be 0 at the time of calling this, but the weak count
1419+
/// must be non-zero or the pointer must have originated from a dangling `Weak<T>` (one created
1420+
/// by [`new`]).
14191421
///
14201422
/// # Examples
14211423
///
@@ -1440,11 +1442,13 @@ impl<T> Weak<T> {
14401442
/// assert!(unsafe { Weak::from_raw(raw_2) }.upgrade().is_none());
14411443
/// ```
14421444
///
1443-
/// [`null`]: ../../std/ptr/fn.null.html
1445+
/// [`as_raw`]: struct.Weak.html#method.as_raw
1446+
/// [`new`]: struct.Weak.html#method.new
14441447
/// [`into_raw`]: struct.Weak.html#method.into_raw
14451448
/// [`upgrade`]: struct.Weak.html#method.upgrade
14461449
/// [`Weak`]: struct.Weak.html
14471450
/// [`Arc`]: struct.Arc.html
1451+
/// [`forget`]: ../../std/mem/fn.forget.html
14481452
#[unstable(feature = "weak_into_raw", issue = "60728")]
14491453
pub unsafe fn from_raw(ptr: *const T) -> Self {
14501454
if ptr.is_null() {

src/libcore/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
#![feature(const_fn)]
7575
#![feature(const_fn_union)]
7676
#![feature(const_generics)]
77+
#![cfg_attr(not(bootstrap), feature(const_ptr_offset_from))]
78+
#![cfg_attr(not(bootstrap), feature(const_type_name))]
7779
#![feature(custom_inner_attributes)]
7880
#![feature(decl_macro)]
7981
#![feature(doc_cfg)]

src/libcore/str/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,8 +3371,8 @@ impl str {
33713371
/// An iterator over the disjoint matches of a pattern within the given string
33723372
/// slice.
33733373
///
3374-
/// The pattern can be any type that implements the Pattern trait. Notable
3375-
/// examples are `&str`, [`char`], and closures that determines the split.
3374+
/// The pattern can be a `&str`, [`char`], or a closure that determines if
3375+
/// a character matches.
33763376
///
33773377
/// # Iterator behavior
33783378
///

src/libcore/sync/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//!
2828
//! Atomic variables are safe to share between threads (they implement [`Sync`])
2929
//! but they do not themselves provide the mechanism for sharing and follow the
30-
//! [threading model](../../../std/thread/index.html#the-threading-model) of rust.
30+
//! [threading model](../../../std/thread/index.html#the-threading-model) of Rust.
3131
//! The most common way to share an atomic variable is to put it into an [`Arc`][arc] (an
3232
//! atomically-reference-counted shared pointer).
3333
//!

src/librustc/infer/error_reporting/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,12 +1809,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
18091809
sub_region,
18101810
"...",
18111811
);
1812-
err.note(&format!(
1813-
"...so that the {}:\nexpected {}\n found {}",
1814-
sup_trace.cause.as_requirement_str(),
1815-
sup_expected.content(),
1816-
sup_found.content()
1812+
err.span_note(sup_trace.cause.span, &format!(
1813+
"...so that the {}",
1814+
sup_trace.cause.as_requirement_str()
18171815
));
1816+
1817+
err.note_expected_found(
1818+
&"",
1819+
sup_expected,
1820+
&"",
1821+
sup_found
1822+
);
18181823
err.emit();
18191824
return;
18201825
}

src/librustc/infer/error_reporting/note.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1313
match *origin {
1414
infer::Subtype(ref trace) => {
1515
if let Some((expected, found)) = self.values_str(&trace.values) {
16-
let expected = expected.content();
17-
let found = found.content();
18-
err.note(&format!("...so that the {}:\nexpected {}\n found {}",
19-
trace.cause.as_requirement_str(),
20-
expected,
21-
found));
16+
err.span_note(
17+
trace.cause.span,
18+
&format!(
19+
"...so that the {}",
20+
trace.cause.as_requirement_str()
21+
)
22+
);
23+
24+
err.note_expected_found(
25+
&"",
26+
expected,
27+
&"",
28+
found
29+
);
2230
} else {
2331
// FIXME: this really should be handled at some earlier stage. Our
2432
// handling of region checking when type errors are present is

src/librustc/ty/print/pretty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,9 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
12821282
if !self.empty_path {
12831283
write!(self, "::")?;
12841284
}
1285+
if ast::Ident::from_str(&name).is_raw_guess() {
1286+
write!(self, "r#")?;
1287+
}
12851288
write!(self, "{}", name)?;
12861289

12871290
// FIXME(eddyb) this will print e.g. `{{closure}}#3`, but it

src/librustc_mir/transform/check_consts/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ impl ConstKind {
7777
let mode = match tcx.hir().body_owner_kind(hir_id) {
7878
HirKind::Closure => return None,
7979

80-
HirKind::Fn if tcx.is_const_fn(def_id) => ConstKind::ConstFn,
80+
// Note: this is deliberately checking for `is_const_fn_raw`, as the `is_const_fn`
81+
// checks take into account the `rustc_const_unstable` attribute combined with enabled
82+
// feature gates. Otherwise, const qualification would _not check_ whether this
83+
// function body follows the `const fn` rules, as an unstable `const fn` would
84+
// be considered "not const". More details are available in issue #67053.
85+
HirKind::Fn if tcx.is_const_fn_raw(def_id) => ConstKind::ConstFn,
8186
HirKind::Fn => return None,
8287

8388
HirKind::Const => ConstKind::Const,

0 commit comments

Comments
 (0)