diff --git a/Cargo.lock b/Cargo.lock index d2b96e6d10270..07e023fbdb81a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,6 +229,21 @@ dependencies = [ "winnow 0.7.13", ] +[[package]] +name = "assert_cmd" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcbb6924530aa9e0432442af08bbcafdad182db80d2e560da42a6d442535bf85" +dependencies = [ + "anstyle", + "bstr", + "libc", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "autocfg" version = "1.5.0" @@ -1128,6 +1143,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + [[package]] name = "digest" version = "0.10.7" @@ -2949,6 +2970,33 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "predicates" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa" + +[[package]] +name = "predicates-tree" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "prettydiff" version = "0.7.0" @@ -3229,6 +3277,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "remote-test-client" version = "0.1.0" +dependencies = [ + "assert_cmd", +] [[package]] name = "remote-test-server" @@ -5425,6 +5476,12 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "termtree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" + [[package]] name = "test-float-parse" version = "0.1.0" @@ -6043,6 +6100,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + [[package]] name = "walkdir" version = "2.5.0" diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index 5f8933aa2beba..8d7351d3a510c 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -125,9 +125,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { } impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { - /// Because we want to track parent items and so forth, enable - /// deep walking so that we walk nested items in the context of - /// their outer items. + // Because we want to track parent items and so forth, enable + // deep walking so that we walk nested items in the context of + // their outer items. fn visit_nested_item(&mut self, item: ItemId) { debug!("visit_nested_item: {:?}", item); diff --git a/compiler/rustc_attr_parsing/src/validate_attr.rs b/compiler/rustc_attr_parsing/src/validate_attr.rs index 927417f89f8c0..4065fe7ce1735 100644 --- a/compiler/rustc_attr_parsing/src/validate_attr.rs +++ b/compiler/rustc_attr_parsing/src/validate_attr.rs @@ -209,7 +209,7 @@ pub fn check_attribute_safety( // - Normal builtin attribute // - Writing `#[unsafe(..)]` is not permitted on normal builtin attributes - (Some(AttributeSafety::Normal), Safety::Unsafe(unsafe_span)) => { + (None | Some(AttributeSafety::Normal), Safety::Unsafe(unsafe_span)) => { psess.dcx().emit_err(errors::InvalidAttrUnsafe { span: unsafe_span, name: attr_item.path.clone(), @@ -218,15 +218,10 @@ pub fn check_attribute_safety( // - Normal builtin attribute // - No explicit `#[unsafe(..)]` written. - (Some(AttributeSafety::Normal), Safety::Default) => { + (None | Some(AttributeSafety::Normal), Safety::Default) => { // OK } - // - Non-builtin attribute - (None, Safety::Unsafe(_) | Safety::Default) => { - // OK (not checked here) - } - ( Some(AttributeSafety::Unsafe { .. } | AttributeSafety::Normal) | None, Safety::Safe(..), diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index fe55262cffd45..c06e3c8b3c174 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -213,7 +213,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { AccessKind::Mutate => { err = self.cannot_assign(span, &(item_msg + &reason)); act = "assign"; - acted_on = "written"; + acted_on = "written to"; span } AccessKind::MutableBorrow => { @@ -518,8 +518,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { err.span_label( span, format!( - "`{name}` is a `{pointer_sigil}` {pointer_desc}, \ - so the data it refers to cannot be {acted_on}", + "`{name}` is a `{pointer_sigil}` {pointer_desc}, so it cannot be \ + {acted_on}", ), ); @@ -542,7 +542,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { self.expected_fn_found_fn_mut_call(&mut err, span, act); } - PlaceRef { local: _, projection: [.., ProjectionElem::Deref] } => { + PlaceRef { local, projection: [.., ProjectionElem::Deref] } => { err.span_label(span, format!("cannot {act}")); match opt_source { @@ -559,11 +559,36 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { )); self.suggest_map_index_mut_alternatives(ty, &mut err, span); } - _ => (), + _ => { + let local = &self.body.local_decls[local]; + match local.local_info() { + LocalInfo::StaticRef { def_id, .. } => { + let span = self.infcx.tcx.def_span(def_id); + err.span_label(span, format!("this `static` cannot be {acted_on}")); + } + LocalInfo::ConstRef { def_id } => { + let span = self.infcx.tcx.def_span(def_id); + err.span_label(span, format!("this `const` cannot be {acted_on}")); + } + LocalInfo::BlockTailTemp(_) | LocalInfo::Boring + if !local.source_info.span.overlaps(span) => + { + err.span_label( + local.source_info.span, + format!("this cannot be {acted_on}"), + ); + } + _ => {} + } + } } } - _ => { + PlaceRef { local, .. } => { + let local = &self.body.local_decls[local]; + if !local.source_info.span.overlaps(span) { + err.span_label(local.source_info.span, format!("this cannot be {acted_on}")); + } err.span_label(span, format!("cannot {act}")); } } diff --git a/compiler/rustc_data_structures/src/steal.rs b/compiler/rustc_data_structures/src/steal.rs index 0d79d98b5d966..afa9bc36f2c5e 100644 --- a/compiler/rustc_data_structures/src/steal.rs +++ b/compiler/rustc_data_structures/src/steal.rs @@ -1,5 +1,5 @@ use crate::stable_hasher::{HashStable, StableHasher}; -use crate::sync::{MappedReadGuard, ReadGuard, RwLock}; +use crate::sync::{MappedReadGuard, MappedWriteGuard, ReadGuard, RwLock, WriteGuard}; /// The `Steal` struct is intended to used as the value for a query. /// Specifically, we sometimes have queries (*cough* MIR *cough*) @@ -40,9 +40,17 @@ impl Steal { ReadGuard::map(borrow, |opt| opt.as_ref().unwrap()) } + /// An escape hatch for rustc drivers to mutate `Steal` caches. + /// + /// Use at your own risk. This can badly break incremental compilation + /// and anything else that relies on the immutability of query caches. #[track_caller] - pub fn get_mut(&mut self) -> &mut T { - self.value.get_mut().as_mut().expect("attempt to read from stolen value") + pub fn risky_hack_borrow_mut(&self) -> MappedWriteGuard<'_, T> { + let borrow = self.value.borrow_mut(); + if borrow.is_none() { + panic!("attempted to read from stolen value: {}", std::any::type_name::()); + } + WriteGuard::map(borrow, |opt| opt.as_mut().unwrap()) } #[track_caller] diff --git a/compiler/rustc_driver_impl/src/signal_handler.rs b/compiler/rustc_driver_impl/src/signal_handler.rs index e7bc57c9749b5..3d5df19bf67ee 100644 --- a/compiler/rustc_driver_impl/src/signal_handler.rs +++ b/compiler/rustc_driver_impl/src/signal_handler.rs @@ -152,7 +152,8 @@ pub(super) fn install() { libc::sigaltstack(&alt_stack, ptr::null_mut()); let mut sa: libc::sigaction = mem::zeroed(); - sa.sa_sigaction = print_stack_trace as libc::sighandler_t; + sa.sa_sigaction = + print_stack_trace as unsafe extern "C" fn(libc::c_int) as libc::sighandler_t; sa.sa_flags = libc::SA_NODEFER | libc::SA_RESETHAND | libc::SA_ONSTACK; libc::sigemptyset(&mut sa.sa_mask); for (signum, _signame) in KILL_SIGNALS { diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 81a7ee1ff45fe..e6fa1fa5ce50a 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2322,11 +2322,6 @@ impl HumanEmitter { show_code_change { for part in parts { - let snippet = if let Ok(snippet) = sm.span_to_snippet(part.span) { - snippet - } else { - String::new() - }; let span_start_pos = sm.lookup_char_pos(part.span.lo()).col_display; let span_end_pos = sm.lookup_char_pos(part.span.hi()).col_display; @@ -2402,7 +2397,7 @@ impl HumanEmitter { // LL - REMOVED <- row_num - 2 - (newlines - first_i - 1) // LL + NEWER // | <- row_num - + let snippet = sm.span_to_snippet(part.span).unwrap_or_default(); let newlines = snippet.lines().count(); if newlines > 0 && row_num > newlines { // Account for removals where the part being removed spans multiple diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 276490bc0c9d5..1dbf7b4726498 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -886,9 +886,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } } } else if let SyntaxExtensionKind::NonMacroAttr = ext { - if let ast::Safety::Unsafe(span) = attr.get_normal_item().unsafety { - self.cx.dcx().span_err(span, "unnecessary `unsafe` on safe attribute"); - } // `-Zmacro-stats` ignores these because they don't do any real expansion. self.cx.expanded_inert_attrs.mark(&attr); item.visit_attrs(|attrs| attrs.insert(pos, attr)); diff --git a/compiler/rustc_hir_analysis/src/variance/terms.rs b/compiler/rustc_hir_analysis/src/variance/terms.rs index cf38957bf24aa..9c7680b921205 100644 --- a/compiler/rustc_hir_analysis/src/variance/terms.rs +++ b/compiler/rustc_hir_analysis/src/variance/terms.rs @@ -44,7 +44,7 @@ impl<'a> fmt::Debug for VarianceTerm<'a> { } } -/// The first pass over the crate simply builds up the set of inferreds. +// The first pass over the crate simply builds up the set of inferreds. pub(crate) struct TermsContext<'a, 'tcx> { pub tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 8aa90c070acd3..c996181354b92 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -265,6 +265,9 @@ lint_forgetting_copy_types = calls to `std::mem::forget` with a value that imple lint_forgetting_references = calls to `std::mem::forget` with a reference instead of an owned value does nothing .label = argument has type `{$arg_ty}` +lint_function_casts_as_integer = direct cast of function item into an integer + .cast_as_fn = first cast to a pointer `as *const ()` + lint_hidden_glob_reexport = private item shadows public glob re-export .note_glob_reexport = the name `{$name}` in the {$namespace} namespace is supposed to be publicly re-exported here .note_private_item = but the private item here shadows it diff --git a/compiler/rustc_lint/src/function_cast_as_integer.rs b/compiler/rustc_lint/src/function_cast_as_integer.rs new file mode 100644 index 0000000000000..2a4ff1f63db52 --- /dev/null +++ b/compiler/rustc_lint/src/function_cast_as_integer.rs @@ -0,0 +1,63 @@ +use rustc_hir as hir; +use rustc_middle::ty; +use rustc_session::{declare_lint, declare_lint_pass}; +use rustc_span::BytePos; + +use crate::lints::{FunctionCastsAsIntegerDiag, FunctionCastsAsIntegerSugg}; +use crate::{LateContext, LateLintPass}; + +declare_lint! { + /// The `function_casts_as_integer` lint detects cases where a function item is cast + /// to an integer. + /// + /// ### Example + /// + /// ```rust + /// fn foo() {} + /// let x = foo as usize; + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// When casting a function item to an integer, it implicitly creates a + /// function pointer that will in turn be cast to an integer. By making + /// it explicit, it improves readability of the code and prevents bugs. + pub FUNCTION_CASTS_AS_INTEGER, + Warn, + "casting a function into an integer", +} + +declare_lint_pass!( + /// Lint for casts of functions into integers. + FunctionCastsAsInteger => [FUNCTION_CASTS_AS_INTEGER] +); + +impl<'tcx> LateLintPass<'tcx> for FunctionCastsAsInteger { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { + let hir::ExprKind::Cast(cast_from_expr, cast_to_expr) = expr.kind else { return }; + let cast_to_ty = cx.typeck_results().expr_ty(expr); + // Casting to a function (pointer?), so all good. + // + // Normally, only casts to integers is possible, but if it ever changed, this condition + // will likely need to be updated. + if matches!(cast_to_ty.kind(), ty::FnDef(..) | ty::FnPtr(..) | ty::RawPtr(..)) { + return; + } + let cast_from_ty = cx.typeck_results().expr_ty(cast_from_expr); + if matches!(cast_from_ty.kind(), ty::FnDef(..)) { + cx.tcx.emit_node_span_lint( + FUNCTION_CASTS_AS_INTEGER, + expr.hir_id, + cast_to_expr.span.with_lo(cast_from_expr.span.hi() + BytePos(1)), + FunctionCastsAsIntegerDiag { + sugg: FunctionCastsAsIntegerSugg { + suggestion: cast_from_expr.span.shrink_to_hi(), + cast_to_ty, + }, + }, + ); + } + } +} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 8a83434e10c15..7c3a81e891300 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -45,6 +45,7 @@ mod errors; mod expect; mod for_loops_over_fallibles; mod foreign_modules; +mod function_cast_as_integer; mod if_let_rescope; mod impl_trait_overcaptures; mod internal; @@ -89,6 +90,7 @@ use deref_into_dyn_supertrait::*; use drop_forget_useless::*; use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums; use for_loops_over_fallibles::*; +use function_cast_as_integer::*; use if_let_rescope::IfLetRescope; use impl_trait_overcaptures::ImplTraitOvercaptures; use internal::*; @@ -241,6 +243,7 @@ late_lint_methods!( IfLetRescope: IfLetRescope::default(), StaticMutRefs: StaticMutRefs, UnqualifiedLocalImports: UnqualifiedLocalImports, + FunctionCastsAsInteger: FunctionCastsAsInteger, CheckTransmutes: CheckTransmutes, LifetimeSyntax: LifetimeSyntax, ] diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index c55f2b9dd6f24..dc50f61f741d6 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3019,6 +3019,26 @@ pub(crate) struct ReservedMultihash { pub suggestion: Span, } +#[derive(LintDiagnostic)] +#[diag(lint_function_casts_as_integer)] +pub(crate) struct FunctionCastsAsIntegerDiag<'tcx> { + #[subdiagnostic] + pub(crate) sugg: FunctionCastsAsIntegerSugg<'tcx>, +} + +#[derive(Subdiagnostic)] +#[suggestion( + lint_cast_as_fn, + code = " as *const ()", + applicability = "machine-applicable", + style = "verbose" +)] +pub(crate) struct FunctionCastsAsIntegerSugg<'tcx> { + #[primary_span] + pub suggestion: Span, + pub cast_to_ty: Ty<'tcx>, +} + #[derive(Debug)] pub(crate) struct MismatchedLifetimeSyntaxes { pub inputs: LifetimeSyntaxCategories>, diff --git a/compiler/rustc_lint/src/passes.rs b/compiler/rustc_lint/src/passes.rs index 191eb721b3477..ae145543e70dc 100644 --- a/compiler/rustc_lint/src/passes.rs +++ b/compiler/rustc_lint/src/passes.rs @@ -55,10 +55,10 @@ macro_rules! late_lint_methods { /// Each `check` method checks a single syntax node, and should not /// invoke methods recursively (unlike `Visitor`). By default they /// do nothing. -// +/// // FIXME: eliminate the duplication with `Visitor`. But this also // contains a few lint-specific methods with no equivalent in `Visitor`. - +// macro_rules! declare_late_lint_pass { ([], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => ( pub trait LateLintPass<'tcx>: LintPass { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 7e762a8780787..899632b9d4b75 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -144,6 +144,7 @@ declare_lint_pass! { UNUSED_UNSAFE, UNUSED_VARIABLES, USELESS_DEPRECATED, + VARARGS_WITHOUT_PATTERN, WARNINGS, // tidy-alphabetical-end ] @@ -5295,3 +5296,50 @@ declare_lint! { report_in_deps: false, }; } + +declare_lint! { + /// The `varargs_without_pattern` lint detects when `...` is used as an argument to a + /// non-foreign function without any pattern being specified. + /// + /// ### Example + /// + /// ```rust + /// // Using `...` in non-foreign function definitions is unstable, however stability is + /// // currently only checked after attributes are expanded, so using `#[cfg(false)]` here will + /// // allow this to compile on stable Rust. + /// #[cfg(false)] + /// fn foo(...) { + /// + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Patterns are currently required for all non-`...` arguments in function definitions (with + /// some exceptions in the 2015 edition). Requiring `...` arguments to have patterns in + /// non-foreign function definitions makes the language more consistent, and removes a source of + /// confusion for the unstable C variadic feature. `...` arguments without a pattern are already + /// stable and widely used in foreign function definitions; this lint only affects non-foreign + /// function definitions. + /// + /// Using `...` (C varargs) in a non-foreign function definition is currently unstable. However, + /// stability checking for the `...` syntax in non-foreign function definitions is currently + /// implemented after attributes have been expanded, meaning that if the attribute removes the + /// use of the unstable syntax (e.g. `#[cfg(false)]`, or a procedural macro), the code will + /// compile on stable Rust; this is the only situation where this lint affects code that + /// compiles on stable Rust. + /// + /// This is a [future-incompatible] lint to transition this to a hard error in the future. + /// + /// [future-incompatible]: ../index.md#future-incompatible-lints + pub VARARGS_WITHOUT_PATTERN, + Warn, + "detects usage of `...` arguments without a pattern in non-foreign items", + @future_incompatible = FutureIncompatibleInfo { + reason: FutureIncompatibilityReason::FutureReleaseError, + reference: "issue #145544 ", + report_in_deps: false, + }; +} diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index 5764a9c84eeaf..6985cc7ddcfa1 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -16,7 +16,7 @@ use crate::ty::{self, ConstKind, GenericArgsRef, ScalarInt, Ty, TyCtxt}; /////////////////////////////////////////////////////////////////////////// /// Evaluated Constants - +/// /// Represents the result of const evaluation via the `eval_to_allocation` query. /// Not to be confused with `ConstAllocation`, which directly refers to the underlying data! /// Here we indirect via an `AllocId`. diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 1862900077f0f..c74333f5655ad 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -1004,6 +1004,9 @@ parse_use_if_else = use an `if-else` expression instead parse_use_let_not_auto = write `let` instead of `auto` to introduce a new variable parse_use_let_not_var = write `let` instead of `var` to introduce a new variable +parse_varargs_without_pattern = missing pattern for `...` argument + .suggestion = name the argument, or use `_` to continue ignoring it + parse_visibility_not_followed_by_item = visibility `{$vis}` is not followed by an item .label = the visibility .help = you likely meant to define an item, e.g., `{$vis} fn foo() {"{}"}` diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index a35c5c304d95e..bde179c9438f2 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3645,3 +3645,10 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub { } } } + +#[derive(LintDiagnostic)] +#[diag(parse_varargs_without_pattern)] +pub(crate) struct VarargsWithoutPattern { + #[suggestion(code = "_: ...", applicability = "machine-applicable")] + pub span: Span, +} diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 5725f4c366796..63109c7ba5cbf 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -201,7 +201,7 @@ impl<'a> Parser<'a> { AttrWrapper::empty(), true, false, - FnParseMode { req_name: |_| true, context: FnContext::Free, req_body: true }, + FnParseMode { req_name: |_, _| true, context: FnContext::Free, req_body: true }, ForceCollect::No, ) { Ok(Some(item)) => { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index ea7c3f0ec3340..bd495f6ec1acb 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -45,6 +45,7 @@ use crate::errors::{ }; use crate::parser::FnContext; use crate::parser::attr::InnerAttrPolicy; +use crate::parser::item::IsDotDotDot; use crate::{exp, fluent_generated as fluent}; /// Creates a placeholder argument. @@ -2284,7 +2285,7 @@ impl<'a> Parser<'a> { let maybe_emit_anon_params_note = |this: &mut Self, err: &mut Diag<'_>| { let ed = this.token.span.with_neighbor(this.prev_token.span).edition(); if matches!(fn_parse_mode.context, crate::parser::item::FnContext::Trait) - && (fn_parse_mode.req_name)(ed) + && (fn_parse_mode.req_name)(ed, IsDotDotDot::No) { err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)"); } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 599ec80e0a387..a4fadb029f5c9 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -12,6 +12,7 @@ use rustc_ast::{ use rustc_ast_pretty::pprust; use rustc_errors::codes::*; use rustc_errors::{Applicability, PResult, StashKey, struct_span_code_err}; +use rustc_session::lint::builtin::VARARGS_WITHOUT_PATTERN; use rustc_span::edit_distance::edit_distance; use rustc_span::edition::Edition; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, source_map, sym}; @@ -119,7 +120,7 @@ impl<'a> Parser<'a> { impl<'a> Parser<'a> { pub fn parse_item(&mut self, force_collect: ForceCollect) -> PResult<'a, Option>> { let fn_parse_mode = - FnParseMode { req_name: |_| true, context: FnContext::Free, req_body: true }; + FnParseMode { req_name: |_, _| true, context: FnContext::Free, req_body: true }; self.parse_item_(fn_parse_mode, force_collect).map(|i| i.map(Box::new)) } @@ -976,7 +977,7 @@ impl<'a> Parser<'a> { force_collect: ForceCollect, ) -> PResult<'a, Option>>> { let fn_parse_mode = - FnParseMode { req_name: |_| true, context: FnContext::Impl, req_body: true }; + FnParseMode { req_name: |_, _| true, context: FnContext::Impl, req_body: true }; self.parse_assoc_item(fn_parse_mode, force_collect) } @@ -985,7 +986,7 @@ impl<'a> Parser<'a> { force_collect: ForceCollect, ) -> PResult<'a, Option>>> { let fn_parse_mode = FnParseMode { - req_name: |edition| edition >= Edition::Edition2018, + req_name: |edition, _| edition >= Edition::Edition2018, context: FnContext::Trait, req_body: false, }; @@ -1245,8 +1246,11 @@ impl<'a> Parser<'a> { &mut self, force_collect: ForceCollect, ) -> PResult<'a, Option>>> { - let fn_parse_mode = - FnParseMode { req_name: |_| true, context: FnContext::Free, req_body: false }; + let fn_parse_mode = FnParseMode { + req_name: |_, is_dot_dot_dot| is_dot_dot_dot == IsDotDotDot::No, + context: FnContext::Free, + req_body: false, + }; Ok(self.parse_item_(fn_parse_mode, force_collect)?.map( |Item { attrs, id, span, vis, kind, tokens }| { let kind = match ForeignItemKind::try_from(kind) { @@ -2133,7 +2137,7 @@ impl<'a> Parser<'a> { Visibility { span: DUMMY_SP, kind: VisibilityKind::Inherited, tokens: None }; // We use `parse_fn` to get a span for the function let fn_parse_mode = - FnParseMode { req_name: |_| true, context: FnContext::Free, req_body: true }; + FnParseMode { req_name: |_, _| true, context: FnContext::Free, req_body: true }; match self.parse_fn( &mut AttrVec::new(), fn_parse_mode, @@ -2366,8 +2370,16 @@ impl<'a> Parser<'a> { /// The function decides if, per-parameter `p`, `p` must have a pattern or just a type. /// /// This function pointer accepts an edition, because in edition 2015, trait declarations -/// were allowed to omit parameter names. In 2018, they became required. -type ReqName = fn(Edition) -> bool; +/// were allowed to omit parameter names. In 2018, they became required. It also accepts an +/// `IsDotDotDot` parameter, as `extern` function declarations and function pointer types are +/// allowed to omit the name of the `...` but regular function items are not. +type ReqName = fn(Edition, IsDotDotDot) -> bool; + +#[derive(Copy, Clone, PartialEq)] +pub(crate) enum IsDotDotDot { + Yes, + No, +} /// Parsing configuration for functions. /// @@ -2400,6 +2412,9 @@ pub(crate) struct FnParseMode { /// to true. /// * The span is from Edition 2015. In particular, you can get a /// 2015 span inside a 2021 crate using macros. + /// + /// Or if `IsDotDotDot::Yes`, this function will also return `false` if the item being parsed + /// is inside an `extern` block. pub(super) req_name: ReqName, /// The context in which this function is parsed, used for diagnostics. /// This indicates the fn is a free function or method and so on. @@ -3049,11 +3064,25 @@ impl<'a> Parser<'a> { return Ok((res?, Trailing::No, UsePreAttrPos::No)); } - let is_name_required = match this.token.kind { - token::DotDotDot => false, - _ => (fn_parse_mode.req_name)( - this.token.span.with_neighbor(this.prev_token.span).edition(), - ), + let is_dot_dot_dot = if this.token.kind == token::DotDotDot { + IsDotDotDot::Yes + } else { + IsDotDotDot::No + }; + let is_name_required = (fn_parse_mode.req_name)( + this.token.span.with_neighbor(this.prev_token.span).edition(), + is_dot_dot_dot, + ); + let is_name_required = if is_name_required && is_dot_dot_dot == IsDotDotDot::Yes { + this.psess.buffer_lint( + VARARGS_WITHOUT_PATTERN, + this.token.span, + ast::CRATE_NODE_ID, + errors::VarargsWithoutPattern { span: this.token.span }, + ); + false + } else { + is_name_required }; let (pat, ty) = if is_name_required || this.is_named_param() { debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required); diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index f7757921cd426..437f6da67b74e 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -404,7 +404,7 @@ impl<'a> Parser<'a> { // Inside parenthesized type arguments, we want types only, not names. let mode = FnParseMode { context: FnContext::Free, - req_name: |_| false, + req_name: |_, _| false, req_body: false, }; let param = p.parse_param_general(&mode, false, false); diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index ad5ab6e6b7794..3fe8971f3d6c6 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -154,7 +154,7 @@ impl<'a> Parser<'a> { attrs.clone(), // FIXME: unwanted clone of attrs false, true, - FnParseMode { req_name: |_| true, context: FnContext::Free, req_body: true }, + FnParseMode { req_name: |_, _| true, context: FnContext::Free, req_body: true }, force_collect, )? { self.mk_stmt(lo.to(item.span), StmtKind::Item(Box::new(item))) diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index f08151c2f776f..df69adce142b8 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -824,7 +824,7 @@ impl<'a> Parser<'a> { self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?; } let mode = crate::parser::item::FnParseMode { - req_name: |_| false, + req_name: |_, _| false, context: FnContext::Free, req_body: false, }; @@ -1380,7 +1380,8 @@ impl<'a> Parser<'a> { self.bump(); let args_lo = self.token.span; let snapshot = self.create_snapshot_for_diagnostic(); - let mode = FnParseMode { req_name: |_| false, context: FnContext::Free, req_body: false }; + let mode = + FnParseMode { req_name: |_, _| false, context: FnContext::Free, req_body: false }; match self.parse_fn_decl(&mode, AllowPlus::No, RecoverReturnSign::OnlyFatArrow) { Ok(decl) => { self.dcx().emit_err(ExpectedFnPathFoundFnKeyword { fn_token_span }); @@ -1471,7 +1472,8 @@ impl<'a> Parser<'a> { // Parse `(T, U) -> R`. let inputs_lo = self.token.span; - let mode = FnParseMode { req_name: |_| false, context: FnContext::Free, req_body: false }; + let mode = + FnParseMode { req_name: |_, _| false, context: FnContext::Free, req_body: false }; let inputs: ThinVec<_> = self.parse_fn_params(&mode)?.into_iter().map(|input| input.ty).collect(); let inputs_span = inputs_lo.to(self.prev_token.span); diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index c668bf0733d14..b33ccbae0e690 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -219,7 +219,6 @@ passes_doc_test_unknown_passes = unknown `doc` attribute `{$path}` .note = `doc` attribute `{$path}` no longer functions; see issue #44136 .label = no longer functions - .help = you may want to use `doc(document_private_items)` .no_op_note = `doc({$path})` is now a no-op passes_doc_test_unknown_plugins = diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index f5023646b1917..ed4cf77d294fd 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -347,7 +347,6 @@ pub(crate) struct DocTestUnknownSpotlight { #[derive(LintDiagnostic)] #[diag(passes_doc_test_unknown_passes)] #[note] -#[help] #[note(passes_no_op_note)] pub(crate) struct DocTestUnknownPasses { pub path: String, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index ad3493d93e80a..0b4c52d68b6ff 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -3592,8 +3592,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { && (lt.kind == MissingLifetimeKind::Ampersand || lt.kind == MissingLifetimeKind::Underscore) { - let pre = if lt.kind == MissingLifetimeKind::Ampersand - && let Some((kind, _span)) = self.diag_metadata.current_function + let pre = if let Some((kind, _span)) = self.diag_metadata.current_function && let FnKind::Fn(_, _, ast::Fn { sig, .. }) = kind && !sig.decl.inputs.is_empty() && let sugg = sig @@ -3623,10 +3622,12 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { } else { ("one of the", "s") }; + let dotdotdot = + if lt.kind == MissingLifetimeKind::Ampersand { "..." } else { "" }; err.multipart_suggestion_verbose( format!( "instead, you are more likely to want to change {the} \ - argument{s} to be borrowed...", + argument{s} to be borrowed{dotdotdot}", ), sugg, Applicability::MaybeIncorrect, diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index f64fa86948c8d..12b294e124c8d 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -72,7 +72,7 @@ fn current_dll_path() -> Result { #[cfg(not(target_os = "aix"))] unsafe { - let addr = current_dll_path as usize as *mut _; + let addr = current_dll_path as fn() -> Result as *mut _; let mut info = std::mem::zeroed(); if libc::dladdr(addr, &mut info) == 0 { return Err("dladdr failed".into()); @@ -151,7 +151,10 @@ fn current_dll_path() -> Result { unsafe { GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, - PCWSTR(current_dll_path as *mut u16), + PCWSTR( + current_dll_path as fn() -> Result + as *mut u16, + ), &mut module, ) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index d0704f597c715..1d7de626f251b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -899,7 +899,6 @@ symbols! { doc_primitive, doc_spotlight, doctest, - document_private_items, dotdot: "..", dotdot_in_tuple_patterns, dotdoteq_in_patterns, diff --git a/compiler/rustc_target/src/spec/targets/armv6k_nintendo_3ds.rs b/compiler/rustc_target/src/spec/targets/armv6k_nintendo_3ds.rs index a79c642870126..37a8b1d878098 100644 --- a/compiler/rustc_target/src/spec/targets/armv6k_nintendo_3ds.rs +++ b/compiler/rustc_target/src/spec/targets/armv6k_nintendo_3ds.rs @@ -5,7 +5,6 @@ use crate::spec::{ /// A base target for Nintendo 3DS devices using the devkitARM toolchain. /// /// Requires the devkitARM toolchain for 3DS targets on the host system. - pub(crate) fn target() -> Target { let pre_link_args = TargetOptions::link_args( LinkerFlavor::Gnu(Cc::Yes, Lld::No), diff --git a/compiler/rustc_target/src/spec/targets/armv7_sony_vita_newlibeabihf.rs b/compiler/rustc_target/src/spec/targets/armv7_sony_vita_newlibeabihf.rs index 6c02ec26fea48..631b9770fac54 100644 --- a/compiler/rustc_target/src/spec/targets/armv7_sony_vita_newlibeabihf.rs +++ b/compiler/rustc_target/src/spec/targets/armv7_sony_vita_newlibeabihf.rs @@ -7,7 +7,6 @@ use crate::spec::{ /// A base target for PlayStation Vita devices using the VITASDK toolchain (using newlib). /// /// Requires the VITASDK toolchain on the host system. - pub(crate) fn target() -> Target { let pre_link_args = TargetOptions::link_args( LinkerFlavor::Gnu(Cc::Yes, Lld::No), diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs index e225656af852c..da888acc47559 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs @@ -864,6 +864,42 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } + if sub.kind() == ty::ReStatic + && let Some(node) = self.tcx.hir_get_if_local(generic_param_scope.into()) + && let hir::Node::Item(hir::Item { + kind: hir::ItemKind::Fn { sig, body, has_body: true, .. }, + .. + }) + | hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::Fn(sig, body), .. + }) = node + && let hir::Node::Expr(expr) = self.tcx.hir_node(body.hir_id) + && let hir::ExprKind::Block(block, _) = expr.kind + && let Some(tail) = block.expr + && tail.span == span + && let hir::FnRetTy::Return(ty) = sig.decl.output + && let hir::TyKind::Path(path) = ty.kind + && let hir::QPath::Resolved(None, path) = path + && let hir::def::Res::Def(_, def_id) = path.res + && Some(def_id) == self.tcx.lang_items().owned_box() + && let [segment] = path.segments + && let Some(args) = segment.args + && let [hir::GenericArg::Type(ty)] = args.args + && let hir::TyKind::TraitObject(_, tagged_ref) = ty.kind + && let hir::LifetimeKind::ImplicitObjectLifetimeDefault = tagged_ref.pointer().kind + { + // Explicitly look for `-> Box` to point at it as the *likely* source of + // the `'static` lifetime requirement. + err.span_label( + ty.span, + format!("this `dyn Trait` has an implicit `'static` lifetime bound"), + ); + } + err } diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 4f6a425a09839..6b13b4c4f56cc 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -622,7 +622,7 @@ pub const fn forget(_: T); /// // Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer. /// // This avoids an integer-to-pointer `transmute`, which can be problematic. /// // Transmuting between raw pointers and function pointers (i.e., two pointer types) is fine. -/// let pointer = foo as *const (); +/// let pointer = foo as fn() -> i32 as *const (); /// let function = unsafe { /// std::mem::transmute::<*const (), fn() -> i32>(pointer) /// }; diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 7d395eb780346..8c69af5704235 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -992,10 +992,10 @@ macro_rules! int_impl { /// /// ``` /// #![feature(exact_div)] - #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_exact_div(-1), Some(", stringify!($Max), "));")] - #[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_exact_div(2), None);")] - #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_exact_div(-1), None);")] - #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_exact_div(0), None);")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_div_exact(-1), Some(", stringify!($Max), "));")] + #[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_div_exact(2), None);")] + #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_div_exact(-1), None);")] + #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div_exact(0), None);")] /// ``` #[unstable( feature = "exact_div", @@ -1004,7 +1004,7 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const fn checked_exact_div(self, rhs: Self) -> Option { + pub const fn checked_div_exact(self, rhs: Self) -> Option { if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) { None } else { @@ -1034,18 +1034,18 @@ macro_rules! int_impl { /// /// ``` /// #![feature(exact_div)] - #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), Some(32));")] - #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(32), Some(2));")] - #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).exact_div(-1), Some(", stringify!($Max), "));")] - #[doc = concat!("assert_eq!(65", stringify!($SelfT), ".exact_div(2), None);")] + #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(2), Some(32));")] + #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(32), Some(2));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).div_exact(-1), Some(", stringify!($Max), "));")] + #[doc = concat!("assert_eq!(65", stringify!($SelfT), ".div_exact(2), None);")] /// ``` /// ```should_panic /// #![feature(exact_div)] - #[doc = concat!("let _ = 64", stringify!($SelfT),".exact_div(0);")] + #[doc = concat!("let _ = 64", stringify!($SelfT),".div_exact(0);")] /// ``` /// ```should_panic /// #![feature(exact_div)] - #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.exact_div(-1);")] + #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.div_exact(-1);")] /// ``` #[unstable( feature = "exact_div", @@ -1055,7 +1055,7 @@ macro_rules! int_impl { without modifying the original"] #[inline] #[rustc_inherit_overflow_checks] - pub const fn exact_div(self, rhs: Self) -> Option { + pub const fn div_exact(self, rhs: Self) -> Option { if self % rhs != 0 { None } else { @@ -1069,7 +1069,7 @@ macro_rules! int_impl { /// /// This results in undefined behavior when `rhs == 0`, `self % rhs != 0`, or #[doc = concat!("`self == ", stringify!($SelfT), "::MIN && rhs == -1`,")] - /// i.e. when [`checked_exact_div`](Self::checked_exact_div) would return `None`. + /// i.e. when [`checked_div_exact`](Self::checked_div_exact) would return `None`. #[unstable( feature = "exact_div", issue = "139911", @@ -1077,10 +1077,10 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const unsafe fn unchecked_exact_div(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_div_exact(self, rhs: Self) -> Self { assert_unsafe_precondition!( check_language_ub, - concat!(stringify!($SelfT), "::unchecked_exact_div cannot overflow, divide by zero, or leave a remainder"), + concat!(stringify!($SelfT), "::unchecked_div_exact cannot overflow, divide by zero, or leave a remainder"), ( lhs: $SelfT = self, rhs: $SelfT = rhs, @@ -1431,17 +1431,17 @@ macro_rules! int_impl { /// ``` /// #![feature(exact_bitshifts)] /// - #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(4), Some(0x10));")] - #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 2), Some(1 << ", stringify!($SelfT), "::BITS - 2));")] - #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 1), None);")] - #[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 2), Some(-0x2 << ", stringify!($SelfT), "::BITS - 2));")] - #[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 1), None);")] + #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(4), Some(0x10));")] + #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(", stringify!($SelfT), "::BITS - 2), Some(1 << ", stringify!($SelfT), "::BITS - 2));")] + #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(", stringify!($SelfT), "::BITS - 1), None);")] + #[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").shl_exact(", stringify!($SelfT), "::BITS - 2), Some(-0x2 << ", stringify!($SelfT), "::BITS - 2));")] + #[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").shl_exact(", stringify!($SelfT), "::BITS - 1), None);")] /// ``` #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> { + pub const fn shl_exact(self, rhs: u32) -> Option<$SelfT> { if rhs < self.leading_zeros() || rhs < self.leading_ones() { // SAFETY: rhs is checked above Some(unsafe { self.unchecked_shl(rhs) }) @@ -1458,16 +1458,16 @@ macro_rules! int_impl { /// /// This results in undefined behavior when `rhs >= self.leading_zeros() && rhs >= /// self.leading_ones()` i.e. when - #[doc = concat!("[`", stringify!($SelfT), "::exact_shl`]")] + #[doc = concat!("[`", stringify!($SelfT), "::shl_exact`]")] /// would return `None`. #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT { + pub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> $SelfT { assert_unsafe_precondition!( check_library_ub, - concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out bits that would change the value of the first bit"), + concat!(stringify!($SelfT), "::unchecked_shl_exact cannot shift out bits that would change the value of the first bit"), ( zeros: u32 = self.leading_zeros(), ones: u32 = self.leading_ones(), @@ -1611,14 +1611,14 @@ macro_rules! int_impl { /// ``` /// #![feature(exact_bitshifts)] /// - #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(4), Some(0x1));")] - #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(5), None);")] + #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(4), Some(0x1));")] + #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(5), None);")] /// ``` #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> { + pub const fn shr_exact(self, rhs: u32) -> Option<$SelfT> { if rhs <= self.trailing_zeros() && rhs < <$SelfT>::BITS { // SAFETY: rhs is checked above Some(unsafe { self.unchecked_shr(rhs) }) @@ -1636,16 +1636,16 @@ macro_rules! int_impl { /// This results in undefined behavior when `rhs > self.trailing_zeros() || rhs >= #[doc = concat!(stringify!($SelfT), "::BITS`")] /// i.e. when - #[doc = concat!("[`", stringify!($SelfT), "::exact_shr`]")] + #[doc = concat!("[`", stringify!($SelfT), "::shr_exact`]")] /// would return `None`. #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT { + pub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> $SelfT { assert_unsafe_precondition!( check_library_ub, - concat!(stringify!($SelfT), "::unchecked_exact_shr cannot shift out non-zero bits"), + concat!(stringify!($SelfT), "::unchecked_shr_exact cannot shift out non-zero bits"), ( zeros: u32 = self.trailing_zeros(), bits: u32 = <$SelfT>::BITS, diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 2996e7b00da4e..ea14972354755 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1222,10 +1222,10 @@ macro_rules! uint_impl { /// /// ``` /// #![feature(exact_div)] - #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(2), Some(32));")] - #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(32), Some(2));")] - #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(0), None);")] - #[doc = concat!("assert_eq!(65", stringify!($SelfT), ".checked_exact_div(2), None);")] + #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(2), Some(32));")] + #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(32), Some(2));")] + #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(0), None);")] + #[doc = concat!("assert_eq!(65", stringify!($SelfT), ".checked_div_exact(2), None);")] /// ``` #[unstable( feature = "exact_div", @@ -1234,7 +1234,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const fn checked_exact_div(self, rhs: Self) -> Option { + pub const fn checked_div_exact(self, rhs: Self) -> Option { if intrinsics::unlikely(rhs == 0) { None } else { @@ -1259,9 +1259,9 @@ macro_rules! uint_impl { /// /// ``` /// #![feature(exact_div)] - #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), Some(32));")] - #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(32), Some(2));")] - #[doc = concat!("assert_eq!(65", stringify!($SelfT), ".exact_div(2), None);")] + #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(2), Some(32));")] + #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(32), Some(2));")] + #[doc = concat!("assert_eq!(65", stringify!($SelfT), ".div_exact(2), None);")] /// ``` #[unstable( feature = "exact_div", @@ -1271,7 +1271,7 @@ macro_rules! uint_impl { without modifying the original"] #[inline] #[rustc_inherit_overflow_checks] - pub const fn exact_div(self, rhs: Self) -> Option { + pub const fn div_exact(self, rhs: Self) -> Option { if self % rhs != 0 { None } else { @@ -1284,7 +1284,7 @@ macro_rules! uint_impl { /// # Safety /// /// This results in undefined behavior when `rhs == 0` or `self % rhs != 0`, - /// i.e. when [`checked_exact_div`](Self::checked_exact_div) would return `None`. + /// i.e. when [`checked_div_exact`](Self::checked_div_exact) would return `None`. #[unstable( feature = "exact_div", issue = "139911", @@ -1292,10 +1292,10 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const unsafe fn unchecked_exact_div(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_div_exact(self, rhs: Self) -> Self { assert_unsafe_precondition!( check_language_ub, - concat!(stringify!($SelfT), "::unchecked_exact_div divide by zero or leave a remainder"), + concat!(stringify!($SelfT), "::unchecked_div_exact divide by zero or leave a remainder"), ( lhs: $SelfT = self, rhs: $SelfT = rhs, @@ -1830,14 +1830,14 @@ macro_rules! uint_impl { /// ``` /// #![feature(exact_bitshifts)] /// - #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(4), Some(0x10));")] - #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(129), None);")] + #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(4), Some(0x10));")] + #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(129), None);")] /// ``` #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> { + pub const fn shl_exact(self, rhs: u32) -> Option<$SelfT> { if rhs <= self.leading_zeros() && rhs < <$SelfT>::BITS { // SAFETY: rhs is checked above Some(unsafe { self.unchecked_shl(rhs) }) @@ -1855,16 +1855,16 @@ macro_rules! uint_impl { /// This results in undefined behavior when `rhs > self.leading_zeros() || rhs >= #[doc = concat!(stringify!($SelfT), "::BITS`")] /// i.e. when - #[doc = concat!("[`", stringify!($SelfT), "::exact_shl`]")] + #[doc = concat!("[`", stringify!($SelfT), "::shl_exact`]")] /// would return `None`. #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT { + pub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> $SelfT { assert_unsafe_precondition!( check_library_ub, - concat!(stringify!($SelfT), "::exact_shl_unchecked cannot shift out non-zero bits"), + concat!(stringify!($SelfT), "::unchecked_shl_exact cannot shift out non-zero bits"), ( zeros: u32 = self.leading_zeros(), bits: u32 = <$SelfT>::BITS, @@ -2002,14 +2002,14 @@ macro_rules! uint_impl { /// ``` /// #![feature(exact_bitshifts)] /// - #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(4), Some(0x1));")] - #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(5), None);")] + #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(4), Some(0x1));")] + #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(5), None);")] /// ``` #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> { + pub const fn shr_exact(self, rhs: u32) -> Option<$SelfT> { if rhs <= self.trailing_zeros() && rhs < <$SelfT>::BITS { // SAFETY: rhs is checked above Some(unsafe { self.unchecked_shr(rhs) }) @@ -2027,16 +2027,16 @@ macro_rules! uint_impl { /// This results in undefined behavior when `rhs > self.trailing_zeros() || rhs >= #[doc = concat!(stringify!($SelfT), "::BITS`")] /// i.e. when - #[doc = concat!("[`", stringify!($SelfT), "::exact_shr`]")] + #[doc = concat!("[`", stringify!($SelfT), "::shr_exact`]")] /// would return `None`. #[unstable(feature = "exact_bitshifts", issue = "144336")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT { + pub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> $SelfT { assert_unsafe_precondition!( check_library_ub, - concat!(stringify!($SelfT), "::exact_shr_unchecked cannot shift out non-zero bits"), + concat!(stringify!($SelfT), "::unchecked_shr_exact cannot shift out non-zero bits"), ( zeros: u32 = self.trailing_zeros(), bits: u32 = <$SelfT>::BITS, diff --git a/library/coretests/tests/num/int_macros.rs b/library/coretests/tests/num/int_macros.rs index e640b7853bd94..37336f49ef1b6 100644 --- a/library/coretests/tests/num/int_macros.rs +++ b/library/coretests/tests/num/int_macros.rs @@ -724,42 +724,42 @@ macro_rules! int_module { } } - const EXACT_DIV_SUCCESS_DIVIDEND1: $T = 42; - const EXACT_DIV_SUCCESS_DIVISOR1: $T = 6; - const EXACT_DIV_SUCCESS_QUOTIENT1: $T = 7; - const EXACT_DIV_SUCCESS_DIVIDEND2: $T = 18; - const EXACT_DIV_SUCCESS_DIVISOR2: $T = 3; - const EXACT_DIV_SUCCESS_QUOTIENT2: $T = 6; - const EXACT_DIV_SUCCESS_DIVIDEND3: $T = -91; - const EXACT_DIV_SUCCESS_DIVISOR3: $T = 13; - const EXACT_DIV_SUCCESS_QUOTIENT3: $T = -7; - const EXACT_DIV_SUCCESS_DIVIDEND4: $T = -57; - const EXACT_DIV_SUCCESS_DIVISOR4: $T = -3; - const EXACT_DIV_SUCCESS_QUOTIENT4: $T = 19; + const DIV_EXACT_SUCCESS_DIVIDEND1: $T = 42; + const DIV_EXACT_SUCCESS_DIVISOR1: $T = 6; + const DIV_EXACT_SUCCESS_QUOTIENT1: $T = 7; + const DIV_EXACT_SUCCESS_DIVIDEND2: $T = 18; + const DIV_EXACT_SUCCESS_DIVISOR2: $T = 3; + const DIV_EXACT_SUCCESS_QUOTIENT2: $T = 6; + const DIV_EXACT_SUCCESS_DIVIDEND3: $T = -91; + const DIV_EXACT_SUCCESS_DIVISOR3: $T = 13; + const DIV_EXACT_SUCCESS_QUOTIENT3: $T = -7; + const DIV_EXACT_SUCCESS_DIVIDEND4: $T = -57; + const DIV_EXACT_SUCCESS_DIVISOR4: $T = -3; + const DIV_EXACT_SUCCESS_QUOTIENT4: $T = 19; test_runtime_and_compiletime! { - fn test_exact_div() { + fn test_div_exact() { // 42 / 6 - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1)); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1)); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1)); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1)); // 18 / 3 - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2)); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2)); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2)); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2)); // -91 / 13 - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND3, EXACT_DIV_SUCCESS_DIVISOR3), Some(EXACT_DIV_SUCCESS_QUOTIENT3)); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND3, EXACT_DIV_SUCCESS_DIVISOR3), Some(EXACT_DIV_SUCCESS_QUOTIENT3)); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND3, DIV_EXACT_SUCCESS_DIVISOR3), Some(DIV_EXACT_SUCCESS_QUOTIENT3)); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND3, DIV_EXACT_SUCCESS_DIVISOR3), Some(DIV_EXACT_SUCCESS_QUOTIENT3)); // -57 / -3 - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND4, EXACT_DIV_SUCCESS_DIVISOR4), Some(EXACT_DIV_SUCCESS_QUOTIENT4)); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND4, EXACT_DIV_SUCCESS_DIVISOR4), Some(EXACT_DIV_SUCCESS_QUOTIENT4)); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND4, DIV_EXACT_SUCCESS_DIVISOR4), Some(DIV_EXACT_SUCCESS_QUOTIENT4)); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND4, DIV_EXACT_SUCCESS_DIVISOR4), Some(DIV_EXACT_SUCCESS_QUOTIENT4)); // failures - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(1, 2), None); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(1, 2), None); - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(<$T>::MIN, -1), None); - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(0, 0), None); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(1, 2), None); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(1, 2), None); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(<$T>::MIN, -1), None); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(0, 0), None); } } }; diff --git a/library/coretests/tests/num/uint_macros.rs b/library/coretests/tests/num/uint_macros.rs index c1cfc448f14f5..b89a371efcc25 100644 --- a/library/coretests/tests/num/uint_macros.rs +++ b/library/coretests/tests/num/uint_macros.rs @@ -595,27 +595,27 @@ macro_rules! uint_module { } } - const EXACT_DIV_SUCCESS_DIVIDEND1: $T = 42; - const EXACT_DIV_SUCCESS_DIVISOR1: $T = 6; - const EXACT_DIV_SUCCESS_QUOTIENT1: $T = 7; - const EXACT_DIV_SUCCESS_DIVIDEND2: $T = 18; - const EXACT_DIV_SUCCESS_DIVISOR2: $T = 3; - const EXACT_DIV_SUCCESS_QUOTIENT2: $T = 6; + const DIV_EXACT_SUCCESS_DIVIDEND1: $T = 42; + const DIV_EXACT_SUCCESS_DIVISOR1: $T = 6; + const DIV_EXACT_SUCCESS_QUOTIENT1: $T = 7; + const DIV_EXACT_SUCCESS_DIVIDEND2: $T = 18; + const DIV_EXACT_SUCCESS_DIVISOR2: $T = 3; + const DIV_EXACT_SUCCESS_QUOTIENT2: $T = 6; test_runtime_and_compiletime! { - fn test_exact_div() { + fn test_div_exact() { // 42 / 6 - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1)); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1)); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1)); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1)); // 18 / 3 - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2)); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2)); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2)); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2)); // failures - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(1, 2), None); - assert_eq_const_safe!(Option<$T>: <$T>::exact_div(1, 2), None); - assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(0, 0), None); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(1, 2), None); + assert_eq_const_safe!(Option<$T>: <$T>::div_exact(1, 2), None); + assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(0, 0), None); } } }; diff --git a/library/coretests/tests/ptr.rs b/library/coretests/tests/ptr.rs index 4d5138d539b95..555a3b01f1fcb 100644 --- a/library/coretests/tests/ptr.rs +++ b/library/coretests/tests/ptr.rs @@ -565,6 +565,7 @@ fn ptr_metadata() { #[test] fn ptr_metadata_bounds() { + #[allow(unknown_lints, function_casts_as_integer)] fn metadata_eq_method_address() -> usize { // The `Metadata` associated type has an `Ord` bound, so this is valid: <::Metadata as PartialEq>::eq as usize diff --git a/library/panic_unwind/src/seh.rs b/library/panic_unwind/src/seh.rs index a5d67dbb6a9f4..257916c4d5cdc 100644 --- a/library/panic_unwind/src/seh.rs +++ b/library/panic_unwind/src/seh.rs @@ -336,6 +336,7 @@ unsafe fn throw_exception(data: Option>) -> ! { // In any case, we basically need to do something like this until we can // express more operations in statics (and we may never be able to). unsafe { + #[allow(function_casts_as_integer)] atomic_store::<_, { AtomicOrdering::SeqCst }>( (&raw mut THROW_INFO.pmfnUnwind).cast(), ptr_t::new(exception_cleanup as *mut u8).raw(), @@ -352,6 +353,7 @@ unsafe fn throw_exception(data: Option>) -> ! { (&raw mut CATCHABLE_TYPE.pType).cast(), ptr_t::new((&raw mut TYPE_DESCRIPTOR).cast()).raw(), ); + #[allow(function_casts_as_integer)] atomic_store::<_, { AtomicOrdering::SeqCst }>( (&raw mut CATCHABLE_TYPE.copyFunction).cast(), ptr_t::new(exception_copy as *mut u8).raw(), diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index c3fcb0e2e42b0..99724e29e02b2 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -293,7 +293,7 @@ impl Backtrace { if !Backtrace::enabled() { return Backtrace { inner: Inner::Disabled }; } - Backtrace::create(Backtrace::capture as usize) + Backtrace::create(Backtrace::capture as fn() -> Backtrace as usize) } /// Forcibly captures a full backtrace, regardless of environment variable @@ -309,7 +309,7 @@ impl Backtrace { #[stable(feature = "backtrace", since = "1.65.0")] #[inline(never)] // want to make sure there's a frame here to remove pub fn force_capture() -> Backtrace { - Backtrace::create(Backtrace::force_capture as usize) + Backtrace::create(Backtrace::force_capture as fn() -> Backtrace as usize) } /// Forcibly captures a disabled backtrace, regardless of environment diff --git a/library/std/src/sys/pal/unix/stack_overflow.rs b/library/std/src/sys/pal/unix/stack_overflow.rs index 062f031189fc4..226b6bce01b58 100644 --- a/library/std/src/sys/pal/unix/stack_overflow.rs +++ b/library/std/src/sys/pal/unix/stack_overflow.rs @@ -174,7 +174,9 @@ mod imp { } action.sa_flags = SA_SIGINFO | SA_ONSTACK; - action.sa_sigaction = signal_handler as sighandler_t; + action.sa_sigaction = signal_handler + as unsafe extern "C" fn(i32, *mut libc::siginfo_t, *mut libc::c_void) + as sighandler_t; // SAFETY: only overriding signals if the default is set unsafe { sigaction(signal, &action, ptr::null_mut()) }; } diff --git a/library/std/src/sys/pal/windows/compat.rs b/library/std/src/sys/pal/windows/compat.rs index 14f2c8d881cf1..c465ceb2301ce 100644 --- a/library/std/src/sys/pal/windows/compat.rs +++ b/library/std/src/sys/pal/windows/compat.rs @@ -155,7 +155,7 @@ macro_rules! compat_fn_with_fallback { /// When that is called it attempts to load the requested symbol. /// If it succeeds, `PTR` is set to the address of that symbol. /// If it fails, then `PTR` is set to `fallback`. - static PTR: Atomic<*mut c_void> = AtomicPtr::new(load as *mut _); + static PTR: Atomic<*mut c_void> = AtomicPtr::new(load as unsafe extern "system" fn($($argname: $argtype),*) -> $rettype as *mut _); unsafe extern "system" fn load($($argname: $argtype),*) -> $rettype { unsafe { @@ -171,7 +171,7 @@ macro_rules! compat_fn_with_fallback { PTR.store(f.as_ptr(), Ordering::Relaxed); mem::transmute(f) } else { - PTR.store(fallback as *mut _, Ordering::Relaxed); + PTR.store(fallback as unsafe extern "system" fn($($argname: $argtype),*) -> $rettype as *mut _, Ordering::Relaxed); fallback } } diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md index 12e09cb07dbb2..dcf2221b8bfc2 100644 --- a/src/bootstrap/README.md +++ b/src/bootstrap/README.md @@ -28,14 +28,14 @@ compiler. What actually happens when you invoke bootstrap is: `x.py` cross-platform) is run. This script is responsible for downloading the stage0 compiler/Cargo binaries, and it then compiles the build system itself (this folder). Finally, it then invokes the actual `bootstrap` binary build system. -2. In Rust, `bootstrap` will slurp up all configuration, perform a number of - sanity checks (whether compilers exist, for example), and then start building the - stage0 artifacts. -3. The stage0 `cargo`, downloaded earlier, is used to build the standard library - and the compiler, and then these binaries are then copied to the `stage1` - directory. That compiler is then used to generate the stage1 artifacts which - are then copied to the stage2 directory, and then finally, the stage2 - artifacts are generated using that compiler. +2. In Rust, the bootstrap binary reads all configuration, performs a number of sanity + checks (for example, verifying toolchains and paths), and then prepares to build the + stage 1 compiler and libraries using the prebuilt stage 0 compiler. +3. The stage 0 compiler and standard library, downloaded earlier, are used to build the + stage 1 compiler, which links against the stage 0 standard library. The newly built stage 1 + compiler is then used to build the stage 1 standard library. After that, the stage 1 + compiler is used once more to produce the stage 2 compiler, which links against the + stage 1 standard library. The goal of each stage is to (a) leverage Cargo as much as possible and failing that (b) leverage Rust as much as possible! @@ -167,7 +167,6 @@ build/ # no extra build output in these directories. stage1/ stage2/ - stage3/ ``` ## Extending bootstrap @@ -177,8 +176,9 @@ When you use bootstrap, you'll call it through the entry point script `bootstrap` has a difficult problem: it is written in Rust, but yet it is run before the Rust compiler is built! To work around this, there are two components of bootstrap: the main one written in rust, and `bootstrap.py`. `bootstrap.py` -is what gets run by entry point script. It takes care of downloading the `stage0` -compiler, which will then build the bootstrap binary written in Rust. +is what gets run by entry point script. It takes care of downloading the prebuilt +stage 0 compiler, std and Cargo binaries, which are then used to build the +bootstrap binary. Because there are two separate codebases behind `x.py`, they need to be kept in sync. In particular, both `bootstrap.py` and the bootstrap binary diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index b3f4672bd6d15..d3df8ce057cc3 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -2075,7 +2075,9 @@ Please disable assertions with `rust.debug-assertions = false`. cmd.arg("--target-rustcflags").arg(flag); } - cmd.arg("--python").arg(builder.python()); + cmd.arg("--python").arg( + builder.config.python.as_ref().expect("python is required for running rustdoc tests"), + ); // FIXME(#148099): Currently we set these Android-related flags in all // modes, even though they should only be needed in "debuginfo" mode, @@ -3359,7 +3361,9 @@ impl Step for BootstrapPy { } fn run(self, builder: &Builder<'_>) -> Self::Output { - let mut check_bootstrap = command(builder.python()); + let mut check_bootstrap = command( + builder.config.python.as_ref().expect("python is required for running bootstrap tests"), + ); check_bootstrap .args(["-m", "unittest", "bootstrap_test.py"]) // Forward command-line args after `--` to unittest, for filtering etc. @@ -3986,3 +3990,40 @@ impl Step for CollectLicenseMetadata { dest } } + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RemoteTestClientTests { + host: TargetSelection, +} + +impl Step for RemoteTestClientTests { + type Output = (); + const IS_HOST: bool = true; + const DEFAULT: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.path("src/tools/remote-test-client") + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(Self { host: run.target }); + } + + fn run(self, builder: &Builder<'_>) { + let bootstrap_host = builder.config.host_target; + let compiler = builder.compiler(0, bootstrap_host); + + let cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolBootstrap, + bootstrap_host, + Kind::Test, + "src/tools/remote-test-client", + SourceType::InTree, + &[], + ); + + run_cargo_test(cargo, &[], &[], "remote-test-client", bootstrap_host, builder); + } +} diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 43faf92fe6d9b..6d2040eca6d50 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -891,6 +891,7 @@ impl<'a> Builder<'a> { test::CrateRustdoc, test::CrateRustdocJsonTypes, test::CrateBootstrap, + test::RemoteTestClientTests, test::Linkcheck, test::TierCheck, test::Cargotest, diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index ed63b2aae452c..e5afb31213ce8 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -1,9 +1,10 @@ -//! Sanity checking performed by bootstrap before actually executing anything. +//! Sanity checking and tool selection performed by bootstrap. //! -//! This module contains the implementation of ensuring that the build -//! environment looks reasonable before progressing. This will verify that -//! various programs like git and python exist, along with ensuring that all C -//! compilers for cross-compiling are found. +//! This module ensures that the build environment is correctly set up before +//! executing any build tasks. It verifies required programs exist (like git and +//! cmake when needed), selects some tools based on the environment (like the +//! Python interpreter), and validates that C compilers for cross-compiling are +//! available. //! //! In theory if we get past this phase it's a bug if a build fails, but in //! practice that's likely not true! diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index d646e3badb415..093db739e6cb2 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1522,21 +1522,6 @@ impl Build { self.config.target_config.get(&target).and_then(|t| t.qemu_rootfs.as_ref()).map(|p| &**p) } - /// Path to the python interpreter to use - fn python(&self) -> &Path { - if self.config.host_target.ends_with("apple-darwin") { - // Force /usr/bin/python3 on macOS for LLDB tests because we're loading the - // LLDB plugin's compiled module which only works with the system python - // (namely not Homebrew-installed python) - Path::new("/usr/bin/python3") - } else { - self.config - .python - .as_ref() - .expect("python is required for running LLDB or rustdoc tests") - } - } - /// Temporary directory that extended error information is emitted to. fn extended_error_dir(&self) -> PathBuf { self.out.join("tmp/extended-error-metadata") diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 921f57eb66d6e..59140b9ce84c8 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -576,4 +576,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "`llvm.enzyme` now works with `download-ci-llvm=true`.", }, + ChangeInfo { + change_id: 148636, + severity: ChangeSeverity::Info, + summary: "The `build.python` option is now respected on macOS (previously ignored and forced to be /usr/bin/python3).", + }, ]; diff --git a/src/doc/rustc-dev-guide/src/tests/running.md b/src/doc/rustc-dev-guide/src/tests/running.md index 0a99c847cce7e..5851a554e8a36 100644 --- a/src/doc/rustc-dev-guide/src/tests/running.md +++ b/src/doc/rustc-dev-guide/src/tests/running.md @@ -319,6 +319,10 @@ Tests are built on the machine running `x` not on the remote machine. Tests which fail to build unexpectedly (or `ui` tests producing incorrect build output) may fail without ever running on the remote machine. +There is a default timeout of 30 minutes in case the `remote-test-server` +cannot be reached by the `x` command. This timeout can be modified by using the +`TEST_DEVICE_TIMEOUT_SECONDS` environment variable. + ## Testing on emulators Some platforms are tested via an emulator for architectures that aren't readily diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 451d0b4f5be91..475e6f172957d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -416,14 +416,6 @@ pub(crate) fn run_global_ctxt( ); } - // Process all of the crate attributes, extracting plugin metadata along - // with the passes which we are supposed to run. - for attr in krate.module.attrs.lists(sym::doc) { - if attr.is_word() && attr.has_name(sym::document_private_items) { - ctxt.render_options.document_private = true; - } - } - info!("Executing passes"); let mut visited = FxHashMap::default(); diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 909262d563e9f..edafc9e7a089f 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -4,6 +4,7 @@ use rustc_abi::ExternAbi; use rustc_ast::ast; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::thin_vec::ThinVec; use rustc_hir as hir; use rustc_hir::attrs::{self, DeprecatedSince}; @@ -988,3 +989,55 @@ fn format_integer_type(it: rustc_abi::IntegerType) -> String { } .to_owned() } + +pub(super) fn target(sess: &rustc_session::Session) -> Target { + // Build a set of which features are enabled on this target + let globally_enabled_features: FxHashSet<&str> = + sess.unstable_target_features.iter().map(|name| name.as_str()).collect(); + + // Build a map of target feature stability by feature name + use rustc_target::target_features::Stability; + let feature_stability: FxHashMap<&str, Stability> = sess + .target + .rust_target_features() + .iter() + .copied() + .map(|(name, stability, _)| (name, stability)) + .collect(); + + Target { + triple: sess.opts.target_triple.tuple().into(), + target_features: sess + .target + .rust_target_features() + .iter() + .copied() + .filter(|(_, stability, _)| { + // Describe only target features which the user can toggle + stability.toggle_allowed().is_ok() + }) + .map(|(name, stability, implied_features)| { + TargetFeature { + name: name.into(), + unstable_feature_gate: match stability { + Stability::Unstable(feature_gate) => Some(feature_gate.as_str().into()), + _ => None, + }, + implies_features: implied_features + .iter() + .copied() + .filter(|name| { + // Imply only target features which the user can toggle + feature_stability + .get(name) + .map(|stability| stability.toggle_allowed().is_ok()) + .unwrap_or(false) + }) + .map(String::from) + .collect(), + globally_enabled: globally_enabled_features.contains(name), + } + }) + .collect(), + } +} diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index b724d7e866a05..b020e3d924a46 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -14,7 +14,6 @@ use std::io::{BufWriter, Write, stdout}; use std::path::PathBuf; use std::rc::Rc; -use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::{DefId, DefIdSet}; use rustc_middle::ty::TyCtxt; use rustc_session::Session; @@ -123,58 +122,6 @@ impl<'tcx> JsonRenderer<'tcx> { } } -fn target(sess: &rustc_session::Session) -> types::Target { - // Build a set of which features are enabled on this target - let globally_enabled_features: FxHashSet<&str> = - sess.unstable_target_features.iter().map(|name| name.as_str()).collect(); - - // Build a map of target feature stability by feature name - use rustc_target::target_features::Stability; - let feature_stability: FxHashMap<&str, Stability> = sess - .target - .rust_target_features() - .iter() - .copied() - .map(|(name, stability, _)| (name, stability)) - .collect(); - - types::Target { - triple: sess.opts.target_triple.tuple().into(), - target_features: sess - .target - .rust_target_features() - .iter() - .copied() - .filter(|(_, stability, _)| { - // Describe only target features which the user can toggle - stability.toggle_allowed().is_ok() - }) - .map(|(name, stability, implied_features)| { - types::TargetFeature { - name: name.into(), - unstable_feature_gate: match stability { - Stability::Unstable(feature_gate) => Some(feature_gate.as_str().into()), - _ => None, - }, - implies_features: implied_features - .iter() - .copied() - .filter(|name| { - // Imply only target features which the user can toggle - feature_stability - .get(name) - .map(|stability| stability.toggle_allowed().is_ok()) - .unwrap_or(false) - }) - .map(String::from) - .collect(), - globally_enabled: globally_enabled_features.contains(name), - } - }) - .collect(), - } -} - impl<'tcx> JsonRenderer<'tcx> { pub(crate) fn init( krate: clean::Crate, @@ -317,7 +264,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { // multiple targets: https://github.com/rust-lang/rust/pull/137632 // // We want to describe a single target, so pass tcx.sess rather than tcx. - let target = target(self.tcx.sess); + let target = conversions::target(self.tcx.sess); debug!("Constructing Output"); let output_crate = types::Crate { diff --git a/src/tools/clippy/tests/ui/cast_enum_constructor.rs b/src/tools/clippy/tests/ui/cast_enum_constructor.rs index eecf56f71a334..6d70387b6ce29 100644 --- a/src/tools/clippy/tests/ui/cast_enum_constructor.rs +++ b/src/tools/clippy/tests/ui/cast_enum_constructor.rs @@ -1,5 +1,5 @@ #![warn(clippy::cast_enum_constructor)] -#![allow(clippy::fn_to_numeric_cast)] +#![allow(clippy::fn_to_numeric_cast, function_casts_as_integer)] fn main() { enum Foo { diff --git a/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.fixed b/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.fixed index e698b99edd5c0..b9691a3284ac0 100644 --- a/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.fixed +++ b/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.fixed @@ -1,5 +1,6 @@ #![feature(float_minimum_maximum)] #![warn(clippy::confusing_method_to_numeric_cast)] +#![allow(function_casts_as_integer)] fn main() { let _ = u16::MAX as usize; //~ confusing_method_to_numeric_cast diff --git a/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.rs b/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.rs index ef65c21563d98..b402cbf92cb2b 100644 --- a/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.rs +++ b/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.rs @@ -1,5 +1,6 @@ #![feature(float_minimum_maximum)] #![warn(clippy::confusing_method_to_numeric_cast)] +#![allow(function_casts_as_integer)] fn main() { let _ = u16::max as usize; //~ confusing_method_to_numeric_cast diff --git a/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.stderr b/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.stderr index ba90df2059af6..0d5e08f880773 100644 --- a/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.stderr +++ b/src/tools/clippy/tests/ui/confusing_method_to_numeric_cast.stderr @@ -1,5 +1,5 @@ error: casting function pointer `u16::max` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:5:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:6:13 | LL | let _ = u16::max as usize; | ^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _ = u16::MAX as usize; | error: casting function pointer `u16::min` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:6:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:7:13 | LL | let _ = u16::min as usize; | ^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = u16::MIN as usize; | error: casting function pointer `u16::max_value` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:7:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:8:13 | LL | let _ = u16::max_value as usize; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + let _ = u16::MAX as usize; | error: casting function pointer `u16::min_value` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:8:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:9:13 | LL | let _ = u16::min_value as usize; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let _ = u16::MIN as usize; | error: casting function pointer `f32::maximum` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:10:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:11:13 | LL | let _ = f32::maximum as usize; | ^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _ = f32::MAX as usize; | error: casting function pointer `f32::max` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:11:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:12:13 | LL | let _ = f32::max as usize; | ^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _ = f32::MAX as usize; | error: casting function pointer `f32::minimum` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:12:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:13:13 | LL | let _ = f32::minimum as usize; | ^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _ = f32::MIN as usize; | error: casting function pointer `f32::min` to `usize` - --> tests/ui/confusing_method_to_numeric_cast.rs:13:13 + --> tests/ui/confusing_method_to_numeric_cast.rs:14:13 | LL | let _ = f32::min as usize; | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/derive.rs b/src/tools/clippy/tests/ui/derive.rs index 6b60421c35490..036f6c444b649 100644 --- a/src/tools/clippy/tests/ui/derive.rs +++ b/src/tools/clippy/tests/ui/derive.rs @@ -9,7 +9,6 @@ #![expect(incomplete_features)] // `unsafe_fields` is incomplete for the time being #![feature(unsafe_fields)] // `clone()` cannot be derived automatically on unsafe fields - #[derive(Copy)] struct Qux; diff --git a/src/tools/clippy/tests/ui/derive.stderr b/src/tools/clippy/tests/ui/derive.stderr index 2b97a58e9d6f6..2701680e788de 100644 --- a/src/tools/clippy/tests/ui/derive.stderr +++ b/src/tools/clippy/tests/ui/derive.stderr @@ -1,5 +1,5 @@ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:16:1 + --> tests/ui/derive.rs:15:1 | LL | / impl Clone for Qux { LL | | @@ -14,7 +14,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]` error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:42:1 + --> tests/ui/derive.rs:41:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | @@ -27,7 +27,7 @@ LL | | } = help: consider deriving `Clone` or removing `Copy` error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:55:1 + --> tests/ui/derive.rs:54:1 | LL | / impl Clone for BigArray { LL | | @@ -40,7 +40,7 @@ LL | | } = help: consider deriving `Clone` or removing `Copy` error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:68:1 + --> tests/ui/derive.rs:67:1 | LL | / impl Clone for FnPtr { LL | | @@ -53,7 +53,7 @@ LL | | } = help: consider deriving `Clone` or removing `Copy` error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:90:1 + --> tests/ui/derive.rs:89:1 | LL | / impl Clone for Generic2 { LL | | diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr index 48961d14f2bba..694690ae5bfa2 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr @@ -1,5 +1,5 @@ error: casting function pointer `foo` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:12:13 + --> tests/ui/fn_to_numeric_cast.rs:13:13 | LL | let _ = foo as i8; | ^^^^^^^^^ help: try: `foo as usize` @@ -8,19 +8,19 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` error: casting function pointer `foo` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:14:13 + --> tests/ui/fn_to_numeric_cast.rs:15:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:16:13 + --> tests/ui/fn_to_numeric_cast.rs:17:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:19:13 + --> tests/ui/fn_to_numeric_cast.rs:20:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` @@ -29,115 +29,115 @@ LL | let _ = foo as i64; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:21:13 + --> tests/ui/fn_to_numeric_cast.rs:22:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:23:13 + --> tests/ui/fn_to_numeric_cast.rs:24:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:26:13 + --> tests/ui/fn_to_numeric_cast.rs:27:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:28:13 + --> tests/ui/fn_to_numeric_cast.rs:29:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:30:13 + --> tests/ui/fn_to_numeric_cast.rs:31:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:33:13 + --> tests/ui/fn_to_numeric_cast.rs:34:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:35:13 + --> tests/ui/fn_to_numeric_cast.rs:36:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `abc` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:49:13 + --> tests/ui/fn_to_numeric_cast.rs:50:13 | LL | let _ = abc as i8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:51:13 + --> tests/ui/fn_to_numeric_cast.rs:52:13 | LL | let _ = abc as i16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:53:13 + --> tests/ui/fn_to_numeric_cast.rs:54:13 | LL | let _ = abc as i32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:56:13 + --> tests/ui/fn_to_numeric_cast.rs:57:13 | LL | let _ = abc as i64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:58:13 + --> tests/ui/fn_to_numeric_cast.rs:59:13 | LL | let _ = abc as i128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:60:13 + --> tests/ui/fn_to_numeric_cast.rs:61:13 | LL | let _ = abc as isize; | ^^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:63:13 + --> tests/ui/fn_to_numeric_cast.rs:64:13 | LL | let _ = abc as u8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:65:13 + --> tests/ui/fn_to_numeric_cast.rs:66:13 | LL | let _ = abc as u16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:67:13 + --> tests/ui/fn_to_numeric_cast.rs:68:13 | LL | let _ = abc as u32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:70:13 + --> tests/ui/fn_to_numeric_cast.rs:71:13 | LL | let _ = abc as u64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:72:13 + --> tests/ui/fn_to_numeric_cast.rs:73:13 | LL | let _ = abc as u128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `f` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:80:5 + --> tests/ui/fn_to_numeric_cast.rs:81:5 | LL | f as i32 | ^^^^^^^^ help: try: `f as usize` diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs index f53cbacdb3771..0a07aeff366eb 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs @@ -3,6 +3,7 @@ //@[64bit]ignore-bitwidth: 32 //@no-rustfix #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] +#![allow(function_casts_as_integer)] fn foo() -> String { String::new() diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs index 42f2128cd3783..83c1e9a8387ef 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs @@ -1,5 +1,6 @@ #![warn(clippy::fn_to_numeric_cast_any)] #![allow(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] +#![allow(function_casts_as_integer)] //@no-rustfix fn foo() -> u8 { 0 diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr index 58fac2d406a0f..f7c49b8ff88b5 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr @@ -1,5 +1,5 @@ error: casting function pointer `foo` to `i8` - --> tests/ui/fn_to_numeric_cast_any.rs:23:13 + --> tests/ui/fn_to_numeric_cast_any.rs:24:13 | LL | let _ = foo as i8; | ^^^^^^^^^ @@ -12,7 +12,7 @@ LL | let _ = foo() as i8; | ++ error: casting function pointer `foo` to `i16` - --> tests/ui/fn_to_numeric_cast_any.rs:26:13 + --> tests/ui/fn_to_numeric_cast_any.rs:27:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = foo() as i16; | ++ error: casting function pointer `foo` to `i32` - --> tests/ui/fn_to_numeric_cast_any.rs:29:13 + --> tests/ui/fn_to_numeric_cast_any.rs:30:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = foo() as i32; | ++ error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast_any.rs:32:13 + --> tests/ui/fn_to_numeric_cast_any.rs:33:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = foo() as i64; | ++ error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast_any.rs:35:13 + --> tests/ui/fn_to_numeric_cast_any.rs:36:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = foo() as i128; | ++ error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast_any.rs:38:13 + --> tests/ui/fn_to_numeric_cast_any.rs:39:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let _ = foo() as isize; | ++ error: casting function pointer `foo` to `u8` - --> tests/ui/fn_to_numeric_cast_any.rs:41:13 + --> tests/ui/fn_to_numeric_cast_any.rs:42:13 | LL | let _ = foo as u8; | ^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _ = foo() as u8; | ++ error: casting function pointer `foo` to `u16` - --> tests/ui/fn_to_numeric_cast_any.rs:44:13 + --> tests/ui/fn_to_numeric_cast_any.rs:45:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = foo() as u16; | ++ error: casting function pointer `foo` to `u32` - --> tests/ui/fn_to_numeric_cast_any.rs:47:13 + --> tests/ui/fn_to_numeric_cast_any.rs:48:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let _ = foo() as u32; | ++ error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast_any.rs:50:13 + --> tests/ui/fn_to_numeric_cast_any.rs:51:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _ = foo() as u64; | ++ error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast_any.rs:53:13 + --> tests/ui/fn_to_numeric_cast_any.rs:54:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _ = foo() as u128; | ++ error: casting function pointer `foo` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:56:13 + --> tests/ui/fn_to_numeric_cast_any.rs:57:13 | LL | let _ = foo as usize; | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _ = foo() as usize; | ++ error: casting function pointer `Struct::static_method` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:61:13 + --> tests/ui/fn_to_numeric_cast_any.rs:62:13 | LL | let _ = Struct::static_method as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let _ = Struct::static_method() as usize; | ++ error: casting function pointer `f` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:66:5 + --> tests/ui/fn_to_numeric_cast_any.rs:67:5 | LL | f as usize | ^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | f() as usize | ++ error: casting function pointer `T::static_method` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:71:5 + --> tests/ui/fn_to_numeric_cast_any.rs:72:5 | LL | T::static_method as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | T::static_method() as usize | ++ error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:78:13 + --> tests/ui/fn_to_numeric_cast_any.rs:79:13 | LL | let _ = (clos as fn(u32) -> u32) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | let _ = (clos as fn(u32) -> u32)() as usize; | ++ error: casting function pointer `foo` to `*const ()` - --> tests/ui/fn_to_numeric_cast_any.rs:83:13 + --> tests/ui/fn_to_numeric_cast_any.rs:84:13 | LL | let _ = foo as *const (); | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/ptr_eq.fixed b/src/tools/clippy/tests/ui/ptr_eq.fixed index 9629b3eea5870..d3624a129b5fd 100644 --- a/src/tools/clippy/tests/ui/ptr_eq.fixed +++ b/src/tools/clippy/tests/ui/ptr_eq.fixed @@ -1,4 +1,5 @@ #![warn(clippy::ptr_eq)] +#![allow(function_casts_as_integer)] macro_rules! mac { ($a:expr, $b:expr) => { diff --git a/src/tools/clippy/tests/ui/ptr_eq.rs b/src/tools/clippy/tests/ui/ptr_eq.rs index 2b741d8df4684..f06a99cabc814 100644 --- a/src/tools/clippy/tests/ui/ptr_eq.rs +++ b/src/tools/clippy/tests/ui/ptr_eq.rs @@ -1,4 +1,5 @@ #![warn(clippy::ptr_eq)] +#![allow(function_casts_as_integer)] macro_rules! mac { ($a:expr, $b:expr) => { diff --git a/src/tools/clippy/tests/ui/ptr_eq.stderr b/src/tools/clippy/tests/ui/ptr_eq.stderr index e7340624b5950..f6be4c3f016b5 100644 --- a/src/tools/clippy/tests/ui/ptr_eq.stderr +++ b/src/tools/clippy/tests/ui/ptr_eq.stderr @@ -1,5 +1,5 @@ error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:22:13 + --> tests/ui/ptr_eq.rs:23:13 | LL | let _ = a as *const _ as usize == b as *const _ as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` @@ -8,31 +8,31 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:24:13 + --> tests/ui/ptr_eq.rs:25:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:50:13 + --> tests/ui/ptr_eq.rs:51:13 | LL | let _ = x as *const u32 == y as *mut u32 as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(x, y)` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:53:13 + --> tests/ui/ptr_eq.rs:54:13 | LL | let _ = x as *const u32 != y as *mut u32 as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!std::ptr::eq(x, y)` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:61:13 + --> tests/ui/ptr_eq.rs:62:13 | LL | let _ = mac!(cast a) as *const _ == mac!(cast b) as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(mac!(cast a), mac!(cast b))` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:65:13 + --> tests/ui/ptr_eq.rs:66:13 | LL | let _ = mac!(cast a) as *const _ == mac!(cast b) as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(mac!(cast a), mac!(cast b))` diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed index 02f67f79e2b19..f332e02a2d327 100644 --- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -4,6 +4,7 @@ #![warn(clippy::useless_transmute)] #![warn(clippy::transmute_ptr_to_ptr)] #![allow(unused, clippy::borrow_as_ptr, clippy::missing_transmute_annotations)] +#![allow(function_casts_as_integer)] use std::mem::{size_of, transmute}; diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs index c5e156405ebca..c29a42ddca53b 100644 --- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -4,6 +4,7 @@ #![warn(clippy::useless_transmute)] #![warn(clippy::transmute_ptr_to_ptr)] #![allow(unused, clippy::borrow_as_ptr, clippy::missing_transmute_annotations)] +#![allow(function_casts_as_integer)] use std::mem::{size_of, transmute}; diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr index f39a64d57eb49..5ddc3de6a039f 100644 --- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -1,5 +1,5 @@ error: transmute from a pointer to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:19:38 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:20:38 | LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; | error: transmute from a pointer to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:26:46 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:27:46 | LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; | error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:33:50 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:34:50 | LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` @@ -34,7 +34,7 @@ LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, us = help: to override `-D warnings` add `#[allow(clippy::transmutes_expressible_as_ptr_casts)]` error: transmute from a reference to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:40:41 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:41:41 | LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` @@ -43,31 +43,31 @@ LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from `fn(usize) -> u8` to `*const usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:49:41 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:50:41 | LL | let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` error: transmute from `fn(usize) -> u8` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:54:49 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:55:49 | LL | let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` error: transmute from `*const u32` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:58:36 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:59:36 | LL | let _usize_from_ref = unsafe { transmute::<*const u32, usize>(&1u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&1u32 as *const u32 as usize` error: transmute from a reference to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:70:14 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:71:14 | LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` error: transmute from `fn()` to `*const u8` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:89:28 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:90:28 | LL | let _x: u8 = unsafe { *std::mem::transmute::(f) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(f as *const u8)` diff --git a/src/tools/compiletest/src/directives.rs b/src/tools/compiletest/src/directives.rs index 7c1bbe940321f..8e9c28e69ea7b 100644 --- a/src/tools/compiletest/src/directives.rs +++ b/src/tools/compiletest/src/directives.rs @@ -14,6 +14,7 @@ use crate::directives::directive_names::{ KNOWN_DIRECTIVE_NAMES_SET, KNOWN_HTMLDOCCK_DIRECTIVE_NAMES, KNOWN_JSONDOCCK_DIRECTIVE_NAMES, }; pub(crate) use crate::directives::file::FileDirectives; +use crate::directives::handlers::DIRECTIVE_HANDLERS_MAP; use crate::directives::line::{DirectiveLine, line_directive}; use crate::directives::needs::CachedNeedsConditions; use crate::edition::{Edition, parse_edition}; @@ -26,6 +27,7 @@ mod auxiliary; mod cfg; mod directive_names; mod file; +mod handlers; mod line; mod needs; #[cfg(test)] @@ -359,269 +361,9 @@ impl TestProps { return; } - use directives::*; - - config.push_name_value_directive( - ln, - ERROR_PATTERN, - &mut self.error_patterns, - |r| r, - ); - config.push_name_value_directive( - ln, - REGEX_ERROR_PATTERN, - &mut self.regex_error_patterns, - |r| r, - ); - - config.push_name_value_directive(ln, DOC_FLAGS, &mut self.doc_flags, |r| r); - - fn split_flags(flags: &str) -> Vec { - // Individual flags can be single-quoted to preserve spaces; see - // . - flags - .split('\'') - .enumerate() - .flat_map(|(i, f)| { - if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() } - }) - .map(move |s| s.to_owned()) - .collect::>() - } - - if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) { - let flags = split_flags(&flags); - for (i, flag) in flags.iter().enumerate() { - if flag == "--edition" || flag.starts_with("--edition=") { - panic!("you must use `//@ edition` to configure the edition"); - } - if (flag == "-C" - && flags.get(i + 1).is_some_and(|v| v.starts_with("incremental="))) - || flag.starts_with("-Cincremental=") - { - panic!( - "you must use `//@ incremental` to enable incremental compilation" - ); - } - } - self.compile_flags.extend(flags); - } - - if let Some(range) = parse_edition_range(config, ln) { - self.edition = Some(range.edition_to_test(config.edition)); - } - - config.parse_and_update_revisions(ln, &mut self.revisions); - - if let Some(flags) = config.parse_name_value_directive(ln, RUN_FLAGS) { - self.run_flags.extend(split_flags(&flags)); - } - - if self.pp_exact.is_none() { - self.pp_exact = config.parse_pp_exact(ln); - } - - config.set_name_directive(ln, SHOULD_ICE, &mut self.should_ice); - config.set_name_directive(ln, BUILD_AUX_DOCS, &mut self.build_aux_docs); - config.set_name_directive(ln, UNIQUE_DOC_OUT_DIR, &mut self.unique_doc_out_dir); - - config.set_name_directive(ln, FORCE_HOST, &mut self.force_host); - config.set_name_directive(ln, CHECK_STDOUT, &mut self.check_stdout); - config.set_name_directive(ln, CHECK_RUN_RESULTS, &mut self.check_run_results); - config.set_name_directive( - ln, - DONT_CHECK_COMPILER_STDOUT, - &mut self.dont_check_compiler_stdout, - ); - config.set_name_directive( - ln, - DONT_CHECK_COMPILER_STDERR, - &mut self.dont_check_compiler_stderr, - ); - config.set_name_directive(ln, NO_PREFER_DYNAMIC, &mut self.no_prefer_dynamic); - - if let Some(m) = config.parse_name_value_directive(ln, PRETTY_MODE) { - self.pretty_mode = m; - } - - config.set_name_directive( - ln, - PRETTY_COMPARE_ONLY, - &mut self.pretty_compare_only, - ); - - // Call a helper method to deal with aux-related directives. - parse_and_update_aux(config, ln, &mut self.aux); - - config.push_name_value_directive( - ln, - EXEC_ENV, - &mut self.exec_env, - Config::parse_env, - ); - config.push_name_value_directive( - ln, - UNSET_EXEC_ENV, - &mut self.unset_exec_env, - |r| r.trim().to_owned(), - ); - config.push_name_value_directive( - ln, - RUSTC_ENV, - &mut self.rustc_env, - Config::parse_env, - ); - config.push_name_value_directive( - ln, - UNSET_RUSTC_ENV, - &mut self.unset_rustc_env, - |r| r.trim().to_owned(), - ); - config.push_name_value_directive( - ln, - FORBID_OUTPUT, - &mut self.forbid_output, - |r| r, - ); - config.set_name_directive( - ln, - CHECK_TEST_LINE_NUMBERS_MATCH, - &mut self.check_test_line_numbers_match, - ); - - self.update_pass_mode(ln, config); - self.update_fail_mode(ln, config); - - config.set_name_directive(ln, IGNORE_PASS, &mut self.ignore_pass); - - if let Some(NormalizeRule { kind, regex, replacement }) = - config.parse_custom_normalization(ln) - { - let rule_tuple = (regex, replacement); - match kind { - NormalizeKind::Stdout => self.normalize_stdout.push(rule_tuple), - NormalizeKind::Stderr => self.normalize_stderr.push(rule_tuple), - NormalizeKind::Stderr32bit => { - if config.target_cfg().pointer_width == 32 { - self.normalize_stderr.push(rule_tuple); - } - } - NormalizeKind::Stderr64bit => { - if config.target_cfg().pointer_width == 64 { - self.normalize_stderr.push(rule_tuple); - } - } - } - } - - if let Some(code) = config - .parse_name_value_directive(ln, FAILURE_STATUS) - .and_then(|code| code.trim().parse::().ok()) - { - self.failure_status = Some(code); - } - - config.set_name_directive( - ln, - DONT_CHECK_FAILURE_STATUS, - &mut self.dont_check_failure_status, - ); - - config.set_name_directive(ln, RUN_RUSTFIX, &mut self.run_rustfix); - config.set_name_directive( - ln, - RUSTFIX_ONLY_MACHINE_APPLICABLE, - &mut self.rustfix_only_machine_applicable, - ); - config.set_name_value_directive( - ln, - ASSEMBLY_OUTPUT, - &mut self.assembly_output, - |r| r.trim().to_string(), - ); - config.set_name_directive( - ln, - STDERR_PER_BITWIDTH, - &mut self.stderr_per_bitwidth, - ); - config.set_name_directive(ln, INCREMENTAL, &mut self.incremental); - - // Unlike the other `name_value_directive`s this needs to be handled manually, - // because it sets a `bool` flag. - if let Some(known_bug) = config.parse_name_value_directive(ln, KNOWN_BUG) { - let known_bug = known_bug.trim(); - if known_bug == "unknown" - || known_bug.split(',').all(|issue_ref| { - issue_ref - .trim() - .split_once('#') - .filter(|(_, number)| { - number.chars().all(|digit| digit.is_numeric()) - }) - .is_some() - }) - { - self.known_bug = true; - } else { - panic!( - "Invalid known-bug value: {known_bug}\nIt requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`." - ); - } - } else if config.parse_name_directive(ln, KNOWN_BUG) { - panic!( - "Invalid known-bug attribute, requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`." - ); - } - - config.set_name_value_directive( - ln, - TEST_MIR_PASS, - &mut self.mir_unit_test, - |s| s.trim().to_string(), - ); - config.set_name_directive(ln, REMAP_SRC_BASE, &mut self.remap_src_base); - - if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) { - self.llvm_cov_flags.extend(split_flags(&flags)); - } - - if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) { - self.filecheck_flags.extend(split_flags(&flags)); - } - - config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg); - - self.update_add_minicore(ln, config); - - if let Some(flags) = - config.parse_name_value_directive(ln, MINICORE_COMPILE_FLAGS) - { - let flags = split_flags(&flags); - for flag in &flags { - if flag == "--edition" || flag.starts_with("--edition=") { - panic!("you must use `//@ edition` to configure the edition"); - } - } - self.minicore_compile_flags.extend(flags); + if let Some(handler) = DIRECTIVE_HANDLERS_MAP.get(ln.name) { + handler.handle(config, ln, self); } - - if let Some(err_kind) = - config.parse_name_value_directive(ln, DONT_REQUIRE_ANNOTATIONS) - { - self.dont_require_annotations - .insert(ErrorKind::expect_from_user_str(err_kind.trim())); - } - - config.set_name_directive( - ln, - DISABLE_GDB_PRETTY_PRINTERS, - &mut self.disable_gdb_pretty_printers, - ); - config.set_name_directive( - ln, - COMPARE_OUTPUT_BY_LINES, - &mut self.compare_output_by_lines, - ); }, ); } @@ -1691,3 +1433,16 @@ impl EditionRange { } } } + +fn split_flags(flags: &str) -> Vec { + // Individual flags can be single-quoted to preserve spaces; see + // . + // FIXME(#147955): Replace this ad-hoc quoting with an escape/quote system that + // is closer to what actual shells do, so that it's more flexible and familiar. + flags + .split('\'') + .enumerate() + .flat_map(|(i, f)| if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }) + .map(move |s| s.to_owned()) + .collect::>() +} diff --git a/src/tools/compiletest/src/directives/handlers.rs b/src/tools/compiletest/src/directives/handlers.rs new file mode 100644 index 0000000000000..b53bda90f626b --- /dev/null +++ b/src/tools/compiletest/src/directives/handlers.rs @@ -0,0 +1,372 @@ +use std::collections::HashMap; +use std::sync::{Arc, LazyLock}; + +use crate::common::Config; +use crate::directives::{ + DirectiveLine, NormalizeKind, NormalizeRule, TestProps, parse_and_update_aux, + parse_edition_range, split_flags, +}; +use crate::errors::ErrorKind; + +pub(crate) static DIRECTIVE_HANDLERS_MAP: LazyLock> = + LazyLock::new(make_directive_handlers_map); + +#[derive(Clone)] +pub(crate) struct Handler { + handler_fn: Arc) + Send + Sync>, +} + +impl Handler { + pub(crate) fn handle(&self, config: &Config, line: &DirectiveLine<'_>, props: &mut TestProps) { + (self.handler_fn)(HandlerArgs { config, line, props }) + } +} + +struct HandlerArgs<'a> { + config: &'a Config, + line: &'a DirectiveLine<'a>, + props: &'a mut TestProps, +} + +/// Intermediate data structure, used for defining a list of handlers. +struct NamedHandler { + names: Vec<&'static str>, + handler: Handler, +} + +/// Helper function to create a simple handler, so that changes can be made +/// to the handler struct without disturbing existing handler declarations. +fn handler( + name: &'static str, + handler_fn: impl Fn(&Config, &DirectiveLine<'_>, &mut TestProps) + Send + Sync + 'static, +) -> NamedHandler { + multi_handler(&[name], handler_fn) +} + +/// Associates the same handler function with multiple directive names. +fn multi_handler( + names: &[&'static str], + handler_fn: impl Fn(&Config, &DirectiveLine<'_>, &mut TestProps) + Send + Sync + 'static, +) -> NamedHandler { + NamedHandler { + names: names.to_owned(), + handler: Handler { + handler_fn: Arc::new(move |args| handler_fn(args.config, args.line, args.props)), + }, + } +} + +fn make_directive_handlers_map() -> HashMap<&'static str, Handler> { + use crate::directives::directives::*; + + // FIXME(Zalathar): Now that most directive-processing has been extracted + // into individual handlers, there should be many opportunities to simplify + // these handlers, e.g. by getting rid of now-redundant name checks. + + let handlers: Vec = vec![ + handler(ERROR_PATTERN, |config, ln, props| { + config.push_name_value_directive(ln, ERROR_PATTERN, &mut props.error_patterns, |r| r); + }), + handler(REGEX_ERROR_PATTERN, |config, ln, props| { + config.push_name_value_directive( + ln, + REGEX_ERROR_PATTERN, + &mut props.regex_error_patterns, + |r| r, + ); + }), + handler(DOC_FLAGS, |config, ln, props| { + config.push_name_value_directive(ln, DOC_FLAGS, &mut props.doc_flags, |r| r); + }), + handler(COMPILE_FLAGS, |config, ln, props| { + if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) { + let flags = split_flags(&flags); + // FIXME(#147955): Extract and unify this with other handlers that + // check compiler flags, e.g. MINICORE_COMPILE_FLAGS. + for (i, flag) in flags.iter().enumerate() { + if flag == "--edition" || flag.starts_with("--edition=") { + panic!("you must use `//@ edition` to configure the edition"); + } + if (flag == "-C" + && flags.get(i + 1).is_some_and(|v| v.starts_with("incremental="))) + || flag.starts_with("-Cincremental=") + { + panic!("you must use `//@ incremental` to enable incremental compilation"); + } + } + props.compile_flags.extend(flags); + } + }), + handler("edition", |config, ln, props| { + if let Some(range) = parse_edition_range(config, ln) { + props.edition = Some(range.edition_to_test(config.edition)); + } + }), + handler("revisions", |config, ln, props| { + config.parse_and_update_revisions(ln, &mut props.revisions); + }), + handler(RUN_FLAGS, |config, ln, props| { + if let Some(flags) = config.parse_name_value_directive(ln, RUN_FLAGS) { + props.run_flags.extend(split_flags(&flags)); + } + }), + handler("pp-exact", |config, ln, props| { + if props.pp_exact.is_none() { + props.pp_exact = config.parse_pp_exact(ln); + } + }), + handler(SHOULD_ICE, |config, ln, props| { + config.set_name_directive(ln, SHOULD_ICE, &mut props.should_ice); + }), + handler(BUILD_AUX_DOCS, |config, ln, props| { + config.set_name_directive(ln, BUILD_AUX_DOCS, &mut props.build_aux_docs); + }), + handler(UNIQUE_DOC_OUT_DIR, |config, ln, props| { + config.set_name_directive(ln, UNIQUE_DOC_OUT_DIR, &mut props.unique_doc_out_dir); + }), + handler(FORCE_HOST, |config, ln, props| { + config.set_name_directive(ln, FORCE_HOST, &mut props.force_host); + }), + handler(CHECK_STDOUT, |config, ln, props| { + config.set_name_directive(ln, CHECK_STDOUT, &mut props.check_stdout); + }), + handler(CHECK_RUN_RESULTS, |config, ln, props| { + config.set_name_directive(ln, CHECK_RUN_RESULTS, &mut props.check_run_results); + }), + handler(DONT_CHECK_COMPILER_STDOUT, |config, ln, props| { + config.set_name_directive( + ln, + DONT_CHECK_COMPILER_STDOUT, + &mut props.dont_check_compiler_stdout, + ); + }), + handler(DONT_CHECK_COMPILER_STDERR, |config, ln, props| { + config.set_name_directive( + ln, + DONT_CHECK_COMPILER_STDERR, + &mut props.dont_check_compiler_stderr, + ); + }), + handler(NO_PREFER_DYNAMIC, |config, ln, props| { + config.set_name_directive(ln, NO_PREFER_DYNAMIC, &mut props.no_prefer_dynamic); + }), + handler(PRETTY_MODE, |config, ln, props| { + if let Some(m) = config.parse_name_value_directive(ln, PRETTY_MODE) { + props.pretty_mode = m; + } + }), + handler(PRETTY_COMPARE_ONLY, |config, ln, props| { + config.set_name_directive(ln, PRETTY_COMPARE_ONLY, &mut props.pretty_compare_only); + }), + multi_handler( + &[AUX_BUILD, AUX_BIN, AUX_CRATE, PROC_MACRO, AUX_CODEGEN_BACKEND], + |config, ln, props| { + // Call a helper method to deal with aux-related directives. + parse_and_update_aux(config, ln, &mut props.aux); + }, + ), + handler(EXEC_ENV, |config, ln, props| { + config.push_name_value_directive(ln, EXEC_ENV, &mut props.exec_env, Config::parse_env); + }), + handler(UNSET_EXEC_ENV, |config, ln, props| { + config.push_name_value_directive(ln, UNSET_EXEC_ENV, &mut props.unset_exec_env, |r| { + r.trim().to_owned() + }); + }), + handler(RUSTC_ENV, |config, ln, props| { + config.push_name_value_directive( + ln, + RUSTC_ENV, + &mut props.rustc_env, + Config::parse_env, + ); + }), + handler(UNSET_RUSTC_ENV, |config, ln, props| { + config.push_name_value_directive( + ln, + UNSET_RUSTC_ENV, + &mut props.unset_rustc_env, + |r| r.trim().to_owned(), + ); + }), + handler(FORBID_OUTPUT, |config, ln, props| { + config.push_name_value_directive(ln, FORBID_OUTPUT, &mut props.forbid_output, |r| r); + }), + handler(CHECK_TEST_LINE_NUMBERS_MATCH, |config, ln, props| { + config.set_name_directive( + ln, + CHECK_TEST_LINE_NUMBERS_MATCH, + &mut props.check_test_line_numbers_match, + ); + }), + multi_handler(&["check-pass", "build-pass", "run-pass"], |config, ln, props| { + props.update_pass_mode(ln, config); + }), + multi_handler( + &["check-fail", "build-fail", "run-fail", "run-crash", "run-fail-or-crash"], + |config, ln, props| { + props.update_fail_mode(ln, config); + }, + ), + handler(IGNORE_PASS, |config, ln, props| { + config.set_name_directive(ln, IGNORE_PASS, &mut props.ignore_pass); + }), + multi_handler( + &[ + "normalize-stdout", + "normalize-stderr", + "normalize-stderr-32bit", + "normalize-stderr-64bit", + ], + |config, ln, props| { + if let Some(NormalizeRule { kind, regex, replacement }) = + config.parse_custom_normalization(ln) + { + let rule_tuple = (regex, replacement); + match kind { + NormalizeKind::Stdout => props.normalize_stdout.push(rule_tuple), + NormalizeKind::Stderr => props.normalize_stderr.push(rule_tuple), + NormalizeKind::Stderr32bit => { + if config.target_cfg().pointer_width == 32 { + props.normalize_stderr.push(rule_tuple); + } + } + NormalizeKind::Stderr64bit => { + if config.target_cfg().pointer_width == 64 { + props.normalize_stderr.push(rule_tuple); + } + } + } + } + }, + ), + handler(FAILURE_STATUS, |config, ln, props| { + if let Some(code) = config + .parse_name_value_directive(ln, FAILURE_STATUS) + .and_then(|code| code.trim().parse::().ok()) + { + props.failure_status = Some(code); + } + }), + handler(DONT_CHECK_FAILURE_STATUS, |config, ln, props| { + config.set_name_directive( + ln, + DONT_CHECK_FAILURE_STATUS, + &mut props.dont_check_failure_status, + ); + }), + handler(RUN_RUSTFIX, |config, ln, props| { + config.set_name_directive(ln, RUN_RUSTFIX, &mut props.run_rustfix); + }), + handler(RUSTFIX_ONLY_MACHINE_APPLICABLE, |config, ln, props| { + config.set_name_directive( + ln, + RUSTFIX_ONLY_MACHINE_APPLICABLE, + &mut props.rustfix_only_machine_applicable, + ); + }), + handler(ASSEMBLY_OUTPUT, |config, ln, props| { + config.set_name_value_directive(ln, ASSEMBLY_OUTPUT, &mut props.assembly_output, |r| { + r.trim().to_string() + }); + }), + handler(STDERR_PER_BITWIDTH, |config, ln, props| { + config.set_name_directive(ln, STDERR_PER_BITWIDTH, &mut props.stderr_per_bitwidth); + }), + handler(INCREMENTAL, |config, ln, props| { + config.set_name_directive(ln, INCREMENTAL, &mut props.incremental); + }), + handler(KNOWN_BUG, |config, ln, props| { + // Unlike the other `name_value_directive`s this needs to be handled manually, + // because it sets a `bool` flag. + if let Some(known_bug) = config.parse_name_value_directive(ln, KNOWN_BUG) { + let known_bug = known_bug.trim(); + if known_bug == "unknown" + || known_bug.split(',').all(|issue_ref| { + issue_ref + .trim() + .split_once('#') + .filter(|(_, number)| number.chars().all(|digit| digit.is_numeric())) + .is_some() + }) + { + props.known_bug = true; + } else { + panic!( + "Invalid known-bug value: {known_bug}\nIt requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`." + ); + } + } else if config.parse_name_directive(ln, KNOWN_BUG) { + panic!( + "Invalid known-bug attribute, requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`." + ); + } + }), + handler(TEST_MIR_PASS, |config, ln, props| { + config.set_name_value_directive(ln, TEST_MIR_PASS, &mut props.mir_unit_test, |s| { + s.trim().to_string() + }); + }), + handler(REMAP_SRC_BASE, |config, ln, props| { + config.set_name_directive(ln, REMAP_SRC_BASE, &mut props.remap_src_base); + }), + handler(LLVM_COV_FLAGS, |config, ln, props| { + if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) { + props.llvm_cov_flags.extend(split_flags(&flags)); + } + }), + handler(FILECHECK_FLAGS, |config, ln, props| { + if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) { + props.filecheck_flags.extend(split_flags(&flags)); + } + }), + handler(NO_AUTO_CHECK_CFG, |config, ln, props| { + config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut props.no_auto_check_cfg); + }), + handler(ADD_MINICORE, |config, ln, props| { + props.update_add_minicore(ln, config); + }), + handler(MINICORE_COMPILE_FLAGS, |config, ln, props| { + if let Some(flags) = config.parse_name_value_directive(ln, MINICORE_COMPILE_FLAGS) { + let flags = split_flags(&flags); + // FIXME(#147955): Extract and unify this with other handlers that + // check compiler flags, e.g. COMPILE_FLAGS. + for flag in &flags { + if flag == "--edition" || flag.starts_with("--edition=") { + panic!("you must use `//@ edition` to configure the edition"); + } + } + props.minicore_compile_flags.extend(flags); + } + }), + handler(DONT_REQUIRE_ANNOTATIONS, |config, ln, props| { + if let Some(err_kind) = config.parse_name_value_directive(ln, DONT_REQUIRE_ANNOTATIONS) + { + props + .dont_require_annotations + .insert(ErrorKind::expect_from_user_str(err_kind.trim())); + } + }), + handler(DISABLE_GDB_PRETTY_PRINTERS, |config, ln, props| { + config.set_name_directive( + ln, + DISABLE_GDB_PRETTY_PRINTERS, + &mut props.disable_gdb_pretty_printers, + ); + }), + handler(COMPARE_OUTPUT_BY_LINES, |config, ln, props| { + config.set_name_directive( + ln, + COMPARE_OUTPUT_BY_LINES, + &mut props.compare_output_by_lines, + ); + }), + ]; + + handlers + .into_iter() + .flat_map(|NamedHandler { names, handler }| { + names.into_iter().map(move |name| (name, Handler::clone(&handler))) + }) + .collect() +} diff --git a/src/tools/compiletest/src/directives/tests.rs b/src/tools/compiletest/src/directives/tests.rs index e221c3a2daf2e..fe39e382ed5b6 100644 --- a/src/tools/compiletest/src/directives/tests.rs +++ b/src/tools/compiletest/src/directives/tests.rs @@ -1,14 +1,31 @@ +use std::collections::BTreeSet; + use camino::Utf8Path; use semver::Version; use crate::common::{Config, Debugger, TestMode}; use crate::directives::{ - self, AuxProps, DirectivesCache, EarlyProps, Edition, EditionRange, FileDirectives, - extract_llvm_version, extract_version_range, line_directive, parse_edition, - parse_normalize_rule, + self, AuxProps, DIRECTIVE_HANDLERS_MAP, DirectivesCache, EarlyProps, Edition, EditionRange, + FileDirectives, KNOWN_DIRECTIVE_NAMES_SET, extract_llvm_version, extract_version_range, + line_directive, parse_edition, parse_normalize_rule, }; use crate::executor::{CollectedTestDesc, ShouldFail}; +/// All directive handlers should have a name that is also in `KNOWN_DIRECTIVE_NAMES_SET`. +#[test] +fn handler_names() { + let unknown_names = DIRECTIVE_HANDLERS_MAP + .keys() + .copied() + .filter(|name| !KNOWN_DIRECTIVE_NAMES_SET.contains(name)) + .collect::>(); + + assert!( + unknown_names.is_empty(), + "Directive handler names not in `directive_names.rs`: {unknown_names:#?}" + ); +} + fn make_test_description( config: &Config, name: String, diff --git a/src/tools/miri/src/shims/native_lib/trace/parent.rs b/src/tools/miri/src/shims/native_lib/trace/parent.rs index 335188b331838..f6ebbc469f737 100644 --- a/src/tools/miri/src/shims/native_lib/trace/parent.rs +++ b/src/tools/miri/src/shims/native_lib/trace/parent.rs @@ -500,7 +500,8 @@ fn handle_segfault( capstone_disassemble(&instr, addr, cs, acc_events).expect("Failed to disassemble instruction"); // Move the instr ptr into the deprotection code. - #[expect(clippy::as_conversions)] + #[allow(unknown_lints)] + #[expect(clippy::as_conversions, function_casts_as_integer)] new_regs.set_ip(mempr_off as usize); // Don't mess up the stack by accident! new_regs.set_sp(stack_ptr); @@ -552,7 +553,8 @@ fn handle_segfault( new_regs = regs_bak; // Reprotect everything and continue. - #[expect(clippy::as_conversions)] + #[allow(unknown_lints)] + #[expect(clippy::as_conversions, function_casts_as_integer)] new_regs.set_ip(mempr_on as usize); new_regs.set_sp(stack_ptr); ptrace::setregs(pid, new_regs).unwrap(); diff --git a/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.rs b/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.rs index a3060abc39402..cf6f43dbbfa91 100644 --- a/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.rs +++ b/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.rs @@ -1,5 +1,7 @@ //@normalize-stderr-test: "::<.*>" -> "" +#![allow(function_casts_as_integer)] + #[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::() diff --git a/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.stdout b/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.stdout index 5c2995e132aa6..b3a4beb4e80ec 100644 --- a/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.stdout +++ b/src/tools/miri/tests/pass/backtrace/backtrace-api-v1.stdout @@ -1,5 +1,5 @@ -tests/pass/backtrace/backtrace-api-v1.rs:27:9 (func_d) -tests/pass/backtrace/backtrace-api-v1.rs:14:9 (func_c) -tests/pass/backtrace/backtrace-api-v1.rs:9:5 (func_b::) -tests/pass/backtrace/backtrace-api-v1.rs:5:5 (func_a) -tests/pass/backtrace/backtrace-api-v1.rs:34:18 (main) +tests/pass/backtrace/backtrace-api-v1.rs:29:9 (func_d) +tests/pass/backtrace/backtrace-api-v1.rs:16:9 (func_c) +tests/pass/backtrace/backtrace-api-v1.rs:11:5 (func_b::) +tests/pass/backtrace/backtrace-api-v1.rs:7:5 (func_a) +tests/pass/backtrace/backtrace-api-v1.rs:36:18 (main) diff --git a/src/tools/remote-test-client/Cargo.toml b/src/tools/remote-test-client/Cargo.toml index d59cd6b3d8e22..6fe690ba20380 100644 --- a/src/tools/remote-test-client/Cargo.toml +++ b/src/tools/remote-test-client/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +assert_cmd = "2" diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index b9741431b5034..21043f0994574 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -11,12 +11,16 @@ use std::io::{self, BufWriter}; use std::net::TcpStream; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::time::Duration; +use std::time::{Duration, Instant}; use std::{env, thread}; const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR"; const DEFAULT_ADDR: &str = "127.0.0.1:12345"; +const CONNECT_TIMEOUT_ENV: &str = "TEST_DEVICE_CONNECT_TIMEOUT_SECONDS"; +/// The default timeout is high to not break slow CI or slow device starts. +const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_mins(30); + macro_rules! t { ($e:expr) => { match $e { @@ -56,6 +60,17 @@ fn main() { } } +fn connect_timeout() -> Duration { + match env::var(CONNECT_TIMEOUT_ENV).ok() { + Some(timeout) => timeout.parse().map(Duration::from_secs).unwrap_or_else(|e| { + panic!( + "error: parsing `{CONNECT_TIMEOUT_ENV}` value \"{timeout}\" as seconds failed: {e}" + ) + }), + None => DEFAULT_CONNECT_TIMEOUT, + } +} + fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option) { let device_address = env::var(REMOTE_ADDR_ENV).unwrap_or(DEFAULT_ADDR.to_string()); @@ -69,7 +84,10 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option usize { fn main() { fn g1(_: extern "C" fn(_: u8, va: ...)) {} - fn g2(_: extern "C" fn(_: u8, ...)) {} + fn g2(_: extern "C" fn(_: u8, _: ...)) {} fn g3(_: extern "C" fn(u8, va: ...)) {} - fn g4(_: extern "C" fn(u8, ...)) {} + fn g4(_: extern "C" fn(u8, _: ...)) {} fn g5(_: extern "C" fn(va: ...)) {} - fn g6(_: extern "C" fn(...)) {} + fn g6(_: extern "C" fn(_: ...)) {} _ = { unsafe extern "C" fn f1(_: u8, va: ...) {} }; - _ = { unsafe extern "C" fn f2(_: u8, ...) {} }; + _ = { unsafe extern "C" fn f2(_: u8, _: ...) {} }; _ = { unsafe extern "C" fn f5(va: ...) {} }; - _ = { unsafe extern "C" fn f6(...) {} }; + _ = { unsafe extern "C" fn f6(_: ...) {} }; } diff --git a/tests/run-make/rustdoc-test-builder/builder.rs b/tests/run-make/rustdoc-test-builder/builder.rs new file mode 100644 index 0000000000000..b5a2c8ae346ea --- /dev/null +++ b/tests/run-make/rustdoc-test-builder/builder.rs @@ -0,0 +1,23 @@ +use std::ffi::OsString; +use std::path::PathBuf; +use std::process::{self, Command}; +use std::{env, fs}; + +fn main() { + let args: Vec = env::args_os().collect(); + let log_path = env::var_os("BUILDER_LOG").map(PathBuf::from).expect("BUILDER_LOG must be set"); + let real_rustc = env::var_os("REAL_RUSTC").expect("REAL_RUSTC must be set"); + + let log_contents = + args.iter().skip(1).map(|arg| arg.to_string_lossy()).collect::>().join("\n"); + fs::write(&log_path, log_contents).expect("failed to write builder log"); + + let status = Command::new(real_rustc) + .args(args.iter().skip(1)) + .status() + .expect("failed to invoke real rustc"); + + if !status.success() { + process::exit(status.code().unwrap_or(1)); + } +} diff --git a/tests/run-make/rustdoc-test-builder/doctest.rs b/tests/run-make/rustdoc-test-builder/doctest.rs new file mode 100644 index 0000000000000..1a4ff6a2fdd76 --- /dev/null +++ b/tests/run-make/rustdoc-test-builder/doctest.rs @@ -0,0 +1,3 @@ +//! ```rust +//! assert_eq!(2 + 2, 4); +//! ``` diff --git a/tests/run-make/rustdoc-test-builder/rmake.rs b/tests/run-make/rustdoc-test-builder/rmake.rs index 9aa8143dc1dc4..d10a3c92cae42 100644 --- a/tests/run-make/rustdoc-test-builder/rmake.rs +++ b/tests/run-make/rustdoc-test-builder/rmake.rs @@ -1,11 +1,14 @@ -// This test ensures that if the rustdoc test binary is not executable, it will -// gracefully fail and not panic. +// This test validates the `--test-builder` rustdoc option. +// It ensures that: +// 1. When the test-builder path points to a non-executable file, rustdoc gracefully fails +// 2. When the test-builder path points to a valid executable, it receives rustc arguments //@ needs-target-std -use run_make_support::{path, rfs, rustdoc}; +use run_make_support::{bare_rustc, path, rfs, rustc_path, rustdoc, target}; fn main() { + // Test 1: Verify that a non-executable test-builder fails gracefully let absolute_path = path("foo.rs").canonicalize().expect("failed to get absolute path"); let output = rustdoc() .input("foo.rs") @@ -19,4 +22,37 @@ fn main() { output.assert_stdout_contains("Failed to spawn "); // ... and that we didn't panic. output.assert_not_ice(); + + // Some targets (for example wasm) cannot execute doctests directly even with a runner, + // so only exercise the success path when the target can run on the host. + if target().contains("wasm") || std::env::var_os("REMOTE_TEST_CLIENT").is_some() { + return; + } + + // Test 2: Verify that a valid test-builder is invoked with correct arguments + // Build a custom test-builder that logs its arguments and forwards to rustc. + // Use `bare_rustc` so we compile for the host architecture even in cross builds. + let builder_bin = path("builder-bin"); + bare_rustc().input("builder.rs").output(&builder_bin).run(); + + let log_path = path("builder.log"); + let _ = std::fs::remove_file(&log_path); + + // Run rustdoc with our custom test-builder + rustdoc() + .input("doctest.rs") + .arg("--test") + .arg("-Zunstable-options") + .arg("--test-builder") + .arg(&builder_bin) + .env("REAL_RUSTC", rustc_path()) + .env("BUILDER_LOG", &log_path) + .run(); + + // Verify the custom builder was invoked with rustc-style arguments + let log_contents = rfs::read_to_string(&log_path); + assert!( + log_contents.contains("--crate-type"), + "expected builder to receive rustc arguments, got:\n{log_contents}" + ); } diff --git a/tests/rustdoc-ui/deprecated-attrs.rs b/tests/rustdoc-ui/deprecated-attrs.rs index dcf8a52de41d8..26aaf0d46808f 100644 --- a/tests/rustdoc-ui/deprecated-attrs.rs +++ b/tests/rustdoc-ui/deprecated-attrs.rs @@ -4,14 +4,12 @@ //~^ ERROR unknown `doc` attribute `no_default_passes` //~| NOTE no longer functions //~| NOTE see issue #44136 -//~| HELP you may want to use `doc(document_private_items)` //~| NOTE `doc(no_default_passes)` is now a no-op //~| NOTE `#[deny(invalid_doc_attributes)]` on by default #![doc(passes = "collapse-docs unindent-comments")] //~^ ERROR unknown `doc` attribute `passes` //~| NOTE no longer functions //~| NOTE see issue #44136 -//~| HELP you may want to use `doc(document_private_items)` //~| NOTE `doc(passes)` is now a no-op #![doc(plugins = "xxx")] //~^ ERROR unknown `doc` attribute `plugins` diff --git a/tests/rustdoc-ui/deprecated-attrs.stderr b/tests/rustdoc-ui/deprecated-attrs.stderr index 3e9820522338a..323257f944ce7 100644 --- a/tests/rustdoc-ui/deprecated-attrs.stderr +++ b/tests/rustdoc-ui/deprecated-attrs.stderr @@ -10,22 +10,20 @@ LL | #![doc(no_default_passes)] | ^^^^^^^^^^^^^^^^^ no longer functions | = note: `doc` attribute `no_default_passes` no longer functions; see issue #44136 - = help: you may want to use `doc(document_private_items)` = note: `doc(no_default_passes)` is now a no-op = note: `#[deny(invalid_doc_attributes)]` on by default error: unknown `doc` attribute `passes` - --> $DIR/deprecated-attrs.rs:10:8 + --> $DIR/deprecated-attrs.rs:9:8 | LL | #![doc(passes = "collapse-docs unindent-comments")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no longer functions | = note: `doc` attribute `passes` no longer functions; see issue #44136 - = help: you may want to use `doc(document_private_items)` = note: `doc(passes)` is now a no-op error: unknown `doc` attribute `plugins` - --> $DIR/deprecated-attrs.rs:16:8 + --> $DIR/deprecated-attrs.rs:14:8 | LL | #![doc(plugins = "xxx")] | ^^^^^^^^^^^^^^^ no longer functions diff --git a/tests/rustdoc/jump-to-def-assoc-items.rs b/tests/rustdoc/jump-to-def/assoc-items.rs similarity index 95% rename from tests/rustdoc/jump-to-def-assoc-items.rs rename to tests/rustdoc/jump-to-def/assoc-items.rs index 0dfe3c7bdc155..01beb8dd7618a 100644 --- a/tests/rustdoc/jump-to-def-assoc-items.rs +++ b/tests/rustdoc/jump-to-def/assoc-items.rs @@ -4,7 +4,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-def-assoc-items.rs.html' +//@ has 'src/foo/assoc-items.rs.html' pub trait Trait { type T; diff --git a/tests/rustdoc/jump-to-def-ice-assoc-types.rs b/tests/rustdoc/jump-to-def/assoc-types.rs similarity index 85% rename from tests/rustdoc/jump-to-def-ice-assoc-types.rs rename to tests/rustdoc/jump-to-def/assoc-types.rs index 9915c53668f0d..f430eaf16389a 100644 --- a/tests/rustdoc/jump-to-def-ice-assoc-types.rs +++ b/tests/rustdoc/jump-to-def/assoc-types.rs @@ -5,7 +5,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-def-ice-assoc-types.rs.html' +//@ has 'src/foo/assoc-types.rs.html' pub trait Trait { type Node; diff --git a/tests/rustdoc/jump-to-def/auxiliary/jump-to-def-macro.rs b/tests/rustdoc/jump-to-def/auxiliary/symbols.rs similarity index 100% rename from tests/rustdoc/jump-to-def/auxiliary/jump-to-def-macro.rs rename to tests/rustdoc/jump-to-def/auxiliary/symbols.rs diff --git a/tests/rustdoc/jump-to-def/jump-to-def-doc-links-calls.rs b/tests/rustdoc/jump-to-def/doc-links-calls.rs similarity index 90% rename from tests/rustdoc/jump-to-def/jump-to-def-doc-links-calls.rs rename to tests/rustdoc/jump-to-def/doc-links-calls.rs index 55e59f23b6f28..05a5051a762ef 100644 --- a/tests/rustdoc/jump-to-def/jump-to-def-doc-links-calls.rs +++ b/tests/rustdoc/jump-to-def/doc-links-calls.rs @@ -2,7 +2,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-def-doc-links-calls.rs.html' +//@ has 'src/foo/doc-links-calls.rs.html' //@ has - '//a[@href="../../foo/struct.Bar.html"]' 'Bar' pub struct Bar; diff --git a/tests/rustdoc/jump-to-def/jump-to-def-doc-links.rs b/tests/rustdoc/jump-to-def/doc-links.rs similarity index 95% rename from tests/rustdoc/jump-to-def/jump-to-def-doc-links.rs rename to tests/rustdoc/jump-to-def/doc-links.rs index 2abb52e0a009f..f1c5c50663822 100644 --- a/tests/rustdoc/jump-to-def/jump-to-def-doc-links.rs +++ b/tests/rustdoc/jump-to-def/doc-links.rs @@ -2,7 +2,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-def-doc-links.rs.html' +//@ has 'src/foo/doc-links.rs.html' //@ has - '//a[@href="../../foo/struct.Bar.html"]' 'Bar' //@ has - '//a[@href="../../foo/struct.Foo.html"]' 'Foo' diff --git a/tests/rustdoc/jump-to-def/jump-to-def-macro.rs b/tests/rustdoc/jump-to-def/jump-to-def-macro.rs deleted file mode 100644 index 680477937c678..0000000000000 --- a/tests/rustdoc/jump-to-def/jump-to-def-macro.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ aux-build:jump-to-def-macro.rs -//@ build-aux-docs -//@ compile-flags: -Zunstable-options --generate-link-to-definition - -#![crate_name = "foo"] - -//@ has 'src/foo/jump-to-def-macro.rs.html' - -#[macro_use] -extern crate jump_to_def_macro; - -//@ has - '//a[@href="../../jump_to_def_macro/macro.symbols.html"]' 'symbols!' -symbols! { - A = 12 -} diff --git a/tests/rustdoc/jump-to-def/macro.rs b/tests/rustdoc/jump-to-def/macro.rs new file mode 100644 index 0000000000000..fcf0c7f570d44 --- /dev/null +++ b/tests/rustdoc/jump-to-def/macro.rs @@ -0,0 +1,15 @@ +//@ aux-build:symbols.rs +//@ build-aux-docs +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/macro.rs.html' + +#[macro_use] +extern crate symbols; + +//@ has - '//a[@href="../../symbols/macro.symbols.html"]' 'symbols!' +symbols! { + A = 12 +} diff --git a/tests/rustdoc/jump-to-def-ice.rs b/tests/rustdoc/jump-to-def/no-body-items.rs similarity index 89% rename from tests/rustdoc/jump-to-def-ice.rs rename to tests/rustdoc/jump-to-def/no-body-items.rs index 5578b9af3d74f..e74640072146e 100644 --- a/tests/rustdoc/jump-to-def-ice.rs +++ b/tests/rustdoc/jump-to-def/no-body-items.rs @@ -5,7 +5,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-def-ice.rs.html' +//@ has 'src/foo/no-body-items.rs.html' pub trait A { type T; diff --git a/tests/rustdoc/jump-to-def/jump-to-non-local-method.rs b/tests/rustdoc/jump-to-def/non-local-method.rs similarity index 96% rename from tests/rustdoc/jump-to-def/jump-to-non-local-method.rs rename to tests/rustdoc/jump-to-def/non-local-method.rs index 1d6d6b8d18faa..c601f3259c4da 100644 --- a/tests/rustdoc/jump-to-def/jump-to-non-local-method.rs +++ b/tests/rustdoc/jump-to-def/non-local-method.rs @@ -2,7 +2,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-non-local-method.rs.html' +//@ has 'src/foo/non-local-method.rs.html' //@ has - '//a[@href="{{channel}}/core/sync/atomic/struct.AtomicIsize.html"]' 'std::sync::atomic::AtomicIsize' use std::sync::atomic::AtomicIsize; diff --git a/tests/rustdoc/jump-to-def/jump-to-def-pats.rs b/tests/rustdoc/jump-to-def/patterns.rs similarity index 96% rename from tests/rustdoc/jump-to-def/jump-to-def-pats.rs rename to tests/rustdoc/jump-to-def/patterns.rs index 852eba208db01..e6b354eacd126 100644 --- a/tests/rustdoc/jump-to-def/jump-to-def-pats.rs +++ b/tests/rustdoc/jump-to-def/patterns.rs @@ -4,7 +4,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-def-pats.rs.html' +//@ has 'src/foo/patterns.rs.html' use std::fmt; diff --git a/tests/rustdoc/jump-to-def/jump-to-def-prelude-types.rs b/tests/rustdoc/jump-to-def/prelude-types.rs similarity index 94% rename from tests/rustdoc/jump-to-def/jump-to-def-prelude-types.rs rename to tests/rustdoc/jump-to-def/prelude-types.rs index 43617b1bc9df7..2476d18e0b629 100644 --- a/tests/rustdoc/jump-to-def/jump-to-def-prelude-types.rs +++ b/tests/rustdoc/jump-to-def/prelude-types.rs @@ -4,7 +4,7 @@ #![crate_name = "foo"] -//@ has 'src/foo/jump-to-def-prelude-types.rs.html' +//@ has 'src/foo/prelude-types.rs.html' // FIXME: would be nice to be able to check both the class and the href at the same time so // we could check the text as well... //@ has - '//a[@class="prelude-ty"]/@href' '{{channel}}/core/result/enum.Result.html' diff --git a/tests/ui/abi/stack-protector.rs b/tests/ui/abi/stack-protector.rs index 928b49c0eea50..dd0d0d43182ea 100644 --- a/tests/ui/abi/stack-protector.rs +++ b/tests/ui/abi/stack-protector.rs @@ -6,6 +6,8 @@ //@ compile-flags: -g //@ ignore-backends: gcc +#![allow(function_casts_as_integer)] + use std::env; use std::process::{Command, ExitStatus}; diff --git a/tests/ui/array-slice-vec/slice-mut-2.stderr b/tests/ui/array-slice-vec/slice-mut-2.stderr index 228417c873dbe..49639ff1d227d 100644 --- a/tests/ui/array-slice-vec/slice-mut-2.stderr +++ b/tests/ui/array-slice-vec/slice-mut-2.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/slice-mut-2.rs:7:18 | LL | let _ = &mut x[2..4]; - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this binding's type | diff --git a/tests/ui/associated-consts/traits-associated-consts-ice-56870.rs b/tests/ui/associated-consts/traits-associated-consts-ice-56870.rs index 0c5a2b8477309..8dec3982ef205 100644 --- a/tests/ui/associated-consts/traits-associated-consts-ice-56870.rs +++ b/tests/ui/associated-consts/traits-associated-consts-ice-56870.rs @@ -2,6 +2,8 @@ //@ build-pass // Regression test for #56870: Internal compiler error (traits & associated consts) +#![allow(function_casts_as_integer)] + use std::fmt::Debug; pub trait Foo { diff --git a/tests/ui/attributes/proc-macro-unsafe.rs b/tests/ui/attributes/proc-macro-unsafe.rs new file mode 100644 index 0000000000000..7849df8256098 --- /dev/null +++ b/tests/ui/attributes/proc-macro-unsafe.rs @@ -0,0 +1,9 @@ +//@ proc-macro: external-macro-use.rs + +extern crate external_macro_use; + +#[unsafe(external_macro_use::a)] +//~^ ERROR unnecessary `unsafe` on safe attribute +fn f() {} + +fn main() {} diff --git a/tests/ui/attributes/proc-macro-unsafe.stderr b/tests/ui/attributes/proc-macro-unsafe.stderr new file mode 100644 index 0000000000000..ccc19bb01d2fe --- /dev/null +++ b/tests/ui/attributes/proc-macro-unsafe.stderr @@ -0,0 +1,8 @@ +error: unnecessary `unsafe` on safe attribute + --> $DIR/proc-macro-unsafe.rs:5:3 + | +LL | #[unsafe(external_macro_use::a)] + | ^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/unsafe/double-unsafe-attributes.rs b/tests/ui/attributes/unsafe/double-unsafe-attributes.rs index c0181d960539c..894d1327da799 100644 --- a/tests/ui/attributes/unsafe/double-unsafe-attributes.rs +++ b/tests/ui/attributes/unsafe/double-unsafe-attributes.rs @@ -1,7 +1,7 @@ #[unsafe(unsafe(no_mangle))] //~^ ERROR expected identifier, found keyword `unsafe` //~| ERROR cannot find attribute `r#unsafe` in this scope -//~| ERROR unnecessary `unsafe` +//~| ERROR `r#unsafe` is not an unsafe attribute fn a() {} fn main() {} diff --git a/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr b/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr index 846800daa5465..0825cf794083d 100644 --- a/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr +++ b/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr @@ -9,11 +9,13 @@ help: escape `unsafe` to use it as an identifier LL | #[unsafe(r#unsafe(no_mangle))] | ++ -error: unnecessary `unsafe` on safe attribute +error: `r#unsafe` is not an unsafe attribute --> $DIR/double-unsafe-attributes.rs:1:3 | LL | #[unsafe(unsafe(no_mangle))] - | ^^^^^^ + | ^^^^^^ this is not an unsafe attribute + | + = note: extraneous unsafe is not allowed in attributes error: cannot find attribute `r#unsafe` in this scope --> $DIR/double-unsafe-attributes.rs:1:10 diff --git a/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.rs b/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.rs index d9054248a292c..b74dffe9eb185 100644 --- a/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.rs +++ b/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.rs @@ -1,4 +1,4 @@ -#[unsafe(diagnostic::on_unimplemented( //~ ERROR: unnecessary `unsafe` +#[unsafe(diagnostic::on_unimplemented( //~ ERROR: `diagnostic::on_unimplemented` is not an unsafe attribute message = "testing", ))] trait Foo {} diff --git a/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.stderr b/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.stderr index a7662f5ee6c7d..3bc291db5acf8 100644 --- a/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.stderr +++ b/tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.stderr @@ -1,8 +1,10 @@ -error: unnecessary `unsafe` on safe attribute +error: `diagnostic::on_unimplemented` is not an unsafe attribute --> $DIR/unsafe-safe-attribute_diagnostic.rs:1:3 | LL | #[unsafe(diagnostic::on_unimplemented( - | ^^^^^^ + | ^^^^^^ this is not an unsafe attribute + | + = note: extraneous unsafe is not allowed in attributes error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/accidentally-cloning-ref-borrow-error.stderr b/tests/ui/borrowck/accidentally-cloning-ref-borrow-error.stderr index 7e51a4819eef6..e7b103eef9348 100644 --- a/tests/ui/borrowck/accidentally-cloning-ref-borrow-error.stderr +++ b/tests/ui/borrowck/accidentally-cloning-ref-borrow-error.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `sm.x` as mutable, as it is behind a `&` reference --> $DIR/accidentally-cloning-ref-borrow-error.rs:32:9 | LL | foo(&mut sm.x); - | ^^^^^^^^^ `sm` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^ `sm` is a `&` reference, so it cannot be borrowed as mutable | help: `Str` doesn't implement `Clone`, so this call clones the reference `&Str` --> $DIR/accidentally-cloning-ref-borrow-error.rs:31:21 diff --git a/tests/ui/borrowck/argument_number_mismatch_ice.stderr b/tests/ui/borrowck/argument_number_mismatch_ice.stderr index 702cebb86bae2..f2f4567f7150f 100644 --- a/tests/ui/borrowck/argument_number_mismatch_ice.stderr +++ b/tests/ui/borrowck/argument_number_mismatch_ice.stderr @@ -11,7 +11,7 @@ error[E0594]: cannot assign to `*input`, which is behind a `&` reference --> $DIR/argument_number_mismatch_ice.rs:10:9 | LL | *input = self.0; - | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition | diff --git a/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr b/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr index 0a32cccff1d4c..d796d541ab209 100644 --- a/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr +++ b/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrow-raw-address-of-deref-mutability.rs:6:13 | LL | let q = &raw mut *x; - | ^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -13,7 +13,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer --> $DIR/borrow-raw-address-of-deref-mutability.rs:12:13 | LL | let q = &raw mut *x; - | ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `x` is a `*const` pointer, so it cannot be borrowed as mutable | help: consider specifying this binding's type | diff --git a/tests/ui/borrowck/borrowck-access-permissions.stderr b/tests/ui/borrowck/borrowck-access-permissions.stderr index 87717a5329052..376b6bd271261 100644 --- a/tests/ui/borrowck/borrowck-access-permissions.stderr +++ b/tests/ui/borrowck/borrowck-access-permissions.stderr @@ -12,6 +12,9 @@ LL | let mut x = 1; error[E0596]: cannot borrow immutable static item `static_x` as mutable --> $DIR/borrowck-access-permissions.rs:16:19 | +LL | static static_x: i32 = 1; + | -------------------- this `static` cannot be borrowed as mutable +... LL | let _y1 = &mut static_x; | ^^^^^^^^^^^^^ cannot borrow as mutable @@ -30,7 +33,7 @@ error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-access-permissions.rs:36:19 | LL | let _y1 = &mut *ref_x; - | ^^^^^^^^^^^ `ref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `ref_x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -41,7 +44,7 @@ error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` poin --> $DIR/borrowck-access-permissions.rs:46:23 | LL | let _y1 = &mut *ptr_x; - | ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so it cannot be borrowed as mutable | help: consider changing this binding's type | @@ -53,7 +56,7 @@ error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` refer --> $DIR/borrowck-access-permissions.rs:59:18 | LL | let _y = &mut *foo_ref.f; - | ^^^^^^^^^^^^^^^ `foo_ref` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^^^^ `foo_ref` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr b/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr index cf0c4127d82f4..62d456c5510a2 100644 --- a/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr +++ b/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference --> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:9:5 | LL | *s.pointer += 1; - | ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^ `s` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -13,7 +13,7 @@ error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference --> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5 | LL | *s.pointer += 1; - | ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^ `s` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/borrowck-assign-to-constants.stderr b/tests/ui/borrowck/borrowck-assign-to-constants.stderr index 82972b573c6f7..6bfed855f95a3 100644 --- a/tests/ui/borrowck/borrowck-assign-to-constants.stderr +++ b/tests/ui/borrowck/borrowck-assign-to-constants.stderr @@ -1,6 +1,9 @@ error[E0594]: cannot assign to immutable static item `foo` --> $DIR/borrowck-assign-to-constants.rs:5:5 | +LL | static foo: isize = 5; + | ----------------- this `static` cannot be written to +... LL | foo = 6; | ^^^^^^^ cannot assign diff --git a/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr b/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr index 59ef61b19d501..7e516fe89b40c 100644 --- a/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr +++ b/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `**t1`, which is behind a `&` reference --> $DIR/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs:9:5 | LL | **t1 = 22; - | ^^^^^^^^^ `t1` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^ `t1` is a `&` reference, so it cannot be written to | help: consider specifying this binding's type | @@ -23,7 +23,7 @@ error[E0596]: cannot borrow `**t0` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs:19:26 | LL | let x: &mut isize = &mut **t0; - | ^^^^^^^^^ `t0` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^ `t0` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/borrowck-issue-14498.stderr b/tests/ui/borrowck/borrowck-issue-14498.stderr index 12d67d536d951..a79fd3c74f896 100644 --- a/tests/ui/borrowck/borrowck-issue-14498.stderr +++ b/tests/ui/borrowck/borrowck-issue-14498.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `***p`, which is behind a `&` reference --> $DIR/borrowck-issue-14498.rs:16:5 | LL | ***p = 2; - | ^^^^^^^^ `p` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^ `p` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr b/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr index fb3db4e144635..cd576aafb383f 100644 --- a/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr +++ b/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr @@ -106,7 +106,7 @@ error[E0596]: cannot borrow `foo.bar1` as mutable, as it is behind a `&` referen --> $DIR/borrowck-reborrow-from-mut.rs:88:17 | LL | let _bar1 = &mut foo.bar1; - | ^^^^^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^^ `foo` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr b/tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr index 61c01f0f024fe..8191f1f4394b7 100644 --- a/tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr +++ b/tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `**layer` as mutable, as it is behind a `&` referenc --> $DIR/issue-115259-suggest-iter-mut.rs:15:65 | LL | self.layers.iter().fold(0, |result, mut layer| result + layer.process()) - | --------- ^^^^^ `layer` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | --------- ^^^^^ `layer` is a `&` reference, so it cannot be borrowed as mutable | | | consider changing this binding's type to be: `&mut Box` | diff --git a/tests/ui/borrowck/issue-42344.stderr b/tests/ui/borrowck/issue-42344.stderr index bf82d462b51bc..e7e98d281302b 100644 --- a/tests/ui/borrowck/issue-42344.stderr +++ b/tests/ui/borrowck/issue-42344.stderr @@ -1,6 +1,9 @@ error[E0596]: cannot borrow `*TAB[_]` as mutable, as `TAB` is an immutable static item --> $DIR/issue-42344.rs:4:5 | +LL | static TAB: [&mut [u8]; 0] = []; + | -------------------------- this `static` cannot be borrowed as mutable +... LL | TAB[0].iter_mut(); | ^^^^^^ cannot borrow as mutable diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr index c6955317d87d5..29121b85f3a08 100644 --- a/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*container` as mutable, as it is behind a `&` refer --> $DIR/issue-62387-suggest-iter-mut-2.rs:30:45 | LL | vec.iter().flat_map(|container| container.things()).cloned().collect::>(); - | --------- ^^^^^^^^^ `container` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | --------- ^^^^^^^^^ `container` is a `&` reference, so it cannot be borrowed as mutable | | | consider changing this binding's type to be: `&mut Container` | diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr b/tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr index ae4920b2a8cb0..55c17ab6cdea1 100644 --- a/tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/issue-62387-suggest-iter-mut.rs:18:27 | LL | v.iter().for_each(|a| a.double()); - | - ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | - ^ `a` is a `&` reference, so it cannot be borrowed as mutable | | | consider changing this binding's type to be: `&mut A` | @@ -15,7 +15,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/issue-62387-suggest-iter-mut.rs:25:39 | LL | v.iter().rev().rev().for_each(|a| a.double()); - | - ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | - ^ `a` is a `&` reference, so it cannot be borrowed as mutable | | | consider changing this binding's type to be: `&mut A` | diff --git a/tests/ui/borrowck/issue-69789-iterator-mut-suggestion.stderr b/tests/ui/borrowck/issue-69789-iterator-mut-suggestion.stderr index 87b8e05913528..048ed80fd82f3 100644 --- a/tests/ui/borrowck/issue-69789-iterator-mut-suggestion.stderr +++ b/tests/ui/borrowck/issue-69789-iterator-mut-suggestion.stderr @@ -5,7 +5,7 @@ LL | for item in &mut std::iter::empty::<&'static ()>() { | -------------------------------------- this iterator yields `&` references LL | LL | *item = (); - | ^^^^^^^^^^ `item` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^ `item` is a `&` reference, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/issue-82032.stderr b/tests/ui/borrowck/issue-82032.stderr index 2ac785cd1e3bd..d44b5e1b35f50 100644 --- a/tests/ui/borrowck/issue-82032.stderr +++ b/tests/ui/borrowck/issue-82032.stderr @@ -7,7 +7,7 @@ LL | for v in self.0.values() { | | help: use mutable method: `values_mut()` | this iterator yields `&` references LL | v.flush(); - | ^ `v` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `v` is a `&` reference, so it cannot be borrowed as mutable error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.rs b/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.rs index d301e7b3524b8..f11eb65614a65 100644 --- a/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.rs +++ b/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.rs @@ -10,7 +10,7 @@ fn main() { //~^ NOTE this iterator yields `&` references *v -= 1; //~^ ERROR cannot assign to `*v`, which is behind a `&` reference - //~| NOTE `v` is a `&` reference, so the data it refers to cannot be written + //~| NOTE `v` is a `&` reference, so it cannot be written to } } diff --git a/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.stderr b/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.stderr index 4e7a9b695e179..0860f0c3afdfc 100644 --- a/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.stderr +++ b/tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.stderr @@ -5,7 +5,7 @@ LL | for v in Query.iter_mut() { | ---------------- this iterator yields `&` references LL | LL | *v -= 1; - | ^^^^^^^ `v` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `v` is a `&` reference, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/issue-85765-closure.rs b/tests/ui/borrowck/issue-85765-closure.rs index f2d1dd0fbc3fb..09b2d6c939a2b 100644 --- a/tests/ui/borrowck/issue-85765-closure.rs +++ b/tests/ui/borrowck/issue-85765-closure.rs @@ -5,27 +5,27 @@ fn main() { //~^ HELP consider changing this binding's type rofl.push(Vec::new()); //~^ ERROR cannot borrow `*rofl` as mutable, as it is behind a `&` reference - //~| NOTE `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable + //~| NOTE `rofl` is a `&` reference, so it cannot be borrowed as mutable let mut mutvar = 42; let r = &mutvar; //~^ HELP consider changing this to be a mutable reference *r = 0; //~^ ERROR cannot assign to `*r`, which is behind a `&` reference - //~| NOTE `r` is a `&` reference, so the data it refers to cannot be written + //~| NOTE `r` is a `&` reference, so it cannot be written to #[rustfmt::skip] let x: &usize = &mut{0}; //~^ HELP consider changing this binding's type *x = 1; //~^ ERROR cannot assign to `*x`, which is behind a `&` reference - //~| NOTE `x` is a `&` reference, so the data it refers to cannot be written + //~| NOTE `x` is a `&` reference, so it cannot be written to #[rustfmt::skip] let y: &usize = &mut(0); //~^ HELP consider changing this binding's type *y = 1; //~^ ERROR cannot assign to `*y`, which is behind a `&` reference - //~| NOTE `y` is a `&` reference, so the data it refers to cannot be written + //~| NOTE `y` is a `&` reference, so it cannot be written to }; } diff --git a/tests/ui/borrowck/issue-85765-closure.stderr b/tests/ui/borrowck/issue-85765-closure.stderr index cd2544ec5c952..1b1cd9cabb68c 100644 --- a/tests/ui/borrowck/issue-85765-closure.stderr +++ b/tests/ui/borrowck/issue-85765-closure.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*rofl` as mutable, as it is behind a `&` reference --> $DIR/issue-85765-closure.rs:6:9 | LL | rofl.push(Vec::new()); - | ^^^^ `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^ `rofl` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this binding's type | @@ -13,7 +13,7 @@ error[E0594]: cannot assign to `*r`, which is behind a `&` reference --> $DIR/issue-85765-closure.rs:13:9 | LL | *r = 0; - | ^^^^^^ `r` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^ `r` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -24,7 +24,7 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/issue-85765-closure.rs:20:9 | LL | *x = 1; - | ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^ `x` is a `&` reference, so it cannot be written to | help: consider changing this binding's type | @@ -35,7 +35,7 @@ error[E0594]: cannot assign to `*y`, which is behind a `&` reference --> $DIR/issue-85765-closure.rs:27:9 | LL | *y = 1; - | ^^^^^^ `y` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^ `y` is a `&` reference, so it cannot be written to | help: consider changing this binding's type | diff --git a/tests/ui/borrowck/issue-85765.rs b/tests/ui/borrowck/issue-85765.rs index 76e0b51735416..22e3882a8c781 100644 --- a/tests/ui/borrowck/issue-85765.rs +++ b/tests/ui/borrowck/issue-85765.rs @@ -4,26 +4,26 @@ fn main() { //~^ HELP consider changing this binding's type rofl.push(Vec::new()); //~^ ERROR cannot borrow `*rofl` as mutable, as it is behind a `&` reference - //~| NOTE `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable + //~| NOTE `rofl` is a `&` reference, so it cannot be borrowed as mutable let mut mutvar = 42; let r = &mutvar; //~^ HELP consider changing this to be a mutable reference *r = 0; //~^ ERROR cannot assign to `*r`, which is behind a `&` reference - //~| NOTE `r` is a `&` reference, so the data it refers to cannot be written + //~| NOTE `r` is a `&` reference, so it cannot be written to #[rustfmt::skip] let x: &usize = &mut{0}; //~^ HELP consider changing this binding's type *x = 1; //~^ ERROR cannot assign to `*x`, which is behind a `&` reference - //~| NOTE `x` is a `&` reference, so the data it refers to cannot be written + //~| NOTE `x` is a `&` reference, so it cannot be written to #[rustfmt::skip] let y: &usize = &mut(0); //~^ HELP consider changing this binding's type *y = 1; //~^ ERROR cannot assign to `*y`, which is behind a `&` reference - //~| NOTE `y` is a `&` reference, so the data it refers to cannot be written + //~| NOTE `y` is a `&` reference, so it cannot be written to } diff --git a/tests/ui/borrowck/issue-85765.stderr b/tests/ui/borrowck/issue-85765.stderr index e252f3d44d976..6567891fde61b 100644 --- a/tests/ui/borrowck/issue-85765.stderr +++ b/tests/ui/borrowck/issue-85765.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*rofl` as mutable, as it is behind a `&` reference --> $DIR/issue-85765.rs:5:5 | LL | rofl.push(Vec::new()); - | ^^^^ `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^ `rofl` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this binding's type | @@ -13,7 +13,7 @@ error[E0594]: cannot assign to `*r`, which is behind a `&` reference --> $DIR/issue-85765.rs:12:5 | LL | *r = 0; - | ^^^^^^ `r` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^ `r` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -24,7 +24,7 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/issue-85765.rs:19:5 | LL | *x = 1; - | ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^ `x` is a `&` reference, so it cannot be written to | help: consider changing this binding's type | @@ -35,7 +35,7 @@ error[E0594]: cannot assign to `*y`, which is behind a `&` reference --> $DIR/issue-85765.rs:26:5 | LL | *y = 1; - | ^^^^^^ `y` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^ `y` is a `&` reference, so it cannot be written to | help: consider changing this binding's type | diff --git a/tests/ui/borrowck/issue-91206.rs b/tests/ui/borrowck/issue-91206.rs index e062a253767de..4f876853610ea 100644 --- a/tests/ui/borrowck/issue-91206.rs +++ b/tests/ui/borrowck/issue-91206.rs @@ -12,5 +12,5 @@ fn main() { //~^ HELP consider specifying this binding's type inner.clear(); //~^ ERROR cannot borrow `*inner` as mutable, as it is behind a `&` reference [E0596] - //~| NOTE `inner` is a `&` reference, so the data it refers to cannot be borrowed as mutable + //~| NOTE `inner` is a `&` reference, so it cannot be borrowed as mutable } diff --git a/tests/ui/borrowck/issue-91206.stderr b/tests/ui/borrowck/issue-91206.stderr index f96b0c7d9e1a6..ebd9ace34bcdd 100644 --- a/tests/ui/borrowck/issue-91206.stderr +++ b/tests/ui/borrowck/issue-91206.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*inner` as mutable, as it is behind a `&` reference --> $DIR/issue-91206.rs:13:5 | LL | inner.clear(); - | ^^^^^ `inner` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^ `inner` is a `&` reference, so it cannot be borrowed as mutable | help: consider specifying this binding's type | diff --git a/tests/ui/borrowck/issue-92015.stderr b/tests/ui/borrowck/issue-92015.stderr index 167a5cf5863c6..cfd30b8337841 100644 --- a/tests/ui/borrowck/issue-92015.stderr +++ b/tests/ui/borrowck/issue-92015.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*foo`, which is behind a `&` reference --> $DIR/issue-92015.rs:6:5 | LL | *foo = 1; - | ^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^ `foo` is a `&` reference, so it cannot be written to | help: consider specifying this binding's type | diff --git a/tests/ui/borrowck/issue-93093.stderr b/tests/ui/borrowck/issue-93093.stderr index d788ce331973c..02239627a8932 100644 --- a/tests/ui/borrowck/issue-93093.stderr +++ b/tests/ui/borrowck/issue-93093.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `self.foo`, which is behind a `&` reference --> $DIR/issue-93093.rs:8:9 | LL | self.foo += 1; - | ^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^ `self` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/mutability-errors.stderr b/tests/ui/borrowck/mutability-errors.stderr index 7307e1f2a86b2..18d8e6eb1a6e7 100644 --- a/tests/ui/borrowck/mutability-errors.stderr +++ b/tests/ui/borrowck/mutability-errors.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/mutability-errors.rs:9:5 | LL | *x = (1,); - | ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^ `x` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -13,7 +13,7 @@ error[E0594]: cannot assign to `x.0`, which is behind a `&` reference --> $DIR/mutability-errors.rs:10:5 | LL | x.0 = 1; - | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `x` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -24,7 +24,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/mutability-errors.rs:11:5 | LL | &mut *x; - | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -35,7 +35,7 @@ error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `&` reference --> $DIR/mutability-errors.rs:12:5 | LL | &mut x.0; - | ^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -70,7 +70,7 @@ error[E0594]: cannot assign to `*x`, which is behind a `*const` pointer --> $DIR/mutability-errors.rs:23:5 | LL | *x = (1,); - | ^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be written + | ^^^^^^^^^ `x` is a `*const` pointer, so it cannot be written to | help: consider changing this to be a mutable pointer | @@ -81,7 +81,7 @@ error[E0594]: cannot assign to `x.0`, which is behind a `*const` pointer --> $DIR/mutability-errors.rs:24:5 | LL | (*x).0 = 1; - | ^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be written + | ^^^^^^^^^^ `x` is a `*const` pointer, so it cannot be written to | help: consider changing this to be a mutable pointer | @@ -92,7 +92,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer --> $DIR/mutability-errors.rs:25:5 | LL | &mut *x; - | ^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^ `x` is a `*const` pointer, so it cannot be borrowed as mutable | help: consider changing this to be a mutable pointer | @@ -103,7 +103,7 @@ error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `*const` pointer --> $DIR/mutability-errors.rs:26:5 | LL | &mut (*x).0; - | ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `x` is a `*const` pointer, so it cannot be borrowed as mutable | help: consider changing this to be a mutable pointer | @@ -358,24 +358,36 @@ LL | fn imm_capture(mut x: (i32,)) { error[E0594]: cannot assign to immutable static item `X` --> $DIR/mutability-errors.rs:76:5 | +LL | static X: (i32,) = (0,); + | ---------------- this `static` cannot be written to +... LL | X = (1,); | ^^^^^^^^ cannot assign error[E0594]: cannot assign to `X.0`, as `X` is an immutable static item --> $DIR/mutability-errors.rs:77:5 | +LL | static X: (i32,) = (0,); + | ---------------- this `static` cannot be written to +... LL | X.0 = 1; | ^^^^^^^ cannot assign error[E0596]: cannot borrow immutable static item `X` as mutable --> $DIR/mutability-errors.rs:78:5 | +LL | static X: (i32,) = (0,); + | ---------------- this `static` cannot be borrowed as mutable +... LL | &mut X; | ^^^^^^ cannot borrow as mutable error[E0596]: cannot borrow `X.0` as mutable, as `X` is an immutable static item --> $DIR/mutability-errors.rs:79:5 | +LL | static X: (i32,) = (0,); + | ---------------- this `static` cannot be borrowed as mutable +... LL | &mut X.0; | ^^^^^^^^ cannot borrow as mutable diff --git a/tests/ui/borrowck/mutable-borrow-behind-reference-61623.stderr b/tests/ui/borrowck/mutable-borrow-behind-reference-61623.stderr index cc7761acda9de..0357b7c6df8ce 100644 --- a/tests/ui/borrowck/mutable-borrow-behind-reference-61623.stderr +++ b/tests/ui/borrowck/mutable-borrow-behind-reference-61623.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*x.1` as mutable, as it is behind a `&` reference --> $DIR/mutable-borrow-behind-reference-61623.rs:7:19 | LL | f2(|| x.0, f1(x.1)) - | ^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr index 9bcfbd3379559..208e73235873b 100644 --- a/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr +++ b/tests/ui/borrowck/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer --> $DIR/no-invalid-mut-suggestion-for-raw-pointer-issue-127562.rs:7:14 | LL | unsafe { *ptr = 3; } - | ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written + | ^^^^^^^^ `ptr` is a `*const` pointer, so it cannot be written to | help: consider changing this to be a mutable pointer | diff --git a/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr b/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr index 1e98006a9a71e..ca0d0bd8a3caa 100644 --- a/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr +++ b/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr @@ -18,7 +18,7 @@ error[E0596]: cannot borrow `*cb` as mutable, as it is behind a `&` reference --> $DIR/suggest-as-ref-on-mut-closure.rs:12:26 | LL | cb.as_ref().map(|cb| cb()); - | -- ^^ `cb` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | -- ^^ `cb` is a `&` reference, so it cannot be borrowed as mutable | | | consider changing this binding's type to be: `&mut &mut dyn FnMut()` diff --git a/tests/ui/borrowck/suggest-mut-iterator.stderr b/tests/ui/borrowck/suggest-mut-iterator.stderr index b396bb7b5ec4c..bdb5fbfd2bcd6 100644 --- a/tests/ui/borrowck/suggest-mut-iterator.stderr +++ b/tests/ui/borrowck/suggest-mut-iterator.stderr @@ -4,7 +4,7 @@ error[E0596]: cannot borrow `*test` as mutable, as it is behind a `&` reference LL | for test in &tests { | ------ this iterator yields `&` references LL | test.add(2); - | ^^^^ `test` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^ `test` is a `&` reference, so it cannot be borrowed as mutable | help: use a mutable iterator instead | diff --git a/tests/ui/borrowck/suggestions/overloaded-index-not-mut-but-should-be-mut.stderr b/tests/ui/borrowck/suggestions/overloaded-index-not-mut-but-should-be-mut.stderr index 44cc9aefcf187..8ddc7368793cd 100644 --- a/tests/ui/borrowck/suggestions/overloaded-index-not-mut-but-should-be-mut.stderr +++ b/tests/ui/borrowck/suggestions/overloaded-index-not-mut-but-should-be-mut.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*string` as mutable, as it is behind a `&` referenc --> $DIR/overloaded-index-not-mut-but-should-be-mut.rs:7:5 | LL | string.push_str("test"); - | ^^^^^^ `string` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^ `string` is a `&` reference, so it cannot be borrowed as mutable | help: consider using `get_mut` | @@ -14,7 +14,7 @@ error[E0596]: cannot borrow `*string` as mutable, as it is behind a `&` referenc --> $DIR/overloaded-index-not-mut-but-should-be-mut.rs:14:5 | LL | string.push_str("test"); - | ^^^^^^ `string` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^ `string` is a `&` reference, so it cannot be borrowed as mutable | help: consider using `get_mut` | @@ -26,7 +26,7 @@ error[E0596]: cannot borrow `*string` as mutable, as it is behind a `&` referenc --> $DIR/overloaded-index-not-mut-but-should-be-mut.rs:19:5 | LL | string.push_str("test"); - | ^^^^^^ `string` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^ `string` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/borrowck/suggestions/overloaded-index-without-indexmut.stderr b/tests/ui/borrowck/suggestions/overloaded-index-without-indexmut.stderr index 6a46332a5d7b7..7e952d69945c4 100644 --- a/tests/ui/borrowck/suggestions/overloaded-index-without-indexmut.stderr +++ b/tests/ui/borrowck/suggestions/overloaded-index-without-indexmut.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*y` as mutable, as it is behind a `&` reference --> $DIR/overloaded-index-without-indexmut.rs:14:5 | LL | y.push_str(""); - | ^ `y` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `y` is a `&` reference, so it cannot be borrowed as mutable error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/trait-impl-argument-difference-ice.stderr b/tests/ui/borrowck/trait-impl-argument-difference-ice.stderr index 3d54d5269ae2b..90d9ee3f32af0 100644 --- a/tests/ui/borrowck/trait-impl-argument-difference-ice.stderr +++ b/tests/ui/borrowck/trait-impl-argument-difference-ice.stderr @@ -36,7 +36,7 @@ error[E0596]: cannot borrow `*self` as mutable, as it is behind a `&` reference --> $DIR/trait-impl-argument-difference-ice.rs:16:19 | LL | let a16 = self.read_word() as u16; - | ^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^ `self` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition | @@ -47,7 +47,7 @@ error[E0596]: cannot borrow `*self` as mutable, as it is behind a `&` reference --> $DIR/trait-impl-argument-difference-ice.rs:18:19 | LL | let b16 = self.read_word() as u16; - | ^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^ `self` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition | diff --git a/tests/ui/c-variadic/issue-86053-1.rs b/tests/ui/c-variadic/issue-86053-1.rs index 58dfee55cf885..e63d348dbb3bc 100644 --- a/tests/ui/c-variadic/issue-86053-1.rs +++ b/tests/ui/c-variadic/issue-86053-1.rs @@ -8,7 +8,7 @@ fn ordering4 < 'a , 'b > ( a : , self , self , self , //~| ERROR unexpected `self` parameter in function //~| ERROR unexpected `self` parameter in function //~| ERROR unexpected `self` parameter in function - self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) { //~^ ERROR unexpected `self` parameter in function //~| ERROR unexpected `self` parameter in function //~| ERROR unexpected `self` parameter in function diff --git a/tests/ui/c-variadic/issue-86053-1.stderr b/tests/ui/c-variadic/issue-86053-1.stderr index adbc04d3a65a4..05b19624129e4 100644 --- a/tests/ui/c-variadic/issue-86053-1.stderr +++ b/tests/ui/c-variadic/issue-86053-1.stderr @@ -25,48 +25,48 @@ LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , error: unexpected `self` parameter in function --> $DIR/issue-86053-1.rs:11:5 | -LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { +LL | self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) { | ^^^^ must be the first parameter of an associated function error: unexpected `self` parameter in function - --> $DIR/issue-86053-1.rs:11:20 + --> $DIR/issue-86053-1.rs:11:23 | -LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { - | ^^^^ must be the first parameter of an associated function +LL | self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ must be the first parameter of an associated function error: unexpected `self` parameter in function - --> $DIR/issue-86053-1.rs:11:29 + --> $DIR/issue-86053-1.rs:11:32 | -LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { - | ^^^^ must be the first parameter of an associated function +LL | self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ must be the first parameter of an associated function error: `...` must be the last argument of a C-variadic function --> $DIR/issue-86053-1.rs:11:12 | -LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { - | ^^^ +LL | self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^^^ error: `...` is not supported for non-extern functions - --> $DIR/issue-86053-1.rs:11:36 + --> $DIR/issue-86053-1.rs:11:39 | -LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { - | ^^^ +LL | self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error[E0412]: cannot find type `F` in this scope - --> $DIR/issue-86053-1.rs:11:48 + --> $DIR/issue-86053-1.rs:11:54 | -LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { - | ^ +LL | self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^ | --> $SRC_DIR/core/src/ops/function.rs:LL:COL | = note: similarly named trait `Fn` defined here help: a trait with a similar name exists | -LL | self , ... , self , self , ... ) where Fn : FnOnce ( & 'a & 'b usize ) { - | + +LL | self , _: ... , self , self , _: ... ) where Fn : FnOnce ( & 'a & 'b usize ) { + | + help: you might be missing a type parameter | LL | fn ordering4 < 'a , 'b, F > ( a : , self , self , self , diff --git a/tests/ui/c-variadic/issue-86053-2.rs b/tests/ui/c-variadic/issue-86053-2.rs index c545831f7171a..0914676a35f4f 100644 --- a/tests/ui/c-variadic/issue-86053-2.rs +++ b/tests/ui/c-variadic/issue-86053-2.rs @@ -5,7 +5,7 @@ trait H {} -unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} +unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), _: ...) {} //~^ ERROR: in type `&'static &'a ()`, reference has a longer lifetime than the data it references [E0491] fn main() {} diff --git a/tests/ui/c-variadic/issue-86053-2.stderr b/tests/ui/c-variadic/issue-86053-2.stderr index 2c4be2522f614..823dadff6f895 100644 --- a/tests/ui/c-variadic/issue-86053-2.stderr +++ b/tests/ui/c-variadic/issue-86053-2.stderr @@ -1,14 +1,14 @@ error[E0491]: in type `&'static &'a ()`, reference has a longer lifetime than the data it references --> $DIR/issue-86053-2.rs:8:39 | -LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} +LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), _: ...) {} | ^^^^^^^^^^^^^^^^^^ | = note: the pointer is valid for the static lifetime note: but the referenced data is only valid for the lifetime `'a` as defined here --> $DIR/issue-86053-2.rs:8:32 | -LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} +LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), _: ...) {} | ^^ error: aborting due to 1 previous error diff --git a/tests/ui/c-variadic/not-async.rs b/tests/ui/c-variadic/not-async.rs index bdb51a9a43232..a4ad9c6bceb54 100644 --- a/tests/ui/c-variadic/not-async.rs +++ b/tests/ui/c-variadic/not-async.rs @@ -2,14 +2,14 @@ #![feature(c_variadic)] #![crate_type = "lib"] -async unsafe extern "C" fn fn_cannot_be_async(x: isize, ...) {} +async unsafe extern "C" fn fn_cannot_be_async(x: isize, _: ...) {} //~^ ERROR functions cannot be both `async` and C-variadic //~| ERROR hidden type for `impl Future` captures lifetime that does not appear in bounds struct S; impl S { - async unsafe extern "C" fn method_cannot_be_async(x: isize, ...) {} + async unsafe extern "C" fn method_cannot_be_async(x: isize, _: ...) {} //~^ ERROR functions cannot be both `async` and C-variadic //~| ERROR hidden type for `impl Future` captures lifetime that does not appear in bounds } diff --git a/tests/ui/c-variadic/not-async.stderr b/tests/ui/c-variadic/not-async.stderr index eab4c4f0822c4..fc5eb10bec4f7 100644 --- a/tests/ui/c-variadic/not-async.stderr +++ b/tests/ui/c-variadic/not-async.stderr @@ -1,30 +1,30 @@ error: functions cannot be both `async` and C-variadic --> $DIR/not-async.rs:5:1 | -LL | async unsafe extern "C" fn fn_cannot_be_async(x: isize, ...) {} - | ^^^^^ `async` because of this ^^^ C-variadic because of this +LL | async unsafe extern "C" fn fn_cannot_be_async(x: isize, _: ...) {} + | ^^^^^ `async` because of this ^^^^^^ C-variadic because of this error: functions cannot be both `async` and C-variadic --> $DIR/not-async.rs:12:5 | -LL | async unsafe extern "C" fn method_cannot_be_async(x: isize, ...) {} - | ^^^^^ `async` because of this ^^^ C-variadic because of this +LL | async unsafe extern "C" fn method_cannot_be_async(x: isize, _: ...) {} + | ^^^^^ `async` because of this ^^^^^^ C-variadic because of this error[E0700]: hidden type for `impl Future` captures lifetime that does not appear in bounds - --> $DIR/not-async.rs:5:62 + --> $DIR/not-async.rs:5:65 | -LL | async unsafe extern "C" fn fn_cannot_be_async(x: isize, ...) {} - | ------------------------------------------------------------ ^^ +LL | async unsafe extern "C" fn fn_cannot_be_async(x: isize, _: ...) {} + | --------------------------------------------------------------- ^^ | | | opaque type defined here | = note: hidden type `{async fn body of fn_cannot_be_async()}` captures lifetime `'_` error[E0700]: hidden type for `impl Future` captures lifetime that does not appear in bounds - --> $DIR/not-async.rs:12:70 + --> $DIR/not-async.rs:12:73 | -LL | async unsafe extern "C" fn method_cannot_be_async(x: isize, ...) {} - | ---------------------------------------------------------------- ^^ +LL | async unsafe extern "C" fn method_cannot_be_async(x: isize, _: ...) {} + | ------------------------------------------------------------------- ^^ | | | opaque type defined here | diff --git a/tests/ui/c-variadic/parse-errors.e2015.fixed b/tests/ui/c-variadic/parse-errors.e2015.fixed new file mode 100644 index 0000000000000..042736cdf6c0d --- /dev/null +++ b/tests/ui/c-variadic/parse-errors.e2015.fixed @@ -0,0 +1,36 @@ +//@ check-fail +//@ run-rustfix +//@ revisions: e2015 e2018 +//@[e2015] edition: 2015 +//@[e2018] edition: 2018 +#![crate_type = "lib"] +#![deny(varargs_without_pattern)] + +#[cfg(false)] +mod module { + unsafe extern "C" fn f(_: ...) { + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + unsafe extern "C" fn f(_: ...) {} + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + } + + impl A { + unsafe extern "C" fn f(_: ...) {} + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + } + + trait A { + unsafe extern "C" fn f(...) {} + //[e2018]~^ ERROR missing pattern for `...` argument + //[e2018]~| WARN this was previously accepted by the compiler + } + + unsafe extern "C" { + fn f(...); // no error + } + + type A = unsafe extern "C" fn(...); // no error +} diff --git a/tests/ui/c-variadic/parse-errors.e2015.stderr b/tests/ui/c-variadic/parse-errors.e2015.stderr new file mode 100644 index 0000000000000..de9362c4380de --- /dev/null +++ b/tests/ui/c-variadic/parse-errors.e2015.stderr @@ -0,0 +1,46 @@ +error: missing pattern for `...` argument + --> $DIR/parse-errors.rs:11:28 + | +LL | unsafe extern "C" fn f(...) { + | ^^^ + | + = 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 #145544 +note: the lint level is defined here + --> $DIR/parse-errors.rs:7:9 + | +LL | #![deny(varargs_without_pattern)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: name the argument, or use `_` to continue ignoring it + | +LL | unsafe extern "C" fn f(_: ...) { + | ++ + +error: missing pattern for `...` argument + --> $DIR/parse-errors.rs:14:32 + | +LL | unsafe extern "C" fn f(...) {} + | ^^^ + | + = 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 #145544 +help: name the argument, or use `_` to continue ignoring it + | +LL | unsafe extern "C" fn f(_: ...) {} + | ++ + +error: missing pattern for `...` argument + --> $DIR/parse-errors.rs:20:32 + | +LL | unsafe extern "C" fn f(...) {} + | ^^^ + | + = 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 #145544 +help: name the argument, or use `_` to continue ignoring it + | +LL | unsafe extern "C" fn f(_: ...) {} + | ++ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/c-variadic/parse-errors.e2018.fixed b/tests/ui/c-variadic/parse-errors.e2018.fixed new file mode 100644 index 0000000000000..596e57ca5614b --- /dev/null +++ b/tests/ui/c-variadic/parse-errors.e2018.fixed @@ -0,0 +1,36 @@ +//@ check-fail +//@ run-rustfix +//@ revisions: e2015 e2018 +//@[e2015] edition: 2015 +//@[e2018] edition: 2018 +#![crate_type = "lib"] +#![deny(varargs_without_pattern)] + +#[cfg(false)] +mod module { + unsafe extern "C" fn f(_: ...) { + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + unsafe extern "C" fn f(_: ...) {} + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + } + + impl A { + unsafe extern "C" fn f(_: ...) {} + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + } + + trait A { + unsafe extern "C" fn f(_: ...) {} + //[e2018]~^ ERROR missing pattern for `...` argument + //[e2018]~| WARN this was previously accepted by the compiler + } + + unsafe extern "C" { + fn f(...); // no error + } + + type A = unsafe extern "C" fn(...); // no error +} diff --git a/tests/ui/c-variadic/parse-errors.e2018.stderr b/tests/ui/c-variadic/parse-errors.e2018.stderr new file mode 100644 index 0000000000000..a7d5f79bf1339 --- /dev/null +++ b/tests/ui/c-variadic/parse-errors.e2018.stderr @@ -0,0 +1,59 @@ +error: missing pattern for `...` argument + --> $DIR/parse-errors.rs:11:28 + | +LL | unsafe extern "C" fn f(...) { + | ^^^ + | + = 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 #145544 +note: the lint level is defined here + --> $DIR/parse-errors.rs:7:9 + | +LL | #![deny(varargs_without_pattern)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: name the argument, or use `_` to continue ignoring it + | +LL | unsafe extern "C" fn f(_: ...) { + | ++ + +error: missing pattern for `...` argument + --> $DIR/parse-errors.rs:14:32 + | +LL | unsafe extern "C" fn f(...) {} + | ^^^ + | + = 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 #145544 +help: name the argument, or use `_` to continue ignoring it + | +LL | unsafe extern "C" fn f(_: ...) {} + | ++ + +error: missing pattern for `...` argument + --> $DIR/parse-errors.rs:20:32 + | +LL | unsafe extern "C" fn f(...) {} + | ^^^ + | + = 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 #145544 +help: name the argument, or use `_` to continue ignoring it + | +LL | unsafe extern "C" fn f(_: ...) {} + | ++ + +error: missing pattern for `...` argument + --> $DIR/parse-errors.rs:26:32 + | +LL | unsafe extern "C" fn f(...) {} + | ^^^ + | + = 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 #145544 +help: name the argument, or use `_` to continue ignoring it + | +LL | unsafe extern "C" fn f(_: ...) {} + | ++ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/c-variadic/parse-errors.rs b/tests/ui/c-variadic/parse-errors.rs new file mode 100644 index 0000000000000..f8b25c545dd1a --- /dev/null +++ b/tests/ui/c-variadic/parse-errors.rs @@ -0,0 +1,36 @@ +//@ check-fail +//@ run-rustfix +//@ revisions: e2015 e2018 +//@[e2015] edition: 2015 +//@[e2018] edition: 2018 +#![crate_type = "lib"] +#![deny(varargs_without_pattern)] + +#[cfg(false)] +mod module { + unsafe extern "C" fn f(...) { + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + unsafe extern "C" fn f(...) {} + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + } + + impl A { + unsafe extern "C" fn f(...) {} + //~^ ERROR missing pattern for `...` argument + //~| WARN this was previously accepted by the compiler + } + + trait A { + unsafe extern "C" fn f(...) {} + //[e2018]~^ ERROR missing pattern for `...` argument + //[e2018]~| WARN this was previously accepted by the compiler + } + + unsafe extern "C" { + fn f(...); // no error + } + + type A = unsafe extern "C" fn(...); // no error +} diff --git a/tests/ui/cast/associated-type-bounds-cast-54094.rs b/tests/ui/cast/associated-type-bounds-cast-54094.rs index c9f307e95b9a0..1daca9c2cd565 100644 --- a/tests/ui/cast/associated-type-bounds-cast-54094.rs +++ b/tests/ui/cast/associated-type-bounds-cast-54094.rs @@ -1,5 +1,8 @@ // https://github.com/rust-lang/rust/issues/54094 //@ check-pass + +#![allow(function_casts_as_integer)] + trait Zoo { type X; } diff --git a/tests/ui/cast/cast-rfc0401.rs b/tests/ui/cast/cast-rfc0401.rs index f917f93a1c824..cb03065f0a690 100644 --- a/tests/ui/cast/cast-rfc0401.rs +++ b/tests/ui/cast/cast-rfc0401.rs @@ -1,6 +1,6 @@ //@ run-pass -#![allow(dead_code)] +#![allow(dead_code, function_casts_as_integer)] use std::vec; diff --git a/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr b/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr index 1904faa959861..930659a2c9098 100644 --- a/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr +++ b/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `**ref_mref_x` as mutable, as it is behind a `&` ref --> $DIR/mut_ref.rs:12:13 | LL | let c = || { - | ^^ `ref_mref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^ `ref_mref_x` is a `&` reference, so it cannot be borrowed as mutable LL | LL | **ref_mref_x = y; | ------------ mutable borrow occurs due to use of `**ref_mref_x` in closure diff --git a/tests/ui/consts/const-eval/const_prop_errors.rs b/tests/ui/consts/const-eval/const_prop_errors.rs index 4580944e1bc57..68118da20e5d1 100644 --- a/tests/ui/consts/const-eval/const_prop_errors.rs +++ b/tests/ui/consts/const-eval/const_prop_errors.rs @@ -1,5 +1,7 @@ //@ check-pass +#![allow(function_casts_as_integer)] + pub trait Foo { fn foo(self) -> u32; } diff --git a/tests/ui/consts/miri_unleashed/mutable_references.stderr b/tests/ui/consts/miri_unleashed/mutable_references.stderr index b35076b669e29..9bff2711e5f1f 100644 --- a/tests/ui/consts/miri_unleashed/mutable_references.stderr +++ b/tests/ui/consts/miri_unleashed/mutable_references.stderr @@ -131,6 +131,9 @@ LL | const RAW_MUT_COERCE: SyncPtr = SyncPtr { x: &mut 0 }; error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item --> $DIR/mutable_references.rs:109:5 | +LL | static OH_YES: &mut i32 = &mut 42; + | ----------------------- this `static` cannot be written to +... LL | *OH_YES = 99; | ^^^^^^^^^^^^ cannot assign diff --git a/tests/ui/consts/write_to_static_via_mut_ref.stderr b/tests/ui/consts/write_to_static_via_mut_ref.stderr index 1bcd7b81fe059..ce44047f15506 100644 --- a/tests/ui/consts/write_to_static_via_mut_ref.stderr +++ b/tests/ui/consts/write_to_static_via_mut_ref.stderr @@ -11,6 +11,9 @@ LL | static OH_NO: &mut i32 = &mut 42; error[E0594]: cannot assign to `*OH_NO`, as `OH_NO` is an immutable static item --> $DIR/write_to_static_via_mut_ref.rs:4:5 | +LL | static OH_NO: &mut i32 = &mut 42; + | ---------------------- this `static` cannot be written to +... LL | *OH_NO = 43; | ^^^^^^^^^^^ cannot assign diff --git a/tests/ui/did_you_mean/issue-38147-1.stderr b/tests/ui/did_you_mean/issue-38147-1.stderr index 6def86e4ba8f1..1a6d1986c55bd 100644 --- a/tests/ui/did_you_mean/issue-38147-1.stderr +++ b/tests/ui/did_you_mean/issue-38147-1.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` referenc --> $DIR/issue-38147-1.rs:17:9 | LL | self.s.push('x'); - | ^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^ `self` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/did_you_mean/issue-38147-4.stderr b/tests/ui/did_you_mean/issue-38147-4.stderr index 57309172194f4..1592238d6bed8 100644 --- a/tests/ui/did_you_mean/issue-38147-4.stderr +++ b/tests/ui/did_you_mean/issue-38147-4.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*f.s` as mutable, as it is behind a `&` reference --> $DIR/issue-38147-4.rs:6:5 | LL | f.s.push('x'); - | ^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^ `f` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/did_you_mean/issue-39544.stderr b/tests/ui/did_you_mean/issue-39544.stderr index 62dc027e31f2d..745ff2bac06dd 100644 --- a/tests/ui/did_you_mean/issue-39544.stderr +++ b/tests/ui/did_you_mean/issue-39544.stderr @@ -13,7 +13,7 @@ error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:16:17 | LL | let _ = &mut self.x; - | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `self` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -24,7 +24,7 @@ error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:20:17 | LL | let _ = &mut self.x; - | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `self` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -35,7 +35,7 @@ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` referenc --> $DIR/issue-39544.rs:21:17 | LL | let _ = &mut other.x; - | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^ `other` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -46,7 +46,7 @@ error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:25:17 | LL | let _ = &mut self.x; - | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `self` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -57,7 +57,7 @@ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` referenc --> $DIR/issue-39544.rs:26:17 | LL | let _ = &mut other.x; - | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^ `other` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -68,7 +68,7 @@ error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:30:17 | LL | let _ = &mut self.x; - | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `self` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -79,7 +79,7 @@ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` referenc --> $DIR/issue-39544.rs:31:17 | LL | let _ = &mut other.x; - | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^ `other` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -90,7 +90,7 @@ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` referenc --> $DIR/issue-39544.rs:35:17 | LL | let _ = &mut other.x; - | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^ `other` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -112,7 +112,7 @@ error[E0596]: cannot borrow `w.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:42:13 | LL | let _ = &mut w.x; - | ^^^^^^^^ `w` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^ `w` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/did_you_mean/issue-40823.stderr b/tests/ui/did_you_mean/issue-40823.stderr index d9f69eb47d241..cf75b20c81450 100644 --- a/tests/ui/did_you_mean/issue-40823.stderr +++ b/tests/ui/did_you_mean/issue-40823.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*buf` as mutable, as it is behind a `&` reference --> $DIR/issue-40823.rs:3:5 | LL | buf.iter_mut(); - | ^^^ `buf` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^ `buf` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/error-codes/E0017.stderr b/tests/ui/error-codes/E0017.stderr index 2039e5564701a..fcc57b9e5c3c6 100644 --- a/tests/ui/error-codes/E0017.stderr +++ b/tests/ui/error-codes/E0017.stderr @@ -26,6 +26,9 @@ LL | const CR: &'static mut i32 = &mut C; error[E0596]: cannot borrow immutable static item `X` as mutable --> $DIR/E0017.rs:11:39 | +LL | static X: i32 = 1; + | ------------- this `static` cannot be borrowed as mutable +... LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ cannot borrow as mutable diff --git a/tests/ui/error-codes/E0389.stderr b/tests/ui/error-codes/E0389.stderr index 156bff7f0223f..c4dcab886a112 100644 --- a/tests/ui/error-codes/E0389.stderr +++ b/tests/ui/error-codes/E0389.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `fancy_ref.num`, which is behind a `&` reference --> $DIR/E0389.rs:8:5 | LL | fancy_ref.num = 6; - | ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/error-codes/E0594.stderr b/tests/ui/error-codes/E0594.stderr index e010cda83ff90..3519d0881fad6 100644 --- a/tests/ui/error-codes/E0594.stderr +++ b/tests/ui/error-codes/E0594.stderr @@ -1,6 +1,9 @@ error[E0594]: cannot assign to immutable static item `NUM` --> $DIR/E0594.rs:4:5 | +LL | static NUM: i32 = 18; + | --------------- this `static` cannot be written to +... LL | NUM = 20; | ^^^^^^^^ cannot assign diff --git a/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.rs b/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.rs index 33d295f7ebe19..084c5ba73fcbc 100644 --- a/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.rs +++ b/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.rs @@ -4,6 +4,8 @@ //@ normalize-stderr: "\[i8\]" -> "[i8 or u8 (arch dependant)]" //@ normalize-stderr: "\[u8\]" -> "[i8 or u8 (arch dependant)]" +#![allow(function_casts_as_integer)] + type Foo = extern "C" fn(::std::ffi::CStr); //~^ WARN `extern` fn uses type extern "C" { diff --git a/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr b/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr index 044c1ae2dd42f..3b98f9a55f8ed 100644 --- a/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr +++ b/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr @@ -1,5 +1,5 @@ warning: `extern` fn uses type `CStr`, which is not FFI-safe - --> $DIR/extern-C-non-FFI-safe-arg-ice-52334.rs:7:12 + --> $DIR/extern-C-non-FFI-safe-arg-ice-52334.rs:9:12 | LL | type Foo = extern "C" fn(::std::ffi::CStr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -9,7 +9,7 @@ LL | type Foo = extern "C" fn(::std::ffi::CStr); = note: `#[warn(improper_ctypes_definitions)]` on by default warning: `extern` block uses type `CStr`, which is not FFI-safe - --> $DIR/extern-C-non-FFI-safe-arg-ice-52334.rs:10:18 + --> $DIR/extern-C-non-FFI-safe-arg-ice-52334.rs:12:18 | LL | fn meh(blah: Foo); | ^^^ not FFI-safe diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr index 1f787c1842cf9..d854a457485dd 100644 --- a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr @@ -1,6 +1,8 @@ error[E0310]: the associated type `impl Fn()` may not live long enough --> $DIR/missing-static-bound-from-impl.rs:11:9 | +LL | fn f(&self) -> Box { + | -------- this `dyn Trait` has an implicit `'static` lifetime bound LL | Box::new(::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | diff --git a/tests/ui/inference/note-and-explain-ReVar-124973.rs b/tests/ui/inference/note-and-explain-ReVar-124973.rs index aa4b909fa76c8..8c04648d57b2d 100644 --- a/tests/ui/inference/note-and-explain-ReVar-124973.rs +++ b/tests/ui/inference/note-and-explain-ReVar-124973.rs @@ -2,7 +2,7 @@ #![feature(c_variadic)] -async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, ...) {} +async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, _: ...) {} //~^ ERROR functions cannot be both `async` and C-variadic //~| ERROR hidden type for `impl Future` captures lifetime that does not appear in bounds diff --git a/tests/ui/inference/note-and-explain-ReVar-124973.stderr b/tests/ui/inference/note-and-explain-ReVar-124973.stderr index 964fbc4a4fb7a..bb37e6231a323 100644 --- a/tests/ui/inference/note-and-explain-ReVar-124973.stderr +++ b/tests/ui/inference/note-and-explain-ReVar-124973.stderr @@ -1,14 +1,14 @@ error: functions cannot be both `async` and C-variadic --> $DIR/note-and-explain-ReVar-124973.rs:5:1 | -LL | async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, ...) {} - | ^^^^^ `async` because of this ^^^ C-variadic because of this +LL | async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, _: ...) {} + | ^^^^^ `async` because of this ^^^^^^ C-variadic because of this error[E0700]: hidden type for `impl Future` captures lifetime that does not appear in bounds - --> $DIR/note-and-explain-ReVar-124973.rs:5:73 + --> $DIR/note-and-explain-ReVar-124973.rs:5:76 | -LL | async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, ...) {} - | ----------------------------------------------------------------------- ^^ +LL | async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, _: ...) {} + | -------------------------------------------------------------------------- ^^ | | | opaque type defined here | diff --git a/tests/ui/issues/issue-46604.stderr b/tests/ui/issues/issue-46604.stderr index d983674995ed2..abe3ad476c60d 100644 --- a/tests/ui/issues/issue-46604.stderr +++ b/tests/ui/issues/issue-46604.stderr @@ -11,6 +11,9 @@ LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; error[E0594]: cannot assign to `buf[_]`, as `buf` is an immutable static item --> $DIR/issue-46604.rs:6:5 | +LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; + | --------------------- this `static` cannot be written to +... LL | buf[0]=2; | ^^^^^^^^ cannot assign diff --git a/tests/ui/issues/issue-51515.stderr b/tests/ui/issues/issue-51515.stderr index 88b8d21090886..5bf33b191c0eb 100644 --- a/tests/ui/issues/issue-51515.stderr +++ b/tests/ui/issues/issue-51515.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*foo`, which is behind a `&` reference --> $DIR/issue-51515.rs:4:5 | LL | *foo = 32; - | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^ `foo` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -13,7 +13,7 @@ error[E0594]: cannot assign to `*bar`, which is behind a `&` reference --> $DIR/issue-51515.rs:8:5 | LL | *bar = 64; - | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^ `bar` is a `&` reference, so it cannot be written to | help: consider specifying this binding's type | diff --git a/tests/ui/let-else/let-else-binding-explicit-mut.stderr b/tests/ui/let-else/let-else-binding-explicit-mut.stderr index 45f2b6b3bcee8..f1ec2d663d352 100644 --- a/tests/ui/let-else/let-else-binding-explicit-mut.stderr +++ b/tests/ui/let-else/let-else-binding-explicit-mut.stderr @@ -2,19 +2,19 @@ error[E0594]: cannot assign to `*n`, which is behind a `&` reference --> $DIR/let-else-binding-explicit-mut.rs:10:5 | LL | *n += 1; - | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `n` is a `&` reference, so it cannot be written to error[E0594]: cannot assign to `*n`, which is behind a `&` reference --> $DIR/let-else-binding-explicit-mut.rs:14:5 | LL | *n += 1; - | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `n` is a `&` reference, so it cannot be written to error[E0594]: cannot assign to `*n`, which is behind a `&` reference --> $DIR/let-else-binding-explicit-mut.rs:18:5 | LL | *n += 1; - | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `n` is a `&` reference, so it cannot be written to error: aborting due to 3 previous errors diff --git a/tests/ui/let-else/let-else-binding-immutable.stderr b/tests/ui/let-else/let-else-binding-immutable.stderr index 0f854493b7e47..eb6c2c5c61eed 100644 --- a/tests/ui/let-else/let-else-binding-immutable.stderr +++ b/tests/ui/let-else/let-else-binding-immutable.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/let-else-binding-immutable.rs:9:5 | LL | *x += 1; - | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `x` is a `&` reference, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/lint/function_casts_as_integer.fixed b/tests/ui/lint/function_casts_as_integer.fixed new file mode 100644 index 0000000000000..e46bd6a349cfc --- /dev/null +++ b/tests/ui/lint/function_casts_as_integer.fixed @@ -0,0 +1,22 @@ +//@ run-rustfix + +#![deny(function_casts_as_integer)] +#![allow(unused_variables, dead_code)] // For the rustfix-ed code. + +fn foo() {} + +enum MyEnum { + Variant(u32), +} + +struct MyStruct(u32); + +fn main() { + let x = foo as *const () as usize; //~ ERROR: function_casts_as_integer + let x = String::len as *const () as usize; //~ ERROR: function_casts_as_integer + let x = MyEnum::Variant as *const () as usize; //~ ERROR: function_casts_as_integer + let x = MyStruct as *const () as usize; //~ ERROR: function_casts_as_integer + // Ok. + let x = foo as fn() as usize; + let x = foo as *const () as usize; +} diff --git a/tests/ui/lint/function_casts_as_integer.rs b/tests/ui/lint/function_casts_as_integer.rs new file mode 100644 index 0000000000000..f6f83d89463f1 --- /dev/null +++ b/tests/ui/lint/function_casts_as_integer.rs @@ -0,0 +1,22 @@ +//@ run-rustfix + +#![deny(function_casts_as_integer)] +#![allow(unused_variables, dead_code)] // For the rustfix-ed code. + +fn foo() {} + +enum MyEnum { + Variant(u32), +} + +struct MyStruct(u32); + +fn main() { + let x = foo as usize; //~ ERROR: function_casts_as_integer + let x = String::len as usize; //~ ERROR: function_casts_as_integer + let x = MyEnum::Variant as usize; //~ ERROR: function_casts_as_integer + let x = MyStruct as usize; //~ ERROR: function_casts_as_integer + // Ok. + let x = foo as fn() as usize; + let x = foo as *const () as usize; +} diff --git a/tests/ui/lint/function_casts_as_integer.stderr b/tests/ui/lint/function_casts_as_integer.stderr new file mode 100644 index 0000000000000..dbfd54a3b56f9 --- /dev/null +++ b/tests/ui/lint/function_casts_as_integer.stderr @@ -0,0 +1,51 @@ +error: direct cast of function item into an integer + --> $DIR/function_casts_as_integer.rs:15:17 + | +LL | let x = foo as usize; + | ^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/function_casts_as_integer.rs:3:9 + | +LL | #![deny(function_casts_as_integer)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +help: first cast to a pointer `as *const ()` + | +LL | let x = foo as *const () as usize; + | ++++++++++++ + +error: direct cast of function item into an integer + --> $DIR/function_casts_as_integer.rs:16:25 + | +LL | let x = String::len as usize; + | ^^^^^^^^ + | +help: first cast to a pointer `as *const ()` + | +LL | let x = String::len as *const () as usize; + | ++++++++++++ + +error: direct cast of function item into an integer + --> $DIR/function_casts_as_integer.rs:17:29 + | +LL | let x = MyEnum::Variant as usize; + | ^^^^^^^^ + | +help: first cast to a pointer `as *const ()` + | +LL | let x = MyEnum::Variant as *const () as usize; + | ++++++++++++ + +error: direct cast of function item into an integer + --> $DIR/function_casts_as_integer.rs:18:22 + | +LL | let x = MyStruct as usize; + | ^^^^^^^^ + | +help: first cast to a pointer `as *const ()` + | +LL | let x = MyStruct as *const () as usize; + | ++++++++++++ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/lto/thin-lto-inlines.rs b/tests/ui/lto/thin-lto-inlines.rs index eeaae5c4c2575..c36f0e1d6c0b3 100644 --- a/tests/ui/lto/thin-lto-inlines.rs +++ b/tests/ui/lto/thin-lto-inlines.rs @@ -8,6 +8,8 @@ // praying two functions go into separate codegen units and then assuming that // if inlining *doesn't* happen the first byte of the functions will differ. +#![allow(function_casts_as_integer)] + pub fn foo() -> u32 { bar::bar() } diff --git a/tests/ui/lto/thin-lto-inlines2.rs b/tests/ui/lto/thin-lto-inlines2.rs index 4c7b9278b0822..62d65bbe0965e 100644 --- a/tests/ui/lto/thin-lto-inlines2.rs +++ b/tests/ui/lto/thin-lto-inlines2.rs @@ -11,6 +11,8 @@ // praying two functions go into separate codegen units and then assuming that // if inlining *doesn't* happen the first byte of the functions will differ. +#![allow(function_casts_as_integer)] + extern crate thin_lto_inlines_aux as bar; pub fn foo() -> u32 { diff --git a/tests/ui/mir/issue-83499-input-output-iteration-ice.rs b/tests/ui/mir/issue-83499-input-output-iteration-ice.rs index dc0d14bf9d6b6..4c547356716c2 100644 --- a/tests/ui/mir/issue-83499-input-output-iteration-ice.rs +++ b/tests/ui/mir/issue-83499-input-output-iteration-ice.rs @@ -4,6 +4,6 @@ fn main() {} -unsafe extern "C" fn foo(_: Bar, ...) -> impl {} +unsafe extern "C" fn foo(_: Bar, _: ...) -> impl {} //~^ ERROR cannot find type `Bar` in this scope //~| ERROR at least one trait must be specified diff --git a/tests/ui/mir/issue-83499-input-output-iteration-ice.stderr b/tests/ui/mir/issue-83499-input-output-iteration-ice.stderr index 31a393e7367a3..5c5936d48e31d 100644 --- a/tests/ui/mir/issue-83499-input-output-iteration-ice.stderr +++ b/tests/ui/mir/issue-83499-input-output-iteration-ice.stderr @@ -1,13 +1,13 @@ error: at least one trait must be specified - --> $DIR/issue-83499-input-output-iteration-ice.rs:7:42 + --> $DIR/issue-83499-input-output-iteration-ice.rs:7:45 | -LL | unsafe extern "C" fn foo(_: Bar, ...) -> impl {} - | ^^^^ +LL | unsafe extern "C" fn foo(_: Bar, _: ...) -> impl {} + | ^^^^ error[E0412]: cannot find type `Bar` in this scope --> $DIR/issue-83499-input-output-iteration-ice.rs:7:29 | -LL | unsafe extern "C" fn foo(_: Bar, ...) -> impl {} +LL | unsafe extern "C" fn foo(_: Bar, _: ...) -> impl {} | ^^^ not found in this scope error: aborting due to 2 previous errors diff --git a/tests/ui/mir/mir_coercions.rs b/tests/ui/mir/mir_coercions.rs index 11230c3fbb7ee..17053f410778b 100644 --- a/tests/ui/mir/mir_coercions.rs +++ b/tests/ui/mir/mir_coercions.rs @@ -1,5 +1,6 @@ //@ run-pass #![feature(coerce_unsized, unsize)] +#![allow(function_casts_as_integer)] use std::ops::CoerceUnsized; use std::marker::Unsize; diff --git a/tests/ui/mir/mir_misc_casts.rs b/tests/ui/mir/mir_misc_casts.rs index 35f217fceba6d..c44f1751448cf 100644 --- a/tests/ui/mir/mir_misc_casts.rs +++ b/tests/ui/mir/mir_misc_casts.rs @@ -1,4 +1,7 @@ //@ run-pass + +#![allow(function_casts_as_integer)] + fn func(){} const STR: &'static str = "hello"; diff --git a/tests/ui/mir/mir_refs_correct.rs b/tests/ui/mir/mir_refs_correct.rs index f1832d90a0f56..f7826202a83ec 100644 --- a/tests/ui/mir/mir_refs_correct.rs +++ b/tests/ui/mir/mir_refs_correct.rs @@ -1,6 +1,7 @@ //@ run-pass //@ aux-build:mir_external_refs.rs +#![allow(function_casts_as_integer)] #![allow(unpredictable_function_pointer_comparisons)] extern crate mir_external_refs as ext; diff --git a/tests/ui/mut/mutable-class-fields-2.stderr b/tests/ui/mut/mutable-class-fields-2.stderr index 7a6ff4da2bf52..57a04bdc21444 100644 --- a/tests/ui/mut/mutable-class-fields-2.stderr +++ b/tests/ui/mut/mutable-class-fields-2.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `self.how_hungry`, which is behind a `&` referenc --> $DIR/mutable-class-fields-2.rs:9:5 | LL | self.how_hungry -= 5; - | ^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/nll/constant-thread-locals-issue-47053.stderr b/tests/ui/nll/constant-thread-locals-issue-47053.stderr index 1c6844d6e332a..64cb866e758f7 100644 --- a/tests/ui/nll/constant-thread-locals-issue-47053.stderr +++ b/tests/ui/nll/constant-thread-locals-issue-47053.stderr @@ -1,6 +1,9 @@ error[E0594]: cannot assign to immutable static item `FOO` --> $DIR/constant-thread-locals-issue-47053.rs:9:5 | +LL | static FOO: isize = 5; + | ----------------- this `static` cannot be written to +... LL | FOO = 6; | ^^^^^^^ cannot assign diff --git a/tests/ui/nll/dont-print-desugared.stderr b/tests/ui/nll/dont-print-desugared.stderr index 289b246e663e1..9386e1f060591 100644 --- a/tests/ui/nll/dont-print-desugared.stderr +++ b/tests/ui/nll/dont-print-desugared.stderr @@ -2,7 +2,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/dont-print-desugared.rs:4:10 | LL | for &ref mut x in s {} - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ - this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0597]: `y` does not live long enough --> $DIR/dont-print-desugared.rs:17:16 diff --git a/tests/ui/nll/issue-47388.stderr b/tests/ui/nll/issue-47388.stderr index bd8b4c1eea00f..a95cc574c87f4 100644 --- a/tests/ui/nll/issue-47388.stderr +++ b/tests/ui/nll/issue-47388.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `fancy_ref.num`, which is behind a `&` reference --> $DIR/issue-47388.rs:8:5 | LL | fancy_ref.num = 6; - | ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/nll/issue-51191.stderr b/tests/ui/nll/issue-51191.stderr index 73f8aab9d1417..a7f7603d27804 100644 --- a/tests/ui/nll/issue-51191.stderr +++ b/tests/ui/nll/issue-51191.stderr @@ -45,6 +45,8 @@ LL | fn imm(mut self) { error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-51191.rs:23:9 | +LL | fn immref(&self) { + | ----- this cannot be borrowed as mutable LL | (&mut self).bar(); | ^^^^^^^^^^^ cannot borrow as mutable diff --git a/tests/ui/nll/issue-51244.stderr b/tests/ui/nll/issue-51244.stderr index 610482f8b1a99..e86202e1aec13 100644 --- a/tests/ui/nll/issue-51244.stderr +++ b/tests/ui/nll/issue-51244.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*my_ref`, which is behind a `&` reference --> $DIR/issue-51244.rs:3:5 | LL | *my_ref = 0; - | ^^^^^^^^^^^ `my_ref` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^ `my_ref` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/nll/issue-57989.stderr b/tests/ui/nll/issue-57989.stderr index 6062b31d6883c..8b102f20c122f 100644 --- a/tests/ui/nll/issue-57989.stderr +++ b/tests/ui/nll/issue-57989.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/issue-57989.rs:5:5 | LL | *x = 0; - | ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^ `x` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/parser/variadic-ffi-semantic-restrictions.rs b/tests/ui/parser/variadic-ffi-semantic-restrictions.rs index 415472176d9c4..025c0e3ecaca4 100644 --- a/tests/ui/parser/variadic-ffi-semantic-restrictions.rs +++ b/tests/ui/parser/variadic-ffi-semantic-restrictions.rs @@ -3,43 +3,43 @@ fn main() {} -fn f1_1(x: isize, ...) {} +fn f1_1(x: isize, _: ...) {} //~^ ERROR `...` is not supported for non-extern functions -fn f1_2(...) {} +fn f1_2(_: ...) {} //~^ ERROR `...` is not supported for non-extern functions -unsafe extern "Rust" fn f1_3(...) {} +unsafe extern "Rust" fn f1_3(_: ...) {} //~^ ERROR `...` is not supported for `extern "Rust"` functions -extern "C" fn f2_1(x: isize, ...) {} +extern "C" fn f2_1(x: isize, _: ...) {} //~^ ERROR functions with a C variable argument list must be unsafe -extern "C" fn f2_2(...) {} +extern "C" fn f2_2(_: ...) {} //~^ ERROR functions with a C variable argument list must be unsafe -extern "C" fn f2_3(..., x: isize) {} +extern "C" fn f2_3(_: ..., x: isize) {} //~^ ERROR `...` must be the last argument of a C-variadic function -extern "C" fn f3_1(x: isize, ...) {} +extern "C" fn f3_1(x: isize, _: ...) {} //~^ ERROR functions with a C variable argument list must be unsafe -extern "C" fn f3_2(...) {} +extern "C" fn f3_2(_: ...) {} //~^ ERROR functions with a C variable argument list must be unsafe -extern "C" fn f3_3(..., x: isize) {} +extern "C" fn f3_3(_: ..., x: isize) {} //~^ ERROR `...` must be the last argument of a C-variadic function -const unsafe extern "C" fn f4_1(x: isize, ...) {} +const unsafe extern "C" fn f4_1(x: isize, _: ...) {} //~^ ERROR functions cannot be both `const` and C-variadic //~| ERROR destructor of `VaListImpl<'_>` cannot be evaluated at compile-time -const extern "C" fn f4_2(x: isize, ...) {} +const extern "C" fn f4_2(x: isize, _: ...) {} //~^ ERROR functions cannot be both `const` and C-variadic //~| ERROR functions with a C variable argument list must be unsafe //~| ERROR destructor of `VaListImpl<'_>` cannot be evaluated at compile-time -const extern "C" fn f4_3(..., x: isize, ...) {} +const extern "C" fn f4_3(_: ..., x: isize, _: ...) {} //~^ ERROR functions cannot be both `const` and C-variadic //~| ERROR functions with a C variable argument list must be unsafe //~| ERROR `...` must be the last argument of a C-variadic function @@ -52,33 +52,33 @@ extern "C" { struct X; impl X { - fn i_f1(x: isize, ...) {} + fn i_f1(x: isize, _: ...) {} //~^ ERROR `...` is not supported for non-extern functions - fn i_f2(...) {} + fn i_f2(_: ...) {} //~^ ERROR `...` is not supported for non-extern functions - fn i_f3(..., x: isize, ...) {} + fn i_f3(_: ..., x: isize, _: ...) {} //~^ ERROR `...` is not supported for non-extern functions //~| ERROR `...` must be the last argument of a C-variadic function - fn i_f4(..., x: isize, ...) {} + fn i_f4(_: ..., x: isize, _: ...) {} //~^ ERROR `...` is not supported for non-extern functions //~| ERROR `...` must be the last argument of a C-variadic function - const fn i_f5(x: isize, ...) {} + const fn i_f5(x: isize, _: ...) {} //~^ ERROR `...` is not supported for non-extern functions //~| ERROR functions cannot be both `const` and C-variadic //~| ERROR destructor of `VaListImpl<'_>` cannot be evaluated at compile-time } trait T { - fn t_f1(x: isize, ...) {} + fn t_f1(x: isize, _: ...) {} //~^ ERROR `...` is not supported for non-extern functions - fn t_f2(x: isize, ...); + fn t_f2(x: isize, _: ...); //~^ ERROR `...` is not supported for non-extern functions - fn t_f3(...) {} + fn t_f3(_: ...) {} //~^ ERROR `...` is not supported for non-extern functions - fn t_f4(...); + fn t_f4(_: ...); //~^ ERROR `...` is not supported for non-extern functions - fn t_f5(..., x: isize) {} + fn t_f5(_: ..., x: isize) {} //~^ ERROR `...` must be the last argument of a C-variadic function - fn t_f6(..., x: isize); + fn t_f6(_: ..., x: isize); //~^ ERROR `...` must be the last argument of a C-variadic function } diff --git a/tests/ui/parser/variadic-ffi-semantic-restrictions.stderr b/tests/ui/parser/variadic-ffi-semantic-restrictions.stderr index da9c9b0f76099..0e02d4434233e 100644 --- a/tests/ui/parser/variadic-ffi-semantic-restrictions.stderr +++ b/tests/ui/parser/variadic-ffi-semantic-restrictions.stderr @@ -1,24 +1,24 @@ error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:6:19 | -LL | fn f1_1(x: isize, ...) {} - | ^^^ +LL | fn f1_1(x: isize, _: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:9:9 | -LL | fn f1_2(...) {} - | ^^^ +LL | fn f1_2(_: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` is not supported for `extern "Rust"` functions --> $DIR/variadic-ffi-semantic-restrictions.rs:12:30 | -LL | unsafe extern "Rust" fn f1_3(...) {} - | ------------- ^^^ +LL | unsafe extern "Rust" fn f1_3(_: ...) {} + | ------------- ^^^^^^ | | | `extern "Rust"` because of this | @@ -27,103 +27,103 @@ LL | unsafe extern "Rust" fn f1_3(...) {} error: functions with a C variable argument list must be unsafe --> $DIR/variadic-ffi-semantic-restrictions.rs:15:30 | -LL | extern "C" fn f2_1(x: isize, ...) {} - | ^^^ +LL | extern "C" fn f2_1(x: isize, _: ...) {} + | ^^^^^^ | help: add the `unsafe` keyword to this definition | -LL | unsafe extern "C" fn f2_1(x: isize, ...) {} +LL | unsafe extern "C" fn f2_1(x: isize, _: ...) {} | ++++++ error: functions with a C variable argument list must be unsafe --> $DIR/variadic-ffi-semantic-restrictions.rs:18:20 | -LL | extern "C" fn f2_2(...) {} - | ^^^ +LL | extern "C" fn f2_2(_: ...) {} + | ^^^^^^ | help: add the `unsafe` keyword to this definition | -LL | unsafe extern "C" fn f2_2(...) {} +LL | unsafe extern "C" fn f2_2(_: ...) {} | ++++++ error: `...` must be the last argument of a C-variadic function --> $DIR/variadic-ffi-semantic-restrictions.rs:21:20 | -LL | extern "C" fn f2_3(..., x: isize) {} - | ^^^ +LL | extern "C" fn f2_3(_: ..., x: isize) {} + | ^^^^^^ error: functions with a C variable argument list must be unsafe --> $DIR/variadic-ffi-semantic-restrictions.rs:24:30 | -LL | extern "C" fn f3_1(x: isize, ...) {} - | ^^^ +LL | extern "C" fn f3_1(x: isize, _: ...) {} + | ^^^^^^ | help: add the `unsafe` keyword to this definition | -LL | unsafe extern "C" fn f3_1(x: isize, ...) {} +LL | unsafe extern "C" fn f3_1(x: isize, _: ...) {} | ++++++ error: functions with a C variable argument list must be unsafe --> $DIR/variadic-ffi-semantic-restrictions.rs:27:20 | -LL | extern "C" fn f3_2(...) {} - | ^^^ +LL | extern "C" fn f3_2(_: ...) {} + | ^^^^^^ | help: add the `unsafe` keyword to this definition | -LL | unsafe extern "C" fn f3_2(...) {} +LL | unsafe extern "C" fn f3_2(_: ...) {} | ++++++ error: `...` must be the last argument of a C-variadic function --> $DIR/variadic-ffi-semantic-restrictions.rs:30:20 | -LL | extern "C" fn f3_3(..., x: isize) {} - | ^^^ +LL | extern "C" fn f3_3(_: ..., x: isize) {} + | ^^^^^^ error: functions cannot be both `const` and C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:33:1 | -LL | const unsafe extern "C" fn f4_1(x: isize, ...) {} - | ^^^^^ `const` because of this ^^^ C-variadic because of this +LL | const unsafe extern "C" fn f4_1(x: isize, _: ...) {} + | ^^^^^ `const` because of this ^^^^^^ C-variadic because of this error: functions cannot be both `const` and C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:37:1 | -LL | const extern "C" fn f4_2(x: isize, ...) {} - | ^^^^^ `const` because of this ^^^ C-variadic because of this +LL | const extern "C" fn f4_2(x: isize, _: ...) {} + | ^^^^^ `const` because of this ^^^^^^ C-variadic because of this error: functions with a C variable argument list must be unsafe --> $DIR/variadic-ffi-semantic-restrictions.rs:37:36 | -LL | const extern "C" fn f4_2(x: isize, ...) {} - | ^^^ +LL | const extern "C" fn f4_2(x: isize, _: ...) {} + | ^^^^^^ | help: add the `unsafe` keyword to this definition | -LL | const unsafe extern "C" fn f4_2(x: isize, ...) {} +LL | const unsafe extern "C" fn f4_2(x: isize, _: ...) {} | ++++++ error: `...` must be the last argument of a C-variadic function --> $DIR/variadic-ffi-semantic-restrictions.rs:42:26 | -LL | const extern "C" fn f4_3(..., x: isize, ...) {} - | ^^^ +LL | const extern "C" fn f4_3(_: ..., x: isize, _: ...) {} + | ^^^^^^ error: functions cannot be both `const` and C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:42:1 | -LL | const extern "C" fn f4_3(..., x: isize, ...) {} - | ^^^^^ `const` because of this ^^^ C-variadic because of this +LL | const extern "C" fn f4_3(_: ..., x: isize, _: ...) {} + | ^^^^^ `const` because of this ^^^^^^ C-variadic because of this error: functions with a C variable argument list must be unsafe - --> $DIR/variadic-ffi-semantic-restrictions.rs:42:41 + --> $DIR/variadic-ffi-semantic-restrictions.rs:42:44 | -LL | const extern "C" fn f4_3(..., x: isize, ...) {} - | ^^^ +LL | const extern "C" fn f4_3(_: ..., x: isize, _: ...) {} + | ^^^^^^ | help: add the `unsafe` keyword to this definition | -LL | const unsafe extern "C" fn f4_3(..., x: isize, ...) {} +LL | const unsafe extern "C" fn f4_3(_: ..., x: isize, _: ...) {} | ++++++ error: `...` must be the last argument of a C-variadic function @@ -135,128 +135,128 @@ LL | fn e_f2(..., x: isize); error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:55:23 | -LL | fn i_f1(x: isize, ...) {} - | ^^^ +LL | fn i_f1(x: isize, _: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:57:13 | -LL | fn i_f2(...) {} - | ^^^ +LL | fn i_f2(_: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` must be the last argument of a C-variadic function --> $DIR/variadic-ffi-semantic-restrictions.rs:59:13 | -LL | fn i_f3(..., x: isize, ...) {} - | ^^^ +LL | fn i_f3(_: ..., x: isize, _: ...) {} + | ^^^^^^ error: `...` is not supported for non-extern functions - --> $DIR/variadic-ffi-semantic-restrictions.rs:59:28 + --> $DIR/variadic-ffi-semantic-restrictions.rs:59:31 | -LL | fn i_f3(..., x: isize, ...) {} - | ^^^ +LL | fn i_f3(_: ..., x: isize, _: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` must be the last argument of a C-variadic function --> $DIR/variadic-ffi-semantic-restrictions.rs:62:13 | -LL | fn i_f4(..., x: isize, ...) {} - | ^^^ +LL | fn i_f4(_: ..., x: isize, _: ...) {} + | ^^^^^^ error: `...` is not supported for non-extern functions - --> $DIR/variadic-ffi-semantic-restrictions.rs:62:28 + --> $DIR/variadic-ffi-semantic-restrictions.rs:62:31 | -LL | fn i_f4(..., x: isize, ...) {} - | ^^^ +LL | fn i_f4(_: ..., x: isize, _: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: functions cannot be both `const` and C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:65:5 | -LL | const fn i_f5(x: isize, ...) {} - | ^^^^^ ^^^ C-variadic because of this +LL | const fn i_f5(x: isize, _: ...) {} + | ^^^^^ ^^^^^^ C-variadic because of this | | | `const` because of this error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:65:29 | -LL | const fn i_f5(x: isize, ...) {} - | ^^^ +LL | const fn i_f5(x: isize, _: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:72:23 | -LL | fn t_f1(x: isize, ...) {} - | ^^^ +LL | fn t_f1(x: isize, _: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:74:23 | -LL | fn t_f2(x: isize, ...); - | ^^^ +LL | fn t_f2(x: isize, _: ...); + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:76:13 | -LL | fn t_f3(...) {} - | ^^^ +LL | fn t_f3(_: ...) {} + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` is not supported for non-extern functions --> $DIR/variadic-ffi-semantic-restrictions.rs:78:13 | -LL | fn t_f4(...); - | ^^^ +LL | fn t_f4(_: ...); + | ^^^^^^ | = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list error: `...` must be the last argument of a C-variadic function --> $DIR/variadic-ffi-semantic-restrictions.rs:80:13 | -LL | fn t_f5(..., x: isize) {} - | ^^^ +LL | fn t_f5(_: ..., x: isize) {} + | ^^^^^^ error: `...` must be the last argument of a C-variadic function --> $DIR/variadic-ffi-semantic-restrictions.rs:82:13 | -LL | fn t_f6(..., x: isize); - | ^^^ +LL | fn t_f6(_: ..., x: isize); + | ^^^^^^ error[E0493]: destructor of `VaListImpl<'_>` cannot be evaluated at compile-time --> $DIR/variadic-ffi-semantic-restrictions.rs:33:43 | -LL | const unsafe extern "C" fn f4_1(x: isize, ...) {} - | ^^^ - value is dropped here +LL | const unsafe extern "C" fn f4_1(x: isize, _: ...) {} + | ^ - value is dropped here | | | the destructor for this type cannot be evaluated in constant functions error[E0493]: destructor of `VaListImpl<'_>` cannot be evaluated at compile-time --> $DIR/variadic-ffi-semantic-restrictions.rs:37:36 | -LL | const extern "C" fn f4_2(x: isize, ...) {} - | ^^^ - value is dropped here +LL | const extern "C" fn f4_2(x: isize, _: ...) {} + | ^ - value is dropped here | | | the destructor for this type cannot be evaluated in constant functions error[E0493]: destructor of `VaListImpl<'_>` cannot be evaluated at compile-time --> $DIR/variadic-ffi-semantic-restrictions.rs:65:29 | -LL | const fn i_f5(x: isize, ...) {} - | ^^^ - value is dropped here +LL | const fn i_f5(x: isize, _: ...) {} + | ^ - value is dropped here | | | the destructor for this type cannot be evaluated in constant functions diff --git a/tests/ui/parser/variadic-ffi-syntactic-pass.rs b/tests/ui/parser/variadic-ffi-syntactic-pass.rs index ebe0b6c2dd258..6a6656044e174 100644 --- a/tests/ui/parser/variadic-ffi-syntactic-pass.rs +++ b/tests/ui/parser/variadic-ffi-syntactic-pass.rs @@ -3,28 +3,28 @@ fn main() {} #[cfg(false)] -fn f1_1(x: isize, ...) {} +fn f1_1(x: isize, _: ...) {} #[cfg(false)] -fn f1_2(...) {} +fn f1_2(_: ...) {} #[cfg(false)] -extern "C" fn f2_1(x: isize, ...) {} +extern "C" fn f2_1(x: isize, _: ...) {} #[cfg(false)] -extern "C" fn f2_2(...) {} +extern "C" fn f2_2(_: ...) {} #[cfg(false)] -extern "C" fn f2_3(..., x: isize) {} +extern "C" fn f2_3(_: ..., x: isize) {} #[cfg(false)] -extern fn f3_1(x: isize, ...) {} +extern fn f3_1(x: isize, _: ...) {} #[cfg(false)] -extern fn f3_2(...) {} +extern fn f3_2(_: ...) {} #[cfg(false)] -extern fn f3_3(..., x: isize) {} +extern fn f3_3(_: ..., x: isize) {} #[cfg(false)] extern { @@ -36,18 +36,18 @@ struct X; #[cfg(false)] impl X { - fn i_f1(x: isize, ...) {} - fn i_f2(...) {} - fn i_f3(..., x: isize, ...) {} - fn i_f4(..., x: isize, ...) {} + fn i_f1(x: isize, _: ...) {} + fn i_f2(_: ...) {} + fn i_f3(_: ..., x: isize, _: ...) {} + fn i_f4(_: ..., x: isize, _: ...) {} } #[cfg(false)] trait T { - fn t_f1(x: isize, ...) {} - fn t_f2(x: isize, ...); - fn t_f3(...) {} - fn t_f4(...); - fn t_f5(..., x: isize) {} - fn t_f6(..., x: isize); + fn t_f1(x: isize, _: ...) {} + fn t_f2(x: isize, _: ...); + fn t_f3(_: ...) {} + fn t_f4(_: ...); + fn t_f5(_: ..., x: isize) {} + fn t_f6(_: ..., x: isize); } diff --git a/tests/ui/pattern/issue-52240.stderr b/tests/ui/pattern/issue-52240.stderr index dcf3da45e5358..7d419dd1b9b24 100644 --- a/tests/ui/pattern/issue-52240.stderr +++ b/tests/ui/pattern/issue-52240.stderr @@ -2,7 +2,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/issue-52240.rs:9:27 | LL | if let (Some(Foo::Bar(ref mut val)), _) = (&arr.get(0), 0) { - | ^^^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^^^ ---------------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 1 previous error diff --git a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr index a1049701dc3b8..5c4446cbc17be 100644 --- a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr +++ b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr @@ -119,7 +119,7 @@ error[E0594]: cannot assign to `*_x0`, which is behind a `&` reference --> $DIR/borrowck-move-ref-pattern.rs:26:5 | LL | *_x0 = U; - | ^^^^^^^^ `_x0` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^ `_x0` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -130,7 +130,7 @@ error[E0594]: cannot assign to `*_x2`, which is behind a `&` reference --> $DIR/borrowck-move-ref-pattern.rs:27:5 | LL | *_x2 = U; - | ^^^^^^^^ `_x2` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^ `_x2` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/pattern/mut-pattern-of-immutable-borrow.rs b/tests/ui/pattern/mut-pattern-of-immutable-borrow.rs new file mode 100644 index 0000000000000..52852414da459 --- /dev/null +++ b/tests/ui/pattern/mut-pattern-of-immutable-borrow.rs @@ -0,0 +1,31 @@ +struct S { + field: Option, +} + +fn a(arg: &mut S) { + match arg.field { //~ ERROR cannot move out of `arg.field` + Some(s) => s.push('a'), //~ ERROR cannot borrow `s` as mutable + None => {} + } +} +fn b(arg: &mut S) { + match &arg.field { //~ ERROR cannot move out of a shared reference + Some(mut s) => s.push('a'), + None => {} + } +} +fn c(arg: &mut S) { + match &arg.field { + Some(ref mut s) => s.push('a'), //~ ERROR cannot borrow data in a `&` reference as mutable + None => {} + } +} + +fn main() { + let mut s = S { + field: Some("a".to_owned()), + }; + a(&mut s); + b(&mut s); + c(&mut s); +} diff --git a/tests/ui/pattern/mut-pattern-of-immutable-borrow.stderr b/tests/ui/pattern/mut-pattern-of-immutable-borrow.stderr new file mode 100644 index 0000000000000..be1b5fadb0dd0 --- /dev/null +++ b/tests/ui/pattern/mut-pattern-of-immutable-borrow.stderr @@ -0,0 +1,55 @@ +error[E0507]: cannot move out of `arg.field` as enum variant `Some` which is behind a mutable reference + --> $DIR/mut-pattern-of-immutable-borrow.rs:6:11 + | +LL | match arg.field { + | ^^^^^^^^^ +LL | Some(s) => s.push('a'), + | - + | | + | data moved here + | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &arg.field { + | + + +error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable + --> $DIR/mut-pattern-of-immutable-borrow.rs:7:20 + | +LL | Some(s) => s.push('a'), + | ^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | Some(mut s) => s.push('a'), + | +++ + +error[E0507]: cannot move out of a shared reference + --> $DIR/mut-pattern-of-immutable-borrow.rs:12:11 + | +LL | match &arg.field { + | ^^^^^^^^^^ +LL | Some(mut s) => s.push('a'), + | ----- + | | + | data moved here + | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | Some(ref mut s) => s.push('a'), + | +++ + +error[E0596]: cannot borrow data in a `&` reference as mutable + --> $DIR/mut-pattern-of-immutable-borrow.rs:19:14 + | +LL | match &arg.field { + | ---------- this cannot be borrowed as mutable +LL | Some(ref mut s) => s.push('a'), + | ^^^^^^^^^ cannot borrow as mutable + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0507, E0596. +For more information about an error, try `rustc --explain E0507`. diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2021.stderr index 4d795d5c38518..6391619fddf0e 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2021.stderr @@ -17,19 +17,25 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:38:10 | LL | let &ref mut x = &0; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ -- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:43:23 | LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { - | ^ cannot borrow as mutable + | ^ ------------------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:48:11 | LL | let &[x] = &&mut [0]; - | ^ cannot borrow as mutable + | ^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 4 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr index 6cc6c58bf7af5..1106342e62e49 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr @@ -45,7 +45,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:38:10 | LL | let &ref mut x = &0; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ -- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:43:23 @@ -57,7 +59,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:48:11 | LL | let &[x] = &&mut [0]; - | ^ cannot borrow as mutable + | ^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0508]: cannot move out of type `[&mut i32; 1]`, a non-copy array --> $DIR/borrowck-errors.rs:52:20 diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr index 036b3dbeae39d..ac84fdf7f95ff 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr @@ -49,19 +49,25 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:38:10 | LL | let &ref mut x = &0; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ -- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:43:23 | LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { - | ^ cannot borrow as mutable + | ^ ------------------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:48:11 | LL | let &[x] = &&mut [0]; - | ^ cannot borrow as mutable + | ^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 6 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2021.stderr index e1764fa1d55da..0e431326cb915 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2021.stderr @@ -17,7 +17,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:38:10 | LL | let &ref mut x = &0; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ -- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 2 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2024.stderr index e1764fa1d55da..0e431326cb915 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2024.stderr @@ -17,7 +17,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/borrowck-errors.rs:38:10 | LL | let &ref mut x = &0; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ -- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 2 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2021.stderr index fc1ca18c12026..4fa82a603a8e4 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2021.stderr @@ -81,19 +81,25 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/mixed-editions.rs:61:21 | LL | let match_ref!([x]) = &&mut [0]; - | ^ cannot borrow as mutable + | ^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/mixed-editions.rs:65:22 | LL | let &match_ctor!(y) = &&mut [0]; - | ^ cannot borrow as mutable + | ^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/mixed-editions.rs:69:11 | LL | let &[bind!(z)] = &&mut [0]; - | ^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable | = note: this error originates in the macro `bind` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2024.stderr index 9377d535f1874..ee152c2871f4e 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2024.stderr @@ -75,19 +75,25 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/mixed-editions.rs:61:21 | LL | let match_ref!([x]) = &&mut [0]; - | ^ cannot borrow as mutable + | ^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/mixed-editions.rs:65:22 | LL | let &match_ctor!(y) = &&mut [0]; - | ^ cannot borrow as mutable + | ^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/mixed-editions.rs:69:11 | LL | let &[bind!(z)] = &&mut [0]; - | ^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable | = note: this error originates in the macro `bind` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2021.stderr index dbb8ae87b661c..30c0814e19380 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2021.stderr @@ -2,7 +2,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/ref-binding-on-inh-ref-errors.rs:73:10 | LL | let [ref mut x] = &[0]; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ ---- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 1 previous error diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr index 956cd2166433a..34af303b55a40 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr @@ -32,7 +32,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/ref-binding-on-inh-ref-errors.rs:73:10 | LL | let [ref mut x] = &[0]; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ ---- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: cannot explicitly borrow within an implicitly-borrowing pattern --> $DIR/ref-binding-on-inh-ref-errors.rs:81:10 diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.stable2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.stable2021.stderr index 33119c4447ada..508264f1a9409 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.stable2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.stable2021.stderr @@ -34,7 +34,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/ref-binding-on-inh-ref-errors.rs:73:10 | LL | let [ref mut x] = &[0]; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ ---- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 3 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2021.stderr index dbb8ae87b661c..30c0814e19380 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2021.stderr @@ -2,7 +2,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/ref-binding-on-inh-ref-errors.rs:73:10 | LL | let [ref mut x] = &[0]; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ ---- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 1 previous error diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr index 9753e3e5fbfea..57e3df45af4d3 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr @@ -138,7 +138,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/ref-binding-on-inh-ref-errors.rs:73:10 | LL | let [ref mut x] = &[0]; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ ---- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: cannot explicitly borrow within an implicitly-borrowing pattern --> $DIR/ref-binding-on-inh-ref-errors.rs:81:10 diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr index 9bf5c9544e51c..b83824180bf16 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr @@ -114,7 +114,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/well-typed-edition-2024.rs:111:19 | LL | let [&mut ref mut x] = &mut [&0]; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 8 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr index 9bf5c9544e51c..b83824180bf16 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr @@ -114,7 +114,9 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/well-typed-edition-2024.rs:111:19 | LL | let [&mut ref mut x] = &mut [&0]; - | ^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^ --------- this cannot be borrowed as mutable + | | + | cannot borrow as mutable error: aborting due to 8 previous errors diff --git a/tests/ui/rfcs/rfc-2005-default-binding-mode/enum.stderr b/tests/ui/rfcs/rfc-2005-default-binding-mode/enum.stderr index 21e3d3d273d7f..3ba69f73783ca 100644 --- a/tests/ui/rfcs/rfc-2005-default-binding-mode/enum.stderr +++ b/tests/ui/rfcs/rfc-2005-default-binding-mode/enum.stderr @@ -2,19 +2,19 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/enum.rs:9:5 | LL | *x += 1; - | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `x` is a `&` reference, so it cannot be written to error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/enum.rs:13:9 | LL | *x += 1; - | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `x` is a `&` reference, so it cannot be written to error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/enum.rs:19:9 | LL | *x += 1; - | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `x` is a `&` reference, so it cannot be written to error: aborting due to 3 previous errors diff --git a/tests/ui/rfcs/rfc-2005-default-binding-mode/explicit-mut.stderr b/tests/ui/rfcs/rfc-2005-default-binding-mode/explicit-mut.stderr index c3f64f65a412e..2892884ebf365 100644 --- a/tests/ui/rfcs/rfc-2005-default-binding-mode/explicit-mut.stderr +++ b/tests/ui/rfcs/rfc-2005-default-binding-mode/explicit-mut.stderr @@ -2,19 +2,19 @@ error[E0594]: cannot assign to `*n`, which is behind a `&` reference --> $DIR/explicit-mut.rs:7:13 | LL | *n += 1; - | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `n` is a `&` reference, so it cannot be written to error[E0594]: cannot assign to `*n`, which is behind a `&` reference --> $DIR/explicit-mut.rs:15:13 | LL | *n += 1; - | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `n` is a `&` reference, so it cannot be written to error[E0594]: cannot assign to `*n`, which is behind a `&` reference --> $DIR/explicit-mut.rs:23:13 | LL | *n += 1; - | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^ `n` is a `&` reference, so it cannot be written to error: aborting due to 3 previous errors diff --git a/tests/ui/runtime/signal-alternate-stack-cleanup.rs b/tests/ui/runtime/signal-alternate-stack-cleanup.rs index f2af86be0a5f5..8d52e9e26a29c 100644 --- a/tests/ui/runtime/signal-alternate-stack-cleanup.rs +++ b/tests/ui/runtime/signal-alternate-stack-cleanup.rs @@ -9,6 +9,7 @@ //@ ignore-vxworks no SIGWINCH in user space //@ ignore-nto no SA_ONSTACK +#![allow(function_casts_as_integer)] #![feature(rustc_private)] extern crate libc; diff --git a/tests/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr b/tests/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr index 4aad8843759b3..0cf9dd3b488c5 100644 --- a/tests/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr +++ b/tests/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr @@ -13,7 +13,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:65:10 | LL | &mut x.y - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -45,7 +45,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:92:5 | LL | x.y = 3; - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -77,7 +77,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:121:5 | LL | x.y_mut() - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -99,7 +99,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:133:6 | LL | *x.y_mut() = 3; - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/span/borrowck-borrow-overloaded-deref-mut.stderr b/tests/ui/span/borrowck-borrow-overloaded-deref-mut.stderr index dbd52dc2d38df..101641c8b06ba 100644 --- a/tests/ui/span/borrowck-borrow-overloaded-deref-mut.stderr +++ b/tests/ui/span/borrowck-borrow-overloaded-deref-mut.stderr @@ -13,7 +13,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-deref-mut.rs:41:11 | LL | &mut **x - | ^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -35,7 +35,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-deref-mut.rs:53:6 | LL | **x = 3; - | ^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr b/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr index f7750884b4a65..6590ba8a79e01 100644 --- a/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr +++ b/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr @@ -14,7 +14,7 @@ error[E0596]: cannot borrow `*f` as mutable, as it is behind a `&` reference --> $DIR/borrowck-call-is-borrow-issue-12224.rs:25:5 | LL | (*f)(); - | ^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^ `f` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -25,7 +25,7 @@ error[E0596]: cannot borrow `f.f` as mutable, as it is behind a `&` reference --> $DIR/borrowck-call-is-borrow-issue-12224.rs:34:5 | LL | f.f.call_mut(()) - | ^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^ `f` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/span/borrowck-call-method-from-mut-aliasable.stderr b/tests/ui/span/borrowck-call-method-from-mut-aliasable.stderr index 39e7279fb77d0..195a052d6dcc9 100644 --- a/tests/ui/span/borrowck-call-method-from-mut-aliasable.stderr +++ b/tests/ui/span/borrowck-call-method-from-mut-aliasable.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-call-method-from-mut-aliasable.rs:17:5 | LL | x.h(); - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/span/borrowck-fn-in-const-b.stderr b/tests/ui/span/borrowck-fn-in-const-b.stderr index d4a8ba2698da0..985196c0286a9 100644 --- a/tests/ui/span/borrowck-fn-in-const-b.stderr +++ b/tests/ui/span/borrowck-fn-in-const-b.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-fn-in-const-b.rs:7:9 | LL | x.push(format!("this is broken")); - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/span/borrowck-object-mutability.stderr b/tests/ui/span/borrowck-object-mutability.stderr index e4b5c8ce71f14..6fd4acd34793d 100644 --- a/tests/ui/span/borrowck-object-mutability.stderr +++ b/tests/ui/span/borrowck-object-mutability.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-object-mutability.rs:8:5 | LL | x.borrowed_mut(); - | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `x` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/span/mut-arg-hint.stderr b/tests/ui/span/mut-arg-hint.stderr index df782280b8af3..45449db4d7825 100644 --- a/tests/ui/span/mut-arg-hint.stderr +++ b/tests/ui/span/mut-arg-hint.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/mut-arg-hint.rs:3:9 | LL | a.push_str("bar"); - | ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `a` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -13,7 +13,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/mut-arg-hint.rs:8:5 | LL | a.push_str("foo"); - | ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `a` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -24,7 +24,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/mut-arg-hint.rs:15:9 | LL | a.push_str("foo"); - | ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^ `a` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/tests/ui/suggestions/dont_suggest_raw_pointer_syntax-issue-127562.stderr b/tests/ui/suggestions/dont_suggest_raw_pointer_syntax-issue-127562.stderr index 5396db7940f72..fdbdf6379c1d4 100644 --- a/tests/ui/suggestions/dont_suggest_raw_pointer_syntax-issue-127562.stderr +++ b/tests/ui/suggestions/dont_suggest_raw_pointer_syntax-issue-127562.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer --> $DIR/dont_suggest_raw_pointer_syntax-issue-127562.rs:5:9 | LL | *ptr = 3; - | ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written + | ^^^^^^^^ `ptr` is a `*const` pointer, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/issue-68049-1.stderr b/tests/ui/suggestions/issue-68049-1.stderr index 4e683b75c48b0..11a8e9cc5275b 100644 --- a/tests/ui/suggestions/issue-68049-1.stderr +++ b/tests/ui/suggestions/issue-68049-1.stderr @@ -4,7 +4,7 @@ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference LL | unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { | ----- this is an immutable reference LL | self.0 += 1; - | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^ `self` is a `&` reference, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/issue-68049-2.stderr b/tests/ui/suggestions/issue-68049-2.stderr index 91def27bfcd7e..97240af207750 100644 --- a/tests/ui/suggestions/issue-68049-2.stderr +++ b/tests/ui/suggestions/issue-68049-2.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `*input`, which is behind a `&` reference --> $DIR/issue-68049-2.rs:9:7 | LL | *input = self.0; - | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition | @@ -13,7 +13,7 @@ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference --> $DIR/issue-68049-2.rs:17:5 | LL | self.0 += *input; - | ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition | diff --git a/tests/ui/suggestions/lifetimes/implicit-static-lifetime-in-dyn-trait-return-type.rs b/tests/ui/suggestions/lifetimes/implicit-static-lifetime-in-dyn-trait-return-type.rs new file mode 100644 index 0000000000000..428033b53065b --- /dev/null +++ b/tests/ui/suggestions/lifetimes/implicit-static-lifetime-in-dyn-trait-return-type.rs @@ -0,0 +1,35 @@ +// #41966 +trait Foo {} + +struct Bar(R); + +impl Foo for Bar { +} + +fn bb(r: R) -> Box { + Box::new(Bar(r)) //~ ERROR the parameter type `R` may not live long enough +} + +fn cc(r: R) -> Box { //~ ERROR missing lifetime specifier + Box::new(Bar(r)) +} + +// #54753 +pub struct Qux(T); + +pub struct Bazzzz(T); + +pub trait Baz {} +impl Baz for Bazzzz {} + +impl Qux { + fn baz(self) -> Box { + Box::new(Bazzzz(self.0)) //~ ERROR the parameter type `T` may not live long enough + } +} + +fn main() { + let a = 10; + let _b = bb(&a); + let _c = cc(&a); +} diff --git a/tests/ui/suggestions/lifetimes/implicit-static-lifetime-in-dyn-trait-return-type.stderr b/tests/ui/suggestions/lifetimes/implicit-static-lifetime-in-dyn-trait-return-type.stderr new file mode 100644 index 0000000000000..c8122dce19542 --- /dev/null +++ b/tests/ui/suggestions/lifetimes/implicit-static-lifetime-in-dyn-trait-return-type.stderr @@ -0,0 +1,53 @@ +error[E0106]: missing lifetime specifier + --> $DIR/implicit-static-lifetime-in-dyn-trait-return-type.rs:13:33 + | +LL | fn cc(r: R) -> Box { + | ^^ expected named lifetime parameter + | + = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from +help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`, or if you will only have owned values + | +LL - fn cc(r: R) -> Box { +LL + fn cc(r: R) -> Box { + | +help: instead, you are more likely to want to change the argument to be borrowed + | +LL | fn cc(r: &R) -> Box { + | + + +error[E0310]: the parameter type `R` may not live long enough + --> $DIR/implicit-static-lifetime-in-dyn-trait-return-type.rs:10:5 + | +LL | fn bb(r: R) -> Box { + | ------- this `dyn Trait` has an implicit `'static` lifetime bound +LL | Box::new(Bar(r)) + | ^^^^^^^^^^^^^^^^ + | | + | the parameter type `R` must be valid for the static lifetime... + | ...so that the type `R` will meet its required lifetime bounds + | +help: consider adding an explicit lifetime bound + | +LL | fn bb(r: R) -> Box { + | +++++++++ + +error[E0310]: the parameter type `T` may not live long enough + --> $DIR/implicit-static-lifetime-in-dyn-trait-return-type.rs:27:9 + | +LL | fn baz(self) -> Box { + | ------- this `dyn Trait` has an implicit `'static` lifetime bound +LL | Box::new(Bazzzz(self.0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the parameter type `T` must be valid for the static lifetime... + | ...so that the type `T` will meet its required lifetime bounds + | +help: consider adding an explicit lifetime bound + | +LL | impl Qux { + | +++++++++ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0106, E0310. +For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/suggestions/suggest-mut-method-for-loop-closure.stderr b/tests/ui/suggestions/suggest-mut-method-for-loop-closure.stderr index 0bd286e0a6228..5c0bbe24ec922 100644 --- a/tests/ui/suggestions/suggest-mut-method-for-loop-closure.stderr +++ b/tests/ui/suggestions/suggest-mut-method-for-loop-closure.stderr @@ -8,7 +8,7 @@ LL | for mut t in buzz.values() { | this iterator yields `&` references ... LL | t.v += 1; - | ^^^^^^^^ `t` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^ `t` is a `&` reference, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/suggest-mut-method-for-loop-hashmap.stderr b/tests/ui/suggestions/suggest-mut-method-for-loop-hashmap.stderr index 1be14aa8f55d6..8e44128063878 100644 --- a/tests/ui/suggestions/suggest-mut-method-for-loop-hashmap.stderr +++ b/tests/ui/suggestions/suggest-mut-method-for-loop-hashmap.stderr @@ -8,7 +8,7 @@ LL | for (_k, v) in map.iter() { | this iterator yields `&` references ... LL | v.v += 1; - | ^^^^^^^^ `v` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^ `v` is a `&` reference, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/suggest-mut-method-for-loop.stderr b/tests/ui/suggestions/suggest-mut-method-for-loop.stderr index 37bb25b300f3b..26764ebc4a45a 100644 --- a/tests/ui/suggestions/suggest-mut-method-for-loop.stderr +++ b/tests/ui/suggestions/suggest-mut-method-for-loop.stderr @@ -8,7 +8,7 @@ LL | for mut t in buzz.values() { | this iterator yields `&` references ... LL | t.v += 1; - | ^^^^^^^^ `t` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^ `t` is a `&` reference, so it cannot be written to error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/suggest-ref-mut.stderr b/tests/ui/suggestions/suggest-ref-mut.stderr index 7c0899f0fbc16..ae96f6408f086 100644 --- a/tests/ui/suggestions/suggest-ref-mut.stderr +++ b/tests/ui/suggestions/suggest-ref-mut.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:9:9 | LL | self.0 = 32; - | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^^^ `self` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -13,7 +13,7 @@ error[E0594]: cannot assign to `*foo`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:17:5 | LL | *foo = 32; - | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^ `foo` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -24,7 +24,7 @@ error[E0594]: cannot assign to `*bar`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:21:9 | LL | *bar = 32; - | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^ `bar` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | @@ -35,7 +35,7 @@ error[E0594]: cannot assign to `*quo`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:25:22 | LL | ref quo => { *quo = 32; }, - | ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written + | ^^^^^^^^^ `quo` is a `&` reference, so it cannot be written to | help: consider changing this to be a mutable reference | diff --git a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr index 62943616e3ad0..0c331355407de 100644 --- a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr +++ b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr @@ -38,6 +38,8 @@ LL | fn without_sized &'static (dyn std::fmt::Debug) + ?Sized>() {} error[E0310]: the parameter type `impl FnOnce(T) -> dyn Future` may not live long enough --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:6:5 | +LL | ) -> Box dyn Future> { + | ---------------------------------------- this `dyn Trait` has an implicit `'static` lifetime bound LL | Box::new(executor) | ^^^^^^^^^^^^^^^^^^ | | diff --git a/tests/ui/thir-print/c-variadic.rs b/tests/ui/thir-print/c-variadic.rs index e03c4b0838582..a418e17e84c35 100644 --- a/tests/ui/thir-print/c-variadic.rs +++ b/tests/ui/thir-print/c-variadic.rs @@ -1,6 +1,7 @@ //@ compile-flags: -Zunpretty=thir-tree --crate-type=lib //@ check-pass #![feature(c_variadic)] +#![expect(varargs_without_pattern)] // The `...` argument uses `PatKind::Missing`. unsafe extern "C" fn foo(_: i32, ...) {} diff --git a/tests/ui/thir-print/c-variadic.stdout b/tests/ui/thir-print/c-variadic.stdout index 8363f06ebe887..adfcd976a1e28 100644 --- a/tests/ui/thir-print/c-variadic.stdout +++ b/tests/ui/thir-print/c-variadic.stdout @@ -2,13 +2,13 @@ DefId(0:3 ~ c_variadic[a5de]::foo): params: [ Param { ty: i32 - ty_span: Some($DIR/c-variadic.rs:6:29: 6:32 (#0)) + ty_span: Some($DIR/c-variadic.rs:7:29: 7:32 (#0)) self_kind: None hir_id: Some(HirId(DefId(0:3 ~ c_variadic[a5de]::foo).1)) param: Some( Pat: { ty: i32 - span: $DIR/c-variadic.rs:6:26: 6:27 (#0) + span: $DIR/c-variadic.rs:7:26: 7:27 (#0) kind: PatKind { Wild } @@ -23,7 +23,7 @@ params: [ param: Some( Pat: { ty: std::ffi::VaListImpl<'{erased}> - span: $DIR/c-variadic.rs:6:34: 6:37 (#0) + span: $DIR/c-variadic.rs:7:34: 7:37 (#0) kind: PatKind { Missing } @@ -35,7 +35,7 @@ body: Expr { ty: () temp_lifetime: TempLifetime { temp_lifetime: Some(Node(6)), backwards_incompatible: None } - span: $DIR/c-variadic.rs:6:39: 6:41 (#0) + span: $DIR/c-variadic.rs:7:39: 7:41 (#0) kind: Scope { region_scope: Node(6) @@ -44,11 +44,11 @@ body: Expr { ty: () temp_lifetime: TempLifetime { temp_lifetime: Some(Node(6)), backwards_incompatible: None } - span: $DIR/c-variadic.rs:6:39: 6:41 (#0) + span: $DIR/c-variadic.rs:7:39: 7:41 (#0) kind: Block { targeted_by_break: false - span: $DIR/c-variadic.rs:6:39: 6:41 (#0) + span: $DIR/c-variadic.rs:7:39: 7:41 (#0) region_scope: Node(5) safety_mode: Safe stmts: [] diff --git a/tests/ui/thread-local/thread-local-mutation.stderr b/tests/ui/thread-local/thread-local-mutation.stderr index 9001de34adfb5..02f5472ad2df6 100644 --- a/tests/ui/thread-local/thread-local-mutation.stderr +++ b/tests/ui/thread-local/thread-local-mutation.stderr @@ -1,6 +1,9 @@ error[E0594]: cannot assign to immutable static item `S` --> $DIR/thread-local-mutation.rs:11:5 | +LL | static S: &str = "before"; + | -------------- this `static` cannot be written to +... LL | S = "after"; | ^^^^^^^^^^^ cannot assign diff --git a/tests/ui/traits/trait-upcasting/mono-impossible.rs b/tests/ui/traits/trait-upcasting/mono-impossible.rs index f19f0538efa70..5deec77a225bc 100644 --- a/tests/ui/traits/trait-upcasting/mono-impossible.rs +++ b/tests/ui/traits/trait-upcasting/mono-impossible.rs @@ -1,5 +1,7 @@ //@ build-pass +#![allow(function_casts_as_integer)] + trait Supertrait { fn method(&self) {} } diff --git a/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr b/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr index c054ddb893d5c..703ad36c4cdc2 100644 --- a/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr +++ b/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow `**t` as mutable, as it is behind a `&` reference --> $DIR/trivial-bounds-inconsistent-copy-reborrow.rs:6:5 | LL | *t - | ^^ `t` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^ `t` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -13,7 +13,7 @@ error[E0596]: cannot borrow `**t` as mutable, as it is behind a `&` reference --> $DIR/trivial-bounds-inconsistent-copy-reborrow.rs:10:6 | LL | {*t} - | ^^ `t` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^ `t` is a `&` reference, so it cannot be borrowed as mutable | help: consider changing this to be a mutable reference |