about summary refs log tree commit diff
path: root/compiler/rustc_session
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2024-07-10 17:38:52 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2025-02-15 16:47:30 +0100
commit9b6fd35738965ef3f246018fddc743b5e5cd8d2c (patch)
tree955710be2b114b379217abfe9c79362d99b37bbe /compiler/rustc_session
parent46d53a68aa1b10833ec25178171f34e29e71f1f1 (diff)
downloadrust-9b6fd35738965ef3f246018fddc743b5e5cd8d2c.tar.gz
rust-9b6fd35738965ef3f246018fddc743b5e5cd8d2c.zip
Reject macro calls inside of `#![crate_name]`
Diffstat (limited to 'compiler/rustc_session')
-rw-r--r--compiler/rustc_session/messages.ftl4
-rw-r--r--compiler/rustc_session/src/errors.rs15
-rw-r--r--compiler/rustc_session/src/output.rs56
3 files changed, 3 insertions, 72 deletions
diff --git a/compiler/rustc_session/messages.ftl b/compiler/rustc_session/messages.ftl
index f108488cd58..74b8087e077 100644
--- a/compiler/rustc_session/messages.ftl
+++ b/compiler/rustc_session/messages.ftl
@@ -8,12 +8,8 @@ session_cannot_mix_and_match_sanitizers = `-Zsanitizer={$first}` is incompatible
 session_cli_feature_diagnostic_help =
     add `-Zcrate-attr="feature({$feature})"` to the command-line options to enable
 
-session_crate_name_does_not_match = `--crate-name` and `#[crate_name]` are required to match, but `{$crate_name}` != `{$attr_crate_name}`
-
 session_crate_name_empty = crate name must not be empty
 
-session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has a leading hyphen
-
 session_embed_source_insufficient_dwarf_version = `-Zembed-source=y` requires at least `-Z dwarf-version=5` but DWARF version is {$dwarf_version}
 
 session_embed_source_requires_debug_info = `-Zembed-source=y` requires debug information to be enabled
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs
index b57560ff782..71d8dbe44fe 100644
--- a/compiler/rustc_session/src/errors.rs
+++ b/compiler/rustc_session/src/errors.rs
@@ -213,21 +213,6 @@ pub(crate) struct FileWriteFail<'a> {
 }
 
 #[derive(Diagnostic)]
-#[diag(session_crate_name_does_not_match)]
-pub(crate) struct CrateNameDoesNotMatch {
-    #[primary_span]
-    pub(crate) span: Span,
-    pub(crate) crate_name: Symbol,
-    pub(crate) attr_crate_name: Symbol,
-}
-
-#[derive(Diagnostic)]
-#[diag(session_crate_name_invalid)]
-pub(crate) struct CrateNameInvalid<'a> {
-    pub(crate) s: &'a str,
-}
-
-#[derive(Diagnostic)]
 #[diag(session_crate_name_empty)]
 pub(crate) struct CrateNameEmpty {
     #[primary_span]
diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs
index a6d4ebf23c7..b37a80274c0 100644
--- a/compiler/rustc_session/src/output.rs
+++ b/compiler/rustc_session/src/output.rs
@@ -2,15 +2,12 @@
 
 use std::path::Path;
 
-use rustc_ast::{self as ast, attr};
+use rustc_ast as ast;
 use rustc_span::{Span, Symbol, sym};
 
 use crate::Session;
-use crate::config::{self, CrateType, Input, OutFileName, OutputFilenames, OutputType};
-use crate::errors::{
-    self, CrateNameDoesNotMatch, CrateNameEmpty, CrateNameInvalid, FileIsNotWriteable,
-    InvalidCharacterInCrateName,
-};
+use crate::config::{self, CrateType, OutFileName, OutputFilenames, OutputType};
+use crate::errors::{self, CrateNameEmpty, FileIsNotWriteable, InvalidCharacterInCrateName};
 
 pub fn out_filename(
     sess: &Session,
@@ -49,53 +46,6 @@ fn is_writeable(p: &Path) -> bool {
     }
 }
 
-/// Find and [validate] the crate name.
-///
-/// [validate]: validate_crate_name
-pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute]) -> Symbol {
-    let validate = |name, span| {
-        validate_crate_name(sess, name, span);
-        name
-    };
-
-    // Look in attributes 100% of the time to make sure the attribute is marked
-    // as used. After doing this, however, we still prioritize a crate name from
-    // the command line over one found in the #[crate_name] attribute. If we
-    // find both we ensure that they're the same later on as well.
-    let attr_crate_name =
-        attr::find_by_name(attrs, sym::crate_name).and_then(|at| at.value_str().map(|s| (at, s)));
-
-    if let Some(crate_name) = &sess.opts.crate_name {
-        let crate_name = Symbol::intern(crate_name);
-        if let Some((attr, attr_crate_name)) = attr_crate_name
-            && attr_crate_name != crate_name
-        {
-            sess.dcx().emit_err(CrateNameDoesNotMatch {
-                span: attr.span,
-                crate_name,
-                attr_crate_name,
-            });
-        }
-        return validate(crate_name, None);
-    }
-
-    if let Some((attr, crate_name)) = attr_crate_name {
-        return validate(crate_name, Some(attr.span));
-    }
-
-    if let Input::File(ref path) = sess.io.input
-        && let Some(s) = path.file_stem().and_then(|s| s.to_str())
-    {
-        if s.starts_with('-') {
-            sess.dcx().emit_err(CrateNameInvalid { s });
-        } else {
-            return validate(Symbol::intern(&s.replace('-', "_")), None);
-        }
-    }
-
-    sym::rust_out
-}
-
 /// Validate the given crate name.
 ///
 /// Note that this validation is more permissive than identifier parsing. It considers