diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 9dab577d84bce..48a41c8bd245a 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1824,6 +1824,14 @@ impl Expr<'_> { _ => false, } } + + pub fn method_ident(&self) -> Option { + match self.kind { + ExprKind::MethodCall(receiver_method, ..) => Some(receiver_method.ident), + ExprKind::Unary(_, expr) | ExprKind::AddrOf(.., expr) => expr.method_ident(), + _ => None, + } + } } /// Checks if the specified expression is a built-in range literal. diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 7120d5ad93455..1e8b212276f2f 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -714,10 +714,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { } fn const_equate(&mut self, _a: Const<'tcx>, _b: Const<'tcx>) { - span_bug!( - self.cause.span(self.infcx.tcx), - "generic_const_exprs: unreachable `const_equate`" - ); + span_bug!(self.cause.span(), "generic_const_exprs: unreachable `const_equate`"); } fn normalization() -> NormalizationStrategy { diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 05556f7d0f956..4f59215c70b92 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1435,7 +1435,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { swap_secondary_and_primary: bool, force_label: bool, ) { - let span = cause.span(self.tcx); + let span = cause.span(); // For some types of errors, expected-found does not make // sense, so just ignore the values we were given. @@ -2085,7 +2085,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr); - let span = trace.cause.span(self.tcx); + let span = trace.cause.span(); let failure_code = trace.cause.as_failure_code(terr); let mut diag = match failure_code { FailureCode::Error0038(did) => { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index e2185d8613379..998699158ff48 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -204,7 +204,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { expected_substs: SubstsRef<'tcx>, actual_substs: SubstsRef<'tcx>, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - let span = cause.span(self.tcx()); + let span = cause.span(); let msg = format!( "implementation of `{}` is not general enough", self.tcx().def_path_str(trait_def_id), diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index 7e42458fda3d0..95b6c4ce1f296 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -18,20 +18,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { trait_item_def_id: DefId, requirement: &dyn fmt::Display, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - let msg = "impl has stricter requirements than trait"; - let sp = self.tcx.sess.source_map().guess_head_span(error_span); + let mut err = struct_span_err!( + self.tcx.sess, + error_span, + E0276, + "impl has stricter requirements than trait" + ); - let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg); - - if trait_item_def_id.is_local() { + if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) { let item_name = self.tcx.item_name(impl_item_def_id.to_def_id()); - err.span_label( - self.tcx.def_span(trait_item_def_id), - format!("definition of `{}` from trait", item_name), - ); + err.span_label(span, format!("definition of `{}` from trait", item_name)); } - err.span_label(sp, format!("impl has extra requirement {}", requirement)); + err.span_label(error_span, format!("impl has extra requirement {}", requirement)); err } @@ -48,7 +47,6 @@ pub fn report_object_safety_error<'tcx>( hir::Node::Item(item) => Some(item.ident.span), _ => None, }); - let span = tcx.sess.source_map().guess_head_span(span); let mut err = struct_span_err!( tcx.sess, span, diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 13e3bb9a36341..50e9383cacc12 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -694,9 +694,8 @@ pub trait LintContext: Sized { } if let Some(span) = in_test_module { - let def_span = self.sess().source_map().guess_head_span(span); db.span_help( - span.shrink_to_lo().to(def_span), + self.sess().source_map().guess_head_span(span), "consider adding a `#[cfg(test)]` to the containing module", ); } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 955f2bdfa1d91..d8cc7d3feb0d0 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -139,13 +139,8 @@ impl<'tcx> ObligationCause<'tcx> { ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() } } - pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span { + pub fn span(&self) -> Span { match *self.code() { - ObligationCauseCode::CompareImplMethodObligation { .. } - | ObligationCauseCode::MainFunctionType - | ObligationCauseCode::StartFunctionType => { - tcx.sess.source_map().guess_head_span(self.span) - } ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { arm_span, .. diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 4e73c26d35f2f..5b21c04664774 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1759,8 +1759,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { || self.tcx.resolutions(()).has_pub_restricted { let descr = descr.to_string(); - let vis_span = - self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id)); + let vis_span = self.tcx.def_span(def_id); if kind == "trait" { self.tcx.sess.emit_err(InPublicInterfaceTraits { span, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 0c271c047091f..d5e65c0b4420a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1435,6 +1435,8 @@ symbols! { thumb2, thumb_mode: "thumb-mode", tmm_reg, + to_string, + to_vec, todo_macro, tool_attributes, tool_lints, diff --git a/compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding.rs b/compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding.rs new file mode 100644 index 0000000000000..1b7161fbb85c5 --- /dev/null +++ b/compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding.rs @@ -0,0 +1,26 @@ +use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel, Target, TargetOptions}; + +const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_freestanding_linker_script.ld"); + +/// A base target for Nintendo Switch devices using a pure LLVM toolchain. +pub fn target() -> Target { + Target { + llvm_target: "aarch64-unknown-none".into(), + pointer_width: 64, + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), + options: TargetOptions { + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + linker: Some("rust-lld".into()), + link_script: Some(LINKER_SCRIPT.into()), + os: "horizon".into(), + max_atomic_width: Some(128), + panic_strategy: PanicStrategy::Abort, + position_independent_executables: true, + dynamic_linking: true, + executables: true, + relro_level: RelroLevel::Off, + ..Default::default() + }, + } +} diff --git a/compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding_linker_script.ld b/compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding_linker_script.ld new file mode 100644 index 0000000000000..f3441e6593782 --- /dev/null +++ b/compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding_linker_script.ld @@ -0,0 +1,78 @@ +OUTPUT_FORMAT(elf64-littleaarch64) +OUTPUT_ARCH(aarch64) +ENTRY(_start) + +PHDRS +{ + text PT_LOAD FLAGS(5); + rodata PT_LOAD FLAGS(4); + data PT_LOAD FLAGS(6); + bss PT_LOAD FLAGS(6); + dynamic PT_DYNAMIC; +} + +SECTIONS +{ + . = 0; + + .text : ALIGN(0x1000) { + HIDDEN(__text_start = .); + KEEP(*(.text.jmp)) + + . = 0x80; + + *(.text .text.*) + *(.plt .plt.*) + } + + /* Read-only sections */ + + . = ALIGN(0x1000); + + .module_name : { *(.module_name) } :rodata + + .rodata : { *(.rodata .rodata.*) } :rodata + .hash : { *(.hash) } + .dynsym : { *(.dynsym .dynsym.*) } + .dynstr : { *(.dynstr .dynstr.*) } + .rela.dyn : { *(.rela.dyn) } + + .eh_frame : { + HIDDEN(__eh_frame_start = .); + *(.eh_frame .eh_frame.*) + HIDDEN(__eh_frame_end = .); + } + + .eh_frame_hdr : { + HIDDEN(__eh_frame_hdr_start = .); + *(.eh_frame_hdr .eh_frame_hdr.*) + HIDDEN(__eh_frame_hdr_end = .); + } + + /* Read-write sections */ + + . = ALIGN(0x1000); + + .data : { + *(.data .data.*) + *(.got .got.*) + *(.got.plt .got.plt.*) + } :data + + .dynamic : { + HIDDEN(__dynamic_start = .); + *(.dynamic) + } + + /* BSS section */ + + . = ALIGN(0x1000); + + .bss : { + HIDDEN(__bss_start = .); + *(.bss .bss.*) + *(COMMON) + . = ALIGN(8); + HIDDEN(__bss_end = .); + } :bss +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index ef49fc8e968a8..1a6bb4a2eaf34 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1035,6 +1035,8 @@ supported_targets! { ("armv6k-nintendo-3ds", armv6k_nintendo_3ds), + ("aarch64-nintendo-switch-freestanding", aarch64_nintendo_switch_freestanding), + ("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi), ("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf), diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 02196a8f16d0b..39fce3cf76935 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -823,10 +823,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { let found_kind = self.closure_kind(closure_substs).unwrap(); - let closure_span = - self.tcx.sess.source_map().guess_head_span( - self.tcx.hir().span_if_local(closure_def_id).unwrap(), - ); + let closure_span = self.tcx.def_span(closure_def_id); let mut err = struct_span_err!( self.tcx.sess, closure_span, @@ -951,9 +948,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { _ => None, }; - let found_span = found_did - .and_then(|did| self.tcx.hir().span_if_local(did)) - .map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be an fn def + let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did)); if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) { // We check closures twice, with obligations flowing in different directions, @@ -1089,7 +1084,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }), .. }) => ( - sm.guess_head_span(fn_decl_span), + fn_decl_span, hir.body(body) .params .iter() diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index ff4ef92f42e71..57d5e5436a691 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1543,7 +1543,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ty::Generator(..) => "generator", _ => "function", }; - let span = self.tcx.sess.source_map().guess_head_span(span); let mut err = struct_span_err!( self.tcx.sess, span, diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 4aa62f8078d42..81f5dcc45b93e 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -603,7 +603,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { ), (Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => { span_bug!( - obligation.cause.span(self.selcx.tcx()), + obligation.cause.span(), "ConstEquate: const_eval_resolve returned an unexpected error" ) } diff --git a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs index db45ee3fed7db..32669e23db96b 100644 --- a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs +++ b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs @@ -84,7 +84,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { // Run canonical query. If overflow occurs, rerun from scratch but this time // in standard trait query mode so that overflow is handled appropriately // within `SelectionContext`. - self.tcx.at(obligation.cause.span(self.tcx)).evaluate_obligation(c_pred) + self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred) } // Helper function that canonicalizes and runs the query. If an diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 7c5673c863210..fa2d2c751d929 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -742,7 +742,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | (_, Err(ErrorHandled::Reported(_))) => Ok(EvaluatedToErr), (Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => { span_bug!( - obligation.cause.span(self.tcx()), + obligation.cause.span(), "ConstEquate: const_eval_resolve returned an unexpected error" ) } diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 699237446cf77..c3205aeb07477 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1958,11 +1958,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ); } - if adt_def.did().is_local() { - err.span_label( - tcx.def_span(adt_def.did()), - format!("variant `{assoc_ident}` not found for this enum"), - ); + if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) { + err.span_label(sp, format!("variant `{}` not found here", assoc_ident)); } err.emit() diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 79e402b542a60..7795e65132f50 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -1,6 +1,6 @@ use crate::check::coercion::{AsCoercionSite, CoerceMany}; use crate::check::{Diverges, Expectation, FnCtxt, Needs}; -use rustc_errors::{Applicability, Diagnostic, MultiSpan}; +use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::{self as hir, ExprKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::traits::Obligation; @@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &cause, Some(&arm.body), arm_ty, - Some(&mut |err: &mut Diagnostic| { + Some(&mut |err| { let Some(ret) = self.ret_type_span else { return; }; diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index dfcd35d2178e7..bd2e89a4dc541 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -375,8 +375,9 @@ fn check_alloc_error_fn( } } -fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) { +fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId) { let def = tcx.adt_def(def_id); + let span = tcx.def_span(def_id); def.destructor(tcx); // force the destructor to be evaluated check_representable(tcx, span, def_id); @@ -388,8 +389,9 @@ fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) { check_packed(tcx, span, def); } -fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) { +fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId) { let def = tcx.adt_def(def_id); + let span = tcx.def_span(def_id); def.destructor(tcx); // force the destructor to be evaluated check_representable(tcx, span, def_id); check_transparent(tcx, span, def); @@ -471,13 +473,14 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b } /// Check that a `static` is inhabited. -fn check_static_inhabited<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) { +fn check_static_inhabited<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) { // Make sure statics are inhabited. // Other parts of the compiler assume that there are no uninhabited places. In principle it // would be enough to check this for `extern` statics, as statics with an initializer will // have UB during initialization if they are uninhabited, but there also seems to be no good // reason to allow any statics to be uninhabited. let ty = tcx.type_of(def_id); + let span = tcx.def_span(def_id); let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) { Ok(l) => l, // Foreign statics that overflow their allowed size should emit an error @@ -524,9 +527,9 @@ pub(super) fn check_opaque<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, substs: SubstsRef<'tcx>, - span: Span, origin: &hir::OpaqueTyOrigin, ) { + let span = tcx.def_span(def_id); check_opaque_for_inheriting_lifetimes(tcx, def_id, span); if tcx.type_of(def_id).references_error() { return; @@ -785,8 +788,8 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) { match tcx.def_kind(id.def_id) { DefKind::Static(..) => { tcx.ensure().typeck(id.def_id); - maybe_check_static_with_link_section(tcx, id.def_id, tcx.def_span(id.def_id)); - check_static_inhabited(tcx, id.def_id, tcx.def_span(id.def_id)); + maybe_check_static_with_link_section(tcx, id.def_id); + check_static_inhabited(tcx, id.def_id); } DefKind::Const => { tcx.ensure().typeck(id.def_id); @@ -796,7 +799,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) { let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else { return; }; - check_enum(tcx, item.span, &enum_definition.variants, item.def_id); + check_enum(tcx, &enum_definition.variants, item.def_id); } DefKind::Fn => {} // entirely within check_item_body DefKind::Impl => { @@ -847,10 +850,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) { } } DefKind::Struct => { - check_struct(tcx, id.def_id, tcx.def_span(id.def_id)); + check_struct(tcx, id.def_id); } DefKind::Union => { - check_union(tcx, id.def_id, tcx.def_span(id.def_id)); + check_union(tcx, id.def_id); } DefKind::OpaqueTy => { let item = tcx.hir().item(id); @@ -863,7 +866,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) { // See https://github.com/rust-lang/rust/issues/75100 if !tcx.sess.opts.actually_rustdoc { let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id()); - check_opaque(tcx, item.def_id, substs, item.span, &origin); + check_opaque(tcx, item.def_id, substs, &origin); } } DefKind::TyAlias => { @@ -927,7 +930,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) { require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span); } hir::ForeignItemKind::Static(..) => { - check_static_inhabited(tcx, def_id, item.span); + check_static_inhabited(tcx, def_id); } _ => {} } @@ -1328,7 +1331,6 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD if !adt.repr().transparent() { return; } - let sp = tcx.sess.source_map().guess_head_span(sp); if adt.is_union() && !tcx.features().transparent_unions { feature_err( @@ -1442,13 +1444,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD } #[allow(trivial_numeric_casts)] -fn check_enum<'tcx>( - tcx: TyCtxt<'tcx>, - sp: Span, - vs: &'tcx [hir::Variant<'tcx>], - def_id: LocalDefId, -) { +fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, vs: &'tcx [hir::Variant<'tcx>], def_id: LocalDefId) { let def = tcx.adt_def(def_id); + let sp = tcx.def_span(def_id); def.destructor(tcx); // force the destructor to be evaluated if vs.is_empty() { diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 2bfb9343877a4..3a31df32298d7 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -171,14 +171,7 @@ fn compare_predicate_entailment<'tcx>( let trait_m_predicates = tcx.predicates_of(trait_m.def_id); // Check region bounds. - check_region_bounds_on_impl_item( - tcx, - impl_m_span, - impl_m, - trait_m, - &trait_m_generics, - &impl_m_generics, - )?; + check_region_bounds_on_impl_item(tcx, impl_m, trait_m, &trait_m_generics, &impl_m_generics)?; // Create obligations for each predicate declared by the impl // definition in the context of the trait's parameter @@ -298,7 +291,7 @@ fn compare_predicate_entailment<'tcx>( let mut diag = struct_span_err!( tcx.sess, - cause.span(tcx), + cause.span(), E0053, "method `{}` has an incompatible type for trait", trait_m.name @@ -410,7 +403,6 @@ fn compare_predicate_entailment<'tcx>( fn check_region_bounds_on_impl_item<'tcx>( tcx: TyCtxt<'tcx>, - span: Span, impl_m: &ty::AssocItem, trait_m: &ty::AssocItem, trait_generics: &ty::Generics, @@ -436,21 +428,25 @@ fn check_region_bounds_on_impl_item<'tcx>( // are zero. Since I don't quite know how to phrase things at // the moment, give a kind of vague error message. if trait_params != impl_params { - let item_kind = assoc_item_kind_str(impl_m); - let def_span = tcx.sess.source_map().guess_head_span(span); - let span = impl_m - .def_id - .as_local() - .and_then(|did| tcx.hir().get_generics(did)) - .map_or(def_span, |g| g.span); - let generics_span = trait_m.def_id.as_local().map(|did| { - let def_sp = tcx.def_span(did); - tcx.hir().get_generics(did).map_or(def_sp, |g| g.span) - }); + let span = tcx + .hir() + .get_generics(impl_m.def_id.expect_local()) + .expect("expected impl item to have generics or else we can't compare them") + .span; + let generics_span = if let Some(local_def_id) = trait_m.def_id.as_local() { + Some( + tcx.hir() + .get_generics(local_def_id) + .expect("expected trait item to have generics or else we can't compare them") + .span, + ) + } else { + None + }; let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait { span, - item_kind, + item_kind: assoc_item_kind_str(impl_m), ident: impl_m.ident(tcx), generics_span, }); @@ -490,7 +486,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( TypeError::ArgumentSorts(ExpectedFound { .. }, i) => { (impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i))) } - _ => (cause.span(tcx), tcx.hir().span_if_local(trait_m.def_id)), + _ => (cause.span(), tcx.hir().span_if_local(trait_m.def_id)), } } @@ -1199,7 +1195,6 @@ fn compare_type_predicate_entailment<'tcx>( check_region_bounds_on_impl_item( tcx, - impl_ty_span, impl_ty, trait_ty, &trait_ty_generics, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 863a981134f24..80feac184125c 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -18,8 +18,6 @@ use rustc_span::symbol::sym; use rustc_span::Span; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; -use std::iter; - impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut Diagnostic) { err.span_suggestion_short( @@ -183,59 +181,60 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else if let (ty::FnDef(def_id, ..), true) = (&found.kind(), self.suggest_fn_call(err, expr, expected, found)) { - if def_id.is_local() { - err.span_label(self.tcx.def_span(def_id), &format!("{} defined here", found)); + if let Some(sp) = self.tcx.hir().span_if_local(*def_id) { + err.span_label(sp, format!("{found} defined here")); } } else if !self.check_for_cast(err, expr, found, expected, expected_ty_expr) { - let is_struct_pat_shorthand_field = - self.maybe_get_struct_pattern_shorthand_field(expr).is_some(); let methods = self.get_conversion_methods(expr.span, expected, found, expr.hir_id); if !methods.is_empty() { - if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) { - let mut suggestions = iter::zip(iter::repeat(&expr_text), &methods) - .filter_map(|(receiver, method)| { - let method_call = format!(".{}()", method.name); - if receiver.ends_with(&method_call) { - None // do not suggest code that is already there (#53348) - } else { - let method_call_list = [".to_vec()", ".to_string()"]; - let mut sugg = if receiver.ends_with(".clone()") - && method_call_list.contains(&method_call.as_str()) - { - let max_len = receiver.rfind('.').unwrap(); - vec![( - expr.span, - format!("{}{}", &receiver[..max_len], method_call), - )] - } else { - if expr.precedence().order() - < ExprPrecedence::MethodCall.order() - { - vec![ - (expr.span.shrink_to_lo(), "(".to_string()), - (expr.span.shrink_to_hi(), format!("){}", method_call)), - ] - } else { - vec![(expr.span.shrink_to_hi(), method_call)] - } - }; - if is_struct_pat_shorthand_field { - sugg.insert( - 0, - (expr.span.shrink_to_lo(), format!("{}: ", receiver)), - ); - } - Some(sugg) - } - }) - .peekable(); - if suggestions.peek().is_some() { - err.multipart_suggestions( - "try using a conversion method", - suggestions, - Applicability::MaybeIncorrect, - ); - } + let mut suggestions = methods.iter() + .filter_map(|conversion_method| { + let receiver_method_ident = expr.method_ident(); + if let Some(method_ident) = receiver_method_ident + && method_ident.name == conversion_method.name + { + return None // do not suggest code that is already there (#53348) + } + + let method_call_list = [sym::to_vec, sym::to_string]; + let mut sugg = if let ExprKind::MethodCall(receiver_method, ..) = expr.kind + && receiver_method.ident.name == sym::clone + && method_call_list.contains(&conversion_method.name) + // If receiver is `.clone()` and found type has one of those methods, + // we guess that the user wants to convert from a slice type (`&[]` or `&str`) + // to an owned type (`Vec` or `String`). These conversions clone internally, + // so we remove the user's `clone` call. + { + vec![( + receiver_method.ident.span, + conversion_method.name.to_string() + )] + } else if expr.precedence().order() + < ExprPrecedence::MethodCall.order() + { + vec![ + (expr.span.shrink_to_lo(), "(".to_string()), + (expr.span.shrink_to_hi(), format!(").{}()", conversion_method.name)), + ] + } else { + vec![(expr.span.shrink_to_hi(), format!(".{}()", conversion_method.name))] + }; + let struct_pat_shorthand_field = self.maybe_get_struct_pattern_shorthand_field(expr); + if let Some(name) = struct_pat_shorthand_field { + sugg.insert( + 0, + (expr.span.shrink_to_lo(), format!("{}: ", name)), + ); + } + Some(sugg) + }) + .peekable(); + if suggestions.peek().is_some() { + err.multipart_suggestions( + "try using a conversion method", + suggestions, + Applicability::MaybeIncorrect, + ); } } else if let ty::Adt(found_adt, found_substs) = found.kind() && self.tcx.is_diagnostic_item(sym::Option, found_adt.did()) diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index dee58791cec18..d6160266dd7d9 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -534,7 +534,7 @@ fn fn_maybe_err(tcx: TyCtxt<'_>, sp: Span, abi: Abi) { } } -fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: Span) { +fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) { // Only restricted on wasm target for now if !tcx.sess.target.is_like_wasm { return; @@ -560,7 +560,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: S let msg = "statics with a custom `#[link_section]` must be a \ simple list of bytes on the wasm target with no \ extra levels of indirection such as references"; - tcx.sess.span_err(span, msg); + tcx.sess.span_err(tcx.def_span(id), msg); } } @@ -621,9 +621,8 @@ fn missing_items_err( // adding the associated item at the end of its body. let sugg_sp = full_impl_span.with_lo(hi).with_hi(hi); // Obtain the level of indentation ending in `sugg_sp`. - let indentation = tcx.sess.source_map().span_to_margin(sugg_sp).unwrap_or(0); - // Make the whitespace that will make the suggestion have the right indentation. - let padding: String = " ".repeat(indentation); + let padding = + tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new()); for trait_item in missing_items { let snippet = suggestion_signature(trait_item, tcx); diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 5621cf2e1a4b5..e205eba44571f 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -1838,7 +1838,7 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, mut span: Span, id: hir::HirI if let Some(hir::Generics { predicates, .. }) = hir_node.and_then(|node| node.generics()) { - let obligation_span = obligation.cause.span(fcx.tcx); + let obligation_span = obligation.cause.span(); span = predicates .iter() diff --git a/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs b/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs index db67c1f7c9ed3..03e076bf5ec89 100644 --- a/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs +++ b/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs @@ -76,17 +76,17 @@ impl<'tcx> InherentOverlapChecker<'tcx> { let name = item1.ident(self.tcx).normalize_to_macros_2_0(); let mut err = struct_span_err!( self.tcx.sess, - self.tcx.span_of_impl(item1.def_id).unwrap(), + self.tcx.def_span(item1.def_id), E0592, "duplicate definitions with name `{}`", name ); err.span_label( - self.tcx.span_of_impl(item1.def_id).unwrap(), + self.tcx.def_span(item1.def_id), format!("duplicate definitions for `{}`", name), ); err.span_label( - self.tcx.span_of_impl(item2.def_id).unwrap(), + self.tcx.def_span(item2.def_id), format!("other definition for `{}`", name), ); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 62dd9a6b36502..ea0f78e2a6be9 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -411,7 +411,7 @@ pub struct Target { impl Target { pub fn from_triple(triple: &str) -> Self { let mut target: Self = Default::default(); - if triple.contains("-none") || triple.contains("nvptx") { + if triple.contains("-none") || triple.contains("nvptx") || triple.contains("switch") { target.no_std = true; } target diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index c5d62a8810a8b..1895e2901489e 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -298,7 +298,8 @@ pub fn use_host_linker(target: TargetSelection) -> bool { || target.contains("nvptx") || target.contains("fortanix") || target.contains("fuchsia") - || target.contains("bpf")) + || target.contains("bpf") + || target.contains("switch")) } pub fn is_valid_test_suite_arg<'a, P: AsRef>( diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 87dc513853968..f6348b2bddc88 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -17,6 +17,7 @@ - [Template for Target-specific Documentation](platform-support/TEMPLATE.md) - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [\*-apple-watchos\*](platform-support/apple-watchos.md) + - [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md) - [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md) - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index eb985803266e7..7a03238f13dff 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -209,6 +209,7 @@ target | std | host | notes `aarch64-apple-tvos` | * | | ARM64 tvOS [`aarch64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | ARM64 Apple WatchOS Simulator [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 +[`aarch64-nintendo-switch-freestanding`](platform-support/aarch64-nintendo-switch-freestanding.md) | * | | ARM64 Nintendo Switch, Horizon [`aarch64-pc-windows-gnullvm`](platform-support/pc-windows-gnullvm.md) | ✓ | ✓ | `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD `aarch64-unknown-hermit` | ✓ | | ARM64 HermitCore diff --git a/src/doc/rustc/src/platform-support/aarch64-nintendo-switch-freestanding.md b/src/doc/rustc/src/platform-support/aarch64-nintendo-switch-freestanding.md new file mode 100644 index 0000000000000..308e1fe2f92a0 --- /dev/null +++ b/src/doc/rustc/src/platform-support/aarch64-nintendo-switch-freestanding.md @@ -0,0 +1,49 @@ +# aarch64-nintendo-switch-freestanding + +**Tier: 3** + +Nintendo Switch with pure-Rust toolchain. + +## Designated Developers + +* [@leo60228](https://github.com/leo60228) +* [@jam1garner](https://github.com/jam1garner) + +## Requirements + +This target is cross-compiled. +It has no special requirements for the host. + +## Building + +The target can be built by enabling it for a `rustc` build: + +```toml +[build] +build-stage = 1 +target = ["aarch64-nintendo-switch-freestanding"] +``` + +## Cross-compilation + +This target can be cross-compiled from any host. + +## Testing + +Currently there is no support to run the rustc test suite for this target. + +## Building Rust programs + +If `rustc` has support for that target and the library artifacts are available, +then Rust programs can be built for that target: + +```text +rustc --target aarch64-nintendo-switch-freestanding your-code.rs +``` + +To generate binaries in the NRO format that can be easily run on-device, you +can use [cargo-nx](https://github.com/aarch64-switch-rs/cargo-nx): + +```text +cargo nx --triple=aarch64-nintendo-switch-freestanding +``` diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 6658f07ce0103..2aef978a072d2 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -479,23 +479,20 @@ function loadCss(cssFileName) { } if (sidebar) { - const isModule = hasClass(document.body, "mod"); - if (!isModule) { - block("primitive", "primitives", "Primitive Types"); - block("mod", "modules", "Modules"); - block("macro", "macros", "Macros"); - block("struct", "structs", "Structs"); - block("enum", "enums", "Enums"); - block("union", "unions", "Unions"); - block("constant", "constants", "Constants"); - block("static", "static", "Statics"); - block("trait", "traits", "Traits"); - block("fn", "functions", "Functions"); - block("type", "types", "Type Definitions"); - block("foreigntype", "foreign-types", "Foreign Types"); - block("keyword", "keywords", "Keywords"); - block("traitalias", "trait-aliases", "Trait Aliases"); - } + block("primitive", "primitives", "Primitive Types"); + block("mod", "modules", "Modules"); + block("macro", "macros", "Macros"); + block("struct", "structs", "Structs"); + block("enum", "enums", "Enums"); + block("union", "unions", "Unions"); + block("constant", "constants", "Constants"); + block("static", "static", "Statics"); + block("trait", "traits", "Traits"); + block("fn", "functions", "Functions"); + block("type", "types", "Type Definitions"); + block("foreigntype", "foreign-types", "Foreign Types"); + block("keyword", "keywords", "Keywords"); + block("traitalias", "trait-aliases", "Trait Aliases"); } } diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index dfb3e4e6a2ccd..9a551b68279d6 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -39,7 +39,7 @@ {%- else if page.css_class == "source" -%} {#- -#} {#- -#} - {%- else -%} + {%- else if !page.css_class.contains("mod") -%} {#- -#} {%- endif -%} {#- -#} diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr index 2db5372da0c6e..803bb06fcc218 100644 --- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr +++ b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr @@ -1,13 +1,8 @@ error[E0732]: `#[repr(inttype)]` must be specified --> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1 | -LL | / enum Enum { -LL | | -LL | | Unit = 1, -LL | | Tuple() = 2, -LL | | Struct{} = 3, -LL | | } - | |_^ +LL | enum Enum { + | ^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/enum/enum-discrim-autosizing.stderr b/src/test/ui/enum/enum-discrim-autosizing.stderr index bcd362b0632a2..eacea86d67e55 100644 --- a/src/test/ui/enum/enum-discrim-autosizing.stderr +++ b/src/test/ui/enum/enum-discrim-autosizing.stderr @@ -1,16 +1,14 @@ error[E0081]: discriminant value `0` assigned more than once --> $DIR/enum-discrim-autosizing.rs:6:1 | -LL | / enum Eu64 { -LL | | -LL | | Au64 = 0, - | | - first assignment of `0` -LL | | -LL | | Bu64 = 0x8000_0000_0000_0000 - | | --------------------- second assignment of `0` (overflowed from `9223372036854775808`) -LL | | -LL | | } - | |_^ +LL | enum Eu64 { + | ^^^^^^^^^ +LL | +LL | Au64 = 0, + | - first assignment of `0` +LL | +LL | Bu64 = 0x8000_0000_0000_0000 + | --------------------- second assignment of `0` (overflowed from `9223372036854775808`) error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0081.stderr b/src/test/ui/error-codes/E0081.stderr index d7c7dbac7d647..ff6113646bb8a 100644 --- a/src/test/ui/error-codes/E0081.stderr +++ b/src/test/ui/error-codes/E0081.stderr @@ -1,48 +1,41 @@ error[E0081]: discriminant value `3` assigned more than once --> $DIR/E0081.rs:1:1 | -LL | / enum Enum { -LL | | -LL | | P = 3, - | | - first assignment of `3` -LL | | -LL | | X = 3, - | | - second assignment of `3` -LL | | -LL | | Y = 5 -LL | | } - | |_^ +LL | enum Enum { + | ^^^^^^^^^ +LL | +LL | P = 3, + | - first assignment of `3` +LL | +LL | X = 3, + | - second assignment of `3` error[E0081]: discriminant value `1` assigned more than once --> $DIR/E0081.rs:11:1 | -LL | / enum EnumOverflowRepr { -LL | | -LL | | P = 257, - | | --- first assignment of `1` (overflowed from `257`) -LL | | -LL | | X = 513, - | | --- second assignment of `1` (overflowed from `513`) -LL | | -LL | | } - | |_^ +LL | enum EnumOverflowRepr { + | ^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | P = 257, + | --- first assignment of `1` (overflowed from `257`) +LL | +LL | X = 513, + | --- second assignment of `1` (overflowed from `513`) error[E0081]: discriminant value `-1` assigned more than once --> $DIR/E0081.rs:20:1 | -LL | / enum NegDisEnum { -LL | | -LL | | First = -1, - | | -- first assignment of `-1` -LL | | -LL | | Second = -2, - | | ----------- assigned discriminant for `Last` was incremented from this discriminant -LL | | -LL | | Last, - | | ---- second assignment of `-1` -LL | | -LL | | } - | |_^ +LL | enum NegDisEnum { + | ^^^^^^^^^^^^^^^ +LL | +LL | First = -1, + | -- first assignment of `-1` +LL | +LL | Second = -2, + | ----------- assigned discriminant for `Last` was incremented from this discriminant +LL | +LL | Last, + | ---- second assignment of `-1` error: aborting due to 3 previous errors diff --git a/src/test/ui/error-codes/E0084.stderr b/src/test/ui/error-codes/E0084.stderr index 1f818da25bb0f..e1bda22b8d19a 100644 --- a/src/test/ui/error-codes/E0084.stderr +++ b/src/test/ui/error-codes/E0084.stderr @@ -4,7 +4,7 @@ error[E0084]: unsupported representation for zero-variant enum LL | #[repr(i32)] | ^^^^^^^^^^^^ LL | enum Foo {} - | ----------- zero-variant enum + | -------- zero-variant enum error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0658.stderr b/src/test/ui/error-codes/E0658.stderr index 4563b0e21940b..8d423484528a1 100644 --- a/src/test/ui/error-codes/E0658.stderr +++ b/src/test/ui/error-codes/E0658.stderr @@ -1,10 +1,8 @@ error[E0658]: repr with 128-bit type is unstable --> $DIR/E0658.rs:2:1 | -LL | / enum Foo { -LL | | Bar(u64), -LL | | } - | |_^ +LL | enum Foo { + | ^^^^^^^^ | = note: see issue #56071 for more information = help: add `#![feature(repr128)]` to the crate attributes to enable diff --git a/src/test/ui/extern/extern-static-size-overflow.stderr b/src/test/ui/extern/extern-static-size-overflow.stderr index f5173feec75d4..1c926399591c2 100644 --- a/src/test/ui/extern/extern-static-size-overflow.stderr +++ b/src/test/ui/extern/extern-static-size-overflow.stderr @@ -2,19 +2,19 @@ error: extern static is too large for the current architecture --> $DIR/extern-static-size-overflow.rs:38:5 | LL | static BAZ: [u8; max_size()]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: extern static is too large for the current architecture --> $DIR/extern-static-size-overflow.rs:39:5 | LL | static UWU: [usize; usize::MAX]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: extern static is too large for the current architecture --> $DIR/extern-static-size-overflow.rs:40:5 | LL | static A: ReallyBig; - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/feature-gates/feature-gate-repr128.stderr b/src/test/ui/feature-gates/feature-gate-repr128.stderr index 3eb005acc33b8..3999a6d2d2f89 100644 --- a/src/test/ui/feature-gates/feature-gate-repr128.stderr +++ b/src/test/ui/feature-gates/feature-gate-repr128.stderr @@ -1,10 +1,8 @@ error[E0658]: repr with 128-bit type is unstable --> $DIR/feature-gate-repr128.rs:2:1 | -LL | / enum A { -LL | | A(u64) -LL | | } - | |_^ +LL | enum A { + | ^^^^^^ | = note: see issue #56071 for more information = help: add `#![feature(repr128)]` to the crate attributes to enable diff --git a/src/test/ui/issues/issue-15524.stderr b/src/test/ui/issues/issue-15524.stderr index a0ea0c2459f7c..1195e0a346ddf 100644 --- a/src/test/ui/issues/issue-15524.stderr +++ b/src/test/ui/issues/issue-15524.stderr @@ -1,53 +1,39 @@ error[E0081]: discriminant value `1` assigned more than once --> $DIR/issue-15524.rs:3:1 | -LL | / enum Foo { -LL | | -LL | | -LL | | -LL | | A = 1, - | | - first assignment of `1` -LL | | B = 1, - | | - second assignment of `1` -... | -LL | | -LL | | } - | |_^ +LL | enum Foo { + | ^^^^^^^^ +... +LL | A = 1, + | - first assignment of `1` +LL | B = 1, + | - second assignment of `1` error[E0081]: discriminant value `1` assigned more than once --> $DIR/issue-15524.rs:3:1 | -LL | / enum Foo { -LL | | -LL | | -LL | | -LL | | A = 1, - | | - first assignment of `1` -LL | | B = 1, -LL | | C = 0, - | | ----- assigned discriminant for `D` was incremented from this discriminant -LL | | D, - | | - second assignment of `1` -... | -LL | | -LL | | } - | |_^ +LL | enum Foo { + | ^^^^^^^^ +... +LL | A = 1, + | - first assignment of `1` +LL | B = 1, +LL | C = 0, + | ----- assigned discriminant for `D` was incremented from this discriminant +LL | D, + | - second assignment of `1` error[E0081]: discriminant value `1` assigned more than once --> $DIR/issue-15524.rs:3:1 | -LL | / enum Foo { -LL | | -LL | | -LL | | -LL | | A = 1, - | | - first assignment of `1` -... | -LL | | E = N, - | | - second assignment of `1` -LL | | -LL | | } - | |_^ +LL | enum Foo { + | ^^^^^^^^ +... +LL | A = 1, + | - first assignment of `1` +... +LL | E = N, + | - second assignment of `1` error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-34209.stderr b/src/test/ui/issues/issue-34209.stderr index 8de0edef076c6..f9a25b69ff621 100644 --- a/src/test/ui/issues/issue-34209.stderr +++ b/src/test/ui/issues/issue-34209.stderr @@ -2,7 +2,7 @@ error[E0599]: no variant named `B` found for enum `S` --> $DIR/issue-34209.rs:7:12 | LL | enum S { - | ------ variant `B` not found for this enum + | ------ variant `B` not found here ... LL | S::B {} => {}, | ^ help: there is a variant with a similar name: `A` diff --git a/src/test/ui/repr/issue-83505-repr-simd.stderr b/src/test/ui/repr/issue-83505-repr-simd.stderr index f1390a652016b..df99baaf52293 100644 --- a/src/test/ui/repr/issue-83505-repr-simd.stderr +++ b/src/test/ui/repr/issue-83505-repr-simd.stderr @@ -22,7 +22,7 @@ LL | #[repr(simd)] | ^^^^^^^^^^^^^ ... LL | enum Es {} - | ---------- zero-variant enum + | ------- zero-variant enum error: aborting due to 3 previous errors diff --git a/src/test/ui/repr/repr-transparent.stderr b/src/test/ui/repr/repr-transparent.stderr index d85661f6faa84..f1c570b952356 100644 --- a/src/test/ui/repr/repr-transparent.stderr +++ b/src/test/ui/repr/repr-transparent.stderr @@ -34,7 +34,7 @@ error[E0084]: unsupported representation for zero-variant enum LL | #[repr(transparent)] | ^^^^^^^^^^^^^^^^^^^^ LL | enum Void {} - | ------------ zero-variant enum + | --------- zero-variant enum error[E0731]: transparent enum needs exactly one variant, but has 0 --> $DIR/repr-transparent.rs:45:1 diff --git a/src/test/ui/statics/uninhabited-static.stderr b/src/test/ui/statics/uninhabited-static.stderr index 10b86bb498694..88ee4cbdc2efc 100644 --- a/src/test/ui/statics/uninhabited-static.stderr +++ b/src/test/ui/statics/uninhabited-static.stderr @@ -2,7 +2,7 @@ error: static of uninhabited type --> $DIR/uninhabited-static.rs:6:5 | LL | static VOID: Void; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/uninhabited-static.rs:2:9 @@ -17,7 +17,7 @@ error: static of uninhabited type --> $DIR/uninhabited-static.rs:8:5 | LL | static NEVER: !; - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #74840 diff --git a/src/test/ui/suggestions/issue-52820.fixed b/src/test/ui/suggestions/issue-52820.fixed new file mode 100644 index 0000000000000..514690de4d045 --- /dev/null +++ b/src/test/ui/suggestions/issue-52820.fixed @@ -0,0 +1,15 @@ +// run-rustfix +#![allow(dead_code)] + +struct Bravery { + guts: String, + brains: String, +} + +fn main() { + let guts = "mettle"; + let _ = Bravery { + guts: guts.to_string(), //~ ERROR mismatched types + brains: guts.to_string(), //~ ERROR mismatched types + }; +} diff --git a/src/test/ui/suggestions/issue-52820.rs b/src/test/ui/suggestions/issue-52820.rs index 075b07f565203..17cd9224c57ec 100644 --- a/src/test/ui/suggestions/issue-52820.rs +++ b/src/test/ui/suggestions/issue-52820.rs @@ -1,3 +1,6 @@ +// run-rustfix +#![allow(dead_code)] + struct Bravery { guts: String, brains: String, diff --git a/src/test/ui/suggestions/issue-52820.stderr b/src/test/ui/suggestions/issue-52820.stderr index 7b46584450192..09269ed4eee99 100644 --- a/src/test/ui/suggestions/issue-52820.stderr +++ b/src/test/ui/suggestions/issue-52820.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-52820.rs:9:9 + --> $DIR/issue-52820.rs:12:9 | LL | guts, | ^^^^ expected struct `String`, found `&str` @@ -10,13 +10,13 @@ LL | guts: guts.to_string(), | +++++ ++++++++++++ error[E0308]: mismatched types - --> $DIR/issue-52820.rs:10:17 + --> $DIR/issue-52820.rs:13:17 | LL | brains: guts.clone(), - | ^^^^^^^^^^^^ - | | + | ^^^^^-----^^ + | | | + | | help: try using a conversion method: `to_string` | expected struct `String`, found `&str` - | help: try using a conversion method: `guts.to_string()` error: aborting due to 2 previous errors diff --git a/src/test/ui/suggestions/issue-53692.fixed b/src/test/ui/suggestions/issue-53692.fixed new file mode 100644 index 0000000000000..35a677b476186 --- /dev/null +++ b/src/test/ui/suggestions/issue-53692.fixed @@ -0,0 +1,20 @@ +// run-rustfix +#![allow(unused_variables)] + +fn main() { + let items = vec![1, 2, 3]; + let ref_items: &[i32] = &items; + let items_clone: Vec = ref_items.to_vec(); + //~^ ERROR mismatched types + + // in that case no suggestion will be triggered + let items_clone_2: Vec = items.clone(); + + let s = "hi"; + let string: String = s.to_string(); + //~^ ERROR mismatched types + + // in that case no suggestion will be triggered + let s2 = "hi"; + let string_2: String = s2.to_string(); +} diff --git a/src/test/ui/suggestions/issue-53692.rs b/src/test/ui/suggestions/issue-53692.rs index 30f344e428248..6f6707be5f651 100644 --- a/src/test/ui/suggestions/issue-53692.rs +++ b/src/test/ui/suggestions/issue-53692.rs @@ -1,17 +1,20 @@ +// run-rustfix +#![allow(unused_variables)] + fn main() { - let items = vec![1, 2, 3]; - let ref_items: &[i32] = &items; - let items_clone: Vec = ref_items.clone(); -//~^ ERROR mismatched types + let items = vec![1, 2, 3]; + let ref_items: &[i32] = &items; + let items_clone: Vec = ref_items.clone(); + //~^ ERROR mismatched types - // in that case no suggestion will be triggered - let items_clone_2:Vec = items.clone(); + // in that case no suggestion will be triggered + let items_clone_2: Vec = items.clone(); - let s = "hi"; - let string: String = s.clone(); -//~^ ERROR mismatched types + let s = "hi"; + let string: String = s.clone(); + //~^ ERROR mismatched types - // in that case no suggestion will be triggered - let s2 = "hi"; - let string_2: String = s2.to_string(); + // in that case no suggestion will be triggered + let s2 = "hi"; + let string_2: String = s2.to_string(); } diff --git a/src/test/ui/suggestions/issue-53692.stderr b/src/test/ui/suggestions/issue-53692.stderr index 09c78da54bcd0..3a1b624f402f0 100644 --- a/src/test/ui/suggestions/issue-53692.stderr +++ b/src/test/ui/suggestions/issue-53692.stderr @@ -1,25 +1,25 @@ error[E0308]: mismatched types - --> $DIR/issue-53692.rs:4:37 + --> $DIR/issue-53692.rs:7:33 | -LL | let items_clone: Vec = ref_items.clone(); - | -------- ^^^^^^^^^^^^^^^^^ - | | | - | | expected struct `Vec`, found `&[i32]` - | | help: try using a conversion method: `ref_items.to_vec()` - | expected due to this +LL | let items_clone: Vec = ref_items.clone(); + | -------- ^^^^^^^^^^-----^^ + | | | | + | | | help: try using a conversion method: `to_vec` + | | expected struct `Vec`, found `&[i32]` + | expected due to this | = note: expected struct `Vec` found reference `&[i32]` error[E0308]: mismatched types - --> $DIR/issue-53692.rs:11:30 + --> $DIR/issue-53692.rs:14:26 | -LL | let string: String = s.clone(); - | ------ ^^^^^^^^^ - | | | - | | expected struct `String`, found `&str` - | | help: try using a conversion method: `s.to_string()` - | expected due to this +LL | let string: String = s.clone(); + | ------ ^^-----^^ + | | | | + | | | help: try using a conversion method: `to_string` + | | expected struct `String`, found `&str` + | expected due to this error: aborting due to 2 previous errors diff --git a/src/test/ui/suggestions/suggest-variants.stderr b/src/test/ui/suggestions/suggest-variants.stderr index 0e2e41b85e2c6..a422bc6563541 100644 --- a/src/test/ui/suggestions/suggest-variants.stderr +++ b/src/test/ui/suggestions/suggest-variants.stderr @@ -2,7 +2,7 @@ error[E0599]: no variant named `Squareee` found for enum `Shape` --> $DIR/suggest-variants.rs:12:41 | LL | enum Shape { - | ---------- variant `Squareee` not found for this enum + | ---------- variant `Squareee` not found here ... LL | println!("My shape is {:?}", Shape::Squareee { size: 5}); | ^^^^^^^^ help: there is a variant with a similar name: `Square` @@ -11,7 +11,7 @@ error[E0599]: no variant named `Circl` found for enum `Shape` --> $DIR/suggest-variants.rs:13:41 | LL | enum Shape { - | ---------- variant `Circl` not found for this enum + | ---------- variant `Circl` not found here ... LL | println!("My shape is {:?}", Shape::Circl { size: 5}); | ^^^^^ help: there is a variant with a similar name: `Circle` @@ -20,7 +20,7 @@ error[E0599]: no variant named `Rombus` found for enum `Shape` --> $DIR/suggest-variants.rs:14:41 | LL | enum Shape { - | ---------- variant `Rombus` not found for this enum + | ---------- variant `Rombus` not found here ... LL | println!("My shape is {:?}", Shape::Rombus{ size: 5}); | ^^^^^^ variant not found in `Shape` diff --git a/src/test/ui/tag-variant-disr-dup.stderr b/src/test/ui/tag-variant-disr-dup.stderr index 27adb6998aede..6b1ba43d2ba6e 100644 --- a/src/test/ui/tag-variant-disr-dup.stderr +++ b/src/test/ui/tag-variant-disr-dup.stderr @@ -1,17 +1,13 @@ error[E0081]: discriminant value `0` assigned more than once --> $DIR/tag-variant-disr-dup.rs:3:1 | -LL | / enum Color { -LL | | -LL | | Red = 0xff0000, -LL | | Green = 0x00ff00, -LL | | Blue = 0x0000ff, -LL | | Black = 0x000000, - | | -------- first assignment of `0` -LL | | White = 0x000000, - | | -------- second assignment of `0` -LL | | } - | |_^ +LL | enum Color { + | ^^^^^^^^^^ +... +LL | Black = 0x000000, + | -------- first assignment of `0` +LL | White = 0x000000, + | -------- second assignment of `0` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr b/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr index 3f297d222dce7..6d141a58ef953 100644 --- a/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr +++ b/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr @@ -31,8 +31,12 @@ LL | trait Trait: Sized {} error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-unsafe-trait-obj-match.rs:25:25 | -LL | let t: &dyn Trait = match opt() { - | ^^^^^^^^^^^ `Trait` cannot be made into an object +LL | let t: &dyn Trait = match opt() { + | _________________________^ +LL | | Some(()) => &S, +LL | | None => &R, +LL | | }; + | |_____^ `Trait` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit --> $DIR/wf-unsafe-trait-obj-match.rs:6:14 diff --git a/src/tools/rls b/src/tools/rls index ece09b88c0365..fcf1f94c9ab2a 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit ece09b88c0365947af79c0ffdeea02bc6c1eec25 +Subproject commit fcf1f94c9ab2acc18cfd4368a4aeb38e77da9649