Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,21 @@ pub(crate) struct FeatureNotValid<'a> {
#[primary_span]
#[label("`{$feature}` is not valid for this target")]
pub span: Span,
#[help("consider removing the leading `+` in the feature name")]
pub plus_hint: bool,
#[subdiagnostic]
pub plus_hint: Option<RemovePlusFromFeatureName<'a>>,
}

#[derive(Subdiagnostic)]
#[suggestion(
"consider removing the leading `+` in the feature name",
code = "enable = \"{stripped}\"",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub struct RemovePlusFromFeatureName<'a> {
#[primary_span]
pub span: Span,
pub stripped: &'a str,
}

#[derive(Diagnostic)]
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_target::spec::Arch;
use rustc_target::target_features::{RUSTC_SPECIFIC_FEATURES, Stability};
use smallvec::SmallVec;

use crate::errors::FeatureNotValid;
use crate::errors::{FeatureNotValid, RemovePlusFromFeatureName};
use crate::{errors, target_features};

/// Compute the enabled target features from the `#[target_feature]` function attribute.
Expand All @@ -34,7 +34,8 @@ pub(crate) fn from_target_feature_attr(
let Some(stability) = rust_target_features.get(feature_str) else {
let plus_hint = feature_str
.strip_prefix('+')
.is_some_and(|stripped| rust_target_features.contains_key(stripped));
.filter(|stripped| rust_target_features.contains_key(*stripped))
.map(|stripped| RemovePlusFromFeatureName { span: feature_span, stripped });
tcx.dcx().emit_err(FeatureNotValid {
feature: feature_str,
span: feature_span,
Expand Down
14 changes: 9 additions & 5 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ pub(crate) enum ModuleSorting {

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum EmitType {
Toolchain,
InvocationSpecific,
HtmlStaticFiles,
HtmlNonStaticFiles,
DepInfo(Option<OutFileName>),
}

Expand All @@ -332,8 +332,12 @@ impl FromStr for EmitType {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"toolchain-shared-resources" => Ok(Self::Toolchain),
"invocation-specific" => Ok(Self::InvocationSpecific),
// old nightly-only choices that are going away soon
"toolchain-shared-resources" => Ok(Self::HtmlStaticFiles),
"invocation-specific" => Ok(Self::HtmlNonStaticFiles),
// modern choices
"html-static-files" => Ok(Self::HtmlStaticFiles),
"html-non-static-files" => Ok(Self::HtmlNonStaticFiles),
"dep-info" => Ok(Self::DepInfo(None)),
option => match option.strip_prefix("dep-info=") {
Some("-") => Ok(Self::DepInfo(Some(OutFileName::Stdout))),
Expand All @@ -346,7 +350,7 @@ impl FromStr for EmitType {

impl RenderOptions {
pub(crate) fn should_emit_crate(&self) -> bool {
self.emit.is_empty() || self.emit.contains(&EmitType::InvocationSpecific)
self.emit.is_empty() || self.emit.contains(&EmitType::HtmlNonStaticFiles)
}

pub(crate) fn dep_info(&self) -> Option<Option<&OutFileName>> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn write_static_files(
try_err!(fs::write(&dst_path, buffer), &dst_path);
}

if opt.emit.is_empty() || opt.emit.contains(&EmitType::Toolchain) {
if opt.emit.is_empty() || opt.emit.contains(&EmitType::HtmlStaticFiles) {
static_files::for_each(|f: &static_files::StaticFile| {
let filename = static_dir.join(f.output_filename());
let contents: &[u8] =
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ fn opts() -> Vec<RustcOptGroup> {
"",
"emit",
"Comma separated list of types of output for rustdoc to emit",
"[toolchain-shared-resources,invocation-specific,dep-info]",
"[html-static-files,html-non-static-files,dep-info]",
),
opt(Unstable, FlagMulti, "", "no-run", "Compile doctests without running them", ""),
opt(
Expand Down
2 changes: 2 additions & 0 deletions tests/auxiliary/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ impl_marker_trait!(
]
);

impl Sync for () {}

#[lang = "drop_in_place"]
fn drop_in_place<T>(_: *mut T) {}

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/emit-shared-files/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() {

rustdoc()
.arg("-Zunstable-options")
.arg("--emit=toolchain-shared-resources")
.arg("--emit=html-static-files")
.out_dir("toolchain-only")
.arg("--resource-suffix=-xxx")
.args(&["--extend-css", "z.css"])
Expand Down Expand Up @@ -68,7 +68,7 @@ fn main() {

rustdoc()
.arg("-Zunstable-options")
.arg("--emit=toolchain-shared-resources")
.arg("--emit=html-static-files")
.out_dir("all-shared")
.arg("--resource-suffix=-xxx")
.args(&["--extend-css", "z.css"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Options:
--generate-redirect-map
Generate JSON file at the top level instead of
generating HTML redirection files
--emit [toolchain-shared-resources,invocation-specific,dep-info]
--emit [html-static-files,html-non-static-files,dep-info]
Comma separated list of types of output for rustdoc to
emit
--no-run Compile doctests without running them
Expand Down
17 changes: 14 additions & 3 deletions tests/ui/target-feature/invalid-attribute.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
//@ only-x86_64
//@ add-minicore
//@ compile-flags: --target=x86_64-unknown-linux-gnu
//@ needs-llvm-components: x86

#![warn(unused_attributes)]
#![feature(no_core)]
#![no_core]

use minicore::*;

#[target_feature(enable = "sse2")]
//~^ ERROR attribute cannot be used on
extern crate alloc;
extern crate minicore;

#[target_feature(enable = "sse2")]
//~^ ERROR attribute cannot be used on
use alloc::alloc::alloc;
use minicore::mem::transmute;

#[target_feature(enable = "sse2")]
//~^ ERROR attribute cannot be used on
Expand Down Expand Up @@ -112,3 +118,8 @@ fn main() {
//~^ ERROR `+sse2` is not valid for this target
//~| NOTE `+sse2` is not valid for this target
unsafe fn hey() {}

#[target_feature(enable = "+sse5")]
//~^ ERROR `+sse5` is not valid for this target
//~| NOTE `+sse5` is not valid for this target
unsafe fn typo() {}
Loading
Loading