Skip to content

Commit 25297a4

Browse files
committed
Auto merge of #143081 - GuillaumeGomez:rollup-zxqitnw, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #142270 (Rustdoc js: even more typechecking improvements) - #142420 (Report infer ty errors during hir ty lowering) - #142818 (Port `#[used]` to new attribute parsing infrastructure) - #143020 (codegen_fn_attrs: make comment more precise) - #143036 (Remove support for `dyn*` from the compiler) - #143060 (Only args in main diag are saved and restored without removing the newly added ones) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d51b6f9 + 508b576 commit 25297a4

File tree

190 files changed

+764
-3126
lines changed

Some content is hidden

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

190 files changed

+764
-3126
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,8 +2577,7 @@ pub enum TyPatKind {
25772577
pub enum TraitObjectSyntax {
25782578
// SAFETY: When adding new variants make sure to update the `Tag` impl.
25792579
Dyn = 0,
2580-
DynStar = 1,
2581-
None = 2,
2580+
None = 1,
25822581
}
25832582

25842583
/// SAFETY: `TraitObjectSyntax` only has 3 data-less variants which means
@@ -2594,8 +2593,7 @@ unsafe impl Tag for TraitObjectSyntax {
25942593
unsafe fn from_usize(tag: usize) -> Self {
25952594
match tag {
25962595
0 => TraitObjectSyntax::Dyn,
2597-
1 => TraitObjectSyntax::DynStar,
2598-
2 => TraitObjectSyntax::None,
2596+
1 => TraitObjectSyntax::None,
25992597
_ => unreachable!(),
26002598
}
26012599
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
505505
);
506506
gate_all!(associated_const_equality, "associated const equality is incomplete");
507507
gate_all!(yeet_expr, "`do yeet` expression is experimental");
508-
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
509508
gate_all!(const_closures, "const closures are experimental");
510509
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
511510
gate_all!(ergonomic_clones, "ergonomic clones are experimental");

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,6 @@ impl<'a> State<'a> {
13031303
ast::TyKind::TraitObject(bounds, syntax) => {
13041304
match syntax {
13051305
ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"),
1306-
ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"),
13071306
ast::TraitObjectSyntax::None => {}
13081307
}
13091308
self.print_type_bounds(bounds);

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ impl Deprecation {
131131
}
132132
}
133133

134+
/// There are three valid forms of the attribute:
135+
/// `#[used]`, which is semantically equivalent to `#[used(linker)]` except that the latter is currently unstable.
136+
/// `#[used(compiler)]`
137+
/// `#[used(linker)]`
138+
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
139+
#[derive(HashStable_Generic, PrintAttribute)]
140+
pub enum UsedBy {
141+
Compiler,
142+
Linker,
143+
}
144+
134145
/// Represents parsed *built-in* inert attributes.
135146
///
136147
/// ## Overview
@@ -285,5 +296,8 @@ pub enum AttributeKind {
285296

286297
/// Represents `#[track_caller]`
287298
TrackCaller(Span),
299+
300+
/// Represents `#[used]`
301+
Used { used_by: UsedBy, span: Span },
288302
// tidy-alphabetical-end
289303
}

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl AttributeKind {
3838
PubTransparent(..) => Yes,
3939
SkipDuringMethodDispatch { .. } => No,
4040
TrackCaller(..) => Yes,
41+
Used { .. } => No,
4142
}
4243
}
4344
}

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr};
1+
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr, UsedBy};
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_session::parse::feature_err;
44
use rustc_span::{Span, Symbol, sym};
@@ -228,3 +228,84 @@ impl<S: Stage> SingleAttributeParser<S> for NoMangleParser {
228228
Some(AttributeKind::NoMangle(cx.attr_span))
229229
}
230230
}
231+
232+
#[derive(Default)]
233+
pub(crate) struct UsedParser {
234+
first_compiler: Option<Span>,
235+
first_linker: Option<Span>,
236+
}
237+
238+
// A custom `AttributeParser` is used rather than a Simple attribute parser because
239+
// - Specifying two `#[used]` attributes is a warning (but will be an error in the future)
240+
// - But specifying two conflicting attributes: `#[used(compiler)]` and `#[used(linker)]` is already an error today
241+
// We can change this to a Simple parser once the warning becomes an error
242+
impl<S: Stage> AttributeParser<S> for UsedParser {
243+
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
244+
&[sym::used],
245+
template!(Word, List: "compiler|linker"),
246+
|group: &mut Self, cx, args| {
247+
let used_by = match args {
248+
ArgParser::NoArgs => UsedBy::Linker,
249+
ArgParser::List(list) => {
250+
let Some(l) = list.single() else {
251+
cx.expected_single_argument(list.span);
252+
return;
253+
};
254+
255+
match l.meta_item().and_then(|i| i.path().word_sym()) {
256+
Some(sym::compiler) => {
257+
if !cx.features().used_with_arg() {
258+
feature_err(
259+
&cx.sess(),
260+
sym::used_with_arg,
261+
cx.attr_span,
262+
"`#[used(compiler)]` is currently unstable",
263+
)
264+
.emit();
265+
}
266+
UsedBy::Compiler
267+
}
268+
Some(sym::linker) => {
269+
if !cx.features().used_with_arg() {
270+
feature_err(
271+
&cx.sess(),
272+
sym::used_with_arg,
273+
cx.attr_span,
274+
"`#[used(linker)]` is currently unstable",
275+
)
276+
.emit();
277+
}
278+
UsedBy::Linker
279+
}
280+
_ => {
281+
cx.expected_specific_argument(l.span(), vec!["compiler", "linker"]);
282+
return;
283+
}
284+
}
285+
}
286+
ArgParser::NameValue(_) => return,
287+
};
288+
289+
let target = match used_by {
290+
UsedBy::Compiler => &mut group.first_compiler,
291+
UsedBy::Linker => &mut group.first_linker,
292+
};
293+
294+
let attr_span = cx.attr_span;
295+
if let Some(prev) = *target {
296+
cx.warn_unused_duplicate(prev, attr_span);
297+
} else {
298+
*target = Some(attr_span);
299+
}
300+
},
301+
)];
302+
303+
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
304+
// Ratcheting behaviour, if both `linker` and `compiler` are specified, use `linker`
305+
Some(match (self.first_compiler, self.first_linker) {
306+
(_, Some(span)) => AttributeKind::Used { used_by: UsedBy::Linker, span },
307+
(Some(span), _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
308+
(None, None) => return None,
309+
})
310+
}
311+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
1818
use crate::attributes::codegen_attrs::{
1919
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TrackCallerParser,
20+
UsedParser,
2021
};
2122
use crate::attributes::confusables::ConfusablesParser;
2223
use crate::attributes::deprecation::DeprecationParser;
@@ -103,6 +104,7 @@ attribute_parsers!(
103104
ConstStabilityParser,
104105
NakedParser,
105106
StabilityParser,
107+
UsedParser,
106108
// tidy-alphabetical-end
107109

108110
// tidy-alphabetical-start

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use rustc_middle::traits::query::NoSolution;
2525
use rustc_middle::ty::adjustment::PointerCoercion;
2626
use rustc_middle::ty::cast::CastTy;
2727
use rustc_middle::ty::{
28-
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
29-
Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt,
30-
TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
28+
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
29+
GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, TypeVisitableExt,
30+
UserArgs, UserTypeAnnotationIndex, fold_regions,
3131
};
3232
use rustc_middle::{bug, span_bug};
3333
use rustc_mir_dataflow::move_paths::MoveData;
@@ -1233,38 +1233,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
12331233
);
12341234
}
12351235

1236-
CastKind::PointerCoercion(PointerCoercion::DynStar, coercion_source) => {
1237-
// get the constraints from the target type (`dyn* Clone`)
1238-
//
1239-
// apply them to prove that the source type `Foo` implements `Clone` etc
1240-
let (existential_predicates, region) = match ty.kind() {
1241-
Dynamic(predicates, region, ty::DynStar) => (predicates, region),
1242-
_ => panic!("Invalid dyn* cast_ty"),
1243-
};
1244-
1245-
let self_ty = op.ty(self.body, tcx);
1246-
1247-
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1248-
self.prove_predicates(
1249-
existential_predicates
1250-
.iter()
1251-
.map(|predicate| predicate.with_self_ty(tcx, self_ty)),
1252-
location.to_locations(),
1253-
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
1254-
);
1255-
1256-
let outlives_predicate = tcx.mk_predicate(Binder::dummy(
1257-
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(
1258-
ty::OutlivesPredicate(self_ty, *region),
1259-
)),
1260-
));
1261-
self.prove_predicate(
1262-
outlives_predicate,
1263-
location.to_locations(),
1264-
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
1265-
);
1266-
}
1267-
12681236
CastKind::PointerCoercion(
12691237
PointerCoercion::MutToConstPointer,
12701238
coercion_source,

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -753,51 +753,6 @@ pub(crate) fn codegen_drop<'tcx>(
753753
fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]);
754754
fx.bcx.ins().jump(ret_block, &[]);
755755
}
756-
ty::Dynamic(_, _, ty::DynStar) => {
757-
// IN THIS ARM, WE HAVE:
758-
// ty = *mut (dyn* Trait)
759-
// which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)
760-
//
761-
// args = [ * ]
762-
// |
763-
// v
764-
// ( Data, Vtable )
765-
// |
766-
// v
767-
// /-------\
768-
// | ... |
769-
// \-------/
770-
//
771-
//
772-
// WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING
773-
//
774-
// data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer)
775-
// vtable = (*args[0]).1 // loads the vtable out
776-
// (data, vtable) // an equivalent Rust `*mut dyn Trait`
777-
//
778-
// SO THEN WE CAN USE THE ABOVE CODE.
779-
let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx);
780-
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
781-
782-
let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
783-
let target_block = fx.get_block(target);
784-
let continued = fx.bcx.create_block();
785-
fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
786-
fx.bcx.switch_to_block(continued);
787-
788-
let virtual_drop = Instance {
789-
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
790-
args: drop_instance.args,
791-
};
792-
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
793-
.fn_abi_of_instance(virtual_drop, ty::List::empty());
794-
795-
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
796-
let sig = fx.bcx.import_signature(sig);
797-
fx.bcx.ins().call_indirect(sig, drop_fn, &[data]);
798-
// FIXME implement cleanup on exceptions
799-
fx.bcx.ins().jump(ret_block, &[]);
800-
}
801756
_ => {
802757
assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _)));
803758

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -778,14 +778,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
778778
let operand = codegen_operand(fx, operand);
779779
crate::unsize::coerce_unsized_into(fx, operand, lval);
780780
}
781-
Rvalue::Cast(
782-
CastKind::PointerCoercion(PointerCoercion::DynStar, _),
783-
ref operand,
784-
_,
785-
) => {
786-
let operand = codegen_operand(fx, operand);
787-
crate::unsize::coerce_dyn_star(fx, operand, lval);
788-
}
789781
Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => {
790782
let operand = codegen_operand(fx, operand);
791783
lval.write_cvalue_transmute(fx, operand);

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,6 @@ fn unsize_ptr<'tcx>(
112112
}
113113
}
114114

115-
/// Coerces `src` to `dst_ty` which is guaranteed to be a `dyn*` type.
116-
pub(crate) fn cast_to_dyn_star<'tcx>(
117-
fx: &mut FunctionCx<'_, '_, 'tcx>,
118-
src: Value,
119-
src_ty_and_layout: TyAndLayout<'tcx>,
120-
dst_ty: Ty<'tcx>,
121-
old_info: Option<Value>,
122-
) -> (Value, Value) {
123-
assert!(
124-
matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)),
125-
"destination type must be a dyn*"
126-
);
127-
(src, unsized_info(fx, src_ty_and_layout.ty, dst_ty, old_info))
128-
}
129-
130115
/// Coerce `src`, which is a reference to a value of type `src_ty`,
131116
/// to a value of type `dst_ty` and store the result in `dst`
132117
pub(crate) fn coerce_unsized_into<'tcx>(
@@ -174,24 +159,6 @@ pub(crate) fn coerce_unsized_into<'tcx>(
174159
}
175160
}
176161

177-
pub(crate) fn coerce_dyn_star<'tcx>(
178-
fx: &mut FunctionCx<'_, '_, 'tcx>,
179-
src: CValue<'tcx>,
180-
dst: CPlace<'tcx>,
181-
) {
182-
let (data, extra) = if let ty::Dynamic(_, _, ty::DynStar) = src.layout().ty.kind() {
183-
let (data, vtable) = src.load_scalar_pair(fx);
184-
(data, Some(vtable))
185-
} else {
186-
let data = src.load_scalar(fx);
187-
(data, None)
188-
};
189-
190-
let (data, vtable) = cast_to_dyn_star(fx, data, src.layout(), dst.layout().ty, extra);
191-
192-
dst.write_cvalue(fx, CValue::by_val_pair(data, vtable, dst.layout()));
193-
}
194-
195162
// Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs
196163

197164
pub(crate) fn size_and_align_of<'tcx>(

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -121,43 +121,6 @@ impl<'tcx> CValue<'tcx> {
121121
}
122122
}
123123

124-
// FIXME remove
125-
/// Forces the data value of a dyn* value to the stack and returns a pointer to it as well as the
126-
/// vtable pointer.
127-
pub(crate) fn dyn_star_force_data_on_stack(
128-
self,
129-
fx: &mut FunctionCx<'_, '_, 'tcx>,
130-
) -> (Value, Value) {
131-
assert!(self.1.ty.is_dyn_star());
132-
133-
match self.0 {
134-
CValueInner::ByRef(ptr, None) => {
135-
let (a_scalar, b_scalar) = match self.1.backend_repr {
136-
BackendRepr::ScalarPair(a, b) => (a, b),
137-
_ => unreachable!("dyn_star_force_data_on_stack({:?})", self),
138-
};
139-
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
140-
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar);
141-
let mut flags = MemFlags::new();
142-
flags.set_notrap();
143-
let vtable = ptr.offset(fx, b_offset).load(fx, clif_ty2, flags);
144-
(ptr.get_addr(fx), vtable)
145-
}
146-
CValueInner::ByValPair(data, vtable) => {
147-
let data_ptr = fx.create_stack_slot(
148-
u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(),
149-
u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(),
150-
);
151-
data_ptr.store(fx, data, MemFlags::trusted());
152-
153-
(data_ptr.get_addr(fx), vtable)
154-
}
155-
CValueInner::ByRef(_, Some(_)) | CValueInner::ByVal(_) => {
156-
unreachable!("dyn_star_force_data_on_stack({:?})", self)
157-
}
158-
}
159-
}
160-
161124
pub(crate) fn try_to_ptr(self) -> Option<(Pointer, Option<Value>)> {
162125
match self.0 {
163126
CValueInner::ByRef(ptr, meta) => Some((ptr, meta)),

0 commit comments

Comments
 (0)