From 964a2aa645513bd6e6adb083d93647c7f705fb8a Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 17:42:17 +0200 Subject: [PATCH] legacy_directory_ownership -> hard error. --- .../src/lints/listing/deny-by-default.md | 13 --- src/librustc/lint/builtin.rs | 8 -- src/librustc_lint/lib.rs | 7 +- src/librustc_passes/ast_validation.rs | 5 -- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 79 ++++++++----------- src/libsyntax_pos/symbol.rs | 1 - 8 files changed, 39 insertions(+), 78 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 6574267f18511..163f8e2666a27 100644 --- a/src/doc/rustc/src/lints/listing/deny-by-default.md +++ b/src/doc/rustc/src/lints/listing/deny-by-default.md @@ -79,19 +79,6 @@ error: private struct constructors are not usable through re-exports in outer mo = note: for more information, see issue #39207 ``` - -## 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 6d9a6bb77dd55..1583bdb815183 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -169,13 +169,6 @@ declare_lint! { "patterns in functions without body were erroneously allowed" } -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`" -} - declare_lint! { pub LEGACY_CONSTRUCTOR_VISIBILITY, Deny, @@ -426,7 +419,6 @@ declare_lint_pass! { SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, PATTERNS_IN_FNS_WITHOUT_BODY, - LEGACY_DIRECTORY_OWNERSHIP, LEGACY_CONSTRUCTOR_VISIBILITY, MISSING_FRAGMENT_SPECIFIER, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 78bc164ba1a0f..ad11996bb8d8a 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -331,11 +331,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { reference: "issue #36887 ", edition: None, }, - FutureIncompatibleInfo { - id: LintId::of(LEGACY_DIRECTORY_OWNERSHIP), - reference: "issue #37872 ", - edition: None, - }, FutureIncompatibleInfo { id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY), reference: "issue #39207 ", @@ -488,6 +483,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { "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_disrectory_ownership", + "converted into hard error, see https://github.com/rust-lang/rust/issues/37872"); } pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 3c31bcef32b7a..8c147a368faba 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -651,11 +651,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.session.buffer_lint(lint, item.id, item.span, msg); - } } ItemKind::Union(ref vdata, _) => { if let VariantData::Tuple(..) | VariantData::Unit(..) = vdata { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index cd602d08c5baa..6649db36f4ec6 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1113,7 +1113,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/parse/mod.rs b/src/libsyntax/parse/mod.rs index 80aa7a35266eb..5758fa2812864 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -148,7 +148,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.rs b/src/libsyntax/parse/parser.rs index eca1e218fcabc..edab39fe0b8bb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -435,7 +435,6 @@ pub struct ModulePath { pub struct ModulePathSuccess { pub path: PathBuf, pub directory_ownership: DirectoryOwnership, - warn: bool, } #[derive(Debug)] @@ -6389,24 +6388,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 = Attribute { - id: attr::mk_attr_id(), - style: ast::AttrStyle::Outer, - path: ast::Path::from_ident( - Ident::with_empty_ctxt(sym::warn_directory_ownership)), - tokens: TokenStream::empty(), - is_sugared_doc: false, - span: DUMMY_SP, - }; - attr::mark_known(&attr); - attrs.push(attr); - } Ok((id, ItemKind::Mod(module), Some(attrs))) } else { let placeholder = ast::Mod { @@ -6500,14 +6485,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(), @@ -6529,11 +6512,12 @@ impl<'a> Parser<'a> { } } - fn submod_path(&mut self, - id: ast::Ident, - outer_attrs: &[Attribute], - id_sp: Span) - -> PResult<'a, ModulePathSuccess> { + fn submod_path( + &mut self, + id: ast::Ident, + outer_attrs: &[Attribute], + id_sp: Span + ) -> PResult<'a, ModulePathSuccess> { if let Some(path) = Parser::submod_path_from_attr(outer_attrs, &self.directory.path) { return Ok(ModulePathSuccess { directory_ownership: match path.file_name().and_then(|s| s.to_str()) { @@ -6545,20 +6529,23 @@ 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()); + id, + relative, + &self.directory.path, + self.sess.source_map() + ); match self.directory.ownership { DirectoryOwnership::Owned { .. } => { @@ -6576,14 +6563,11 @@ impl<'a> Parser<'a> { } Err(err) } - DirectoryOwnership::UnownedViaMod(warn) => { - if warn { - if let Ok(result) = paths.result { - return Ok(ModulePathSuccess { warn: true, ..result }); - } - } - let mut err = self.diagnostic().struct_span_err(id_sp, - "cannot declare a new module at this location"); + DirectoryOwnership::UnownedViaMod => { + let mut err = self.struct_span_err( + id_sp, + "cannot declare a new module at this location" + ); if !id_sp.is_dummy() { let src_path = self.sess.source_map().span_to_filename(id_sp); if let FileName::Real(src_path) = src_path { @@ -6591,18 +6575,25 @@ impl<'a> Parser<'a> { let mut dest_path = src_path.clone(); dest_path.set_file_name(stem); dest_path.push("mod.rs"); - err.span_note(id_sp, - &format!("maybe move this module `{}` to its own \ - directory via `{}`", src_path.display(), - dest_path.display())); + err.span_note( + id_sp, + &format!( + "maybe move this module `{}` to its own \ + directory via `{}`", src_path.display(), + dest_path.display(), + ) + ); } } } if paths.path_exists { - err.span_note(id_sp, - &format!("... or maybe `use` the module `{}` instead \ - of possibly redeclaring it", - paths.name)); + err.span_note( + id_sp, + &format!( + "... or maybe `use` the module `{}` instead of possibly redeclaring it", + paths.name, + ) + ); } Err(err) } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 12c4ba059feb6..00327c63b81c2 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -720,7 +720,6 @@ symbols! { visible_private_types, volatile, warn, - warn_directory_ownership, wasm_import_module, wasm_target_feature, while_let,