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

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

+14-10
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

+14-10
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

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

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

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

+10-5
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

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

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

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

src/librustc_parse/Cargo.toml

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ doctest = false
1212
[dependencies]
1313
bitflags = "1.0"
1414
log = "0.4"
15-
syntax_pos = { path = "../libsyntax_pos" }
16-
syntax = { path = "../libsyntax" }
17-
errors = { path = "../librustc_errors", package = "rustc_errors" }
1815
rustc_data_structures = { path = "../librustc_data_structures" }
1916
rustc_feature = { path = "../librustc_feature" }
2017
rustc_lexer = { path = "../librustc_lexer" }
21-
rustc_target = { path = "../librustc_target" }
22-
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
18+
rustc_errors = { path = "../librustc_errors" }
2319
rustc_error_codes = { path = "../librustc_error_codes" }
20+
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
21+
syntax_pos = { path = "../libsyntax_pos" }
22+
syntax = { path = "../libsyntax" }

src/librustc_parse/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
use crate::validate_attr;
1212
use rustc_feature::Features;
13+
use rustc_errors::Applicability;
1314
use syntax::attr::HasAttrs;
1415
use syntax::feature_gate::{feature_err, get_features};
1516
use syntax::attr;
@@ -21,7 +22,6 @@ use syntax::sess::ParseSess;
2122
use syntax::util::map_in_place::MapInPlace;
2223
use syntax_pos::symbol::sym;
2324

24-
use errors::Applicability;
2525
use smallvec::SmallVec;
2626

2727
/// A folder that strips out items that do not belong in the current configuration.

src/librustc_parse/lexer/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1+
use rustc_data_structures::sync::Lrc;
2+
use rustc_errors::{FatalError, DiagnosticBuilder};
3+
use rustc_lexer::Base;
4+
use rustc_lexer::unescape;
15
use syntax::token::{self, Token, TokenKind};
26
use syntax::sess::ParseSess;
3-
use syntax::symbol::{sym, Symbol};
47
use syntax::util::comments;
5-
6-
use errors::{FatalError, DiagnosticBuilder};
8+
use syntax_pos::symbol::{sym, Symbol};
79
use syntax_pos::{BytePos, Pos, Span};
8-
use rustc_lexer::Base;
9-
use rustc_lexer::unescape;
1010

1111
use std::char;
1212
use std::convert::TryInto;
13-
use rustc_data_structures::sync::Lrc;
1413
use log::debug;
1514

1615
mod tokentrees;

src/librustc_parse/lexer/tokentrees.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use rustc_data_structures::fx::FxHashMap;
2-
use syntax_pos::Span;
3-
41
use super::{StringReader, UnmatchedBrace};
52

3+
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_errors::PResult;
65
use syntax::print::pprust::token_to_string;
76
use syntax::token::{self, Token};
87
use syntax::tokenstream::{DelimSpan, IsJoint::{self, *}, TokenStream, TokenTree, TreeAndJoint};
9-
10-
use errors::PResult;
8+
use syntax_pos::Span;
119

1210
impl<'a> StringReader<'a> {
1311
crate fn into_token_trees(self) -> (PResult<'a, TokenStream>, Vec<UnmatchedBrace>) {

src/librustc_parse/lexer/unicode_chars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// http://www.unicode.org/Public/security/10.0.0/confusables.txt
33

44
use super::StringReader;
5-
use errors::{Applicability, DiagnosticBuilder};
6-
use syntax_pos::{BytePos, Pos, Span, symbol::kw};
75
use crate::token;
6+
use rustc_errors::{Applicability, DiagnosticBuilder};
7+
use syntax_pos::{BytePos, Pos, Span, symbol::kw};
88

99
#[rustfmt::skip] // for line breaks
1010
const UNICODE_ARRAY: &[(char, &str, char)] = &[

src/librustc_parse/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use syntax::sess::ParseSess;
88
use syntax::token::{self, Nonterminal};
99
use syntax::tokenstream::{self, TokenStream, TokenTree};
1010

11-
use errors::{PResult, FatalError, Level, Diagnostic};
11+
use rustc_errors::{PResult, FatalError, Level, Diagnostic};
1212
use rustc_data_structures::sync::Lrc;
1313
use syntax_pos::{Span, SourceFile, FileName};
1414

@@ -53,7 +53,7 @@ pub enum DirectoryOwnership {
5353
macro_rules! panictry_buffer {
5454
($handler:expr, $e:expr) => ({
5555
use std::result::Result::{Ok, Err};
56-
use errors::FatalError;
56+
use rustc_errors::FatalError;
5757
match $e {
5858
Ok(e) => e,
5959
Err(errs) => {

src/librustc_parse/parser/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::{SeqSep, Parser, TokenType, PathStyle};
2+
use rustc_errors::PResult;
23
use syntax::attr;
34
use syntax::ast;
45
use syntax::util::comments;
56
use syntax::token::{self, Nonterminal};
67
use syntax_pos::{Span, Symbol};
7-
use errors::PResult;
88

99
use log::debug;
1010

src/librustc_parse/parser/diagnostics.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
use super::{BlockMode, PathStyle, SemiColonMode, TokenType, TokenExpectType, SeqSep, Parser};
22

3-
use syntax::ast::{
4-
self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind,
5-
Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind,
6-
};
3+
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_errors::{self, PResult, Applicability, DiagnosticBuilder, Handler, pluralize};
5+
use rustc_error_codes::*;
6+
use syntax::ast::{self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item};
7+
use syntax::ast::{ItemKind, Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind};
78
use syntax::token::{self, TokenKind, token_can_begin_expr};
89
use syntax::print::pprust;
910
use syntax::ptr::P;
10-
use syntax::symbol::{kw, sym};
1111
use syntax::ThinVec;
1212
use syntax::util::parser::AssocOp;
1313
use syntax::struct_span_err;
14-
15-
use errors::{PResult, Applicability, DiagnosticBuilder, pluralize};
16-
use rustc_data_structures::fx::FxHashSet;
14+
use syntax_pos::symbol::{kw, sym};
1715
use syntax_pos::{Span, DUMMY_SP, MultiSpan, SpanSnippetError};
16+
1817
use log::{debug, trace};
1918
use std::mem;
2019

21-
use rustc_error_codes::*;
22-
2320
const TURBOFISH: &'static str = "use `::<...>` instead of `<...>` to specify type arguments";
2421

2522
/// Creates a placeholder argument.
@@ -61,10 +58,10 @@ pub enum Error {
6158
}
6259

6360
impl Error {
64-
fn span_err<S: Into<MultiSpan>>(
61+
fn span_err(
6562
self,
66-
sp: S,
67-
handler: &errors::Handler,
63+
sp: impl Into<MultiSpan>,
64+
handler: &Handler,
6865
) -> DiagnosticBuilder<'_> {
6966
match self {
7067
Error::FileNotFoundForModule {
@@ -212,7 +209,7 @@ impl<'a> Parser<'a> {
212209
self.sess.span_diagnostic.span_bug(sp, m)
213210
}
214211

215-
pub(super) fn diagnostic(&self) -> &'a errors::Handler {
212+
pub(super) fn diagnostic(&self) -> &'a Handler {
216213
&self.sess.span_diagnostic
217214
}
218215

0 commit comments

Comments
 (0)