Skip to content

Commit ea488f7

Browse files
committed
Auto merge of #3059 - rust-lang:rustup-2023-09-12, r=RalfJung
Automatic sync from rustc
2 parents 3bf9c5a + 1916a4a commit ea488f7

File tree

614 files changed

+12298
-3433
lines changed

Some content is hidden

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

614 files changed

+12298
-3433
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ build/
5858
\#*
5959
\#*\#
6060
.#*
61+
rustc-ice-*.txt
6162

6263
## Tags
6364
tags

.mailmap

+4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ Gareth Daniel Smith <[email protected]> gareth <gareth@gareth-N56VM.(n
205205
Gareth Daniel Smith <[email protected]> Gareth Smith <[email protected]>
206206
Gauri Kholkar <[email protected]>
207207
208+
Ghost <ghost> <[email protected]>
209+
Ghost <ghost> <[email protected]>
210+
Ghost <ghost> <[email protected]>
211+
Ghost <ghost> <[email protected]>
208212
Giles Cope <[email protected]>
209213
Glen De Cauwsemaecker <[email protected]>
210214
Graham Fawcett <[email protected]> Graham Fawcett <[email protected]>

Cargo.lock

+1-2
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ dependencies = [
558558
"declare_clippy_lint",
559559
"if_chain",
560560
"itertools",
561-
"pulldown-cmark",
562561
"quine-mc_cluskey",
563562
"regex",
564563
"regex-syntax 0.7.2",
@@ -4175,7 +4174,7 @@ dependencies = [
41754174
name = "rustc_parse_format"
41764175
version = "0.0.0"
41774176
dependencies = [
4178-
"rustc_data_structures",
4177+
"rustc_index",
41794178
"rustc_lexer",
41804179
]
41814180

compiler/rustc_abi/src/lib.rs

+40-1
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,18 @@ impl Abi {
13001300
matches!(*self, Abi::Uninhabited)
13011301
}
13021302

1303-
/// Returns `true` is this is a scalar type
1303+
/// Returns `true` if this is a scalar type
13041304
#[inline]
13051305
pub fn is_scalar(&self) -> bool {
13061306
matches!(*self, Abi::Scalar(_))
13071307
}
13081308

1309+
/// Returns `true` if this is a bool
1310+
#[inline]
1311+
pub fn is_bool(&self) -> bool {
1312+
matches!(*self, Abi::Scalar(s) if s.is_bool())
1313+
}
1314+
13091315
/// Returns the fixed alignment of this ABI, if any is mandated.
13101316
pub fn inherent_align<C: HasDataLayout>(&self, cx: &C) -> Option<AbiAndPrefAlign> {
13111317
Some(match *self {
@@ -1348,6 +1354,23 @@ impl Abi {
13481354
Abi::Uninhabited | Abi::Aggregate { .. } => Abi::Aggregate { sized: true },
13491355
}
13501356
}
1357+
1358+
pub fn eq_up_to_validity(&self, other: &Self) -> bool {
1359+
match (self, other) {
1360+
// Scalar, Vector, ScalarPair have `Scalar` in them where we ignore validity ranges.
1361+
// We do *not* ignore the sign since it matters for some ABIs (e.g. s390x).
1362+
(Abi::Scalar(l), Abi::Scalar(r)) => l.primitive() == r.primitive(),
1363+
(
1364+
Abi::Vector { element: element_l, count: count_l },
1365+
Abi::Vector { element: element_r, count: count_r },
1366+
) => element_l.primitive() == element_r.primitive() && count_l == count_r,
1367+
(Abi::ScalarPair(l1, l2), Abi::ScalarPair(r1, r2)) => {
1368+
l1.primitive() == r1.primitive() && l2.primitive() == r2.primitive()
1369+
}
1370+
// Everything else must be strictly identical.
1371+
_ => self == other,
1372+
}
1373+
}
13511374
}
13521375

13531376
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
@@ -1686,6 +1709,22 @@ impl LayoutS {
16861709
Abi::Aggregate { sized } => sized && self.size.bytes() == 0,
16871710
}
16881711
}
1712+
1713+
/// Checks if these two `Layout` are equal enough to be considered "the same for all function
1714+
/// call ABIs". Note however that real ABIs depend on more details that are not reflected in the
1715+
/// `Layout`; the `PassMode` need to be compared as well.
1716+
pub fn eq_abi(&self, other: &Self) -> bool {
1717+
// The one thing that we are not capturing here is that for unsized types, the metadata must
1718+
// also have the same ABI, and moreover that the same metadata leads to the same size. The
1719+
// 2nd point is quite hard to check though.
1720+
self.size == other.size
1721+
&& self.is_sized() == other.is_sized()
1722+
&& self.abi.eq_up_to_validity(&other.abi)
1723+
&& self.abi.is_bool() == other.abi.is_bool()
1724+
&& self.align.abi == other.align.abi
1725+
&& self.max_repr_align == other.max_repr_align
1726+
&& self.unadjusted_abi_align == other.unadjusted_abi_align
1727+
}
16891728
}
16901729

16911730
#[derive(Copy, Clone, Debug)]

compiler/rustc_ast_lowering/src/index.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ use rustc_data_structures::fx::FxHashMap;
22
use rustc_data_structures::sorted_map::SortedMap;
33
use rustc_hir as hir;
44
use rustc_hir::def_id::LocalDefId;
5-
use rustc_hir::definitions;
65
use rustc_hir::intravisit::{self, Visitor};
76
use rustc_hir::*;
87
use rustc_index::{Idx, IndexVec};
98
use rustc_middle::span_bug;
10-
use rustc_session::Session;
11-
use rustc_span::source_map::SourceMap;
9+
use rustc_middle::ty::TyCtxt;
1210
use rustc_span::{Span, DUMMY_SP};
1311

1412
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
1513
pub(super) struct NodeCollector<'a, 'hir> {
16-
/// Source map
17-
source_map: &'a SourceMap,
14+
tcx: TyCtxt<'hir>,
15+
1816
bodies: &'a SortedMap<ItemLocalId, &'hir Body<'hir>>,
1917

2018
/// Outputs
@@ -25,14 +23,11 @@ pub(super) struct NodeCollector<'a, 'hir> {
2523
parent_node: hir::ItemLocalId,
2624

2725
owner: OwnerId,
28-
29-
definitions: &'a definitions::Definitions,
3026
}
3127

32-
#[instrument(level = "debug", skip(sess, definitions, bodies))]
28+
#[instrument(level = "debug", skip(tcx, bodies))]
3329
pub(super) fn index_hir<'hir>(
34-
sess: &Session,
35-
definitions: &definitions::Definitions,
30+
tcx: TyCtxt<'hir>,
3631
item: hir::OwnerNode<'hir>,
3732
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
3833
) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, FxHashMap<LocalDefId, ItemLocalId>) {
@@ -42,8 +37,7 @@ pub(super) fn index_hir<'hir>(
4237
// used.
4338
nodes.push(Some(ParentedNode { parent: ItemLocalId::INVALID, node: item.into() }));
4439
let mut collector = NodeCollector {
45-
source_map: sess.source_map(),
46-
definitions,
40+
tcx,
4741
owner: item.def_id(),
4842
parent_node: ItemLocalId::new(0),
4943
nodes,
@@ -79,11 +73,17 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
7973
span,
8074
"inconsistent HirId at `{:?}` for `{:?}`: \
8175
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
82-
self.source_map.span_to_diagnostic_string(span),
76+
self.tcx.sess.source_map().span_to_diagnostic_string(span),
8377
node,
84-
self.definitions.def_path(self.owner.def_id).to_string_no_crate_verbose(),
78+
self.tcx
79+
.definitions_untracked()
80+
.def_path(self.owner.def_id)
81+
.to_string_no_crate_verbose(),
8582
self.owner,
86-
self.definitions.def_path(hir_id.owner.def_id).to_string_no_crate_verbose(),
83+
self.tcx
84+
.definitions_untracked()
85+
.def_path(hir_id.owner.def_id)
86+
.to_string_no_crate_verbose(),
8787
hir_id.owner,
8888
)
8989
}

compiler/rustc_ast_lowering/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
671671
} else {
672672
(None, None)
673673
};
674-
let (nodes, parenting) =
675-
index::index_hir(self.tcx.sess, &*self.tcx.definitions_untracked(), node, &bodies);
674+
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies);
676675
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
677676
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash };
678677

@@ -771,7 +770,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
771770
/// Intercept all spans entering HIR.
772771
/// Mark a span as relative to the current owning item.
773772
fn lower_span(&self, span: Span) -> Span {
774-
if self.tcx.sess.opts.incremental_relative_spans() {
773+
if self.tcx.sess.opts.incremental.is_some() {
775774
span.with_parent(Some(self.current_hir_id_owner.def_id))
776775
} else {
777776
// Do not make spans relative when not using incremental compilation.

compiler/rustc_borrowck/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ borrowck_returned_lifetime_wrong =
166166
borrowck_returned_ref_escaped =
167167
returns a reference to a captured variable which escapes the closure body
168168
169+
borrowck_simd_shuffle_last_const = last argument of `simd_shuffle` is required to be a `const` item
170+
169171
borrowck_suggest_create_freash_reborrow =
170172
consider reborrowing the `Pin` instead of moving it
171173

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+37-13
Original file line numberDiff line numberDiff line change
@@ -2130,21 +2130,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21302130
/// misleading users in cases like `tests/ui/nll/borrowed-temporary-error.rs`.
21312131
/// We could expand the analysis to suggest hoising all of the relevant parts of
21322132
/// the users' code to make the code compile, but that could be too much.
2133-
struct NestedStatementVisitor {
2133+
/// We found the `prop_expr` by the way to check whether the expression is a `FormatArguments`,
2134+
/// which is a special case since it's generated by the compiler.
2135+
struct NestedStatementVisitor<'tcx> {
21342136
span: Span,
21352137
current: usize,
21362138
found: usize,
2139+
prop_expr: Option<&'tcx hir::Expr<'tcx>>,
21372140
}
21382141

2139-
impl<'tcx> Visitor<'tcx> for NestedStatementVisitor {
2140-
fn visit_block(&mut self, block: &hir::Block<'tcx>) {
2142+
impl<'tcx> Visitor<'tcx> for NestedStatementVisitor<'tcx> {
2143+
fn visit_block(&mut self, block: &'tcx hir::Block<'tcx>) {
21412144
self.current += 1;
21422145
walk_block(self, block);
21432146
self.current -= 1;
21442147
}
2145-
fn visit_expr(&mut self, expr: &hir::Expr<'tcx>) {
2148+
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
21462149
if self.span == expr.span.source_callsite() {
21472150
self.found = self.current;
2151+
if self.prop_expr.is_none() {
2152+
self.prop_expr = Some(expr);
2153+
}
21482154
}
21492155
walk_expr(self, expr);
21502156
}
@@ -2162,22 +2168,40 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21622168
span: proper_span,
21632169
current: 0,
21642170
found: 0,
2171+
prop_expr: None,
21652172
};
21662173
visitor.visit_stmt(stmt);
2174+
2175+
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
2176+
let expr_ty: Option<Ty<'_>> = visitor.prop_expr.map(|expr| typeck_results.expr_ty(expr).peel_refs());
2177+
2178+
let is_format_arguments_item =
2179+
if let Some(expr_ty) = expr_ty
2180+
&& let ty::Adt(adt, _) = expr_ty.kind() {
2181+
self.infcx.tcx.lang_items().get(LangItem::FormatArguments) == Some(adt.did())
2182+
} else {
2183+
false
2184+
};
2185+
21672186
if visitor.found == 0
21682187
&& stmt.span.contains(proper_span)
21692188
&& let Some(p) = sm.span_to_margin(stmt.span)
21702189
&& let Ok(s) = sm.span_to_snippet(proper_span)
21712190
{
2172-
let addition = format!("let binding = {};\n{}", s, " ".repeat(p));
2173-
err.multipart_suggestion_verbose(
2174-
msg,
2175-
vec![
2176-
(stmt.span.shrink_to_lo(), addition),
2177-
(proper_span, "binding".to_string()),
2178-
],
2179-
Applicability::MaybeIncorrect,
2180-
);
2191+
if !is_format_arguments_item {
2192+
let addition = format!("let binding = {};\n{}", s, " ".repeat(p));
2193+
err.multipart_suggestion_verbose(
2194+
msg,
2195+
vec![
2196+
(stmt.span.shrink_to_lo(), addition),
2197+
(proper_span, "binding".to_string()),
2198+
],
2199+
Applicability::MaybeIncorrect,
2200+
);
2201+
} else {
2202+
err.note("the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used");
2203+
err.note("to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html>");
2204+
}
21812205
suggested = true;
21822206
break;
21832207
}

0 commit comments

Comments
 (0)