Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7f95fa4

Browse files
committed
Merge from rustc
2 parents 6b969d7 + fab6d8a commit 7f95fa4

File tree

378 files changed

+4100
-2892
lines changed

Some content is hidden

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

378 files changed

+4100
-2892
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ name = "anyhow"
186186
version = "1.0.95"
187187
source = "registry+https://github.com/rust-lang/crates.io-index"
188188
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
189+
dependencies = [
190+
"backtrace",
191+
]
189192

190193
[[package]]
191194
name = "ar_archive_writer"
@@ -1195,6 +1198,17 @@ version = "2.3.0"
11951198
source = "registry+https://github.com/rust-lang/crates.io-index"
11961199
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
11971200

1201+
[[package]]
1202+
name = "features-status-dump"
1203+
version = "0.1.0"
1204+
dependencies = [
1205+
"anyhow",
1206+
"clap",
1207+
"serde",
1208+
"serde_json",
1209+
"tidy",
1210+
]
1211+
11981212
[[package]]
11991213
name = "field-offset"
12001214
version = "0.3.6"
@@ -5418,6 +5432,7 @@ dependencies = [
54185432
"regex",
54195433
"rustc-hash 2.1.0",
54205434
"semver",
5435+
"serde",
54215436
"similar",
54225437
"termcolor",
54235438
"walkdir",

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ members = [
4747
"src/tools/coverage-dump",
4848
"src/tools/rustc-perf-wrapper",
4949
"src/tools/wasm-component-ld",
50+
"src/tools/features-status-dump",
5051
]
5152

5253
exclude = [

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
284284
ExprKind::Index(el, er, brackets_span) => {
285285
hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er), *brackets_span)
286286
}
287-
ExprKind::Range(Some(e1), Some(e2), RangeLimits::Closed) => {
288-
self.lower_expr_range_closed(e.span, e1, e2)
289-
}
290287
ExprKind::Range(e1, e2, lims) => {
291288
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), *lims)
292289
}
@@ -1512,15 +1509,39 @@ impl<'hir> LoweringContext<'_, 'hir> {
15121509

15131510
let lang_item = match (e1, e2, lims) {
15141511
(None, None, HalfOpen) => hir::LangItem::RangeFull,
1515-
(Some(..), None, HalfOpen) => hir::LangItem::RangeFrom,
1512+
(Some(..), None, HalfOpen) => {
1513+
if self.tcx.features().new_range() {
1514+
hir::LangItem::RangeFromCopy
1515+
} else {
1516+
hir::LangItem::RangeFrom
1517+
}
1518+
}
15161519
(None, Some(..), HalfOpen) => hir::LangItem::RangeTo,
1517-
(Some(..), Some(..), HalfOpen) => hir::LangItem::Range,
1520+
(Some(..), Some(..), HalfOpen) => {
1521+
if self.tcx.features().new_range() {
1522+
hir::LangItem::RangeCopy
1523+
} else {
1524+
hir::LangItem::Range
1525+
}
1526+
}
15181527
(None, Some(..), Closed) => hir::LangItem::RangeToInclusive,
1519-
(Some(..), Some(..), Closed) => unreachable!(),
1528+
(Some(e1), Some(e2), Closed) => {
1529+
if self.tcx.features().new_range() {
1530+
hir::LangItem::RangeInclusiveCopy
1531+
} else {
1532+
return self.lower_expr_range_closed(span, e1, e2);
1533+
}
1534+
}
15201535
(start, None, Closed) => {
15211536
self.dcx().emit_err(InclusiveRangeWithNoEnd { span });
15221537
match start {
1523-
Some(..) => hir::LangItem::RangeFrom,
1538+
Some(..) => {
1539+
if self.tcx.features().new_range() {
1540+
hir::LangItem::RangeFromCopy
1541+
} else {
1542+
hir::LangItem::RangeFrom
1543+
}
1544+
}
15241545
None => hir::LangItem::RangeFull,
15251546
}
15261547
}

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,12 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
412412
});
413413
}
414414

415-
fn visit_pattern_type_pattern(&mut self, p: &'hir hir::Pat<'hir>) {
416-
self.visit_pat(p)
415+
fn visit_pattern_type_pattern(&mut self, pat: &'hir hir::TyPat<'hir>) {
416+
self.insert(pat.span, pat.hir_id, Node::TyPat(pat));
417+
418+
self.with_parent(pat.hir_id, |this| {
419+
intravisit::walk_ty_pat(this, pat);
420+
});
417421
}
418422

419423
fn visit_precise_capturing_arg(

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13771377
}
13781378
}
13791379
}
1380-
TyKind::Pat(ty, pat) => hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_pat(pat)),
1380+
TyKind::Pat(ty, pat) => {
1381+
hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat))
1382+
}
13811383
TyKind::MacCall(_) => {
13821384
span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")
13831385
}

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use rustc_ast::ptr::P;
44
use rustc_ast::*;
55
use rustc_data_structures::stack::ensure_sufficient_stack;
66
use rustc_hir as hir;
7-
use rustc_hir::def::Res;
7+
use rustc_hir::def::{DefKind, Res};
88
use rustc_middle::span_bug;
99
use rustc_span::source_map::{Spanned, respan};
10-
use rustc_span::{Ident, Span};
10+
use rustc_span::{Ident, Span, kw};
1111

1212
use super::errors::{
1313
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
@@ -429,4 +429,81 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
429429
};
430430
self.arena.alloc(hir::PatExpr { hir_id: self.lower_node_id(expr.id), span, kind })
431431
}
432+
433+
pub(crate) fn lower_ty_pat(&mut self, pattern: &Pat) -> &'hir hir::TyPat<'hir> {
434+
self.arena.alloc(self.lower_ty_pat_mut(pattern))
435+
}
436+
437+
fn lower_ty_pat_mut(&mut self, mut pattern: &Pat) -> hir::TyPat<'hir> {
438+
// loop here to avoid recursion
439+
let pat_hir_id = self.lower_node_id(pattern.id);
440+
let node = loop {
441+
match &pattern.kind {
442+
PatKind::Range(e1, e2, Spanned { node: end, .. }) => {
443+
// FIXME(pattern_types): remove this closure and call `lower_const_arg` instead.
444+
// That requires first modifying the AST to have const args here.
445+
let mut lower_expr = |e: &Expr| -> &_ {
446+
if let ExprKind::Path(None, path) = &e.kind
447+
&& let Some(res) = self
448+
.resolver
449+
.get_partial_res(e.id)
450+
.and_then(|partial_res| partial_res.full_res())
451+
{
452+
self.lower_const_path_to_const_arg(path, res, e.id, e.span)
453+
} else {
454+
let node_id = self.next_node_id();
455+
let def_id = self.create_def(
456+
self.current_hir_id_owner.def_id,
457+
node_id,
458+
kw::Empty,
459+
DefKind::AnonConst,
460+
e.span,
461+
);
462+
let hir_id = self.lower_node_id(node_id);
463+
let ac = self.arena.alloc(hir::AnonConst {
464+
def_id,
465+
hir_id,
466+
body: self.lower_const_body(pattern.span, Some(e)),
467+
span: self.lower_span(pattern.span),
468+
});
469+
self.arena.alloc(hir::ConstArg {
470+
hir_id: self.next_id(),
471+
kind: hir::ConstArgKind::Anon(ac),
472+
})
473+
}
474+
};
475+
break hir::TyPatKind::Range(
476+
e1.as_deref().map(|e| lower_expr(e)),
477+
e2.as_deref().map(|e| lower_expr(e)),
478+
self.lower_range_end(end, e2.is_some()),
479+
);
480+
}
481+
// return inner to be processed in next loop
482+
PatKind::Paren(inner) => pattern = inner,
483+
PatKind::MacCall(_) => panic!("{:?} shouldn't exist here", pattern.span),
484+
PatKind::Err(guar) => break hir::TyPatKind::Err(*guar),
485+
PatKind::Deref(..)
486+
| PatKind::Box(..)
487+
| PatKind::Or(..)
488+
| PatKind::Struct(..)
489+
| PatKind::TupleStruct(..)
490+
| PatKind::Tuple(..)
491+
| PatKind::Ref(..)
492+
| PatKind::Expr(..)
493+
| PatKind::Guard(..)
494+
| PatKind::Slice(_)
495+
| PatKind::Ident(..)
496+
| PatKind::Path(..)
497+
| PatKind::Wild
498+
| PatKind::Never
499+
| PatKind::Rest => {
500+
break hir::TyPatKind::Err(
501+
self.dcx().span_err(pattern.span, "pattern not supported in pattern types"),
502+
);
503+
}
504+
}
505+
};
506+
507+
hir::TyPat { hir_id: pat_hir_id, kind: node, span: self.lower_span(pattern.span) }
508+
}
432509
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,12 +3112,24 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
31123112
drop_span, borrow_span
31133113
);
31143114

3115+
// `TerminatorKind::Return`'s span (the `drop_span` here) `lo` can be subtly wrong and point
3116+
// at a single character after the end of the function. This is somehow relied upon in
3117+
// existing diagnostics, and changing this in `rustc_mir_build` makes diagnostics worse in
3118+
// general. We fix these here.
3119+
let sm = self.infcx.tcx.sess.source_map();
3120+
let end_of_function = if drop_span.is_empty()
3121+
&& let Ok(adjusted_span) = sm.span_extend_prev_while(drop_span, |c| c == '}')
3122+
{
3123+
adjusted_span
3124+
} else {
3125+
drop_span
3126+
};
31153127
self.thread_local_value_does_not_live_long_enough(borrow_span)
31163128
.with_span_label(
31173129
borrow_span,
31183130
"thread-local variables cannot be borrowed beyond the end of the function",
31193131
)
3120-
.with_span_label(drop_span, "end of enclosing function is here")
3132+
.with_span_label(end_of_function, "end of enclosing function is here")
31213133
}
31223134

31233135
#[instrument(level = "debug", skip(self))]

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
465465
unchecked_umul(x, y) => LLVMBuildNUWMul,
466466
}
467467

468+
fn or_disjoint(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value {
469+
unsafe {
470+
let or = llvm::LLVMBuildOr(self.llbuilder, a, b, UNNAMED);
471+
472+
// If a and b are both values, then `or` is a value, rather than
473+
// an instruction, so we need to check before setting the flag.
474+
// (See also `LLVMBuildNUWNeg` which also needs a check.)
475+
if llvm::LLVMIsAInstruction(or).is_some() {
476+
llvm::LLVMSetIsDisjoint(or, True);
477+
}
478+
or
479+
}
480+
}
481+
468482
set_math_builder_methods! {
469483
fadd_fast(x, y) => (LLVMBuildFAdd, LLVMRustSetFastMath),
470484
fsub_fast(x, y) => (LLVMBuildFSub, LLVMRustSetFastMath),

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,9 @@ unsafe extern "C" {
13801380
pub fn LLVMBuildFNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
13811381
pub fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
13821382

1383+
// Extra flags on arithmetic
1384+
pub fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool);
1385+
13831386
// Memory
13841387
pub fn LLVMBuildAlloca<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
13851388
pub fn LLVMBuildArrayAlloca<'a>(

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
225225
args[1].val.unaligned_volatile_store(bx, dst);
226226
return Ok(());
227227
}
228+
sym::disjoint_bitor => {
229+
let a = args[0].immediate();
230+
let b = args[1].immediate();
231+
bx.or_disjoint(a, b)
232+
}
228233
sym::exact_div => {
229234
let ty = arg_tys[0];
230235
match int_type_width_signed(ty, bx.tcx()) {

0 commit comments

Comments
 (0)