Skip to content

Commit db8f076

Browse files
committed
Auto merge of #163695 - JonathanBrouwer:rollup-qSYnNoO, r=JonathanBrouwer
Rollup of 8 pull requests Successful merges: - #163645 (add `ignore-compare-mode-next-solver` to all next-solver tests) - #163663 (reflection: fix ICE when TypeId::info called on ADT) - #163454 (Improve suggestion for lifetime preceding type in generics) - #163561 (tests: accept noundef in a couple more places) - #163633 (core: io: clean `unused_variables` lint under `no_io_statics`) - #163681 (Make the tracking issue template better suited for experiments) - #163685 (Avoid long iterator chain in all_rust_features) - #163690 (refactor: migrate to LLVM-C's `LLVMGetOrInsertFunction`) Failed merges: - #161491 (Rip out old solver coherence)
2 parents d6b6dc7 + 7e68f55 commit db8f076

271 files changed

Lines changed: 770 additions & 637 deletions

File tree

Some content is hidden

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

‎.github/ISSUE_TEMPLATE/tracking_issue.md‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
---
22
name: Tracking Issue
3-
about: A tracking issue for an accepted feature or RFC in Rust.
3+
about: A tracking issue for an unstable feature in Rust.
44
title: Tracking Issue for XXX
55
labels: C-tracking-issue
66
---
77
<!--
88
NOTE: For library features, please use the "Library Tracking Issue" template instead.
99
1010
Thank you for creating a tracking issue! 📜 Tracking issues are for tracking a
11-
feature from implementation to stabilisation. Make sure to include the relevant
12-
RFC for the feature if it has one. Otherwise provide a short summary of the
13-
feature and link any relevant PRs or issues, and remove any sections that are
14-
not relevant to the feature.
11+
feature from implementation to stabilisation.
1512
1613
Remember to add team labels to the tracking issue.
17-
For a language team feature, this would e.g., be `T-lang`.
14+
For a language team feature, this would e.g., be `T-lang`:
15+
16+
> @rustbot label T-lang
17+
1818
Such a feature should also be labeled with e.g., `F-my_feature`.
1919
This label is used to associate issues (e.g., bugs and design questions) to the feature.
2020
-->
2121

22-
This is a tracking issue for the RFC "XXX" (rust-lang/rfcs#NNN).
23-
The feature gate for the issue is `#![feature(FFF)]`.
22+
This is a tracking issue for `#![feature(FFF)]`.
23+
The RFC for this feature is rust-lang/rfcs#NNN.
24+
25+
<!--
26+
Make sure to include the relevant RFC for the feature if it has one.
27+
28+
Otherwise, provide a short summary and motivation of the
29+
feature and link any relevant PRs or issues.
30+
Remove any sections that are not relevant to the feature.
31+
-->
2432

2533
### About tracking issues
2634

@@ -38,8 +46,8 @@ implementing a feature, followed by a PR that stabilises the feature. However
3846
for larger features an implementation could be broken up into multiple PRs.
3947
-->
4048

41-
- [ ] Implement the RFC (cc @rust-lang/XXX -- can anyone write up mentoring
42-
instructions?)
49+
- [ ] Create the feature gate
50+
- [ ] Implement the feature
4351
- [ ] Adjust documentation ([see instructions on rustc-dev-guide][doc-guide])
4452
- [ ] Style updates for any new syntax ([nightly-style-procedure])
4553
- [ ] Style team decision on new formatting
@@ -59,8 +67,8 @@ stabilised. It is useful to link related discussions and conculsions as they
5967
develop.
6068
-->
6169

62-
- [ ] list all the "unresolved questions" found in the RFC to ensure they are
63-
not forgotten.
70+
- [ ] List any unresolved questions, including those listed in the RFC if there is one,
71+
to ensure they are not forgotten.
6472

6573
### Implementation history
6674

‎compiler/rustc_codegen_llvm/src/declare.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ pub(crate) fn declare_simple_fn<'ll>(
4343
ty: &'ll Type,
4444
) -> &'ll Value {
4545
debug!("declare_simple_fn(name={:?}, ty={:?})", name, ty);
46-
let llfn = unsafe {
47-
llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_c_char_ptr(), name.len(), ty)
48-
};
46+
let llfn =
47+
unsafe { llvm::LLVMGetOrInsertFunction(cx.llmod, name.as_c_char_ptr(), name.len(), ty) };
4948

5049
llvm::SetFunctionCallConv(llfn, callconv);
5150
llvm::set_unnamed_address(llfn, unnamed);

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,12 @@ unsafe extern "C" {
11251125
FunctionTy: &'a Type,
11261126
) -> &'a Value;
11271127
pub(crate) fn LLVMDeleteFunction(Fn: &Value);
1128+
pub(crate) fn LLVMGetOrInsertFunction<'a>(
1129+
M: &'a Module,
1130+
Name: *const c_char,
1131+
NameLen: size_t,
1132+
FunctionTy: &'a Type,
1133+
) -> &'a Value;
11281134

11291135
// Operations about llvm intrinsics
11301136
pub(crate) fn LLVMLookupIntrinsicID(Name: *const c_char, NameLen: size_t) -> c_uint;
@@ -2033,13 +2039,6 @@ unsafe extern "C" {
20332039
) -> &Attribute;
20342040

20352041
// Operations on functions
2036-
/// FIXME: After dropping LLVM 21, migrate to LLVM-C's `LLVMGetOrInsertFunction`.
2037-
pub(crate) fn LLVMRustGetOrInsertFunction<'a>(
2038-
M: &'a Module,
2039-
Name: *const c_char,
2040-
NameLen: size_t,
2041-
FunctionTy: &'a Type,
2042-
) -> &'a Value;
20432042
pub(crate) fn LLVMRustAddFunctionAttributes<'a>(
20442043
Fn: &'a Value,
20452044
index: c_uint,

‎compiler/rustc_const_eval/src/const_eval/type_info.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
9191
self.project_downcast_named(&field_dest, sym::Slice)?;
9292
variant
9393
}
94-
ty::Adt(adt_def, generics) => {
95-
self.write_adt_type_info(&field_dest, (ty, *adt_def), generics)?
96-
}
94+
ty::Adt(adt_def, _) => self.write_adt_type_info(&field_dest, *adt_def)?,
9795
ty::Bool => {
9896
let (variant, _variant_place) =
9997
self.project_downcast_named(&field_dest, sym::Bool)?;

‎compiler/rustc_const_eval/src/const_eval/type_info/adt.rs‎

Lines changed: 6 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,204 +1,38 @@
11
use rustc_abi::{FieldIdx, VariantIdx};
2-
use rustc_middle::ty::layout::TyAndLayout;
32
use rustc_middle::ty::{
4-
AdtDef, AdtKind, Const, ConstKind, GenericArgKind, GenericArgs, Region, Ty, VariantDef,
3+
AdtDef, AdtKind, Const, ConstKind, GenericArgKind, GenericArgs, Region, Ty,
54
};
65
use rustc_span::{bug, span_bug, sym};
76

87
use crate::const_eval::CompileTimeMachine;
98
use crate::interpret::{
10-
CtfeProvenance, InterpCx, InterpResult, MPlaceTy, Projectable, Scalar, Writeable, interp_ok,
9+
CtfeProvenance, InterpCx, InterpResult, MPlaceTy, Projectable, Writeable, interp_ok,
1110
};
1211

1312
impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
1413
// FIXME(type_info): No semver considerations for now
1514
pub(crate) fn write_adt_type_info(
1615
&mut self,
1716
place: &impl Writeable<'tcx, CtfeProvenance>,
18-
adt: (Ty<'tcx>, AdtDef<'tcx>),
19-
generics: &'tcx GenericArgs<'tcx>,
17+
adt_def: AdtDef<'tcx>,
2018
) -> InterpResult<'tcx, VariantIdx> {
21-
let (adt_ty, adt_def) = adt;
2219
let variant_idx = match adt_def.adt_kind() {
2320
AdtKind::Struct => {
24-
let (variant, variant_place) = self.project_downcast_named(place, sym::Struct)?;
25-
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
26-
self.write_struct_type_info(
27-
place,
28-
(adt_ty, adt_def.variant(VariantIdx::ZERO)),
29-
generics,
30-
)?;
21+
let (variant, _) = self.project_downcast_named(place, sym::Struct)?;
3122
variant
3223
}
3324
AdtKind::Union => {
34-
let (variant, variant_place) = self.project_downcast_named(place, sym::Union)?;
35-
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
36-
self.write_union_type_info(
37-
place,
38-
(adt_ty, adt_def.variant(VariantIdx::ZERO)),
39-
generics,
40-
)?;
25+
let (variant, _) = self.project_downcast_named(place, sym::Union)?;
4126
variant
4227
}
4328
AdtKind::Enum => {
44-
let (variant, variant_place) = self.project_downcast_named(place, sym::Enum)?;
45-
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
46-
self.write_enum_type_info(place, adt, generics)?;
29+
let (variant, _) = self.project_downcast_named(place, sym::Enum)?;
4730
variant
4831
}
4932
};
5033
interp_ok(variant_idx)
5134
}
5235

53-
pub(crate) fn write_struct_type_info(
54-
&mut self,
55-
place: impl Writeable<'tcx, CtfeProvenance>,
56-
struct_: (Ty<'tcx>, &'tcx VariantDef),
57-
generics: &'tcx GenericArgs<'tcx>,
58-
) -> InterpResult<'tcx> {
59-
let (struct_ty, struct_def) = struct_;
60-
let struct_layout = self.layout_of(struct_ty)?;
61-
62-
for (field_idx, field) in
63-
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
64-
{
65-
let field_place = self.project_field(&place, field_idx)?;
66-
67-
match field.name {
68-
sym::generics => self.write_generics(&field_place, generics)?,
69-
sym::fields => {
70-
self.write_variant_fields(field_place, struct_def, struct_layout, generics)?
71-
}
72-
sym::non_exhaustive => {
73-
let is_non_exhaustive = struct_def.is_field_list_non_exhaustive();
74-
self.write_scalar(Scalar::from_bool(is_non_exhaustive), &field_place)?
75-
}
76-
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
77-
}
78-
}
79-
80-
interp_ok(())
81-
}
82-
83-
pub(crate) fn write_union_type_info(
84-
&mut self,
85-
place: impl Writeable<'tcx, CtfeProvenance>,
86-
union_: (Ty<'tcx>, &'tcx VariantDef),
87-
generics: &'tcx GenericArgs<'tcx>,
88-
) -> InterpResult<'tcx> {
89-
let (union_ty, union_def) = union_;
90-
let union_layout = self.layout_of(union_ty)?;
91-
92-
for (field_idx, field) in
93-
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
94-
{
95-
let field_place = self.project_field(&place, field_idx)?;
96-
97-
match field.name {
98-
sym::generics => self.write_generics(&field_place, generics)?,
99-
sym::fields => {
100-
self.write_variant_fields(field_place, union_def, union_layout, generics)?
101-
}
102-
sym::non_exhaustive => {
103-
let is_non_exhaustive = union_def.is_field_list_non_exhaustive();
104-
self.write_scalar(Scalar::from_bool(is_non_exhaustive), &field_place)?
105-
}
106-
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
107-
}
108-
}
109-
110-
interp_ok(())
111-
}
112-
113-
pub(crate) fn write_enum_type_info(
114-
&mut self,
115-
place: impl Writeable<'tcx, CtfeProvenance>,
116-
enum_: (Ty<'tcx>, AdtDef<'tcx>),
117-
generics: &'tcx GenericArgs<'tcx>,
118-
) -> InterpResult<'tcx> {
119-
let (enum_ty, enum_def) = enum_;
120-
let enum_layout = self.layout_of(enum_ty)?;
121-
122-
for (field_idx, field) in
123-
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
124-
{
125-
let field_place = self.project_field(&place, field_idx)?;
126-
127-
match field.name {
128-
sym::generics => self.write_generics(&field_place, generics)?,
129-
sym::type_id_variants => {
130-
self.allocate_fill_and_write_slice_ptr(
131-
&field_place,
132-
enum_def.variants().len() as u64,
133-
|this, i, place| {
134-
let variant_idx = VariantIdx::from_usize(i as usize);
135-
let variant_def = &enum_def.variants()[variant_idx];
136-
let variant_layout = enum_layout.for_variant(this, variant_idx);
137-
this.write_enum_variant(place, (variant_layout, &variant_def), generics)
138-
},
139-
)?;
140-
}
141-
sym::non_exhaustive => {
142-
let is_non_exhaustive = enum_def.is_variant_list_non_exhaustive();
143-
self.write_scalar(Scalar::from_bool(is_non_exhaustive), &field_place)?
144-
}
145-
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
146-
}
147-
}
148-
149-
interp_ok(())
150-
}
151-
152-
fn write_enum_variant(
153-
&mut self,
154-
place: impl Writeable<'tcx, CtfeProvenance>,
155-
variant: (TyAndLayout<'tcx>, &'tcx VariantDef),
156-
generics: &'tcx GenericArgs<'tcx>,
157-
) -> InterpResult<'tcx> {
158-
let (variant_layout, variant_def) = variant;
159-
160-
for (field_idx, field_def) in
161-
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
162-
{
163-
let field_place = self.project_field(&place, field_idx)?;
164-
match field_def.name {
165-
sym::name => {
166-
let name_place = self.allocate_str_dedup(variant_def.name.as_str())?;
167-
let ptr = self.mplace_to_imm_ptr(&name_place, None)?;
168-
self.write_immediate(*ptr, &field_place)?
169-
}
170-
sym::fields => {
171-
self.write_variant_fields(field_place, &variant_def, variant_layout, generics)?
172-
}
173-
sym::non_exhaustive => {
174-
let is_non_exhaustive = variant_def.is_field_list_non_exhaustive();
175-
self.write_scalar(Scalar::from_bool(is_non_exhaustive), &field_place)?
176-
}
177-
other => span_bug!(self.tcx.def_span(field_def.did), "unimplemented field {other}"),
178-
}
179-
}
180-
interp_ok(())
181-
}
182-
183-
// Write fields for struct, enum variants
184-
fn write_variant_fields(
185-
&mut self,
186-
place: impl Writeable<'tcx, CtfeProvenance>,
187-
variant_def: &'tcx VariantDef,
188-
variant_layout: TyAndLayout<'tcx>,
189-
generics: &'tcx GenericArgs<'tcx>,
190-
) -> InterpResult<'tcx> {
191-
self.allocate_fill_and_write_slice_ptr(
192-
&place,
193-
variant_def.fields.len() as u64,
194-
|this, i, place| {
195-
let field_def = &variant_def.fields[FieldIdx::from_usize(i as usize)];
196-
let field_ty = field_def.ty(*this.tcx, generics).skip_norm_wip();
197-
this.write_field(field_ty, place, variant_layout, Some(field_def.name), i)
198-
},
199-
)
200-
}
201-
20236
pub(super) fn write_generics(
20337
&mut self,
20438
place: &impl Writeable<'tcx, CtfeProvenance>,

‎compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,6 @@ LLVMRustVerifyFunction(LLVMValueRef Fn, LLVMRustVerifierFailureAction Action) {
195195
return LLVMVerifyFunction(Fn, fromRust(Action));
196196
}
197197

198-
extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
199-
const char *Name,
200-
size_t NameLen,
201-
LLVMTypeRef FunctionTy) {
202-
return wrap(unwrap(M)
203-
->getOrInsertFunction(StringRef(Name, NameLen),
204-
unwrap<FunctionType>(FunctionTy))
205-
.getCallee());
206-
}
207-
208198
// Get the global variable with the given name if it exists or create a new
209199
// external global.
210200
extern "C" LLVMValueRef

‎compiler/rustc_parse/src/parser/diagnostics.rs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,44 @@ impl<'a> Parser<'a> {
22872287
}
22882288
}
22892289

2290+
/// Handle encountering a lifetime in a generic argument list that is not
2291+
/// followed by a `,` or `>`.
2292+
/// We emit an error and check if the lifetime is followed by a type
2293+
/// in, e.g. `Foo<'a T>`.
2294+
/// In this case, it is likely the user meant either `Foo<&'a T>` or `Foo<'a, T>`.
2295+
/// We give both suggestions, then emit an error. Note that we do not try to recover,
2296+
/// since we cannot know which of the two suggestions is correct and emitting either
2297+
/// of the two types could cause confusing errors further on.
2298+
pub(super) fn handle_lifetime_arg_preceding_type(&mut self, span: Span) -> PResult<'a, ()> {
2299+
let snapshot = self.create_snapshot_for_diagnostic();
2300+
let (mutbl, ty) = self.parse_ref_ty_no_leading_ampersand();
2301+
self.restore_snapshot(snapshot);
2302+
if ty.is_none() {
2303+
// The lifetime is not followed by a type, do nothing.
2304+
return Ok(());
2305+
}
2306+
// If we find `'a mut T`, suggesting to add a comma is wrong.
2307+
let suggest_comma = mutbl.is_not();
2308+
// Add `>` to the list of expected tokens.
2309+
self.check(exp!(Gt));
2310+
let mut err = self.unexpected().unwrap_err();
2311+
err.span_suggestion_verbose(
2312+
span.shrink_to_lo(),
2313+
"you might have meant to write a reference type here",
2314+
"&",
2315+
Applicability::MaybeIncorrect,
2316+
);
2317+
if suggest_comma {
2318+
err.span_suggestion_verbose(
2319+
span.shrink_to_hi(),
2320+
"use a comma to separate type parameters",
2321+
",",
2322+
Applicability::MaybeIncorrect,
2323+
);
2324+
}
2325+
Err(err.into())
2326+
}
2327+
22902328
/// Handle encountering a symbol in a generic argument list that is not a `,` or `>`. In this
22912329
/// case, we emit an error and try to suggest enclosing a const argument in braces if it looks
22922330
/// like the user has forgotten them.

0 commit comments

Comments
 (0)