Skip to content

Commit 9d8866a

Browse files
committed
Auto merge of rust-lang#122065 - matthiaskrgr:rollup-nx4qiby, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#113518 (bootstrap/libtest: print test name eagerly on failure even with `verbose-tests=false` / `--quiet`) - rust-lang#119888 (Stabilize the `#[diagnostic]` namespace and `#[diagnostic::on_unimplemented]` attribute) - rust-lang#121752 (Detect unused struct impls pub trait) - rust-lang#121885 (Move generic `NonZero` `rustc_layout_scalar_valid_range_start` attribute to inner type.) - rust-lang#121926 (`f16` and `f128` step 3: compiler support & feature gate) - rust-lang#121959 (Removing absolute path in proc-macro) - rust-lang#122015 (Add better explanation for `rustc_index::IndexVec`) - rust-lang#122027 (Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries) - rust-lang#122038 (Fix linting paths with qself in `unused_qualifications`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b77e018 + 0936b1c commit 9d8866a

File tree

78 files changed

+1079
-713
lines changed

Some content is hidden

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

78 files changed

+1079
-713
lines changed

compiler/rustc_ast/src/util/literal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ fn filtered_float_lit(
276276
Some(suffix) => LitKind::Float(
277277
symbol,
278278
ast::LitFloatType::Suffixed(match suffix {
279+
sym::f16 => ast::FloatTy::F16,
279280
sym::f32 => ast::FloatTy::F32,
280281
sym::f64 => ast::FloatTy::F64,
282+
sym::f128 => ast::FloatTy::F128,
281283
_ => return Err(LitError::InvalidFloatSuffix(suffix)),
282284
}),
283285
),

compiler/rustc_ast_passes/src/feature_gate.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
33
use rustc_ast::{attr, AssocConstraint, AssocConstraintKind, NodeId};
4-
use rustc_ast::{PatKind, RangeEnd};
4+
use rustc_ast::{token, PatKind, RangeEnd};
55
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
66
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
77
use rustc_session::Session;
@@ -203,14 +203,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
203203
);
204204
}
205205
}
206-
if !attr.is_doc_comment()
207-
&& let [seg, _] = attr.get_normal_item().path.segments.as_slice()
208-
&& seg.ident.name == sym::diagnostic
209-
&& !self.features.diagnostic_namespace
210-
{
211-
let msg = "`#[diagnostic]` attribute name space is experimental";
212-
gate!(self, diagnostic_namespace, seg.ident.span, msg);
213-
}
214206

215207
// Emit errors for non-staged-api crates.
216208
if !self.features.staged_api {
@@ -383,6 +375,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
383375
ast::ExprKind::TryBlock(_) => {
384376
gate!(&self, try_blocks, e.span, "`try` expression is experimental");
385377
}
378+
ast::ExprKind::Lit(token::Lit { kind: token::LitKind::Float, suffix, .. }) => {
379+
match suffix {
380+
Some(sym::f16) => {
381+
gate!(&self, f16, e.span, "the type `f16` is unstable")
382+
}
383+
Some(sym::f128) => {
384+
gate!(&self, f128, e.span, "the type `f128` is unstable")
385+
}
386+
_ => (),
387+
}
388+
}
386389
_ => {}
387390
}
388391
visit::walk_expr(self, e)

compiler/rustc_codegen_gcc/src/errors.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use rustc_errors::{
2-
DiagCtxt, DiagArgValue, Diag, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level,
2+
DiagCtxt, Diag, EmissionGuarantee, IntoDiagnostic, Level,
33
};
44
use rustc_macros::{Diagnostic, Subdiagnostic};
55
use rustc_span::Span;
6-
use std::borrow::Cow;
76

87
use crate::fluent_generated as fluent;
98

@@ -31,18 +30,6 @@ pub(crate) enum PossibleFeature<'a> {
3130
None,
3231
}
3332

34-
struct ExitCode(Option<i32>);
35-
36-
impl IntoDiagnosticArg for ExitCode {
37-
fn into_diagnostic_arg(self) -> DiagArgValue {
38-
let ExitCode(exit_code) = self;
39-
match exit_code {
40-
Some(t) => t.into_diagnostic_arg(),
41-
None => DiagArgValue::Str(Cow::Borrowed("<signal>")),
42-
}
43-
}
44-
}
45-
4633
#[derive(Diagnostic)]
4734
#[diag(codegen_gcc_lto_not_supported)]
4835
pub(crate) struct LTONotSupported;
@@ -80,12 +67,6 @@ pub(crate) struct CopyBitcode {
8067
#[note]
8168
pub(crate) struct DynamicLinkingWithLTO;
8269

83-
#[derive(Diagnostic)]
84-
#[diag(codegen_gcc_load_bitcode)]
85-
pub(crate) struct LoadBitcode {
86-
name: String,
87-
}
88-
8970
#[derive(Diagnostic)]
9071
#[diag(codegen_gcc_lto_disallowed)]
9172
pub(crate) struct LtoDisallowed;

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ declare_features! (
146146
(accepted, derive_default_enum, "1.62.0", Some(86985)),
147147
/// Allows the use of destructuring assignments.
148148
(accepted, destructuring_assignment, "1.59.0", Some(71126)),
149+
/// Allows using the `#[diagnostic]` attribute tool namespace
150+
(accepted, diagnostic_namespace, "CURRENT_RUSTC_VERSION", Some(111996)),
149151
/// Allows `#[doc(alias = "...")]`.
150152
(accepted, doc_alias, "1.48.0", Some(50146)),
151153
/// Allows `..` in tuple (struct) patterns.

compiler/rustc_feature/src/unstable.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,6 @@ declare_features! (
436436
(unstable, deprecated_safe, "1.61.0", Some(94978)),
437437
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
438438
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
439-
/// Allows using the `#[diagnostic]` attribute tool namespace
440-
(unstable, diagnostic_namespace, "1.73.0", Some(111996)),
441439
/// Controls errors in trait implementations.
442440
(unstable, do_not_recommend, "1.67.0", Some(51992)),
443441
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
@@ -463,6 +461,10 @@ declare_features! (
463461
(unstable, extended_varargs_abi_support, "1.65.0", Some(100189)),
464462
/// Allows defining `extern type`s.
465463
(unstable, extern_types, "1.23.0", Some(43467)),
464+
/// Allow using 128-bit (quad precision) floating point numbers.
465+
(unstable, f128, "CURRENT_RUSTC_VERSION", Some(116909)),
466+
/// Allow using 16-bit (half precision) floating point numbers.
467+
(unstable, f16, "CURRENT_RUSTC_VERSION", Some(116909)),
466468
/// Allows the use of `#[ffi_const]` on foreign functions.
467469
(unstable, ffi_const, "1.45.0", Some(58328)),
468470
/// Allows the use of `#[ffi_pure]` on foreign functions.

compiler/rustc_hir/src/hir.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,7 @@ pub enum PrimTy {
24442444

24452445
impl PrimTy {
24462446
/// All of the primitive types
2447-
pub const ALL: [Self; 17] = [
2447+
pub const ALL: [Self; 19] = [
24482448
// any changes here should also be reflected in `PrimTy::from_name`
24492449
Self::Int(IntTy::I8),
24502450
Self::Int(IntTy::I16),
@@ -2458,9 +2458,10 @@ impl PrimTy {
24582458
Self::Uint(UintTy::U64),
24592459
Self::Uint(UintTy::U128),
24602460
Self::Uint(UintTy::Usize),
2461+
Self::Float(FloatTy::F16),
24612462
Self::Float(FloatTy::F32),
24622463
Self::Float(FloatTy::F64),
2463-
// FIXME(f16_f128): add these when enabled below
2464+
Self::Float(FloatTy::F128),
24642465
Self::Bool,
24652466
Self::Char,
24662467
Self::Str,
@@ -2508,12 +2509,10 @@ impl PrimTy {
25082509
sym::u64 => Self::Uint(UintTy::U64),
25092510
sym::u128 => Self::Uint(UintTy::U128),
25102511
sym::usize => Self::Uint(UintTy::Usize),
2512+
sym::f16 => Self::Float(FloatTy::F16),
25112513
sym::f32 => Self::Float(FloatTy::F32),
25122514
sym::f64 => Self::Float(FloatTy::F64),
2513-
// FIXME(f16_f128): enabling these will open the gates of f16 and f128 being
2514-
// understood by rustc.
2515-
// sym::f16 => Self::Float(FloatTy::F16),
2516-
// sym::f128 => Self::Float(FloatTy::F128),
2515+
sym::f128 => Self::Float(FloatTy::F128),
25172516
sym::bool => Self::Bool,
25182517
sym::char => Self::Char,
25192518
sym::str => Self::Str,

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+37
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ use rustc_span::Span;
1414
pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
1515
use rustc_hir::*;
1616

17+
// For an RPITIT, synthesize generics which are equal to the opaque's generics
18+
// and parent fn's generics compressed into one list.
19+
if let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, opaque_def_id }) =
20+
tcx.opt_rpitit_info(def_id.to_def_id())
21+
{
22+
let trait_def_id = tcx.parent(fn_def_id);
23+
let opaque_ty_generics = tcx.generics_of(opaque_def_id);
24+
let opaque_ty_parent_count = opaque_ty_generics.parent_count;
25+
let mut params = opaque_ty_generics.params.clone();
26+
27+
let parent_generics = tcx.generics_of(trait_def_id);
28+
let parent_count = parent_generics.parent_count + parent_generics.params.len();
29+
30+
let mut trait_fn_params = tcx.generics_of(fn_def_id).params.clone();
31+
32+
for param in &mut params {
33+
param.index = param.index + parent_count as u32 + trait_fn_params.len() as u32
34+
- opaque_ty_parent_count as u32;
35+
}
36+
37+
trait_fn_params.extend(params);
38+
params = trait_fn_params;
39+
40+
let param_def_id_to_index =
41+
params.iter().map(|param| (param.def_id, param.index)).collect();
42+
43+
return ty::Generics {
44+
parent: Some(trait_def_id),
45+
parent_count,
46+
params,
47+
param_def_id_to_index,
48+
has_self: opaque_ty_generics.has_self,
49+
has_late_bound_regions: opaque_ty_generics.has_late_bound_regions,
50+
host_effect_index: parent_generics.host_effect_index,
51+
};
52+
}
53+
1754
let hir_id = tcx.local_def_id_to_hir_id(def_id);
1855

1956
let node = tcx.hir_node(hir_id);

compiler/rustc_hir_analysis/src/collect/type_of.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::HirId;
55
use rustc_middle::query::plumbing::CyclePlaceholder;
66
use rustc_middle::ty::print::with_forced_trimmed_paths;
77
use rustc_middle::ty::util::IntTypeExt;
8-
use rustc_middle::ty::{self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
8+
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
99
use rustc_span::symbol::Ident;
1010
use rustc_span::{Span, DUMMY_SP};
1111

@@ -350,22 +350,31 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
350350
// If we are computing `type_of` the synthesized associated type for an RPITIT in the impl
351351
// side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the
352352
// associated type in the impl.
353-
if let Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) =
354-
tcx.opt_rpitit_info(def_id.to_def_id())
355-
{
356-
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
357-
Ok(map) => {
358-
let assoc_item = tcx.associated_item(def_id);
359-
return map[&assoc_item.trait_item_def_id.unwrap()];
360-
}
361-
Err(_) => {
362-
return ty::EarlyBinder::bind(Ty::new_error_with_message(
363-
tcx,
364-
DUMMY_SP,
365-
"Could not collect return position impl trait in trait tys",
366-
));
353+
match tcx.opt_rpitit_info(def_id.to_def_id()) {
354+
Some(ty::ImplTraitInTraitData::Impl { fn_def_id }) => {
355+
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
356+
Ok(map) => {
357+
let assoc_item = tcx.associated_item(def_id);
358+
return map[&assoc_item.trait_item_def_id.unwrap()];
359+
}
360+
Err(_) => {
361+
return ty::EarlyBinder::bind(Ty::new_error_with_message(
362+
tcx,
363+
DUMMY_SP,
364+
"Could not collect return position impl trait in trait tys",
365+
));
366+
}
367367
}
368368
}
369+
// For an RPITIT in a trait, just return the corresponding opaque.
370+
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
371+
return ty::EarlyBinder::bind(Ty::new_opaque(
372+
tcx,
373+
opaque_def_id,
374+
ty::GenericArgs::identity_for_item(tcx, opaque_def_id),
375+
));
376+
}
377+
None => {}
369378
}
370379

371380
let hir_id = tcx.local_def_id_to_hir_id(def_id);

compiler/rustc_index/src/vec.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,27 @@ use std::vec;
1212
use crate::{Idx, IndexSlice};
1313

1414
/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`.
15-
/// Its purpose is to avoid mixing indexes.
15+
///
16+
/// ## Why use this instead of a `Vec`?
17+
///
18+
/// An `IndexVec` allows element access only via a specific associated index type, meaning that
19+
/// trying to use the wrong index type (possibly accessing an invalid element) will fail at
20+
/// compile time.
21+
///
22+
/// It also documents what the index is indexing: in a `HashMap<usize, Something>` it's not
23+
/// immediately clear what the `usize` means, while a `HashMap<FieldIdx, Something>` makes it obvious.
24+
///
25+
/// ```compile_fail
26+
/// use rustc_index::{Idx, IndexVec};
27+
///
28+
/// fn f<I1: Idx, I2: Idx>(vec1: IndexVec<I1, u8>, idx1: I1, idx2: I2) {
29+
/// &vec1[idx1]; // Ok
30+
/// &vec1[idx2]; // Compile error!
31+
/// }
32+
/// ```
1633
///
1734
/// While it's possible to use `u32` or `usize` directly for `I`,
18-
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
35+
/// you almost certainly want to use a [`newtype_index!`] generated type instead.
1936
///
2037
/// This allows to index the IndexVec with the new index type.
2138
///

0 commit comments

Comments
 (0)