Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #123746

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_infer/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ infer_fps_items_are_distinct = fn items are distinct from fn pointers
infer_fps_remove_ref = consider removing the reference
infer_fps_use_ref = consider using a reference
infer_fulfill_req_lifetime = the type `{$ty}` does not fulfill the required lifetime
infer_full_type_written = the full type name has been written to '{$path}'
infer_implicit_static_lifetime_note = this has an implicit `'static` lifetime requirement
infer_implicit_static_lifetime_suggestion = consider relaxing the implicit `'static` requirement
infer_label_bad = {$bad_kind ->
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_infer/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::infer::error_reporting::{
ObligationCauseAsDiagArg,
};

use std::path::PathBuf;

pub mod note_and_explain;

#[derive(Diagnostic)]
Expand Down Expand Up @@ -47,6 +49,9 @@ pub struct AnnotationRequired<'a> {
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
#[subdiagnostic]
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
#[note(infer_full_type_written)]
pub was_written: Option<()>,
pub path: PathBuf,
}

// Copy of `AnnotationRequired` for E0283
Expand All @@ -65,6 +70,9 @@ pub struct AmbiguousImpl<'a> {
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
#[subdiagnostic]
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
#[note(infer_full_type_written)]
pub was_written: Option<()>,
pub path: PathBuf,
}

// Copy of `AnnotationRequired` for E0284
Expand All @@ -83,6 +91,9 @@ pub struct AmbiguousReturn<'a> {
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
#[subdiagnostic]
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
#[note(infer_full_type_written)]
pub was_written: Option<()>,
pub path: PathBuf,
}

// Used when a better one isn't available
Expand Down
75 changes: 56 additions & 19 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ use rustc_middle::infer::unify_key::{
};
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
use rustc_middle::ty::{self, InferConst};
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef};
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
use rustc_middle::ty::{
self, GenericArg, GenericArgKind, GenericArgsRef, InferConst, IsSuggestable, Ty, TyCtxt,
TypeFoldable, TypeFolder, TypeSuperFoldable, TypeckResults,
};
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{BytePos, Span};
use rustc_span::{BytePos, Span, DUMMY_SP};
use std::borrow::Cow;
use std::iter;
use std::path::PathBuf;

pub enum TypeAnnotationNeeded {
/// ```compile_fail,E0282
Expand Down Expand Up @@ -153,6 +155,29 @@ impl UnderspecifiedArgKind {
}
}

struct ClosureEraser<'tcx> {
tcx: TyCtxt<'tcx>,
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ClosureEraser<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
self.tcx
}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.kind() {
ty::Closure(_, args) => {
let closure_sig = args.as_closure().sig();
Ty::new_fn_ptr(
self.tcx,
self.tcx.signature_unclosure(closure_sig, hir::Unsafety::Normal),
)
}
_ => ty.super_fold_with(self),
}
}
}

fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinter<'a, 'tcx> {
let mut printer = FmtPrinter::new(infcx.tcx, ns);
let ty_getter = move |ty_vid| {
Expand Down Expand Up @@ -209,6 +234,10 @@ fn ty_to_string<'tcx>(
) -> String {
let mut printer = fmt_printer(infcx, Namespace::TypeNS);
let ty = infcx.resolve_vars_if_possible(ty);
// We use `fn` ptr syntax for closures, but this only works when the closure
// does not capture anything.
let ty = ty.fold_with(&mut ClosureEraser { tcx: infcx.tcx });

match (ty.kind(), called_method_def_id) {
// We don't want the regular output for `fn`s because it includes its path in
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
Expand All @@ -223,11 +252,6 @@ fn ty_to_string<'tcx>(
"Vec<_>".to_string()
}
_ if ty.is_ty_or_numeric_infer() => "/* Type */".to_string(),
// FIXME: The same thing for closures, but this only works when the closure
// does not capture anything.
//
// We do have to hide the `extern "rust-call"` ABI in that case though,
// which is too much of a bother for now.
_ => {
ty.print(&mut printer).unwrap();
printer.into_buffer()
Expand Down Expand Up @@ -387,6 +411,8 @@ impl<'tcx> InferCtxt<'tcx> {
infer_subdiags,
multi_suggestions,
bad_label,
was_written: None,
path: Default::default(),
}),
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
span,
Expand All @@ -396,6 +422,8 @@ impl<'tcx> InferCtxt<'tcx> {
infer_subdiags,
multi_suggestions,
bad_label,
was_written: None,
path: Default::default(),
}),
TypeAnnotationNeeded::E0284 => self.dcx().create_err(AmbiguousReturn {
span,
Expand All @@ -405,6 +433,8 @@ impl<'tcx> InferCtxt<'tcx> {
infer_subdiags,
multi_suggestions,
bad_label,
was_written: None,
path: Default::default(),
}),
}
}
Expand Down Expand Up @@ -442,7 +472,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
};

let (source_kind, name) = kind.ty_localized_msg(self);
let (source_kind, name, path) = kind.ty_localized_msg(self);
let failure_span = if should_label_span && !failure_span.overlaps(span) {
Some(failure_span)
} else {
Expand Down Expand Up @@ -518,15 +548,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
GenericArgKind::Type(_) => self
.next_ty_var(TypeVariableOrigin {
span: rustc_span::DUMMY_SP,
span: DUMMY_SP,
kind: TypeVariableOriginKind::MiscVariable,
})
.into(),
GenericArgKind::Const(arg) => self
.next_const_var(
arg.ty(),
ConstVariableOrigin {
span: rustc_span::DUMMY_SP,
span: DUMMY_SP,
kind: ConstVariableOriginKind::MiscVariable,
},
)
Expand All @@ -547,7 +577,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => {
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
span: rustc_span::DUMMY_SP,
span: DUMMY_SP,
kind: TypeVariableOriginKind::MiscVariable,
}));
if let Some(args) = args.make_suggestable(self.infcx.tcx, true, placeholder) {
Expand Down Expand Up @@ -584,7 +614,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => {
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
span: rustc_span::DUMMY_SP,
span: DUMMY_SP,
kind: TypeVariableOriginKind::MiscVariable,
}));
if let Some(ty) = ty.make_suggestable(self.infcx.tcx, true, placeholder) {
Expand All @@ -606,6 +636,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer_subdiags,
multi_suggestions,
bad_label: None,
was_written: path.as_ref().map(|_| ()),
path: path.unwrap_or_default(),
}),
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
span,
Expand All @@ -615,6 +647,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer_subdiags,
multi_suggestions,
bad_label: None,
was_written: path.as_ref().map(|_| ()),
path: path.unwrap_or_default(),
}),
TypeAnnotationNeeded::E0284 => self.dcx().create_err(AmbiguousReturn {
span,
Expand All @@ -624,6 +658,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer_subdiags,
multi_suggestions,
bad_label: None,
was_written: path.as_ref().map(|_| ()),
path: path.unwrap_or_default(),
}),
}
}
Expand Down Expand Up @@ -688,22 +724,23 @@ impl<'tcx> InferSource<'tcx> {
}

impl<'tcx> InferSourceKind<'tcx> {
fn ty_localized_msg(&self, infcx: &InferCtxt<'tcx>) -> (&'static str, String) {
fn ty_localized_msg(&self, infcx: &InferCtxt<'tcx>) -> (&'static str, String, Option<PathBuf>) {
let mut path = None;
match *self {
InferSourceKind::LetBinding { ty, .. }
| InferSourceKind::ClosureArg { ty, .. }
| InferSourceKind::ClosureReturn { ty, .. } => {
if ty.is_closure() {
("closure", closure_as_fn_str(infcx, ty))
("closure", closure_as_fn_str(infcx, ty), path)
} else if !ty.is_ty_or_numeric_infer() {
("normal", ty_to_string(infcx, ty, None))
("normal", infcx.tcx.short_ty_string(ty, &mut path), path)
} else {
("other", String::new())
("other", String::new(), path)
}
}
// FIXME: We should be able to add some additional info here.
InferSourceKind::GenericArg { .. }
| InferSourceKind::FullyQualifiedMethodCall { .. } => ("other", String::new()),
| InferSourceKind::FullyQualifiedMethodCall { .. } => ("other", String::new(), path),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
BuiltinLintDiag::RedundantImport(spans, ident) => {
for (span, is_imported) in spans {
let introduced = if is_imported { "imported" } else { "defined" };
let span_msg = if span.is_dummy() { "by prelude" } else { "here" };
let span_msg = if span.is_dummy() { "by the extern prelude" } else { "here" };
diag.span_label(
span,
format!("the item `{ident}` is already {introduced} {span_msg}"),
Expand Down
24 changes: 15 additions & 9 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,10 +1074,14 @@ impl UnusedParens {
// Otherwise proceed with linting.
_ => {}
}
let spans = inner
.span
.find_ancestor_inside(value.span)
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())));
let spans = if !value.span.from_expansion() {
inner
.span
.find_ancestor_inside(value.span)
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())))
} else {
None
};
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space, false);
}
}
Expand Down Expand Up @@ -1233,11 +1237,13 @@ impl EarlyLintPass for UnusedParens {
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
_ => {
let spans = r
.span
.find_ancestor_inside(ty.span)
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())));

let spans = if !ty.span.from_expansion() {
r.span
.find_ancestor_inside(ty.span)
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
} else {
None
};
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false), false);
}
}
Expand Down
5 changes: 1 addition & 4 deletions library/core/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,10 @@ mod impls {
impl_clone! {
usize u8 u16 u32 u64 u128
isize i8 i16 i32 i64 i128
f32 f64
f16 f32 f64 f128
bool char
}

#[cfg(not(bootstrap))]
impl_clone! { f16 f128 }

#[unstable(feature = "never_type", issue = "35121")]
impl Clone for ! {
#[inline]
Expand Down
10 changes: 2 additions & 8 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,12 +1497,9 @@ mod impls {
}

partial_eq_impl! {
bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64
bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
}

#[cfg(not(bootstrap))]
partial_eq_impl! { f16 f128 }

macro_rules! eq_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1553,10 +1550,7 @@ mod impls {
}
}

partial_ord_impl! { f32 f64 }

#[cfg(not(bootstrap))]
partial_ord_impl! { f16 f128 }
partial_ord_impl! { f16 f32 f64 f128 }

macro_rules! ord_impl {
($($t:ty)*) => ($(
Expand Down
7 changes: 7 additions & 0 deletions library/core/src/convert/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ macro_rules! impl_float_to_int {
}
}

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

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

// float -> float
impl_from!(f16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);

macro_rules! impl_float_from_bool {
($float:ty) => {
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/fmt/nofloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ macro_rules! floating {
};
}

floating! { f16 }
floating! { f32 }
floating! { f64 }
floating! { f128 }
8 changes: 6 additions & 2 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@
//
// Language features:
// tidy-alphabetical-start
#![cfg_attr(not(bootstrap), feature(f128))]
#![cfg_attr(not(bootstrap), feature(f16))]
#![feature(abi_unadjusted)]
#![feature(adt_const_params)]
#![feature(allow_internal_unsafe)]
Expand All @@ -226,6 +224,8 @@
#![feature(doc_notable_trait)]
#![feature(effects)]
#![feature(extern_types)]
#![feature(f128)]
#![feature(f16)]
#![feature(freeze_impls)]
#![feature(fundamental)]
#![feature(generic_arg_infer)]
Expand Down Expand Up @@ -347,6 +347,10 @@ pub mod u8;
#[path = "num/shells/usize.rs"]
pub mod usize;

#[path = "num/f128.rs"]
pub mod f128;
#[path = "num/f16.rs"]
pub mod f16;
#[path = "num/f32.rs"]
pub mod f32;
#[path = "num/f64.rs"]
Expand Down
Loading
Loading