Skip to content

Commit 4d0b4a3

Browse files
authored
Merge branch 'rust-lang:main' into doc/location-caller-updated
2 parents ff7b6cc + 77761f3 commit 4d0b4a3

File tree

855 files changed

+11234
-5858
lines changed

Some content is hidden

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

855 files changed

+11234
-5858
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ no_llvm_build
4848
/llvm/
4949
/mingw-build/
5050
/build
51-
/build-rust-analyzer/
51+
/build-rust-analyzer
5252
/dist/
5353
/unicode-downloads
5454
/target

Cargo.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
12881288
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
12891289
dependencies = [
12901290
"libc",
1291-
"windows-sys 0.52.0",
1291+
"windows-sys 0.60.2",
12921292
]
12931293

12941294
[[package]]
@@ -2154,7 +2154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
21542154
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
21552155
dependencies = [
21562156
"cfg-if",
2157-
"windows-targets 0.52.6",
2157+
"windows-targets 0.53.3",
21582158
]
21592159

21602160
[[package]]
@@ -4905,7 +4905,7 @@ dependencies = [
49054905
"errno",
49064906
"libc",
49074907
"linux-raw-sys",
4908-
"windows-sys 0.52.0",
4908+
"windows-sys 0.61.2",
49094909
]
49104910

49114911
[[package]]
@@ -5273,9 +5273,9 @@ dependencies = [
52735273

52745274
[[package]]
52755275
name = "stringdex"
5276-
version = "0.0.2"
5276+
version = "0.0.3"
52775277
source = "registry+https://github.com/rust-lang/crates.io-index"
5278-
checksum = "18b3bd4f10d15ef859c40291769f0d85209de6b0f1c30713ff9cdf45ac43ea36"
5278+
checksum = "556a6126952cb2f5150057c98a77cc6c771027dea2825bf7fa03d3d638b0a4f8"
52795279
dependencies = [
52805280
"stacker",
52815281
]

bootstrap.example.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
# toolchain or changing LLVM locally, you probably want to leave this enabled.
6060
#
6161
# Set this to `true` to download if CI llvm available otherwise it builds
62-
# from `src/llvm-project`.
62+
# from `src/llvm-project`. If you set it to `true`, it's safe and time-saving to run
63+
# `git submodule deinit src/llvm-project` to avoid git updating the llvm-project submodule
64+
# when building compiler locally.
65+
#
6366
#
6467
# Set this to `"if-unchanged"` to download only if the llvm-project has not
6568
# been modified. You can also use this if you are unsure whether you're on a

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,51 @@ impl ExternAbi {
276276
_ => CVariadicStatus::NotSupported,
277277
}
278278
}
279+
280+
/// Returns whether the ABI supports guaranteed tail calls.
281+
#[cfg(feature = "nightly")]
282+
pub fn supports_guaranteed_tail_call(self) -> bool {
283+
match self {
284+
Self::CmseNonSecureCall | Self::CmseNonSecureEntry => {
285+
// See https://godbolt.org/z/9jhdeqErv. The CMSE calling conventions clear registers
286+
// before returning, and hence cannot guarantee a tail call.
287+
false
288+
}
289+
Self::AvrInterrupt
290+
| Self::AvrNonBlockingInterrupt
291+
| Self::Msp430Interrupt
292+
| Self::RiscvInterruptM
293+
| Self::RiscvInterruptS
294+
| Self::X86Interrupt => {
295+
// See https://godbolt.org/z/Edfjnxxcq. Interrupts cannot be called directly.
296+
false
297+
}
298+
Self::GpuKernel | Self::PtxKernel => {
299+
// See https://godbolt.org/z/jq5TE5jK1.
300+
false
301+
}
302+
Self::Custom => {
303+
// This ABI does not support calls at all (except via assembly).
304+
false
305+
}
306+
Self::C { .. }
307+
| Self::System { .. }
308+
| Self::Rust
309+
| Self::RustCall
310+
| Self::RustCold
311+
| Self::RustInvalid
312+
| Self::Unadjusted
313+
| Self::EfiApi
314+
| Self::Aapcs { .. }
315+
| Self::Cdecl { .. }
316+
| Self::Stdcall { .. }
317+
| Self::Fastcall { .. }
318+
| Self::Thiscall { .. }
319+
| Self::Vectorcall { .. }
320+
| Self::SysV64 { .. }
321+
| Self::Win64 { .. } => true,
322+
}
323+
}
279324
}
280325

281326
pub fn all_names() -> Vec<&'static str> {

compiler/rustc_ast/src/visit.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,9 @@ macro_rules! common_visitor_and_walkers {
645645
fn visit_fn(
646646
&mut self,
647647
fk: FnKind<$($lt)? $(${ignore($mut)} '_)?>,
648+
_: &AttrVec,
648649
_: Span,
649-
_: NodeId
650+
_: NodeId,
650651
) -> Self::Result {
651652
walk_fn(self, fk)
652653
}
@@ -740,6 +741,7 @@ macro_rules! common_visitor_and_walkers {
740741
type Ctxt;
741742
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
742743
&$($lt)? $($mut)? self,
744+
attrs: &AttrVec,
743745
span: Span,
744746
id: NodeId,
745747
visibility: &$($lt)? $($mut)? Visibility,
@@ -773,7 +775,7 @@ macro_rules! common_visitor_and_walkers {
773775
) -> V::Result {
774776
let Item { attrs, id, kind, vis, span, tokens: _ } = item;
775777
visit_visitable!($($mut)? visitor, id, attrs, vis);
776-
try_visit!(kind.walk(*span, *id, vis, ctxt, visitor));
778+
try_visit!(kind.walk(attrs, *span, *id, vis, ctxt, visitor));
777779
visit_visitable!($($mut)? visitor, span);
778780
V::Result::output()
779781
}
@@ -799,6 +801,7 @@ macro_rules! common_visitor_and_walkers {
799801
type Ctxt = ();
800802
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
801803
&$($lt)? $($mut)? self,
804+
attrs: &AttrVec,
802805
span: Span,
803806
id: NodeId,
804807
visibility: &$($lt)? $($mut)? Visibility,
@@ -808,7 +811,7 @@ macro_rules! common_visitor_and_walkers {
808811
match self {
809812
ItemKind::Fn(func) => {
810813
let kind = FnKind::Fn(FnCtxt::Free, visibility, &$($mut)? *func);
811-
try_visit!(vis.visit_fn(kind, span, id));
814+
try_visit!(vis.visit_fn(kind, attrs, span, id));
812815
}
813816
ItemKind::ExternCrate(orig_name, ident) =>
814817
visit_visitable!($($mut)? vis, orig_name, ident),
@@ -856,6 +859,7 @@ macro_rules! common_visitor_and_walkers {
856859
type Ctxt = AssocCtxt;
857860
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
858861
&$($lt)? $($mut)? self,
862+
attrs: &AttrVec,
859863
span: Span,
860864
id: NodeId,
861865
visibility: &$($lt)? $($mut)? Visibility,
@@ -867,7 +871,7 @@ macro_rules! common_visitor_and_walkers {
867871
visit_visitable!($($mut)? vis, item),
868872
AssocItemKind::Fn(func) => {
869873
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), visibility, &$($mut)? *func);
870-
try_visit!(vis.visit_fn(kind, span, id))
874+
try_visit!(vis.visit_fn(kind, attrs, span, id))
871875
}
872876
AssocItemKind::Type(alias) =>
873877
visit_visitable!($($mut)? vis, alias),
@@ -886,6 +890,7 @@ macro_rules! common_visitor_and_walkers {
886890
type Ctxt = ();
887891
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
888892
&$($lt)? $($mut)? self,
893+
attrs: &AttrVec,
889894
span: Span,
890895
id: NodeId,
891896
visibility: &$($lt)? $($mut)? Visibility,
@@ -897,7 +902,7 @@ macro_rules! common_visitor_and_walkers {
897902
visit_visitable!($($mut)? vis, item),
898903
ForeignItemKind::Fn(func) => {
899904
let kind = FnKind::Fn(FnCtxt::Foreign, visibility, &$($mut)?*func);
900-
try_visit!(vis.visit_fn(kind, span, id))
905+
try_visit!(vis.visit_fn(kind, attrs, span, id))
901906
}
902907
ForeignItemKind::TyAlias(alias) =>
903908
visit_visitable!($($mut)? vis, alias),
@@ -999,7 +1004,7 @@ macro_rules! common_visitor_and_walkers {
9991004
}) => {
10001005
visit_visitable!($($mut)? vis, constness, movability, capture_clause);
10011006
let kind = FnKind::Closure(binder, coroutine_kind, fn_decl, body);
1002-
try_visit!(vis.visit_fn(kind, *span, *id));
1007+
try_visit!(vis.visit_fn(kind, attrs, *span, *id));
10031008
visit_visitable!($($mut)? vis, fn_decl_span, fn_arg_span);
10041009
}
10051010
ExprKind::Block(block, opt_label) =>

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
16+
use rustc_span::{ByteSymbol, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span, call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1771,8 +1771,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
17711771
let pat = self.lower_pat(pat);
17721772
let for_span =
17731773
self.mark_span_with_reason(DesugaringKind::ForLoop, self.lower_span(e.span), None);
1774-
let head_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
1775-
let pat_span = self.mark_span_with_reason(DesugaringKind::ForLoop, pat.span, None);
1774+
let for_ctxt = for_span.ctxt();
1775+
1776+
// Try to point both the head and pat spans to their position in the for loop
1777+
// rather than inside a macro.
1778+
let head_span =
1779+
head.span.find_ancestor_in_same_ctxt(e.span).unwrap_or(head.span).with_ctxt(for_ctxt);
1780+
let pat_span =
1781+
pat.span.find_ancestor_in_same_ctxt(e.span).unwrap_or(pat.span).with_ctxt(for_ctxt);
17761782

17771783
let loop_hir_id = self.lower_node_id(e.id);
17781784
let label = self.lower_label(opt_label, e.id, loop_hir_id);
@@ -1826,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18261832
arena_vec![self; iter],
18271833
));
18281834
// `unsafe { ... }`
1829-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
18301836
let kind = self.make_lowered_await(head_span, iter, FutureKind::AsyncIterator);
18311837
self.arena.alloc(hir::Expr { hir_id: self.next_id(), kind, span: head_span })
18321838
}
@@ -1881,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18811887
arena_vec![self; iter],
18821888
));
18831889
// `unsafe { ... }`
1884-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
18851891
let inner_match_expr = self.arena.alloc(self.expr_match(
18861892
for_span,
18871893
iter,
@@ -1923,7 +1929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19231929
/// ControlFlow::Break(residual) =>
19241930
/// #[allow(unreachable_code)]
19251931
/// // If there is an enclosing `try {...}`:
1926-
/// break 'catch_target Try::from_residual(residual),
1932+
/// break 'catch_target Residual::into_try_type(residual),
19271933
/// // Otherwise:
19281934
/// return Try::from_residual(residual),
19291935
/// }
@@ -1973,7 +1979,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
19731979
let (residual_local, residual_local_nid) = self.pat_ident(try_span, residual_ident);
19741980
let residual_expr = self.expr_ident_mut(try_span, residual_ident, residual_local_nid);
19751981
let from_residual_expr = self.wrap_in_try_constructor(
1976-
hir::LangItem::TryTraitFromResidual,
1982+
if self.catch_scope.is_some() {
1983+
hir::LangItem::ResidualIntoTryType
1984+
} else {
1985+
hir::LangItem::TryTraitFromResidual
1986+
},
19771987
try_span,
19781988
self.arena.alloc(residual_expr),
19791989
unstable_span,
@@ -2097,30 +2107,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
20972107
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
20982108
}
20992109

2100-
fn expr_uint(&mut self, sp: Span, ty: ast::UintTy, value: u128) -> hir::Expr<'hir> {
2110+
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
21012111
let lit = hir::Lit {
21022112
span: self.lower_span(sp),
2103-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2113+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21042114
};
21052115
self.expr(sp, hir::ExprKind::Lit(lit))
21062116
}
21072117

2108-
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
2109-
self.expr_uint(sp, ast::UintTy::Usize, value as u128)
2110-
}
2111-
2112-
pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
2113-
self.expr_uint(sp, ast::UintTy::U32, value as u128)
2114-
}
2115-
2116-
pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
2117-
self.expr_uint(sp, ast::UintTy::U16, value as u128)
2118-
}
2119-
2120-
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
2118+
pub(super) fn expr_byte_str(&mut self, sp: Span, value: ByteSymbol) -> hir::Expr<'hir> {
21212119
let lit = hir::Lit {
21222120
span: self.lower_span(sp),
2123-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2121+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21242122
};
21252123
self.expr(sp, hir::ExprKind::Lit(lit))
21262124
}
@@ -2256,9 +2254,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22562254
self.expr(span, expr_path)
22572255
}
22582256

2259-
fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
2257+
pub(super) fn expr_unsafe(
2258+
&mut self,
2259+
span: Span,
2260+
expr: &'hir hir::Expr<'hir>,
2261+
) -> hir::Expr<'hir> {
22602262
let hir_id = self.next_id();
2261-
let span = expr.span;
22622263
self.expr(
22632264
span,
22642265
hir::ExprKind::Block(
@@ -2296,15 +2297,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
22962297
self.arena.alloc(self.expr_block(b))
22972298
}
22982299

2299-
pub(super) fn expr_array_ref(
2300-
&mut self,
2301-
span: Span,
2302-
elements: &'hir [hir::Expr<'hir>],
2303-
) -> hir::Expr<'hir> {
2304-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2305-
self.expr_ref(span, array)
2306-
}
2307-
23082300
pub(super) fn expr_ref(&mut self, span: Span, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
23092301
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23102302
}

0 commit comments

Comments
 (0)