Skip to content

Commit deace71

Browse files
committed
Auto merge of rust-lang#119324 - compiler-errors:rollup-c6eqcg9, r=compiler-errors
Rollup of 5 pull requests Successful merges: - rust-lang#119235 (Add missing feature gate for sanitizer CFI cfgs) - rust-lang#119240 (Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s) - rust-lang#119297 (Pass DeadItem and lint as consistent group in dead-code.) - rust-lang#119307 (Clean up some lifetimes in `rustc_pattern_analysis`) - rust-lang#119323 (add test for coercing never to infinite type) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a75fed7 + a5b3d13 commit deace71

33 files changed

+249
-179
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
638638
self.lower_span(span),
639639
Some(self.allow_gen_future.clone()),
640640
);
641-
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
641+
let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span);
642642
let input_ty = hir::Ty {
643643
hir_id: self.next_id(),
644644
kind: hir::TyKind::Path(resume_ty),
@@ -774,7 +774,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
774774
self.lower_span(span),
775775
Some(self.allow_gen_future.clone()),
776776
);
777-
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
777+
let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span);
778778
let input_ty = hir::Ty {
779779
hir_id: self.next_id(),
780780
kind: hir::TyKind::Path(resume_ty),
@@ -2126,11 +2126,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
21262126
lang_item: hir::LangItem,
21272127
name: Symbol,
21282128
) -> hir::Expr<'hir> {
2129+
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span));
21292130
let path = hir::ExprKind::Path(hir::QPath::TypeRelative(
2130-
self.arena.alloc(self.ty(
2131-
span,
2132-
hir::TyKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span))),
2133-
)),
2131+
self.arena.alloc(self.ty(span, hir::TyKind::Path(qpath))),
21342132
self.arena.alloc(hir::PathSegment::new(
21352133
Ident::new(name, span),
21362134
self.next_id(),

compiler/rustc_ast_lowering/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
772772
self.resolver.get_import_res(id).present_items()
773773
}
774774

775+
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {
776+
hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, None))
777+
}
778+
775779
fn make_lang_item_path(
776780
&mut self,
777781
lang_item: hir::LangItem,
@@ -789,7 +793,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
789793
hir_id: self.next_id(),
790794
res,
791795
args,
792-
infer_args: false,
796+
infer_args: args.is_none(),
793797
}]),
794798
})
795799
}

compiler/rustc_feature/src/builtin_attrs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const GATED_CFGS: &[GatedCfg] = &[
3636
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
3737
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
3838
(sym::relocation_model, sym::cfg_relocation_model, cfg_fn!(cfg_relocation_model)),
39+
(sym::sanitizer_cfi_generalize_pointers, sym::cfg_sanitizer_cfi, cfg_fn!(cfg_sanitizer_cfi)),
40+
(sym::sanitizer_cfi_normalize_integers, sym::cfg_sanitizer_cfi, cfg_fn!(cfg_sanitizer_cfi)),
3941
];
4042

4143
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ declare_features! (
371371
(unstable, cfg_relocation_model, "1.73.0", Some(114929)),
372372
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
373373
(unstable, cfg_sanitize, "1.41.0", Some(39699)),
374+
/// Allows `cfg(sanitizer_cfi_generalize_pointers)` and `cfg(sanitizer_cfi_normalize_integers)`.
375+
(unstable, cfg_sanitizer_cfi, "CURRENT_RUSTC_VERSION", Some(89653)),
374376
/// Allows `cfg(target_abi = "...")`.
375377
(unstable, cfg_target_abi, "1.55.0", Some(80970)),
376378
/// Allows `cfg(target(abi = "..."))`.

compiler/rustc_middle/src/thir/visit.rs

+27-12
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ use super::{
33
PatKind, Stmt, StmtKind, Thir,
44
};
55

6-
pub trait Visitor<'a, 'tcx: 'a>: Sized {
7-
fn thir(&self) -> &'a Thir<'tcx>;
6+
pub trait Visitor<'thir, 'tcx: 'thir>: Sized {
7+
fn thir(&self) -> &'thir Thir<'tcx>;
88

9-
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
9+
fn visit_expr(&mut self, expr: &'thir Expr<'tcx>) {
1010
walk_expr(self, expr);
1111
}
1212

13-
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
13+
fn visit_stmt(&mut self, stmt: &'thir Stmt<'tcx>) {
1414
walk_stmt(self, stmt);
1515
}
1616

17-
fn visit_block(&mut self, block: &Block) {
17+
fn visit_block(&mut self, block: &'thir Block) {
1818
walk_block(self, block);
1919
}
2020

21-
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
21+
fn visit_arm(&mut self, arm: &'thir Arm<'tcx>) {
2222
walk_arm(self, arm);
2323
}
2424

25-
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
25+
fn visit_pat(&mut self, pat: &'thir Pat<'tcx>) {
2626
walk_pat(self, pat);
2727
}
2828

@@ -36,7 +36,10 @@ pub trait Visitor<'a, 'tcx: 'a>: Sized {
3636
// other `visit*` functions.
3737
}
3838

39-
pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) {
39+
pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
40+
visitor: &mut V,
41+
expr: &'thir Expr<'tcx>,
42+
) {
4043
use ExprKind::*;
4144
match expr.kind {
4245
Scope { value, region_scope: _, lint_level: _ } => {
@@ -168,7 +171,10 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
168171
}
169172
}
170173

171-
pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stmt<'tcx>) {
174+
pub fn walk_stmt<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
175+
visitor: &mut V,
176+
stmt: &'thir Stmt<'tcx>,
177+
) {
172178
match &stmt.kind {
173179
StmtKind::Expr { expr, scope: _ } => visitor.visit_expr(&visitor.thir()[*expr]),
174180
StmtKind::Let {
@@ -191,7 +197,10 @@ pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stm
191197
}
192198
}
193199

194-
pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &Block) {
200+
pub fn walk_block<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
201+
visitor: &mut V,
202+
block: &'thir Block,
203+
) {
195204
for &stmt in &*block.stmts {
196205
visitor.visit_stmt(&visitor.thir()[stmt]);
197206
}
@@ -200,7 +209,10 @@ pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &B
200209
}
201210
}
202211

203-
pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'tcx>) {
212+
pub fn walk_arm<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
213+
visitor: &mut V,
214+
arm: &'thir Arm<'tcx>,
215+
) {
204216
match arm.guard {
205217
Some(Guard::If(expr)) => visitor.visit_expr(&visitor.thir()[expr]),
206218
Some(Guard::IfLet(ref pat, expr)) => {
@@ -213,7 +225,10 @@ pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'
213225
visitor.visit_expr(&visitor.thir()[arm.body]);
214226
}
215227

216-
pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'tcx>) {
228+
pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
229+
visitor: &mut V,
230+
pat: &'thir Pat<'tcx>,
231+
) {
217232
use PatKind::*;
218233
match &pat.kind {
219234
AscribeUserType { subpattern, ascription: _ }

compiler/rustc_mir_build/src/check_unsafety.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> {
175175
self.thir
176176
}
177177

178-
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
178+
fn visit_expr(&mut self, expr: &'a Expr<'tcx>) {
179179
match expr.kind {
180180
ExprKind::Field { lhs, .. } => {
181181
if let ty::Adt(adt_def, _) = self.thir[lhs].ty.kind() {
@@ -206,7 +206,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
206206
self.thir
207207
}
208208

209-
fn visit_block(&mut self, block: &Block) {
209+
fn visit_block(&mut self, block: &'a Block) {
210210
match block.safety_mode {
211211
// compiler-generated unsafe code should not count towards the usefulness of
212212
// an outer unsafe block
@@ -234,7 +234,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
234234
}
235235
}
236236

237-
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
237+
fn visit_pat(&mut self, pat: &'a Pat<'tcx>) {
238238
if self.in_union_destructure {
239239
match pat.kind {
240240
// binding to a variable allows getting stuff out of variable
@@ -319,7 +319,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
319319
}
320320
}
321321

322-
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
322+
fn visit_expr(&mut self, expr: &'a Expr<'tcx>) {
323323
// could we be in the LHS of an assignment to a field?
324324
match expr.kind {
325325
ExprKind::Field { .. }

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ enum LetSource {
7575
WhileLet,
7676
}
7777

78-
struct MatchVisitor<'thir, 'p, 'tcx> {
78+
struct MatchVisitor<'p, 'tcx> {
7979
tcx: TyCtxt<'tcx>,
8080
param_env: ty::ParamEnv<'tcx>,
8181
typeck_results: &'tcx ty::TypeckResults<'tcx>,
82-
thir: &'thir Thir<'tcx>,
82+
thir: &'p Thir<'tcx>,
8383
lint_level: HirId,
8484
let_source: LetSource,
8585
pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
@@ -92,13 +92,13 @@ struct MatchVisitor<'thir, 'p, 'tcx> {
9292

9393
// Visitor for a thir body. This calls `check_match`, `check_let` and `check_let_chain` as
9494
// appropriate.
95-
impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
96-
fn thir(&self) -> &'thir Thir<'tcx> {
95+
impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
96+
fn thir(&self) -> &'p Thir<'tcx> {
9797
self.thir
9898
}
9999

100100
#[instrument(level = "trace", skip(self))]
101-
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
101+
fn visit_arm(&mut self, arm: &'p Arm<'tcx>) {
102102
self.with_lint_level(arm.lint_level, |this| {
103103
match arm.guard {
104104
Some(Guard::If(expr)) => {
@@ -121,7 +121,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
121121
}
122122

123123
#[instrument(level = "trace", skip(self))]
124-
fn visit_expr(&mut self, ex: &Expr<'tcx>) {
124+
fn visit_expr(&mut self, ex: &'p Expr<'tcx>) {
125125
match ex.kind {
126126
ExprKind::Scope { value, lint_level, .. } => {
127127
self.with_lint_level(lint_level, |this| {
@@ -174,7 +174,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
174174
self.with_let_source(LetSource::None, |this| visit::walk_expr(this, ex));
175175
}
176176

177-
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
177+
fn visit_stmt(&mut self, stmt: &'p Stmt<'tcx>) {
178178
match stmt.kind {
179179
StmtKind::Let {
180180
box ref pattern, initializer, else_block, lint_level, span, ..
@@ -195,7 +195,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
195195
}
196196
}
197197

198-
impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
198+
impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
199199
#[instrument(level = "trace", skip(self, f))]
200200
fn with_let_source(&mut self, let_source: LetSource, f: impl FnOnce(&mut Self)) {
201201
let old_let_source = self.let_source;
@@ -224,7 +224,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
224224
/// subexpressions we are not handling ourselves.
225225
fn visit_land(
226226
&mut self,
227-
ex: &Expr<'tcx>,
227+
ex: &'p Expr<'tcx>,
228228
accumulator: &mut Vec<Option<(Span, RefutableFlag)>>,
229229
) -> Result<(), ErrorGuaranteed> {
230230
match ex.kind {
@@ -251,7 +251,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
251251
/// expression. This must call `visit_expr` on the subexpressions we are not handling ourselves.
252252
fn visit_land_rhs(
253253
&mut self,
254-
ex: &Expr<'tcx>,
254+
ex: &'p Expr<'tcx>,
255255
) -> Result<Option<(Span, RefutableFlag)>, ErrorGuaranteed> {
256256
match ex.kind {
257257
ExprKind::Scope { value, lint_level, .. } => {
@@ -276,7 +276,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
276276
fn lower_pattern(
277277
&mut self,
278278
cx: &MatchCheckCtxt<'p, 'tcx>,
279-
pat: &Pat<'tcx>,
279+
pat: &'p Pat<'tcx>,
280280
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
281281
if let Err(err) = pat.pat_error_reported() {
282282
self.error = Err(err);
@@ -395,7 +395,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
395395
}
396396

397397
#[instrument(level = "trace", skip(self))]
398-
fn check_let(&mut self, pat: &Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
398+
fn check_let(&mut self, pat: &'p Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
399399
assert!(self.let_source != LetSource::None);
400400
let scrut = scrutinee.map(|id| &self.thir[id]);
401401
if let LetSource::PlainLet = self.let_source {
@@ -547,7 +547,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
547547

548548
fn analyze_binding(
549549
&mut self,
550-
pat: &Pat<'tcx>,
550+
pat: &'p Pat<'tcx>,
551551
refutability: RefutableFlag,
552552
scrut: Option<&Expr<'tcx>>,
553553
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
@@ -560,7 +560,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
560560

561561
fn is_let_irrefutable(
562562
&mut self,
563-
pat: &Pat<'tcx>,
563+
pat: &'p Pat<'tcx>,
564564
scrut: Option<&Expr<'tcx>>,
565565
) -> Result<RefutableFlag, ErrorGuaranteed> {
566566
let (cx, report) = self.analyze_binding(pat, Refutable, scrut)?;
@@ -575,7 +575,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
575575
#[instrument(level = "trace", skip(self))]
576576
fn check_binding_is_irrefutable(
577577
&mut self,
578-
pat: &Pat<'tcx>,
578+
pat: &'p Pat<'tcx>,
579579
origin: &str,
580580
scrut: Option<&Expr<'tcx>>,
581581
sp: Option<Span>,
@@ -677,7 +677,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
677677
/// - `x @ Some(ref mut? y)`.
678678
///
679679
/// This analysis is *not* subsumed by NLL.
680-
fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, '_, 'tcx>, pat: &Pat<'tcx>) {
680+
fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat: &Pat<'tcx>) {
681681
// Extract `sub` in `binding @ sub`.
682682
let PatKind::Binding { name, mode, ty, subpattern: Some(box ref sub), .. } = pat.kind else {
683683
return;
@@ -772,7 +772,7 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, '_, 'tcx>,
772772
}
773773

774774
fn check_for_bindings_named_same_as_variants(
775-
cx: &MatchVisitor<'_, '_, '_>,
775+
cx: &MatchVisitor<'_, '_>,
776776
pat: &Pat<'_>,
777777
rf: RefutableFlag,
778778
) {

0 commit comments

Comments
 (0)