Skip to content

Commit

Permalink
Fix for diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Mar 5, 2023
1 parent fce7053 commit 2c0c25d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_gcc/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ codegen_gcc_invalid_monomorphization_unsupported_operation =
codegen_gcc_invalid_minimum_alignment =
invalid minimum global alignment: {$err}
codegen_gcc_tied_target_features = the target features {$features} must all be either enabled or disabled together
.help = add the missing features in a `target_feature` attribute
11 changes: 6 additions & 5 deletions compiler/rustc_codegen_gcc/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_session::Session;
use rustc_span::symbol::sym;
use smallvec::{smallvec, SmallVec};

use crate::context::CodegenCx;
use crate::{context::CodegenCx, errors::TiedTargetFeatures};

// Given a map from target_features to whether they are enabled or disabled,
// ensure only valid combinations are allowed.
Expand Down Expand Up @@ -84,10 +84,11 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
let span = cx.tcx
.get_attr(instance.def_id(), sym::target_feature)
.map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span);
let msg = format!("the target features {} must all be either enabled or disabled together", features.join(", "));
let mut err = cx.tcx.sess.struct_span_err(span, &msg);
err.help("add the missing features in a `target_feature` attribute");
err.emit();
cx.tcx.sess.create_err(TiedTargetFeatures {
features: features.join(", "),
span,
})
.emit();
return;
}

Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_gcc/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,12 @@ pub(crate) struct UnwindingInlineAsm {
pub(crate) struct InvalidMinimumAlignment {
pub err: String,
}

#[derive(Diagnostic)]
#[diag(codegen_gcc_tied_target_features)]
#[help]
pub(crate) struct TiedTargetFeatures {
#[primary_span]
pub span: Span,
pub features: String,
}

0 comments on commit 2c0c25d

Please sign in to comment.