Skip to content

Commit e4828d5

Browse files
committed
Auto merge of rust-lang#89019 - Manishearth:rollup-5qp8a5s, r=Manishearth
Rollup of 10 pull requests Successful merges: - rust-lang#88292 (Enable --generate-link-to-definition for rustc's docs) - rust-lang#88729 (Recover from `Foo(a: 1, b: 2)`) - rust-lang#88875 (cleanup(rustc_trait_selection): remove vestigial code from rustc_on_unimplemented) - rust-lang#88892 (Move object safety suggestions to the end of the error) - rust-lang#88928 (Document the closure arguments for `reduce`.) - rust-lang#88976 (Clean up and add doc comments for CStr) - rust-lang#88983 (Allow calling `get_body_with_borrowck_facts` without `-Z polonius`) - rust-lang#88985 (Update clobber_abi list to include k[1-7] regs) - rust-lang#88986 (Update the backtrace crate) - rust-lang#89009 (Fix typo in `break` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 237bb5e + d9fa356 commit e4828d5

File tree

49 files changed

+210
-106
lines changed

Some content is hidden

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

49 files changed

+210
-106
lines changed

compiler/rustc_borrowck/src/consumers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ pub use super::{
1414
};
1515

1616
/// This function computes Polonius facts for the given body. It makes a copy of
17-
/// the body because it needs to regenerate the region identifiers.
17+
/// the body because it needs to regenerate the region identifiers. This function
18+
/// should never be invoked during a typical compilation session due to performance
19+
/// issues with Polonius.
1820
///
1921
/// Note:
2022
/// * This function will panic if the required body was already stolen. This
2123
/// can, for example, happen when requesting a body of a `const` function
2224
/// because they are evaluated during typechecking. The panic can be avoided
2325
/// by overriding the `mir_borrowck` query. You can find a complete example
2426
/// that shows how to do this at `src/test/run-make/obtain-borrowck/`.
25-
/// * This function will also panic if computation of Polonius facts
26-
/// (`-Zpolonius` flag) is not enabled.
2727
///
2828
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
2929
pub fn get_body_with_borrowck_facts<'tcx>(

compiler/rustc_borrowck/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ fn do_mir_borrowck<'a, 'tcx>(
154154

155155
debug!("do_mir_borrowck(def = {:?})", def);
156156

157-
assert!(
158-
!return_body_with_facts || infcx.tcx.sess.opts.debugging_opts.polonius,
159-
"borrowck facts can be requested only when Polonius is enabled"
160-
);
161-
162157
let tcx = infcx.tcx;
163158
let param_env = tcx.param_env(def.did);
164159
let id = tcx.hir().local_def_id_to_hir_id(def.did);
@@ -235,6 +230,8 @@ fn do_mir_borrowck<'a, 'tcx>(
235230
let borrow_set =
236231
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));
237232

233+
let use_polonius = return_body_with_facts || infcx.tcx.sess.opts.debugging_opts.polonius;
234+
238235
// Compute non-lexical lifetimes.
239236
let nll::NllOutput {
240237
regioncx,
@@ -254,6 +251,7 @@ fn do_mir_borrowck<'a, 'tcx>(
254251
&mdpe.move_data,
255252
&borrow_set,
256253
&upvars,
254+
use_polonius,
257255
);
258256

259257
// Dump MIR results into a file, if that is enabled. This let us

compiler/rustc_borrowck/src/nll.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
164164
move_data: &MoveData<'tcx>,
165165
borrow_set: &BorrowSet<'tcx>,
166166
upvars: &[Upvar<'tcx>],
167+
use_polonius: bool,
167168
) -> NllOutput<'tcx> {
168-
let mut all_facts = AllFacts::enabled(infcx.tcx).then_some(AllFacts::default());
169+
let mut all_facts =
170+
(use_polonius || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
169171

170172
let universal_regions = Rc::new(universal_regions);
171173

@@ -281,7 +283,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
281283
all_facts.write_to_dir(dir_path, location_table).unwrap();
282284
}
283285

284-
if infcx.tcx.sess.opts.debugging_opts.polonius {
286+
if use_polonius {
285287
let algorithm =
286288
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid"));
287289
let algorithm = Algorithm::from_str(&algorithm).unwrap();

compiler/rustc_expand/src/mbe/quoted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(super) fn parse(
7272
// this with just `span.edition()`. A
7373
// `SyntaxContext::root()` from the current crate will
7474
// have the edition of the current crate, and a
75-
// `SyntaxxContext::root()` from a foreign crate will
75+
// `SyntaxContext::root()` from a foreign crate will
7676
// have the edition of that crate (which we manually
7777
// retrieve via the `edition` parameter).
7878
if span.ctxt() == SyntaxContext::root() {

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ pub fn report_object_safety_error(
8383
messages.push(msg.clone());
8484
}
8585
}
86-
if trait_span.is_some() {
87-
// Only provide the help if its a local trait, otherwise it's not actionable.
88-
violation.solution(&mut err);
89-
}
9086
}
9187
}
9288
let has_multi_span = !multi_span.is_empty();
@@ -104,5 +100,13 @@ pub fn report_object_safety_error(
104100
to be resolvable dynamically; for more information visit \
105101
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
106102
);
103+
if trait_span.is_some() {
104+
let mut reported_violations: Vec<_> = reported_violations.into_iter().collect();
105+
reported_violations.sort();
106+
for violation in reported_violations {
107+
// Only provide the help if its a local trait, otherwise it's not actionable.
108+
violation.solution(&mut err);
109+
}
110+
}
107111
err
108112
}

compiler/rustc_middle/src/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ pub struct ImplSourceTraitAliasData<'tcx, N> {
730730
pub nested: Vec<N>,
731731
}
732732

733-
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable)]
733+
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
734734
pub enum ObjectSafetyViolation {
735735
/// `Self: Sized` declared on the trait.
736736
SizedSelf(SmallVec<[Span; 1]>),
@@ -879,7 +879,7 @@ impl ObjectSafetyViolation {
879879
}
880880

881881
/// Reasons a method might not be object-safe.
882-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
882+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
883883
pub enum MethodViolationCode {
884884
/// e.g., `fn foo()`
885885
StaticMethod(Option<(&'static str, Span)>, Span, bool /* has args */),

compiler/rustc_mir_dataflow/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub use self::drop_flag_effects::{
2828
on_lookup_result_bits,
2929
};
3030
pub use self::framework::{
31-
fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine, Forward,
32-
GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor,
31+
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine,
32+
Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor,
3333
ResultsVisitable, ResultsVisitor,
3434
};
3535

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ mod unreachable_prop;
7676
use rustc_const_eval::transform::check_consts;
7777
use rustc_const_eval::transform::promote_consts;
7878
use rustc_const_eval::transform::validate;
79-
use rustc_const_eval::transform::MirPass;
79+
pub use rustc_const_eval::transform::MirPass;
8080
use rustc_mir_dataflow::rustc_peek;
8181

8282
pub fn provide(providers: &mut Providers) {

compiler/rustc_parse/src/parser/expr.rs

+91-10
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,12 @@ impl<'a> Parser<'a> {
907907
}
908908
}
909909

910+
fn look_ahead_type_ascription_as_field(&mut self) -> bool {
911+
self.look_ahead(1, |t| t.is_ident())
912+
&& self.look_ahead(2, |t| t == &token::Colon)
913+
&& self.look_ahead(3, |t| t.can_begin_expr())
914+
}
915+
910916
fn parse_dot_suffix_expr(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>> {
911917
match self.token.uninterpolate().kind {
912918
token::Ident(..) => self.parse_dot_suffix(base, lo),
@@ -1056,12 +1062,76 @@ impl<'a> Parser<'a> {
10561062

10571063
/// Parse a function call expression, `expr(...)`.
10581064
fn parse_fn_call_expr(&mut self, lo: Span, fun: P<Expr>) -> P<Expr> {
1059-
let seq = self.parse_paren_expr_seq().map(|args| {
1065+
let snapshot = if self.token.kind == token::OpenDelim(token::Paren)
1066+
&& self.look_ahead_type_ascription_as_field()
1067+
{
1068+
Some((self.clone(), fun.kind.clone()))
1069+
} else {
1070+
None
1071+
};
1072+
let open_paren = self.token.span;
1073+
1074+
let mut seq = self.parse_paren_expr_seq().map(|args| {
10601075
self.mk_expr(lo.to(self.prev_token.span), self.mk_call(fun, args), AttrVec::new())
10611076
});
1077+
if let Some(expr) =
1078+
self.maybe_recover_struct_lit_bad_delims(lo, open_paren, &mut seq, snapshot)
1079+
{
1080+
return expr;
1081+
}
10621082
self.recover_seq_parse_error(token::Paren, lo, seq)
10631083
}
10641084

1085+
/// If we encounter a parser state that looks like the user has written a `struct` literal with
1086+
/// parentheses instead of braces, recover the parser state and provide suggestions.
1087+
fn maybe_recover_struct_lit_bad_delims(
1088+
&mut self,
1089+
lo: Span,
1090+
open_paren: Span,
1091+
seq: &mut PResult<'a, P<Expr>>,
1092+
snapshot: Option<(Self, ExprKind)>,
1093+
) -> Option<P<Expr>> {
1094+
match (seq.as_mut(), snapshot) {
1095+
(Err(ref mut err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
1096+
let name = pprust::path_to_string(&path);
1097+
snapshot.bump(); // `(`
1098+
match snapshot.parse_struct_fields(path.clone(), false, token::Paren) {
1099+
Ok((fields, ..)) if snapshot.eat(&token::CloseDelim(token::Paren)) => {
1100+
// We have are certain we have `Enum::Foo(a: 3, b: 4)`, suggest
1101+
// `Enum::Foo { a: 3, b: 4 }` or `Enum::Foo(3, 4)`.
1102+
*self = snapshot;
1103+
let close_paren = self.prev_token.span;
1104+
let span = lo.to(self.prev_token.span);
1105+
err.cancel();
1106+
self.struct_span_err(
1107+
span,
1108+
"invalid `struct` delimiters or `fn` call arguments",
1109+
)
1110+
.multipart_suggestion(
1111+
&format!("if `{}` is a struct, use braces as delimiters", name),
1112+
vec![(open_paren, " { ".to_string()), (close_paren, " }".to_string())],
1113+
Applicability::MaybeIncorrect,
1114+
)
1115+
.multipart_suggestion(
1116+
&format!("if `{}` is a function, use the arguments directly", name),
1117+
fields
1118+
.into_iter()
1119+
.map(|field| (field.span.until(field.expr.span), String::new()))
1120+
.collect(),
1121+
Applicability::MaybeIncorrect,
1122+
)
1123+
.emit();
1124+
return Some(self.mk_expr_err(span));
1125+
}
1126+
Ok(_) => {}
1127+
Err(mut err) => err.emit(),
1128+
}
1129+
}
1130+
_ => {}
1131+
}
1132+
None
1133+
}
1134+
10651135
/// Parse an indexing expression `expr[...]`.
10661136
fn parse_index_expr(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>> {
10671137
self.bump(); // `[`
@@ -2374,14 +2444,12 @@ impl<'a> Parser<'a> {
23742444
.emit();
23752445
}
23762446

2377-
/// Precondition: already parsed the '{'.
2378-
pub(super) fn parse_struct_expr(
2447+
pub(super) fn parse_struct_fields(
23792448
&mut self,
2380-
qself: Option<ast::QSelf>,
23812449
pth: ast::Path,
2382-
attrs: AttrVec,
23832450
recover: bool,
2384-
) -> PResult<'a, P<Expr>> {
2451+
close_delim: token::DelimToken,
2452+
) -> PResult<'a, (Vec<ExprField>, ast::StructRest, bool)> {
23852453
let mut fields = Vec::new();
23862454
let mut base = ast::StructRest::None;
23872455
let mut recover_async = false;
@@ -2393,11 +2461,11 @@ impl<'a> Parser<'a> {
23932461
e.note("for more on editions, read https://doc.rust-lang.org/edition-guide");
23942462
};
23952463

2396-
while self.token != token::CloseDelim(token::Brace) {
2464+
while self.token != token::CloseDelim(close_delim) {
23972465
if self.eat(&token::DotDot) {
23982466
let exp_span = self.prev_token.span;
23992467
// We permit `.. }` on the left-hand side of a destructuring assignment.
2400-
if self.check(&token::CloseDelim(token::Brace)) {
2468+
if self.check(&token::CloseDelim(close_delim)) {
24012469
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
24022470
base = ast::StructRest::Rest(self.prev_token.span.shrink_to_hi());
24032471
break;
@@ -2438,7 +2506,7 @@ impl<'a> Parser<'a> {
24382506
}
24392507
};
24402508

2441-
match self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)]) {
2509+
match self.expect_one_of(&[token::Comma], &[token::CloseDelim(close_delim)]) {
24422510
Ok(_) => {
24432511
if let Some(f) = parsed_field.or(recovery_field) {
24442512
// Only include the field if there's no parse error for the field name.
@@ -2469,8 +2537,21 @@ impl<'a> Parser<'a> {
24692537
}
24702538
}
24712539
}
2540+
Ok((fields, base, recover_async))
2541+
}
24722542

2473-
let span = pth.span.to(self.token.span);
2543+
/// Precondition: already parsed the '{'.
2544+
pub(super) fn parse_struct_expr(
2545+
&mut self,
2546+
qself: Option<ast::QSelf>,
2547+
pth: ast::Path,
2548+
attrs: AttrVec,
2549+
recover: bool,
2550+
) -> PResult<'a, P<Expr>> {
2551+
let lo = pth.span;
2552+
let (fields, base, recover_async) =
2553+
self.parse_struct_fields(pth.clone(), recover, token::Brace)?;
2554+
let span = lo.to(self.token.span);
24742555
self.expect(&token::CloseDelim(token::Brace))?;
24752556
let expr = if recover_async {
24762557
ExprKind::Err

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,6 @@ symbols! {
934934
panic_unwind,
935935
panicking,
936936
param_attrs,
937-
parent_trait,
938937
partial_cmp,
939938
partial_ord,
940939
passes,

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
154154
flags.push((sym::from_method, Some(method.to_string())));
155155
}
156156
}
157-
if let Some((t, _)) = self.get_parent_trait_ref(&obligation.cause.code) {
158-
flags.push((sym::parent_trait, Some(t)));
159-
}
160157

161158
if let Some(k) = obligation.cause.span.desugaring_kind() {
162159
flags.push((sym::from_desugaring, None));

library/core/src/iter/traits/iterator.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2172,8 +2172,9 @@ pub trait Iterator {
21722172
/// If the iterator is empty, returns [`None`]; otherwise, returns the
21732173
/// result of the reduction.
21742174
///
2175+
/// The reducing function is a closure with two arguments: an 'accumulator', and an element.
21752176
/// For iterators with at least one element, this is the same as [`fold()`]
2176-
/// with the first element of the iterator as the initial value, folding
2177+
/// with the first element of the iterator as the initial accumulator value, folding
21772178
/// every subsequent element into it.
21782179
///
21792180
/// [`fold()`]: Iterator::fold
@@ -2187,8 +2188,8 @@ pub trait Iterator {
21872188
/// where I: Iterator,
21882189
/// I::Item: Ord,
21892190
/// {
2190-
/// iter.reduce(|a, b| {
2191-
/// if a >= b { a } else { b }
2191+
/// iter.reduce(|accum, item| {
2192+
/// if accum >= item { accum } else { item }
21922193
/// })
21932194
/// }
21942195
/// let a = [10, 20, 5, -23, 0];

library/std/src/ffi/c_str.rs

+3
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ impl From<CString> for Box<CStr> {
915915

916916
#[stable(feature = "cow_from_cstr", since = "1.28.0")]
917917
impl<'a> From<CString> for Cow<'a, CStr> {
918+
/// Converts a [`CString`] into an owned [`Cow`] without copying or allocating.
918919
#[inline]
919920
fn from(s: CString) -> Cow<'a, CStr> {
920921
Cow::Owned(s)
@@ -923,6 +924,7 @@ impl<'a> From<CString> for Cow<'a, CStr> {
923924

924925
#[stable(feature = "cow_from_cstr", since = "1.28.0")]
925926
impl<'a> From<&'a CStr> for Cow<'a, CStr> {
927+
/// Converts a [`CStr`] into a borrowed [`Cow`] without copying or allocating.
926928
#[inline]
927929
fn from(s: &'a CStr) -> Cow<'a, CStr> {
928930
Cow::Borrowed(s)
@@ -931,6 +933,7 @@ impl<'a> From<&'a CStr> for Cow<'a, CStr> {
931933

932934
#[stable(feature = "cow_from_cstr", since = "1.28.0")]
933935
impl<'a> From<&'a CString> for Cow<'a, CStr> {
936+
/// Converts a `&`[`CString`] into a borrowed [`Cow`] without copying or allocating.
934937
#[inline]
935938
fn from(s: &'a CString) -> Cow<'a, CStr> {
936939
Cow::Borrowed(s.as_c_str())

library/std/src/keyword_docs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ mod as_keyword {}
7777
/// '_inner: for j in 1..=200 {
7878
/// println!(" inner iteration (j): {}", j);
7979
/// if j >= 3 {
80-
/// // breaks from inner loop, let's outer loop continue.
80+
/// // breaks from inner loop, lets outer loop continue.
8181
/// break;
8282
/// }
8383
/// if i >= 2 {

src/bootstrap/doc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ impl Step for Rustc {
589589
cargo.rustdocflag("-Zunstable-options");
590590
cargo.rustdocflag("-Znormalize-docs");
591591
cargo.rustdocflag("--show-type-layout");
592+
cargo.rustdocflag("--generate-link-to-definition");
592593
compile::rustc_cargo(builder, &mut cargo, target);
593594
cargo.arg("-Zunstable-options");
594595
cargo.arg("-Zskip-rustdoc-fingerprint");

src/doc/unstable-book/src/library-features/asm.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,9 @@ The following ABIs can be used with `clobber_abi`:
804804

805805
| Architecture | ABI name | Clobbered registers |
806806
| ------------ | -------- | ------------------- |
807-
| x86-32 | `"C"`, `"system"`, `"efiapi"`, `"cdecl"`, `"stdcall"`, `"fastcall"` | `ax`, `cx`, `dx`, `xmm[0-7]`, `mm[0-7]`, `st([0-7])` |
808-
| x86-64 | `"C"`, `"system"` (on Windows), `"efiapi"`, `"win64"` | `ax`, `cx`, `dx`, `r[8-11]`, `xmm[0-31]`, `mm[0-7]`, `st([0-7])` |
809-
| x86-64 | `"C"`, `"system"` (on non-Windows), `"sysv64"` | `ax`, `cx`, `dx`, `si`, `di`, `r[8-11]`, `xmm[0-31]`, `mm[0-7]`, `st([0-7])` |
807+
| x86-32 | `"C"`, `"system"`, `"efiapi"`, `"cdecl"`, `"stdcall"`, `"fastcall"` | `ax`, `cx`, `dx`, `xmm[0-7]`, `mm[0-7]`, `k[1-7]`, `st([0-7])` |
808+
| x86-64 | `"C"`, `"system"` (on Windows), `"efiapi"`, `"win64"` | `ax`, `cx`, `dx`, `r[8-11]`, `xmm[0-31]`, `mm[0-7]`, `k[1-7]`, `st([0-7])` |
809+
| x86-64 | `"C"`, `"system"` (on non-Windows), `"sysv64"` | `ax`, `cx`, `dx`, `si`, `di`, `r[8-11]`, `xmm[0-31]`, `mm[0-7]`, `k[1-7]`, `st([0-7])` |
810810
| AArch64 | `"C"`, `"system"`, `"efiapi"` | `x[0-17]`, `x30`, `v[0-31]`, `p[0-15]`, `ffr` |
811811
| ARM | `"C"`, `"system"`, `"efiapi"`, `"aapcs"` | `r[0-3]`, `r12`, `r14`, `s[0-15]`, `d[0-7]`, `d[16-31]` |
812812
| RISC-V | `"C"`, `"system"`, `"efiapi"` | `x1`, `x[5-7]`, `x[10-17]`, `x[28-31]`, `f[0-7]`, `f[10-17]`, `f[28-31]`, `v[0-31]` |

0 commit comments

Comments
 (0)