Auto merge of #117680 - matthiaskrgr:rollup-kgaa4ma, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #115485 (Format macro const literals with pretty printer) - #117616 (warn when using an unstable feature with -Ctarget-feature) - #117639 (Update books) - #117675 (llvm-wrapper: Remove include of non-existant Vectorize.h) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
7adc89b69b
@ -76,8 +76,8 @@ codegen_llvm_target_machine = could not create LLVM TargetMachine for triple: {$
|
|||||||
codegen_llvm_target_machine_with_llvm_err = could not create LLVM TargetMachine for triple: {$triple}: {$llvm_err}
|
codegen_llvm_target_machine_with_llvm_err = could not create LLVM TargetMachine for triple: {$triple}: {$llvm_err}
|
||||||
|
|
||||||
codegen_llvm_unknown_ctarget_feature =
|
codegen_llvm_unknown_ctarget_feature =
|
||||||
unknown feature specified for `-Ctarget-feature`: `{$feature}`
|
unknown and unstable feature specified for `-Ctarget-feature`: `{$feature}`
|
||||||
.note = it is still passed through to the codegen backend
|
.note = it is still passed through to the codegen backend, but use of this feature might be unsound and the behavior of this feature can change in the future
|
||||||
.possible_feature = you might have meant: `{$rust_feature}`
|
.possible_feature = you might have meant: `{$rust_feature}`
|
||||||
.consider_filing_feature_request = consider filing a feature request
|
.consider_filing_feature_request = consider filing a feature request
|
||||||
|
|
||||||
@ -87,6 +87,10 @@ codegen_llvm_unknown_ctarget_feature_prefix =
|
|||||||
|
|
||||||
codegen_llvm_unknown_debuginfo_compression = unknown debuginfo compression algorithm {$algorithm} - will fall back to uncompressed debuginfo
|
codegen_llvm_unknown_debuginfo_compression = unknown debuginfo compression algorithm {$algorithm} - will fall back to uncompressed debuginfo
|
||||||
|
|
||||||
|
codegen_llvm_unstable_ctarget_feature =
|
||||||
|
unstable feature specified for `-Ctarget-feature`: `{$feature}`
|
||||||
|
.note = this feature is not stably supported; its behavior can change in the future
|
||||||
|
|
||||||
codegen_llvm_write_bytecode = failed to write bytecode to {$path}: {$err}
|
codegen_llvm_write_bytecode = failed to write bytecode to {$path}: {$err}
|
||||||
|
|
||||||
codegen_llvm_write_ir = failed to write LLVM IR to {$path}
|
codegen_llvm_write_ir = failed to write LLVM IR to {$path}
|
||||||
|
@ -26,6 +26,13 @@ pub(crate) struct UnknownCTargetFeature<'a> {
|
|||||||
pub rust_feature: PossibleFeature<'a>,
|
pub rust_feature: PossibleFeature<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_unstable_ctarget_feature)]
|
||||||
|
#[note]
|
||||||
|
pub(crate) struct UnstableCTargetFeature<'a> {
|
||||||
|
pub feature: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum PossibleFeature<'a> {
|
pub(crate) enum PossibleFeature<'a> {
|
||||||
#[help(codegen_llvm_possible_feature)]
|
#[help(codegen_llvm_possible_feature)]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::back::write::create_informational_target_machine;
|
use crate::back::write::create_informational_target_machine;
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature,
|
PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature,
|
||||||
UnknownCTargetFeaturePrefix,
|
UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
|
||||||
};
|
};
|
||||||
use crate::llvm;
|
use crate::llvm;
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
@ -531,25 +531,34 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
|||||||
};
|
};
|
||||||
|
|
||||||
let feature = backend_feature_name(s)?;
|
let feature = backend_feature_name(s)?;
|
||||||
// Warn against use of LLVM specific feature names on the CLI.
|
// Warn against use of LLVM specific feature names and unstable features on the CLI.
|
||||||
if diagnostics && !supported_features.iter().any(|&(v, _)| v == feature) {
|
if diagnostics {
|
||||||
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _)| {
|
let feature_state = supported_features.iter().find(|&&(v, _)| v == feature);
|
||||||
let llvm_features = to_llvm_features(sess, rust_feature);
|
if feature_state.is_none() {
|
||||||
if llvm_features.contains(&feature) && !llvm_features.contains(&rust_feature) {
|
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _)| {
|
||||||
Some(rust_feature)
|
let llvm_features = to_llvm_features(sess, rust_feature);
|
||||||
|
if llvm_features.contains(&feature)
|
||||||
|
&& !llvm_features.contains(&rust_feature)
|
||||||
|
{
|
||||||
|
Some(rust_feature)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let unknown_feature = if let Some(rust_feature) = rust_feature {
|
||||||
|
UnknownCTargetFeature {
|
||||||
|
feature,
|
||||||
|
rust_feature: PossibleFeature::Some { rust_feature },
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
UnknownCTargetFeature { feature, rust_feature: PossibleFeature::None }
|
||||||
}
|
};
|
||||||
});
|
sess.emit_warning(unknown_feature);
|
||||||
let unknown_feature = if let Some(rust_feature) = rust_feature {
|
} else if feature_state.is_some_and(|(_name, feature_gate)| feature_gate.is_some())
|
||||||
UnknownCTargetFeature {
|
{
|
||||||
feature,
|
// An unstable feature. Warn about using it.
|
||||||
rust_feature: PossibleFeature::Some { rust_feature },
|
sess.emit_warning(UnstableCTargetFeature { feature });
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
UnknownCTargetFeature { feature, rust_feature: PossibleFeature::None }
|
|
||||||
};
|
|
||||||
sess.emit_warning(unknown_feature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if diagnostics {
|
if diagnostics {
|
||||||
|
@ -23,6 +23,15 @@
|
|||||||
// check whether they're named already elsewhere in rust
|
// check whether they're named already elsewhere in rust
|
||||||
// e.g. in stdarch and whether the given name matches LLVM's
|
// e.g. in stdarch and whether the given name matches LLVM's
|
||||||
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted
|
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted
|
||||||
|
//
|
||||||
|
// When adding a new feature, be particularly mindful of features that affect function ABIs. Those
|
||||||
|
// need to be treated very carefully to avoid introducing unsoundness! This often affects features
|
||||||
|
// that enable/disable hardfloat support (see https://github.com/rust-lang/rust/issues/116344 for an
|
||||||
|
// example of this going wrong), but features enabling new SIMD registers are also a concern (see
|
||||||
|
// https://github.com/rust-lang/rust/issues/116558 for an example of this going wrong).
|
||||||
|
//
|
||||||
|
// Stabilizing a target feature (setting the 2nd component of the pair to `None`) requires t-lang
|
||||||
|
// approval.
|
||||||
|
|
||||||
const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
|
const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
|
||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
#include "llvm/Transforms/Instrumentation.h"
|
#include "llvm/Transforms/Instrumentation.h"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Transforms/Vectorize.h"
|
|
||||||
|
|
||||||
#define LLVM_VERSION_GE(major, minor) \
|
#define LLVM_VERSION_GE(major, minor) \
|
||||||
(LLVM_VERSION_MAJOR > (major) || \
|
(LLVM_VERSION_MAJOR > (major) || \
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#![cfg_attr(not(bootstrap), feature(coroutines))]
|
#![cfg_attr(not(bootstrap), feature(coroutines))]
|
||||||
#![feature(iter_from_coroutine)]
|
#![feature(iter_from_coroutine)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
|
#![feature(if_let_guard)]
|
||||||
#![feature(proc_macro_internals)]
|
#![feature(proc_macro_internals)]
|
||||||
#![feature(macro_metavar_expr)]
|
#![feature(macro_metavar_expr)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
|
@ -2386,31 +2386,32 @@ fn classify(expr: &hir::Expr<'_>) -> Classification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let classification = classify(value);
|
match classify(value) {
|
||||||
|
// For non-macro literals, we avoid invoking the pretty-printer and use the source snippet
|
||||||
if classification == Literal
|
// instead to preserve certain stylistic choices the user likely made for the sake of
|
||||||
&& !value.span.from_expansion()
|
// legibility, like:
|
||||||
&& let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span)
|
|
||||||
{
|
|
||||||
// For literals, we avoid invoking the pretty-printer and use the source snippet instead to
|
|
||||||
// preserve certain stylistic choices the user likely made for the sake legibility like
|
|
||||||
//
|
//
|
||||||
// * hexadecimal notation
|
// * hexadecimal notation
|
||||||
// * underscores
|
// * underscores
|
||||||
// * character escapes
|
// * character escapes
|
||||||
//
|
//
|
||||||
// FIXME: This passes through `-/*spacer*/0` verbatim.
|
// FIXME: This passes through `-/*spacer*/0` verbatim.
|
||||||
snippet
|
Literal if !value.span.from_expansion()
|
||||||
} else if classification == Simple {
|
&& let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) => {
|
||||||
|
snippet
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise we prefer pretty-printing to get rid of extraneous whitespace, comments and
|
// Otherwise we prefer pretty-printing to get rid of extraneous whitespace, comments and
|
||||||
// other formatting artifacts.
|
// other formatting artifacts.
|
||||||
id_to_string(&hir, body.hir_id)
|
Literal | Simple => id_to_string(&hir, body.hir_id),
|
||||||
} else if tcx.def_kind(hir.body_owner_def_id(body).to_def_id()) == DefKind::AnonConst {
|
|
||||||
// FIXME: Omit the curly braces if the enclosing expression is an array literal
|
// FIXME: Omit the curly braces if the enclosing expression is an array literal
|
||||||
// with a repeated element (an `ExprKind::Repeat`) as in such case it
|
// with a repeated element (an `ExprKind::Repeat`) as in such case it
|
||||||
// would not actually need any disambiguation.
|
// would not actually need any disambiguation.
|
||||||
"{ _ }".to_owned()
|
Complex => if tcx.def_kind(hir.body_owner_def_id(body).to_def_id()) == DefKind::AnonConst {
|
||||||
} else {
|
"{ _ }".to_owned()
|
||||||
"_".to_owned()
|
} else {
|
||||||
|
"_".to_owned()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 16fd3c06d9e558dae2d52000818274ae70c9e90a
|
Subproject commit cd8193e972f61b92117095fc73b67af767b4d6bc
|
@ -1 +1 @@
|
|||||||
Subproject commit 6709beeb7d0fbc5ffc91ac4893a24434123b9bfa
|
Subproject commit 311b84962016b28c75525c86e7b3f49fd9101a39
|
@ -1 +1 @@
|
|||||||
Subproject commit b0ee9ec8fa59a6c7620165e061f4747202377a62
|
Subproject commit 77dbe5782b2488af3bb489ad702eaff438f465bf
|
40
tests/rustdoc/issue-115295-macro-const-display.rs
Normal file
40
tests/rustdoc/issue-115295-macro-const-display.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has foo/trait.Trait.html
|
||||||
|
pub trait Trait<T> {}
|
||||||
|
|
||||||
|
// @has foo/struct.WithConst.html
|
||||||
|
pub struct WithConst<const N: usize>;
|
||||||
|
|
||||||
|
macro_rules! spans_from_macro {
|
||||||
|
() => {
|
||||||
|
impl WithConst<42> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Trait<WithConst<42>> for WithConst<42> {}
|
||||||
|
impl Trait<WithConst<43>> for WithConst<{ 43 }> {}
|
||||||
|
impl Trait<WithConst<{ 44 }>> for WithConst<44> {}
|
||||||
|
pub struct Other {
|
||||||
|
pub field: WithConst<42>,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// @has - '//*[@class="impl"]//h3[@class="code-header"]' \
|
||||||
|
// "impl Trait<WithConst<41>> for WithConst<41>"
|
||||||
|
impl Trait<WithConst<41>> for WithConst<41> {}
|
||||||
|
|
||||||
|
// @has - '//*[@class="impl"]//h3[@class="code-header"]' \
|
||||||
|
// "impl WithConst<42>"
|
||||||
|
// @has - '//*[@class="impl"]//h3[@class="code-header"]' \
|
||||||
|
// "impl Trait<WithConst<42>> for WithConst<42>"
|
||||||
|
// @has - '//*[@class="impl"]//h3[@class="code-header"]' \
|
||||||
|
// "impl Trait<WithConst<43>> for WithConst<{ 43 }>"
|
||||||
|
// @has - '//*[@class="impl"]//h3[@class="code-header"]' \
|
||||||
|
// "impl Trait<WithConst<44>> for WithConst<44>"
|
||||||
|
|
||||||
|
// @has foo/struct.Other.html
|
||||||
|
// @has - //pre "pub field: WithConst<42>"
|
||||||
|
spans_from_macro!();
|
@ -0,0 +1,6 @@
|
|||||||
|
warning: unstable feature specified for `-Ctarget-feature`: `nontrapping-fptoint`
|
||||||
|
|
|
||||||
|
= note: this feature is not stably supported; its behavior can change in the future
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
warning: unknown feature specified for `-Ctarget-feature`: `rdrnd`
|
warning: unknown and unstable feature specified for `-Ctarget-feature`: `rdrnd`
|
||||||
|
|
|
|
||||||
= note: it is still passed through to the codegen backend
|
= note: it is still passed through to the codegen backend, but use of this feature might be unsound and the behavior of this feature can change in the future
|
||||||
= help: you might have meant: `rdrand`
|
= help: you might have meant: `rdrand`
|
||||||
|
|
||||||
warning: 1 warning emitted
|
warning: 1 warning emitted
|
||||||
|
6
tests/ui/target-feature/unstable-feature.rs
Normal file
6
tests/ui/target-feature/unstable-feature.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// compile-flags: -Ctarget-feature=+vaes --crate-type=rlib --target=x86_64-unknown-linux-gnu
|
||||||
|
// build-pass
|
||||||
|
// needs-llvm-components: x86
|
||||||
|
|
||||||
|
#![feature(no_core)]
|
||||||
|
#![no_core]
|
6
tests/ui/target-feature/unstable-feature.stderr
Normal file
6
tests/ui/target-feature/unstable-feature.stderr
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
warning: unstable feature specified for `-Ctarget-feature`: `vaes`
|
||||||
|
|
|
||||||
|
= note: this feature is not stably supported; its behavior can change in the future
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
Loading…
Reference in New Issue
Block a user