diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index ba644e611182779520548a59fd96ee7e2febb735..8c56cf1cb3414bb1508114f63ce389b9a4fddc20 100644 --- a/src/bootstrap/bin/rustdoc.rs +++ b/src/bootstrap/bin/rustdoc.rs @@ -13,7 +13,6 @@ fn main() { let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set"); let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set"); let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set"); - let mut has_unstable = false; use std::str::FromStr; @@ -55,22 +54,10 @@ fn main() { cmd.arg("--crate-version").arg(version); } - // Needed to be able to run all rustdoc tests. - if env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES").is_some() { - // This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized - if !has_unstable { - cmd.arg("-Z").arg("unstable-options"); - } - cmd.arg("--generate-redirect-pages"); - has_unstable = true; - } - // Needed to be able to run all rustdoc tests. if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") { // This "unstable-options" can be removed when `--resource-suffix` is stabilized - if !has_unstable { - cmd.arg("-Z").arg("unstable-options"); - } + cmd.arg("-Z").arg("unstable-options"); cmd.arg("--resource-suffix").arg(x); } diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index d02c19467ee68da0b9b420a038f7bdf8d6eb43e5..ed351354c441d904dc9a52ad3ceab5b7f2f15dd3 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -451,7 +451,6 @@ fn run(self, builder: &Builder<'_>) { .arg("--markdown-css") .arg("rust.css") .arg("--markdown-no-toc") - .arg("--generate-redirect-pages") .arg("-Z") .arg("unstable-options") .arg("--resource-suffix") diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 77bcc00d75b2b68c8ab14e7b42bc7f34bd54c0cf..312532558090edf22103cdf10241fa7a2747baa3 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -397,8 +397,6 @@ fn run(self, builder: &Builder<'_>) { cargo.env("MIRI", &miri); // Debug things. cargo.env("RUST_BACKTRACE", "1"); - // Overwrite bootstrap's `rustc` wrapper overwriting our flags. - cargo.env("RUSTC_DEBUG_ASSERTIONS", "true"); // Let cargo-miri know where xargo ended up. cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check")); diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index fccdfa0dca92af8e574680a78fac64c43506dba2..77ff567aa7af172c074b3c744f180900e77c326c 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1701,7 +1701,7 @@ pub fn new() -> Weak { /// ``` /// /// [`null`]: ../../std/ptr/fn.null.html - #[stable(feature = "weak_into_raw", since = "1.45.0")] + #[stable(feature = "rc_as_ptr", since = "1.45.0")] pub fn as_ptr(&self) -> *const T { let ptr: *mut RcBox = NonNull::as_ptr(self.ptr); diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 2d6a3917c764e30eb33fb3e60eb47cb0653ddca5..0053a54f20346cbc0408011e13ce4a89e5ba67f5 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -587,7 +587,7 @@ pub fn into_raw(this: Self) -> *const T { /// assert_eq!(x_ptr, Arc::as_ptr(&y)); /// assert_eq!(unsafe { &*x_ptr }, "hello"); /// ``` - #[stable(feature = "weak_into_raw", since = "1.45.0")] + #[stable(feature = "rc_as_ptr", since = "1.45.0")] pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut ArcInner = NonNull::as_ptr(this.ptr); diff --git a/src/libcore/ffi.rs b/src/libcore/ffi.rs index ca4632006509fec3f368a96001265ad5dacb9224..ee3192eddbd06ec67db6f4d9e9546e86cec0cc4c 100644 --- a/src/libcore/ffi.rs +++ b/src/libcore/ffi.rs @@ -1,7 +1,7 @@ #![stable(feature = "", since = "1.30.0")] #![allow(non_camel_case_types)] -//! Utilities related to FFI bindings. +//! Utilities related to foreign function interface (FFI) bindings. use crate::fmt; use crate::marker::PhantomData; diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index 4cc83f8e31c20de2e61fa8cbe288dd1625fd712c..2becbe2f6758a8b0264f0e152054982cc853de07 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -280,6 +280,8 @@ fn verify_piece(&mut self, p: &parse::Piece<'_>) { ("x", "LowerHex"), ("X", "UpperHex"), ] { + // FIXME: rustfix (`run-rustfix`) fails to apply suggestions. + // > "Cannot replace slice of data that was already replaced" err.tool_only_span_suggestion( sp, &format!("use the `{}` trait", name), diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index 2f4b1bbd3ba0f139842191b17162469ebd69c2e5..862ffd50d38f6a2e5df2f6b5641f0f245b6867ba 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -6,17 +6,18 @@ //! produces simple tokens which are a pair of type-tag and a bit of original text, //! and does not report errors, instead storing them as flags on the token. //! -//! Tokens produced by this lexer are not yet ready for parsing the Rust syntax, -//! for that see `librustc_parse::lexer`, which converts this basic token stream +//! Tokens produced by this lexer are not yet ready for parsing the Rust syntax. +//! For that see [`librustc_parse::lexer`], which converts this basic token stream //! into wide tokens used by actual parser. //! //! The purpose of this crate is to convert raw sources into a labeled sequence //! of well-known token types, so building an actual Rust token stream will //! be easier. //! -//! Main entity of this crate is [`TokenKind`] enum which represents common +//! The main entity of this crate is the [`TokenKind`] enum which represents common //! lexeme types. - +//! +//! [`librustc_parse::lexer`]: ../rustc_parse/lexer/index.html // We want to be able to build this crate with a stable compiler, so no // `#![feature]` attributes should be added. diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index e4c1ca4e851b0cfe1f519da46cfac6b1bd60751a..fbe3377d87500f754797dfb1845d83c42594a379 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -1004,14 +1004,6 @@ fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Loca let expected = ScalarMaybeUninit::from(Scalar::from_bool(*expected)); let value_const = self.ecx.read_scalar(value).unwrap(); if expected != value_const { - // Poison all places this operand references so that further code - // doesn't use the invalid value - match cond { - Operand::Move(ref place) | Operand::Copy(ref place) => { - Self::remove_const(&mut self.ecx, place.local); - } - Operand::Constant(_) => {} - } let mut eval_to_int = |op| { let op = self .eval_operand(op, source_info) @@ -1020,27 +1012,37 @@ fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Loca }; let msg = match msg { AssertKind::DivisionByZero(op) => { - AssertKind::DivisionByZero(eval_to_int(op)) + Some(AssertKind::DivisionByZero(eval_to_int(op))) } AssertKind::RemainderByZero(op) => { - AssertKind::RemainderByZero(eval_to_int(op)) + Some(AssertKind::RemainderByZero(eval_to_int(op))) } AssertKind::BoundsCheck { ref len, ref index } => { let len = eval_to_int(len); let index = eval_to_int(index); - AssertKind::BoundsCheck { len, index } + Some(AssertKind::BoundsCheck { len, index }) } // Overflow is are already covered by checks on the binary operators. - AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => return, + AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => None, // Need proper const propagator for these. - _ => return, + _ => None, }; - self.report_assert_as_lint( - lint::builtin::UNCONDITIONAL_PANIC, - source_info, - "this operation will panic at runtime", - msg, - ); + // Poison all places this operand references so that further code + // doesn't use the invalid value + match cond { + Operand::Move(ref place) | Operand::Copy(ref place) => { + Self::remove_const(&mut self.ecx, place.local); + } + Operand::Constant(_) => {} + } + if let Some(msg) = msg { + self.report_assert_as_lint( + lint::builtin::UNCONDITIONAL_PANIC, + source_info, + "this operation will panic at runtime", + msg, + ); + } } else { if self.should_const_prop(value) { if let ScalarMaybeUninit::Scalar(scalar) = value_const { diff --git a/src/librustc_mir_build/build/misc.rs b/src/librustc_mir_build/build/misc.rs index e8933ff8aa749a0db27435c8a481b606dd4ca749..29651d9bc663a8380f436e8483a9555a8c6ac2bf 100644 --- a/src/librustc_mir_build/build/misc.rs +++ b/src/librustc_mir_build/build/misc.rs @@ -15,7 +15,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// N.B., **No cleanup is scheduled for this temporary.** You should /// call `schedule_drop` once the temporary is initialized. crate fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> { - let temp = self.local_decls.push(LocalDecl::new(ty, span)); + // Mark this local as internal to avoid temporaries with types not present in the + // user's code resulting in ICEs from the generator transform. + let temp = self.local_decls.push(LocalDecl::new(ty, span).internal()); let place = Place::from(temp); debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty); place diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index 16a118cb48c913eb1901a75a64f9cd44cbe1fd58..7822c09739049aab36e4c2e631a735e73a1f1dbb 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -1228,10 +1228,13 @@ pub(super) fn recover_closing_delimiter( if let Some(sp) = unmatched.unclosed_span { err.span_label(sp, "unclosed delimiter"); } + // Backticks should be removed to apply suggestions. + let mut delim = delim.to_string(); + delim.retain(|c| c != '`'); err.span_suggestion_short( self.prev_token.span.shrink_to_hi(), - &format!("{} may belong here", delim.to_string()), - delim.to_string(), + &format!("`{}` may belong here", delim), + delim, Applicability::MaybeIncorrect, ); if unmatched.found_delim.is_none() { diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 7811d5fb741b27d946b6ce57c6856d8d2b4977d5..61c680469f03ce15e0b95e60abbd36414464cde2 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -699,7 +699,7 @@ fn parse_seq_to_before_tokens( // misses a separator. expect_err .span_suggestion_short( - sp, + self.sess.source_map().next_point(sp), &format!("missing `{}`", token_str), token_str, Applicability::MaybeIncorrect, diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index d3bccaaa3e4b98e3f8977c6b1964f995140cfd5c..199f49ca323e023c595d45a55509513119c46158 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -488,7 +488,7 @@ fn check_safety_of_rvalue_destructor_if_necessary( ) { if let mc::PlaceBase::Rvalue = place_with_id.place.base { if place_with_id.place.projections.is_empty() { - let typ = self.resolve_type(place_with_id.place.ty); + let typ = self.resolve_type(place_with_id.place.ty()); let body_id = self.body_id; let _ = dropck::check_drop_obligations(self, typ, span, body_id); } @@ -640,8 +640,8 @@ fn link_region( borrow_kind: ty::BorrowKind, borrow_place: &mc::PlaceWithHirId<'tcx>, ) { - let origin = infer::DataBorrowed(borrow_place.place.ty, span); - self.type_must_outlive(origin, borrow_place.place.ty, borrow_region); + let origin = infer::DataBorrowed(borrow_place.place.ty(), span); + self.type_must_outlive(origin, borrow_place.place.ty(), borrow_region); for pointer_ty in borrow_place.place.deref_tys() { debug!( diff --git a/src/librustc_typeck/expr_use_visitor.rs b/src/librustc_typeck/expr_use_visitor.rs index b72fae96e4ca0ac25d6d047c57c35ff140522ccd..4e5ef4329c2c612bc68843cf0255d9e0188519f4 100644 --- a/src/librustc_typeck/expr_use_visitor.rs +++ b/src/librustc_typeck/expr_use_visitor.rs @@ -384,7 +384,7 @@ fn walk_struct_expr( // Select just those fields of the `with` // expression that will actually be used - match with_place.place.ty.kind { + match with_place.place.ty().kind { ty::Adt(adt, substs) if adt.is_struct() => { // Consume those fields of the with expression that are needed. for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() { @@ -583,7 +583,7 @@ fn copy_or_move<'a, 'tcx>( place_with_id: &PlaceWithHirId<'tcx>, ) -> ConsumeMode { if !mc.type_is_copy_modulo_regions( - place_with_id.place.ty, + place_with_id.place.ty(), mc.tcx().hir().span(place_with_id.hir_id), ) { Move diff --git a/src/librustc_typeck/mem_categorization.rs b/src/librustc_typeck/mem_categorization.rs index d619d37be2d7b9ef201c9037d63dd7f24de4f149..ac42ce80689ec1a4cdbfafdecc15efd81b85eb41 100644 --- a/src/librustc_typeck/mem_categorization.rs +++ b/src/librustc_typeck/mem_categorization.rs @@ -73,18 +73,21 @@ pub enum PlaceBase { Upvar(ty::UpvarId), } -#[derive(Clone, Debug)] -pub enum ProjectionKind<'tcx> { +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum ProjectionKind { /// A dereference of a pointer, reference or `Box` of the given type - Deref(Ty<'tcx>), + Deref, /// An index or a field Other, } #[derive(Clone, Debug)] pub struct Projection<'tcx> { + // Type after the projection is being applied. + ty: Ty<'tcx>, + /// Defines the type of access - kind: ProjectionKind<'tcx>, + kind: ProjectionKind, } /// A `Place` represents how a value is located in memory. @@ -92,8 +95,8 @@ pub struct Projection<'tcx> { /// This is an HIR version of `mir::Place` #[derive(Clone, Debug)] pub struct Place<'tcx> { - /// The type of the `Place` - pub ty: Ty<'tcx>, + /// The type of the `PlaceBase` + pub base_ty: Ty<'tcx>, /// The "outermost" place that holds this value. pub base: PlaceBase, /// How this place is derived from the base place. @@ -115,13 +118,13 @@ pub struct PlaceWithHirId<'tcx> { impl<'tcx> PlaceWithHirId<'tcx> { crate fn new( hir_id: hir::HirId, - ty: Ty<'tcx>, + base_ty: Ty<'tcx>, base: PlaceBase, projections: Vec>, ) -> PlaceWithHirId<'tcx> { PlaceWithHirId { hir_id: hir_id, - place: Place { ty: ty, base: base, projections: projections }, + place: Place { base_ty: base_ty, base: base, projections: projections }, } } } @@ -134,10 +137,26 @@ impl<'tcx> Place<'tcx> { /// `x: &*const u32` and the `Place` is `**x`, then the types returned are ///`*const u32` then `&*const u32`. crate fn deref_tys(&self) -> impl Iterator> + '_ { - self.projections.iter().rev().filter_map(|proj| { - if let ProjectionKind::Deref(deref_ty) = proj.kind { Some(deref_ty) } else { None } + self.projections.iter().enumerate().rev().filter_map(move |(index, proj)| { + if ProjectionKind::Deref == proj.kind { + Some(self.ty_before_projection(index)) + } else { + None + } }) } + + // Returns the type of this `Place` after all projections have been applied. + pub fn ty(&self) -> Ty<'tcx> { + self.projections.last().map_or_else(|| self.base_ty, |proj| proj.ty) + } + + // Returns the type of this `Place` immediately before `projection_index`th projection + // is applied. + crate fn ty_before_projection(&self, projection_index: usize) -> Ty<'tcx> { + assert!(projection_index < self.projections.len()); + if projection_index == 0 { self.base_ty } else { self.projections[projection_index - 1].ty } + } } crate trait HirNode { @@ -516,8 +535,13 @@ fn cat_upvar(&self, hir_id: hir::HirId, var_id: hir::HirId) -> McResult, ) -> PlaceWithHirId<'tcx> { let mut projections = base_place.place.projections; - projections.push(Projection { kind: ProjectionKind::Other }); - let ret = PlaceWithHirId::new(node.hir_id(), ty, base_place.place.base, projections); + projections.push(Projection { kind: ProjectionKind::Other, ty: ty }); + let ret = PlaceWithHirId::new( + node.hir_id(), + base_place.place.base_ty, + base_place.place.base, + projections, + ); debug!("cat_field ret {:?}", ret); ret } @@ -552,18 +576,23 @@ fn cat_deref( ) -> McResult> { debug!("cat_deref: base_place={:?}", base_place); - let base_ty = base_place.place.ty; - let deref_ty = match base_ty.builtin_deref(true) { + let base_curr_ty = base_place.place.ty(); + let deref_ty = match base_curr_ty.builtin_deref(true) { Some(mt) => mt.ty, None => { - debug!("explicit deref of non-derefable type: {:?}", base_ty); + debug!("explicit deref of non-derefable type: {:?}", base_curr_ty); return Err(()); } }; let mut projections = base_place.place.projections; - projections.push(Projection { kind: ProjectionKind::Deref(base_ty) }); - - let ret = PlaceWithHirId::new(node.hir_id(), deref_ty, base_place.place.base, projections); + projections.push(Projection { kind: ProjectionKind::Deref, ty: deref_ty }); + + let ret = PlaceWithHirId::new( + node.hir_id(), + base_place.place.base_ty, + base_place.place.base, + projections, + ); debug!("cat_deref ret {:?}", ret); Ok(ret) } @@ -687,7 +716,7 @@ fn cat_pattern_( } PatKind::Slice(before, ref slice, after) => { - let element_ty = match place_with_id.place.ty.builtin_index() { + let element_ty = match place_with_id.place.ty().builtin_index() { Some(ty) => ty, None => { debug!("explicit index of non-indexable type {:?}", place_with_id); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 35b15cf717cee1270b687315e450e8dacf8717c7..14a6f3c89a3c9486560bb7da93af8f33caba8ea0 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -242,8 +242,6 @@ pub struct RenderOptions { /// If false, the `select` element to have search filtering by crates on rendered docs /// won't be generated. pub generate_search_filter: bool, - /// Option (disabled by default) to generate files used by RLS and some other tools. - pub generate_redirect_pages: bool, /// Document items that have lower than `pub` visibility. pub document_private: bool, /// Document items that have `doc(hidden)`. @@ -528,7 +526,6 @@ fn println_condition(condition: Condition) { let static_root_path = matches.opt_str("static-root-path"); let generate_search_filter = !matches.opt_present("disable-per-crate-search"); let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from); - let generate_redirect_pages = matches.opt_present("generate-redirect-pages"); let test_builder = matches.opt_str("test-builder").map(PathBuf::from); let codegen_options_strs = matches.opt_strs("C"); let debugging_options_strs = matches.opt_strs("Z"); @@ -592,7 +589,6 @@ fn println_condition(condition: Condition) { markdown_css, markdown_playground_url, generate_search_filter, - generate_redirect_pages, document_private, document_hidden, }, diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index 0b2b0cdc18b092e5c135c8cded2d3ef400566479..cc78b4682d231a9d6431a818152fdab3ab34e378 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -154,38 +154,6 @@ pub fn as_str(&self) -> &'static str { ItemType::TraitAlias => "traitalias", } } - - pub fn name_space(&self) -> &'static str { - match *self { - ItemType::Struct - | ItemType::Union - | ItemType::Enum - | ItemType::Module - | ItemType::Typedef - | ItemType::Trait - | ItemType::Primitive - | ItemType::AssocType - | ItemType::OpaqueTy - | ItemType::TraitAlias - | ItemType::ForeignType => NAMESPACE_TYPE, - - ItemType::ExternCrate - | ItemType::Import - | ItemType::Function - | ItemType::Static - | ItemType::Impl - | ItemType::TyMethod - | ItemType::Method - | ItemType::StructField - | ItemType::Variant - | ItemType::Constant - | ItemType::AssocConst => NAMESPACE_VALUE, - - ItemType::Macro | ItemType::ProcAttribute | ItemType::ProcDerive => NAMESPACE_MACRO, - - ItemType::Keyword => NAMESPACE_KEYWORD, - } - } } impl fmt::Display for ItemType { @@ -193,8 +161,3 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.as_str()) } } - -pub const NAMESPACE_TYPE: &str = "t"; -pub const NAMESPACE_VALUE: &str = "v"; -pub const NAMESPACE_MACRO: &str = "m"; -pub const NAMESPACE_KEYWORD: &str = "k"; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 04c4685213b2e7df6ad05df902306e7c7156afef..69e3540ed625be77c49298ce2a26682fc823550d 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -195,8 +195,6 @@ struct Context { /// Optional path string to be used to load static files on output pages. If not set, uses /// combinations of `../` to reach the documentation root. pub static_root_path: Option, - /// Option disabled by default to generate files used by RLS and some other tools. - pub generate_redirect_pages: bool, /// The fs handle we are working with. pub fs: DocFS, /// The default edition used to parse doctests. @@ -468,7 +466,6 @@ pub fn run( resource_suffix, static_root_path, generate_search_filter, - generate_redirect_pages, document_private, .. } = options; @@ -536,7 +533,6 @@ pub fn run( themes, resource_suffix, static_root_path, - generate_redirect_pages, fs: DocFS::new(&errors), edition, codes: ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()), @@ -1556,14 +1552,6 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result if !self.render_redirect_pages { all.append(full_path(self, &item), &item_type); } - if self.shared.generate_redirect_pages { - // Redirect from a sane URL using the namespace to Rustdoc's - // URL for the page. - let redir_name = format!("{}.{}.html", name, item_type.name_space()); - let redir_dst = self.dst.join(redir_name); - let v = layout::redirect(file_name); - self.shared.fs.write(&redir_dst, v.as_bytes())?; - } // If the item is a macro, redirect from the old macro URL (with !) // to the new one (without). if item_type == ItemType::Macro { @@ -2586,8 +2574,7 @@ fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item) { let name = m.name.as_ref().unwrap(); let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); - let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "

", id = id, ns_id = ns_id); + write!(w, "

", id = id); render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl); write!(w, ""); render_stability_since(w, m, t); @@ -2972,20 +2959,14 @@ fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct ItemType::StructField, field.name.as_ref().unwrap() )); - let ns_id = cx.derive_id(format!( - "{}.{}", - field.name.as_ref().unwrap(), - ItemType::StructField.name_space() - )); write!( w, "\ \ - {name}: {ty}\ + {name}: {ty}\ ", item_type = ItemType::StructField, id = id, - ns_id = ns_id, name = field.name.as_ref().unwrap(), ty = ty.print() ); @@ -3103,18 +3084,12 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) { for variant in &e.variants { let id = cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.as_ref().unwrap())); - let ns_id = cx.derive_id(format!( - "{}.{}", - variant.name.as_ref().unwrap(), - ItemType::Variant.name_space() - )); write!( w, "
\ - \ - {name}", + \ + {name}", id = id, - ns_id = ns_id, name = variant.name.as_ref().unwrap() ); if let clean::VariantItem(ref var) = variant.inner { @@ -3155,21 +3130,13 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) { variant.name.as_ref().unwrap(), field.name.as_ref().unwrap() )); - let ns_id = cx.derive_id(format!( - "{}.{}.{}.{}", - variant.name.as_ref().unwrap(), - ItemType::Variant.name_space(), - field.name.as_ref().unwrap(), - ItemType::StructField.name_space() - )); write!( w, "\ \ - {f}: {t}\ + {f}: {t}\ ", id = id, - ns_id = ns_id, f = field.name.as_ref().unwrap(), t = ty.print() ); @@ -3661,9 +3628,7 @@ fn doc_impl_item( // Only render when the method is not static or we allow static methods if render_method_item { let id = cx.derive_id(format!("{}.{}", item_type, name)); - let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "

", id, item_type, extra_class); - write!(w, "", ns_id); + write!(w, "

", id, item_type, extra_class); render_assoc_item(w, item, link.anchor(&id), ItemType::Impl); write!(w, ""); render_stability_since_raw(w, item.stable_since(), outer_version); @@ -3679,17 +3644,13 @@ fn doc_impl_item( } clean::TypedefItem(ref tydef, _) => { let id = cx.derive_id(format!("{}.{}", ItemType::AssocType, name)); - let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "

", id, item_type, extra_class); - write!(w, "", ns_id); + write!(w, "

", id, item_type, extra_class); assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id), ""); write!(w, "

"); } clean::AssocConstItem(ref ty, ref default) => { let id = cx.derive_id(format!("{}.{}", item_type, name)); - let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "

", id, item_type, extra_class); - write!(w, "", ns_id); + write!(w, "

", id, item_type, extra_class); assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), ""); write!(w, ""); render_stability_since_raw(w, item.stable_since(), outer_version); @@ -3704,9 +3665,7 @@ fn doc_impl_item( } clean::AssocTypeItem(ref bounds, ref default) => { let id = cx.derive_id(format!("{}.{}", item_type, name)); - let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "

", id, item_type, extra_class); - write!(w, "", ns_id); + write!(w, "

", id, item_type, extra_class); assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), ""); write!(w, "

"); } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 62a23298c1b9f215bb09bab134a21c90acb56ea4..69e2bacc21882e3d81fa18f1ca7838ed97ad7d8f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -112,9 +112,11 @@ function defocusSearchBar() { } function getPageId() { - var id = document.location.href.split("#")[1]; - if (id) { - return id.split("?")[0].split("&")[0]; + if (window.location.hash) { + var tmp = window.location.hash.replace(/^#/, ""); + if (tmp.length > 0) { + return tmp; + } } return null; } @@ -2551,6 +2553,13 @@ function defocusSearchBar() { onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper); onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper); + var pageId = getPageId(); + + autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true"); + + if (pageId !== null) { + expandSection(pageId); + } }()); function createToggleWrapper(tog) { @@ -2686,12 +2695,6 @@ function defocusSearchBar() { hideSidebar(); }; - autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true"); - - if (window.location.hash && window.location.hash.length > 0) { - expandSection(window.location.hash.replace(/^#/, "")); - } - if (main) { onEachLazy(main.getElementsByClassName("loading-content"), function(e) { e.remove(); diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 9c6dd25394db0e8ed4d1c1c0beffbf9cd36eaa3e..a3f4dc55fe757eb3fc9d6de8d70250afd21c9e85 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -100,6 +100,9 @@ h1.fqn { border-bottom: 1px dashed; margin-top: 0; } +h1.fqn > .in-band > a:hover { + text-decoration: underline; +} h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) { border-bottom: 1px solid; } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index de6fa3dbd4a89135d7a83f8843f49d148c51ce9e..8e2dd77cc115542ff779142ea76c9ac7e1b3f577 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -374,13 +374,6 @@ fn opts() -> Vec { "PATH", ) }), - unstable("generate-redirect-pages", |o| { - o.optflag( - "", - "generate-redirect-pages", - "Generate extra pages to support legacy URLs and tool links", - ) - }), unstable("show-coverage", |o| { o.optflag( "", diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 8da74f375d9ceb1916e17c5da9e584e545a84268..f1d1bf439f17133e1eac0d11f1d14d2f29bd33f5 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -164,6 +164,7 @@ fn macro_resolve(&self, path_str: &str, parent_id: Option) -> Option fn resolve( &self, path_str: &str, + disambiguator: Option<&str>, ns: Namespace, current_item: &Option, parent_id: Option, @@ -203,11 +204,22 @@ fn resolve( } return Ok((res, Some(path_str.to_owned()))); } - other => { - debug!( - "failed to resolve {} in namespace {:?} (got {:?})", - path_str, ns, other - ); + Res::Def(DefKind::Mod, _) => { + // This resolved to a module, but if we were passed `type@`, + // we want primitive types to take precedence instead. + if disambiguator == Some("type") { + if let Some(prim) = is_primitive(path_str, ns) { + if extra_fragment.is_some() { + return Err(ErrorKind::AnchorFailure( + "primitive types cannot be followed by anchors", + )); + } + return Ok((prim, Some(path_str.to_owned()))); + } + } + return Ok((res, extra_fragment.clone())); + } + _ => { return Ok((res, extra_fragment.clone())); } }; @@ -566,11 +578,13 @@ fn fold_item(&mut self, mut item: Item) -> Option { let mut path_str; let (res, fragment) = { let mut kind = None; + let mut disambiguator = None; path_str = if let Some(prefix) = ["struct@", "enum@", "type@", "trait@", "union@"] .iter() .find(|p| link.starts_with(**p)) { kind = Some(TypeNS); + disambiguator = Some(&prefix[..prefix.len() - 1]); link.trim_start_matches(prefix) } else if let Some(prefix) = [ "const@", @@ -586,18 +600,23 @@ fn fold_item(&mut self, mut item: Item) -> Option { .find(|p| link.starts_with(**p)) { kind = Some(ValueNS); + disambiguator = Some(&prefix[..prefix.len() - 1]); link.trim_start_matches(prefix) } else if link.ends_with("()") { kind = Some(ValueNS); + disambiguator = Some("fn"); link.trim_end_matches("()") } else if link.starts_with("macro@") { kind = Some(MacroNS); + disambiguator = Some("macro"); link.trim_start_matches("macro@") } else if link.starts_with("derive@") { kind = Some(MacroNS); + disambiguator = Some("derive"); link.trim_start_matches("derive@") } else if link.ends_with('!') { kind = Some(MacroNS); + disambiguator = Some("macro"); link.trim_end_matches('!') } else { &link[..] @@ -634,6 +653,7 @@ fn fold_item(&mut self, mut item: Item) -> Option { Some(ns @ ValueNS) => { match self.resolve( path_str, + disambiguator, ns, ¤t_item, base_node, @@ -657,6 +677,7 @@ fn fold_item(&mut self, mut item: Item) -> Option { Some(ns @ TypeNS) => { match self.resolve( path_str, + disambiguator, ns, ¤t_item, base_node, @@ -683,6 +704,7 @@ fn fold_item(&mut self, mut item: Item) -> Option { .map(|res| (res, extra_fragment.clone())), type_ns: match self.resolve( path_str, + disambiguator, TypeNS, ¤t_item, base_node, @@ -697,6 +719,7 @@ fn fold_item(&mut self, mut item: Item) -> Option { }, value_ns: match self.resolve( path_str, + disambiguator, ValueNS, ¤t_item, base_node, @@ -1069,7 +1092,7 @@ fn handle_variant( }; let parent_def = Res::Def(DefKind::Enum, parent); let variant = cx.tcx.expect_variant_res(res); - Ok((parent_def, Some(format!("{}.v", variant.ident.name)))) + Ok((parent_def, Some(format!("variant.{}", variant.ident.name)))) } const PRIMITIVES: &[(&str, Res)] = &[ diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 9ac54dd5f7a65e328092e72bf1aae22438310125..47b8532b7a6e6d1bdada556bbc32b8bc4f8f645b 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_op_in_unsafe_fn)] use crate::io::prelude::*; use crate::fmt; @@ -583,7 +584,8 @@ fn is_read_vectored(&self) -> bool { #[inline] unsafe fn initializer(&self) -> Initializer { - Initializer::nop() + // SAFETY: Read is guaranteed to work on uninitialized memory + unsafe { Initializer::nop() } } } #[stable(feature = "rust1", since = "1.0.0")] @@ -622,7 +624,8 @@ fn is_read_vectored(&self) -> bool { #[inline] unsafe fn initializer(&self) -> Initializer { - Initializer::nop() + // SAFETY: Read is guaranteed to work on uninitialized memory + unsafe { Initializer::nop() } } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index e4d714936047e71b03807c2afc5e24deb6eb87a7..2b2bbc6e9d6ae473a24ca68f6b2676fa0428fffa 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -133,7 +133,7 @@ fn read_exact_at(&self, mut buf: &mut [u8], mut offset: u64) -> io::Result<()> { /// Note that similar to [`File::write`], it is not an error to return a /// short write. /// - /// [`File::write`]: ../../../../std/fs/struct.File.html#write.v + /// [`File::write`]: ../../../../std/fs/struct.File.html#method.write /// /// # Examples /// diff --git a/src/libstd/sys/vxworks/ext/fs.rs b/src/libstd/sys/vxworks/ext/fs.rs index 7cc64658ee1a9d1dd6d45fe14efbe60dea4618f7..b479fbaf34613a422121d674b1f88e522c3395ae 100644 --- a/src/libstd/sys/vxworks/ext/fs.rs +++ b/src/libstd/sys/vxworks/ext/fs.rs @@ -132,7 +132,7 @@ fn read_exact_at(&self, mut buf: &mut [u8], mut offset: u64) -> io::Result<()> { /// Note that similar to [`File::write`], it is not an error to return a /// short write. /// - /// [`File::write`]: ../../../../std/fs/struct.File.html#write.v + /// [`File::write`]: ../../../../std/fs/struct.File.html#method.write /// /// # Examples /// diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index f85120d170f737269f11ffdf445acf4fc7e0d608..81b2bf998720022c3765ce605c60b654244b56fb 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -259,7 +259,7 @@ pub trait OpenOptionsExt { /// [Impersonation Levels]: /// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-security_impersonation_level #[stable(feature = "open_options_ext", since = "1.10.0")] - fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions; + fn security_qos_flags(&mut self, flags: u32) -> &mut Self; } #[stable(feature = "open_options_ext", since = "1.10.0")] diff --git a/src/test/rustdoc/assoc-types.rs b/src/test/rustdoc/assoc-types.rs index b708dc0c717ca61cfe5e233256b7ec61d40a0a96..5f0fdbb322cad0c269bdd715025f42158160792b 100644 --- a/src/test/rustdoc/assoc-types.rs +++ b/src/test/rustdoc/assoc-types.rs @@ -5,9 +5,7 @@ // @has assoc_types/trait.Index.html pub trait Index { // @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized' - // @has - '//code[@id="Output.t"]' 'type Output: ?Sized' type Output: ?Sized; - // @has - '//code[@id="index.v"]' 'fn index' // @has - '//*[@id="tymethod.index"]//code' \ // "fn index<'a>(&'a self, index: I) -> &'a Self::Output" // @has - '//*[@id="tymethod.index"]//code//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' \ diff --git a/src/test/rustdoc/const.rs b/src/test/rustdoc/const.rs index c33db5809cc7c5d685e47d439e66523f7d65a527..638de3292becbafb83eee6c48aecd6370b118f2c 100644 --- a/src/test/rustdoc/const.rs +++ b/src/test/rustdoc/const.rs @@ -3,7 +3,7 @@ pub struct Foo; impl Foo { - // @has const/struct.Foo.html '//code[@id="new.v"]' 'const unsafe fn new' + // @has const/struct.Foo.html '//*[@id="method.new"]//code' 'const unsafe fn new' pub const unsafe fn new() -> Foo { Foo } diff --git a/src/test/rustdoc/inline_cross/impl_trait.rs b/src/test/rustdoc/inline_cross/impl_trait.rs index 6f4a48c83c05ba3108f1b038e5f9b12197794631..e3a166b3d0e5fba8709f14b999b21d904f3443de 100644 --- a/src/test/rustdoc/inline_cross/impl_trait.rs +++ b/src/test/rustdoc/inline_cross/impl_trait.rs @@ -31,8 +31,8 @@ pub use impl_trait_aux::async_fn; // @has impl_trait/struct.Foo.html -// @has - '//code[@id="method.v"]' "pub fn method<'a>(_x: impl Clone + Into> + 'a)" -// @!has - '//code[@id="method.v"]' 'where' +// @has - '//*[@id="method.method"]//code' "pub fn method<'a>(_x: impl Clone + Into> + 'a)" +// @!has - '//*[@id="method.method"]//code' 'where' pub use impl_trait_aux::Foo; // @has impl_trait/struct.Bar.html diff --git a/src/test/rustdoc/intra-link-prim-precedence.rs b/src/test/rustdoc/intra-link-prim-precedence.rs new file mode 100644 index 0000000000000000000000000000000000000000..ca83d5e2281a72f72ed3febccc1457ac374a4b94 --- /dev/null +++ b/src/test/rustdoc/intra-link-prim-precedence.rs @@ -0,0 +1,12 @@ +// ignore-tidy-linelength +#![deny(intra_doc_resolution_failure)] + +pub mod char {} + +/// See also [type@char] +// @has intra_link_prim_precedence/struct.MyString.html '//a/@href' 'https://doc.rust-lang.org/nightly/std/primitive.char.html' +pub struct MyString; + +/// See also [char] +// @has intra_link_prim_precedence/struct.MyString2.html '//a/@href' 'intra_link_prim_precedence/char/index.html' +pub struct MyString2; diff --git a/src/test/rustdoc/intra-link-self.rs b/src/test/rustdoc/intra-link-self.rs index 97752d5cfcb5c96d29e81fc020c4231d70102594..81545fec7411bc0654e6bf399f135759f6e5f1e8 100644 --- a/src/test/rustdoc/intra-link-self.rs +++ b/src/test/rustdoc/intra-link-self.rs @@ -40,7 +40,7 @@ pub struct MyStruct { } pub enum MyEnum { - // @has foo/enum.MyEnum.html '//a/@href' '../foo/enum.MyEnum.html#EnumVariant.v' + // @has foo/enum.MyEnum.html '//a/@href' '../foo/enum.MyEnum.html#variant.EnumVariant' /// [`EnumVariant`] /// diff --git a/src/test/rustdoc/intra-links.rs b/src/test/rustdoc/intra-links.rs index c356ab3a8ac52d9de2b85e3c9c61d8a848deac86..c6725f526aa2aada62cb11a9fc1895dd6051bd6b 100644 --- a/src/test/rustdoc/intra-links.rs +++ b/src/test/rustdoc/intra-links.rs @@ -2,7 +2,7 @@ // @has - '//a/@href' '../intra_links/struct.ThisType.html' // @has - '//a/@href' '../intra_links/struct.ThisType.html#method.this_method' // @has - '//a/@href' '../intra_links/enum.ThisEnum.html' -// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#ThisVariant.v' +// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#variant.ThisVariant' // @has - '//a/@href' '../intra_links/trait.ThisTrait.html' // @has - '//a/@href' '../intra_links/trait.ThisTrait.html#tymethod.this_associated_method' // @has - '//a/@href' '../intra_links/trait.ThisTrait.html#associatedtype.ThisAssociatedType' @@ -73,7 +73,7 @@ pub fn SoAmbiguous() {} // @has - '//a/@href' '../intra_links/struct.ThisType.html' // @has - '//a/@href' '../intra_links/struct.ThisType.html#method.this_method' // @has - '//a/@href' '../intra_links/enum.ThisEnum.html' -// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#ThisVariant.v' +// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#variant.ThisVariant' /// Shortcut links for: /// * [`ThisType`] /// * [`ThisType::this_method`] diff --git a/src/test/rustdoc/issue-19190.rs b/src/test/rustdoc/issue-19190.rs index c6bac51c5740dcd6da42b9af545f843a53724fcd..9dac49c6413d803ca7906b8b5dc11864a68e5625 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -1,5 +1,3 @@ -// compile-flags:-Z unstable-options --generate-redirect-pages - use std::ops::Deref; pub struct Foo; @@ -15,9 +13,8 @@ impl Deref for Bar { fn deref(&self) -> &Foo { loop {} } } -// @has issue_19190/Bar.t.html // @has issue_19190/struct.Bar.html -// @has - '//*[@id="foo.v"]' 'fn foo(&self)' +// @has - '//*[@id="method.foo"]//code' 'fn foo(&self)' // @has - '//*[@id="method.foo"]' 'fn foo(&self)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' +// @!has - '//*[@id="method.static_foo"]//code' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-25001.rs b/src/test/rustdoc/issue-25001.rs index 55d8ee394385b50b4bc4c49c59784e0ef39bb6de..e53cf6451353f733a6da031e3b447d9bca4996c6 100644 --- a/src/test/rustdoc/issue-25001.rs +++ b/src/test/rustdoc/issue-25001.rs @@ -9,17 +9,14 @@ pub trait Bar { impl Foo { // @has - '//*[@id="method.pass"]//code' 'fn pass()' - // @has - '//code[@id="pass.v"]' 'fn pass()' pub fn pass() {} } impl Foo { // @has - '//*[@id="method.pass-1"]//code' 'fn pass() -> usize' - // @has - '//code[@id="pass.v-1"]' 'fn pass() -> usize' pub fn pass() -> usize { 42 } } impl Foo { // @has - '//*[@id="method.pass-2"]//code' 'fn pass() -> isize' - // @has - '//code[@id="pass.v-2"]' 'fn pass() -> isize' pub fn pass() -> isize { 42 } } diff --git a/src/test/rustdoc/issue-35169-2.rs b/src/test/rustdoc/issue-35169-2.rs index 33f7646ced68b4ef1f13442ff2b4cd3f23edc2cc..a688ae48d00ce84bbf01b5908c3be9ae8662f5b2 100644 --- a/src/test/rustdoc/issue-35169-2.rs +++ b/src/test/rustdoc/issue-35169-2.rs @@ -24,17 +24,17 @@ fn deref_mut(&mut self) -> &mut Foo { loop {} } } // @has issue_35169_2/struct.Bar.html -// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' +// @has - '//*[@id="method.by_ref"]//code' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' -// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' +// @has - '//*[@id="method.by_explicit_ref"]//code' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' -// @has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' +// @has - '//*[@id="method.by_mut_ref"]//code' 'fn by_mut_ref(&mut self)' // @has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' -// @has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' +// @has - '//*[@id="method.by_explicit_mut_ref"]//code' 'fn by_explicit_mut_ref(self: &mut Foo)' // @has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' -// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' +// @!has - '//*[@id="method.by_explicit_box"]//code' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' -// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' +// @!has - '//*[@id="method.by_explicit_self_box"]//code' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' +// @!has - '//*[@id="method.static_foo"]//code' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-35169.rs b/src/test/rustdoc/issue-35169.rs index 04fffc40572a6b5515cfad66c6f99b924c78261f..4f10c04a616b382f839978f2a148b8e7ae39b77c 100644 --- a/src/test/rustdoc/issue-35169.rs +++ b/src/test/rustdoc/issue-35169.rs @@ -19,17 +19,17 @@ fn deref(&self) -> &Foo { loop {} } } // @has issue_35169/struct.Bar.html -// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' +// @has - '//*[@id="method.by_ref"]//code' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' -// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' +// @has - '//*[@id="method.by_explicit_ref"]//code' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' -// @!has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' +// @!has - '//*[@id="method.by_mut_ref"]//code' 'fn by_mut_ref(&mut self)' // @!has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' -// @!has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' +// @!has - '//*[@id="method.by_explicit_mut_ref"]//code' 'fn by_explicit_mut_ref(self: &mut Foo)' // @!has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' -// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' +// @!has - '//*[@id="method.by_explicit_box"]//code' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' -// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' +// @!has - '//*[@id="method.by_explicit_self_box"]//code' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' +// @!has - '//*[@id="method.static_foo"]//code' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/struct-field.rs b/src/test/rustdoc/struct-field.rs index c99169fbca57fa398a0d65ee39025a90855f91a3..532e29bc691c4265249c3b4122999bd36cb0439a 100644 --- a/src/test/rustdoc/struct-field.rs +++ b/src/test/rustdoc/struct-field.rs @@ -4,7 +4,7 @@ // @has foo/index.html '//*[@class="docblock"]/p/a[@href="../foo/struct.Foo.html#structfield.bar"]' 'Foo::bar' // @has foo/index.html '//*[@class="docblock"]/p/a[@href="../foo/union.Bar.html#structfield.foo"]' 'Bar::foo' -// @has foo/index.html '//*[@class="docblock"]/p/a[@href="../foo/enum.Uniooon.html#X.v"]' 'Uniooon::X' +// @has foo/index.html '//*[@class="docblock"]/p/a[@href="../foo/enum.Uniooon.html#variant.X"]' 'Uniooon::X' //! Test with [Foo::bar], [Bar::foo], [Uniooon::X] diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index 235f0e852da2ca9dd4bb49bb34a8877de71c7406..6de198453cd273d2fde91ceb7580d280a630987e 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,7 +1,3 @@ -// compile-flags:-Z unstable-options --generate-redirect-pages - -// @has structfields/Foo.t.html -// @has - struct.Foo.html // @has structfields/struct.Foo.html pub struct Foo { // @has - //pre "pub a: ()" @@ -16,8 +12,6 @@ pub struct Foo { pub d: usize, } -// @has structfields/Bar.t.html -// @has - struct.Bar.html // @has structfields/struct.Bar.html pub struct Bar { // @has - //pre "pub a: ()" @@ -25,8 +19,6 @@ pub struct Bar { // @!has - //pre "// some fields omitted" } -// @has structfields/Qux.t.html -// @has - enum.Qux.html // @has structfields/enum.Qux.html pub enum Qux { Quz { diff --git a/src/test/ui/block-expression-remove-semicolon.fixed b/src/test/ui/block-expression-remove-semicolon.fixed new file mode 100644 index 0000000000000000000000000000000000000000..5629d4b6e6e5f65e8ee8d10b651baa7f70389d49 --- /dev/null +++ b/src/test/ui/block-expression-remove-semicolon.fixed @@ -0,0 +1,12 @@ +// run-rustfix + +fn foo() -> i32 { + 0 +} + +fn main() { + let _x: i32 = { + //~^ ERROR mismatched types + foo() //~ HELP consider removing this semicolon + }; +} diff --git a/src/test/ui/block-expression-remove-semicolon.rs b/src/test/ui/block-expression-remove-semicolon.rs index afa10b38b91445a3d02761de281f2754c0a4f360..33f11b50afca2adbd84706fdd4f1b3168664219a 100644 --- a/src/test/ui/block-expression-remove-semicolon.rs +++ b/src/test/ui/block-expression-remove-semicolon.rs @@ -1,9 +1,11 @@ +// run-rustfix + fn foo() -> i32 { - 0 + 0 } fn main() { - let x: i32 = { + let _x: i32 = { //~^ ERROR mismatched types foo(); //~ HELP consider removing this semicolon }; diff --git a/src/test/ui/block-expression-remove-semicolon.stderr b/src/test/ui/block-expression-remove-semicolon.stderr index e39cd04f81b3c7869b4c2b21530c8adf4756f6b2..74dc4d595a9294d88a43c1cef0a980be24134b5b 100644 --- a/src/test/ui/block-expression-remove-semicolon.stderr +++ b/src/test/ui/block-expression-remove-semicolon.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types - --> $DIR/block-expression-remove-semicolon.rs:6:18 + --> $DIR/block-expression-remove-semicolon.rs:8:19 | -LL | let x: i32 = { - | __________________^ +LL | let _x: i32 = { + | ___________________^ LL | | LL | | foo(); | | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/consider-removing-last-semi.fixed b/src/test/ui/block-result/consider-removing-last-semi.fixed new file mode 100644 index 0000000000000000000000000000000000000000..a2ecb73ac5b28f290a7af9fc0ba5e08c03d4605e --- /dev/null +++ b/src/test/ui/block-result/consider-removing-last-semi.fixed @@ -0,0 +1,13 @@ +// run-rustfix + +pub fn f() -> String { //~ ERROR mismatched types + 0u8; + "bla".to_string() +} + +pub fn g() -> String { //~ ERROR mismatched types + "this won't work".to_string(); + "removeme".to_string() +} + +fn main() {} diff --git a/src/test/ui/block-result/consider-removing-last-semi.rs b/src/test/ui/block-result/consider-removing-last-semi.rs index f8cdccba27e202854b49ffe8ace1368af77f68b5..4991d24b26cced93060180bc8763c517ed2251e1 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.rs +++ b/src/test/ui/block-result/consider-removing-last-semi.rs @@ -1,9 +1,11 @@ -fn f() -> String { //~ ERROR mismatched types +// run-rustfix + +pub fn f() -> String { //~ ERROR mismatched types 0u8; "bla".to_string(); } -fn g() -> String { //~ ERROR mismatched types +pub fn g() -> String { //~ ERROR mismatched types "this won't work".to_string(); "removeme".to_string(); } diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr index b45f2a6282136c63c6f1c410da25bb416c5ddd45..15ca8316708a2b5d8f516558a2df0150f2a60dcf 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.stderr +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -1,21 +1,21 @@ error[E0308]: mismatched types - --> $DIR/consider-removing-last-semi.rs:1:11 + --> $DIR/consider-removing-last-semi.rs:3:15 | -LL | fn f() -> String { - | - ^^^^^^ expected struct `std::string::String`, found `()` - | | - | implicitly returns `()` as its body has no tail or `return` expression +LL | pub fn f() -> String { + | - ^^^^^^ expected struct `std::string::String`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression LL | 0u8; LL | "bla".to_string(); | - help: consider removing this semicolon error[E0308]: mismatched types - --> $DIR/consider-removing-last-semi.rs:6:11 + --> $DIR/consider-removing-last-semi.rs:8:15 | -LL | fn g() -> String { - | - ^^^^^^ expected struct `std::string::String`, found `()` - | | - | implicitly returns `()` as its body has no tail or `return` expression +LL | pub fn g() -> String { + | - ^^^^^^ expected struct `std::string::String`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression LL | "this won't work".to_string(); LL | "removeme".to_string(); | - help: consider removing this semicolon diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.fixed b/src/test/ui/coercion/coercion-missing-tail-expected-type.fixed new file mode 100644 index 0000000000000000000000000000000000000000..713e04774a0e70a6356f8e20835afc29e6c47170 --- /dev/null +++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.fixed @@ -0,0 +1,16 @@ +// #41425 -- error message "mismatched types" has wrong types +// run-rustfix + +fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types + x + 1 +} + +fn foo() -> Result { //~ ERROR mismatched types + Ok(1) +} + +fn main() { + let x = plus_one(5); + let _ = foo(); + println!("X = {}", x); +} diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.rs b/src/test/ui/coercion/coercion-missing-tail-expected-type.rs index 20a4407e9a1c0623eb19664f4f948bf7b2f8aea8..e14d79d8acae688f10c87f1934a71dff81ecbd54 100644 --- a/src/test/ui/coercion/coercion-missing-tail-expected-type.rs +++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.rs @@ -1,4 +1,5 @@ // #41425 -- error message "mismatched types" has wrong types +// run-rustfix fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types x + 1; @@ -10,5 +11,6 @@ fn foo() -> Result { //~ ERROR mismatched types fn main() { let x = plus_one(5); + let _ = foo(); println!("X = {}", x); } diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr index f1911dde981f5859c0163bcf9b161568f50a438c..da8db4331dffbd5a8ee4dcd4b6b9a7dc43ed4022 100644 --- a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr +++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/coercion-missing-tail-expected-type.rs:3:24 + --> $DIR/coercion-missing-tail-expected-type.rs:4:24 | LL | fn plus_one(x: i32) -> i32 { | -------- ^^^ expected `i32`, found `()` @@ -9,7 +9,7 @@ LL | x + 1; | - help: consider removing this semicolon error[E0308]: mismatched types - --> $DIR/coercion-missing-tail-expected-type.rs:7:13 + --> $DIR/coercion-missing-tail-expected-type.rs:8:13 | LL | fn foo() -> Result { | --- ^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found `()` diff --git a/src/test/ui/const-generics/unused_braces.fixed b/src/test/ui/const-generics/unused_braces.fixed new file mode 100644 index 0000000000000000000000000000000000000000..5c2b9267af583741f26e852027487b0e1371d99b --- /dev/null +++ b/src/test/ui/const-generics/unused_braces.fixed @@ -0,0 +1,15 @@ +// check-pass +// run-rustfix + +#![allow(incomplete_features)] +#![warn(unused_braces)] + +#![feature(const_generics)] + +struct A; + +fn main() { + let _: A<7>; // ok + let _: A< 7 >; //~ WARN unnecessary braces + let _: A<{ 3 + 5 }>; // ok +} diff --git a/src/test/ui/const-generics/unused_braces.rs b/src/test/ui/const-generics/unused_braces.rs index 2c3ce7c9eab4de82d6d21ee04d6ac47cab209940..c3e02b45ed5a26ecf4097df28fd9b925f86c53aa 100644 --- a/src/test/ui/const-generics/unused_braces.rs +++ b/src/test/ui/const-generics/unused_braces.rs @@ -1,8 +1,10 @@ // check-pass +// run-rustfix + +#![allow(incomplete_features)] #![warn(unused_braces)] #![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete struct A; diff --git a/src/test/ui/const-generics/unused_braces.stderr b/src/test/ui/const-generics/unused_braces.stderr index e14958ee566ee42f8e02ffaa625584a15178afae..618698a323445c9e62a70905d20c84b121ddf9f9 100644 --- a/src/test/ui/const-generics/unused_braces.stderr +++ b/src/test/ui/const-generics/unused_braces.stderr @@ -1,23 +1,14 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/unused_braces.rs:4:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - warning: unnecessary braces around const expression - --> $DIR/unused_braces.rs:11:14 + --> $DIR/unused_braces.rs:13:14 | LL | let _: A<{ 7 }>; | ^^^^^ help: remove these braces | note: the lint level is defined here - --> $DIR/unused_braces.rs:2:9 + --> $DIR/unused_braces.rs:5:9 | LL | #![warn(unused_braces)] | ^^^^^^^^^^^^^ -warning: 2 warnings emitted +warning: 1 warning emitted diff --git a/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs new file mode 100644 index 0000000000000000000000000000000000000000..5f2d5e80243fe62a76362679ffc08cb042142daf --- /dev/null +++ b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs @@ -0,0 +1,9 @@ +// check-pass + +pub struct Fixed64(i64); + +pub fn div(f: Fixed64) { + f.0 / 0; +} + +fn main() {} diff --git a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed new file mode 100644 index 0000000000000000000000000000000000000000..87debfeceaaf33a779a7d6bb4ab7d6c51d79b63d --- /dev/null +++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed @@ -0,0 +1,5 @@ +// run-rustfix + +fn main() { + let _x = !1; //~ ERROR cannot be used as a unary operator +} diff --git a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs index b59fe423025e68e07f22f6693073179436f0c391..015a8edcea355cbece7eaaaa0b985c360e30a6a4 100644 --- a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs +++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs @@ -1,3 +1,5 @@ +// run-rustfix + fn main() { - let x = ~1; //~ ERROR cannot be used as a unary operator + let _x = ~1; //~ ERROR cannot be used as a unary operator } diff --git a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr index 79bc7d2565be619f284419e92b3809b57cb7996a..84b81d561e9096855790a9cc39a4dc4d851a034a 100644 --- a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr +++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr @@ -1,8 +1,8 @@ error: `~` cannot be used as a unary operator - --> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:2:13 + --> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:4:14 | -LL | let x = ~1; - | ^ help: use `!` to perform bitwise not +LL | let _x = ~1; + | ^ help: use `!` to perform bitwise not error: aborting due to previous error diff --git a/src/test/ui/did_you_mean/issue-54109-without-witness.fixed b/src/test/ui/did_you_mean/issue-54109-without-witness.fixed new file mode 100644 index 0000000000000000000000000000000000000000..21471d75c821550449a18c25d83336fb6091e324 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-54109-without-witness.fixed @@ -0,0 +1,69 @@ +// run-rustfix + +// This test is to check if suggestions can be applied automatically. + +#![allow(dead_code, unused_parens)] + +fn main() {} + +fn test_and() { + let a = true; + let b = false; + + let _ = a && b; //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + + if a && b { //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + println!("both"); + } +} + +fn test_or() { + let a = true; + let b = false; + + let _ = a || b; //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + + if a || b { //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + println!("both"); + } +} + +fn test_and_par() { + let a = true; + let b = false; + if (a && b) { //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + println!("both"); + } +} + +fn test_or_par() { + let a = true; + let b = false; + if (a || b) { //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + println!("both"); + } +} + +fn test_while_and() { + let a = true; + let b = false; + while a && b { //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + println!("both"); + } +} + +fn test_while_or() { + let a = true; + let b = false; + while a || b { //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + println!("both"); + } +} diff --git a/src/test/ui/did_you_mean/issue-54109-without-witness.rs b/src/test/ui/did_you_mean/issue-54109-without-witness.rs new file mode 100644 index 0000000000000000000000000000000000000000..bb9a3a195962e58a91b3da4111e9d47ed8e68cd0 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-54109-without-witness.rs @@ -0,0 +1,69 @@ +// run-rustfix + +// This test is to check if suggestions can be applied automatically. + +#![allow(dead_code, unused_parens)] + +fn main() {} + +fn test_and() { + let a = true; + let b = false; + + let _ = a and b; //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + + if a and b { //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + println!("both"); + } +} + +fn test_or() { + let a = true; + let b = false; + + let _ = a or b; //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + + if a or b { //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + println!("both"); + } +} + +fn test_and_par() { + let a = true; + let b = false; + if (a and b) { //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + println!("both"); + } +} + +fn test_or_par() { + let a = true; + let b = false; + if (a or b) { //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + println!("both"); + } +} + +fn test_while_and() { + let a = true; + let b = false; + while a and b { //~ ERROR `and` is not a logical operator + //~| ERROR `and` is not a logical operator + println!("both"); + } +} + +fn test_while_or() { + let a = true; + let b = false; + while a or b { //~ ERROR `or` is not a logical operator + //~| ERROR `or` is not a logical operator + println!("both"); + } +} diff --git a/src/test/ui/did_you_mean/issue-54109-without-witness.stderr b/src/test/ui/did_you_mean/issue-54109-without-witness.stderr new file mode 100644 index 0000000000000000000000000000000000000000..fe48af592db9137873028764506f500dbaa25eeb --- /dev/null +++ b/src/test/ui/did_you_mean/issue-54109-without-witness.stderr @@ -0,0 +1,130 @@ +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:13:15 + | +LL | let _ = a and b; + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:13:15 + | +LL | let _ = a and b; + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:16:10 + | +LL | if a and b { + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:16:10 + | +LL | if a and b { + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:26:15 + | +LL | let _ = a or b; + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:26:15 + | +LL | let _ = a or b; + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:29:10 + | +LL | if a or b { + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:29:10 + | +LL | if a or b { + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:38:11 + | +LL | if (a and b) { + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:38:11 + | +LL | if (a and b) { + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:47:11 + | +LL | if (a or b) { + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:47:11 + | +LL | if (a or b) { + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:56:13 + | +LL | while a and b { + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `and` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:56:13 + | +LL | while a and b { + | ^^^ help: use `&&` to perform logical conjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:65:13 + | +LL | while a or b { + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: `or` is not a logical operator + --> $DIR/issue-54109-without-witness.rs:65:13 + | +LL | while a or b { + | ^^ help: use `||` to perform logical disjunction + | + = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators + +error: aborting due to 16 previous errors + diff --git a/src/test/ui/error-codes/E0642.fixed b/src/test/ui/error-codes/E0642.fixed new file mode 100644 index 0000000000000000000000000000000000000000..fc6255e0274431a35c29bbc6688b0282667ccc78 --- /dev/null +++ b/src/test/ui/error-codes/E0642.fixed @@ -0,0 +1,20 @@ +// run-rustfix + +#![allow(unused)] // for rustfix + +#[derive(Clone, Copy)] +struct S; + +trait T { + fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies + + fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies + + fn method(_: S) {} //~ ERROR patterns aren't allowed in methods without bodies + + fn f(&ident: &S) {} // ok + fn g(&&ident: &&S) {} // ok + fn h(mut ident: S) {} // ok +} + +fn main() {} diff --git a/src/test/ui/error-codes/E0642.rs b/src/test/ui/error-codes/E0642.rs index cfbd362c1da1995812f3fdd3c1926d3693d4ab01..5f85f3935e1a04d19319aec8ffb1294b839adbea 100644 --- a/src/test/ui/error-codes/E0642.rs +++ b/src/test/ui/error-codes/E0642.rs @@ -1,3 +1,7 @@ +// run-rustfix + +#![allow(unused)] // for rustfix + #[derive(Clone, Copy)] struct S; diff --git a/src/test/ui/error-codes/E0642.stderr b/src/test/ui/error-codes/E0642.stderr index 45486a5d632be8ff38fd4a3ccccdaeb930b656a0..83fcac042b1b41624b4c6816c8e99ffe757ecb57 100644 --- a/src/test/ui/error-codes/E0642.stderr +++ b/src/test/ui/error-codes/E0642.stderr @@ -1,5 +1,5 @@ error[E0642]: patterns aren't allowed in methods without bodies - --> $DIR/E0642.rs:5:12 + --> $DIR/E0642.rs:9:12 | LL | fn foo((x, y): (i32, i32)); | ^^^^^^ @@ -10,7 +10,7 @@ LL | fn foo(_: (i32, i32)); | ^ error[E0642]: patterns aren't allowed in methods without bodies - --> $DIR/E0642.rs:7:12 + --> $DIR/E0642.rs:11:12 | LL | fn bar((x, y): (i32, i32)) {} | ^^^^^^ @@ -21,7 +21,7 @@ LL | fn bar(_: (i32, i32)) {} | ^ error[E0642]: patterns aren't allowed in methods without bodies - --> $DIR/E0642.rs:9:15 + --> $DIR/E0642.rs:13:15 | LL | fn method(S { .. }: S) {} | ^^^^^^^^ diff --git a/src/test/ui/generic/generic-no-mangle.fixed b/src/test/ui/generic/generic-no-mangle.fixed new file mode 100644 index 0000000000000000000000000000000000000000..72f9af0124c1669f974aa5c5d15f9561b529a125 --- /dev/null +++ b/src/test/ui/generic/generic-no-mangle.fixed @@ -0,0 +1,17 @@ +// run-rustfix + +#![deny(no_mangle_generic_items)] + + +pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled + + +pub extern fn bar() {} //~ ERROR functions generic over types or consts must be mangled + +#[no_mangle] +pub fn baz(x: &i32) -> &i32 { x } + +#[no_mangle] +pub fn qux<'a>(x: &'a i32) -> &i32 { x } + +fn main() {} diff --git a/src/test/ui/generic/generic-no-mangle.rs b/src/test/ui/generic/generic-no-mangle.rs index 994aebc7f6e3e9082f14bb7ab93e1394e6f862a3..08d631e6eee1eab8d6d035fefcd41adfb6d37034 100644 --- a/src/test/ui/generic/generic-no-mangle.rs +++ b/src/test/ui/generic/generic-no-mangle.rs @@ -1,3 +1,5 @@ +// run-rustfix + #![deny(no_mangle_generic_items)] #[no_mangle] diff --git a/src/test/ui/generic/generic-no-mangle.stderr b/src/test/ui/generic/generic-no-mangle.stderr index ab2ad541e8640916f62bd651c080a4c6637a9e79..e8e6d9d502d4b42a057d1eda29f5260a7769c7c0 100644 --- a/src/test/ui/generic/generic-no-mangle.stderr +++ b/src/test/ui/generic/generic-no-mangle.stderr @@ -1,5 +1,5 @@ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:4:1 + --> $DIR/generic-no-mangle.rs:6:1 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -7,13 +7,13 @@ LL | pub fn foo() {} | ^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/generic-no-mangle.rs:1:9 + --> $DIR/generic-no-mangle.rs:3:9 | LL | #![deny(no_mangle_generic_items)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:7:1 + --> $DIR/generic-no-mangle.rs:9:1 | LL | #[no_mangle] | ------------ help: remove this attribute diff --git a/src/test/ui/impossible_range.fixed b/src/test/ui/impossible_range.fixed new file mode 100644 index 0000000000000000000000000000000000000000..3fd950e0dbfc87b3d6fdea2c16f2dc85a1a1ed90 --- /dev/null +++ b/src/test/ui/impossible_range.fixed @@ -0,0 +1,20 @@ +// run-rustfix +// Make sure that invalid ranges generate an error during parsing, not an ICE + +#![allow(path_statements)] + +pub fn main() { + ..; + 0..; + ..1; + 0..1; + ..; //~ERROR inclusive range with no end + //~^HELP use `..` instead +} + +fn _foo1() { + ..=1; + 0..=1; + 0..; //~ERROR inclusive range with no end + //~^HELP use `..` instead +} diff --git a/src/test/ui/impossible_range.rs b/src/test/ui/impossible_range.rs index 21e5c03eb1605b254f76db7f8ef7bccefc56e51e..0fe0e17be669aea8c6a48747fe69adf01bcc68c1 100644 --- a/src/test/ui/impossible_range.rs +++ b/src/test/ui/impossible_range.rs @@ -1,5 +1,8 @@ +// run-rustfix // Make sure that invalid ranges generate an error during parsing, not an ICE +#![allow(path_statements)] + pub fn main() { ..; 0..; diff --git a/src/test/ui/impossible_range.stderr b/src/test/ui/impossible_range.stderr index ea2ab0f299d1b9f3c759e9e3f6e43ab06f6c0508..53c56065c2a3a056fe4cf7e9dfdb27c9d9a7611d 100644 --- a/src/test/ui/impossible_range.stderr +++ b/src/test/ui/impossible_range.stderr @@ -1,5 +1,5 @@ error[E0586]: inclusive range with no end - --> $DIR/impossible_range.rs:8:5 + --> $DIR/impossible_range.rs:11:5 | LL | ..=; | ^^^ help: use `..` instead @@ -7,7 +7,7 @@ LL | ..=; = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error[E0586]: inclusive range with no end - --> $DIR/impossible_range.rs:15:6 + --> $DIR/impossible_range.rs:18:6 | LL | 0..=; | ^^^ help: use `..` instead diff --git a/src/test/ui/issue-73914.rs b/src/test/ui/issue-73914.rs new file mode 100644 index 0000000000000000000000000000000000000000..1e99faaded4efce4187a4262b4da2b1fe91506fe --- /dev/null +++ b/src/test/ui/issue-73914.rs @@ -0,0 +1,30 @@ +// build-pass +// compile-flags:-Copt-level=0 +// edition:2018 + +struct S(std::marker::PhantomData); + +impl std::ops::Deref for S { + type Target = T; + + fn deref(&self) -> &Self::Target { + todo!() + } +} +impl std::ops::DerefMut for S { + fn deref_mut(&mut self) -> &mut Self::Target { + todo!() + } +} + +async fn new() -> S { + todo!() +} + +async fn crash() { + *new().await = 1 + 1; +} + +fn main() { + let _ = crash(); +} diff --git a/src/test/ui/issues/issue-1962.fixed b/src/test/ui/issues/issue-1962.fixed new file mode 100644 index 0000000000000000000000000000000000000000..b810a90ef37f9057244371fa67c744436ae2089d --- /dev/null +++ b/src/test/ui/issues/issue-1962.fixed @@ -0,0 +1,10 @@ +// compile-flags: -D while-true +// run-rustfix + +fn main() { + let mut i = 0; + loop { //~ ERROR denote infinite loops with `loop + i += 1; + if i == 5 { break; } + } +} diff --git a/src/test/ui/issues/issue-1962.rs b/src/test/ui/issues/issue-1962.rs index e9ab3b5f99baa3666b41cd52d2ac02efe0262ad5..00d2bbd28506e10a7b79378626f10c20762e0848 100644 --- a/src/test/ui/issues/issue-1962.rs +++ b/src/test/ui/issues/issue-1962.rs @@ -1,8 +1,10 @@ // compile-flags: -D while-true +// run-rustfix + fn main() { - let mut i = 0; - while true { //~ ERROR denote infinite loops with `loop - i += 1; - if i == 5 { break; } - } + let mut i = 0; + while true { //~ ERROR denote infinite loops with `loop + i += 1; + if i == 5 { break; } + } } diff --git a/src/test/ui/issues/issue-1962.stderr b/src/test/ui/issues/issue-1962.stderr index afef59c52642f8499bbec8875501d7e960060b11..17142912696a75f67f9d8aacad6d66a716541e9c 100644 --- a/src/test/ui/issues/issue-1962.stderr +++ b/src/test/ui/issues/issue-1962.stderr @@ -1,8 +1,8 @@ error: denote infinite loops with `loop { ... }` - --> $DIR/issue-1962.rs:4:3 + --> $DIR/issue-1962.rs:6:5 | -LL | while true { - | ^^^^^^^^^^ help: use `loop` +LL | while true { + | ^^^^^^^^^^ help: use `loop` | = note: requested on the command line with `-D while-true` diff --git a/src/test/ui/issues/issue-40782.fixed b/src/test/ui/issues/issue-40782.fixed new file mode 100644 index 0000000000000000000000000000000000000000..d61c248c6ec62d9946c50942ebf2597b43ac2c9a --- /dev/null +++ b/src/test/ui/issues/issue-40782.fixed @@ -0,0 +1,6 @@ +// run-rustfix + +fn main() { + for _i in 0..2 { //~ ERROR missing `in` + } +} diff --git a/src/test/ui/issues/issue-40782.rs b/src/test/ui/issues/issue-40782.rs index 60db19ef9151fad665a85adabd11e98caef114f1..3688c69fbc613c2931466bf992cb716d307c114b 100644 --- a/src/test/ui/issues/issue-40782.rs +++ b/src/test/ui/issues/issue-40782.rs @@ -1,4 +1,6 @@ +// run-rustfix + fn main() { - for i 0..2 { //~ ERROR missing `in` + for _i 0..2 { //~ ERROR missing `in` } } diff --git a/src/test/ui/issues/issue-40782.stderr b/src/test/ui/issues/issue-40782.stderr index fdc57466f3cac6f8d696f6025f1496cc2a090092..9d7776f32b34572a722cac4266f1a69218d20721 100644 --- a/src/test/ui/issues/issue-40782.stderr +++ b/src/test/ui/issues/issue-40782.stderr @@ -1,8 +1,8 @@ error: missing `in` in `for` loop - --> $DIR/issue-40782.rs:2:10 + --> $DIR/issue-40782.rs:4:11 | -LL | for i 0..2 { - | ^ help: try adding `in` here +LL | for _i 0..2 { + | ^ help: try adding `in` here error: aborting due to previous error diff --git a/src/test/ui/issues/issue-46186.fixed b/src/test/ui/issues/issue-46186.fixed new file mode 100644 index 0000000000000000000000000000000000000000..2cb5a4996ee2526e675c642003e4de7e23794ac1 --- /dev/null +++ b/src/test/ui/issues/issue-46186.fixed @@ -0,0 +1,8 @@ +// run-rustfix + +pub struct Struct { + pub a: usize, +} +//~^ ERROR expected item, found `;` + +fn main() {} diff --git a/src/test/ui/issues/issue-46186.rs b/src/test/ui/issues/issue-46186.rs index 9dfd61fdf3f20516ee339a95e0d3a40d4a779bfd..84cad38c5ecb9695c255c5d9dfd87d17b485e486 100644 --- a/src/test/ui/issues/issue-46186.rs +++ b/src/test/ui/issues/issue-46186.rs @@ -1,5 +1,7 @@ -struct Struct { - a: usize, +// run-rustfix + +pub struct Struct { + pub a: usize, }; //~^ ERROR expected item, found `;` diff --git a/src/test/ui/issues/issue-46186.stderr b/src/test/ui/issues/issue-46186.stderr index eb0dbb8aa41b8faf464134c1f61acc1ff2d6a3d4..0766c8a33df14791836b0950e4e635dd83286019 100644 --- a/src/test/ui/issues/issue-46186.stderr +++ b/src/test/ui/issues/issue-46186.stderr @@ -1,5 +1,5 @@ error: expected item, found `;` - --> $DIR/issue-46186.rs:3:2 + --> $DIR/issue-46186.rs:5:2 | LL | }; | ^ help: remove this semicolon diff --git a/src/test/ui/issues/issue-50571.fixed b/src/test/ui/issues/issue-50571.fixed new file mode 100644 index 0000000000000000000000000000000000000000..2f8c925b85328c6e3a79da3802761a1943b33c0b --- /dev/null +++ b/src/test/ui/issues/issue-50571.fixed @@ -0,0 +1,8 @@ +// run-rustfix + +trait Foo { + fn foo(_: [i32; 2]) {} + //~^ ERROR: patterns aren't allowed in methods without bodies +} + +fn main() {} diff --git a/src/test/ui/issues/issue-50571.rs b/src/test/ui/issues/issue-50571.rs index 728c113bdc32347849e68dbf7116862419136e60..56f422e7d58388e3fcbceb870b42d33f1f84aaf4 100644 --- a/src/test/ui/issues/issue-50571.rs +++ b/src/test/ui/issues/issue-50571.rs @@ -1,3 +1,5 @@ +// run-rustfix + trait Foo { fn foo([a, b]: [i32; 2]) {} //~^ ERROR: patterns aren't allowed in methods without bodies diff --git a/src/test/ui/issues/issue-50571.stderr b/src/test/ui/issues/issue-50571.stderr index df9d10b39507bbcf05bb76c19eeb97c615ecac17..ed01362758573c4d237912cfe9fff7d9b239b5d1 100644 --- a/src/test/ui/issues/issue-50571.stderr +++ b/src/test/ui/issues/issue-50571.stderr @@ -1,5 +1,5 @@ error[E0642]: patterns aren't allowed in methods without bodies - --> $DIR/issue-50571.rs:2:12 + --> $DIR/issue-50571.rs:4:12 | LL | fn foo([a, b]: [i32; 2]) {} | ^^^^^^ diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.fixed b/src/test/ui/lint/issue-54538-unused-parens-lint.fixed new file mode 100644 index 0000000000000000000000000000000000000000..c70c39b5f6dc786911c90a86cec46d2b7e4e7fd8 --- /dev/null +++ b/src/test/ui/lint/issue-54538-unused-parens-lint.fixed @@ -0,0 +1,107 @@ +// run-rustfix + +#![feature(box_patterns, stmt_expr_attributes)] +#![feature(or_patterns)] + +#![allow( + dead_code, + ellipsis_inclusive_range_patterns, + irrefutable_let_patterns, + unreachable_patterns, + unused_mut, + unused_variables +)] +#![deny(unused_parens)] + +fn lint_on_top_level() { + let a = 0; //~ ERROR unnecessary parentheses around pattern + for a in 0..1 {} //~ ERROR unnecessary parentheses around pattern + if let a = 0 {} //~ ERROR unnecessary parentheses around pattern + while let a = 0 {} //~ ERROR unnecessary parentheses around pattern + fn foo(a: u8) {} //~ ERROR unnecessary parentheses around pattern + let _ = |a: u8| 0; //~ ERROR unnecessary parentheses around pattern +} + +fn _no_lint_attr() { + let _x = #[allow(dead_code)] (1 + 2); +} + +// Don't lint in these cases (#64106). +fn or_patterns_no_lint() { + match Box::new(0) { + box (0 | 1) => {} // Should not lint as `box 0 | 1` binds as `(box 0) | 1`. + _ => {} + } + + match 0 { + x @ (0 | 1) => {} // Should not lint as `x @ 0 | 1` binds as `(x @ 0) | 1`. + _ => {} + } + + if let &(0 | 1) = &0 {} // Should also not lint. + if let &mut (0 | 1) = &mut 0 {} // Same. + + fn foo((Ok(a) | Err(a)): Result) {} // Doesn't parse if we remove parens for now. + + let _ = |(Ok(a) | Err(a)): Result| 1; // `|Ok(a) | Err(a)| 1` parses as bit-or. +} + +fn or_patterns_will_lint() { + if let 0 | 1 = 0 {} //~ ERROR unnecessary parentheses around pattern + if let (0 | 1,) = (0,) {} //~ ERROR unnecessary parentheses around pattern + if let [0 | 1] = [0] {} //~ ERROR unnecessary parentheses around pattern + if let 0 | 1 | 2 = 0 {} //~ ERROR unnecessary parentheses around pattern + struct TS(u8); + if let TS(0 | 1) = TS(0) {} //~ ERROR unnecessary parentheses around pattern + struct NS { f: u8 } + if let NS { f: 0 | 1 } = (NS { f: 0 }) {} //~ ERROR unnecessary parentheses around pattern +} + +// Don't lint on `&(mut x)` because `&mut x` means something else (#55342). +fn deref_mut_binding_no_lint() { + let &(mut x) = &0; +} + +fn main() { + match 1 { + _ => {} //~ ERROR unnecessary parentheses around pattern + y => {} //~ ERROR unnecessary parentheses around pattern + ref r => {} //~ ERROR unnecessary parentheses around pattern + e @ 1...2 => {} //~ ERROR unnecessary parentheses around pattern + (1...2) => {} // Non ambiguous range pattern should not warn + e @ (3...4) => {} // Non ambiguous range pattern should not warn + } + + match &1 { + e @ &(1...2) => {} //~ ERROR unnecessary parentheses around pattern + &_ => {} //~ ERROR unnecessary parentheses around pattern + e @ &(1...2) => {} // Ambiguous range pattern should not warn + &(1...2) => {} // Ambiguous range pattern should not warn + } + + match &1 { + e @ &(1...2) | e @ &(3...4) => {} // Complex ambiguous pattern should not warn + &_ => {} + } + + match 1 { + _ => {} //~ ERROR unnecessary parentheses around pattern + y => {} //~ ERROR unnecessary parentheses around pattern + ref r => {} //~ ERROR unnecessary parentheses around pattern + e @ 1..=2 => {} //~ ERROR unnecessary parentheses around pattern + (1..=2) => {} // Non ambiguous range pattern should not warn + e @ (3..=4) => {} // Non ambiguous range pattern should not warn + } + + match &1 { + e @ &(1..=2) => {} //~ ERROR unnecessary parentheses around pattern + &_ => {} //~ ERROR unnecessary parentheses around pattern + e @ &(1..=2) => {} // Ambiguous range pattern should not warn + &(1..=2) => {} // Ambiguous range pattern should not warn + } + + match &1 { + e @ &(1..=2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn + &_ => {} + } +} diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.rs b/src/test/ui/lint/issue-54538-unused-parens-lint.rs index f3d2d1bb58d8f67984d3096f1c6b8bc7b4385536..9dd3b63c0fed785c82d1f3eb4719390af66fd228 100644 --- a/src/test/ui/lint/issue-54538-unused-parens-lint.rs +++ b/src/test/ui/lint/issue-54538-unused-parens-lint.rs @@ -1,10 +1,16 @@ -#![feature(box_patterns, stmt_expr_attributes)] +// run-rustfix +#![feature(box_patterns, stmt_expr_attributes)] #![feature(or_patterns)] -#![allow(ellipsis_inclusive_range_patterns)] -#![allow(unreachable_patterns)] -#![allow(unused_variables)] +#![allow( + dead_code, + ellipsis_inclusive_range_patterns, + irrefutable_let_patterns, + unreachable_patterns, + unused_mut, + unused_variables +)] #![deny(unused_parens)] fn lint_on_top_level() { diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.stderr b/src/test/ui/lint/issue-54538-unused-parens-lint.stderr index b31ad95b191c986c1e1711764113b4a97a062587..ee466857757a37b9c8922a874d5a16d39cd546ea 100644 --- a/src/test/ui/lint/issue-54538-unused-parens-lint.stderr +++ b/src/test/ui/lint/issue-54538-unused-parens-lint.stderr @@ -1,149 +1,149 @@ error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:11:9 + --> $DIR/issue-54538-unused-parens-lint.rs:17:9 | LL | let (a) = 0; | ^^^ help: remove these parentheses | note: the lint level is defined here - --> $DIR/issue-54538-unused-parens-lint.rs:8:9 + --> $DIR/issue-54538-unused-parens-lint.rs:14:9 | LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:12:9 + --> $DIR/issue-54538-unused-parens-lint.rs:18:9 | LL | for (a) in 0..1 {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:13:12 + --> $DIR/issue-54538-unused-parens-lint.rs:19:12 | LL | if let (a) = 0 {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:14:15 + --> $DIR/issue-54538-unused-parens-lint.rs:20:15 | LL | while let (a) = 0 {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:15:12 + --> $DIR/issue-54538-unused-parens-lint.rs:21:12 | LL | fn foo((a): u8) {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:16:14 + --> $DIR/issue-54538-unused-parens-lint.rs:22:14 | LL | let _ = |(a): u8| 0; | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:44:12 + --> $DIR/issue-54538-unused-parens-lint.rs:50:12 | LL | if let (0 | 1) = 0 {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:45:13 + --> $DIR/issue-54538-unused-parens-lint.rs:51:13 | LL | if let ((0 | 1),) = (0,) {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:46:13 + --> $DIR/issue-54538-unused-parens-lint.rs:52:13 | LL | if let [(0 | 1)] = [0] {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:47:16 + --> $DIR/issue-54538-unused-parens-lint.rs:53:16 | LL | if let 0 | (1 | 2) = 0 {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:49:15 + --> $DIR/issue-54538-unused-parens-lint.rs:55:15 | LL | if let TS((0 | 1)) = TS(0) {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:51:20 + --> $DIR/issue-54538-unused-parens-lint.rs:57:20 | LL | if let NS { f: (0 | 1) } = (NS { f: 0 }) {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:61:9 + --> $DIR/issue-54538-unused-parens-lint.rs:67:9 | LL | (_) => {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:62:9 + --> $DIR/issue-54538-unused-parens-lint.rs:68:9 | LL | (y) => {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:63:9 + --> $DIR/issue-54538-unused-parens-lint.rs:69:9 | LL | (ref r) => {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:64:9 + --> $DIR/issue-54538-unused-parens-lint.rs:70:9 | LL | (e @ 1...2) => {} | ^^^^^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:70:9 + --> $DIR/issue-54538-unused-parens-lint.rs:76:9 | LL | (e @ &(1...2)) => {} | ^^^^^^^^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:71:10 + --> $DIR/issue-54538-unused-parens-lint.rs:77:10 | LL | &(_) => {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:82:9 + --> $DIR/issue-54538-unused-parens-lint.rs:88:9 | LL | (_) => {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:83:9 + --> $DIR/issue-54538-unused-parens-lint.rs:89:9 | LL | (y) => {} | ^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:84:9 + --> $DIR/issue-54538-unused-parens-lint.rs:90:9 | LL | (ref r) => {} | ^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:85:9 + --> $DIR/issue-54538-unused-parens-lint.rs:91:9 | LL | (e @ 1..=2) => {} | ^^^^^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:91:9 + --> $DIR/issue-54538-unused-parens-lint.rs:97:9 | LL | (e @ &(1..=2)) => {} | ^^^^^^^^^^^^^^ help: remove these parentheses error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:92:10 + --> $DIR/issue-54538-unused-parens-lint.rs:98:10 | LL | &(_) => {} | ^^^ help: remove these parentheses diff --git a/src/test/ui/lint/lint-unnecessary-parens.fixed b/src/test/ui/lint/lint-unnecessary-parens.fixed new file mode 100644 index 0000000000000000000000000000000000000000..c9dec395580f194cbea64eed3800f60f67b68d90 --- /dev/null +++ b/src/test/ui/lint/lint-unnecessary-parens.fixed @@ -0,0 +1,79 @@ +// run-rustfix + +#![deny(unused_parens)] +#![allow(while_true)] // for rustfix + +#[derive(Eq, PartialEq)] +struct X { y: bool } +impl X { + fn foo(&self, conjunct: bool) -> bool { self.y && conjunct } +} + +fn foo() -> isize { + return 1; //~ ERROR unnecessary parentheses around `return` value +} +fn bar(y: bool) -> X { + return X { y }; //~ ERROR unnecessary parentheses around `return` value +} + +pub fn unused_parens_around_return_type() -> u32 { //~ ERROR unnecessary parentheses around type + panic!() +} + +pub fn unused_parens_around_block_return() -> u32 { + let _foo = { + 5 //~ ERROR unnecessary parentheses around block return value + }; + 5 //~ ERROR unnecessary parentheses around block return value +} + +pub trait Trait { + fn test(&self); +} + +pub fn passes_unused_parens_lint() -> &'static (dyn Trait) { + panic!() +} + +macro_rules! baz { + ($($foo:expr),+) => { + ($($foo),*) + } +} + +pub const CONST_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value +pub static STATIC_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value + +fn main() { + foo(); + bar(true); //~ ERROR unnecessary parentheses around function argument + + if true {} //~ ERROR unnecessary parentheses around `if` condition + while true {} //~ ERROR unnecessary parentheses around `while` condition + match true { //~ ERROR unnecessary parentheses around `match` scrutinee expression + _ => {} + } + if let 1 = 1 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression + while let 1 = 2 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression + let v = X { y: false }; + // struct lits needs parens, so these shouldn't warn. + if (v == X { y: true }) {} + if (X { y: true } == v) {} + if (X { y: false }.y) {} + + while (X { y: false }.foo(true)) {} + while (true | X { y: false }.y) {} + + match (X { y: false }) { + _ => {} + } + + X { y: false }.foo(true); //~ ERROR unnecessary parentheses around method argument + + let mut _a = 0; //~ ERROR unnecessary parentheses around assigned value + _a = 0; //~ ERROR unnecessary parentheses around assigned value + _a += 1; //~ ERROR unnecessary parentheses around assigned value + + let _a = baz!(3, 4); + let _b = baz!(3); +} diff --git a/src/test/ui/lint/lint-unnecessary-parens.rs b/src/test/ui/lint/lint-unnecessary-parens.rs index 623cd04d9bce35ddb1a65209554ef1c3ee0648a8..884bb4d2e99b67cc3029c4d661de5a9eb7436203 100644 --- a/src/test/ui/lint/lint-unnecessary-parens.rs +++ b/src/test/ui/lint/lint-unnecessary-parens.rs @@ -1,4 +1,7 @@ +// run-rustfix + #![deny(unused_parens)] +#![allow(while_true)] // for rustfix #[derive(Eq, PartialEq)] struct X { y: bool } @@ -13,22 +16,22 @@ fn bar(y: bool) -> X { return (X { y }); //~ ERROR unnecessary parentheses around `return` value } -fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parentheses around type +pub fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parentheses around type panic!() } -fn unused_parens_around_block_return() -> u32 { - let foo = { +pub fn unused_parens_around_block_return() -> u32 { + let _foo = { (5) //~ ERROR unnecessary parentheses around block return value }; (5) //~ ERROR unnecessary parentheses around block return value } -trait Trait { +pub trait Trait { fn test(&self); } -fn passes_unused_parens_lint() -> &'static (dyn Trait) { +pub fn passes_unused_parens_lint() -> &'static (dyn Trait) { panic!() } @@ -38,8 +41,8 @@ fn passes_unused_parens_lint() -> &'static (dyn Trait) { } } -const CONST_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value -static STATIC_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value +pub const CONST_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value +pub static STATIC_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value fn main() { foo(); @@ -47,7 +50,6 @@ fn main() { if (true) {} //~ ERROR unnecessary parentheses around `if` condition while (true) {} //~ ERROR unnecessary parentheses around `while` condition - //~^ WARN denote infinite loops with match (true) { //~ ERROR unnecessary parentheses around `match` scrutinee expression _ => {} } diff --git a/src/test/ui/lint/lint-unnecessary-parens.stderr b/src/test/ui/lint/lint-unnecessary-parens.stderr index f5a2564a5ff65b46d5061b1e59faf902a676074e..1abf47c8af5214e1fde9a60e29a7a9036cdadd18 100644 --- a/src/test/ui/lint/lint-unnecessary-parens.stderr +++ b/src/test/ui/lint/lint-unnecessary-parens.stderr @@ -1,118 +1,110 @@ error: unnecessary parentheses around `return` value - --> $DIR/lint-unnecessary-parens.rs:10:12 + --> $DIR/lint-unnecessary-parens.rs:13:12 | LL | return (1); | ^^^ help: remove these parentheses | note: the lint level is defined here - --> $DIR/lint-unnecessary-parens.rs:1:9 + --> $DIR/lint-unnecessary-parens.rs:3:9 | LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ error: unnecessary parentheses around `return` value - --> $DIR/lint-unnecessary-parens.rs:13:12 + --> $DIR/lint-unnecessary-parens.rs:16:12 | LL | return (X { y }); | ^^^^^^^^^ help: remove these parentheses error: unnecessary parentheses around type - --> $DIR/lint-unnecessary-parens.rs:16:42 + --> $DIR/lint-unnecessary-parens.rs:19:46 | -LL | fn unused_parens_around_return_type() -> (u32) { - | ^^^^^ help: remove these parentheses +LL | pub fn unused_parens_around_return_type() -> (u32) { + | ^^^^^ help: remove these parentheses error: unnecessary parentheses around block return value - --> $DIR/lint-unnecessary-parens.rs:22:9 + --> $DIR/lint-unnecessary-parens.rs:25:9 | LL | (5) | ^^^ help: remove these parentheses error: unnecessary parentheses around block return value - --> $DIR/lint-unnecessary-parens.rs:24:5 + --> $DIR/lint-unnecessary-parens.rs:27:5 | LL | (5) | ^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:41:27 + --> $DIR/lint-unnecessary-parens.rs:44:31 | -LL | const CONST_ITEM: usize = (10); - | ^^^^ help: remove these parentheses +LL | pub const CONST_ITEM: usize = (10); + | ^^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:42:29 + --> $DIR/lint-unnecessary-parens.rs:45:33 | -LL | static STATIC_ITEM: usize = (10); - | ^^^^ help: remove these parentheses +LL | pub static STATIC_ITEM: usize = (10); + | ^^^^ help: remove these parentheses error: unnecessary parentheses around function argument - --> $DIR/lint-unnecessary-parens.rs:46:9 + --> $DIR/lint-unnecessary-parens.rs:49:9 | LL | bar((true)); | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `if` condition - --> $DIR/lint-unnecessary-parens.rs:48:8 + --> $DIR/lint-unnecessary-parens.rs:51:8 | LL | if (true) {} | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `while` condition - --> $DIR/lint-unnecessary-parens.rs:49:11 + --> $DIR/lint-unnecessary-parens.rs:52:11 | LL | while (true) {} | ^^^^^^ help: remove these parentheses -warning: denote infinite loops with `loop { ... }` - --> $DIR/lint-unnecessary-parens.rs:49:5 - | -LL | while (true) {} - | ^^^^^^^^^^^^ help: use `loop` - | - = note: `#[warn(while_true)]` on by default - error: unnecessary parentheses around `match` scrutinee expression - --> $DIR/lint-unnecessary-parens.rs:51:11 + --> $DIR/lint-unnecessary-parens.rs:53:11 | LL | match (true) { | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `let` scrutinee expression - --> $DIR/lint-unnecessary-parens.rs:54:16 + --> $DIR/lint-unnecessary-parens.rs:56:16 | LL | if let 1 = (1) {} | ^^^ help: remove these parentheses error: unnecessary parentheses around `let` scrutinee expression - --> $DIR/lint-unnecessary-parens.rs:55:19 + --> $DIR/lint-unnecessary-parens.rs:57:19 | LL | while let 1 = (2) {} | ^^^ help: remove these parentheses error: unnecessary parentheses around method argument - --> $DIR/lint-unnecessary-parens.rs:69:24 + --> $DIR/lint-unnecessary-parens.rs:71:24 | LL | X { y: false }.foo((true)); | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:71:18 + --> $DIR/lint-unnecessary-parens.rs:73:18 | LL | let mut _a = (0); | ^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:72:10 + --> $DIR/lint-unnecessary-parens.rs:74:10 | LL | _a = (0); | ^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:73:11 + --> $DIR/lint-unnecessary-parens.rs:75:11 | LL | _a += (1); | ^^^ help: remove these parentheses -error: aborting due to 17 previous errors; 1 warning emitted +error: aborting due to 17 previous errors diff --git a/src/test/ui/lint/lint-unused-mut-self.fixed b/src/test/ui/lint/lint-unused-mut-self.fixed new file mode 100644 index 0000000000000000000000000000000000000000..92ce103586c2584bbddc7a40312185888a698178 --- /dev/null +++ b/src/test/ui/lint/lint-unused-mut-self.fixed @@ -0,0 +1,14 @@ +// run-rustfix + +#![allow(unused_assignments)] +#![allow(unused_variables)] +#![allow(dead_code)] +#![deny(unused_mut)] + +struct Foo; +impl Foo { + fn foo(self) {} //~ ERROR: variable does not need to be mutable + fn bar(self: Box) {} //~ ERROR: variable does not need to be mutable +} + +fn main() {} diff --git a/src/test/ui/lint/lint-unused-mut-self.rs b/src/test/ui/lint/lint-unused-mut-self.rs index 3c709d07939803aa80036ef9c442102cdbdb84af..70736ce216e5ecce15108a44c539f6f024e385d2 100644 --- a/src/test/ui/lint/lint-unused-mut-self.rs +++ b/src/test/ui/lint/lint-unused-mut-self.rs @@ -1,3 +1,5 @@ +// run-rustfix + #![allow(unused_assignments)] #![allow(unused_variables)] #![allow(dead_code)] diff --git a/src/test/ui/lint/lint-unused-mut-self.stderr b/src/test/ui/lint/lint-unused-mut-self.stderr index 16ad4758b92b8819385c263e20c88dbb9b2a8824..01a524bd323c44ef02f9f210e53bd73044c4a64a 100644 --- a/src/test/ui/lint/lint-unused-mut-self.stderr +++ b/src/test/ui/lint/lint-unused-mut-self.stderr @@ -1,5 +1,5 @@ error: variable does not need to be mutable - --> $DIR/lint-unused-mut-self.rs:8:12 + --> $DIR/lint-unused-mut-self.rs:10:12 | LL | fn foo(mut self) {} | ----^^^^ @@ -7,13 +7,13 @@ LL | fn foo(mut self) {} | help: remove this `mut` | note: the lint level is defined here - --> $DIR/lint-unused-mut-self.rs:4:9 + --> $DIR/lint-unused-mut-self.rs:6:9 | LL | #![deny(unused_mut)] | ^^^^^^^^^^ error: variable does not need to be mutable - --> $DIR/lint-unused-mut-self.rs:9:12 + --> $DIR/lint-unused-mut-self.rs:11:12 | LL | fn bar(mut self: Box) {} | ----^^^^ diff --git a/src/test/ui/lint/lint-unused-mut-variables.rs b/src/test/ui/lint/lint-unused-mut-variables.rs index 5c7ed9d52194010d90e44b2ea971a0649e94554b..67ec7facf1780bef3f1b47d29650d92fb7f47577 100644 --- a/src/test/ui/lint/lint-unused-mut-variables.rs +++ b/src/test/ui/lint/lint-unused-mut-variables.rs @@ -92,13 +92,16 @@ fn main() { mut x => {} //~ WARN: variable does not need to be mutable } + match (30, 2) { - (mut x, 1) | //~ WARN: variable does not need to be mutable + // FIXME: Here's a false positive, + // shouldn't be removed `mut` not to be bound with a different way. + (mut x, 1) | //~ WARN: variable does not need to be mutable - (mut x, 2) | - (mut x, 3) => { - } - _ => {} + (mut x, 2) | + (mut x, 3) => { + } + _ => {} } let x = |mut y: isize| 10; //~ WARN: variable does not need to be mutable diff --git a/src/test/ui/lint/lint-unused-mut-variables.stderr b/src/test/ui/lint/lint-unused-mut-variables.stderr index 42365f24274b9a65cb24283eb006554aaa2ee180..805ed2b40bb7bc422a6885d0fae606bb4a969027 100644 --- a/src/test/ui/lint/lint-unused-mut-variables.stderr +++ b/src/test/ui/lint/lint-unused-mut-variables.stderr @@ -69,7 +69,7 @@ LL | mut a: i32, | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:104:14 + --> $DIR/lint-unused-mut-variables.rs:107:14 | LL | let x = |mut y: isize| 10; | ----^ @@ -141,15 +141,15 @@ LL | mut x => {} | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:96:8 + --> $DIR/lint-unused-mut-variables.rs:99:10 | -LL | (mut x, 1) | - | ----^ - | | - | help: remove this `mut` +LL | (mut x, 1) | + | ----^ + | | + | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:109:9 + --> $DIR/lint-unused-mut-variables.rs:112:9 | LL | let mut a = &mut 5; | ----^ @@ -157,7 +157,7 @@ LL | let mut a = &mut 5; | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:114:9 + --> $DIR/lint-unused-mut-variables.rs:117:9 | LL | let mut b = (&mut a,); | ----^ @@ -165,7 +165,7 @@ LL | let mut b = (&mut a,); | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:117:9 + --> $DIR/lint-unused-mut-variables.rs:120:9 | LL | let mut x = &mut 1; | ----^ @@ -173,7 +173,7 @@ LL | let mut x = &mut 1; | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:129:9 + --> $DIR/lint-unused-mut-variables.rs:132:9 | LL | let mut v : &mut Vec<()> = &mut vec![]; | ----^ @@ -181,7 +181,7 @@ LL | let mut v : &mut Vec<()> = &mut vec![]; | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:184:9 + --> $DIR/lint-unused-mut-variables.rs:187:9 | LL | let mut raw_address_of_const = 1; | ----^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ LL | let mut raw_address_of_const = 1; | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:106:13 + --> $DIR/lint-unused-mut-variables.rs:109:13 | LL | fn what(mut foo: isize) {} | ----^^^ @@ -197,7 +197,7 @@ LL | fn what(mut foo: isize) {} | help: remove this `mut` warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:124:20 + --> $DIR/lint-unused-mut-variables.rs:127:20 | LL | fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] { | ----^^^ @@ -205,7 +205,7 @@ LL | fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] { | help: remove this `mut` error: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:202:9 + --> $DIR/lint-unused-mut-variables.rs:205:9 | LL | let mut b = vec![2]; | ----^ @@ -213,7 +213,7 @@ LL | let mut b = vec![2]; | help: remove this `mut` | note: the lint level is defined here - --> $DIR/lint-unused-mut-variables.rs:198:8 + --> $DIR/lint-unused-mut-variables.rs:201:8 | LL | #[deny(unused_mut)] | ^^^^^^^^^^ diff --git a/src/test/ui/lint/suggestions.fixed b/src/test/ui/lint/suggestions.fixed new file mode 100644 index 0000000000000000000000000000000000000000..35851690b738135126aa773d6b3437f1d056f3b4 --- /dev/null +++ b/src/test/ui/lint/suggestions.fixed @@ -0,0 +1,66 @@ +// ignore-tidy-tab +// run-rustfix + +#![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896 + +#[no_mangle] pub static DISCOVERY: usize = 1; +//~^ ERROR const items should never be `#[no_mangle]` +//~| HELP try a static value + + +//~^ HELP remove this attribute +pub fn defiant(_t: T) {} +//~^ WARN functions generic over types or consts must be mangled + +#[no_mangle] +fn rio_grande() {} + +mod badlands { + // The private-no-mangle lints shouldn't suggest inserting `pub` when the + // item is already `pub` (but triggered the lint because, e.g., it's in a + // private module). (Issue #47383) + #[no_mangle] pub static DAUNTLESS: bool = true; + //~^ ERROR const items should never be `#[no_mangle]` + //~| HELP try a static value + #[allow(dead_code)] // for rustfix + pub fn val_jean() {} + //~^ WARN functions generic over types or consts must be mangled + //~| HELP remove this attribute + + // ... but we can suggest just-`pub` instead of restricted + #[no_mangle] pub static VETAR: bool = true; + //~^ ERROR const items should never be `#[no_mangle]` + //~| HELP try a static value + #[allow(dead_code)] // for rustfix + pub(crate) fn crossfield() {} + //~^ WARN functions generic over types or consts must be mangled + //~| HELP remove this attribute +} + +struct Equinox { + warp_factor: f32, +} + +fn main() { + loop { + //~^ WARN denote infinite loops + //~| HELP use `loop` + let registry_no = format!("NX-{}", 74205); + //~^ WARN does not need to be mutable + //~| HELP remove this `mut` + //~| WARN unnecessary parentheses + //~| HELP remove these parentheses + // the line after `mut` has a `\t` at the beginning, this is on purpose + let b = 1; + //~^^ WARN does not need to be mutable + //~| HELP remove this `mut` + let d = Equinox { warp_factor: 9.975 }; + match d { + #[allow(unused_variables)] // for rustfix + Equinox { warp_factor } => {} + //~^ WARN this pattern is redundant + //~| HELP use shorthand field pattern + } + println!("{} {}", registry_no, b); + } +} diff --git a/src/test/ui/lint/suggestions.rs b/src/test/ui/lint/suggestions.rs index 518b5f211e5da26c9403a135de06806986d6062a..be6f0d6b30fed2691cf7732ea1dcb30cf5e39a42 100644 --- a/src/test/ui/lint/suggestions.rs +++ b/src/test/ui/lint/suggestions.rs @@ -1,4 +1,5 @@ // ignore-tidy-tab +// run-rustfix #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896 @@ -21,6 +22,7 @@ mod badlands { #[no_mangle] pub const DAUNTLESS: bool = true; //~^ ERROR const items should never be `#[no_mangle]` //~| HELP try a static value + #[allow(dead_code)] // for rustfix #[no_mangle] pub fn val_jean() {} //~^ WARN functions generic over types or consts must be mangled //~| HELP remove this attribute @@ -29,6 +31,7 @@ mod badlands { #[no_mangle] pub(crate) const VETAR: bool = true; //~^ ERROR const items should never be `#[no_mangle]` //~| HELP try a static value + #[allow(dead_code)] // for rustfix #[no_mangle] pub(crate) fn crossfield() {} //~^ WARN functions generic over types or consts must be mangled //~| HELP remove this attribute @@ -54,6 +57,7 @@ fn main() { //~| HELP remove this `mut` let d = Equinox { warp_factor: 9.975 }; match d { + #[allow(unused_variables)] // for rustfix Equinox { warp_factor: warp_factor } => {} //~^ WARN this pattern is redundant //~| HELP use shorthand field pattern diff --git a/src/test/ui/lint/suggestions.stderr b/src/test/ui/lint/suggestions.stderr index 0730c22417c05c7baf151864ba7e74c889c0e16e..cad2514625588e36c89a9de4c127459f0aebf332 100644 --- a/src/test/ui/lint/suggestions.stderr +++ b/src/test/ui/lint/suggestions.stderr @@ -1,5 +1,5 @@ warning: denote infinite loops with `loop { ... }` - --> $DIR/suggestions.rs:42:5 + --> $DIR/suggestions.rs:45:5 | LL | while true { | ^^^^^^^^^^ help: use `loop` @@ -7,19 +7,19 @@ LL | while true { = note: `#[warn(while_true)]` on by default warning: unnecessary parentheses around assigned value - --> $DIR/suggestions.rs:45:31 + --> $DIR/suggestions.rs:48:31 | LL | let mut registry_no = (format!("NX-{}", 74205)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses | note: the lint level is defined here - --> $DIR/suggestions.rs:3:21 + --> $DIR/suggestions.rs:4:21 | LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896 | ^^^^^^^^^^^^^ warning: variable does not need to be mutable - --> $DIR/suggestions.rs:45:13 + --> $DIR/suggestions.rs:48:13 | LL | let mut registry_no = (format!("NX-{}", 74205)); | ----^^^^^^^^^^^ @@ -27,13 +27,13 @@ LL | let mut registry_no = (format!("NX-{}", 74205)); | help: remove this `mut` | note: the lint level is defined here - --> $DIR/suggestions.rs:3:9 + --> $DIR/suggestions.rs:4:9 | LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896 | ^^^^^^^^^^ warning: variable does not need to be mutable - --> $DIR/suggestions.rs:51:13 + --> $DIR/suggestions.rs:54:13 | LL | let mut | _____________^ @@ -45,7 +45,7 @@ LL | || b = 1; | help: remove this `mut` error: const items should never be `#[no_mangle]` - --> $DIR/suggestions.rs:5:14 + --> $DIR/suggestions.rs:6:14 | LL | #[no_mangle] const DISCOVERY: usize = 1; | -----^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | #[no_mangle] const DISCOVERY: usize = 1; = note: `#[deny(no_mangle_const_items)]` on by default warning: functions generic over types or consts must be mangled - --> $DIR/suggestions.rs:11:1 + --> $DIR/suggestions.rs:12:1 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -66,7 +66,7 @@ LL | pub fn defiant(_t: T) {} = note: `#[warn(no_mangle_generic_items)]` on by default warning: the `warp_factor:` in this pattern is redundant - --> $DIR/suggestions.rs:57:23 + --> $DIR/suggestions.rs:61:23 | LL | Equinox { warp_factor: warp_factor } => {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use shorthand field pattern: `warp_factor` @@ -74,7 +74,7 @@ LL | Equinox { warp_factor: warp_factor } => {} = note: `#[warn(non_shorthand_field_patterns)]` on by default error: const items should never be `#[no_mangle]` - --> $DIR/suggestions.rs:21:18 + --> $DIR/suggestions.rs:22:18 | LL | #[no_mangle] pub const DAUNTLESS: bool = true; | ---------^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | #[no_mangle] pub const DAUNTLESS: bool = true; | help: try a static value: `pub static` warning: functions generic over types or consts must be mangled - --> $DIR/suggestions.rs:24:18 + --> $DIR/suggestions.rs:26:18 | LL | #[no_mangle] pub fn val_jean() {} | ------------ ^^^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | #[no_mangle] pub fn val_jean() {} | help: remove this attribute error: const items should never be `#[no_mangle]` - --> $DIR/suggestions.rs:29:18 + --> $DIR/suggestions.rs:31:18 | LL | #[no_mangle] pub(crate) const VETAR: bool = true; | ----------------^^^^^^^^^^^^^^^^^^^^ @@ -98,7 +98,7 @@ LL | #[no_mangle] pub(crate) const VETAR: bool = true; | help: try a static value: `pub static` warning: functions generic over types or consts must be mangled - --> $DIR/suggestions.rs:32:18 + --> $DIR/suggestions.rs:35:18 | LL | #[no_mangle] pub(crate) fn crossfield() {} | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/unused_braces.fixed b/src/test/ui/lint/unused_braces.fixed new file mode 100644 index 0000000000000000000000000000000000000000..c0225911c6ed00879c3dd3f8422d2100858a2ca8 --- /dev/null +++ b/src/test/ui/lint/unused_braces.fixed @@ -0,0 +1,53 @@ +// check-pass +// run-rustfix + +#![warn(unused_braces, unused_parens)] +#![allow(unreachable_code, unused_unsafe)] // for rustfix + +fn consume(_: T) {} + +fn main() { + let _ = 7; + //~^WARN unnecessary parentheses + + // Do not emit a lint in these cases, + // as we have to be careful with + // `ref` patterns. + { + let _ = { 7 }; + + if let 7 = { 7 } { } + + match { 7 } { + _ => (), + } + } + + if true { + //~^ WARN unnecessary braces + } + + while false { + //~^ WARN unnecessary braces + } + + let _: [u8; 3 ]; + //~^ WARN unnecessary braces + + consume( 7 ); + //~^ WARN unnecessary braces + + // Do not emit lint for multiline blocks. + let _ = { + 7 + }; + + // Do not emit lint for unsafe blocks. + let _ = unsafe { 7 }; + + // Do not emit lint, as the `{` would then + // be parsed as part of the `return`. + if { return } { + + } +} diff --git a/src/test/ui/lint/unused_braces.rs b/src/test/ui/lint/unused_braces.rs index 952398ef0685bd8f0345eb2ac6aa4fe9e7e5b21b..5ca4811fc32d8342f523d5af85ea902dcf852510 100644 --- a/src/test/ui/lint/unused_braces.rs +++ b/src/test/ui/lint/unused_braces.rs @@ -1,5 +1,8 @@ // check-pass +// run-rustfix + #![warn(unused_braces, unused_parens)] +#![allow(unreachable_code, unused_unsafe)] // for rustfix fn consume(_: T) {} diff --git a/src/test/ui/lint/unused_braces.stderr b/src/test/ui/lint/unused_braces.stderr index 541d64b3e2a5d233189caae4ff7503844919c24a..8fa5dfde61db06eba3999604f7b2629ef8f52b8c 100644 --- a/src/test/ui/lint/unused_braces.stderr +++ b/src/test/ui/lint/unused_braces.stderr @@ -1,41 +1,41 @@ warning: unnecessary parentheses around assigned value - --> $DIR/unused_braces.rs:7:13 + --> $DIR/unused_braces.rs:10:13 | LL | let _ = (7); | ^^^ help: remove these parentheses | note: the lint level is defined here - --> $DIR/unused_braces.rs:2:24 + --> $DIR/unused_braces.rs:4:24 | LL | #![warn(unused_braces, unused_parens)] | ^^^^^^^^^^^^^ warning: unnecessary braces around `if` condition - --> $DIR/unused_braces.rs:23:8 + --> $DIR/unused_braces.rs:26:8 | LL | if { true } { | ^^^^^^^^ help: remove these braces | note: the lint level is defined here - --> $DIR/unused_braces.rs:2:9 + --> $DIR/unused_braces.rs:4:9 | LL | #![warn(unused_braces, unused_parens)] | ^^^^^^^^^^^^^ warning: unnecessary braces around `while` condition - --> $DIR/unused_braces.rs:27:11 + --> $DIR/unused_braces.rs:30:11 | LL | while { false } { | ^^^^^^^^^ help: remove these braces warning: unnecessary braces around const expression - --> $DIR/unused_braces.rs:31:17 + --> $DIR/unused_braces.rs:34:17 | LL | let _: [u8; { 3 }]; | ^^^^^ help: remove these braces warning: unnecessary braces around function argument - --> $DIR/unused_braces.rs:34:13 + --> $DIR/unused_braces.rs:37:13 | LL | consume({ 7 }); | ^^^^^ help: remove these braces diff --git a/src/test/ui/lint/unused_braces_borrow.fixed b/src/test/ui/lint/unused_braces_borrow.fixed new file mode 100644 index 0000000000000000000000000000000000000000..25950334549f95baccc299ff076825fe54d05fe2 --- /dev/null +++ b/src/test/ui/lint/unused_braces_borrow.fixed @@ -0,0 +1,26 @@ +// check-pass +// run-rustfix + +#![warn(unused_braces)] + +// changing `&{ expr }` to `&expr` changes the semantic of the program +// so we should not warn this case + +#[repr(packed)] +pub struct A { + pub a: u8, + pub b: u32, +} + +fn consume(_: T) {} + +fn main() { + let a = A { + a: 42, + b: 1729, + }; + + consume(&{ a.b }); + consume( a.b ); + //~^ WARN unnecessary braces +} diff --git a/src/test/ui/lint/unused_braces_borrow.rs b/src/test/ui/lint/unused_braces_borrow.rs index d0b059744e1fd94e00ba6dd8e2989691c619f227..b7c529d73b94e058d394e52f13cbddecbf4579c7 100644 --- a/src/test/ui/lint/unused_braces_borrow.rs +++ b/src/test/ui/lint/unused_braces_borrow.rs @@ -1,13 +1,15 @@ // check-pass +// run-rustfix + #![warn(unused_braces)] // changing `&{ expr }` to `&expr` changes the semantic of the program // so we should not warn this case #[repr(packed)] -struct A { - a: u8, - b: u32, +pub struct A { + pub a: u8, + pub b: u32, } fn consume(_: T) {} diff --git a/src/test/ui/lint/unused_braces_borrow.stderr b/src/test/ui/lint/unused_braces_borrow.stderr index 187fb9a212e0b430cc3c02d8b8c23cd9571383dc..f018c46fcd3c6ae3772d60b184e2267c3f61fd77 100644 --- a/src/test/ui/lint/unused_braces_borrow.stderr +++ b/src/test/ui/lint/unused_braces_borrow.stderr @@ -1,11 +1,11 @@ warning: unnecessary braces around function argument - --> $DIR/unused_braces_borrow.rs:22:13 + --> $DIR/unused_braces_borrow.rs:24:13 | LL | consume({ a.b }); | ^^^^^^^ help: remove these braces | note: the lint level is defined here - --> $DIR/unused_braces_borrow.rs:2:9 + --> $DIR/unused_braces_borrow.rs:4:9 | LL | #![warn(unused_braces)] | ^^^^^^^^^^^^^ diff --git a/src/test/ui/nll/capture-mut-ref.fixed b/src/test/ui/nll/capture-mut-ref.fixed new file mode 100644 index 0000000000000000000000000000000000000000..639de2813a90a85f2ff7afa334526d08e599ad41 --- /dev/null +++ b/src/test/ui/nll/capture-mut-ref.fixed @@ -0,0 +1,16 @@ +// run-rustfix + +// Check that capturing a mutable reference by move and assigning to its +// referent doesn't make the unused mut lint think that it is mutable. + +#![deny(unused_mut)] + +pub fn mutable_upvar() { + let x = &mut 0; + //~^ ERROR + move || { + *x = 1; + }; +} + +fn main() {} diff --git a/src/test/ui/nll/capture-mut-ref.rs b/src/test/ui/nll/capture-mut-ref.rs index 9d2624a9d6fa628b2710da6ec316f9a31385e578..89f49e1ea5186d1ace0054dcf3469a4b7778706e 100644 --- a/src/test/ui/nll/capture-mut-ref.rs +++ b/src/test/ui/nll/capture-mut-ref.rs @@ -1,9 +1,11 @@ +// run-rustfix + // Check that capturing a mutable reference by move and assigning to its // referent doesn't make the unused mut lint think that it is mutable. #![deny(unused_mut)] -fn mutable_upvar() { +pub fn mutable_upvar() { let mut x = &mut 0; //~^ ERROR move || { diff --git a/src/test/ui/nll/capture-mut-ref.stderr b/src/test/ui/nll/capture-mut-ref.stderr index 95d8e874a68d465c1fa36c88c6d1de7c051b91ca..4898d569235e73d1b7cc13ecd991970d0ac70ab3 100644 --- a/src/test/ui/nll/capture-mut-ref.stderr +++ b/src/test/ui/nll/capture-mut-ref.stderr @@ -1,5 +1,5 @@ error: variable does not need to be mutable - --> $DIR/capture-mut-ref.rs:7:9 + --> $DIR/capture-mut-ref.rs:9:9 | LL | let mut x = &mut 0; | ----^ @@ -7,7 +7,7 @@ LL | let mut x = &mut 0; | help: remove this `mut` | note: the lint level is defined here - --> $DIR/capture-mut-ref.rs:4:9 + --> $DIR/capture-mut-ref.rs:6:9 | LL | #![deny(unused_mut)] | ^^^^^^^^^^ diff --git a/src/test/ui/nll/issue-61424.fixed b/src/test/ui/nll/issue-61424.fixed new file mode 100644 index 0000000000000000000000000000000000000000..63e00c1722e453b196fc5f487e495809c1752751 --- /dev/null +++ b/src/test/ui/nll/issue-61424.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +#![deny(unused_mut)] + +fn main() { + let x; //~ ERROR: variable does not need to be mutable + x = String::new(); + dbg!(x); +} diff --git a/src/test/ui/nll/issue-61424.rs b/src/test/ui/nll/issue-61424.rs index 44c8e9f7256f54d89141ba98eaa169c1a40786d9..3b64996c27b07ead844a1dfbf56b7ba8b9712dbd 100644 --- a/src/test/ui/nll/issue-61424.rs +++ b/src/test/ui/nll/issue-61424.rs @@ -1,3 +1,5 @@ +// run-rustfix + #![deny(unused_mut)] fn main() { diff --git a/src/test/ui/nll/issue-61424.stderr b/src/test/ui/nll/issue-61424.stderr index 41dd7254d75a37d6ae0711e05e884fb1e1f98e36..6de6b7f3abd0b8a743abf61ab534aede4de2a26d 100644 --- a/src/test/ui/nll/issue-61424.stderr +++ b/src/test/ui/nll/issue-61424.stderr @@ -1,5 +1,5 @@ error: variable does not need to be mutable - --> $DIR/issue-61424.rs:4:9 + --> $DIR/issue-61424.rs:6:9 | LL | let mut x; | ----^ @@ -7,7 +7,7 @@ LL | let mut x; | help: remove this `mut` | note: the lint level is defined here - --> $DIR/issue-61424.rs:1:9 + --> $DIR/issue-61424.rs:3:9 | LL | #![deny(unused_mut)] | ^^^^^^^^^^ diff --git a/src/test/ui/nll/unused-mut-issue-50343.fixed b/src/test/ui/nll/unused-mut-issue-50343.fixed new file mode 100644 index 0000000000000000000000000000000000000000..5632de1cd34ded4224ca7be61505a11ee3aad669 --- /dev/null +++ b/src/test/ui/nll/unused-mut-issue-50343.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +#![deny(unused_mut)] +#![allow(unused_variables)] // for rustfix + +fn main() { + vec![(42, 22)].iter().map(|(x, _y)| ()).count(); + //~^ ERROR: variable does not need to be mutable +} diff --git a/src/test/ui/nll/unused-mut-issue-50343.rs b/src/test/ui/nll/unused-mut-issue-50343.rs index da0d9229c1262bb9edfda28e23ee317df70e8df6..c849ac8c79e43243bfb40c18c7803d6aac5cd108 100644 --- a/src/test/ui/nll/unused-mut-issue-50343.rs +++ b/src/test/ui/nll/unused-mut-issue-50343.rs @@ -1,4 +1,7 @@ +// run-rustfix + #![deny(unused_mut)] +#![allow(unused_variables)] // for rustfix fn main() { vec![(42, 22)].iter().map(|(mut x, _y)| ()).count(); diff --git a/src/test/ui/nll/unused-mut-issue-50343.stderr b/src/test/ui/nll/unused-mut-issue-50343.stderr index c86981a8dff1576faec795413dcc72c55362832f..cb02d76205c7f22800092c2aae6b9d727a545b2c 100644 --- a/src/test/ui/nll/unused-mut-issue-50343.stderr +++ b/src/test/ui/nll/unused-mut-issue-50343.stderr @@ -1,5 +1,5 @@ error: variable does not need to be mutable - --> $DIR/unused-mut-issue-50343.rs:4:33 + --> $DIR/unused-mut-issue-50343.rs:7:33 | LL | vec![(42, 22)].iter().map(|(mut x, _y)| ()).count(); | ----^ @@ -7,7 +7,7 @@ LL | vec![(42, 22)].iter().map(|(mut x, _y)| ()).count(); | help: remove this `mut` | note: the lint level is defined here - --> $DIR/unused-mut-issue-50343.rs:1:9 + --> $DIR/unused-mut-issue-50343.rs:3:9 | LL | #![deny(unused_mut)] | ^^^^^^^^^^ diff --git a/src/test/ui/parser/bad-fn-ptr-qualifier.fixed b/src/test/ui/parser/bad-fn-ptr-qualifier.fixed new file mode 100644 index 0000000000000000000000000000000000000000..ad8e718cf88a596a9d2105d6710bf25724c519ef --- /dev/null +++ b/src/test/ui/parser/bad-fn-ptr-qualifier.fixed @@ -0,0 +1,26 @@ +// run-rustfix +// edition:2018 +// Most of items are taken from ./recover-const-async-fn-ptr.rs but this is able to apply rustfix. + +pub type T0 = fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type T1 = extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type T2 = unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type T3 = fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type T4 = extern fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type T5 = unsafe extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type T6 = unsafe extern "C" fn(); +//~^ ERROR an `fn` pointer type cannot be `const` +//~| ERROR an `fn` pointer type cannot be `async` + +pub type FTT0 = for<'a> fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type FTT1 = for<'a> extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type FTT2 = for<'a> unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type FTT3 = for<'a> fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type FTT4 = for<'a> extern fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type FTT5 = for<'a> unsafe extern "C" fn(); +//~^ ERROR an `fn` pointer type cannot be `async` +pub type FTT6 = for<'a> unsafe extern "C" fn(); +//~^ ERROR an `fn` pointer type cannot be `const` +//~| ERROR an `fn` pointer type cannot be `async` + +fn main() {} diff --git a/src/test/ui/parser/bad-fn-ptr-qualifier.rs b/src/test/ui/parser/bad-fn-ptr-qualifier.rs new file mode 100644 index 0000000000000000000000000000000000000000..c04813dadff7bd7b049529193b5962b5fba30f0c --- /dev/null +++ b/src/test/ui/parser/bad-fn-ptr-qualifier.rs @@ -0,0 +1,26 @@ +// run-rustfix +// edition:2018 +// Most of items are taken from ./recover-const-async-fn-ptr.rs but this is able to apply rustfix. + +pub type T0 = const fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type T1 = const extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type T2 = const unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type T3 = async fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type T4 = async extern fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type T5 = async unsafe extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type T6 = const async unsafe extern "C" fn(); +//~^ ERROR an `fn` pointer type cannot be `const` +//~| ERROR an `fn` pointer type cannot be `async` + +pub type FTT0 = for<'a> const fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type FTT1 = for<'a> const extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type FTT2 = for<'a> const unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const` +pub type FTT3 = for<'a> async fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type FTT4 = for<'a> async extern fn(); //~ ERROR an `fn` pointer type cannot be `async` +pub type FTT5 = for<'a> async unsafe extern "C" fn(); +//~^ ERROR an `fn` pointer type cannot be `async` +pub type FTT6 = for<'a> const async unsafe extern "C" fn(); +//~^ ERROR an `fn` pointer type cannot be `const` +//~| ERROR an `fn` pointer type cannot be `async` + +fn main() {} diff --git a/src/test/ui/parser/bad-fn-ptr-qualifier.stderr b/src/test/ui/parser/bad-fn-ptr-qualifier.stderr new file mode 100644 index 0000000000000000000000000000000000000000..265e31329ca546aac88adf1177338f7330e2fa9e --- /dev/null +++ b/src/test/ui/parser/bad-fn-ptr-qualifier.stderr @@ -0,0 +1,146 @@ +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:5:15 + | +LL | pub type T0 = const fn(); + | -----^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:6:15 + | +LL | pub type T1 = const extern "C" fn(); + | -----^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:7:15 + | +LL | pub type T2 = const unsafe extern fn(); + | -----^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:8:15 + | +LL | pub type T3 = async fn(); + | -----^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:9:15 + | +LL | pub type T4 = async extern fn(); + | -----^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:10:15 + | +LL | pub type T5 = async unsafe extern "C" fn(); + | -----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:11:15 + | +LL | pub type T6 = const async unsafe extern "C" fn(); + | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:11:15 + | +LL | pub type T6 = const async unsafe extern "C" fn(); + | ^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:15:17 + | +LL | pub type FTT0 = for<'a> const fn(); + | ^^^^^^^^-----^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:16:17 + | +LL | pub type FTT1 = for<'a> const extern "C" fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:17:17 + | +LL | pub type FTT2 = for<'a> const unsafe extern fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:18:17 + | +LL | pub type FTT3 = for<'a> async fn(); + | ^^^^^^^^-----^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:19:17 + | +LL | pub type FTT4 = for<'a> async extern fn(); + | ^^^^^^^^-----^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:20:17 + | +LL | pub type FTT5 = for<'a> async unsafe extern "C" fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/bad-fn-ptr-qualifier.rs:22:17 + | +LL | pub type FTT6 = for<'a> const async unsafe extern "C" fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/bad-fn-ptr-qualifier.rs:22:17 + | +LL | pub type FTT6 = for<'a> const async unsafe extern "C" fn(); + | ^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: aborting due to 16 previous errors + diff --git a/src/test/ui/parser/if-in-in.fixed b/src/test/ui/parser/if-in-in.fixed new file mode 100644 index 0000000000000000000000000000000000000000..0bb88c55936f0b36de75f5938944d2ccfa3a532c --- /dev/null +++ b/src/test/ui/parser/if-in-in.fixed @@ -0,0 +1,7 @@ +// run-rustfix + +fn main() { + for i in 1..2 { //~ ERROR expected iterable, found keyword `in` + println!("{}", i); + } +} diff --git a/src/test/ui/parser/if-in-in.rs b/src/test/ui/parser/if-in-in.rs index 212378c28665b57333d4fbc07f1b09d8878c5d98..6c0986fe1ba5f770193cdc0efbca5e4d0fc8f767 100644 --- a/src/test/ui/parser/if-in-in.rs +++ b/src/test/ui/parser/if-in-in.rs @@ -1,3 +1,5 @@ +// run-rustfix + fn main() { for i in in 1..2 { //~ ERROR expected iterable, found keyword `in` println!("{}", i); diff --git a/src/test/ui/parser/if-in-in.stderr b/src/test/ui/parser/if-in-in.stderr index 1adb4429ec7d0b426041cc57ddcbcbaad5c84540..0e69bc4b2ce53b6cdcd79f25998033dbf40c49b9 100644 --- a/src/test/ui/parser/if-in-in.stderr +++ b/src/test/ui/parser/if-in-in.stderr @@ -1,5 +1,5 @@ error: expected iterable, found keyword `in` - --> $DIR/if-in-in.rs:2:14 + --> $DIR/if-in-in.rs:4:14 | LL | for i in in 1..2 { | ---^^ diff --git a/src/test/ui/parser/issue-10392-2.fixed b/src/test/ui/parser/issue-10392-2.fixed new file mode 100644 index 0000000000000000000000000000000000000000..3386fac17dfd7c71a08e761fb161586365cc2089 --- /dev/null +++ b/src/test/ui/parser/issue-10392-2.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +pub struct A { pub foo: isize } + +fn a() -> A { panic!() } + +fn main() { + let A { .. } = a(); //~ ERROR: expected `}` +} diff --git a/src/test/ui/parser/issue-10392-2.rs b/src/test/ui/parser/issue-10392-2.rs index 3b5e3199a8ab3dcee5643fbb434cc7aca18129ef..30628ae31c3bdab3ef901214647fb466f2d28e71 100644 --- a/src/test/ui/parser/issue-10392-2.rs +++ b/src/test/ui/parser/issue-10392-2.rs @@ -1,4 +1,6 @@ -struct A { foo: isize } +// run-rustfix + +pub struct A { pub foo: isize } fn a() -> A { panic!() } diff --git a/src/test/ui/parser/issue-10392-2.stderr b/src/test/ui/parser/issue-10392-2.stderr index ccc5dd938b5fd9192600d7e90921e90bec5647c1..4154ecfeb71c3b4463ac0f33a4f8f4d57a60d186 100644 --- a/src/test/ui/parser/issue-10392-2.stderr +++ b/src/test/ui/parser/issue-10392-2.stderr @@ -1,5 +1,5 @@ error: expected `}`, found `,` - --> $DIR/issue-10392-2.rs:6:15 + --> $DIR/issue-10392-2.rs:8:15 | LL | let A { .., } = a(); | --^ diff --git a/src/test/ui/parser/issue-3036.fixed b/src/test/ui/parser/issue-3036.fixed new file mode 100644 index 0000000000000000000000000000000000000000..e5d5622e6fc00395bcde854b36ad0bb91f2da2a9 --- /dev/null +++ b/src/test/ui/parser/issue-3036.fixed @@ -0,0 +1,7 @@ +// run-rustfix + +// Testing that semicolon tokens are printed correctly in errors + +fn main() { + let _x = 3; //~ ERROR: expected `;` +} diff --git a/src/test/ui/parser/issue-3036.rs b/src/test/ui/parser/issue-3036.rs index 6a8b67fefa780fb7d6a65ebd960974bc024c59d9..2f76fb99b22068a43503417267e42b9cf7664202 100644 --- a/src/test/ui/parser/issue-3036.rs +++ b/src/test/ui/parser/issue-3036.rs @@ -1,6 +1,7 @@ +// run-rustfix + // Testing that semicolon tokens are printed correctly in errors -fn main() -{ - let x = 3 //~ ERROR: expected `;` +fn main() { + let _x = 3 //~ ERROR: expected `;` } diff --git a/src/test/ui/parser/issue-3036.stderr b/src/test/ui/parser/issue-3036.stderr index e5f5a7d8968dc0e3d1ea6812e0d3e7d7dc977b91..e02223931c1145aa3b6bd83e6e3312b54d78e45a 100644 --- a/src/test/ui/parser/issue-3036.stderr +++ b/src/test/ui/parser/issue-3036.stderr @@ -1,8 +1,8 @@ error: expected `;`, found `}` - --> $DIR/issue-3036.rs:5:14 + --> $DIR/issue-3036.rs:6:15 | -LL | let x = 3 - | ^ help: add `;` here +LL | let _x = 3 + | ^ help: add `;` here LL | } | - unexpected token diff --git a/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.fixed b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.fixed new file mode 100644 index 0000000000000000000000000000000000000000..95019b2786925741d7ff2467a88f4cc679911f85 --- /dev/null +++ b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.fixed @@ -0,0 +1,14 @@ +// run-rustfix + +// In this regression test for #67146, we check that the +// negative outlives bound `!'a` is rejected by the parser. +// This regression was first introduced in PR #57364. + +fn main() {} + +pub fn f1() {} +//~^ ERROR negative bounds are not supported +pub fn f2<'a, T: Ord>() {} +//~^ ERROR negative bounds are not supported +pub fn f3<'a, T: Ord>() {} +//~^ ERROR negative bounds are not supported diff --git a/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.rs b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.rs index 5a109ba7c6894f25600642ddefe2eef5117d39ef..82f54f8faa98cd615bfe34a30ab2b6ce4016f167 100644 --- a/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.rs +++ b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.rs @@ -1,12 +1,14 @@ +// run-rustfix + // In this regression test for #67146, we check that the // negative outlives bound `!'a` is rejected by the parser. // This regression was first introduced in PR #57364. fn main() {} -fn f1() {} +pub fn f1() {} //~^ ERROR negative bounds are not supported -fn f2<'a, T: Ord + !'a>() {} +pub fn f2<'a, T: Ord + !'a>() {} //~^ ERROR negative bounds are not supported -fn f3<'a, T: !'a + Ord>() {} +pub fn f3<'a, T: !'a + Ord>() {} //~^ ERROR negative bounds are not supported diff --git a/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.stderr b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.stderr index 4dc06347304421eb3394b53cf0d29acf7bc11bba..a4a422948aca6db3eb79a2c1ad97ce78d87bde15 100644 --- a/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.stderr +++ b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.stderr @@ -1,20 +1,20 @@ error: negative bounds are not supported - --> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:7:8 + --> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:9:12 | -LL | fn f1() {} - | ^^^^^^^^^^ negative bounds are not supported +LL | pub fn f1() {} + | ^^^^^^^^^^ negative bounds are not supported error: negative bounds are not supported - --> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:9:18 + --> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:11:22 | -LL | fn f2<'a, T: Ord + !'a>() {} - | ^^^^^ negative bounds are not supported +LL | pub fn f2<'a, T: Ord + !'a>() {} + | ^^^^^ negative bounds are not supported error: negative bounds are not supported - --> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:11:12 + --> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:13:16 | -LL | fn f3<'a, T: !'a + Ord>() {} - | ^^^^^ negative bounds are not supported +LL | pub fn f3<'a, T: !'a + Ord>() {} + | ^^^^^ negative bounds are not supported error: aborting due to 3 previous errors diff --git a/src/test/ui/parser/issue-70388-without-witness.fixed b/src/test/ui/parser/issue-70388-without-witness.fixed new file mode 100644 index 0000000000000000000000000000000000000000..464e78fd0359534e0bd9bdcf11cddd3e6f94cd94 --- /dev/null +++ b/src/test/ui/parser/issue-70388-without-witness.fixed @@ -0,0 +1,9 @@ +// run-rustfix +// This is for checking if we can apply suggestions as-is. + +pub struct Foo(i32); + +fn main() { + let Foo(..) = Foo(0); //~ ERROR unexpected `...` + let [_, .., _] = [0, 1]; //~ ERROR unexpected `...` +} diff --git a/src/test/ui/parser/issue-70388-without-witness.rs b/src/test/ui/parser/issue-70388-without-witness.rs new file mode 100644 index 0000000000000000000000000000000000000000..9e35e4c38aa871b5deb0aeb96f918ffce93c6440 --- /dev/null +++ b/src/test/ui/parser/issue-70388-without-witness.rs @@ -0,0 +1,9 @@ +// run-rustfix +// This is for checking if we can apply suggestions as-is. + +pub struct Foo(i32); + +fn main() { + let Foo(...) = Foo(0); //~ ERROR unexpected `...` + let [_, ..., _] = [0, 1]; //~ ERROR unexpected `...` +} diff --git a/src/test/ui/parser/issue-70388-without-witness.stderr b/src/test/ui/parser/issue-70388-without-witness.stderr new file mode 100644 index 0000000000000000000000000000000000000000..b750ad4c626d6b8a1b10d5b8a8af9468079016bb --- /dev/null +++ b/src/test/ui/parser/issue-70388-without-witness.stderr @@ -0,0 +1,20 @@ +error: unexpected `...` + --> $DIR/issue-70388-without-witness.rs:7:13 + | +LL | let Foo(...) = Foo(0); + | ^^^ + | | + | not a valid pattern + | help: for a rest pattern, use `..` instead of `...` + +error: unexpected `...` + --> $DIR/issue-70388-without-witness.rs:8:13 + | +LL | let [_, ..., _] = [0, 1]; + | ^^^ + | | + | not a valid pattern + | help: for a rest pattern, use `..` instead of `...` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/parser/let-binop.fixed b/src/test/ui/parser/let-binop.fixed new file mode 100644 index 0000000000000000000000000000000000000000..93f7f97b04fb77220b9175270bfe335b1da9ad37 --- /dev/null +++ b/src/test/ui/parser/let-binop.fixed @@ -0,0 +1,10 @@ +// run-rustfix + +fn main() { + let a: i8 = 1; //~ ERROR can't reassign to an uninitialized variable + let _ = a; + let b = 1; //~ ERROR can't reassign to an uninitialized variable + let _ = b; + let c = 1; //~ ERROR can't reassign to an uninitialized variable + let _ = c; +} diff --git a/src/test/ui/parser/let-binop.rs b/src/test/ui/parser/let-binop.rs index 7f58f5df2d4125786ff200cc557cd910d1338554..2adbceae5d3c439a4157d0587ea5ebb7a826adab 100644 --- a/src/test/ui/parser/let-binop.rs +++ b/src/test/ui/parser/let-binop.rs @@ -1,3 +1,5 @@ +// run-rustfix + fn main() { let a: i8 *= 1; //~ ERROR can't reassign to an uninitialized variable let _ = a; diff --git a/src/test/ui/parser/let-binop.stderr b/src/test/ui/parser/let-binop.stderr index 71431499ac70b8c0ea43c7e8db333fac646da5e4..90295854a2d2d6a35be0bd81f7a65935704a08c2 100644 --- a/src/test/ui/parser/let-binop.stderr +++ b/src/test/ui/parser/let-binop.stderr @@ -1,17 +1,17 @@ error: can't reassign to an uninitialized variable - --> $DIR/let-binop.rs:2:15 + --> $DIR/let-binop.rs:4:15 | LL | let a: i8 *= 1; | ^^ help: initialize the variable error: can't reassign to an uninitialized variable - --> $DIR/let-binop.rs:4:11 + --> $DIR/let-binop.rs:6:11 | LL | let b += 1; | ^^ help: initialize the variable error: can't reassign to an uninitialized variable - --> $DIR/let-binop.rs:6:11 + --> $DIR/let-binop.rs:8:11 | LL | let c *= 1; | ^^ help: initialize the variable diff --git a/src/test/ui/parser/match-refactor-to-expr.fixed b/src/test/ui/parser/match-refactor-to-expr.fixed new file mode 100644 index 0000000000000000000000000000000000000000..f21024235a591c14edca52b78d09bb2849f286fa --- /dev/null +++ b/src/test/ui/parser/match-refactor-to-expr.fixed @@ -0,0 +1,12 @@ +// run-rustfix + +fn main() { + let foo = + //~ NOTE while parsing this match expression + Some(4).unwrap_or(5) + //~^ NOTE expected one of `.`, `?`, `{`, or an operator + ; //~ NOTE unexpected token + //~^ ERROR expected one of `.`, `?`, `{`, or an operator, found `;` + + println!("{}", foo) +} diff --git a/src/test/ui/parser/match-refactor-to-expr.rs b/src/test/ui/parser/match-refactor-to-expr.rs index e10ebf2e2d60af0955b0174f59b96e7113f40a37..e02d74e2f7eac03457413a02372a6e2d04806fe5 100644 --- a/src/test/ui/parser/match-refactor-to-expr.rs +++ b/src/test/ui/parser/match-refactor-to-expr.rs @@ -1,7 +1,9 @@ +// run-rustfix + fn main() { let foo = match //~ NOTE while parsing this match expression - Some(4).unwrap_or_else(5) + Some(4).unwrap_or(5) //~^ NOTE expected one of `.`, `?`, `{`, or an operator ; //~ NOTE unexpected token //~^ ERROR expected one of `.`, `?`, `{`, or an operator, found `;` diff --git a/src/test/ui/parser/match-refactor-to-expr.stderr b/src/test/ui/parser/match-refactor-to-expr.stderr index 5cbf0232bc31ef990d7e7a33d66cf98b3eb5228b..15107ab9a258b699a131bba45734928a817f6ff5 100644 --- a/src/test/ui/parser/match-refactor-to-expr.stderr +++ b/src/test/ui/parser/match-refactor-to-expr.stderr @@ -1,13 +1,13 @@ error: expected one of `.`, `?`, `{`, or an operator, found `;` - --> $DIR/match-refactor-to-expr.rs:6:9 + --> $DIR/match-refactor-to-expr.rs:8:9 | LL | match | ----- | | | while parsing this match expression | help: try removing this `match` -LL | Some(4).unwrap_or_else(5) - | - expected one of `.`, `?`, `{`, or an operator +LL | Some(4).unwrap_or(5) + | - expected one of `.`, `?`, `{`, or an operator LL | LL | ; | ^ unexpected token diff --git a/src/test/ui/parser/range_inclusive.fixed b/src/test/ui/parser/range_inclusive.fixed new file mode 100644 index 0000000000000000000000000000000000000000..fe23880d1d48a7973f217bb97e07548a64ad29b2 --- /dev/null +++ b/src/test/ui/parser/range_inclusive.fixed @@ -0,0 +1,7 @@ +// run-rustfix +// Make sure that inclusive ranges with no end point don't parse. + +pub fn main() { + for _ in 1.. {} //~ERROR inclusive range with no end + //~^HELP use `..` instead +} diff --git a/src/test/ui/parser/range_inclusive.rs b/src/test/ui/parser/range_inclusive.rs index 7c3b906b47f9f4b8723ccbba0ca8ca4065049596..bc6d2413d26232f5d62734475e2b4fedf8595805 100644 --- a/src/test/ui/parser/range_inclusive.rs +++ b/src/test/ui/parser/range_inclusive.rs @@ -1,3 +1,4 @@ +// run-rustfix // Make sure that inclusive ranges with no end point don't parse. pub fn main() { diff --git a/src/test/ui/parser/range_inclusive.stderr b/src/test/ui/parser/range_inclusive.stderr index 1dd479945968104d4c270154d978c91038e5b16f..8a91782639f450f90053886c4ebc629481f7b8dc 100644 --- a/src/test/ui/parser/range_inclusive.stderr +++ b/src/test/ui/parser/range_inclusive.stderr @@ -1,5 +1,5 @@ error[E0586]: inclusive range with no end - --> $DIR/range_inclusive.rs:4:15 + --> $DIR/range_inclusive.rs:5:15 | LL | for _ in 1..= {} | ^^^ help: use `..` instead diff --git a/src/test/ui/parser/trait-object-lifetime-parens.rs b/src/test/ui/parser/trait-object-lifetime-parens.rs index 5a5c19f32e8060553581805d79d4e819e94d51d4..f44ebe5ba5bf2330c7e7348cab45d1d5f021d1f0 100644 --- a/src/test/ui/parser/trait-object-lifetime-parens.rs +++ b/src/test/ui/parser/trait-object-lifetime-parens.rs @@ -6,6 +6,7 @@ fn f<'a, T: Trait + ('a)>() {} //~ ERROR parenthesized lifetime bounds are not s fn check<'a>() { let _: Box; //~ ERROR parenthesized lifetime bounds are not supported + // FIXME: It'd be great if we could add suggestion to the following case. let _: Box<('a) + Trait>; //~ ERROR lifetime in trait object type must be followed by `+` } diff --git a/src/test/ui/parser/trait-object-lifetime-parens.stderr b/src/test/ui/parser/trait-object-lifetime-parens.stderr index 1289c248275dc8b39b6b16ea8bee252fc17727eb..9c7a9662c40243e08d481e1f1ee07b0a934d3ffe 100644 --- a/src/test/ui/parser/trait-object-lifetime-parens.stderr +++ b/src/test/ui/parser/trait-object-lifetime-parens.stderr @@ -11,7 +11,7 @@ LL | let _: Box; | ^^^^ help: remove the parentheses error: lifetime in trait object type must be followed by `+` - --> $DIR/trait-object-lifetime-parens.rs:9:17 + --> $DIR/trait-object-lifetime-parens.rs:10:17 | LL | let _: Box<('a) + Trait>; | ^^ diff --git a/src/test/ui/path-lookahead.fixed b/src/test/ui/path-lookahead.fixed new file mode 100644 index 0000000000000000000000000000000000000000..928955630e9ffbcb41a1818a2763a67917dfeed2 --- /dev/null +++ b/src/test/ui/path-lookahead.fixed @@ -0,0 +1,17 @@ +// run-pass +// run-rustfix + +#![allow(dead_code)] +#![warn(unused_parens)] + +// Parser test for #37765 + +fn with_parens(arg: T) -> String { + return ::to_string(&arg); //~WARN unnecessary parentheses around `return` value +} + +fn no_parens(arg: T) -> String { + return ::to_string(&arg); +} + +fn main() {} diff --git a/src/test/ui/path-lookahead.rs b/src/test/ui/path-lookahead.rs index 86bcb08de404eddcc04839b11c2cdfe2b96652af..d05c75fe8d8e0b13d3053950fc091b3c001cc4f0 100644 --- a/src/test/ui/path-lookahead.rs +++ b/src/test/ui/path-lookahead.rs @@ -1,17 +1,17 @@ // run-pass +// run-rustfix + #![allow(dead_code)] #![warn(unused_parens)] // Parser test for #37765 fn with_parens(arg: T) -> String { - return (::to_string(&arg)); //~WARN unnecessary parentheses around `return` value + return (::to_string(&arg)); //~WARN unnecessary parentheses around `return` value } fn no_parens(arg: T) -> String { - return ::to_string(&arg); + return ::to_string(&arg); } -fn main() { - -} +fn main() {} diff --git a/src/test/ui/path-lookahead.stderr b/src/test/ui/path-lookahead.stderr index 7a57b6100f3805d1887a86a3761e4e44bbf29ea4..dcf235a9e277455079318ec30f933f6ae57a03da 100644 --- a/src/test/ui/path-lookahead.stderr +++ b/src/test/ui/path-lookahead.stderr @@ -1,11 +1,11 @@ warning: unnecessary parentheses around `return` value - --> $DIR/path-lookahead.rs:8:10 + --> $DIR/path-lookahead.rs:10:12 | -LL | return (::to_string(&arg)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses +LL | return (::to_string(&arg)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses | note: the lint level is defined here - --> $DIR/path-lookahead.rs:3:9 + --> $DIR/path-lookahead.rs:5:9 | LL | #![warn(unused_parens)] | ^^^^^^^^^^^^^ diff --git a/src/test/ui/pub/pub-ident-fn-2.fixed b/src/test/ui/pub/pub-ident-fn-2.fixed new file mode 100644 index 0000000000000000000000000000000000000000..afd75a41f7b0f7d026893a11408a69b5d208689b --- /dev/null +++ b/src/test/ui/pub/pub-ident-fn-2.fixed @@ -0,0 +1,10 @@ +// run-rustfix + +pub fn foo(_s: usize) { bar() } +//~^ ERROR missing `fn` for function definition + +fn bar() {} + +fn main() { + foo(2); +} diff --git a/src/test/ui/pub/pub-ident-fn-2.rs b/src/test/ui/pub/pub-ident-fn-2.rs index e1fc20c657730686daa72fafdeaa3f156b370898..e7b86a9098d16dd9575c101ffe675461a10e5521 100644 --- a/src/test/ui/pub/pub-ident-fn-2.rs +++ b/src/test/ui/pub/pub-ident-fn-2.rs @@ -1,6 +1,10 @@ -pub foo(s: usize) { bar() } +// run-rustfix + +pub foo(_s: usize) { bar() } //~^ ERROR missing `fn` for function definition +fn bar() {} + fn main() { foo(2); } diff --git a/src/test/ui/pub/pub-ident-fn-2.stderr b/src/test/ui/pub/pub-ident-fn-2.stderr index c44a5961565ab3bd3f9ef31e012f92fc01021ef2..b830b0e90098a490db11ac237b7578e3937b4a22 100644 --- a/src/test/ui/pub/pub-ident-fn-2.stderr +++ b/src/test/ui/pub/pub-ident-fn-2.stderr @@ -1,12 +1,12 @@ error: missing `fn` for function definition - --> $DIR/pub-ident-fn-2.rs:1:4 + --> $DIR/pub-ident-fn-2.rs:3:4 | -LL | pub foo(s: usize) { bar() } +LL | pub foo(_s: usize) { bar() } | ^ | help: add `fn` here to parse `foo` as a public function | -LL | pub fn foo(s: usize) { bar() } +LL | pub fn foo(_s: usize) { bar() } | ^^ error: aborting due to previous error diff --git a/src/test/ui/pub/pub-ident-fn-with-lifetime.fixed b/src/test/ui/pub/pub-ident-fn-with-lifetime.fixed new file mode 100644 index 0000000000000000000000000000000000000000..e510ace5fc14c91f44874a240b0ff040a409f4f9 --- /dev/null +++ b/src/test/ui/pub/pub-ident-fn-with-lifetime.fixed @@ -0,0 +1,8 @@ +// run-rustfix + +pub fn foo<'a>(_s: &'a usize) -> bool { true } +//~^ ERROR missing `fn` for function definition + +fn main() { + foo(&2); +} diff --git a/src/test/ui/pub/pub-ident-fn-with-lifetime.rs b/src/test/ui/pub/pub-ident-fn-with-lifetime.rs index 84f7bdc1fb14796d9bd4642eacc072fcb5a86934..63e6eca151600ffed09c849482d3f8c3d3f775ff 100644 --- a/src/test/ui/pub/pub-ident-fn-with-lifetime.rs +++ b/src/test/ui/pub/pub-ident-fn-with-lifetime.rs @@ -1,6 +1,8 @@ +// run-rustfix + pub foo<'a>(_s: &'a usize) -> bool { true } //~^ ERROR missing `fn` for function definition fn main() { - foo(2); + foo(&2); } diff --git a/src/test/ui/pub/pub-ident-fn-with-lifetime.stderr b/src/test/ui/pub/pub-ident-fn-with-lifetime.stderr index 90c78141adbf664d440b3ea3cd2f258713e0a1d6..5b378df04b025d4243fadb2f3fd188b066bfc190 100644 --- a/src/test/ui/pub/pub-ident-fn-with-lifetime.stderr +++ b/src/test/ui/pub/pub-ident-fn-with-lifetime.stderr @@ -1,5 +1,5 @@ error: missing `fn` for function definition - --> $DIR/pub-ident-fn-with-lifetime.rs:1:4 + --> $DIR/pub-ident-fn-with-lifetime.rs:3:4 | LL | pub foo<'a>(_s: &'a usize) -> bool { true } | ^^^ diff --git a/src/test/ui/pub/pub-ident-struct.fixed b/src/test/ui/pub/pub-ident-struct.fixed new file mode 100644 index 0000000000000000000000000000000000000000..58cde8fd6e0ca9a432580d7e4879f0668b4c679c --- /dev/null +++ b/src/test/ui/pub/pub-ident-struct.fixed @@ -0,0 +1,6 @@ +// run-rustfix + +pub struct S { +//~^ ERROR missing `struct` for struct definition +} +fn main() {} diff --git a/src/test/ui/pub/pub-ident-struct.rs b/src/test/ui/pub/pub-ident-struct.rs index f2e6dfc77b6e0b206078d02be97d86f6f2c248cd..3930e556e9a9cc1fc9a2ac591beb3628c65f8070 100644 --- a/src/test/ui/pub/pub-ident-struct.rs +++ b/src/test/ui/pub/pub-ident-struct.rs @@ -1,3 +1,5 @@ +// run-rustfix + pub S { //~^ ERROR missing `struct` for struct definition } diff --git a/src/test/ui/pub/pub-ident-struct.stderr b/src/test/ui/pub/pub-ident-struct.stderr index efd7d1fe76a168a01e4da1fe30333c12100415c6..8af24904ef24cc1f4bec0d7e6c9dad202b5b91d6 100644 --- a/src/test/ui/pub/pub-ident-struct.stderr +++ b/src/test/ui/pub/pub-ident-struct.stderr @@ -1,5 +1,5 @@ error: missing `struct` for struct definition - --> $DIR/pub-ident-struct.rs:1:4 + --> $DIR/pub-ident-struct.rs:3:4 | LL | pub S { | ^ diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.fixed b/src/test/ui/range/range-inclusive-pattern-precedence.fixed new file mode 100644 index 0000000000000000000000000000000000000000..22ab6c755be2d30c33eb87438e5c0ac411bf2391 --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence.fixed @@ -0,0 +1,20 @@ +// In expression, `&a..=b` is treated as `(&a)..=(b)` and `box a..=b` is +// `(box a)..=(b)`. In a pattern, however, `&a..=b` means `&(a..=b)`. This may +// lead to confusion. + +// run-rustfix + +#![warn(ellipsis_inclusive_range_patterns)] + +pub fn main() { + match &12 { + &(0..=9) => {} + //~^ WARN `...` range patterns are deprecated + //~| HELP use `..=` for an inclusive range + &(10 ..=15) => {} + //~^ ERROR the range pattern here has ambiguous interpretation + //~^^ HELP add parentheses to clarify the precedence + &(16..=20) => {} + _ => {} + } +} diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.rs b/src/test/ui/range/range-inclusive-pattern-precedence.rs index fbafe1fe6ee121dc6a0afa28e2dd84eb7d4df4f2..f38a7920c94d66f26fae6824b76c5e3a643b2717 100644 --- a/src/test/ui/range/range-inclusive-pattern-precedence.rs +++ b/src/test/ui/range/range-inclusive-pattern-precedence.rs @@ -1,13 +1,10 @@ // In expression, `&a..=b` is treated as `(&a)..=(b)` and `box a..=b` is // `(box a)..=(b)`. In a pattern, however, `&a..=b` means `&(a..=b)`. This may // lead to confusion. -// -// We are going to disallow `&a..=b` and `box a..=b` in a pattern. However, the -// older ... syntax is still allowed as a stability guarantee. -#![feature(box_patterns)] -#![warn(ellipsis_inclusive_range_patterns)] +// run-rustfix +#![warn(ellipsis_inclusive_range_patterns)] pub fn main() { match &12 { @@ -20,15 +17,4 @@ pub fn main() { &(16..=20) => {} _ => {} } - - match Box::new(12) { - box 0...9 => {} - //~^ WARN `...` range patterns are deprecated - //~| HELP use `..=` for an inclusive range - box 10..=15 => {} - //~^ ERROR the range pattern here has ambiguous interpretation - //~^^ HELP add parentheses to clarify the precedence - box (16..=20) => {} - _ => {} - } } diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.stderr b/src/test/ui/range/range-inclusive-pattern-precedence.stderr index 3a4a514df7adea54eb57391d876316f9756367cc..853141969c20da8b252a2a3162126ad3e5453688 100644 --- a/src/test/ui/range/range-inclusive-pattern-precedence.stderr +++ b/src/test/ui/range/range-inclusive-pattern-precedence.stderr @@ -1,32 +1,20 @@ error: the range pattern here has ambiguous interpretation - --> $DIR/range-inclusive-pattern-precedence.rs:17:10 + --> $DIR/range-inclusive-pattern-precedence.rs:14:10 | LL | &10..=15 => {} | ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` -error: the range pattern here has ambiguous interpretation - --> $DIR/range-inclusive-pattern-precedence.rs:28:13 - | -LL | box 10..=15 => {} - | ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` - warning: `...` range patterns are deprecated - --> $DIR/range-inclusive-pattern-precedence.rs:14:9 + --> $DIR/range-inclusive-pattern-precedence.rs:11:9 | LL | &0...9 => {} | ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)` | note: the lint level is defined here - --> $DIR/range-inclusive-pattern-precedence.rs:9:9 + --> $DIR/range-inclusive-pattern-precedence.rs:7:9 | LL | #![warn(ellipsis_inclusive_range_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: `...` range patterns are deprecated - --> $DIR/range-inclusive-pattern-precedence.rs:25:14 - | -LL | box 0...9 => {} - | ^^^ help: use `..=` for an inclusive range - -error: aborting due to 2 previous errors; 2 warnings emitted +error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/range/range-inclusive-pattern-precedence2.rs b/src/test/ui/range/range-inclusive-pattern-precedence2.rs new file mode 100644 index 0000000000000000000000000000000000000000..6a3fd413e4fd7f0605a5571155bc310dfa0ecdf2 --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence2.rs @@ -0,0 +1,19 @@ +// We are going to disallow `&a..=b` and `box a..=b` in a pattern. However, the +// older ... syntax is still allowed as a stability guarantee. + +#![feature(box_patterns)] +#![warn(ellipsis_inclusive_range_patterns)] + +fn main() { + match Box::new(12) { + // FIXME: can we add suggestions like `&(0..=9)`? + box 0...9 => {} + //~^ WARN `...` range patterns are deprecated + //~| HELP use `..=` for an inclusive range + box 10..=15 => {} + //~^ ERROR the range pattern here has ambiguous interpretation + //~^^ HELP add parentheses to clarify the precedence + box (16..=20) => {} + _ => {} + } +} diff --git a/src/test/ui/range/range-inclusive-pattern-precedence2.stderr b/src/test/ui/range/range-inclusive-pattern-precedence2.stderr new file mode 100644 index 0000000000000000000000000000000000000000..7fbd972569e8dc81af4ed61aa9a15efa1931c396 --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence2.stderr @@ -0,0 +1,20 @@ +error: the range pattern here has ambiguous interpretation + --> $DIR/range-inclusive-pattern-precedence2.rs:13:13 + | +LL | box 10..=15 => {} + | ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` + +warning: `...` range patterns are deprecated + --> $DIR/range-inclusive-pattern-precedence2.rs:10:14 + | +LL | box 0...9 => {} + | ^^^ help: use `..=` for an inclusive range + | +note: the lint level is defined here + --> $DIR/range-inclusive-pattern-precedence2.rs:5:9 + | +LL | #![warn(ellipsis_inclusive_range_patterns)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error; 1 warning emitted + diff --git a/src/test/ui/resolve/resolve-conflict-import-vs-import.fixed b/src/test/ui/resolve/resolve-conflict-import-vs-import.fixed new file mode 100644 index 0000000000000000000000000000000000000000..e429513b51d3411f5bebebf59fb1edcf3d26af1a --- /dev/null +++ b/src/test/ui/resolve/resolve-conflict-import-vs-import.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +#[allow(unused_imports)] +use std::mem::transmute; + +//~^ ERROR the name `transmute` is defined multiple times + +fn main() { +} diff --git a/src/test/ui/resolve/resolve-conflict-import-vs-import.rs b/src/test/ui/resolve/resolve-conflict-import-vs-import.rs index 322f000040e17687e942859a74c90350f4922575..43853117af6999202a5cb1197a3cea52d24c882b 100644 --- a/src/test/ui/resolve/resolve-conflict-import-vs-import.rs +++ b/src/test/ui/resolve/resolve-conflict-import-vs-import.rs @@ -1,3 +1,6 @@ +// run-rustfix + +#[allow(unused_imports)] use std::mem::transmute; use std::mem::transmute; //~^ ERROR the name `transmute` is defined multiple times diff --git a/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr b/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr index 8df68ad3229edcaa21dd3e0ff12acbe2fa03764f..632be50f4c4bf0239e3a9daca7b361fff70d010a 100644 --- a/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr +++ b/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr @@ -1,5 +1,5 @@ error[E0252]: the name `transmute` is defined multiple times - --> $DIR/resolve-conflict-import-vs-import.rs:2:5 + --> $DIR/resolve-conflict-import-vs-import.rs:5:5 | LL | use std::mem::transmute; | ------------------- previous import of the value `transmute` here diff --git a/src/test/ui/resolve/token-error-correct-4.fixed b/src/test/ui/resolve/token-error-correct-4.fixed new file mode 100644 index 0000000000000000000000000000000000000000..064b9e74e24fd524ea203b9bbda4150ce99e48e1 --- /dev/null +++ b/src/test/ui/resolve/token-error-correct-4.fixed @@ -0,0 +1,10 @@ +// run-rustfix +// Test that we do some basic error correction in the tokeniser and apply suggestions. + +fn setsuna(_: ()) {} + +fn kazusa() {} + +fn main() { + setsuna(kazusa()); //~ ERROR: expected one of +} //~ ERROR: expected expression diff --git a/src/test/ui/resolve/token-error-correct-4.rs b/src/test/ui/resolve/token-error-correct-4.rs new file mode 100644 index 0000000000000000000000000000000000000000..5e31d71e7bf46dafb611a310262582938d1c7fac --- /dev/null +++ b/src/test/ui/resolve/token-error-correct-4.rs @@ -0,0 +1,10 @@ +// run-rustfix +// Test that we do some basic error correction in the tokeniser and apply suggestions. + +fn setsuna(_: ()) {} + +fn kazusa() {} + +fn main() { + setsuna(kazusa(); //~ ERROR: expected one of +} //~ ERROR: expected expression diff --git a/src/test/ui/resolve/token-error-correct-4.stderr b/src/test/ui/resolve/token-error-correct-4.stderr new file mode 100644 index 0000000000000000000000000000000000000000..64aff54ba731128370867ce82a5a947daa6064e2 --- /dev/null +++ b/src/test/ui/resolve/token-error-correct-4.stderr @@ -0,0 +1,16 @@ +error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;` + --> $DIR/token-error-correct-4.rs:9:21 + | +LL | setsuna(kazusa(); + | - ^ help: `)` may belong here + | | + | unclosed delimiter + +error: expected expression, found `)` + --> $DIR/token-error-correct-4.rs:10:1 + | +LL | } + | ^ expected expression + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/similar-tokens.fixed b/src/test/ui/similar-tokens.fixed new file mode 100644 index 0000000000000000000000000000000000000000..addba76ae3b51fd214b0e3a4a040340b8b0b8c62 --- /dev/null +++ b/src/test/ui/similar-tokens.fixed @@ -0,0 +1,13 @@ +// run-rustfix + +#![allow(unused_imports)] + +pub mod x { + pub struct A; + pub struct B; +} + +// `.` is similar to `,` so list parsing should continue to closing `}` +use x::{A, B}; //~ ERROR expected one of `,`, `::`, `as`, or `}`, found `.` + +fn main() {} diff --git a/src/test/ui/similar-tokens.rs b/src/test/ui/similar-tokens.rs index b42f3a313e1e7781b1d385b701f5132a619f7155..3d1bf5fe54ae1132fd2ef05ec9cd309670a4468e 100644 --- a/src/test/ui/similar-tokens.rs +++ b/src/test/ui/similar-tokens.rs @@ -1,4 +1,8 @@ -mod x { +// run-rustfix + +#![allow(unused_imports)] + +pub mod x { pub struct A; pub struct B; } diff --git a/src/test/ui/similar-tokens.stderr b/src/test/ui/similar-tokens.stderr index 35a2fe79d5e66e380eaf1f833ae1465308058d28..6a8d09ebae668083a8d2006ff3d6124982814509 100644 --- a/src/test/ui/similar-tokens.stderr +++ b/src/test/ui/similar-tokens.stderr @@ -1,5 +1,5 @@ error: expected one of `,`, `::`, `as`, or `}`, found `.` - --> $DIR/similar-tokens.rs:7:10 + --> $DIR/similar-tokens.rs:11:10 | LL | use x::{A. B}; | ^ diff --git a/src/test/ui/structs/struct-duplicate-comma.fixed b/src/test/ui/structs/struct-duplicate-comma.fixed new file mode 100644 index 0000000000000000000000000000000000000000..c804cf57abaaadb53e3d913ce5ad2a88520da28e --- /dev/null +++ b/src/test/ui/structs/struct-duplicate-comma.fixed @@ -0,0 +1,15 @@ +// run-rustfix +// Issue #50974 + +pub struct Foo { + pub a: u8, + pub b: u8 +} + +fn main() { + let _ = Foo { + a: 0, + //~^ ERROR expected identifier + b: 42 + }; +} diff --git a/src/test/ui/structs/struct-duplicate-comma.rs b/src/test/ui/structs/struct-duplicate-comma.rs index ff0d58abc3adaf966ac6bef48963def279b6d1c1..db2e7cb3d05e6fb6485c602c770eba6125c48306 100644 --- a/src/test/ui/structs/struct-duplicate-comma.rs +++ b/src/test/ui/structs/struct-duplicate-comma.rs @@ -1,12 +1,13 @@ +// run-rustfix // Issue #50974 -struct Foo { - a: u8, - b: u8 +pub struct Foo { + pub a: u8, + pub b: u8 } fn main() { - let bar = Foo { + let _ = Foo { a: 0,, //~^ ERROR expected identifier b: 42 diff --git a/src/test/ui/structs/struct-duplicate-comma.stderr b/src/test/ui/structs/struct-duplicate-comma.stderr index 2297fea63536396f09cce521b1fa054f804b11f9..834b3c5c17164c4136f05f054b6651c6073b7fe4 100644 --- a/src/test/ui/structs/struct-duplicate-comma.stderr +++ b/src/test/ui/structs/struct-duplicate-comma.stderr @@ -1,8 +1,8 @@ error: expected identifier, found `,` - --> $DIR/struct-duplicate-comma.rs:10:14 + --> $DIR/struct-duplicate-comma.rs:11:14 | -LL | let bar = Foo { - | --- while parsing this struct +LL | let _ = Foo { + | --- while parsing this struct LL | a: 0,, | ^ | | diff --git a/src/test/ui/structs/struct-missing-comma.fixed b/src/test/ui/structs/struct-missing-comma.fixed new file mode 100644 index 0000000000000000000000000000000000000000..a28179ba241681ae4ab2d54dc09f22d8fbcb8b80 --- /dev/null +++ b/src/test/ui/structs/struct-missing-comma.fixed @@ -0,0 +1,12 @@ +// Issue #50636 +// run-rustfix + +pub struct S { + pub foo: u32, //~ expected `,`, or `}`, found keyword `pub` + // ~^ HELP try adding a comma: ',' + pub bar: u32 +} + +fn main() { + let _ = S { foo: 5, bar: 6 }; +} diff --git a/src/test/ui/structs/struct-missing-comma.rs b/src/test/ui/structs/struct-missing-comma.rs index 4c3cac3369136a4854c089e38cd63044b7b240ef..b6d6c9b8f87628599e23223db499e53acb4ca25f 100644 --- a/src/test/ui/structs/struct-missing-comma.rs +++ b/src/test/ui/structs/struct-missing-comma.rs @@ -1,11 +1,12 @@ // Issue #50636 +// run-rustfix -struct S { - foo: u32 //~ expected `,`, or `}`, found `bar` +pub struct S { + pub foo: u32 //~ expected `,`, or `}`, found keyword `pub` // ~^ HELP try adding a comma: ',' - bar: u32 + pub bar: u32 } fn main() { - let s = S { foo: 5, bar: 6 }; + let _ = S { foo: 5, bar: 6 }; } diff --git a/src/test/ui/structs/struct-missing-comma.stderr b/src/test/ui/structs/struct-missing-comma.stderr index f5b79f54001e7670693570351b4719ce88d4ff62..eceec65e7634625a120d0bbae3ae7d5175a06390 100644 --- a/src/test/ui/structs/struct-missing-comma.stderr +++ b/src/test/ui/structs/struct-missing-comma.stderr @@ -1,8 +1,8 @@ -error: expected `,`, or `}`, found `bar` - --> $DIR/struct-missing-comma.rs:4:13 +error: expected `,`, or `}`, found keyword `pub` + --> $DIR/struct-missing-comma.rs:5:17 | -LL | foo: u32 - | ^ help: try adding a comma: `,` +LL | pub foo: u32 + | ^ help: try adding a comma: `,` error: aborting due to previous error diff --git a/src/test/ui/suggestions/struct-initializer-comma.fixed b/src/test/ui/suggestions/struct-initializer-comma.fixed new file mode 100644 index 0000000000000000000000000000000000000000..6a4ee39b16d86e8b08d3fadff41e0a8177938a21 --- /dev/null +++ b/src/test/ui/suggestions/struct-initializer-comma.fixed @@ -0,0 +1,15 @@ +// run-rustfix + +pub struct Foo { + pub first: bool, + pub second: u8, +} + +fn main() { + let _ = Foo { + //~^ ERROR missing field + first: true, + second: 25 + //~^ ERROR expected one of + }; +} diff --git a/src/test/ui/suggestions/struct-initializer-comma.rs b/src/test/ui/suggestions/struct-initializer-comma.rs index 613b976848f703807516042c5e512d39335dc720..c137f0594186d0608ed73094286d8c6d95cec58f 100644 --- a/src/test/ui/suggestions/struct-initializer-comma.rs +++ b/src/test/ui/suggestions/struct-initializer-comma.rs @@ -1,10 +1,12 @@ -struct Foo { - first: bool, - second: u8, +// run-rustfix + +pub struct Foo { + pub first: bool, + pub second: u8, } fn main() { - let a = Foo { + let _ = Foo { //~^ ERROR missing field first: true second: 25 diff --git a/src/test/ui/suggestions/struct-initializer-comma.stderr b/src/test/ui/suggestions/struct-initializer-comma.stderr index 731e8e10ab3ca016898bbaddcb4a1f19647ff41e..5eff43f32cda15e97945e53a754140c989249ced 100644 --- a/src/test/ui/suggestions/struct-initializer-comma.stderr +++ b/src/test/ui/suggestions/struct-initializer-comma.stderr @@ -1,7 +1,7 @@ error: expected one of `,`, `.`, `?`, `}`, or an operator, found `second` - --> $DIR/struct-initializer-comma.rs:10:9 + --> $DIR/struct-initializer-comma.rs:12:9 | -LL | let a = Foo { +LL | let _ = Foo { | --- while parsing this struct LL | LL | first: true @@ -13,9 +13,9 @@ LL | second: 25 | ^^^^^^ unexpected token error[E0063]: missing field `second` in initializer of `Foo` - --> $DIR/struct-initializer-comma.rs:7:13 + --> $DIR/struct-initializer-comma.rs:9:13 | -LL | let a = Foo { +LL | let _ = Foo { | ^^^ missing `second` error: aborting due to 2 previous errors diff --git a/src/test/ui/suggestions/suggest-remove-refs-1.fixed b/src/test/ui/suggestions/suggest-remove-refs-1.fixed new file mode 100644 index 0000000000000000000000000000000000000000..042e85b10ae21dfec6a764d946d12b8719356bdc --- /dev/null +++ b/src/test/ui/suggestions/suggest-remove-refs-1.fixed @@ -0,0 +1,10 @@ +// run-rustfix + +fn main() { + let v = vec![0, 1, 2, 3]; + + for (i, _) in v.iter().enumerate() { + //~^ ERROR `&std::iter::Enumerate>` is not an iterator + println!("{}", i); + } +} diff --git a/src/test/ui/suggestions/suggest-remove-refs-1.rs b/src/test/ui/suggestions/suggest-remove-refs-1.rs index 792cd6c5a0c3a8a35ab45e829889a941d441faaa..7bdf5dbf35884c82abe877bf3f36e19ebb327210 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-1.rs +++ b/src/test/ui/suggestions/suggest-remove-refs-1.rs @@ -1,7 +1,9 @@ +// run-rustfix + fn main() { let v = vec![0, 1, 2, 3]; - for (i, n) in &v.iter().enumerate() { + for (i, _) in &v.iter().enumerate() { //~^ ERROR `&std::iter::Enumerate>` is not an iterator println!("{}", i); } diff --git a/src/test/ui/suggestions/suggest-remove-refs-1.stderr b/src/test/ui/suggestions/suggest-remove-refs-1.stderr index fcaddd40d263baa866958068b51f2d38ac03ea32..5be0072fa33024120f86db58e96fcf4f3a3c2564 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-1.stderr +++ b/src/test/ui/suggestions/suggest-remove-refs-1.stderr @@ -1,7 +1,7 @@ error[E0277]: `&std::iter::Enumerate>` is not an iterator - --> $DIR/suggest-remove-refs-1.rs:4:19 + --> $DIR/suggest-remove-refs-1.rs:6:19 | -LL | for (i, n) in &v.iter().enumerate() { +LL | for (i, _) in &v.iter().enumerate() { | -^^^^^^^^^^^^^^^^^^^^ | | | `&std::iter::Enumerate>` is not an iterator diff --git a/src/test/ui/suggestions/suggest-remove-refs-2.fixed b/src/test/ui/suggestions/suggest-remove-refs-2.fixed new file mode 100644 index 0000000000000000000000000000000000000000..bdf47b0e87f131096e26bf2b7280970891e2a7c2 --- /dev/null +++ b/src/test/ui/suggestions/suggest-remove-refs-2.fixed @@ -0,0 +1,10 @@ +// run-rustfix + +fn main() { + let v = vec![0, 1, 2, 3]; + + for (i, _) in v.iter().enumerate() { + //~^ ERROR `&&&&&std::iter::Enumerate>` is not an iterator + println!("{}", i); + } +} diff --git a/src/test/ui/suggestions/suggest-remove-refs-2.rs b/src/test/ui/suggestions/suggest-remove-refs-2.rs index 52d940143b32726b8612c0765a7ff54899604af8..3ed56377e146c03e550b5f1c626eeff6c2d546dc 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-2.rs +++ b/src/test/ui/suggestions/suggest-remove-refs-2.rs @@ -1,7 +1,9 @@ +// run-rustfix + fn main() { let v = vec![0, 1, 2, 3]; - for (i, n) in & & & & &v.iter().enumerate() { + for (i, _) in & & & & &v.iter().enumerate() { //~^ ERROR `&&&&&std::iter::Enumerate>` is not an iterator println!("{}", i); } diff --git a/src/test/ui/suggestions/suggest-remove-refs-2.stderr b/src/test/ui/suggestions/suggest-remove-refs-2.stderr index fe1b0f1ea22ade6857055dd7d47b417cbe24facd..ff84a2ce377051b59f3fb06b10b5068f460934b8 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-2.stderr +++ b/src/test/ui/suggestions/suggest-remove-refs-2.stderr @@ -1,7 +1,7 @@ error[E0277]: `&&&&&std::iter::Enumerate>` is not an iterator - --> $DIR/suggest-remove-refs-2.rs:4:19 + --> $DIR/suggest-remove-refs-2.rs:6:19 | -LL | for (i, n) in & & & & &v.iter().enumerate() { +LL | for (i, _) in & & & & &v.iter().enumerate() { | ---------^^^^^^^^^^^^^^^^^^^^ | | | `&&&&&std::iter::Enumerate>` is not an iterator diff --git a/src/test/ui/suggestions/suggest-remove-refs-3.fixed b/src/test/ui/suggestions/suggest-remove-refs-3.fixed new file mode 100644 index 0000000000000000000000000000000000000000..e0ecafabf393eb833facca2966161858b3745c10 --- /dev/null +++ b/src/test/ui/suggestions/suggest-remove-refs-3.fixed @@ -0,0 +1,12 @@ +// run-rustfix + +fn main() { + let v = vec![0, 1, 2, 3]; + + for (i, _) in v + .iter() + .enumerate() { + //~^^^^ ERROR `&&&&&std::iter::Enumerate>` is not an + println!("{}", i); + } +} diff --git a/src/test/ui/suggestions/suggest-remove-refs-3.rs b/src/test/ui/suggestions/suggest-remove-refs-3.rs index 981924d3251df5dba952ccf08704868848296fe2..e13099e8c32465d0c569d61e7120262b86c3198c 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-3.rs +++ b/src/test/ui/suggestions/suggest-remove-refs-3.rs @@ -1,7 +1,9 @@ +// run-rustfix + fn main() { let v = vec![0, 1, 2, 3]; - for (i, n) in & & & + for (i, _) in & & & & &v .iter() .enumerate() { diff --git a/src/test/ui/suggestions/suggest-remove-refs-3.stderr b/src/test/ui/suggestions/suggest-remove-refs-3.stderr index a6c16e1817a54644d65eb2ef3a8b08c08ecb2bab..d2f7c72b0e474ff8d5656c50ad9735ba8cba29d8 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-3.stderr +++ b/src/test/ui/suggestions/suggest-remove-refs-3.stderr @@ -1,7 +1,7 @@ error[E0277]: `&&&&&std::iter::Enumerate>` is not an iterator - --> $DIR/suggest-remove-refs-3.rs:4:19 + --> $DIR/suggest-remove-refs-3.rs:6:19 | -LL | for (i, n) in & & & +LL | for (i, _) in & & & | ___________________^ | |___________________| | || diff --git a/src/test/ui/try-block/try-block-unused-delims.fixed b/src/test/ui/try-block/try-block-unused-delims.fixed new file mode 100644 index 0000000000000000000000000000000000000000..c8b03c2006840c4dc864c3785c88c2b3a633dbbf --- /dev/null +++ b/src/test/ui/try-block/try-block-unused-delims.fixed @@ -0,0 +1,29 @@ +// check-pass +// compile-flags: --edition 2018 +// run-rustfix + +#![feature(try_blocks)] +#![warn(unused_parens, unused_braces)] + +fn consume(_: Result) -> T { todo!() } + +fn main() { + consume(try {}); + //~^ WARN unnecessary parentheses + + consume( try {} ); + //~^ WARN unnecessary braces + + match try {} { + //~^ WARN unnecessary parentheses + Ok(()) | Err(()) => (), + } + + if let Err(()) = try {} {} + //~^ WARN unnecessary parentheses + + match try {} { + //~^ WARN unnecessary parentheses + Ok(()) | Err(()) => (), + } +} diff --git a/src/test/ui/try-block/try-block-unused-delims.rs b/src/test/ui/try-block/try-block-unused-delims.rs index 0b767eb2dad77de9c4dfbe5469dd63c104352a06..ce087fb351d63e4823ab88056bc47447ccb08d9b 100644 --- a/src/test/ui/try-block/try-block-unused-delims.rs +++ b/src/test/ui/try-block/try-block-unused-delims.rs @@ -1,5 +1,6 @@ // check-pass // compile-flags: --edition 2018 +// run-rustfix #![feature(try_blocks)] #![warn(unused_parens, unused_braces)] diff --git a/src/test/ui/try-block/try-block-unused-delims.stderr b/src/test/ui/try-block/try-block-unused-delims.stderr index 5c7602ee0ab1246c4322f5b1ffc16dfd2ee1f8c0..c5a2405462932dad56d491348e71c97f63c38e0e 100644 --- a/src/test/ui/try-block/try-block-unused-delims.stderr +++ b/src/test/ui/try-block/try-block-unused-delims.stderr @@ -1,41 +1,41 @@ warning: unnecessary parentheses around function argument - --> $DIR/try-block-unused-delims.rs:10:13 + --> $DIR/try-block-unused-delims.rs:11:13 | LL | consume((try {})); | ^^^^^^^^ help: remove these parentheses | note: the lint level is defined here - --> $DIR/try-block-unused-delims.rs:5:9 + --> $DIR/try-block-unused-delims.rs:6:9 | LL | #![warn(unused_parens, unused_braces)] | ^^^^^^^^^^^^^ warning: unnecessary braces around function argument - --> $DIR/try-block-unused-delims.rs:13:13 + --> $DIR/try-block-unused-delims.rs:14:13 | LL | consume({ try {} }); | ^^^^^^^^^^ help: remove these braces | note: the lint level is defined here - --> $DIR/try-block-unused-delims.rs:5:24 + --> $DIR/try-block-unused-delims.rs:6:24 | LL | #![warn(unused_parens, unused_braces)] | ^^^^^^^^^^^^^ warning: unnecessary parentheses around `match` scrutinee expression - --> $DIR/try-block-unused-delims.rs:16:11 + --> $DIR/try-block-unused-delims.rs:17:11 | LL | match (try {}) { | ^^^^^^^^ help: remove these parentheses warning: unnecessary parentheses around `let` scrutinee expression - --> $DIR/try-block-unused-delims.rs:21:22 + --> $DIR/try-block-unused-delims.rs:22:22 | LL | if let Err(()) = (try {}) {} | ^^^^^^^^ help: remove these parentheses warning: unnecessary parentheses around `match` scrutinee expression - --> $DIR/try-block-unused-delims.rs:24:11 + --> $DIR/try-block-unused-delims.rs:25:11 | LL | match (try {}) { | ^^^^^^^^ help: remove these parentheses diff --git a/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.fixed b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.fixed new file mode 100644 index 0000000000000000000000000000000000000000..7fdd618c2ecaedede78bc73c5f488b152ef986dc --- /dev/null +++ b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.fixed @@ -0,0 +1,59 @@ +// check-pass +// run-rustfix +// +// rust-lang/rust#73592: borrow_mut through Deref should work. +// +// Before #72280, when we see something like `&mut *rcvr.method()`, we +// incorrectly requires `rcvr` to be type-checked as a mut place. While this +// requirement is usually correct for smart pointers, it is overly restrictive +// for types like `Mutex` or `RefCell` which can produce a guard that +// implements `DerefMut` from `&self`. +// +// Making it more confusing, because we use Deref as the fallback when DerefMut +// is implemented, we won't see an issue when the smart pointer does not +// implement `DerefMut`. It only causes an issue when `rcvr` is obtained via a +// type that implements both `Deref` or `DerefMut`. +// +// This bug is only discovered in #73592 after it is already fixed as a side-effect +// of a refactoring made in #72280. + +#![warn(unused_mut)] + +use std::pin::Pin; +use std::cell::RefCell; + +struct S(RefCell<()>); + +fn test_pin(s: Pin<&S>) { + // This works before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_pin_mut(s: Pin<&mut S>) { + // This should compile but didn't before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_vec(s: &Vec>) { + // This should compile but didn't before #72280. + let _ = &mut *s[0].borrow_mut(); +} + +fn test_mut_pin(s: Pin<&S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn test_mut_pin_mut(s: Pin<&mut S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn main() { + let mut s = S(RefCell::new(())); + test_pin(Pin::new(&s)); + test_pin_mut(Pin::new(&mut s)); + test_mut_pin(Pin::new(&s)); + test_mut_pin_mut(Pin::new(&mut s)); + test_vec(&vec![s.0]); +} diff --git a/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.rs b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.rs index 0cf77da559470a0aab29fb00ec2119dea1dd46b2..3b399e629d3419d51a2a8f69c9353318eacabc3c 100644 --- a/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.rs +++ b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.rs @@ -1,4 +1,5 @@ // check-pass +// run-rustfix // // rust-lang/rust#73592: borrow_mut through Deref should work. // diff --git a/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.stderr b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.stderr index 51303adc9e53387e47cde762d6699870e1d9b6d5..5f5f672c3843a1de8cedcc3b94a774cd138329ba 100644 --- a/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.stderr +++ b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.stderr @@ -1,5 +1,5 @@ warning: variable does not need to be mutable - --> $DIR/issue-73592-borrow_mut-through-deref.rs:41:17 + --> $DIR/issue-73592-borrow_mut-through-deref.rs:42:17 | LL | fn test_mut_pin(mut s: Pin<&S>) { | ----^ @@ -7,13 +7,13 @@ LL | fn test_mut_pin(mut s: Pin<&S>) { | help: remove this `mut` | note: the lint level is defined here - --> $DIR/issue-73592-borrow_mut-through-deref.rs:19:9 + --> $DIR/issue-73592-borrow_mut-through-deref.rs:20:9 | LL | #![warn(unused_mut)] | ^^^^^^^^^^ warning: variable does not need to be mutable - --> $DIR/issue-73592-borrow_mut-through-deref.rs:46:21 + --> $DIR/issue-73592-borrow_mut-through-deref.rs:47:21 | LL | fn test_mut_pin_mut(mut s: Pin<&mut S>) { | ----^ diff --git a/src/test/ui/unused/unused-mut-warning-captured-var.fixed b/src/test/ui/unused/unused-mut-warning-captured-var.fixed new file mode 100644 index 0000000000000000000000000000000000000000..b67b2a7259be0a29921a8c04d0e4d473fd7bd7e9 --- /dev/null +++ b/src/test/ui/unused/unused-mut-warning-captured-var.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +#![forbid(unused_mut)] + +fn main() { + let x = 1; + //~^ ERROR: variable does not need to be mutable + move|| { println!("{}", x); }; +} diff --git a/src/test/ui/unused/unused-mut-warning-captured-var.rs b/src/test/ui/unused/unused-mut-warning-captured-var.rs index c945969cf63255c27413d75b69ff3a96d20ed3a5..8726c4f173fa3a31f7e1d3a850c855289b574166 100644 --- a/src/test/ui/unused/unused-mut-warning-captured-var.rs +++ b/src/test/ui/unused/unused-mut-warning-captured-var.rs @@ -1,3 +1,5 @@ +// run-rustfix + #![forbid(unused_mut)] fn main() { diff --git a/src/test/ui/unused/unused-mut-warning-captured-var.stderr b/src/test/ui/unused/unused-mut-warning-captured-var.stderr index 39d470e02a80f6d4342e06ac4bcb4bedffaed704..20aeedcc24125ecf7981fb75b2f1bb14c28a9aa4 100644 --- a/src/test/ui/unused/unused-mut-warning-captured-var.stderr +++ b/src/test/ui/unused/unused-mut-warning-captured-var.stderr @@ -1,5 +1,5 @@ error: variable does not need to be mutable - --> $DIR/unused-mut-warning-captured-var.rs:4:9 + --> $DIR/unused-mut-warning-captured-var.rs:6:9 | LL | let mut x = 1; | ----^ @@ -7,7 +7,7 @@ LL | let mut x = 1; | help: remove this `mut` | note: the lint level is defined here - --> $DIR/unused-mut-warning-captured-var.rs:1:11 + --> $DIR/unused-mut-warning-captured-var.rs:3:11 | LL | #![forbid(unused_mut)] | ^^^^^^^^^^ diff --git a/src/tools/build-manifest/README.md b/src/tools/build-manifest/README.md index 6834f56efe7dbb7f26841a64a6015be884bcd450..a80f36d49699801d46581277d67e13d8f6473be6 100644 --- a/src/tools/build-manifest/README.md +++ b/src/tools/build-manifest/README.md @@ -22,7 +22,7 @@ Then, you can generate the manifest and all the packages from `path/to/dist` to ``` $ BUILD_MANIFEST_DISABLE_SIGNING=1 cargo +nightly run \ path/to/dist path/to/output 1970-01-01 \ - nightly nightly nightly nightly nightly nightly nightly \ + nightly nightly nightly nightly nightly nightly nightly nightly \ http://example.com ``` diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 614e25589601e8664f613640ed93100b2663bf68..5c50587ea973d7bcf89a05b5867da0f195d33ec7 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -158,6 +158,8 @@ static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"]; +static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview", "rust-analyzer-preview"]; + #[derive(Serialize)] #[serde(rename_all = "kebab-case")] struct Manifest { @@ -222,6 +224,7 @@ struct Builder { rust_release: String, cargo_release: String, rls_release: String, + rust_analyzer_release: String, clippy_release: String, rustfmt_release: String, llvm_tools_release: String, @@ -237,6 +240,7 @@ struct Builder { rust_version: Option, cargo_version: Option, rls_version: Option, + rust_analyzer_version: Option, clippy_version: Option, rustfmt_version: Option, llvm_tools_version: Option, @@ -245,6 +249,7 @@ struct Builder { rust_git_commit_hash: Option, cargo_git_commit_hash: Option, rls_git_commit_hash: Option, + rust_analyzer_git_commit_hash: Option, clippy_git_commit_hash: Option, rustfmt_git_commit_hash: Option, llvm_tools_git_commit_hash: Option, @@ -274,6 +279,7 @@ fn main() { let s3_address = args.next().unwrap(); let cargo_release = args.next().unwrap(); let rls_release = args.next().unwrap(); + let rust_analyzer_release = args.next().unwrap(); let clippy_release = args.next().unwrap(); let miri_release = args.next().unwrap(); let rustfmt_release = args.next().unwrap(); @@ -290,6 +296,7 @@ fn main() { rust_release, cargo_release, rls_release, + rust_analyzer_release, clippy_release, rustfmt_release, llvm_tools_release, @@ -305,6 +312,7 @@ fn main() { rust_version: None, cargo_version: None, rls_version: None, + rust_analyzer_version: None, clippy_version: None, rustfmt_version: None, llvm_tools_version: None, @@ -313,6 +321,7 @@ fn main() { rust_git_commit_hash: None, cargo_git_commit_hash: None, rls_git_commit_hash: None, + rust_analyzer_git_commit_hash: None, clippy_git_commit_hash: None, rustfmt_git_commit_hash: None, llvm_tools_git_commit_hash: None, @@ -327,6 +336,7 @@ enum PkgType { RustSrc, Cargo, Rls, + RustAnalyzer, Clippy, Rustfmt, LlvmTools, @@ -341,6 +351,7 @@ fn from_component(component: &str) -> Self { "rust-src" => RustSrc, "cargo" => Cargo, "rls" | "rls-preview" => Rls, + "rust-analyzer" | "rust-analyzer-preview" => RustAnalyzer, "clippy" | "clippy-preview" => Clippy, "rustfmt" | "rustfmt-preview" => Rustfmt, "llvm-tools" | "llvm-tools-preview" => LlvmTools, @@ -355,6 +366,7 @@ fn build(&mut self) { self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu"); self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu"); self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu"); + self.rust_analyzer_version = self.version("rust-analyzer", "x86_64-unknown-linux-gnu"); self.clippy_version = self.version("clippy", "x86_64-unknown-linux-gnu"); self.rustfmt_version = self.version("rustfmt", "x86_64-unknown-linux-gnu"); self.llvm_tools_version = self.version("llvm-tools", "x86_64-unknown-linux-gnu"); @@ -363,6 +375,8 @@ fn build(&mut self) { self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu"); self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu"); self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu"); + self.rust_analyzer_git_commit_hash = + self.git_commit_hash("rust-analyzer", "x86_64-unknown-linux-gnu"); self.clippy_git_commit_hash = self.git_commit_hash("clippy", "x86_64-unknown-linux-gnu"); self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu"); self.llvm_tools_git_commit_hash = @@ -436,6 +450,7 @@ fn add_packages_to(&mut self, manifest: &mut Manifest) { package("rust-docs", DOCS_TARGETS); package("rust-src", &["*"]); package("rls-preview", HOSTS); + package("rust-analyzer-preview", HOSTS); package("clippy-preview", HOSTS); package("miri-preview", HOSTS); package("rustfmt-preview", HOSTS); @@ -469,6 +484,7 @@ fn add_profiles_to(&mut self, manifest: &mut Manifest) { "rustfmt-preview", "clippy-preview", "rls-preview", + "rust-analyzer-preview", "rust-src", "llvm-tools-preview", "rust-analysis", @@ -543,6 +559,7 @@ fn target_host_combination(&mut self, host: &str, manifest: &Manifest) -> Option host_component("clippy-preview"), host_component("miri-preview"), host_component("rls-preview"), + host_component("rust-analyzer-preview"), host_component("rustfmt-preview"), host_component("llvm-tools-preview"), host_component("rust-analysis"), @@ -612,8 +629,8 @@ fn package(&mut self, pkgname: &str, dst: &mut BTreeMap, target .map(|version| (version, true)) .unwrap_or_default(); // `is_present` defaults to `false` here. - // Miri is nightly-only; never ship it for other trains. - if pkgname == "miri-preview" && self.rust_release != "nightly" { + // Never ship nightly-only components for other trains. + if self.rust_release != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(&pkgname) { is_present = false; // Pretend the component is entirely missing. } @@ -671,6 +688,9 @@ fn filename(&self, component: &str, target: &str) -> String { RustSrc => format!("rust-src-{}.tar.gz", self.rust_release), Cargo => format!("cargo-{}-{}.tar.gz", self.cargo_release, target), Rls => format!("rls-{}-{}.tar.gz", self.rls_release, target), + RustAnalyzer => { + format!("rust-analyzer-{}-{}.tar.gz", self.rust_analyzer_release, target) + } Clippy => format!("clippy-{}-{}.tar.gz", self.clippy_release, target), Rustfmt => format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target), LlvmTools => format!("llvm-tools-{}-{}.tar.gz", self.llvm_tools_release, target), @@ -684,6 +704,7 @@ fn cached_version(&self, component: &str) -> &Option { match PkgType::from_component(component) { Cargo => &self.cargo_version, Rls => &self.rls_version, + RustAnalyzer => &self.rust_analyzer_version, Clippy => &self.clippy_version, Rustfmt => &self.rustfmt_version, LlvmTools => &self.llvm_tools_version, @@ -697,6 +718,7 @@ fn cached_git_commit_hash(&self, component: &str) -> &Option { match PkgType::from_component(component) { Cargo => &self.cargo_git_commit_hash, Rls => &self.rls_git_commit_hash, + RustAnalyzer => &self.rust_analyzer_git_commit_hash, Clippy => &self.clippy_git_commit_hash, Rustfmt => &self.rustfmt_git_commit_hash, LlvmTools => &self.llvm_tools_git_commit_hash, diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs index d40cdfcca9f66f0da9476166913d50b0dc047fdc..b10181062ff10042703b31c373d875ad64658841 100644 --- a/src/tools/clippy/clippy_lints/src/escape.rs +++ b/src/tools/clippy/clippy_lints/src/escape.rs @@ -150,7 +150,7 @@ fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>) { return; } - if is_non_trait_box(cmt.place.ty) && !self.is_large_box(cmt.place.ty) { + if is_non_trait_box(cmt.place.ty()) && !self.is_large_box(cmt.place.ty()) { self.set.insert(cmt.hir_id); } return;