Skip to content

Commit 7701a7e

Browse files
committed
Auto merge of #105456 - matthiaskrgr:rollup-yennygf, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #104922 (Detect long types in E0308 and write them to disk) - #105120 (kmc-solid: `std::sys` code maintenance) - #105255 (Make nested RPIT inherit the parent opaque's generics.) - #105317 (make retagging work even with 'unstable' places) - #105405 (Stop passing -export-dynamic to wasm-ld.) - #105408 (Add help for `#![feature(impl_trait_in_fn_trait_return)]`) - #105423 (Use `Symbol` for the crate name instead of `String`/`str`) - #105433 (CI: add missing line continuation marker) - #105434 (Fix warning when libcore is compiled with no_fp_fmt_parse) - #105441 (Remove `UnsafetyState`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b359ccf + 660795e commit 7701a7e

File tree

69 files changed

+825
-575
lines changed

Some content is hidden

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

69 files changed

+825
-575
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4348,6 +4348,7 @@ dependencies = [
43484348
"rustc_span",
43494349
"rustc_target",
43504350
"smallvec",
4351+
"termize",
43514352
"tracing",
43524353
"winapi",
43534354
]

compiler/rustc_ast_lowering/src/lib.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ enum ImplTraitContext {
259259
},
260260
/// Impl trait in type aliases.
261261
TypeAliasesOpaqueTy,
262+
/// `impl Trait` is unstably accepted in this position.
263+
FeatureGated(ImplTraitPosition, Symbol),
262264
/// `impl Trait` is not accepted in this position.
263265
Disallowed(ImplTraitPosition),
264266
}
@@ -1372,25 +1374,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13721374
}
13731375
path
13741376
}
1375-
ImplTraitContext::Disallowed(
1376-
position @ (ImplTraitPosition::TraitReturn | ImplTraitPosition::ImplReturn),
1377-
) => {
1377+
ImplTraitContext::FeatureGated(position, feature) => {
13781378
self.tcx
13791379
.sess
13801380
.create_feature_err(
13811381
MisplacedImplTrait {
13821382
span: t.span,
1383-
position: DiagnosticArgFromDisplay(&position),
1383+
position: DiagnosticArgFromDisplay(position),
13841384
},
1385-
sym::return_position_impl_trait_in_trait,
1385+
*feature,
13861386
)
13871387
.emit();
13881388
hir::TyKind::Err
13891389
}
13901390
ImplTraitContext::Disallowed(position) => {
13911391
self.tcx.sess.emit_err(MisplacedImplTrait {
13921392
span: t.span,
1393-
position: DiagnosticArgFromDisplay(&position),
1393+
position: DiagnosticArgFromDisplay(position),
13941394
});
13951395
hir::TyKind::Err
13961396
}
@@ -1739,14 +1739,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17391739
} else {
17401740
match &decl.output {
17411741
FnRetTy::Ty(ty) => {
1742-
let mut context = if kind.return_impl_trait_allowed(self.tcx) {
1742+
let context = if kind.return_impl_trait_allowed(self.tcx) {
17431743
let fn_def_id = self.local_def_id(fn_node_id);
17441744
ImplTraitContext::ReturnPositionOpaqueTy {
17451745
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
17461746
in_trait: matches!(kind, FnDeclKind::Trait),
17471747
}
17481748
} else {
1749-
ImplTraitContext::Disallowed(match kind {
1749+
let position = match kind {
17501750
FnDeclKind::Fn | FnDeclKind::Inherent => {
17511751
unreachable!("fn should allow in-band lifetimes")
17521752
}
@@ -1755,9 +1755,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17551755
FnDeclKind::Pointer => ImplTraitPosition::PointerReturn,
17561756
FnDeclKind::Trait => ImplTraitPosition::TraitReturn,
17571757
FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
1758-
})
1758+
};
1759+
match kind {
1760+
FnDeclKind::Trait | FnDeclKind::Impl => ImplTraitContext::FeatureGated(
1761+
position,
1762+
sym::return_position_impl_trait_in_trait,
1763+
),
1764+
_ => ImplTraitContext::Disallowed(position),
1765+
}
17591766
};
1760-
hir::FnRetTy::Return(self.lower_ty(ty, &mut context))
1767+
hir::FnRetTy::Return(self.lower_ty(ty, &context))
17611768
}
17621769
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
17631770
}
@@ -1938,7 +1945,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19381945
output,
19391946
span,
19401947
if in_trait && !this.tcx.features().return_position_impl_trait_in_trait {
1941-
ImplTraitContext::Disallowed(ImplTraitPosition::TraitReturn)
1948+
ImplTraitContext::FeatureGated(
1949+
ImplTraitPosition::TraitReturn,
1950+
sym::return_position_impl_trait_in_trait,
1951+
)
19421952
} else {
19431953
ImplTraitContext::ReturnPositionOpaqueTy {
19441954
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),

compiler/rustc_ast_lowering/src/path.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::{self as ast, *};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{DefKind, PartialRes, Res};
1111
use rustc_hir::GenericArg;
12-
use rustc_span::symbol::{kw, Ident};
12+
use rustc_span::symbol::{kw, sym, Ident};
1313
use rustc_span::{BytePos, Span, DUMMY_SP};
1414

1515
use smallvec::{smallvec, SmallVec};
@@ -352,11 +352,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
352352
// fn f(_: impl Fn() -> impl Debug) -> impl Fn() -> impl Debug
353353
// // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
354354
// ```
355-
FnRetTy::Ty(ty)
356-
if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. })
357-
&& self.tcx.features().impl_trait_in_fn_trait_return =>
358-
{
359-
self.lower_ty(&ty, itctx)
355+
FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. }) => {
356+
if self.tcx.features().impl_trait_in_fn_trait_return {
357+
self.lower_ty(&ty, itctx)
358+
} else {
359+
self.lower_ty(
360+
&ty,
361+
&ImplTraitContext::FeatureGated(
362+
ImplTraitPosition::FnTraitReturn,
363+
sym::impl_trait_in_fn_trait_return,
364+
),
365+
)
366+
}
360367
}
361368
FnRetTy::Ty(ty) => {
362369
self.lower_ty(&ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn link_binary<'a>(
102102
sess,
103103
crate_type,
104104
outputs,
105-
codegen_results.crate_info.local_crate_name.as_str(),
105+
codegen_results.crate_info.local_crate_name,
106106
);
107107
match crate_type {
108108
CrateType::Rlib => {

compiler/rustc_const_eval/src/interpret/machine.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,21 @@ pub trait Machine<'mir, 'tcx>: Sized {
373373
Ok(())
374374
}
375375

376-
/// Executes a retagging operation.
376+
/// Executes a retagging operation for a single pointer.
377+
/// Returns the possibly adjusted pointer.
377378
#[inline]
378-
fn retag(
379+
fn retag_ptr_value(
380+
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
381+
_kind: mir::RetagKind,
382+
val: &ImmTy<'tcx, Self::Provenance>,
383+
) -> InterpResult<'tcx, ImmTy<'tcx, Self::Provenance>> {
384+
Ok(val.clone())
385+
}
386+
387+
/// Executes a retagging operation on a compound value.
388+
/// Replaces all pointers stored in the given place.
389+
#[inline]
390+
fn retag_place_contents(
379391
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
380392
_kind: mir::RetagKind,
381393
_place: &PlaceTy<'tcx, Self::Provenance>,

compiler/rustc_const_eval/src/interpret/step.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir;
88
use rustc_middle::mir::interpret::{InterpResult, Scalar};
99
use rustc_middle::ty::layout::LayoutOf;
1010

11-
use super::{InterpCx, Machine};
11+
use super::{ImmTy, InterpCx, Machine};
1212

1313
/// Classify whether an operator is "left-homogeneous", i.e., the LHS has the
1414
/// same type as the result.
@@ -108,7 +108,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
108108
// Stacked Borrows.
109109
Retag(kind, place) => {
110110
let dest = self.eval_place(**place)?;
111-
M::retag(self, *kind, &dest)?;
111+
M::retag_place_contents(self, *kind, &dest)?;
112112
}
113113

114114
Intrinsic(box ref intrinsic) => self.emulate_nondiverging_intrinsic(intrinsic)?,
@@ -247,10 +247,41 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
247247
self.write_scalar(Scalar::from_machine_usize(len, self), &dest)?;
248248
}
249249

250-
AddressOf(_, place) | Ref(_, _, place) => {
250+
Ref(_, borrow_kind, place) => {
251251
let src = self.eval_place(place)?;
252252
let place = self.force_allocation(&src)?;
253-
self.write_immediate(place.to_ref(self), &dest)?;
253+
let val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
254+
// A fresh reference was created, make sure it gets retagged.
255+
let val = M::retag_ptr_value(
256+
self,
257+
if borrow_kind.allows_two_phase_borrow() {
258+
mir::RetagKind::TwoPhase
259+
} else {
260+
mir::RetagKind::Default
261+
},
262+
&val,
263+
)?;
264+
self.write_immediate(*val, &dest)?;
265+
}
266+
267+
AddressOf(_, place) => {
268+
// Figure out whether this is an addr_of of an already raw place.
269+
let place_base_raw = if place.has_deref() {
270+
let ty = self.frame().body.local_decls[place.local].ty;
271+
ty.is_unsafe_ptr()
272+
} else {
273+
// Not a deref, and thus not raw.
274+
false
275+
};
276+
277+
let src = self.eval_place(place)?;
278+
let place = self.force_allocation(&src)?;
279+
let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
280+
if !place_base_raw {
281+
// If this was not already raw, it needs retagging.
282+
val = M::retag_ptr_value(self, mir::RetagKind::Raw, &val)?;
283+
}
284+
self.write_immediate(*val, &dest)?;
254285
}
255286

256287
NullaryOp(null_op, ty) => {

compiler/rustc_driver/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_data_structures::sync::SeqCst;
2525
use rustc_errors::registry::{InvalidErrorCode, Registry};
2626
use rustc_errors::{ErrorGuaranteed, PResult};
2727
use rustc_feature::find_gated_cfg;
28+
use rustc_hir::def_id::LOCAL_CRATE;
2829
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
2930
use rustc_interface::{interface, Queries};
3031
use rustc_lint::LintStore;
@@ -374,14 +375,14 @@ fn run_compiler(
374375
queries.global_ctxt()?.peek_mut().enter(|tcx| {
375376
let result = tcx.analysis(());
376377
if sess.opts.unstable_opts.save_analysis {
377-
let crate_name = queries.crate_name()?.peek().clone();
378+
let crate_name = tcx.crate_name(LOCAL_CRATE);
378379
sess.time("save_analysis", || {
379380
save::process_crate(
380381
tcx,
381-
&crate_name,
382+
crate_name,
382383
compiler.input(),
383384
None,
384-
DumpHandler::new(compiler.output_dir().as_deref(), &crate_name),
385+
DumpHandler::new(compiler.output_dir().as_deref(), crate_name),
385386
)
386387
});
387388
}
@@ -678,7 +679,7 @@ fn print_crate_info(
678679
let crate_types = collect_crate_types(sess, attrs);
679680
for &style in &crate_types {
680681
let fname =
681-
rustc_session::output::filename_for_input(sess, style, &id, &t_outputs);
682+
rustc_session::output::filename_for_input(sess, style, id, &t_outputs);
682683
println!("{}", fname.file_name().unwrap().to_string_lossy());
683684
}
684685
}

compiler/rustc_expand/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ pub trait LintStoreExpand {
960960
node_id: NodeId,
961961
attrs: &[Attribute],
962962
items: &[P<Item>],
963-
name: &str,
963+
name: Symbol,
964964
);
965965
}
966966

compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ impl InvocationCollectorNode for P<ast::Item> {
11221122
ecx.current_expansion.lint_node_id,
11231123
&attrs,
11241124
&items,
1125-
ident.name.as_str(),
1125+
ident.name,
11261126
);
11271127
}
11281128

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ impl<'tcx> AttributeMap<'tcx> {
827827
pub struct OwnerNodes<'tcx> {
828828
/// Pre-computed hash of the full HIR.
829829
pub hash_including_bodies: Fingerprint,
830-
/// Pre-computed hash of the item signature, sithout recursing into the body.
830+
/// Pre-computed hash of the item signature, without recursing into the body.
831831
pub hash_without_bodies: Fingerprint,
832832
/// Full HIR for the current owner.
833833
// The zeroth node's parent should never be accessed: the owner's parent is computed by the

compiler/rustc_hir/src/tests.rs

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::definitions::{DefKey, DefPathData, DisambiguatedDefPathData};
22
use rustc_span::def_id::{DefPathHash, StableCrateId};
3+
use rustc_span::edition::Edition;
4+
use rustc_span::{create_session_if_not_set_then, Symbol};
35

46
#[test]
57
fn def_path_hash_depends_on_crate_id() {
@@ -11,26 +13,28 @@ fn def_path_hash_depends_on_crate_id() {
1113
// the crate by changing the crate disambiguator (e.g. via bumping the
1214
// crate's version number).
1315

14-
let id0 = StableCrateId::new("foo", false, vec!["1".to_string()]);
15-
let id1 = StableCrateId::new("foo", false, vec!["2".to_string()]);
16+
create_session_if_not_set_then(Edition::Edition2024, |_| {
17+
let id0 = StableCrateId::new(Symbol::intern("foo"), false, vec!["1".to_string()]);
18+
let id1 = StableCrateId::new(Symbol::intern("foo"), false, vec!["2".to_string()]);
1619

17-
let h0 = mk_test_hash(id0);
18-
let h1 = mk_test_hash(id1);
20+
let h0 = mk_test_hash(id0);
21+
let h1 = mk_test_hash(id1);
1922

20-
assert_ne!(h0.stable_crate_id(), h1.stable_crate_id());
21-
assert_ne!(h0.local_hash(), h1.local_hash());
23+
assert_ne!(h0.stable_crate_id(), h1.stable_crate_id());
24+
assert_ne!(h0.local_hash(), h1.local_hash());
2225

23-
fn mk_test_hash(stable_crate_id: StableCrateId) -> DefPathHash {
24-
let parent_hash = DefPathHash::new(stable_crate_id, 0);
26+
fn mk_test_hash(stable_crate_id: StableCrateId) -> DefPathHash {
27+
let parent_hash = DefPathHash::new(stable_crate_id, 0);
2528

26-
let key = DefKey {
27-
parent: None,
28-
disambiguated_data: DisambiguatedDefPathData {
29-
data: DefPathData::CrateRoot,
30-
disambiguator: 0,
31-
},
32-
};
29+
let key = DefKey {
30+
parent: None,
31+
disambiguated_data: DisambiguatedDefPathData {
32+
data: DefPathData::CrateRoot,
33+
disambiguator: 0,
34+
},
35+
};
3336

34-
key.compute_stable_hash(parent_hash)
35-
}
37+
key.compute_stable_hash(parent_hash)
38+
}
39+
})
3640
}

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use hir::{
44
GenericParamKind, HirId, Node,
55
};
66
use rustc_hir as hir;
7-
use rustc_hir::def::DefKind;
87
use rustc_hir::def_id::DefId;
98
use rustc_middle::ty::{self, TyCtxt};
109
use rustc_session::lint;
@@ -143,20 +142,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
143142
Some(tcx.typeck_root_def_id(def_id))
144143
}
145144
Node::Item(item) => match item.kind {
146-
ItemKind::OpaqueTy(hir::OpaqueTy {
147-
origin:
148-
hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
149-
in_trait,
150-
..
151-
}) => {
152-
if in_trait {
153-
assert!(matches!(tcx.def_kind(fn_def_id), DefKind::AssocFn))
154-
} else {
155-
assert!(matches!(tcx.def_kind(fn_def_id), DefKind::AssocFn | DefKind::Fn))
156-
}
157-
Some(fn_def_id.to_def_id())
158-
}
159-
ItemKind::OpaqueTy(hir::OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => {
145+
ItemKind::OpaqueTy(hir::OpaqueTy { .. }) => {
160146
let parent_id = tcx.hir().get_parent_item(hir_id);
161147
assert_ne!(parent_id, hir::CRATE_OWNER_ID);
162148
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);

compiler/rustc_hir_typeck/src/check.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::coercion::CoerceMany;
22
use crate::gather_locals::GatherLocalsVisitor;
33
use crate::FnCtxt;
4-
use crate::{GeneratorTypes, UnsafetyState};
4+
use crate::GeneratorTypes;
55
use rustc_hir as hir;
66
use rustc_hir::def::DefKind;
77
use rustc_hir::intravisit::Visitor;
@@ -30,7 +30,6 @@ pub(super) fn check_fn<'a, 'tcx>(
3030
can_be_generator: Option<hir::Movability>,
3131
) -> Option<GeneratorTypes<'tcx>> {
3232
let fn_id = fcx.tcx.hir().local_def_id_to_hir_id(fn_def_id);
33-
fcx.ps.set(UnsafetyState::function(fn_sig.unsafety, fn_id));
3433

3534
let tcx = fcx.tcx;
3635
let hir = tcx.hir();

0 commit comments

Comments
 (0)