From c0056c04f61a051e26dae2631c59637da815abbb Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 16:59:05 +0200 Subject: [PATCH 1/8] legacy_ctor_visibility -> error --- .../src/lints/listing/deny-by-default.md | 35 ------------------- src/librustc/lint/builtin.rs | 11 ------ src/librustc_lint/lib.rs | 2 ++ src/librustc_resolve/late.rs | 20 +---------- src/test/ui/privacy/legacy-ctor-visibility.rs | 7 +--- .../ui/privacy/legacy-ctor-visibility.stderr | 17 ++++----- 6 files changed, 13 insertions(+), 79 deletions(-) diff --git a/src/doc/rustc/src/lints/listing/deny-by-default.md b/src/doc/rustc/src/lints/listing/deny-by-default.md index 5688e90ada129..540543f98f3a0 100644 --- a/src/doc/rustc/src/lints/listing/deny-by-default.md +++ b/src/doc/rustc/src/lints/listing/deny-by-default.md @@ -45,41 +45,6 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type` = note: for more information, see issue #36887 ``` -## legacy-constructor-visibility - -[RFC 1506](https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md) modified some -visibility rules, and changed the visibility of struct constructors. Some -example code that triggers this lint: - -```rust,ignore -mod m { - pub struct S(u8); - - fn f() { - // this is trying to use S from the 'use' line, but because the `u8` is - // not pub, it is private - ::S; - } -} - -use m::S; -``` - -This will produce: - -```text -error: private struct constructors are not usable through re-exports in outer modules - --> src/main.rs:5:9 - | -5 | ::S; - | ^^^ - | - = note: `#[deny(legacy_constructor_visibility)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #39207 -``` - - ## legacy-directory-ownership The legacy_directory_ownership warning is issued when diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 65777fe78db39..4dd45f27aca4c 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -218,16 +218,6 @@ declare_lint! { }; } -declare_lint! { - pub LEGACY_CONSTRUCTOR_VISIBILITY, - Deny, - "detects use of struct constructors that would be invisible with new visibility rules", - @future_incompatible = FutureIncompatibleInfo { - reference: "issue #39207 ", - edition: None, - }; -} - declare_lint! { pub MISSING_FRAGMENT_SPECIFIER, Deny, @@ -560,7 +550,6 @@ declare_lint_pass! { SAFE_PACKED_BORROWS, PATTERNS_IN_FNS_WITHOUT_BODY, LEGACY_DIRECTORY_OWNERSHIP, - LEGACY_CONSTRUCTOR_VISIBILITY, MISSING_FRAGMENT_SPECIFIER, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, LATE_BOUND_LIFETIME_ARGUMENTS, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index b1beef04c5929..4636a3d65b7bc 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -334,6 +334,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) { "converted into hard error, see https://github.com/rust-lang/rust/issues/57742"); store.register_removed("incoherent_fundamental_impls", "converted into hard error, see https://github.com/rust-lang/rust/issues/46205"); + store.register_removed("legacy_constructor_visibility", + "converted into hard error, see https://github.com/rust-lang/rust/issues/39207"); } fn register_internals(store: &mut lint::LintStore) { diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 58af4b817d267..9c8425975119d 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -1539,25 +1539,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err { partial_res } else { - // Add a temporary hack to smooth the transition to new struct ctor - // visibility rules. See #38932 for more details. - let mut res = None; - if let Res::Def(DefKind::Struct, def_id) = partial_res.base_res() { - if let Some((ctor_res, ctor_vis)) - = self.r.struct_constructors.get(&def_id).cloned() { - if is_expected(ctor_res) && - self.r.is_accessible_from(ctor_vis, self.parent_scope.module) { - let lint = lint::builtin::LEGACY_CONSTRUCTOR_VISIBILITY; - self.r.lint_buffer.buffer_lint(lint, id, span, - "private struct constructors are not usable through \ - re-exports in outer modules", - ); - res = Some(PartialRes::new(ctor_res)); - } - } - } - - res.unwrap_or_else(|| report_errors(self, Some(partial_res.base_res()))) + report_errors(self, Some(partial_res.base_res())) } } Some(partial_res) if source.defer_to_typeck() => { diff --git a/src/test/ui/privacy/legacy-ctor-visibility.rs b/src/test/ui/privacy/legacy-ctor-visibility.rs index 7db4be729e8fa..5732b6446fea8 100644 --- a/src/test/ui/privacy/legacy-ctor-visibility.rs +++ b/src/test/ui/privacy/legacy-ctor-visibility.rs @@ -1,7 +1,3 @@ -// ignore-tidy-linelength - -#![allow(unused)] - use m::S; mod m { @@ -11,8 +7,7 @@ mod m { use S; fn f() { S(10); - //~^ ERROR private struct constructors are not usable through re-exports in outer modules - //~| WARN this was previously accepted + //~^ ERROR expected function, tuple struct or tuple variant, found struct `S` } } } diff --git a/src/test/ui/privacy/legacy-ctor-visibility.stderr b/src/test/ui/privacy/legacy-ctor-visibility.stderr index 69b6e08befc67..74a1f1ceeffb4 100644 --- a/src/test/ui/privacy/legacy-ctor-visibility.stderr +++ b/src/test/ui/privacy/legacy-ctor-visibility.stderr @@ -1,12 +1,13 @@ -error: private struct constructors are not usable through re-exports in outer modules - --> $DIR/legacy-ctor-visibility.rs:13:13 +error[E0423]: expected function, tuple struct or tuple variant, found struct `S` + --> $DIR/legacy-ctor-visibility.rs:9:13 | -LL | S(10); - | ^ - | - = note: `#[deny(legacy_constructor_visibility)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #39207 +LL | / fn f() { +LL | | S(10); + | | ^ help: a function with a similar name exists: `f` +LL | | +LL | | } + | |_________- similarly named function `f` defined here error: aborting due to previous error +For more information about this error, try `rustc --explain E0423`. From 79b35e90f1cbfa21b6a39354cf7d8e8acfa8b0e1 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 17:42:17 +0200 Subject: [PATCH 2/8] legacy_directory_ownership -> error --- .../src/lints/listing/deny-by-default.md | 12 --------- src/librustc/lint/builtin.rs | 12 --------- src/librustc_lint/lib.rs | 2 ++ src/librustc_passes/ast_validation.rs | 5 ---- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser/module.rs | 26 ++++--------------- src/libsyntax_expand/expand.rs | 2 +- src/libsyntax_pos/symbol.rs | 1 - 8 files changed, 9 insertions(+), 53 deletions(-) diff --git a/src/doc/rustc/src/lints/listing/deny-by-default.md b/src/doc/rustc/src/lints/listing/deny-by-default.md index 540543f98f3a0..f175a881fefc1 100644 --- a/src/doc/rustc/src/lints/listing/deny-by-default.md +++ b/src/doc/rustc/src/lints/listing/deny-by-default.md @@ -45,18 +45,6 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type` = note: for more information, see issue #36887 ``` -## legacy-directory-ownership - -The legacy_directory_ownership warning is issued when - -* There is a non-inline module with a `#[path]` attribute (e.g. `#[path = "foo.rs"] mod bar;`), -* The module's file ("foo.rs" in the above example) is not named "mod.rs", and -* The module's file contains a non-inline child module without a `#[path]` attribute. - -The warning can be fixed by renaming the parent module to "mod.rs" and moving -it into its own directory if appropriate. - - ## missing-fragment-specifier The missing_fragment_specifier warning is issued when an unused pattern in a diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 4dd45f27aca4c..9301dac32cd2e 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -207,17 +207,6 @@ declare_lint! { }; } -declare_lint! { - pub LEGACY_DIRECTORY_OWNERSHIP, - Deny, - "non-inline, non-`#[path]` modules (e.g., `mod foo;`) were erroneously allowed in some files \ - not named `mod.rs`", - @future_incompatible = FutureIncompatibleInfo { - reference: "issue #37872 ", - edition: None, - }; -} - declare_lint! { pub MISSING_FRAGMENT_SPECIFIER, Deny, @@ -549,7 +538,6 @@ declare_lint_pass! { SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, PATTERNS_IN_FNS_WITHOUT_BODY, - LEGACY_DIRECTORY_OWNERSHIP, MISSING_FRAGMENT_SPECIFIER, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, LATE_BOUND_LIFETIME_ARGUMENTS, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 4636a3d65b7bc..1dcd61896c38d 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -336,6 +336,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) { "converted into hard error, see https://github.com/rust-lang/rust/issues/46205"); store.register_removed("legacy_constructor_visibility", "converted into hard error, see https://github.com/rust-lang/rust/issues/39207"); + store.register_removed("legacy_disrectory_ownership", + "converted into hard error, see https://github.com/rust-lang/rust/issues/37872"); } fn register_internals(store: &mut lint::LintStore) { diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index e625334040e0a..e046f6c2a07b8 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -654,11 +654,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ItemKind::Mod(_) => { // Ensure that `path` attributes on modules are recorded as used (cf. issue #35584). attr::first_attr_value_str_by_name(&item.attrs, sym::path); - if attr::contains_name(&item.attrs, sym::warn_directory_ownership) { - let lint = lint::builtin::LEGACY_DIRECTORY_OWNERSHIP; - let msg = "cannot declare a new module at this location"; - self.lint_buffer.buffer_lint(lint, item.id, item.span, msg); - } } ItemKind::Union(ref vdata, _) => { if let VariantData::Tuple(..) | VariantData::Unit(..) = vdata { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 6d8ecdf805b01..59f4a4d22d671 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -51,7 +51,7 @@ pub enum DirectoryOwnership { relative: Option, }, UnownedViaBlock, - UnownedViaMod(bool /* legacy warnings? */), + UnownedViaMod, } // A bunch of utility functions of the form `parse__from_` diff --git a/src/libsyntax/parse/parser/module.rs b/src/libsyntax/parse/parser/module.rs index 242a17659a06b..958cdae9492f3 100644 --- a/src/libsyntax/parse/parser/module.rs +++ b/src/libsyntax/parse/parser/module.rs @@ -21,7 +21,6 @@ pub(super) struct ModulePath { pub(super) struct ModulePathSuccess { pub path: PathBuf, pub directory_ownership: DirectoryOwnership, - warn: bool, } impl<'a> Parser<'a> { @@ -55,17 +54,10 @@ impl<'a> Parser<'a> { if self.eat(&token::Semi) { if in_cfg && self.recurse_into_file_modules { // This mod is in an external file. Let's go get it! - let ModulePathSuccess { path, directory_ownership, warn } = + let ModulePathSuccess { path, directory_ownership } = self.submod_path(id, &outer_attrs, id_span)?; - let (module, mut attrs) = + let (module, attrs) = self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?; - // Record that we fetched the mod from an external file. - if warn { - let attr = attr::mk_attr_outer( - attr::mk_word_item(Ident::with_dummy_span(sym::warn_directory_ownership))); - attr::mark_known(&attr); - attrs.push(attr); - } Ok((id, ItemKind::Mod(module), Some(attrs))) } else { let placeholder = ast::Mod { @@ -136,17 +128,16 @@ impl<'a> Parser<'a> { // `#[path]` included and contains a `mod foo;` declaration. // If you encounter this, it's your own darn fault :P Some(_) => DirectoryOwnership::Owned { relative: None }, - _ => DirectoryOwnership::UnownedViaMod(true), + _ => DirectoryOwnership::UnownedViaMod, }, path, - warn: false, }); } let relative = match self.directory.ownership { DirectoryOwnership::Owned { relative } => relative, DirectoryOwnership::UnownedViaBlock | - DirectoryOwnership::UnownedViaMod(_) => None, + DirectoryOwnership::UnownedViaMod => None, }; let paths = Parser::default_submod_path( id, relative, &self.directory.path, self.sess.source_map()); @@ -167,12 +158,7 @@ impl<'a> Parser<'a> { } Err(err) } - DirectoryOwnership::UnownedViaMod(warn) => { - if warn { - if let Ok(result) = paths.result { - return Ok(ModulePathSuccess { warn: true, ..result }); - } - } + DirectoryOwnership::UnownedViaMod => { let mut err = self.diagnostic().struct_span_err(id_sp, "cannot declare a new module at this location"); if !id_sp.is_dummy() { @@ -250,14 +236,12 @@ impl<'a> Parser<'a> { directory_ownership: DirectoryOwnership::Owned { relative: Some(id), }, - warn: false, }), (false, true) => Ok(ModulePathSuccess { path: secondary_path, directory_ownership: DirectoryOwnership::Owned { relative: None, }, - warn: false, }), (false, false) => Err(Error::FileNotFoundForModule { mod_name: mod_name.clone(), diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index da70fdbb0f308..8c82e59e528e5 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -1300,7 +1300,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { Some(_) => DirectoryOwnership::Owned { relative: Some(item.ident), }, - None => DirectoryOwnership::UnownedViaMod(false), + None => DirectoryOwnership::UnownedViaMod, }; path.pop(); module.directory = path; diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 3f7b3e5b3d82a..d834a59b48682 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -734,7 +734,6 @@ symbols! { visible_private_types, volatile, warn, - warn_directory_ownership, wasm_import_module, wasm_target_feature, while_let, From 98d2c510dd121d31061ae95b41a5afb3386d17e3 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 19:34:21 +0200 Subject: [PATCH 3/8] safe_extern_static -> error --- .../src/lints/listing/deny-by-default.md | 5 --- src/librustc/lint/builtin.rs | 11 ----- src/librustc/mir/mod.rs | 1 - src/librustc_lint/lib.rs | 2 + src/librustc_mir/transform/check_unsafety.rs | 43 +++++++------------ src/test/ui/issues/issue-14227.rs | 5 +-- src/test/ui/issues/issue-14227.stderr | 10 +++-- src/test/ui/issues/issue-16538.rs | 3 +- src/test/ui/issues/issue-16538.stderr | 16 +++++-- src/test/ui/issues/issue-28324.rs | 5 +-- src/test/ui/issues/issue-28324.stderr | 10 +++-- src/test/ui/safe-extern-statics.rs | 6 --- src/test/ui/safe-extern-statics.stderr | 34 ++++++--------- 13 files changed, 57 insertions(+), 94 deletions(-) diff --git a/src/doc/rustc/src/lints/listing/deny-by-default.md b/src/doc/rustc/src/lints/listing/deny-by-default.md index f175a881fefc1..b349c68359cdb 100644 --- a/src/doc/rustc/src/lints/listing/deny-by-default.md +++ b/src/doc/rustc/src/lints/listing/deny-by-default.md @@ -151,11 +151,6 @@ To fix it, remove the `()`s. This lint detects a specific situation of re-exporting a private `extern crate`; -## safe-extern-statics - -In older versions of Rust, there was a soundness issue where `extern static`s were allowed -to be accessed in safe code. This lint now catches and denies this kind of code. - ## unknown-crate-types This lint detects an unknown crate type found in a `#[crate_type]` directive. Some diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 9301dac32cd2e..c1957df2e62dd 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -177,16 +177,6 @@ declare_lint! { "lints that have been renamed or removed" } -declare_lint! { - pub SAFE_EXTERN_STATICS, - Deny, - "safe access to extern statics was erroneously allowed", - @future_incompatible = FutureIncompatibleInfo { - reference: "issue #36247 ", - edition: None, - }; -} - declare_lint! { pub SAFE_PACKED_BORROWS, Warn, @@ -535,7 +525,6 @@ declare_lint_pass! { INVALID_TYPE_PARAM_DEFAULT, CONST_ERR, RENAMED_AND_REMOVED_LINTS, - SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, PATTERNS_IN_FNS_WITHOUT_BODY, MISSING_FRAGMENT_SPECIFIER, diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index f7e0d0131dea2..2eaf05beb2e9f 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2701,7 +2701,6 @@ pub enum UnsafetyViolationKind { General, /// Permitted both in `const fn`s and regular `fn`s. GeneralAndConstFn, - ExternStatic(hir::HirId), BorrowPacked(hir::HirId), } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 1dcd61896c38d..5c10399d7dbae 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -338,6 +338,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) { "converted into hard error, see https://github.com/rust-lang/rust/issues/39207"); store.register_removed("legacy_disrectory_ownership", "converted into hard error, see https://github.com/rust-lang/rust/issues/37872"); + store.register_removed("safe_extern_statics", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36247"); } fn register_internals(store: &mut lint::LintStore) { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 7d5507168587b..9dc4fdf53083f 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -8,7 +8,7 @@ use rustc::ty::cast::CastTy; use rustc::hir; use rustc::hir::Node; use rustc::hir::def_id::DefId; -use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSAFE}; +use rustc::lint::builtin::{SAFE_PACKED_BORROWS, UNUSED_UNSAFE}; use rustc::mir::*; use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext}; @@ -208,23 +208,20 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { } PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }) => { if self.tcx.is_mutable_static(def_id) { - self.require_unsafe("use of mutable static", + self.require_unsafe( + "use of mutable static", "mutable statics can be mutated by multiple threads: aliasing \ - violations or data races will cause undefined behavior", - UnsafetyViolationKind::General); + violations or data races will cause undefined behavior", + UnsafetyViolationKind::General, + ); } else if self.tcx.is_foreign_item(def_id) { - let source_info = self.source_info; - let lint_root = - self.source_scope_local_data[source_info.scope].lint_root; - self.register_violations(&[UnsafetyViolation { - source_info, - description: Symbol::intern("use of extern static"), - details: Symbol::intern( - "extern statics are not controlled by the Rust type system: \ - invalid data, aliasing violations or data races will cause \ - undefined behavior"), - kind: UnsafetyViolationKind::ExternStatic(lint_root) - }], &[]); + self.require_unsafe( + "use of extern static", + "extern statics are not controlled by the Rust type system: \ + invalid data, aliasing violations or data races will cause \ + undefined behavior", + UnsafetyViolationKind::General, + ); } } } @@ -351,8 +348,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { match violation.kind { UnsafetyViolationKind::GeneralAndConstFn | UnsafetyViolationKind::General => {}, - UnsafetyViolationKind::BorrowPacked(_) | - UnsafetyViolationKind::ExternStatic(_) => if self.min_const_fn { + UnsafetyViolationKind::BorrowPacked(_) => if self.min_const_fn { // const fns don't need to be backwards compatible and can // emit these violations as a hard error instead of a backwards // compat lint @@ -380,8 +376,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { UnsafetyViolationKind::GeneralAndConstFn => {}, // these things are forbidden in const fns UnsafetyViolationKind::General | - UnsafetyViolationKind::BorrowPacked(_) | - UnsafetyViolationKind::ExternStatic(_) => { + UnsafetyViolationKind::BorrowPacked(_) => { let mut violation = violation.clone(); // const fns don't need to be backwards compatible and can // emit these violations as a hard error instead of a backwards @@ -646,14 +641,6 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { .note(&details.as_str()) .emit(); } - UnsafetyViolationKind::ExternStatic(lint_hir_id) => { - tcx.lint_node_note(SAFE_EXTERN_STATICS, - lint_hir_id, - source_info.span, - &format!("{} is unsafe and requires unsafe function or block \ - (error E0133)", description), - &details.as_str()); - } UnsafetyViolationKind::BorrowPacked(lint_hir_id) => { if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) { tcx.unsafe_derive_on_repr_packed(impl_def_id); diff --git a/src/test/ui/issues/issue-14227.rs b/src/test/ui/issues/issue-14227.rs index 5de3867f95c22..d80eefc41bf53 100644 --- a/src/test/ui/issues/issue-14227.rs +++ b/src/test/ui/issues/issue-14227.rs @@ -1,10 +1,7 @@ -#![allow(safe_extern_statics, warnings)] - extern { pub static symbol: u32; } static CRASH: u32 = symbol; -//~^ ERROR could not evaluate static initializer -//~| tried to read from foreign (extern) static +//~^ ERROR use of extern static is unsafe and requires fn main() {} diff --git a/src/test/ui/issues/issue-14227.stderr b/src/test/ui/issues/issue-14227.stderr index 88e99e213bf74..f9cdbe452df9c 100644 --- a/src/test/ui/issues/issue-14227.stderr +++ b/src/test/ui/issues/issue-14227.stderr @@ -1,9 +1,11 @@ -error[E0080]: could not evaluate static initializer - --> $DIR/issue-14227.rs:6:21 +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-14227.rs:4:21 | LL | static CRASH: u32 = symbol; - | ^^^^^^ tried to read from foreign (extern) static + | ^^^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior error: aborting due to previous error -For more information about this error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-16538.rs b/src/test/ui/issues/issue-16538.rs index a990c078a7986..54d9a732912c7 100644 --- a/src/test/ui/issues/issue-16538.rs +++ b/src/test/ui/issues/issue-16538.rs @@ -1,5 +1,3 @@ -#![allow(safe_extern_statics)] - mod Y { pub type X = usize; extern { @@ -13,5 +11,6 @@ mod Y { static foo: *const Y::X = Y::foo(Y::x as *const Y::X); //~^ ERROR `*const usize` cannot be shared between threads safely [E0277] //~| ERROR E0015 +//~| ERROR use of extern static is unsafe and requires fn main() {} diff --git a/src/test/ui/issues/issue-16538.stderr b/src/test/ui/issues/issue-16538.stderr index 2d8b5bf2f6fb8..5e1f95a989ee0 100644 --- a/src/test/ui/issues/issue-16538.stderr +++ b/src/test/ui/issues/issue-16538.stderr @@ -1,11 +1,11 @@ error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-16538.rs:13:27 + --> $DIR/issue-16538.rs:11:27 | LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: `*const usize` cannot be shared between threads safely - --> $DIR/issue-16538.rs:13:1 + --> $DIR/issue-16538.rs:11:1 | LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely @@ -13,7 +13,15 @@ LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); = help: the trait `std::marker::Sync` is not implemented for `*const usize` = note: shared static variables must have a type that implements `Sync` -error: aborting due to 2 previous errors +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-16538.rs:11:34 + | +LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); + | ^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0015, E0277. +Some errors have detailed explanations: E0015, E0133, E0277. For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-28324.rs b/src/test/ui/issues/issue-28324.rs index 73e8cd6ab0da1..bb48508a4a438 100644 --- a/src/test/ui/issues/issue-28324.rs +++ b/src/test/ui/issues/issue-28324.rs @@ -1,11 +1,8 @@ -#![allow(safe_extern_statics)] - extern { static error_message_count: u32; } pub static BAZ: u32 = *&error_message_count; -//~^ ERROR could not evaluate static initializer -//~| tried to read from foreign (extern) static +//~^ ERROR use of extern static is unsafe and requires fn main() {} diff --git a/src/test/ui/issues/issue-28324.stderr b/src/test/ui/issues/issue-28324.stderr index bbd02ba03f489..d7dad99215204 100644 --- a/src/test/ui/issues/issue-28324.stderr +++ b/src/test/ui/issues/issue-28324.stderr @@ -1,9 +1,11 @@ -error[E0080]: could not evaluate static initializer - --> $DIR/issue-28324.rs:7:23 +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-28324.rs:5:24 | LL | pub static BAZ: u32 = *&error_message_count; - | ^^^^^^^^^^^^^^^^^^^^^ tried to read from foreign (extern) static + | ^^^^^^^^^^^^^^^^^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior error: aborting due to previous error -For more information about this error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/safe-extern-statics.rs b/src/test/ui/safe-extern-statics.rs index eda309444681b..0535a078d2c31 100644 --- a/src/test/ui/safe-extern-statics.rs +++ b/src/test/ui/safe-extern-statics.rs @@ -1,7 +1,5 @@ // aux-build:extern-statics.rs -#![allow(unused)] - extern crate extern_statics; use extern_statics::*; @@ -11,11 +9,7 @@ extern { fn main() { let a = A; //~ ERROR use of extern static is unsafe - //~^ WARN this was previously accepted by the compiler let ra = &A; //~ ERROR use of extern static is unsafe - //~^ WARN this was previously accepted by the compiler let xa = XA; //~ ERROR use of extern static is unsafe - //~^ WARN this was previously accepted by the compiler let xra = &XA; //~ ERROR use of extern static is unsafe - //~^ WARN this was previously accepted by the compiler } diff --git a/src/test/ui/safe-extern-statics.stderr b/src/test/ui/safe-extern-statics.stderr index 0948fad74e50e..b42572ea3eeb5 100644 --- a/src/test/ui/safe-extern-statics.stderr +++ b/src/test/ui/safe-extern-statics.stderr @@ -1,43 +1,35 @@ -error: use of extern static is unsafe and requires unsafe function or block (error E0133) - --> $DIR/safe-extern-statics.rs:13:13 +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:11:13 | LL | let a = A; - | ^ + | ^ use of extern static | - = note: `#[deny(safe_extern_statics)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #36247 = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior -error: use of extern static is unsafe and requires unsafe function or block (error E0133) - --> $DIR/safe-extern-statics.rs:15:14 +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:12:14 | LL | let ra = &A; - | ^^ + | ^^ use of extern static | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #36247 = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior -error: use of extern static is unsafe and requires unsafe function or block (error E0133) - --> $DIR/safe-extern-statics.rs:17:14 +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:13:14 | LL | let xa = XA; - | ^^ + | ^^ use of extern static | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #36247 = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior -error: use of extern static is unsafe and requires unsafe function or block (error E0133) - --> $DIR/safe-extern-statics.rs:19:15 +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:14:15 | LL | let xra = &XA; - | ^^^ + | ^^^ use of extern static | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #36247 = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0133`. From b54c5781b8252189f04a58247f644bcf2bd9dd68 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 19:58:26 +0200 Subject: [PATCH 4/8] parenthesized_params_in_types_and_modules -> error --- .../src/lints/listing/deny-by-default.md | 25 ------- src/librustc/hir/lowering.rs | 39 +++-------- src/librustc/lint/builtin.rs | 11 ---- src/librustc_lint/lib.rs | 2 + src/test/ui/issues/issue-32995-2.rs | 5 -- src/test/ui/issues/issue-32995-2.stderr | 29 +++------ src/test/ui/issues/issue-32995.rs | 9 --- src/test/ui/issues/issue-32995.stderr | 65 +++++++------------ .../let-binding-init-expr-as-ty.rs | 2 +- .../let-binding-init-expr-as-ty.stderr | 19 ++++-- src/test/ui/type/ascription/issue-34255-1.rs | 1 - .../ui/type/ascription/issue-34255-1.stderr | 10 +-- 12 files changed, 59 insertions(+), 158 deletions(-) diff --git a/src/doc/rustc/src/lints/listing/deny-by-default.md b/src/doc/rustc/src/lints/listing/deny-by-default.md index b349c68359cdb..466a748bcee91 100644 --- a/src/doc/rustc/src/lints/listing/deny-by-default.md +++ b/src/doc/rustc/src/lints/listing/deny-by-default.md @@ -122,31 +122,6 @@ error: literal out of range for u8 | ``` -## parenthesized-params-in-types-and-modules - -This lint detects incorrect parentheses. Some example code that triggers this -lint: - -```rust,ignore -let x = 5 as usize(); -``` - -This will produce: - -```text -error: parenthesized parameters may only be used with a trait - --> src/main.rs:2:21 - | -2 | let x = 5 as usize(); - | ^^ - | - = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 -``` - -To fix it, remove the `()`s. - ## pub-use-of-private-extern-crate This lint detects a specific situation of re-exporting a private `extern crate`; diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index c8bb35202f518..9f5e5fae07f04 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -44,8 +44,7 @@ use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS}; use crate::hir::{GenericArg, ConstArg}; use crate::hir::ptr::P; use crate::lint; -use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, - ELIDED_LIFETIMES_IN_PATHS}; +use crate::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS}; use crate::middle::cstore::CrateStore; use crate::session::Session; use crate::session::config::nightly_options; @@ -298,7 +297,6 @@ enum ParamMode { enum ParenthesizedGenericArgs { Ok, - Warn, Err, } @@ -1695,29 +1693,19 @@ impl<'a> LoweringContext<'a> { }; let parenthesized_generic_args = match partial_res.base_res() { // `a::b::Trait(Args)` - Res::Def(DefKind::Trait, _) - if i + 1 == proj_start => ParenthesizedGenericArgs::Ok, + Res::Def(DefKind::Trait, _) if i + 1 == proj_start => { + ParenthesizedGenericArgs::Ok + } // `a::b::Trait(Args)::TraitItem` - Res::Def(DefKind::Method, _) - | Res::Def(DefKind::AssocConst, _) - | Res::Def(DefKind::AssocTy, _) - if i + 2 == proj_start => - { + Res::Def(DefKind::Method, _) | + Res::Def(DefKind::AssocConst, _) | + Res::Def(DefKind::AssocTy, _) if i + 2 == proj_start => { ParenthesizedGenericArgs::Ok } // Avoid duplicated errors. Res::Err => ParenthesizedGenericArgs::Ok, // An error - Res::Def(DefKind::Struct, _) - | Res::Def(DefKind::Enum, _) - | Res::Def(DefKind::Union, _) - | Res::Def(DefKind::TyAlias, _) - | Res::Def(DefKind::Variant, _) if i + 1 == proj_start => - { - ParenthesizedGenericArgs::Err - } - // A warning for now, for compatibility reasons. - _ => ParenthesizedGenericArgs::Warn, + _ => ParenthesizedGenericArgs::Err, }; let num_lifetimes = type_def_id.map_or(0, |def_id| { @@ -1780,7 +1768,7 @@ impl<'a> LoweringContext<'a> { segment, param_mode, 0, - ParenthesizedGenericArgs::Warn, + ParenthesizedGenericArgs::Err, itctx.reborrow(), None, )); @@ -1856,15 +1844,6 @@ impl<'a> LoweringContext<'a> { } GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args { ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data), - ParenthesizedGenericArgs::Warn => { - self.resolver.lint_buffer().buffer_lint( - PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, - CRATE_NODE_ID, - data.span, - msg.into(), - ); - (hir::GenericArgs::none(), true) - } ParenthesizedGenericArgs::Err => { let mut err = struct_span_err!(self.sess, data.span, E0214, "{}", msg); err.span_label(data.span, "only `Fn` traits may use parentheses"); diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index c1957df2e62dd..c9dd60827ffcf 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -207,16 +207,6 @@ declare_lint! { }; } -declare_lint! { - pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, - Deny, - "detects parenthesized generic parameters in type and module names", - @future_incompatible = FutureIncompatibleInfo { - reference: "issue #42238 ", - edition: None, - }; -} - declare_lint! { pub LATE_BOUND_LIFETIME_ARGUMENTS, Warn, @@ -528,7 +518,6 @@ declare_lint_pass! { SAFE_PACKED_BORROWS, PATTERNS_IN_FNS_WITHOUT_BODY, MISSING_FRAGMENT_SPECIFIER, - PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, LATE_BOUND_LIFETIME_ARGUMENTS, ORDER_DEPENDENT_TRAIT_OBJECTS, DEPRECATED, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 5c10399d7dbae..c3c5589b9d070 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -340,6 +340,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) { "converted into hard error, see https://github.com/rust-lang/rust/issues/37872"); store.register_removed("safe_extern_statics", "converted into hard error, see https://github.com/rust-lang/rust/issues/36247"); + store.register_removed("parenthesized_params_in_types_and_modules", + "converted into hard error, see https://github.com/rust-lang/rust/issues/42238"); } fn register_internals(store: &mut lint::LintStore) { diff --git a/src/test/ui/issues/issue-32995-2.rs b/src/test/ui/issues/issue-32995-2.rs index 2234f68f24629..e713a64d3f5a6 100644 --- a/src/test/ui/issues/issue-32995-2.rs +++ b/src/test/ui/issues/issue-32995-2.rs @@ -1,13 +1,9 @@ -#![allow(unused)] - fn main() { { fn f() {} } //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted { fn f() -> impl ::std::marker()::Send { } } //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted } #[derive(Clone)] @@ -15,4 +11,3 @@ struct X; impl ::std::marker()::Copy for X {} //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait -//~| WARN previously accepted diff --git a/src/test/ui/issues/issue-32995-2.stderr b/src/test/ui/issues/issue-32995-2.stderr index 976e3064db64b..6c2d772a23332 100644 --- a/src/test/ui/issues/issue-32995-2.stderr +++ b/src/test/ui/issues/issue-32995-2.stderr @@ -1,30 +1,21 @@ -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995-2.rs:4:22 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995-2.rs:2:22 | LL | { fn f() {} } - | ^^^^^^^^ - | - = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995-2.rs:8:29 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995-2.rs:5:29 | LL | { fn f() -> impl ::std::marker()::Send { } } - | ^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995-2.rs:16:13 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995-2.rs:12:13 | LL | impl ::std::marker()::Copy for X {} - | ^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^^ only `Fn` traits may use parentheses error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0214`. diff --git a/src/test/ui/issues/issue-32995.rs b/src/test/ui/issues/issue-32995.rs index 3526deffc79ab..0d07a76939f2a 100644 --- a/src/test/ui/issues/issue-32995.rs +++ b/src/test/ui/issues/issue-32995.rs @@ -1,33 +1,24 @@ -#![allow(unused)] - fn main() { let x: usize() = 1; //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted let b: ::std::boxed()::Box<_> = Box::new(1); //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted let p = ::std::str::()::from_utf8(b"foo").unwrap(); //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted let p = ::std::str::from_utf8::()(b"foo").unwrap(); //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted let o : Box = Box::new(1); //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted let o : Box = Box::new(1); //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted } fn foo() { let d : X() = Default::default(); //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| WARN previously accepted } diff --git a/src/test/ui/issues/issue-32995.stderr b/src/test/ui/issues/issue-32995.stderr index 724e82a59dc35..b868011b99b24 100644 --- a/src/test/ui/issues/issue-32995.stderr +++ b/src/test/ui/issues/issue-32995.stderr @@ -1,66 +1,45 @@ -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995.rs:4:12 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995.rs:2:12 | LL | let x: usize() = 1; - | ^^^^^^^ - | - = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995.rs:8:19 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995.rs:5:19 | LL | let b: ::std::boxed()::Box<_> = Box::new(1); - | ^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995.rs:12:20 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995.rs:8:20 | LL | let p = ::std::str::()::from_utf8(b"foo").unwrap(); - | ^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995.rs:16:25 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995.rs:11:25 | LL | let p = ::std::str::from_utf8::()(b"foo").unwrap(); - | ^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995.rs:20:29 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995.rs:14:29 | LL | let o : Box = Box::new(1); - | ^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995.rs:24:35 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995.rs:17:35 | LL | let o : Box = Box::new(1); - | ^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^^^^ only `Fn` traits may use parentheses -error: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/issue-32995.rs:30:13 +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-32995.rs:22:13 | LL | let d : X() = Default::default(); - | ^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^ only `Fn` traits may use parentheses error: aborting due to 7 previous errors +For more information about this error, try `rustc --explain E0214`. diff --git a/src/test/ui/suggestions/let-binding-init-expr-as-ty.rs b/src/test/ui/suggestions/let-binding-init-expr-as-ty.rs index beea951a18a29..94c72a31e5e6c 100644 --- a/src/test/ui/suggestions/let-binding-init-expr-as-ty.rs +++ b/src/test/ui/suggestions/let-binding-init-expr-as-ty.rs @@ -1,9 +1,9 @@ pub fn foo(num: i32) -> i32 { let foo: i32::from_be(num); //~^ ERROR expected type, found local variable `num` + //~| ERROR type arguments are not allowed for this type //~| ERROR parenthesized type parameters may only be used with a `Fn` trait //~| ERROR ambiguous associated type - //~| WARNING this was previously accepted by the compiler but is being phased out foo } diff --git a/src/test/ui/suggestions/let-binding-init-expr-as-ty.stderr b/src/test/ui/suggestions/let-binding-init-expr-as-ty.stderr index a7c784fe82788..5353b3a75b249 100644 --- a/src/test/ui/suggestions/let-binding-init-expr-as-ty.stderr +++ b/src/test/ui/suggestions/let-binding-init-expr-as-ty.stderr @@ -6,15 +6,20 @@ LL | let foo: i32::from_be(num); | | | help: use `=` if you meant to assign -error: parenthesized type parameters may only be used with a `Fn` trait +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait --> $DIR/let-binding-init-expr-as-ty.rs:2:19 | LL | let foo: i32::from_be(num); | ^^^^^^^^^^^^ + | | + | only `Fn` traits may use parentheses + | help: use angle brackets instead: `from_be` + +error[E0109]: type arguments are not allowed for this type + --> $DIR/let-binding-init-expr-as-ty.rs:2:27 | - = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 +LL | let foo: i32::from_be(num); + | ^^^ type argument not allowed error[E0223]: ambiguous associated type --> $DIR/let-binding-init-expr-as-ty.rs:2:14 @@ -22,7 +27,7 @@ error[E0223]: ambiguous associated type LL | let foo: i32::from_be(num); | ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `::from_be` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0223, E0573. -For more information about an error, try `rustc --explain E0223`. +Some errors have detailed explanations: E0109, E0214, E0223, E0573. +For more information about an error, try `rustc --explain E0109`. diff --git a/src/test/ui/type/ascription/issue-34255-1.rs b/src/test/ui/type/ascription/issue-34255-1.rs index c21d9f3d97cbb..c0d39c59014ec 100644 --- a/src/test/ui/type/ascription/issue-34255-1.rs +++ b/src/test/ui/type/ascription/issue-34255-1.rs @@ -8,7 +8,6 @@ impl Reactor { //~^ ERROR cannot find value `input_cells` in this scope //~| ERROR parenthesized type parameters may only be used with a `Fn` trait //~| ERROR wrong number of type arguments: expected 1, found 0 - //~| WARNING this was previously accepted by the compiler but is being phased out } } diff --git a/src/test/ui/type/ascription/issue-34255-1.stderr b/src/test/ui/type/ascription/issue-34255-1.stderr index 0d0acfde88605..7895cf77fc0bf 100644 --- a/src/test/ui/type/ascription/issue-34255-1.stderr +++ b/src/test/ui/type/ascription/issue-34255-1.stderr @@ -4,15 +4,11 @@ error[E0425]: cannot find value `input_cells` in this scope LL | input_cells: Vec::new() | ^^^^^^^^^^^ a field by this name exists in `Self` -error: parenthesized type parameters may only be used with a `Fn` trait +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait --> $DIR/issue-34255-1.rs:7:27 | LL | input_cells: Vec::new() - | ^^^^^ - | - = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #42238 + | ^^^^^ only `Fn` traits may use parentheses error[E0107]: wrong number of type arguments: expected 1, found 0 --> $DIR/issue-34255-1.rs:7:22 @@ -22,5 +18,5 @@ LL | input_cells: Vec::new() error: aborting due to 3 previous errors -Some errors have detailed explanations: E0107, E0425. +Some errors have detailed explanations: E0107, E0214, E0425. For more information about an error, try `rustc --explain E0107`. From 8e27c4f3122c2ccb529ee3911a9d7e956f2462cd Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 20:29:45 +0200 Subject: [PATCH 5/8] duplicate_macro_exports -> error --- src/librustc/lint/builtin.rs | 16 ---------------- src/librustc_lint/lib.rs | 2 ++ src/librustc_resolve/resolve_imports.rs | 18 +++++++----------- .../ui/issues/auxiliary/issue-38715-modern.rs | 7 ------- src/test/ui/issues/auxiliary/issue-38715.rs | 7 ------- src/test/ui/issues/issue-38715-rpass.rs | 15 --------------- src/test/ui/issues/issue-38715.rs | 1 - src/test/ui/issues/issue-38715.stderr | 3 --- 8 files changed, 9 insertions(+), 60 deletions(-) delete mode 100644 src/test/ui/issues/auxiliary/issue-38715-modern.rs delete mode 100644 src/test/ui/issues/auxiliary/issue-38715.rs delete mode 100644 src/test/ui/issues/issue-38715-rpass.rs diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index c9dd60827ffcf..2e7db40474736 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -331,16 +331,6 @@ declare_lint! { "detects labels that are never used" } -declare_lint! { - pub DUPLICATE_MACRO_EXPORTS, - Deny, - "detects duplicate macro exports", - @future_incompatible = FutureIncompatibleInfo { - reference: "issue #35896 ", - edition: Some(Edition::Edition2018), - }; -} - declare_lint! { pub INTRA_DOC_LINK_RESOLUTION_FAILURE, Warn, @@ -533,7 +523,6 @@ declare_lint_pass! { ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, UNSTABLE_NAME_COLLISIONS, IRREFUTABLE_LET_PATTERNS, - DUPLICATE_MACRO_EXPORTS, INTRA_DOC_LINK_RESOLUTION_FAILURE, MISSING_DOC_CODE_EXAMPLES, PRIVATE_DOC_TESTS, @@ -559,7 +548,6 @@ pub enum BuiltinLintDiagnostics { Normal, BareTraitObject(Span, /* is_global */ bool), AbsPathWithModule(Span), - DuplicatedMacroExports(ast::Ident, Span, Span), ProcMacroDeriveResolutionFallback(Span), MacroExpandedMacroExportsAccessedByAbsolutePaths(Span), ElidedLifetimesInPaths(usize, Span, bool, Span, String), @@ -642,10 +630,6 @@ impl BuiltinLintDiagnostics { }; db.span_suggestion(span, "use `crate`", sugg, app); } - BuiltinLintDiagnostics::DuplicatedMacroExports(ident, earlier_span, later_span) => { - db.span_label(later_span, format!("`{}` already exported", ident)); - db.span_note(earlier_span, "previous macro export is now shadowed"); - } BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback(span) => { db.span_label(span, "names from parent modules are not \ accessible without an explicit import"); diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index c3c5589b9d070..6310ff3b8478a 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -342,6 +342,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) { "converted into hard error, see https://github.com/rust-lang/rust/issues/36247"); store.register_removed("parenthesized_params_in_types_and_modules", "converted into hard error, see https://github.com/rust-lang/rust/issues/42238"); + store.register_removed("duplicate_macro_exports", + "converted into hard error, see https://github.com/rust-lang/rust/issues/35896"); } fn register_internals(store: &mut lint::LintStore) { diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index c06be18dc2c18..083b11daaa153 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -16,18 +16,14 @@ use errors::{Applicability, pluralize}; use rustc_data_structures::ptr_key::PtrKey; use rustc::ty; use rustc::lint::builtin::BuiltinLintDiagnostics; -use rustc::lint::builtin::{ - DUPLICATE_MACRO_EXPORTS, - PUB_USE_OF_PRIVATE_EXTERN_CRATE, - UNUSED_IMPORTS, -}; +use rustc::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS}; use rustc::hir::def_id::DefId; use rustc::hir::def::{self, PartialRes, Export}; use rustc::session::DiagnosticMessageId; use rustc::util::nodemap::FxHashSet; use rustc::{bug, span_bug}; -use syntax::ast::{Ident, Name, NodeId, CRATE_NODE_ID}; +use syntax::ast::{Ident, Name, NodeId}; use syntax::symbol::kw; use syntax::util::lev_distance::find_best_match_for_name; use syntax::{struct_span_err, unwrap_or}; @@ -496,13 +492,13 @@ impl<'a> Resolver<'a> { if let (&NameBindingKind::Res(_, true), &NameBindingKind::Res(_, true)) = (&old_binding.kind, &binding.kind) { - this.lint_buffer.buffer_lint_with_diagnostic( - DUPLICATE_MACRO_EXPORTS, - CRATE_NODE_ID, + this.session.struct_span_err( binding.span, &format!("a macro named `{}` has already been exported", key.ident), - BuiltinLintDiagnostics::DuplicatedMacroExports( - key.ident, old_binding.span, binding.span)); + ) + .span_label(binding.span, format!("`{}` already exported", key.ident)) + .span_note(old_binding.span, "previous macro export is now shadowed") + .emit(); resolution.binding = Some(binding); } else { diff --git a/src/test/ui/issues/auxiliary/issue-38715-modern.rs b/src/test/ui/issues/auxiliary/issue-38715-modern.rs deleted file mode 100644 index 15d072957cbd8..0000000000000 --- a/src/test/ui/issues/auxiliary/issue-38715-modern.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![allow(duplicate_macro_exports)] - -#[macro_export] -macro_rules! foo_modern { ($i:ident) => {} } - -#[macro_export] -macro_rules! foo_modern { () => {} } diff --git a/src/test/ui/issues/auxiliary/issue-38715.rs b/src/test/ui/issues/auxiliary/issue-38715.rs deleted file mode 100644 index 5c15073f5a5e6..0000000000000 --- a/src/test/ui/issues/auxiliary/issue-38715.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![allow(duplicate_macro_exports)] - -#[macro_export] -macro_rules! foo { ($i:ident) => {} } - -#[macro_export] -macro_rules! foo { () => {} } diff --git a/src/test/ui/issues/issue-38715-rpass.rs b/src/test/ui/issues/issue-38715-rpass.rs deleted file mode 100644 index e3c3a027f3cd0..0000000000000 --- a/src/test/ui/issues/issue-38715-rpass.rs +++ /dev/null @@ -1,15 +0,0 @@ -// run-pass -// aux-build:issue-38715.rs -// aux-build:issue-38715-modern.rs - -// Test that `#[macro_export] macro_rules!` shadow earlier `#[macro_export] macro_rules!` - -#[macro_use] -extern crate issue_38715; -#[macro_use] -extern crate issue_38715_modern; - -fn main() { - foo!(); - foo_modern!(); -} diff --git a/src/test/ui/issues/issue-38715.rs b/src/test/ui/issues/issue-38715.rs index 850ffcdabe4cb..7e9defab58864 100644 --- a/src/test/ui/issues/issue-38715.rs +++ b/src/test/ui/issues/issue-38715.rs @@ -3,6 +3,5 @@ macro_rules! foo { ($i:ident) => {} } #[macro_export] macro_rules! foo { () => {} } //~ ERROR a macro named `foo` has already been exported - //~| WARN this was previously accepted fn main() {} diff --git a/src/test/ui/issues/issue-38715.stderr b/src/test/ui/issues/issue-38715.stderr index 02b96d2d2449c..d7c4f88ff5079 100644 --- a/src/test/ui/issues/issue-38715.stderr +++ b/src/test/ui/issues/issue-38715.stderr @@ -4,9 +4,6 @@ error: a macro named `foo` has already been exported LL | macro_rules! foo { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `foo` already exported | - = note: `#[deny(duplicate_macro_exports)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! - = note: for more information, see issue #35896 note: previous macro export is now shadowed --> $DIR/issue-38715.rs:2:1 | From 0cbd06ae1c12368d5c73024caf1a47daf7ea87be Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 21:59:22 +0200 Subject: [PATCH 6/8] nested_impl_trait -> error --- src/librustc/lint/builtin.rs | 18 --- src/librustc_lint/lib.rs | 2 + src/librustc_passes/ast_validation.rs | 126 +++--------------- ...-deeply-nested-impl-trait-in-assoc-proj.rs | 37 +---- ...ply-nested-impl-trait-in-assoc-proj.stderr | 32 +---- .../issues/issue-57979-impl-trait-in-path.rs | 35 +---- .../issue-57979-impl-trait-in-path.stderr | 30 +---- ...e-57979-nested-impl-trait-in-assoc-proj.rs | 35 +---- ...979-nested-impl-trait-in-assoc-proj.stderr | 42 ++---- 9 files changed, 57 insertions(+), 300 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 2e7db40474736..4ffb8dabe3b97 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -446,16 +446,6 @@ declare_lint! { }; } -declare_lint! { - pub NESTED_IMPL_TRAIT, - Warn, - "nested occurrence of `impl Trait` type", - @future_incompatible = FutureIncompatibleInfo { - reference: "issue #59014 ", - edition: None, - }; -} - declare_lint! { pub MUTABLE_BORROW_RESERVATION_CONFLICT, Warn, @@ -534,7 +524,6 @@ declare_lint_pass! { parser::META_VARIABLE_MISUSE, DEPRECATED_IN_FUTURE, AMBIGUOUS_ASSOCIATED_ITEMS, - NESTED_IMPL_TRAIT, MUTABLE_BORROW_RESERVATION_CONFLICT, INDIRECT_STRUCTURAL_MATCH, SOFT_UNSTABLE, @@ -553,7 +542,6 @@ pub enum BuiltinLintDiagnostics { ElidedLifetimesInPaths(usize, Span, bool, Span, String), UnknownCrateTypes(Span, String, String), UnusedImports(String, Vec<(Span, String)>), - NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span }, RedundantImport(Vec<(Span, bool)>, ast::Ident), DeprecatedMacro(Option, Span), } @@ -662,12 +650,6 @@ impl BuiltinLintDiagnostics { ); } } - BuiltinLintDiagnostics::NestedImplTrait { - outer_impl_trait_span, inner_impl_trait_span - } => { - db.span_label(outer_impl_trait_span, "outer `impl Trait`"); - db.span_label(inner_impl_trait_span, "nested `impl Trait` here"); - } BuiltinLintDiagnostics::RedundantImport(spans, ident) => { for (span, is_imported) in spans { let introduced = if is_imported { "imported" } else { "defined" }; diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 6310ff3b8478a..2ca3d4b19b269 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -344,6 +344,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) { "converted into hard error, see https://github.com/rust-lang/rust/issues/42238"); store.register_removed("duplicate_macro_exports", "converted into hard error, see https://github.com/rust-lang/rust/issues/35896"); + store.register_removed("nested_impl_trait", + "converted into hard error, see https://github.com/rust-lang/rust/issues/59014"); } fn register_internals(store: &mut lint::LintStore) { diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index e046f6c2a07b8..4577b6e1e07ab 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -9,7 +9,6 @@ use std::mem; use syntax::print::pprust; use rustc::lint; -use rustc::lint::builtin::{BuiltinLintDiagnostics, NESTED_IMPL_TRAIT}; use rustc::session::Session; use rustc_data_structures::fx::FxHashMap; use syntax::ast::*; @@ -23,31 +22,6 @@ use syntax::{span_err, struct_span_err, walk_list}; use syntax_pos::{Span, MultiSpan}; use errors::{Applicability, FatalError}; -#[derive(Copy, Clone, Debug)] -struct OuterImplTrait { - span: Span, - - /// rust-lang/rust#57979: a bug in original implementation caused - /// us to fail sometimes to record an outer `impl Trait`. - /// Therefore, in order to reliably issue a warning (rather than - /// an error) in the *precise* places where we are newly injecting - /// the diagnostic, we have to distinguish between the places - /// where the outer `impl Trait` has always been recorded, versus - /// the places where it has only recently started being recorded. - only_recorded_since_pull_request_57730: bool, -} - -impl OuterImplTrait { - /// This controls whether we should downgrade the nested impl - /// trait diagnostic to a warning rather than an error, based on - /// whether the outer impl trait had been improperly skipped in - /// earlier implementations of the analysis on the stable - /// compiler. - fn should_warn_instead_of_error(&self) -> bool { - self.only_recorded_since_pull_request_57730 - } -} - struct AstValidator<'a> { session: &'a Session, has_proc_macro_decls: bool, @@ -55,7 +29,7 @@ struct AstValidator<'a> { /// Used to ban nested `impl Trait`, e.g., `impl Into`. /// Nested `impl Trait` _is_ allowed in associated type position, /// e.g., `impl Iterator`. - outer_impl_trait: Option, + outer_impl_trait: Option, /// Used to ban `impl Trait` in path projections like `::Item` /// or `Foo::Bar` @@ -65,26 +39,10 @@ struct AstValidator<'a> { /// certain positions. is_assoc_ty_bound_banned: bool, - /// rust-lang/rust#57979: the ban of nested `impl Trait` was buggy - /// until PRs #57730 and #57981 landed: it would jump directly to - /// walk_ty rather than visit_ty (or skip recurring entirely for - /// impl trait in projections), and thus miss some cases. We track - /// whether we should downgrade to a warning for short-term via - /// these booleans. - warning_period_57979_didnt_record_next_impl_trait: bool, - warning_period_57979_impl_trait_in_proj: bool, - lint_buffer: &'a mut lint::LintBuffer, } impl<'a> AstValidator<'a> { - fn with_impl_trait_in_proj_warning(&mut self, v: bool, f: impl FnOnce(&mut Self) -> T) -> T { - let old = mem::replace(&mut self.warning_period_57979_impl_trait_in_proj, v); - let ret = f(self); - self.warning_period_57979_impl_trait_in_proj = old; - ret - } - fn with_banned_impl_trait(&mut self, f: impl FnOnce(&mut Self)) { let old = mem::replace(&mut self.is_impl_trait_banned, true); f(self); @@ -97,7 +55,7 @@ impl<'a> AstValidator<'a> { self.is_assoc_ty_bound_banned = old; } - fn with_impl_trait(&mut self, outer: Option, f: impl FnOnce(&mut Self)) { + fn with_impl_trait(&mut self, outer: Option, f: impl FnOnce(&mut Self)) { let old = mem::replace(&mut self.outer_impl_trait, outer); f(self); self.outer_impl_trait = old; @@ -105,14 +63,7 @@ impl<'a> AstValidator<'a> { fn visit_assoc_ty_constraint_from_generic_args(&mut self, constraint: &'a AssocTyConstraint) { match constraint.kind { - AssocTyConstraintKind::Equality { ref ty } => { - // rust-lang/rust#57979: bug in old `visit_generic_args` called - // `walk_ty` rather than `visit_ty`, skipping outer `impl Trait` - // if it happened to occur at `ty`. - if let TyKind::ImplTrait(..) = ty.kind { - self.warning_period_57979_didnt_record_next_impl_trait = true; - } - } + AssocTyConstraintKind::Equality { .. } => {} AssocTyConstraintKind::Bound { .. } => { if self.is_assoc_ty_bound_banned { self.err_handler().span_err(constraint.span, @@ -124,37 +75,11 @@ impl<'a> AstValidator<'a> { self.visit_assoc_ty_constraint(constraint); } - fn visit_ty_from_generic_args(&mut self, ty: &'a Ty) { - // rust-lang/rust#57979: bug in old `visit_generic_args` called - // `walk_ty` rather than `visit_ty`, skippping outer `impl Trait` - // if it happened to occur at `ty`. - if let TyKind::ImplTrait(..) = ty.kind { - self.warning_period_57979_didnt_record_next_impl_trait = true; - } - self.visit_ty(ty); - } - - fn outer_impl_trait(&mut self, span: Span) -> OuterImplTrait { - let only_recorded_since_pull_request_57730 = - self.warning_period_57979_didnt_record_next_impl_trait; - - // (This flag is designed to be set to `true`, and then only - // reach the construction point for the outer impl trait once, - // so its safe and easiest to unconditionally reset it to - // false.) - self.warning_period_57979_didnt_record_next_impl_trait = false; - - OuterImplTrait { - span, only_recorded_since_pull_request_57730, - } - } - // Mirrors `visit::walk_ty`, but tracks relevant state. fn walk_ty(&mut self, t: &'a Ty) { match t.kind { TyKind::ImplTrait(..) => { - let outer_impl_trait = self.outer_impl_trait(t.span); - self.with_impl_trait(Some(outer_impl_trait), |this| visit::walk_ty(this, t)) + self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t)) } TyKind::Path(ref qself, ref path) => { // We allow these: @@ -484,32 +409,21 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } TyKind::ImplTrait(_, ref bounds) => { if self.is_impl_trait_banned { - if self.warning_period_57979_impl_trait_in_proj { - self.lint_buffer.buffer_lint( - NESTED_IMPL_TRAIT, ty.id, ty.span, - "`impl Trait` is not allowed in path parameters"); - } else { - struct_span_err!(self.session, ty.span, E0667, - "`impl Trait` is not allowed in path parameters").emit(); - } + struct_span_err!( + self.session, ty.span, E0667, + "`impl Trait` is not allowed in path parameters" + ) + .emit(); } - if let Some(outer_impl_trait) = self.outer_impl_trait { - if outer_impl_trait.should_warn_instead_of_error() { - self.lint_buffer.buffer_lint_with_diagnostic( - NESTED_IMPL_TRAIT, ty.id, ty.span, - "nested `impl Trait` is not allowed", - BuiltinLintDiagnostics::NestedImplTrait { - outer_impl_trait_span: outer_impl_trait.span, - inner_impl_trait_span: ty.span, - }); - } else { - struct_span_err!(self.session, ty.span, E0666, - "nested `impl Trait` is not allowed") - .span_label(outer_impl_trait.span, "outer `impl Trait`") - .span_label(ty.span, "nested `impl Trait` here") - .emit(); - } + if let Some(outer_impl_trait_sp) = self.outer_impl_trait { + struct_span_err!( + self.session, ty.span, E0666, + "nested `impl Trait` is not allowed" + ) + .span_label(outer_impl_trait_sp, "outer `impl Trait`") + .span_label(ty.span, "nested `impl Trait` here") + .emit(); } if !bounds.iter() @@ -517,7 +431,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.err_handler().span_err(ty.span, "at least one trait must be specified"); } - self.with_impl_trait_in_proj_warning(true, |this| this.walk_ty(ty)); + self.walk_ty(ty); return; } _ => {} @@ -726,7 +640,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let Some(ref type_) = data.output { // `-> Foo` syntax is essentially an associated type binding, // so it is also allowed to contain nested `impl Trait`. - self.with_impl_trait(None, |this| this.visit_ty_from_generic_args(type_)); + self.with_impl_trait(None, |this| this.visit_ty(type_)); } } } @@ -844,8 +758,6 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut lint::LintBuffe outer_impl_trait: None, is_impl_trait_banned: false, is_assoc_ty_bound_banned: false, - warning_period_57979_didnt_record_next_impl_trait: false, - warning_period_57979_impl_trait_in_proj: false, lint_buffer: lints, }; visit::walk_crate(&mut validator, krate); diff --git a/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs b/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs index 5eef6a39325fe..0daec3305c0ae 100644 --- a/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs +++ b/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs @@ -1,42 +1,17 @@ // rust-lang/rust#57979 : the initial support for `impl Trait` didn't // properly check syntax hidden behind an associated type projection, // but it did catch *some cases*. This is checking that we continue to -// properly emit errors for those, even with the new -// future-incompatibility warnings. +// properly emit errors for those. // // issue-57979-nested-impl-trait-in-assoc-proj.rs shows the main case // that we were previously failing to catch. struct Deeper(T); -mod allowed { - #![allow(nested_impl_trait)] - - pub trait Foo { } - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux>>) { } - //~^ ERROR nested `impl Trait` is not allowed -} - -mod warned { - #![warn(nested_impl_trait)] - - pub trait Foo { } - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux>>) { } - //~^ ERROR nested `impl Trait` is not allowed -} - -mod denied { - #![deny(nested_impl_trait)] - - pub trait Foo { } - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux>>) { } - //~^ ERROR nested `impl Trait` is not allowed -} +pub trait Foo { } +pub trait Bar { } +pub trait Quux { type Assoc; } +pub fn demo(_: impl Quux>>) { } +//~^ ERROR nested `impl Trait` is not allowed fn main() { } diff --git a/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.stderr b/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.stderr index 2b6f15e6d3eb2..6bebbc01f3d6f 100644 --- a/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.stderr +++ b/src/test/ui/impl-trait/issues/issue-57979-deeply-nested-impl-trait-in-assoc-proj.stderr @@ -1,30 +1,12 @@ error[E0666]: nested `impl Trait` is not allowed - --> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:18:59 + --> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:14:48 | -LL | pub fn demo(_: impl Quux>>) { } - | ---------^^^^^^^^- - | | | - | | nested `impl Trait` here - | outer `impl Trait` +LL | pub fn demo(_: impl Quux>>) { } + | ---------^^^^^^^^- + | | | + | | nested `impl Trait` here + | outer `impl Trait` -error[E0666]: nested `impl Trait` is not allowed - --> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:28:59 - | -LL | pub fn demo(_: impl Quux>>) { } - | ---------^^^^^^^^- - | | | - | | nested `impl Trait` here - | outer `impl Trait` - -error[E0666]: nested `impl Trait` is not allowed - --> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:38:59 - | -LL | pub fn demo(_: impl Quux>>) { } - | ---------^^^^^^^^- - | | | - | | nested `impl Trait` here - | outer `impl Trait` - -error: aborting due to 3 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0666`. diff --git a/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs b/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs index 84fcb5e2880a7..c5ecd1caae1f9 100644 --- a/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs +++ b/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.rs @@ -3,35 +3,10 @@ // Here we test behavior of occurrences of `impl Trait` within a path // component in that context. -mod allowed { - #![allow(nested_impl_trait)] - - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } - impl Quux for () { type Assoc = u32; } -} - -mod warned { - #![warn(nested_impl_trait)] - - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } - //~^ WARN `impl Trait` is not allowed in path parameters - //~| WARN will become a hard error in a future release! - impl Quux for () { type Assoc = u32; } -} - -mod denied { - #![deny(nested_impl_trait)] - - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } - //~^ ERROR `impl Trait` is not allowed in path parameters - //~| WARN will become a hard error in a future release! - impl Quux for () { type Assoc = u32; } -} +pub trait Bar { } +pub trait Quux { type Assoc; } +pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } +//~^ ERROR `impl Trait` is not allowed in path parameters +impl Quux for () { type Assoc = u32; } fn main() { } diff --git a/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr b/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr index 982ecba291f79..f64545d83b8d6 100644 --- a/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr +++ b/src/test/ui/impl-trait/issues/issue-57979-impl-trait-in-path.stderr @@ -1,30 +1,8 @@ -warning: `impl Trait` is not allowed in path parameters - --> $DIR/issue-57979-impl-trait-in-path.rs:20:52 +error[E0667]: `impl Trait` is not allowed in path parameters + --> $DIR/issue-57979-impl-trait-in-path.rs:8:48 | -LL | pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } - | ^^^^^^^^ - | -note: lint level defined here - --> $DIR/issue-57979-impl-trait-in-path.rs:16:13 - | -LL | #![warn(nested_impl_trait)] - | ^^^^^^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #59014 - -error: `impl Trait` is not allowed in path parameters - --> $DIR/issue-57979-impl-trait-in-path.rs:31:52 - | -LL | pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } - | ^^^^^^^^ - | -note: lint level defined here - --> $DIR/issue-57979-impl-trait-in-path.rs:27:13 - | -LL | #![deny(nested_impl_trait)] - | ^^^^^^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #59014 +LL | pub fn demo(_: impl Quux<(), Assoc=<() as Quux>::Assoc>) { } + | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.rs b/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.rs index 5c20ffc7c6724..5a444d3dfddfa 100644 --- a/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.rs +++ b/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.rs @@ -3,35 +3,10 @@ // Here we test behavior of occurrences of `impl Trait` within an // `impl Trait` in that context. -mod allowed { - #![allow(nested_impl_trait)] - - pub trait Foo { } - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux>) { } -} - -mod warned { - #![warn(nested_impl_trait)] - - pub trait Foo { } - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux>) { } - //~^ WARN nested `impl Trait` is not allowed - //~| WARN will become a hard error in a future release! -} - -mod denied { - #![deny(nested_impl_trait)] - - pub trait Foo { } - pub trait Bar { } - pub trait Quux { type Assoc; } - pub fn demo(_: impl Quux>) { } - //~^ ERROR nested `impl Trait` is not allowed - //~| WARN will become a hard error in a future release! -} +pub trait Foo { } +pub trait Bar { } +pub trait Quux { type Assoc; } +pub fn demo(_: impl Quux>) { } +//~^ ERROR nested `impl Trait` is not allowed fn main() { } diff --git a/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.stderr b/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.stderr index 508aea2432132..8d3d4b5e20618 100644 --- a/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.stderr +++ b/src/test/ui/impl-trait/issues/issue-57979-nested-impl-trait-in-assoc-proj.stderr @@ -1,36 +1,12 @@ -warning: nested `impl Trait` is not allowed - --> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:21:45 - | -LL | pub fn demo(_: impl Quux>) { } - | ---------^^^^^^^^- - | | | - | | nested `impl Trait` here - | outer `impl Trait` - | -note: lint level defined here - --> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:16:13 - | -LL | #![warn(nested_impl_trait)] - | ^^^^^^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #59014 - -error: nested `impl Trait` is not allowed - --> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:32:45 - | -LL | pub fn demo(_: impl Quux>) { } - | ---------^^^^^^^^- - | | | - | | nested `impl Trait` here - | outer `impl Trait` - | -note: lint level defined here - --> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:27:13 - | -LL | #![deny(nested_impl_trait)] - | ^^^^^^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #59014 +error[E0666]: nested `impl Trait` is not allowed + --> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:9:41 + | +LL | pub fn demo(_: impl Quux>) { } + | ---------^^^^^^^^- + | | | + | | nested `impl Trait` here + | outer `impl Trait` error: aborting due to previous error +For more information about this error, try `rustc --explain E0666`. From a12e69d62798a4fb894209b249e16a6eda7c0d0f Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 27 Oct 2019 00:14:49 +0200 Subject: [PATCH 7/8] ill_formed_attribute_input -> deny --- src/librustc/lint/builtin.rs | 2 +- .../issue-43106-gating-of-inline.rs | 2 +- .../issue-43106-gating-of-inline.stderr | 6 ++--- .../ui/malformed/malformed-regressions.rs | 26 +++++++------------ .../ui/malformed/malformed-regressions.stderr | 24 +++++++++-------- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 4ffb8dabe3b97..baa1075e6b327 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -408,7 +408,7 @@ declare_lint! { pub mod parser { declare_lint! { pub ILL_FORMED_ATTRIBUTE_INPUT, - Warn, + Deny, "ill-formed attribute inputs that were previously accepted and used in practice", @future_incompatible = super::FutureIncompatibleInfo { reference: "issue #57571 ", diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-inline.rs b/src/test/ui/feature-gate/issue-43106-gating-of-inline.rs index bb9e6d4ca83b0..80c602eb00afb 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-inline.rs +++ b/src/test/ui/feature-gate/issue-43106-gating-of-inline.rs @@ -15,7 +15,7 @@ mod inline { //~^ ERROR attribute should be applied to function or closure #[inline = "2100"] fn f() { } - //~^ WARN attribute must be of the form + //~^ ERROR attribute must be of the form //~| WARN this was previously accepted #[inline] struct S; diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr index 4310a0c7d588e..0987937192fe2 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr @@ -1,10 +1,10 @@ -warning: attribute must be of the form `#[inline]` or `#[inline(always|never)]` +error: attribute must be of the form `#[inline]` or `#[inline(always|never)]` --> $DIR/issue-43106-gating-of-inline.rs:17:5 | LL | #[inline = "2100"] fn f() { } | ^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(ill_formed_attribute_input)]` on by default + = note: `#[deny(ill_formed_attribute_input)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 @@ -47,6 +47,6 @@ error[E0518]: attribute should be applied to function or closure LL | #[inline] impl S { } | ^^^^^^^^^ ---------- not a function or closure -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0518`. diff --git a/src/test/ui/malformed/malformed-regressions.rs b/src/test/ui/malformed/malformed-regressions.rs index 1eca8c739040c..ac1444bbaef4e 100644 --- a/src/test/ui/malformed/malformed-regressions.rs +++ b/src/test/ui/malformed/malformed-regressions.rs @@ -1,18 +1,12 @@ -// build-pass (FIXME(62277): could be check-pass?) +#[doc] //~ ERROR attribute must be of the form +//~^ WARN this was previously accepted +#[ignore()] //~ ERROR attribute must be of the form +//~^ WARN this was previously accepted +#[inline = ""] //~ ERROR attribute must be of the form +//~^ WARN this was previously accepted +#[link] //~ ERROR attribute must be of the form +//~^ WARN this was previously accepted +#[link = ""] //~ ERROR attribute must be of the form +//~^ WARN this was previously accepted -#[doc] -//~^ WARN attribute must be of the form -//~| WARN this was previously accepted -#[ignore()] -//~^ WARN attribute must be of the form -//~| WARN this was previously accepted -#[inline = ""] -//~^ WARN attribute must be of the form -//~| WARN this was previously accepted -#[link] -//~^WARN attribute must be of the form -//~| WARN this was previously accepted -#[link = ""] -//~^ WARN attribute must be of the form -//~| WARN this was previously accepted fn main() {} diff --git a/src/test/ui/malformed/malformed-regressions.stderr b/src/test/ui/malformed/malformed-regressions.stderr index 8f4e952338f8c..b14f99be50c2d 100644 --- a/src/test/ui/malformed/malformed-regressions.stderr +++ b/src/test/ui/malformed/malformed-regressions.stderr @@ -1,15 +1,15 @@ -warning: attribute must be of the form `#[doc(hidden|inline|...)]` or `#[doc = "string"]` - --> $DIR/malformed-regressions.rs:3:1 +error: attribute must be of the form `#[doc(hidden|inline|...)]` or `#[doc = "string"]` + --> $DIR/malformed-regressions.rs:1:1 | LL | #[doc] | ^^^^^^ | - = note: `#[warn(ill_formed_attribute_input)]` on by default + = note: `#[deny(ill_formed_attribute_input)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 -warning: attribute must be of the form `#[ignore]` or `#[ignore = "reason"]` - --> $DIR/malformed-regressions.rs:6:1 +error: attribute must be of the form `#[ignore]` or `#[ignore = "reason"]` + --> $DIR/malformed-regressions.rs:3:1 | LL | #[ignore()] | ^^^^^^^^^^^ @@ -17,8 +17,8 @@ LL | #[ignore()] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 -warning: attribute must be of the form `#[inline]` or `#[inline(always|never)]` - --> $DIR/malformed-regressions.rs:9:1 +error: attribute must be of the form `#[inline]` or `#[inline(always|never)]` + --> $DIR/malformed-regressions.rs:5:1 | LL | #[inline = ""] | ^^^^^^^^^^^^^^ @@ -26,8 +26,8 @@ LL | #[inline = ""] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 -warning: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` - --> $DIR/malformed-regressions.rs:12:1 +error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` + --> $DIR/malformed-regressions.rs:7:1 | LL | #[link] | ^^^^^^^ @@ -35,8 +35,8 @@ LL | #[link] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 -warning: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` - --> $DIR/malformed-regressions.rs:15:1 +error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` + --> $DIR/malformed-regressions.rs:9:1 | LL | #[link = ""] | ^^^^^^^^^^^^ @@ -44,3 +44,5 @@ LL | #[link = ""] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 +error: aborting due to 5 previous errors + From 574d2b83a16dbbe975bbb3cf2ed541563a2f756c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 22:33:19 +0200 Subject: [PATCH 8/8] patterns_in_fns_without_body -> deny --- .../src/lints/listing/deny-by-default.md | 40 +++++++++++++++++++ .../src/lints/listing/warn-by-default.md | 40 ------------------- src/librustc/lint/builtin.rs | 2 +- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/doc/rustc/src/lints/listing/deny-by-default.md b/src/doc/rustc/src/lints/listing/deny-by-default.md index 466a748bcee91..dc5a9e44acfa2 100644 --- a/src/doc/rustc/src/lints/listing/deny-by-default.md +++ b/src/doc/rustc/src/lints/listing/deny-by-default.md @@ -122,6 +122,46 @@ error: literal out of range for u8 | ``` +## patterns-in-fns-without-body + +This lint detects patterns in functions without body were that were +previously erroneously allowed. Some example code that triggers this lint: + +```rust,compile_fail +trait Trait { + fn foo(mut arg: u8); +} +``` + +This will produce: + +```text +warning: patterns aren't allowed in methods without bodies + --> src/main.rs:2:12 + | +2 | fn foo(mut arg: u8); + | ^^^^^^^ + | + = note: `#[warn(patterns_in_fns_without_body)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #35203 +``` + +To fix this, remove the pattern; it can be used in the implementation without +being used in the definition. That is: + +```rust +trait Trait { + fn foo(arg: u8); +} + +impl Trait for i32 { + fn foo(mut arg: u8) { + + } +} +``` + ## pub-use-of-private-extern-crate This lint detects a specific situation of re-exporting a private `extern crate`; diff --git a/src/doc/rustc/src/lints/listing/warn-by-default.md b/src/doc/rustc/src/lints/listing/warn-by-default.md index 813d7c4bafef8..77642a850fae8 100644 --- a/src/doc/rustc/src/lints/listing/warn-by-default.md +++ b/src/doc/rustc/src/lints/listing/warn-by-default.md @@ -307,46 +307,6 @@ warning: path statement with no effect | ``` -## patterns-in-fns-without-body - -This lint detects patterns in functions without body were that were -previously erroneously allowed. Some example code that triggers this lint: - -```rust -trait Trait { - fn foo(mut arg: u8); -} -``` - -This will produce: - -```text -warning: patterns aren't allowed in methods without bodies - --> src/main.rs:2:12 - | -2 | fn foo(mut arg: u8); - | ^^^^^^^ - | - = note: `#[warn(patterns_in_fns_without_body)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #35203 -``` - -To fix this, remove the pattern; it can be used in the implementation without -being used in the definition. That is: - -```rust -trait Trait { - fn foo(arg: u8); -} - -impl Trait for i32 { - fn foo(mut arg: u8) { - - } -} -``` - ## plugin-as-library This lint detects when compiler plugins are used as ordinary library in diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index baa1075e6b327..f8a592d22c19c 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -189,7 +189,7 @@ declare_lint! { declare_lint! { pub PATTERNS_IN_FNS_WITHOUT_BODY, - Warn, + Deny, "patterns in functions without body were erroneously allowed", @future_incompatible = FutureIncompatibleInfo { reference: "issue #35203 ",