Skip to content

Commit ec34ab5

Browse files
committed
Auto merge of #123746 - fmease:rollup-pqkaizg, r=fmease
Rollup of 6 pull requests Successful merges: - #122470 (`f16` and `f128` step 4: basic library support) - #122954 (Be more specific when flagging imports as redundant due to the extern prelude) - #123314 (Skip `unused_parens` report for `Paren(Path(..))` in macro.) - #123360 (Document restricted_std) - #123703 (Use `fn` ptr signature instead of `{closure@..}` in infer error) - #123732 (Factor some common `io::Error` constants) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b3bd705 + 8cb7d6a commit ec34ab5

File tree

79 files changed

+847
-266
lines changed

Some content is hidden

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

79 files changed

+847
-266
lines changed

compiler/rustc_infer/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ infer_fps_items_are_distinct = fn items are distinct from fn pointers
144144
infer_fps_remove_ref = consider removing the reference
145145
infer_fps_use_ref = consider using a reference
146146
infer_fulfill_req_lifetime = the type `{$ty}` does not fulfill the required lifetime
147+
148+
infer_full_type_written = the full type name has been written to '{$path}'
149+
147150
infer_implicit_static_lifetime_note = this has an implicit `'static` lifetime requirement
148151
infer_implicit_static_lifetime_suggestion = consider relaxing the implicit `'static` requirement
149152
infer_label_bad = {$bad_kind ->

compiler/rustc_infer/src/errors/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use crate::infer::error_reporting::{
1818
ObligationCauseAsDiagArg,
1919
};
2020

21+
use std::path::PathBuf;
22+
2123
pub mod note_and_explain;
2224

2325
#[derive(Diagnostic)]
@@ -47,6 +49,9 @@ pub struct AnnotationRequired<'a> {
4749
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
4850
#[subdiagnostic]
4951
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
52+
#[note(infer_full_type_written)]
53+
pub was_written: Option<()>,
54+
pub path: PathBuf,
5055
}
5156

5257
// Copy of `AnnotationRequired` for E0283
@@ -65,6 +70,9 @@ pub struct AmbiguousImpl<'a> {
6570
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
6671
#[subdiagnostic]
6772
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
73+
#[note(infer_full_type_written)]
74+
pub was_written: Option<()>,
75+
pub path: PathBuf,
6876
}
6977

7078
// Copy of `AnnotationRequired` for E0284
@@ -83,6 +91,9 @@ pub struct AmbiguousReturn<'a> {
8391
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
8492
#[subdiagnostic]
8593
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
94+
#[note(infer_full_type_written)]
95+
pub was_written: Option<()>,
96+
pub path: PathBuf,
8697
}
8798

8899
// Used when a better one isn't available

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+56-19
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ use rustc_middle::infer::unify_key::{
1818
};
1919
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
2020
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
21-
use rustc_middle::ty::{self, InferConst};
22-
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef};
23-
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
21+
use rustc_middle::ty::{
22+
self, GenericArg, GenericArgKind, GenericArgsRef, InferConst, IsSuggestable, Ty, TyCtxt,
23+
TypeFoldable, TypeFolder, TypeSuperFoldable, TypeckResults,
24+
};
2425
use rustc_span::symbol::{kw, sym, Ident};
25-
use rustc_span::{BytePos, Span};
26+
use rustc_span::{BytePos, Span, DUMMY_SP};
2627
use std::borrow::Cow;
2728
use std::iter;
29+
use std::path::PathBuf;
2830

2931
pub enum TypeAnnotationNeeded {
3032
/// ```compile_fail,E0282
@@ -153,6 +155,29 @@ impl UnderspecifiedArgKind {
153155
}
154156
}
155157

158+
struct ClosureEraser<'tcx> {
159+
tcx: TyCtxt<'tcx>,
160+
}
161+
162+
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ClosureEraser<'tcx> {
163+
fn interner(&self) -> TyCtxt<'tcx> {
164+
self.tcx
165+
}
166+
167+
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
168+
match ty.kind() {
169+
ty::Closure(_, args) => {
170+
let closure_sig = args.as_closure().sig();
171+
Ty::new_fn_ptr(
172+
self.tcx,
173+
self.tcx.signature_unclosure(closure_sig, hir::Unsafety::Normal),
174+
)
175+
}
176+
_ => ty.super_fold_with(self),
177+
}
178+
}
179+
}
180+
156181
fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinter<'a, 'tcx> {
157182
let mut printer = FmtPrinter::new(infcx.tcx, ns);
158183
let ty_getter = move |ty_vid| {
@@ -209,6 +234,10 @@ fn ty_to_string<'tcx>(
209234
) -> String {
210235
let mut printer = fmt_printer(infcx, Namespace::TypeNS);
211236
let ty = infcx.resolve_vars_if_possible(ty);
237+
// We use `fn` ptr syntax for closures, but this only works when the closure
238+
// does not capture anything.
239+
let ty = ty.fold_with(&mut ClosureEraser { tcx: infcx.tcx });
240+
212241
match (ty.kind(), called_method_def_id) {
213242
// We don't want the regular output for `fn`s because it includes its path in
214243
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
@@ -223,11 +252,6 @@ fn ty_to_string<'tcx>(
223252
"Vec<_>".to_string()
224253
}
225254
_ if ty.is_ty_or_numeric_infer() => "/* Type */".to_string(),
226-
// FIXME: The same thing for closures, but this only works when the closure
227-
// does not capture anything.
228-
//
229-
// We do have to hide the `extern "rust-call"` ABI in that case though,
230-
// which is too much of a bother for now.
231255
_ => {
232256
ty.print(&mut printer).unwrap();
233257
printer.into_buffer()
@@ -387,6 +411,8 @@ impl<'tcx> InferCtxt<'tcx> {
387411
infer_subdiags,
388412
multi_suggestions,
389413
bad_label,
414+
was_written: None,
415+
path: Default::default(),
390416
}),
391417
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
392418
span,
@@ -396,6 +422,8 @@ impl<'tcx> InferCtxt<'tcx> {
396422
infer_subdiags,
397423
multi_suggestions,
398424
bad_label,
425+
was_written: None,
426+
path: Default::default(),
399427
}),
400428
TypeAnnotationNeeded::E0284 => self.dcx().create_err(AmbiguousReturn {
401429
span,
@@ -405,6 +433,8 @@ impl<'tcx> InferCtxt<'tcx> {
405433
infer_subdiags,
406434
multi_suggestions,
407435
bad_label,
436+
was_written: None,
437+
path: Default::default(),
408438
}),
409439
}
410440
}
@@ -442,7 +472,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
442472
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
443473
};
444474

445-
let (source_kind, name) = kind.ty_localized_msg(self);
475+
let (source_kind, name, path) = kind.ty_localized_msg(self);
446476
let failure_span = if should_label_span && !failure_span.overlaps(span) {
447477
Some(failure_span)
448478
} else {
@@ -518,15 +548,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
518548
GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
519549
GenericArgKind::Type(_) => self
520550
.next_ty_var(TypeVariableOrigin {
521-
span: rustc_span::DUMMY_SP,
551+
span: DUMMY_SP,
522552
kind: TypeVariableOriginKind::MiscVariable,
523553
})
524554
.into(),
525555
GenericArgKind::Const(arg) => self
526556
.next_const_var(
527557
arg.ty(),
528558
ConstVariableOrigin {
529-
span: rustc_span::DUMMY_SP,
559+
span: DUMMY_SP,
530560
kind: ConstVariableOriginKind::MiscVariable,
531561
},
532562
)
@@ -547,7 +577,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
547577
}
548578
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => {
549579
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
550-
span: rustc_span::DUMMY_SP,
580+
span: DUMMY_SP,
551581
kind: TypeVariableOriginKind::MiscVariable,
552582
}));
553583
if let Some(args) = args.make_suggestable(self.infcx.tcx, true, placeholder) {
@@ -584,7 +614,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
584614
}
585615
InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => {
586616
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
587-
span: rustc_span::DUMMY_SP,
617+
span: DUMMY_SP,
588618
kind: TypeVariableOriginKind::MiscVariable,
589619
}));
590620
if let Some(ty) = ty.make_suggestable(self.infcx.tcx, true, placeholder) {
@@ -606,6 +636,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
606636
infer_subdiags,
607637
multi_suggestions,
608638
bad_label: None,
639+
was_written: path.as_ref().map(|_| ()),
640+
path: path.unwrap_or_default(),
609641
}),
610642
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
611643
span,
@@ -615,6 +647,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
615647
infer_subdiags,
616648
multi_suggestions,
617649
bad_label: None,
650+
was_written: path.as_ref().map(|_| ()),
651+
path: path.unwrap_or_default(),
618652
}),
619653
TypeAnnotationNeeded::E0284 => self.dcx().create_err(AmbiguousReturn {
620654
span,
@@ -624,6 +658,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
624658
infer_subdiags,
625659
multi_suggestions,
626660
bad_label: None,
661+
was_written: path.as_ref().map(|_| ()),
662+
path: path.unwrap_or_default(),
627663
}),
628664
}
629665
}
@@ -688,22 +724,23 @@ impl<'tcx> InferSource<'tcx> {
688724
}
689725

690726
impl<'tcx> InferSourceKind<'tcx> {
691-
fn ty_localized_msg(&self, infcx: &InferCtxt<'tcx>) -> (&'static str, String) {
727+
fn ty_localized_msg(&self, infcx: &InferCtxt<'tcx>) -> (&'static str, String, Option<PathBuf>) {
728+
let mut path = None;
692729
match *self {
693730
InferSourceKind::LetBinding { ty, .. }
694731
| InferSourceKind::ClosureArg { ty, .. }
695732
| InferSourceKind::ClosureReturn { ty, .. } => {
696733
if ty.is_closure() {
697-
("closure", closure_as_fn_str(infcx, ty))
734+
("closure", closure_as_fn_str(infcx, ty), path)
698735
} else if !ty.is_ty_or_numeric_infer() {
699-
("normal", ty_to_string(infcx, ty, None))
736+
("normal", infcx.tcx.short_ty_string(ty, &mut path), path)
700737
} else {
701-
("other", String::new())
738+
("other", String::new(), path)
702739
}
703740
}
704741
// FIXME: We should be able to add some additional info here.
705742
InferSourceKind::GenericArg { .. }
706-
| InferSourceKind::FullyQualifiedMethodCall { .. } => ("other", String::new()),
743+
| InferSourceKind::FullyQualifiedMethodCall { .. } => ("other", String::new(), path),
707744
}
708745
}
709746
}

compiler/rustc_lint/src/context/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
105105
BuiltinLintDiag::RedundantImport(spans, ident) => {
106106
for (span, is_imported) in spans {
107107
let introduced = if is_imported { "imported" } else { "defined" };
108-
let span_msg = if span.is_dummy() { "by prelude" } else { "here" };
108+
let span_msg = if span.is_dummy() { "by the extern prelude" } else { "here" };
109109
diag.span_label(
110110
span,
111111
format!("the item `{ident}` is already {introduced} {span_msg}"),

compiler/rustc_lint/src/unused.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1074,10 +1074,14 @@ impl UnusedParens {
10741074
// Otherwise proceed with linting.
10751075
_ => {}
10761076
}
1077-
let spans = inner
1078-
.span
1079-
.find_ancestor_inside(value.span)
1080-
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())));
1077+
let spans = if !value.span.from_expansion() {
1078+
inner
1079+
.span
1080+
.find_ancestor_inside(value.span)
1081+
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())))
1082+
} else {
1083+
None
1084+
};
10811085
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space, false);
10821086
}
10831087
}
@@ -1233,11 +1237,13 @@ impl EarlyLintPass for UnusedParens {
12331237
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
12341238
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
12351239
_ => {
1236-
let spans = r
1237-
.span
1238-
.find_ancestor_inside(ty.span)
1239-
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())));
1240-
1240+
let spans = if !ty.span.from_expansion() {
1241+
r.span
1242+
.find_ancestor_inside(ty.span)
1243+
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
1244+
} else {
1245+
None
1246+
};
12411247
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false), false);
12421248
}
12431249
}

library/core/src/clone.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,10 @@ mod impls {
227227
impl_clone! {
228228
usize u8 u16 u32 u64 u128
229229
isize i8 i16 i32 i64 i128
230-
f32 f64
230+
f16 f32 f64 f128
231231
bool char
232232
}
233233

234-
#[cfg(not(bootstrap))]
235-
impl_clone! { f16 f128 }
236-
237234
#[unstable(feature = "never_type", issue = "35121")]
238235
impl Clone for ! {
239236
#[inline]

library/core/src/cmp.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1497,12 +1497,9 @@ mod impls {
14971497
}
14981498

14991499
partial_eq_impl! {
1500-
bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64
1500+
bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
15011501
}
15021502

1503-
#[cfg(not(bootstrap))]
1504-
partial_eq_impl! { f16 f128 }
1505-
15061503
macro_rules! eq_impl {
15071504
($($t:ty)*) => ($(
15081505
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1553,10 +1550,7 @@ mod impls {
15531550
}
15541551
}
15551552

1556-
partial_ord_impl! { f32 f64 }
1557-
1558-
#[cfg(not(bootstrap))]
1559-
partial_ord_impl! { f16 f128 }
1553+
partial_ord_impl! { f16 f32 f64 f128 }
15601554

15611555
macro_rules! ord_impl {
15621556
($($t:ty)*) => ($(

library/core/src/convert/num.rs

+7
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ macro_rules! impl_float_to_int {
3434
}
3535
}
3636

37+
impl_float_to_int!(f16 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
3738
impl_float_to_int!(f32 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
3839
impl_float_to_int!(f64 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
40+
impl_float_to_int!(f128 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
3941

4042
// Conversion traits for primitive integer and float types
4143
// Conversions T -> T are covered by a blanket impl and therefore excluded
@@ -163,7 +165,12 @@ impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
163165
impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
164166

165167
// float -> float
168+
impl_from!(f16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
169+
impl_from!(f16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
170+
impl_from!(f16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
166171
impl_from!(f32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172+
impl_from!(f32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
173+
impl_from!(f64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
167174

168175
macro_rules! impl_float_from_bool {
169176
($float:ty) => {

library/core/src/fmt/nofloat.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ macro_rules! floating {
1111
};
1212
}
1313

14+
floating! { f16 }
1415
floating! { f32 }
1516
floating! { f64 }
17+
floating! { f128 }

library/core/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@
200200
//
201201
// Language features:
202202
// tidy-alphabetical-start
203-
#![cfg_attr(not(bootstrap), feature(f128))]
204-
#![cfg_attr(not(bootstrap), feature(f16))]
205203
#![feature(abi_unadjusted)]
206204
#![feature(adt_const_params)]
207205
#![feature(allow_internal_unsafe)]
@@ -226,6 +224,8 @@
226224
#![feature(doc_notable_trait)]
227225
#![feature(effects)]
228226
#![feature(extern_types)]
227+
#![feature(f128)]
228+
#![feature(f16)]
229229
#![feature(freeze_impls)]
230230
#![feature(fundamental)]
231231
#![feature(generic_arg_infer)]
@@ -347,6 +347,10 @@ pub mod u8;
347347
#[path = "num/shells/usize.rs"]
348348
pub mod usize;
349349

350+
#[path = "num/f128.rs"]
351+
pub mod f128;
352+
#[path = "num/f16.rs"]
353+
pub mod f16;
350354
#[path = "num/f32.rs"]
351355
pub mod f32;
352356
#[path = "num/f64.rs"]

0 commit comments

Comments
 (0)