Skip to content

Commit 50c0192

Browse files
committed
Auto merge of rust-lang#73235 - Dylan-DPC:rollup-zp8oxhg, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#72380 (Fix `is_const_context`, update `check_for_cast`) - rust-lang#72941 (Ensure stack when building MIR for matches) - rust-lang#72976 (Clean up E0642 explanation) - rust-lang#73080 (doc/rustdoc: Fix incorrect external_doc feature flag) - rust-lang#73155 (save_analysis: better handle paths and functions signature) - rust-lang#73164 (Add new E0762 error code) - rust-lang#73172 (Fix more clippy warnings) - rust-lang#73181 (Automatically prioritize unsoundness issues) - rust-lang#73183 (Support proc macros in intra doc link resolution) - rust-lang#73208 (Fix doctest template) - rust-lang#73219 (x.py: with --json-output, forward cargo's JSON) Failed merges: r? @ghost
2 parents 3ddf480 + ba0a8d2 commit 50c0192

File tree

44 files changed

+5807
-415
lines changed

Some content is hidden

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

44 files changed

+5807
-415
lines changed

src/bootstrap/compile.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,13 @@ pub fn stream_cargo(
983983
for line in stdout.lines() {
984984
let line = t!(line);
985985
match serde_json::from_str::<CargoMessage<'_>>(&line) {
986-
Ok(msg) => cb(msg),
986+
Ok(msg) => {
987+
if builder.config.json_output {
988+
// Forward JSON to stdout.
989+
println!("{}", line);
990+
}
991+
cb(msg)
992+
}
987993
// If this was informational, just print it out and continue
988994
Err(_) => println!("{}", line),
989995
}

src/doc/rustdoc/src/documentation-tests.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ without including it in your main documentation. For example, you could write th
416416
`lib.rs` to test your README as part of your doctests:
417417

418418
```rust,ignore
419-
#![feature(extern_doc)]
419+
#![feature(external_doc)]
420420
421421
#[doc(include="../README.md")]
422422
#[cfg(doctest)]

src/libcore/num/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3309,7 +3309,8 @@ Basic usage:
33093309
33103310
```
33113311
", $Feature, "assert_eq!(100", stringify!($SelfT), ".saturating_add(1), 101);
3312-
assert_eq!(200u8.saturating_add(127), 255);", $EndFeature, "
3312+
assert_eq!(", stringify!($SelfT), "::MAX.saturating_add(127), ", stringify!($SelfT), "::MAX);",
3313+
$EndFeature, "
33133314
```"),
33143315

33153316
#[stable(feature = "rust1", since = "1.0.0")]

src/librustc_ast/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl TokenStream {
392392
break;
393393
}
394394
}
395-
token_trees = out.into_iter().map(|t| TokenTree::Token(t)).collect();
395+
token_trees = out.into_iter().map(TokenTree::Token).collect();
396396
if token_trees.len() != 1 {
397397
debug!("break_tokens: broke {:?} to {:?}", tree, token_trees);
398398
}

src/librustc_ast_lowering/expr.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1237,10 +1237,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
12371237
) => {
12381238
assert!(!*late);
12391239
let out_op_sp = if input { op_sp2 } else { op_sp };
1240-
let msg = &format!(
1241-
"use `lateout` instead of \
1242-
`out` to avoid conflict"
1243-
);
1240+
let msg = "use `lateout` instead of \
1241+
`out` to avoid conflict";
12441242
err.span_help(out_op_sp, msg);
12451243
}
12461244
_ => {}

src/librustc_builtin_macros/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
457457

458458
let mut chars = arg.format.ty.chars();
459459
let mut modifier = chars.next();
460-
if !chars.next().is_none() {
460+
if chars.next().is_some() {
461461
let span = arg
462462
.format
463463
.ty_span

src/librustc_codegen_ssa/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6363
.tcx()
6464
.destructure_const(ty::ParamEnv::reveal_all().and(&c))
6565
.fields
66-
.into_iter()
66+
.iter()
6767
.map(|field| {
6868
if let Some(prim) = field.val.try_to_scalar() {
6969
let layout = bx.layout_of(field_ty);

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ E0754: include_str!("./error_codes/E0754.md"),
440440
E0758: include_str!("./error_codes/E0758.md"),
441441
E0760: include_str!("./error_codes/E0760.md"),
442442
E0761: include_str!("./error_codes/E0761.md"),
443+
E0762: include_str!("./error_codes/E0762.md"),
443444
;
444445
// E0006, // merged with E0005
445446
// E0008, // cannot bind by-move into a pattern guard

src/librustc_error_codes/error_codes/E0642.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Trait methods currently cannot take patterns as arguments.
22

3-
Example of erroneous code:
3+
Erroneous code example:
44

55
```compile_fail,E0642
66
trait Foo {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
A character literal wasn't ended with a quote.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0762
6+
static C: char = '●; // error!
7+
```
8+
9+
To fix this error, add the missing quote:
10+
11+
```
12+
static C: char = '●'; // ok!
13+
```

src/librustc_errors/annotate_snippet_emitter_writer.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,10 @@ impl AnnotateSnippetEmitterWriter {
159159
// FIXME(#59346): Not really sure when `fold` should be true or false
160160
fold: false,
161161
annotations: annotations
162-
.into_iter()
162+
.iter()
163163
.map(|annotation| SourceAnnotation {
164164
range: (annotation.start_col, annotation.end_col),
165-
label: annotation
166-
.label
167-
.as_ref()
168-
.map(|s| s.as_str())
169-
.unwrap_or_default(),
165+
label: annotation.label.as_deref().unwrap_or_default(),
170166
annotation_type: annotation_type_for_level(*level),
171167
})
172168
.collect(),

src/librustc_hir_pretty/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,28 @@ pub fn path_to_string(segment: &hir::Path<'_>) -> String {
227227
to_string(NO_ANN, |s| s.print_path(segment, false))
228228
}
229229

230+
pub fn fn_to_string(
231+
decl: &hir::FnDecl<'_>,
232+
header: hir::FnHeader,
233+
name: Option<Symbol>,
234+
generics: &hir::Generics<'_>,
235+
vis: &hir::Visibility<'_>,
236+
arg_names: &[Ident],
237+
body_id: Option<hir::BodyId>,
238+
) -> String {
239+
to_string(NO_ANN, |s| s.print_fn(decl, header, name, generics, vis, arg_names, body_id))
240+
}
241+
242+
pub fn enum_def_to_string(
243+
enum_definition: &hir::EnumDef<'_>,
244+
generics: &hir::Generics<'_>,
245+
name: Symbol,
246+
span: rustc_span::Span,
247+
visibility: &hir::Visibility<'_>,
248+
) -> String {
249+
to_string(NO_ANN, |s| s.print_enum_def(enum_definition, generics, name, span, visibility))
250+
}
251+
230252
impl<'a> State<'a> {
231253
pub fn cbox(&mut self, u: usize) {
232254
self.s.cbox(u);

src/librustc_infer/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
550550
let error_code = error_code.into();
551551
let mut err = self.tcx.sess.struct_span_err_with_code(
552552
local_visitor.target_span,
553-
&format!("type annotations needed"),
553+
"type annotations needed",
554554
error_code,
555555
);
556556

src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7777
}
7878
_ => {}
7979
}
80-
let mut type_param_span: MultiSpan =
81-
visitor.types.iter().cloned().collect::<Vec<_>>().into();
80+
let mut type_param_span: MultiSpan = visitor.types.to_vec().into();
8281
for &span in &visitor.types {
8382
type_param_span.push_span_label(
8483
span,

src/librustc_lexer/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ pub fn strip_shebang(input: &str) -> Option<usize> {
187187
// Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
188188
// a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
189189
// then it may be valid Rust code, so consider it Rust code.
190-
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).filter(|tok|
190+
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok|
191191
!matches!(tok, TokenKind::Whitespace | TokenKind::LineComment | TokenKind::BlockComment { .. })
192-
).next();
192+
);
193193
if next_non_whitespace_token != Some(TokenKind::OpenBracket) {
194194
// No other choice than to consider this a shebang.
195195
return Some(2 + first_line_tail.len());

src/librustc_middle/hir/map/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ impl<'hir> Map<'hir> {
335335
}
336336
}
337337

338+
pub fn enclosing_body_owner(&self, hir_id: HirId) -> HirId {
339+
for (parent, _) in self.parent_iter(hir_id) {
340+
if let Some(body) = self.maybe_body_owned_by(parent) {
341+
return self.body_owner(body);
342+
}
343+
}
344+
345+
bug!("no `enclosing_body_owner` for hir_id `{}`", hir_id);
346+
}
347+
338348
/// Returns the `HirId` that corresponds to the definition of
339349
/// which this is the body of, i.e., a `fn`, `const` or `static`
340350
/// item (possibly associated), a closure, or a `hir::AnonConst`.
@@ -537,18 +547,8 @@ impl<'hir> Map<'hir> {
537547

538548
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
539549
/// Used exclusively for diagnostics, to avoid suggestion function calls.
540-
pub fn is_const_context(&self, hir_id: HirId) -> bool {
541-
let parent_id = self.get_parent_item(hir_id);
542-
match self.get(parent_id) {
543-
Node::Item(&Item { kind: ItemKind::Const(..) | ItemKind::Static(..), .. })
544-
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), .. })
545-
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Const(..), .. })
546-
| Node::AnonConst(_) => true,
547-
Node::Item(&Item { kind: ItemKind::Fn(ref sig, ..), .. }) => {
548-
sig.header.constness == Constness::Const
549-
}
550-
_ => false,
551-
}
550+
pub fn is_inside_const_context(&self, hir_id: HirId) -> bool {
551+
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
552552
}
553553

554554
/// Whether `hir_id` corresponds to a `mod` or a crate.

src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
495495
let closure_id = hir.as_local_hir_id(self.mir_def_id);
496496
let fn_call_id = hir.get_parent_node(closure_id);
497497
let node = hir.get(fn_call_id);
498-
let item_id = hir.get_parent_item(fn_call_id);
498+
let item_id = hir.enclosing_body_owner(fn_call_id);
499499
let mut look_at_return = true;
500500
// If we can detect the expression to be an `fn` call where the closure was an argument,
501501
// we point at the `fn` definition argument...

src/librustc_mir/const_eval/eval_queries.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ pub fn const_eval_raw_provider<'tcx>(
309309

310310
let res = ecx.load_mir(cid.instance.def, cid.promoted);
311311
res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body))
312-
.and_then(|place| {
313-
Ok(RawConst { alloc_id: place.ptr.assert_ptr().alloc_id, ty: place.layout.ty })
314-
})
312+
.map(|place| RawConst { alloc_id: place.ptr.assert_ptr().alloc_id, ty: place.layout.ty })
315313
.map_err(|error| {
316314
let err = error_to_const_error(&ecx, error);
317315
// errors in statics are always emitted as fatal errors

src/librustc_mir/transform/check_packed_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PackedRefChecker<'a, 'tcx> {
5151
lint_root,
5252
source_info.span,
5353
|lint| {
54-
lint.build(&format!("reference to packed field is unaligned",))
54+
lint.build("reference to packed field is unaligned")
5555
.note(
5656
"fields of packed structs are not properly aligned, and creating \
5757
a misaligned reference is undefined behavior (even if that \

src/librustc_mir/transform/nrvo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn local_eligible_for_nrvo(body: &mut mir::Body<'_>) -> Option<Local> {
111111
copied_to_return_place = Some(returned_local);
112112
}
113113

114-
return copied_to_return_place;
114+
copied_to_return_place
115115
}
116116

117117
fn find_local_assigned_to_return_place(
@@ -136,7 +136,7 @@ fn find_local_assigned_to_return_place(
136136
}
137137
}
138138

139-
return None;
139+
None
140140
}
141141

142142
// If this statement is an assignment of an unprojected local to the return place,

src/librustc_mir/transform/simplify_try.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn get_arm_identity_info<'a, 'tcx>(stmts: &'a [Statement<'tcx>]) -> Option<ArmId
9999
fn try_eat<'a, 'tcx>(
100100
stmt_iter: &mut StmtIter<'a, 'tcx>,
101101
test: impl Fn(&'a Statement<'tcx>) -> bool,
102-
mut action: impl FnMut(usize, &'a Statement<'tcx>) -> (),
102+
mut action: impl FnMut(usize, &'a Statement<'tcx>),
103103
) {
104104
while stmt_iter.peek().map(|(_, stmt)| test(stmt)).unwrap_or(false) {
105105
let (idx, stmt) = stmt_iter.next().unwrap();
@@ -271,7 +271,7 @@ fn optimization_applies<'tcx>(
271271
}
272272

273273
// Verify the assigment chain consists of the form b = a; c = b; d = c; etc...
274-
if opt_info.field_tmp_assignments.len() == 0 {
274+
if opt_info.field_tmp_assignments.is_empty() {
275275
trace!("NO: no assignments found");
276276
}
277277
let mut last_assigned_to = opt_info.field_tmp_assignments[0].1;

src/librustc_mir_build/build/matches/mod.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
1010
use crate::build::{BlockAnd, BlockAndExtension, Builder};
1111
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
1212
use crate::hair::{self, *};
13-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
13+
use rustc_data_structures::{fx::{FxHashMap, FxHashSet}, stack::ensure_sufficient_stack};
1414
use rustc_hir::HirId;
1515
use rustc_index::bit_set::BitSet;
1616
use rustc_middle::middle::region;
@@ -909,30 +909,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
909909
split_or_candidate |= self.simplify_candidate(candidate);
910910
}
911911

912-
if split_or_candidate {
913-
// At least one of the candidates has been split into subcandidates.
914-
// We need to change the candidate list to include those.
915-
let mut new_candidates = Vec::new();
912+
ensure_sufficient_stack(|| {
913+
if split_or_candidate {
914+
// At least one of the candidates has been split into subcandidates.
915+
// We need to change the candidate list to include those.
916+
let mut new_candidates = Vec::new();
916917

917-
for candidate in candidates {
918-
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
918+
for candidate in candidates {
919+
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
920+
}
921+
self.match_simplified_candidates(
922+
span,
923+
start_block,
924+
otherwise_block,
925+
&mut *new_candidates,
926+
fake_borrows,
927+
);
928+
} else {
929+
self.match_simplified_candidates(
930+
span,
931+
start_block,
932+
otherwise_block,
933+
candidates,
934+
fake_borrows,
935+
);
919936
}
920-
self.match_simplified_candidates(
921-
span,
922-
start_block,
923-
otherwise_block,
924-
&mut *new_candidates,
925-
fake_borrows,
926-
);
927-
} else {
928-
self.match_simplified_candidates(
929-
span,
930-
start_block,
931-
otherwise_block,
932-
candidates,
933-
fake_borrows,
934-
);
935-
};
937+
});
936938
}
937939

938940
fn match_simplified_candidates(

src/librustc_parse/lexer/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,15 @@ impl<'a> StringReader<'a> {
325325
let (lit_kind, mode, prefix_len, postfix_len) = match kind {
326326
rustc_lexer::LiteralKind::Char { terminated } => {
327327
if !terminated {
328-
self.fatal_span_(start, suffix_start, "unterminated character literal").raise()
328+
self.sess
329+
.span_diagnostic
330+
.struct_span_fatal_with_code(
331+
self.mk_sp(start, suffix_start),
332+
"unterminated character literal",
333+
error_code!(E0762),
334+
)
335+
.emit();
336+
FatalError.raise();
329337
}
330338
(token::Char, Mode::Char, 1, 1) // ' '
331339
}
@@ -401,7 +409,7 @@ impl<'a> StringReader<'a> {
401409
let content_end = suffix_start - BytePos(postfix_len);
402410
let id = self.symbol_from_to(content_start, content_end);
403411
self.validate_literal_escape(mode, content_start, content_end);
404-
return (lit_kind, id);
412+
(lit_kind, id)
405413
}
406414

407415
pub fn pos(&self) -> BytePos {

src/librustc_parse/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ impl<'a> Parser<'a> {
936936
} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
937937
// The current token is in the same line as the prior token, not recoverable.
938938
} else if [token::Comma, token::Colon].contains(&self.token.kind)
939-
&& &self.prev_token.kind == &token::CloseDelim(token::Paren)
939+
&& self.prev_token.kind == token::CloseDelim(token::Paren)
940940
{
941941
// Likely typo: The current token is on a new line and is expected to be
942942
// `.`, `;`, `?`, or an operator after a close delimiter token.

0 commit comments

Comments
 (0)