diff --git a/.mailmap b/.mailmap index 93f5ca8157cf6..f62df9ca5f3cf 100644 --- a/.mailmap +++ b/.mailmap @@ -543,6 +543,7 @@ Takashi Idobe Takayuki Maeda Tamir Duberstein Tamir Duberstein Tatsuyuki Ishi +Tau Gärtli Tero Hänninen Tero Hänninen The8472 Theo Belaire Theo Belaire diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index bd068b29c1235..602a84ce4dd27 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -21,7 +21,7 @@ use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; use crate::diagnostics::BorrowedContentSource; use crate::util::FindAssignments; -use crate::MirBorrowckCtxt; +use crate::{session_diagnostics, MirBorrowckCtxt}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub(crate) enum AccessKind { @@ -234,7 +234,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { Some(mir::BorrowKind::Mut { kind: mir::MutBorrowKind::Default }), |_kind, var_span| { let place = self.describe_any_place(access_place.as_ref()); - crate::session_diagnostics::CaptureVarCause::MutableBorrowUsePlaceClosure { + session_diagnostics::CaptureVarCause::MutableBorrowUsePlaceClosure { place, var_span, } @@ -667,19 +667,26 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// User cannot make signature of a trait mutable without changing the /// trait. So we find if this error belongs to a trait and if so we move /// suggestion to the trait or disable it if it is out of scope of this crate - fn is_error_in_trait(&self, local: Local) -> (bool, Option) { + /// + /// The returned values are: + /// - is the current item an assoc `fn` of an impl that corresponds to a trait def? if so, we + /// have to suggest changing both the impl `fn` arg and the trait `fn` arg + /// - is the trait from the local crate? If not, we can't suggest changing signatures + /// - `Span` of the argument in the trait definition + fn is_error_in_trait(&self, local: Local) -> (bool, bool, Option) { if self.body.local_kind(local) != LocalKind::Arg { - return (false, None); + return (false, false, None); } let my_def = self.body.source.def_id(); let my_hir = self.infcx.tcx.local_def_id_to_hir_id(my_def.as_local().unwrap()); let Some(td) = self.infcx.tcx.impl_of_method(my_def).and_then(|x| self.infcx.tcx.trait_id_of_impl(x)) else { - return (false, None); + return (false, false, None); }; ( true, + td.is_local(), td.as_local().and_then(|tld| match self.infcx.tcx.hir_node_by_def_id(tld) { Node::Item(hir::Item { kind: hir::ItemKind::Trait(_, _, _, _, items), .. }) => { let mut f_in_trait_opt = None; @@ -695,19 +702,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { break; } f_in_trait_opt.and_then(|f_in_trait| { - match self.infcx.tcx.hir_node(f_in_trait) { - Node::TraitItem(hir::TraitItem { - kind: - hir::TraitItemKind::Fn( - hir::FnSig { decl: hir::FnDecl { inputs, .. }, .. }, - _, - ), - .. - }) => { - let hir::Ty { span, .. } = *inputs.get(local.index() - 1)?; - Some(span) - } - _ => None, + if let Node::TraitItem(ti) = self.infcx.tcx.hir_node(f_in_trait) + && let hir::TraitItemKind::Fn(sig, _) = ti.kind + && let Some(ty) = sig.decl.inputs.get(local.index() - 1) + && let hir::TyKind::Ref(_, mut_ty) = ty.kind + && let hir::Mutability::Not = mut_ty.mutbl + && sig.decl.implicit_self.has_implicit_self() + { + Some(ty.span) + } else { + None } }) } @@ -1061,20 +1065,24 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let (pointer_sigil, pointer_desc) = if local_decl.ty.is_ref() { ("&", "reference") } else { ("*const", "pointer") }; - let (is_trait_sig, local_trait) = self.is_error_in_trait(local); - if is_trait_sig && local_trait.is_none() { + let (is_trait_sig, is_local, local_trait) = self.is_error_in_trait(local); + + if is_trait_sig && !is_local { + // Do not suggest to change the signature when the trait comes from another crate. + err.span_label( + local_decl.source_info.span, + format!("this is an immutable {pointer_desc}"), + ); return; } - - let decl_span = match local_trait { - Some(span) => span, - None => local_decl.source_info.span, - }; + let decl_span = local_decl.source_info.span; let label = match *local_decl.local_info() { LocalInfo::User(mir::BindingForm::ImplicitSelf(_)) => { let suggestion = suggest_ampmut_self(self.infcx.tcx, decl_span); - Some((true, decl_span, suggestion)) + let additional = + local_trait.map(|span| (span, suggest_ampmut_self(self.infcx.tcx, span))); + Some((true, decl_span, suggestion, additional)) } LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm { @@ -1113,7 +1121,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // don't create labels for compiler-generated spans Some(_) => None, None => { - let label = if name != kw::SelfLower { + let (has_sugg, decl_span, sugg) = if name != kw::SelfLower { suggest_ampmut( self.infcx.tcx, local_decl.ty, @@ -1140,7 +1148,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ), } }; - Some(label) + Some((has_sugg, decl_span, sugg, None)) } } } @@ -1151,22 +1159,33 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { })) => { let pattern_span: Span = local_decl.source_info.span; suggest_ref_mut(self.infcx.tcx, pattern_span) - .map(|span| (true, span, "mut ".to_owned())) + .map(|span| (true, span, "mut ".to_owned(), None)) } _ => unreachable!(), }; match label { - Some((true, err_help_span, suggested_code)) => { - err.span_suggestion_verbose( - err_help_span, - format!("consider changing this to be a mutable {pointer_desc}"), - suggested_code, + Some((true, err_help_span, suggested_code, additional)) => { + let mut sugg = vec![(err_help_span, suggested_code)]; + if let Some(s) = additional { + sugg.push(s); + } + + err.multipart_suggestion_verbose( + format!( + "consider changing this to be a mutable {pointer_desc}{}", + if is_trait_sig { + " in the `impl` method and the `trait` definition" + } else { + "" + } + ), + sugg, Applicability::MachineApplicable, ); } - Some((false, err_label_span, message)) => { + Some((false, err_label_span, message, _)) => { let def_id = self.body.source.def_id(); let hir_id = if let Some(local_def_id) = def_id.as_local() && let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 51d01afc4ebd8..720f4927ea892 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -2004,16 +2004,17 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { } } - let parent_id = fcx.tcx.hir().get_parent_item(id); - let mut parent_item = fcx.tcx.hir_node_by_def_id(parent_id.def_id); + let mut parent_id = fcx.tcx.hir().get_parent_item(id).def_id; + let mut parent_item = fcx.tcx.hir_node_by_def_id(parent_id); // When suggesting return, we need to account for closures and async blocks, not just items. for (_, node) in fcx.tcx.hir().parent_iter(id) { match node { hir::Node::Expr(&hir::Expr { - kind: hir::ExprKind::Closure(hir::Closure { .. }), + kind: hir::ExprKind::Closure(hir::Closure { def_id, .. }), .. }) => { parent_item = node; + parent_id = *def_id; break; } hir::Node::Item(_) | hir::Node::TraitItem(_) | hir::Node::ImplItem(_) => break, @@ -2023,13 +2024,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { if let (Some(expr), Some(_), Some(fn_decl)) = (expression, blk_id, parent_item.fn_decl()) { fcx.suggest_missing_break_or_return_expr( - &mut err, - expr, - fn_decl, - expected, - found, - id, - parent_id.into(), + &mut err, expr, fn_decl, expected, found, id, parent_id, ); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index f1e82543a993a..da46ed076900d 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -942,7 +942,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn get_node_fn_decl( &self, node: Node<'tcx>, - ) -> Option<(hir::HirId, &'tcx hir::FnDecl<'tcx>, Ident, bool)> { + ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, Ident, bool)> { match node { Node::Item(&hir::Item { ident, @@ -953,25 +953,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // This is less than ideal, it will not suggest a return type span on any // method called `main`, regardless of whether it is actually the entry point, // but it will still present it as the reason for the expected type. - Some(( - hir::HirId::make_owner(owner_id.def_id), - &sig.decl, - ident, - ident.name != sym::main, - )) + Some((owner_id.def_id, &sig.decl, ident, ident.name != sym::main)) } Node::TraitItem(&hir::TraitItem { ident, kind: hir::TraitItemKind::Fn(ref sig, ..), owner_id, .. - }) => Some((hir::HirId::make_owner(owner_id.def_id), &sig.decl, ident, true)), + }) => Some((owner_id.def_id, &sig.decl, ident, true)), Node::ImplItem(&hir::ImplItem { ident, kind: hir::ImplItemKind::Fn(ref sig, ..), owner_id, .. - }) => Some((hir::HirId::make_owner(owner_id.def_id), &sig.decl, ident, false)), + }) => Some((owner_id.def_id, &sig.decl, ident, false)), Node::Expr(&hir::Expr { hir_id, kind: @@ -1001,12 +996,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) => (ident, sig, owner_id), _ => return None, }; - Some(( - hir::HirId::make_owner(owner_id.def_id), - &sig.decl, - ident, - ident.name != sym::main, - )) + Some((owner_id.def_id, &sig.decl, ident, ident.name != sym::main)) } _ => None, } @@ -1017,7 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn get_fn_decl( &self, blk_id: hir::HirId, - ) -> Option<(hir::HirId, &'tcx hir::FnDecl<'tcx>, bool)> { + ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> { // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // `while` before reaching it, as block tail returns are not available in them. self.tcx.hir().get_return_block(blk_id).and_then(|blk_id| { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 1e1136ef46778..804cd03353820 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -9,6 +9,7 @@ use crate::method::probe::{IsSuggestion, Mode, ProbeScope}; use crate::rustc_middle::ty::Article; use core::cmp::min; use core::iter; +use hir::def_id::LocalDefId; use rustc_ast::util::parser::{ExprPrecedence, PREC_POSTFIX}; use rustc_data_structures::packed::Pu128; use rustc_errors::{Applicability, Diag, MultiSpan}; @@ -796,7 +797,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, found: Ty<'tcx>, can_suggest: bool, - fn_id: hir::HirId, + fn_id: LocalDefId, ) -> bool { let found = self.resolve_numeric_literals_with_default(self.resolve_vars_if_possible(found)); @@ -923,7 +924,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err: &mut Diag<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, - fn_id: hir::HirId, + fn_id: LocalDefId, ) { // Only apply the suggestion if: // - the return type is a generic parameter @@ -937,7 +938,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty::Param(expected_ty_as_param) = expected.kind() else { return }; - let fn_node = self.tcx.hir_node(fn_id); + let fn_node = self.tcx.hir_node_by_def_id(fn_id); let hir::Node::Item(hir::Item { kind: @@ -1031,7 +1032,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, found: Ty<'tcx>, id: hir::HirId, - fn_id: hir::HirId, + fn_id: LocalDefId, ) { if !expected.is_unit() { return; @@ -1083,11 +1084,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let can_return = match fn_decl.output { hir::FnRetTy::Return(ty) => { let ty = self.lowerer().lower_ty(ty); - let bound_vars = self.tcx.late_bound_vars(fn_id); + let bound_vars = self.tcx.late_bound_vars(self.tcx.local_def_id_to_hir_id(fn_id)); let ty = self .tcx .instantiate_bound_regions_with_erased(Binder::bind_with_vars(ty, bound_vars)); - let ty = match self.tcx.asyncness(fn_id.owner) { + let ty = match self.tcx.asyncness(fn_id) { ty::Asyncness::Yes => self.get_impl_future_output_ty(ty).unwrap_or_else(|| { span_bug!( fn_decl.output.span(), @@ -1108,8 +1109,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => false, }; if can_return - && let Some(owner_node) = self.tcx.hir_node(fn_id).as_owner() - && let Some(span) = expr.span.find_ancestor_inside(*owner_node.span()) + && let Some(span) = expr.span.find_ancestor_inside( + self.tcx.hir().span_with_body(self.tcx.local_def_id_to_hir_id(fn_id)), + ) { err.multipart_suggestion( "you might have meant to return this value", diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 76fe36a77cb8a..3d9380a3ebd35 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1391,6 +1391,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let mut redundant_spans: Vec<_> = redundant_span.present_items().collect(); redundant_spans.sort(); redundant_spans.dedup(); + /* FIXME(unused_imports): Add this back as a new lint self.lint_buffer.buffer_lint_with_diagnostic( UNUSED_IMPORTS, id, @@ -1398,6 +1399,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { format!("the item `{source}` is imported redundantly"), BuiltinLintDiag::RedundantImport(redundant_spans, source), ); + */ return true; } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 39ccf6d371465..b8221d9d7f9f0 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -177,7 +177,7 @@ enum ImplTraitContext { /// Used for tracking import use types which will be used for redundant import checking. /// ### Used::Scope Example -/// ```rust,compile_fail +/// ```rust,ignore (redundant_imports) /// #![deny(unused_imports)] /// use std::mem::drop; /// fn main() { diff --git a/library/core/src/io/borrowed_buf.rs b/library/core/src/io/borrowed_buf.rs index 778d38b153764..81371708b51e9 100644 --- a/library/core/src/io/borrowed_buf.rs +++ b/library/core/src/io/borrowed_buf.rs @@ -249,9 +249,10 @@ impl<'a> BorrowedCursor<'a> { /// Panics if there are less than `n` bytes initialized. #[inline] pub fn advance(&mut self, n: usize) -> &mut Self { - assert!(self.buf.init >= self.buf.filled + n); + let filled = self.buf.filled.strict_add(n); + assert!(filled <= self.buf.init); - self.buf.filled += n; + self.buf.filled = filled; self } diff --git a/library/core/src/net/socket_addr.rs b/library/core/src/net/socket_addr.rs index 55116285842aa..c24d8f5519504 100644 --- a/library/core/src/net/socket_addr.rs +++ b/library/core/src/net/socket_addr.rs @@ -591,7 +591,7 @@ impl fmt::Display for SocketAddrV4 { if f.precision().is_none() && f.width().is_none() { write!(f, "{}:{}", self.ip(), self.port()) } else { - const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65536"; + const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65535"; let mut buf = DisplayBuffer::<{ LONGEST_IPV4_SOCKET_ADDR.len() }>::new(); // Buffer is long enough for the longest possible IPv4 socket address, so this should never fail. @@ -621,7 +621,7 @@ impl fmt::Display for SocketAddrV6 { } } else { const LONGEST_IPV6_SOCKET_ADDR: &str = - "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%4294967296]:65536"; + "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%4294967295]:65535"; let mut buf = DisplayBuffer::<{ LONGEST_IPV6_SOCKET_ADDR.len() }>::new(); match self.scope_id() { diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index fb1bf53ddc782..98973a43e1ded 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -311,14 +311,14 @@ pub use self::buffered::WriterPanicked; #[unstable(feature = "raw_os_error_ty", issue = "107792")] pub use self::error::RawOsError; pub(crate) use self::stdio::attempt_print_to_stderr; -#[unstable(feature = "internal_output_capture", issue = "none")] -#[doc(no_inline, hidden)] -pub use self::stdio::set_output_capture; #[stable(feature = "is_terminal", since = "1.70.0")] pub use self::stdio::IsTerminal; #[unstable(feature = "print_internals", issue = "none")] #[doc(hidden)] pub use self::stdio::{_eprint, _print}; +#[unstable(feature = "internal_output_capture", issue = "none")] +#[doc(no_inline, hidden)] +pub use self::stdio::{set_output_capture, try_set_output_capture}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::{ buffered::{BufReader, BufWriter, IntoInnerError, LineWriter}, diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 73fa7cbc3fead..07fa9259e0b7f 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -15,6 +15,7 @@ use crate::panic::{RefUnwindSafe, UnwindSafe}; use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantLock, ReentrantLockGuard}; use crate::sys::stdio; +use crate::thread::AccessError; type LocalStream = Arc>>; @@ -1064,12 +1065,31 @@ impl fmt::Debug for StderrLock<'_> { )] #[doc(hidden)] pub fn set_output_capture(sink: Option) -> Option { + try_set_output_capture(sink).expect( + "cannot access a Thread Local Storage value \ + during or after destruction", + ) +} + +/// Tries to set the thread-local output capture buffer and returns the old one. +/// This may fail once thread-local destructors are called. It's used in panic +/// handling instead of `set_output_capture`. +#[unstable( + feature = "internal_output_capture", + reason = "this function is meant for use in the test crate \ + and may disappear in the future", + issue = "none" +)] +#[doc(hidden)] +pub fn try_set_output_capture( + sink: Option, +) -> Result, AccessError> { if sink.is_none() && !OUTPUT_CAPTURE_USED.load(Ordering::Relaxed) { // OUTPUT_CAPTURE is definitely None since OUTPUT_CAPTURE_USED is false. - return None; + return Ok(None); } OUTPUT_CAPTURE_USED.store(true, Ordering::Relaxed); - OUTPUT_CAPTURE.with(move |slot| slot.replace(sink)) + OUTPUT_CAPTURE.try_with(move |slot| slot.replace(sink)) } /// Write `args` to the capture buffer if enabled and possible, or `global_s` diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs index eb5d59887683b..090a091b09a13 100644 --- a/library/std/src/io/tests.rs +++ b/library/std/src/io/tests.rs @@ -209,6 +209,15 @@ fn read_buf_exact() { assert_eq!(c.read_buf_exact(buf.unfilled()).unwrap_err().kind(), io::ErrorKind::UnexpectedEof); } +#[test] +#[should_panic] +fn borrowed_cursor_advance_overflow() { + let mut buf = [0; 512]; + let mut buf = BorrowedBuf::from(&mut buf[..]); + buf.unfilled().advance(1); + buf.unfilled().advance(usize::MAX); +} + #[test] fn take_eof() { struct R; diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index f46e1e171d251..0052fcbb94a81 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -24,11 +24,11 @@ use crate::sys_common::backtrace; use crate::thread; #[cfg(not(test))] -use crate::io::set_output_capture; +use crate::io::try_set_output_capture; // make sure to use the stderr output configured // by libtest in the real copy of std #[cfg(test)] -use realstd::io::set_output_capture; +use realstd::io::try_set_output_capture; // Binary interface to the panic runtime that the standard library depends on. // @@ -284,9 +284,9 @@ fn default_hook(info: &PanicInfo<'_>) { } }; - if let Some(local) = set_output_capture(None) { + if let Ok(Some(local)) = try_set_output_capture(None) { write(&mut *local.lock().unwrap_or_else(|e| e.into_inner())); - set_output_capture(Some(local)); + try_set_output_capture(Some(local)).ok(); } else if let Some(mut out) = panic_output() { write(&mut out); } diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 0941f758de57c..1dc9041658e53 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -7,8 +7,7 @@ {# #} {{page.title}} {# #} {# #} {# #} diff --git a/tests/ui/async-await/dont-ice-for-type-mismatch-in-closure-in-async.rs b/tests/ui/async-await/dont-ice-for-type-mismatch-in-closure-in-async.rs new file mode 100644 index 0000000000000..8ad99a4c20167 --- /dev/null +++ b/tests/ui/async-await/dont-ice-for-type-mismatch-in-closure-in-async.rs @@ -0,0 +1,17 @@ +//@ edition: 2021 + +fn call(_: impl Fn() -> bool) {} + +async fn test() { + call(|| -> Option<()> { + //~^ ERROR expected + if true { + false + //~^ ERROR mismatched types + } + true + //~^ ERROR mismatched types + }) +} + +fn main() {} diff --git a/tests/ui/async-await/dont-ice-for-type-mismatch-in-closure-in-async.stderr b/tests/ui/async-await/dont-ice-for-type-mismatch-in-closure-in-async.stderr new file mode 100644 index 0000000000000..70cd9f924ac5e --- /dev/null +++ b/tests/ui/async-await/dont-ice-for-type-mismatch-in-closure-in-async.stderr @@ -0,0 +1,46 @@ +error[E0308]: mismatched types + --> $DIR/dont-ice-for-type-mismatch-in-closure-in-async.rs:9:13 + | +LL | / if true { +LL | | false + | | ^^^^^ expected `()`, found `bool` +LL | | +LL | | } + | |_________- expected this to be `()` + +error[E0308]: mismatched types + --> $DIR/dont-ice-for-type-mismatch-in-closure-in-async.rs:12:9 + | +LL | true + | ^^^^ expected `Option<()>`, found `bool` + | + = note: expected enum `Option<()>` + found type `bool` + +error[E0271]: expected `{closure@dont-ice-for-type-mismatch-in-closure-in-async.rs:6:10}` to be a closure that returns `bool`, but it returns `Option<()>` + --> $DIR/dont-ice-for-type-mismatch-in-closure-in-async.rs:6:10 + | +LL | call(|| -> Option<()> { + | _____----_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | if true { +LL | | false +... | +LL | | +LL | | }) + | |_____^ expected `bool`, found `Option<()>` + | + = note: expected type `bool` + found enum `Option<()>` +note: required by a bound in `call` + --> $DIR/dont-ice-for-type-mismatch-in-closure-in-async.rs:3:25 + | +LL | fn call(_: impl Fn() -> bool) {} + | ^^^^ required by this bound in `call` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0271, E0308. +For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/borrowck/argument_number_mismatch_ice.stderr b/tests/ui/borrowck/argument_number_mismatch_ice.stderr index 2a6a6dbc64c71..702cebb86bae2 100644 --- a/tests/ui/borrowck/argument_number_mismatch_ice.stderr +++ b/tests/ui/borrowck/argument_number_mismatch_ice.stderr @@ -12,6 +12,11 @@ error[E0594]: cannot assign to `*input`, which is behind a `&` reference | LL | *input = self.0; | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition + | +LL | fn example(&self, input: &mut i32) { + | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/borrowck/trait-impl-argument-difference-ice.rs b/tests/ui/borrowck/trait-impl-argument-difference-ice.rs new file mode 100644 index 0000000000000..872507cc4de6a --- /dev/null +++ b/tests/ui/borrowck/trait-impl-argument-difference-ice.rs @@ -0,0 +1,25 @@ +// Issue https://github.com/rust-lang/rust/issues/123414 +trait MemoryUnit { + extern "C" fn read_word(&mut self) -> u8; + extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + //~^ WARNING anonymous parameters are deprecated and will be removed in the next edition + //~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + //~| ERROR associated type `Assoc` not found for `Self` +} + +struct ROM {} + +impl MemoryUnit for ROM { +//~^ ERROR not all trait items implemented, missing: `read_word` + extern "C" fn read_dword(&'_ self) -> u16 { + //~^ ERROR method `read_dword` has a `&self` declaration in the impl, but not in the trait + let a16 = self.read_word() as u16; + //~^ ERROR cannot borrow `*self` as mutable, as it is behind a `&` reference + let b16 = self.read_word() as u16; + //~^ ERROR cannot borrow `*self` as mutable, as it is behind a `&` reference + + (b16 << 8) | a16 + } +} + +pub fn main() {} diff --git a/tests/ui/borrowck/trait-impl-argument-difference-ice.stderr b/tests/ui/borrowck/trait-impl-argument-difference-ice.stderr new file mode 100644 index 0000000000000..5c70eccfbd35c --- /dev/null +++ b/tests/ui/borrowck/trait-impl-argument-difference-ice.stderr @@ -0,0 +1,60 @@ +warning: anonymous parameters are deprecated and will be removed in the next edition + --> $DIR/trait-impl-argument-difference-ice.rs:4:30 + | +LL | extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + | ^^^^^^^^^^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: Self::Assoc<'_>` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #41686 + = note: `#[warn(anonymous_parameters)]` on by default + +error[E0220]: associated type `Assoc` not found for `Self` + --> $DIR/trait-impl-argument-difference-ice.rs:4:36 + | +LL | extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + | ^^^^^ associated type `Assoc` not found + +error[E0185]: method `read_dword` has a `&self` declaration in the impl, but not in the trait + --> $DIR/trait-impl-argument-difference-ice.rs:14:5 + | +LL | extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + | ------------------------------------------------- trait method declared without `&self` +... +LL | extern "C" fn read_dword(&'_ self) -> u16 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl + +error[E0046]: not all trait items implemented, missing: `read_word` + --> $DIR/trait-impl-argument-difference-ice.rs:12:1 + | +LL | extern "C" fn read_word(&mut self) -> u8; + | ----------------------------------------- `read_word` from trait +... +LL | impl MemoryUnit for ROM { + | ^^^^^^^^^^^^^^^^^^^^^^^ missing `read_word` in implementation + +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 + | +help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition + | +LL | extern "C" fn read_dword(&'_ mut self) -> u16 { + | ~~~~~~~~~~~~ + +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 + | +help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition + | +LL | extern "C" fn read_dword(&'_ mut self) -> u16 { + | ~~~~~~~~~~~~ + +error: aborting due to 5 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0046, E0185, E0220, E0596. +For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/imports/redundant-import-extern-prelude.rs b/tests/ui/imports/redundant-import-extern-prelude.rs index acf59b09a1dec..f1de06417aa5d 100644 --- a/tests/ui/imports/redundant-import-extern-prelude.rs +++ b/tests/ui/imports/redundant-import-extern-prelude.rs @@ -1,7 +1,7 @@ +//@ check-pass // Check that we detect imports that are redundant due to the extern prelude // and that we emit a reasonable diagnostic. // issue: rust-lang/rust#121915 -//~^^^ NOTE the item `aux_issue_121915` is already defined by the extern prelude // See also the discussion in . @@ -9,9 +9,8 @@ //@ aux-build: aux-issue-121915.rs #[deny(unused_imports)] -//~^ NOTE the lint level is defined here fn main() { use aux_issue_121915; - //~^ ERROR the item `aux_issue_121915` is imported redundantly + //FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly aux_issue_121915::item(); } diff --git a/tests/ui/imports/redundant-import-extern-prelude.stderr b/tests/ui/imports/redundant-import-extern-prelude.stderr deleted file mode 100644 index d49e013c3d34d..0000000000000 --- a/tests/ui/imports/redundant-import-extern-prelude.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: the item `aux_issue_121915` is imported redundantly - --> $DIR/redundant-import-extern-prelude.rs:14:9 - | -LL | use aux_issue_121915; - | ^^^^^^^^^^^^^^^^ the item `aux_issue_121915` is already defined by the extern prelude - | -note: the lint level is defined here - --> $DIR/redundant-import-extern-prelude.rs:11:8 - | -LL | #[deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/imports/redundant-import-issue-121915-2015.rs b/tests/ui/imports/redundant-import-issue-121915-2015.rs index d41d190bb58c4..be3b8209ada99 100644 --- a/tests/ui/imports/redundant-import-issue-121915-2015.rs +++ b/tests/ui/imports/redundant-import-issue-121915-2015.rs @@ -1,3 +1,4 @@ +//@ check-pass //@ compile-flags: --extern aux_issue_121915 --edition 2015 //@ aux-build: aux-issue-121915.rs @@ -6,6 +7,6 @@ extern crate aux_issue_121915; #[deny(unused_imports)] fn main() { use aux_issue_121915; - //~^ ERROR the item `aux_issue_121915` is imported redundantly + //FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly aux_issue_121915::item(); } diff --git a/tests/ui/imports/redundant-import-issue-121915-2015.stderr b/tests/ui/imports/redundant-import-issue-121915-2015.stderr deleted file mode 100644 index 174ed4fb96b11..0000000000000 --- a/tests/ui/imports/redundant-import-issue-121915-2015.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: the item `aux_issue_121915` is imported redundantly - --> $DIR/redundant-import-issue-121915-2015.rs:8:9 - | -LL | extern crate aux_issue_121915; - | ------------------------------ the item `aux_issue_121915` is already imported here -... -LL | use aux_issue_121915; - | ^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/redundant-import-issue-121915-2015.rs:6:8 - | -LL | #[deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/imports/redundant-import-lang-prelude-attr.rs b/tests/ui/imports/redundant-import-lang-prelude-attr.rs index 18d0e688206b0..59cd570f44c25 100644 --- a/tests/ui/imports/redundant-import-lang-prelude-attr.rs +++ b/tests/ui/imports/redundant-import-lang-prelude-attr.rs @@ -1,6 +1,6 @@ +//@ check-pass // Check that we detect imports (of built-in attributes) that are redundant due to // the language prelude and that we emit a reasonable diagnostic. -//~^^ NOTE the item `allow` is already defined by the extern prelude // Note that we use the term "extern prelude" in the label even though "language prelude" // would be more correct. However, it's not worth special-casing this. @@ -10,9 +10,8 @@ //@ edition: 2018 #![deny(unused_imports)] -//~^ NOTE the lint level is defined here -use allow; //~ ERROR the item `allow` is imported redundantly +use allow; //FIXME(unused_imports): ~ ERROR the item `allow` is imported redundantly #[allow(unused)] fn main() {} diff --git a/tests/ui/imports/redundant-import-lang-prelude-attr.stderr b/tests/ui/imports/redundant-import-lang-prelude-attr.stderr deleted file mode 100644 index a3ca7ce24ed0b..0000000000000 --- a/tests/ui/imports/redundant-import-lang-prelude-attr.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: the item `allow` is imported redundantly - --> $DIR/redundant-import-lang-prelude-attr.rs:15:5 - | -LL | use allow; - | ^^^^^ the item `allow` is already defined by the extern prelude - | -note: the lint level is defined here - --> $DIR/redundant-import-lang-prelude-attr.rs:12:9 - | -LL | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/imports/redundant-import-lang-prelude.rs b/tests/ui/imports/redundant-import-lang-prelude.rs index 3faf9423c37f8..53d3b70996342 100644 --- a/tests/ui/imports/redundant-import-lang-prelude.rs +++ b/tests/ui/imports/redundant-import-lang-prelude.rs @@ -1,6 +1,6 @@ +//@ check-pass // Check that we detect imports that are redundant due to the language prelude // and that we emit a reasonable diagnostic. -//~^^ NOTE the item `u8` is already defined by the extern prelude // Note that we use the term "extern prelude" in the label even though "language prelude" // would be more correct. However, it's not worth special-casing this. @@ -8,10 +8,9 @@ // See also the discussion in . #![deny(unused_imports)] -//~^ NOTE the lint level is defined here use std::primitive::u8; -//~^ ERROR the item `u8` is imported redundantly +//FIXME(unused_imports): ~^ ERROR the item `u8` is imported redundantly const _: u8 = 0; diff --git a/tests/ui/imports/redundant-import-lang-prelude.stderr b/tests/ui/imports/redundant-import-lang-prelude.stderr deleted file mode 100644 index e6a4535f9802d..0000000000000 --- a/tests/ui/imports/redundant-import-lang-prelude.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: the item `u8` is imported redundantly - --> $DIR/redundant-import-lang-prelude.rs:13:5 - | -LL | use std::primitive::u8; - | ^^^^^^^^^^^^^^^^^^ the item `u8` is already defined by the extern prelude - | -note: the lint level is defined here - --> $DIR/redundant-import-lang-prelude.rs:10:9 - | -LL | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/imports/suggest-remove-issue-121315.rs b/tests/ui/imports/suggest-remove-issue-121315.rs index 63533480ec127..2bb82833a5bc3 100644 --- a/tests/ui/imports/suggest-remove-issue-121315.rs +++ b/tests/ui/imports/suggest-remove-issue-121315.rs @@ -1,19 +1,20 @@ //@ compile-flags: --edition 2021 + #![deny(unused_imports)] #![allow(dead_code)] fn test0() { // Test remove FlatUnused use std::convert::TryFrom; - //~^ ERROR the item `TryFrom` is imported redundantly + //FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly let _ = u32::try_from(5i32); } fn test1() { // FIXME(yukang) Test remove NestedFullUnused use std::convert::{TryFrom, TryInto}; - //~^ ERROR the item `TryFrom` is imported redundantly - //~| ERROR the item `TryInto` is imported redundantly + //FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly + //FIXME(unused_imports): ~| ERROR the item `TryInto` is imported redundantly let _ = u32::try_from(5i32); let _a: i32 = u32::try_into(5u32).unwrap(); @@ -23,7 +24,7 @@ fn test2() { // FIXME(yukang): Test remove both redundant and unused use std::convert::{AsMut, Into}; //~^ ERROR unused import: `AsMut` - //~| ERROR the item `Into` is imported redundantly + //FIXME(unused_imports): ~| ERROR the item `Into` is imported redundantly let _a: u32 = (5u8).into(); } diff --git a/tests/ui/imports/suggest-remove-issue-121315.stderr b/tests/ui/imports/suggest-remove-issue-121315.stderr index dbd742f6c781f..5701514e1bd6e 100644 --- a/tests/ui/imports/suggest-remove-issue-121315.stderr +++ b/tests/ui/imports/suggest-remove-issue-121315.stderr @@ -1,56 +1,20 @@ -error: the item `TryFrom` is imported redundantly - --> $DIR/suggest-remove-issue-121315.rs:7:9 - | -LL | use std::convert::TryFrom; - | ^^^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `TryFrom` is already defined here - | -note: the lint level is defined here - --> $DIR/suggest-remove-issue-121315.rs:2:9 - | -LL | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: the item `TryFrom` is imported redundantly - --> $DIR/suggest-remove-issue-121315.rs:14:24 - | -LL | use std::convert::{TryFrom, TryInto}; - | ^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `TryFrom` is already defined here - -error: the item `TryInto` is imported redundantly - --> $DIR/suggest-remove-issue-121315.rs:14:33 - | -LL | use std::convert::{TryFrom, TryInto}; - | ^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `TryInto` is already defined here - error: unused import: `AsMut` - --> $DIR/suggest-remove-issue-121315.rs:24:24 + --> $DIR/suggest-remove-issue-121315.rs:25:24 | LL | use std::convert::{AsMut, Into}; | ^^^^^ - -error: the item `Into` is imported redundantly - --> $DIR/suggest-remove-issue-121315.rs:24:31 | -LL | use std::convert::{AsMut, Into}; - | ^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL +note: the lint level is defined here + --> $DIR/suggest-remove-issue-121315.rs:3:9 | - = note: the item `Into` is already defined here +LL | #![deny(unused_imports)] + | ^^^^^^^^^^^^^^ error: unused import: `From` - --> $DIR/suggest-remove-issue-121315.rs:33:24 + --> $DIR/suggest-remove-issue-121315.rs:34:24 | LL | use std::convert::{From, Infallible}; | ^^^^ -error: aborting due to 6 previous errors +error: aborting due to 2 previous errors diff --git a/tests/ui/lint/unused/issue-59896.rs b/tests/ui/lint/unused/issue-59896.rs index ff9f19acf8471..a98017524f550 100644 --- a/tests/ui/lint/unused/issue-59896.rs +++ b/tests/ui/lint/unused/issue-59896.rs @@ -1,9 +1,10 @@ +//@ check-pass #![deny(unused_imports)] struct S; fn main() { - use S; //~ ERROR the item `S` is imported redundantly + use S; //FIXME(unused_imports): ~ ERROR the item `S` is imported redundantly let _s = S; } diff --git a/tests/ui/lint/unused/issue-59896.stderr b/tests/ui/lint/unused/issue-59896.stderr deleted file mode 100644 index 3e8298c6b72e6..0000000000000 --- a/tests/ui/lint/unused/issue-59896.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: the item `S` is imported redundantly - --> $DIR/issue-59896.rs:6:9 - | -LL | struct S; - | --------- the item `S` is already defined here -... -LL | use S; - | ^ - | -note: the lint level is defined here - --> $DIR/issue-59896.rs:1:9 - | -LL | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs b/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs index 28d1fea98b582..797e57f48e9d2 100644 --- a/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs +++ b/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs @@ -9,7 +9,7 @@ pub mod bar { use bar::*; pub fn warning() -> Foo { - use bar::Foo; //~ WARNING imported redundantly + use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly Foo(Bar('a')) } diff --git a/tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr b/tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr deleted file mode 100644 index 2c3b33452702b..0000000000000 --- a/tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr +++ /dev/null @@ -1,17 +0,0 @@ -warning: the item `Foo` is imported redundantly - --> $DIR/use-redundant-glob-parent.rs:12:9 - | -LL | use bar::*; - | ------ the item `Foo` is already imported here -... -LL | use bar::Foo; - | ^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/use-redundant-glob-parent.rs:2:9 - | -LL | #![warn(unused_imports)] - | ^^^^^^^^^^^^^^ - -warning: 1 warning emitted - diff --git a/tests/ui/lint/use-redundant/use-redundant-glob.rs b/tests/ui/lint/use-redundant/use-redundant-glob.rs index 3d3fe2579b54c..e5835be89d841 100644 --- a/tests/ui/lint/use-redundant/use-redundant-glob.rs +++ b/tests/ui/lint/use-redundant/use-redundant-glob.rs @@ -8,7 +8,7 @@ pub mod bar { pub fn warning() -> bar::Foo { use bar::*; - use bar::Foo; //~ WARNING imported redundantly + use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly Foo(Bar('a')) } diff --git a/tests/ui/lint/use-redundant/use-redundant-glob.stderr b/tests/ui/lint/use-redundant/use-redundant-glob.stderr deleted file mode 100644 index d3b406d82b6db..0000000000000 --- a/tests/ui/lint/use-redundant/use-redundant-glob.stderr +++ /dev/null @@ -1,16 +0,0 @@ -warning: the item `Foo` is imported redundantly - --> $DIR/use-redundant-glob.rs:11:9 - | -LL | use bar::*; - | ------ the item `Foo` is already imported here -LL | use bar::Foo; - | ^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/use-redundant-glob.rs:2:9 - | -LL | #![warn(unused_imports)] - | ^^^^^^^^^^^^^^ - -warning: 1 warning emitted - diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs b/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs index d0fb3454d3f2b..2db3435d46dbd 100644 --- a/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs +++ b/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs @@ -23,7 +23,8 @@ mod foo { fn main() { { - use std::string::String; //~ WARNING the item `String` is imported redundantly + use std::string::String; + //FIXME(unused_imports): ~^ WARNING the item `String` is imported redundantly // 'String' from 'std::string::String'. let s = String::new(); println!("{}", s); diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr b/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr deleted file mode 100644 index b8832a3178371..0000000000000 --- a/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr +++ /dev/null @@ -1,17 +0,0 @@ -warning: the item `String` is imported redundantly - --> $DIR/use-redundant-issue-71450.rs:26:13 - | -LL | use std::string::String; - | ^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `String` is already defined here - | -note: the lint level is defined here - --> $DIR/use-redundant-issue-71450.rs:3:9 - | -LL | #![warn(unused_imports)] - | ^^^^^^^^^^^^^^ - -warning: 1 warning emitted - diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs index ae5118b2729b9..62f50c8a0df90 100644 --- a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs +++ b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs @@ -2,11 +2,15 @@ #![warn(unused_imports)] -use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly -use std::option::Option::None; //~ WARNING the item `None` is imported redundantly +use std::option::Option::Some; +//FIXME(unused_imports): ~^ WARNING the item `Some` is imported redundantly +use std::option::Option::None; +//FIXME(unused_imports): ~ WARNING the item `None` is imported redundantly -use std::result::Result::Ok;//~ WARNING the item `Ok` is imported redundantly -use std::result::Result::Err;//~ WARNING the item `Err` is imported redundantly +use std::result::Result::Ok; +//FIXME(unused_imports): ~^ WARNING the item `Ok` is imported redundantly +use std::result::Result::Err; +//FIXME(unused_imports): ~^ WARNING the item `Err` is imported redundantly use std::convert::{TryFrom, TryInto}; fn main() { diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr deleted file mode 100644 index 1b09df911eb03..0000000000000 --- a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr +++ /dev/null @@ -1,44 +0,0 @@ -warning: the item `Some` is imported redundantly - --> $DIR/use-redundant-prelude-rust-2015.rs:5:5 - | -LL | use std::option::Option::Some; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `Some` is already defined here - | -note: the lint level is defined here - --> $DIR/use-redundant-prelude-rust-2015.rs:2:9 - | -LL | #![warn(unused_imports)] - | ^^^^^^^^^^^^^^ - -warning: the item `None` is imported redundantly - --> $DIR/use-redundant-prelude-rust-2015.rs:6:5 - | -LL | use std::option::Option::None; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `None` is already defined here - -warning: the item `Ok` is imported redundantly - --> $DIR/use-redundant-prelude-rust-2015.rs:8:5 - | -LL | use std::result::Result::Ok; - | ^^^^^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `Ok` is already defined here - -warning: the item `Err` is imported redundantly - --> $DIR/use-redundant-prelude-rust-2015.rs:9:5 - | -LL | use std::result::Result::Err; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `Err` is already defined here - -warning: 4 warnings emitted - diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs index cb4dcb6c0bd67..1baa1ac1b8cd3 100644 --- a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs +++ b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs @@ -2,8 +2,10 @@ //@ edition:2021 #![warn(unused_imports)] -use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly -use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly +use std::convert::TryFrom; +//FIXME(unused_imports): ~^ WARNING the item `TryFrom` is imported redundantly +use std::convert::TryInto; +//FIXME(unused_imports): ~^ WARNING the item `TryInto` is imported redundantly fn main() { let _e: Result = 8u8.try_into(); diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr deleted file mode 100644 index 542356dc996df..0000000000000 --- a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr +++ /dev/null @@ -1,26 +0,0 @@ -warning: the item `TryFrom` is imported redundantly - --> $DIR/use-redundant-prelude-rust-2021.rs:5:5 - | -LL | use std::convert::TryFrom; - | ^^^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `TryFrom` is already defined here - | -note: the lint level is defined here - --> $DIR/use-redundant-prelude-rust-2021.rs:3:9 - | -LL | #![warn(unused_imports)] - | ^^^^^^^^^^^^^^ - -warning: the item `TryInto` is imported redundantly - --> $DIR/use-redundant-prelude-rust-2021.rs:6:5 - | -LL | use std::convert::TryInto; - | ^^^^^^^^^^^^^^^^^^^^^ - --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL - | - = note: the item `TryInto` is already defined here - -warning: 2 warnings emitted - diff --git a/tests/ui/lint/use-redundant/use-redundant.rs b/tests/ui/lint/use-redundant/use-redundant.rs index 88d3ee75a3f2d..9e4902af34b7d 100644 --- a/tests/ui/lint/use-redundant/use-redundant.rs +++ b/tests/ui/lint/use-redundant/use-redundant.rs @@ -18,7 +18,7 @@ use m1::*; //~ WARNING unused import use m2::*; //~ WARNING unused import fn main() { - use crate::foo::Bar; //~ WARNING imported redundantly + use crate::foo::Bar; //FIXME(unused_imports): ~ WARNING imported redundantly let _a: Bar = 3; baz(); diff --git a/tests/ui/lint/use-redundant/use-redundant.stderr b/tests/ui/lint/use-redundant/use-redundant.stderr index c861a1956e1d1..224e841123748 100644 --- a/tests/ui/lint/use-redundant/use-redundant.stderr +++ b/tests/ui/lint/use-redundant/use-redundant.stderr @@ -16,14 +16,5 @@ warning: unused import: `m2::*` LL | use m2::*; | ^^^^^ -warning: the item `Bar` is imported redundantly - --> $DIR/use-redundant.rs:21:9 - | -LL | use crate::foo::Bar; - | --------------- the item `Bar` is already imported here -... -LL | use crate::foo::Bar; - | ^^^^^^^^^^^^^^^ - -warning: 3 warnings emitted +warning: 2 warnings emitted diff --git a/tests/ui/suggestions/issue-68049-1.stderr b/tests/ui/suggestions/issue-68049-1.stderr index 760f83d548f0f..4e683b75c48b0 100644 --- a/tests/ui/suggestions/issue-68049-1.stderr +++ b/tests/ui/suggestions/issue-68049-1.stderr @@ -1,6 +1,8 @@ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference --> $DIR/issue-68049-1.rs:7:9 | +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 diff --git a/tests/ui/suggestions/issue-68049-2.rs b/tests/ui/suggestions/issue-68049-2.rs index 1c3430c14e9f2..496a1299dcf48 100644 --- a/tests/ui/suggestions/issue-68049-2.rs +++ b/tests/ui/suggestions/issue-68049-2.rs @@ -1,11 +1,11 @@ trait Hello { - fn example(&self, input: &i32); // should suggest here + fn example(&self, input: &i32); } struct Test1(i32); impl Hello for Test1 { - fn example(&self, input: &i32) { // should not suggest here + fn example(&self, input: &i32) { *input = self.0; //~ ERROR cannot assign } } @@ -13,7 +13,7 @@ impl Hello for Test1 { struct Test2(i32); impl Hello for Test2 { - fn example(&self, input: &i32) { // should not suggest here + fn example(&self, input: &i32) { self.0 += *input; //~ ERROR cannot assign } } diff --git a/tests/ui/suggestions/issue-68049-2.stderr b/tests/ui/suggestions/issue-68049-2.stderr index 6f3c78443f829..449ecabeb7f48 100644 --- a/tests/ui/suggestions/issue-68049-2.stderr +++ b/tests/ui/suggestions/issue-68049-2.stderr @@ -4,9 +4,9 @@ error[E0594]: cannot assign to `*input`, which is behind a `&` reference LL | *input = self.0; | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written | -help: consider changing this to be a mutable reference +help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition | -LL | fn example(&self, input: &mut i32) { // should not suggest here +LL | fn example(&self, input: &mut i32) { | +++ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference @@ -15,10 +15,14 @@ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference LL | self.0 += *input; | ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written | -help: consider changing this to be a mutable reference +help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition + | +LL ~ fn example(&mut self, input: &i32); +LL | } + ... +LL | impl Hello for Test2 { +LL ~ fn example(&mut self, input: &i32) { | -LL | fn example(&mut self, input: &i32); // should suggest here - | ~~~~~~~~~ error: aborting due to 2 previous errors