Skip to content

Commit e2806a5

Browse files
committed
Auto merge of rust-lang#140180 - ChrisDenton:rollup-5pvs08u, r=ChrisDenton
Rollup of 7 pull requests Successful merges: - rust-lang#140142 (Some more graphviz tweaks) - rust-lang#140146 (Update `compiler_builtins` to 0.1.156) - rust-lang#140147 (Clean: rename `open_braces` to `open_delimiters` in lexer and move `make_unclosed_delims_error` into `diagnostics.rs`.) - rust-lang#140160 (Use `is_lang_item` and `as_lang_item` instead of handrolling their logic) - rust-lang#140163 (Validate extension in `PathBuf::add_extension`) - rust-lang#140173 (Ping Mara when touching format_args!() internals.) - rust-lang#140175 (`rc""` more clear error message) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 645d0ad + ecb9775 commit e2806a5

File tree

41 files changed

+373
-355
lines changed

Some content is hidden

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

41 files changed

+373
-355
lines changed

Diff for: compiler/rustc_ast_lowering/src/path.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir as hir;
55
use rustc_hir::GenericArg;
66
use rustc_hir::def::{DefKind, PartialRes, Res};
77
use rustc_hir::def_id::DefId;
8-
use rustc_middle::span_bug;
8+
use rustc_middle::{span_bug, ty};
99
use rustc_session::parse::add_feature_diagnostics;
1010
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
1111
use smallvec::{SmallVec, smallvec};
@@ -590,14 +590,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
590590
/// lowering of `async Fn()` bounds to desugar to another trait like `LendingFn`.
591591
fn map_trait_to_async_trait(&self, def_id: DefId) -> Option<DefId> {
592592
let lang_items = self.tcx.lang_items();
593-
if Some(def_id) == lang_items.fn_trait() {
594-
lang_items.async_fn_trait()
595-
} else if Some(def_id) == lang_items.fn_mut_trait() {
596-
lang_items.async_fn_mut_trait()
597-
} else if Some(def_id) == lang_items.fn_once_trait() {
598-
lang_items.async_fn_once_trait()
599-
} else {
600-
None
593+
match self.tcx.fn_trait_kind_from_def_id(def_id)? {
594+
ty::ClosureKind::Fn => lang_items.async_fn_trait(),
595+
ty::ClosureKind::FnMut => lang_items.async_fn_mut_trait(),
596+
ty::ClosureKind::FnOnce => lang_items.async_fn_once_trait(),
601597
}
602598
}
603599
}

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12651265
&& let CallKind::FnCall { fn_trait_id, self_ty } = kind
12661266
&& let ty::Param(_) = self_ty.kind()
12671267
&& ty == self_ty
1268-
&& [
1269-
self.infcx.tcx.lang_items().fn_once_trait(),
1270-
self.infcx.tcx.lang_items().fn_mut_trait(),
1271-
self.infcx.tcx.lang_items().fn_trait(),
1272-
]
1273-
.contains(&Some(fn_trait_id))
1268+
&& self.infcx.tcx.fn_trait_kind_from_def_id(fn_trait_id).is_some()
12741269
{
12751270
// Do not suggest `F: FnOnce() + Clone`.
12761271
false

Diff for: compiler/rustc_borrowck/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -702,12 +702,12 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
702702
// 2. loans made in overlapping scopes do not conflict
703703
// 3. assignments do not affect things loaned out as immutable
704704
// 4. moves do not affect things loaned out in any way
705-
impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
705+
impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
706706
fn visit_after_early_statement_effect(
707707
&mut self,
708708
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
709709
state: &BorrowckDomain,
710-
stmt: &'a Statement<'tcx>,
710+
stmt: &Statement<'tcx>,
711711
location: Location,
712712
) {
713713
debug!("MirBorrowckCtxt::process_statement({:?}, {:?}): {:?}", location, stmt, state);
@@ -783,7 +783,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
783783
&mut self,
784784
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
785785
state: &BorrowckDomain,
786-
term: &'a Terminator<'tcx>,
786+
term: &Terminator<'tcx>,
787787
loc: Location,
788788
) {
789789
debug!("MirBorrowckCtxt::process_terminator({:?}, {:?}): {:?}", loc, term, state);
@@ -896,7 +896,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
896896
&mut self,
897897
_results: &mut Results<'tcx, Borrowck<'a, 'tcx>>,
898898
state: &BorrowckDomain,
899-
term: &'a Terminator<'tcx>,
899+
term: &Terminator<'tcx>,
900900
loc: Location,
901901
) {
902902
let span = term.source_info.span;
@@ -1363,7 +1363,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
13631363
fn consume_rvalue(
13641364
&mut self,
13651365
location: Location,
1366-
(rvalue, span): (&'a Rvalue<'tcx>, Span),
1366+
(rvalue, span): (&Rvalue<'tcx>, Span),
13671367
state: &BorrowckDomain,
13681368
) {
13691369
match rvalue {
@@ -1636,7 +1636,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
16361636
fn consume_operand(
16371637
&mut self,
16381638
location: Location,
1639-
(operand, span): (&'a Operand<'tcx>, Span),
1639+
(operand, span): (&Operand<'tcx>, Span),
16401640
state: &BorrowckDomain,
16411641
) {
16421642
match *operand {

Diff for: compiler/rustc_hir_analysis/src/check/intrinsic.rs

+26-34
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
use rustc_abi::ExternAbi;
44
use rustc_errors::DiagMessage;
5-
use rustc_hir::{self as hir};
6-
use rustc_middle::bug;
5+
use rustc_hir::{self as hir, LangItem};
76
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
87
use rustc_middle::ty::{self, Ty, TyCtxt};
98
use rustc_span::def_id::LocalDefId;
@@ -173,23 +172,22 @@ pub(crate) fn check_intrinsic_type(
173172
ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv),
174173
]);
175174
let mk_va_list_ty = |mutbl| {
176-
tcx.lang_items().va_list().map(|did| {
177-
let region = ty::Region::new_bound(
178-
tcx,
179-
ty::INNERMOST,
180-
ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon },
181-
);
182-
let env_region = ty::Region::new_bound(
183-
tcx,
184-
ty::INNERMOST,
185-
ty::BoundRegion {
186-
var: ty::BoundVar::from_u32(2),
187-
kind: ty::BoundRegionKind::ClosureEnv,
188-
},
189-
);
190-
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
191-
(Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty)
192-
})
175+
let did = tcx.require_lang_item(LangItem::VaList, Some(span));
176+
let region = ty::Region::new_bound(
177+
tcx,
178+
ty::INNERMOST,
179+
ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon },
180+
);
181+
let env_region = ty::Region::new_bound(
182+
tcx,
183+
ty::INNERMOST,
184+
ty::BoundRegion {
185+
var: ty::BoundVar::from_u32(2),
186+
kind: ty::BoundRegionKind::ClosureEnv,
187+
},
188+
);
189+
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
190+
(Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty)
193191
};
194192

195193
let (n_tps, n_lts, n_cts, inputs, output, safety) = if name_str.starts_with("atomic_") {
@@ -548,23 +546,17 @@ pub(crate) fn check_intrinsic_type(
548546
)
549547
}
550548

551-
sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) {
552-
Some((va_list_ref_ty, _)) => (0, 0, vec![va_list_ref_ty], tcx.types.unit),
553-
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
554-
},
549+
sym::va_start | sym::va_end => {
550+
(0, 0, vec![mk_va_list_ty(hir::Mutability::Mut).0], tcx.types.unit)
551+
}
555552

556-
sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) {
557-
Some((va_list_ref_ty, va_list_ty)) => {
558-
let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
559-
(0, 0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.types.unit)
560-
}
561-
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
562-
},
553+
sym::va_copy => {
554+
let (va_list_ref_ty, va_list_ty) = mk_va_list_ty(hir::Mutability::Not);
555+
let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
556+
(0, 0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.types.unit)
557+
}
563558

564-
sym::va_arg => match mk_va_list_ty(hir::Mutability::Mut) {
565-
Some((va_list_ref_ty, _)) => (1, 0, vec![va_list_ref_ty], param(0)),
566-
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
567-
},
559+
sym::va_arg => (1, 0, vec![mk_va_list_ty(hir::Mutability::Mut).0], param(0)),
568560

569561
sym::nontemporal_store => {
570562
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], tcx.types.unit)

Diff for: compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err
750750
ObligationCause::misc(impl_span, checker.impl_def_id),
751751
param_env,
752752
nontrivial_field_ty,
753-
tcx.lang_items().pointer_like().unwrap(),
753+
tcx.require_lang_item(LangItem::PointerLike, Some(impl_span)),
754754
);
755755
// FIXME(dyn-star): We should regionck this implementation.
756756
if ocx.select_all_or_error().is_empty() {

Diff for: compiler/rustc_hir_typeck/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) fn check_legal_trait_for_method_call(
3737
body_id: DefId,
3838
) -> Result<(), ErrorGuaranteed> {
3939
if tcx.is_lang_item(trait_id, LangItem::Drop)
40-
&& tcx.lang_items().fallback_surface_drop_fn() != Some(body_id)
40+
&& !tcx.is_lang_item(body_id, LangItem::FallbackSurfaceDrop)
4141
{
4242
let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
4343
errors::ExplicitDestructorCallSugg::Snippet {

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
925925

926926
let detect_dotdot = |err: &mut Diag<'_>, ty: Ty<'_>, expr: &hir::Expr<'_>| {
927927
if let ty::Adt(adt, _) = ty.kind()
928-
&& self.tcx().lang_items().get(hir::LangItem::RangeFull) == Some(adt.did())
928+
&& self.tcx().is_lang_item(adt.did(), hir::LangItem::RangeFull)
929929
&& let hir::ExprKind::Struct(
930930
hir::QPath::LangItem(hir::LangItem::RangeFull, _),
931931
[],

Diff for: compiler/rustc_hir_typeck/src/pat.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -1457,15 +1457,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14571457
_ => (None, None),
14581458
};
14591459

1460-
let ranges = &[
1461-
self.tcx.lang_items().range_struct(),
1462-
self.tcx.lang_items().range_from_struct(),
1463-
self.tcx.lang_items().range_to_struct(),
1464-
self.tcx.lang_items().range_full_struct(),
1465-
self.tcx.lang_items().range_inclusive_struct(),
1466-
self.tcx.lang_items().range_to_inclusive_struct(),
1467-
];
1468-
if type_def_id != None && ranges.contains(&type_def_id) {
1460+
let is_range = match type_def_id.and_then(|id| self.tcx.as_lang_item(id)) {
1461+
Some(
1462+
LangItem::Range
1463+
| LangItem::RangeFrom
1464+
| LangItem::RangeTo
1465+
| LangItem::RangeFull
1466+
| LangItem::RangeInclusiveStruct
1467+
| LangItem::RangeToInclusive,
1468+
) => true,
1469+
_ => false,
1470+
};
1471+
if is_range {
14691472
if !self.maybe_suggest_range_literal(&mut e, item_def_id, *ident) {
14701473
let msg = "constants only support matching by type, \
14711474
if you meant to match against a range of values, \

Diff for: compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use std::cell::RefCell;
22
use std::ops::Deref;
33

44
use rustc_data_structures::unord::{UnordMap, UnordSet};
5-
use rustc_hir as hir;
65
use rustc_hir::def_id::LocalDefId;
7-
use rustc_hir::{HirId, HirIdMap};
6+
use rustc_hir::{self as hir, HirId, HirIdMap, LangItem};
87
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
98
use rustc_middle::span_bug;
109
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypingMode};
@@ -137,7 +136,7 @@ impl<'tcx> TypeckRootCtxt<'tcx> {
137136
obligation.predicate.kind().skip_binder()
138137
&& let Some(ty) =
139138
self.shallow_resolve(tpred.self_ty()).ty_vid().map(|t| self.root_var(t))
140-
&& self.tcx.lang_items().sized_trait().is_some_and(|st| st != tpred.trait_ref.def_id)
139+
&& !self.tcx.is_lang_item(tpred.trait_ref.def_id, LangItem::Sized)
141140
{
142141
let new_self_ty = self.tcx.types.unit;
143142

Diff for: compiler/rustc_lint/src/shadowed_into_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_hir as hir;
1+
use rustc_hir::{self as hir, LangItem};
22
use rustc_middle::ty::{self, Ty};
33
use rustc_session::lint::FutureIncompatibilityReason;
44
use rustc_session::{declare_lint, impl_lint_pass};
@@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ShadowedIntoIter {
8181
let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) else {
8282
return;
8383
};
84-
if Some(method_def_id) != cx.tcx.lang_items().into_iter_fn() {
84+
if !cx.tcx.is_lang_item(method_def_id, LangItem::IntoIterIntoIter) {
8585
return;
8686
}
8787

Diff for: compiler/rustc_middle/src/middle/lang_items.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ impl<'tcx> TyCtxt<'tcx> {
3535
/// returns a corresponding [`ty::ClosureKind`].
3636
/// For any other [`DefId`] return `None`.
3737
pub fn fn_trait_kind_from_def_id(self, id: DefId) -> Option<ty::ClosureKind> {
38-
let items = self.lang_items();
39-
match Some(id) {
40-
x if x == items.fn_trait() => Some(ty::ClosureKind::Fn),
41-
x if x == items.fn_mut_trait() => Some(ty::ClosureKind::FnMut),
42-
x if x == items.fn_once_trait() => Some(ty::ClosureKind::FnOnce),
38+
match self.as_lang_item(id)? {
39+
LangItem::Fn => Some(ty::ClosureKind::Fn),
40+
LangItem::FnMut => Some(ty::ClosureKind::FnMut),
41+
LangItem::FnOnce => Some(ty::ClosureKind::FnOnce),
4342
_ => None,
4443
}
4544
}
@@ -48,11 +47,10 @@ impl<'tcx> TyCtxt<'tcx> {
4847
/// returns a corresponding [`ty::ClosureKind`].
4948
/// For any other [`DefId`] return `None`.
5049
pub fn async_fn_trait_kind_from_def_id(self, id: DefId) -> Option<ty::ClosureKind> {
51-
let items = self.lang_items();
52-
match Some(id) {
53-
x if x == items.async_fn_trait() => Some(ty::ClosureKind::Fn),
54-
x if x == items.async_fn_mut_trait() => Some(ty::ClosureKind::FnMut),
55-
x if x == items.async_fn_once_trait() => Some(ty::ClosureKind::FnOnce),
50+
match self.as_lang_item(id)? {
51+
LangItem::AsyncFn => Some(ty::ClosureKind::Fn),
52+
LangItem::AsyncFnMut => Some(ty::ClosureKind::FnMut),
53+
LangItem::AsyncFnOnce => Some(ty::ClosureKind::FnOnce),
5654
_ => None,
5755
}
5856
}

Diff for: compiler/rustc_middle/src/ty/sty.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1774,9 +1774,7 @@ impl<'tcx> Ty<'tcx> {
17741774
match pointee_ty.ptr_metadata_ty_or_tail(tcx, |x| x) {
17751775
Ok(metadata_ty) => metadata_ty,
17761776
Err(tail_ty) => {
1777-
let Some(metadata_def_id) = tcx.lang_items().metadata_type() else {
1778-
bug!("No metadata_type lang item while looking at {self:?}")
1779-
};
1777+
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
17801778
Ty::new_projection(tcx, metadata_def_id, [tail_ty])
17811779
}
17821780
}

Diff for: compiler/rustc_mir_dataflow/src/framework/cursor.rs

-15
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,11 @@ where
114114
self.reachable_blocks.insert_all()
115115
}
116116

117-
/// Returns the underlying `Results`.
118-
pub fn results(&self) -> &Results<'tcx, A> {
119-
&self.results
120-
}
121-
122-
/// Returns the underlying `Results`.
123-
pub fn mut_results(&mut self) -> &mut Results<'tcx, A> {
124-
&mut self.results
125-
}
126-
127117
/// Returns the `Analysis` used to generate the underlying `Results`.
128118
pub fn analysis(&self) -> &A {
129119
&self.results.analysis
130120
}
131121

132-
/// Returns the `Analysis` used to generate the underlying `Results`.
133-
pub fn mut_analysis(&mut self) -> &mut A {
134-
&mut self.results.analysis
135-
}
136-
137122
/// Resets the cursor to hold the entry set for the given basic block.
138123
///
139124
/// For forward dataflow analyses, this is the dataflow state prior to the first statement.

Diff for: compiler/rustc_mir_dataflow/src/framework/direction.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub trait Direction {
4343
block: BasicBlock,
4444
block_data: &'mir mir::BasicBlockData<'tcx>,
4545
results: &mut Results<'tcx, A>,
46-
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
46+
vis: &mut impl ResultsVisitor<'tcx, A>,
4747
) where
4848
A: Analysis<'tcx>;
4949
}
@@ -212,7 +212,7 @@ impl Direction for Backward {
212212
block: BasicBlock,
213213
block_data: &'mir mir::BasicBlockData<'tcx>,
214214
results: &mut Results<'tcx, A>,
215-
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
215+
vis: &mut impl ResultsVisitor<'tcx, A>,
216216
) where
217217
A: Analysis<'tcx>,
218218
{
@@ -394,7 +394,7 @@ impl Direction for Forward {
394394
block: BasicBlock,
395395
block_data: &'mir mir::BasicBlockData<'tcx>,
396396
results: &mut Results<'tcx, A>,
397-
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
397+
vis: &mut impl ResultsVisitor<'tcx, A>,
398398
) where
399399
A: Analysis<'tcx>,
400400
{

0 commit comments

Comments
 (0)