mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Auto merge of #115193 - weihanglo:rollup-6s3mz06, r=weihanglo
Rollup of 9 pull requests Successful merges: - #114987 (elaborate a bit on the (lack of) safety in 'Mmap::map') - #115084 (Add smir `predicates_of`) - #115117 (Detect and report nix shell) - #115124 (kmc-solid: Import `std::sync::PoisonError` in `std::sys::solid::os`) - #115152 (refactor(lint): translate `RenamedOrRemovedLint`) - #115154 (Move some ui tests to subdirectories) - #115167 (Fix ub-int-array test for big-endian platforms) - #115172 (Add more tests for if_let_guard) - #115177 (Add symbols for Clippy usage) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
c9228aeaba
@ -11,9 +11,14 @@ pub struct Mmap(Vec<u8>);
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl Mmap {
|
||||
/// # Safety
|
||||
///
|
||||
/// The given file must not be mutated (i.e., not written, not truncated, ...) until the mapping is closed.
|
||||
///
|
||||
/// However in practice most callers do not ensure this, so uses of this function are likely unsound.
|
||||
#[inline]
|
||||
pub unsafe fn map(file: File) -> io::Result<Self> {
|
||||
// Safety: this is in fact not safe.
|
||||
// Safety: the caller must ensure that this is safe.
|
||||
unsafe { memmap2::Mmap::map(&file).map(Mmap) }
|
||||
}
|
||||
}
|
||||
|
@ -158,13 +158,15 @@ lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`
|
||||
|
||||
lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}
|
||||
|
||||
lint_check_name_removed = lint `{$lint_name}` has been removed: {$reason}
|
||||
|
||||
lint_check_name_renamed = lint `{$lint_name}` has been renamed to `{$replace}`
|
||||
|
||||
lint_check_name_unknown = unknown lint: `{$lint_name}`
|
||||
.help = did you mean: `{$suggestion}`
|
||||
|
||||
lint_check_name_unknown_tool = unknown lint tool: `{$tool_name}`
|
||||
|
||||
lint_check_name_warning = {$msg}
|
||||
|
||||
lint_command_line_source = `forbid` lint level was set on command line
|
||||
|
||||
lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike
|
||||
@ -484,8 +486,11 @@ lint_redundant_semicolons =
|
||||
*[false] this semicolon
|
||||
}
|
||||
|
||||
lint_renamed_or_removed_lint = {$msg}
|
||||
lint_removed_lint = lint `{$name}` has been removed: {$reason}
|
||||
|
||||
lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
|
||||
.suggestion = use the new name
|
||||
.help = use the new name `{$replace}`
|
||||
|
||||
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
use self::TargetLint::*;
|
||||
|
||||
use crate::errors::{
|
||||
CheckNameDeprecated, CheckNameUnknown, CheckNameUnknownTool, CheckNameWarning, RequestedLevel,
|
||||
UnsupportedGroup,
|
||||
CheckNameDeprecated, CheckNameRemoved, CheckNameRenamed, CheckNameUnknown,
|
||||
CheckNameUnknownTool, RequestedLevel, UnsupportedGroup,
|
||||
};
|
||||
use crate::levels::LintLevelsBuilder;
|
||||
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
|
||||
@ -124,9 +124,10 @@ pub enum CheckLintNameResult<'a> {
|
||||
NoLint(Option<Symbol>),
|
||||
/// The lint refers to a tool that has not been registered.
|
||||
NoTool,
|
||||
/// The lint is either renamed or removed. This is the warning
|
||||
/// message, and an optional new name (`None` if removed).
|
||||
Warning(String, Option<String>),
|
||||
/// The lint has been renamed to a new name.
|
||||
Renamed(String),
|
||||
/// The lint has been removed due to the given reason.
|
||||
Removed(String),
|
||||
/// The lint is from a tool. If the Option is None, then either
|
||||
/// the lint does not exist in the tool or the code was not
|
||||
/// compiled with the tool and therefore the lint was never
|
||||
@ -342,25 +343,32 @@ impl LintStore {
|
||||
sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() });
|
||||
return;
|
||||
}
|
||||
let lint_name = lint_name.to_string();
|
||||
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
|
||||
CheckLintNameResult::Warning(msg, _) => {
|
||||
sess.emit_warning(CheckNameWarning {
|
||||
msg,
|
||||
CheckLintNameResult::Renamed(replace) => {
|
||||
sess.emit_warning(CheckNameRenamed {
|
||||
lint_name,
|
||||
replace: &replace,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::Removed(reason) => {
|
||||
sess.emit_warning(CheckNameRemoved {
|
||||
lint_name,
|
||||
reason: &reason,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::NoLint(suggestion) => {
|
||||
sess.emit_err(CheckNameUnknown {
|
||||
lint_name: lint_name.clone(),
|
||||
lint_name,
|
||||
suggestion,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
|
||||
sess.emit_warning(CheckNameDeprecated {
|
||||
lint_name: lint_name.clone(),
|
||||
new_name,
|
||||
lint_name,
|
||||
new_name: &new_name,
|
||||
sub: RequestedLevel { level, lint_name },
|
||||
});
|
||||
}
|
||||
@ -445,14 +453,8 @@ impl LintStore {
|
||||
}
|
||||
}
|
||||
match self.by_name.get(&complete_name) {
|
||||
Some(Renamed(new_name, _)) => CheckLintNameResult::Warning(
|
||||
format!("lint `{complete_name}` has been renamed to `{new_name}`"),
|
||||
Some(new_name.to_owned()),
|
||||
),
|
||||
Some(Removed(reason)) => CheckLintNameResult::Warning(
|
||||
format!("lint `{complete_name}` has been removed: {reason}"),
|
||||
None,
|
||||
),
|
||||
Some(Renamed(new_name, _)) => CheckLintNameResult::Renamed(new_name.to_string()),
|
||||
Some(Removed(reason)) => CheckLintNameResult::Removed(reason.to_string()),
|
||||
None => match self.lint_groups.get(&*complete_name) {
|
||||
// If neither the lint, nor the lint group exists check if there is a `clippy::`
|
||||
// variant of this lint
|
||||
|
@ -91,9 +91,9 @@ pub struct BuiltinEllipsisInclusiveRangePatterns {
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(lint_requested_level)]
|
||||
pub struct RequestedLevel {
|
||||
pub struct RequestedLevel<'a> {
|
||||
pub level: Level,
|
||||
pub lint_name: String,
|
||||
pub lint_name: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
@ -102,13 +102,13 @@ pub struct UnsupportedGroup {
|
||||
pub lint_group: String,
|
||||
}
|
||||
|
||||
pub struct CheckNameUnknown {
|
||||
pub lint_name: String,
|
||||
pub struct CheckNameUnknown<'a> {
|
||||
pub lint_name: &'a str,
|
||||
pub suggestion: Option<Symbol>,
|
||||
pub sub: RequestedLevel,
|
||||
pub sub: RequestedLevel<'a>,
|
||||
}
|
||||
|
||||
impl IntoDiagnostic<'_> for CheckNameUnknown {
|
||||
impl IntoDiagnostic<'_> for CheckNameUnknown<'_> {
|
||||
fn into_diagnostic(
|
||||
self,
|
||||
handler: &Handler,
|
||||
@ -127,25 +127,35 @@ impl IntoDiagnostic<'_> for CheckNameUnknown {
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(lint_check_name_unknown_tool, code = "E0602")]
|
||||
pub struct CheckNameUnknownTool {
|
||||
pub struct CheckNameUnknownTool<'a> {
|
||||
pub tool_name: Symbol,
|
||||
#[subdiagnostic]
|
||||
pub sub: RequestedLevel,
|
||||
pub sub: RequestedLevel<'a>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(lint_check_name_warning)]
|
||||
pub struct CheckNameWarning {
|
||||
pub msg: String,
|
||||
#[diag(lint_check_name_renamed)]
|
||||
pub struct CheckNameRenamed<'a> {
|
||||
pub lint_name: &'a str,
|
||||
pub replace: &'a str,
|
||||
#[subdiagnostic]
|
||||
pub sub: RequestedLevel,
|
||||
pub sub: RequestedLevel<'a>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(lint_check_name_removed)]
|
||||
pub struct CheckNameRemoved<'a> {
|
||||
pub lint_name: &'a str,
|
||||
pub reason: &'a str,
|
||||
#[subdiagnostic]
|
||||
pub sub: RequestedLevel<'a>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(lint_check_name_deprecated)]
|
||||
pub struct CheckNameDeprecated {
|
||||
pub lint_name: String,
|
||||
pub new_name: String,
|
||||
pub struct CheckNameDeprecated<'a> {
|
||||
pub lint_name: &'a str,
|
||||
pub new_name: &'a str,
|
||||
#[subdiagnostic]
|
||||
pub sub: RequestedLevel,
|
||||
pub sub: RequestedLevel<'a>,
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ use crate::{
|
||||
fluent_generated as fluent,
|
||||
late::unerased_lint_store,
|
||||
lints::{
|
||||
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint,
|
||||
RenamedOrRemovedLint, RenamedOrRemovedLintSuggestion, UnknownLint, UnknownLintSuggestion,
|
||||
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint, RemovedLint,
|
||||
RenamedLint, RenamedLintSuggestion, UnknownLint, UnknownLintSuggestion,
|
||||
},
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
@ -915,18 +915,26 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||
|
||||
_ if !self.warn_about_weird_lints => {}
|
||||
|
||||
CheckLintNameResult::Warning(msg, renamed) => {
|
||||
CheckLintNameResult::Renamed(new_name) => {
|
||||
let suggestion =
|
||||
renamed.as_ref().map(|replace| RenamedOrRemovedLintSuggestion {
|
||||
suggestion: sp,
|
||||
replace: replace.as_str(),
|
||||
});
|
||||
RenamedLintSuggestion { suggestion: sp, replace: new_name.as_str() };
|
||||
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
|
||||
self.emit_spanned_lint(
|
||||
RENAMED_AND_REMOVED_LINTS,
|
||||
sp.into(),
|
||||
RenamedOrRemovedLint { msg, suggestion },
|
||||
RenamedLint { name: name.as_str(), suggestion },
|
||||
);
|
||||
}
|
||||
|
||||
CheckLintNameResult::Removed(reason) => {
|
||||
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
|
||||
self.emit_spanned_lint(
|
||||
RENAMED_AND_REMOVED_LINTS,
|
||||
sp.into(),
|
||||
RemovedLint { name: name.as_str(), reason: reason.as_str() },
|
||||
);
|
||||
}
|
||||
|
||||
CheckLintNameResult::NoLint(suggestion) => {
|
||||
let name = if let Some(tool_ident) = tool_ident {
|
||||
format!("{}::{}", tool_ident.name, name)
|
||||
@ -945,7 +953,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||
// If this lint was renamed, apply the new lint instead of ignoring the attribute.
|
||||
// This happens outside of the match because the new lint should be applied even if
|
||||
// we don't warn about the name change.
|
||||
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
|
||||
if let CheckLintNameResult::Renamed(new_name) = lint_result {
|
||||
// Ignore any errors or warnings that happen because the new name is inaccurate
|
||||
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
|
||||
if let CheckLintNameResult::Ok(ids) =
|
||||
|
@ -1012,23 +1012,29 @@ pub struct DeprecatedLintName<'a> {
|
||||
pub replace: &'a str,
|
||||
}
|
||||
|
||||
// FIXME: Non-translatable msg
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_renamed_or_removed_lint)]
|
||||
pub struct RenamedOrRemovedLint<'a> {
|
||||
pub msg: &'a str,
|
||||
#[diag(lint_renamed_lint)]
|
||||
pub struct RenamedLint<'a> {
|
||||
pub name: &'a str,
|
||||
#[subdiagnostic]
|
||||
pub suggestion: Option<RenamedOrRemovedLintSuggestion<'a>>,
|
||||
pub suggestion: RenamedLintSuggestion<'a>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
|
||||
pub struct RenamedOrRemovedLintSuggestion<'a> {
|
||||
pub struct RenamedLintSuggestion<'a> {
|
||||
#[primary_span]
|
||||
pub suggestion: Span,
|
||||
pub replace: &'a str,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_removed_lint)]
|
||||
pub struct RemovedLint<'a> {
|
||||
pub name: &'a str,
|
||||
pub reason: &'a str,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_unknown_lint)]
|
||||
pub struct UnknownLint {
|
||||
|
@ -108,6 +108,23 @@ impl<'tcx> Context for Tables<'tcx> {
|
||||
let generic_def = self.tcx.generics_of(def_id);
|
||||
generic_def.stable(self)
|
||||
}
|
||||
|
||||
fn predicates_of(
|
||||
&mut self,
|
||||
trait_def: &stable_mir::ty::TraitDef,
|
||||
) -> stable_mir::GenericPredicates {
|
||||
let trait_def_id = self.trait_def_id(trait_def);
|
||||
let ty::GenericPredicates { parent, predicates } = self.tcx.predicates_of(trait_def_id);
|
||||
stable_mir::GenericPredicates {
|
||||
parent: parent.map(|did| self.trait_def(did)),
|
||||
predicates: predicates
|
||||
.iter()
|
||||
.map(|(clause, span)| {
|
||||
(clause.as_predicate().kind().skip_binder().stable(self), span.stable(self))
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Tables<'tcx> {
|
||||
@ -200,7 +217,7 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
|
||||
stable_mir::mir::Rvalue::Repeat(op.stable(tables), len)
|
||||
}
|
||||
Ref(region, kind, place) => stable_mir::mir::Rvalue::Ref(
|
||||
opaque(region),
|
||||
region.stable(tables),
|
||||
kind.stable(tables),
|
||||
place.stable(tables),
|
||||
),
|
||||
@ -842,12 +859,9 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> {
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
use stable_mir::ty::GenericArgKind;
|
||||
match self {
|
||||
ty::GenericArgKind::Lifetime(region) => GenericArgKind::Lifetime(opaque(region)),
|
||||
ty::GenericArgKind::Lifetime(region) => GenericArgKind::Lifetime(region.stable(tables)),
|
||||
ty::GenericArgKind::Type(ty) => GenericArgKind::Type(tables.intern_ty(*ty)),
|
||||
ty::GenericArgKind::Const(cnst) => {
|
||||
let cnst = ConstantKind::from_const(*cnst, tables.tcx);
|
||||
GenericArgKind::Const(stable_mir::ty::Const { literal: cnst.stable(tables) })
|
||||
}
|
||||
ty::GenericArgKind::Const(cnst) => GenericArgKind::Const(cnst.stable(tables)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -950,12 +964,12 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
|
||||
impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
|
||||
type T = stable_mir::ty::BoundRegionKind;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
use stable_mir::ty::BoundRegionKind;
|
||||
|
||||
match self {
|
||||
ty::BoundRegionKind::BrAnon(option_span) => {
|
||||
BoundRegionKind::BrAnon(option_span.map(|span| opaque(&span)))
|
||||
BoundRegionKind::BrAnon(option_span.map(|span| span.stable(tables)))
|
||||
}
|
||||
ty::BoundRegionKind::BrNamed(def_id, symbol) => {
|
||||
BoundRegionKind::BrNamed(rustc_internal::br_named_def(*def_id), symbol.to_string())
|
||||
@ -1053,16 +1067,14 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
|
||||
}
|
||||
ty::Str => TyKind::RigidTy(RigidTy::Str),
|
||||
ty::Array(ty, constant) => {
|
||||
let cnst = ConstantKind::from_const(*constant, tables.tcx);
|
||||
let cnst = stable_mir::ty::Const { literal: cnst.stable(tables) };
|
||||
TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), cnst))
|
||||
TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), constant.stable(tables)))
|
||||
}
|
||||
ty::Slice(ty) => TyKind::RigidTy(RigidTy::Slice(tables.intern_ty(*ty))),
|
||||
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
|
||||
TyKind::RigidTy(RigidTy::RawPtr(tables.intern_ty(*ty), mutbl.stable(tables)))
|
||||
}
|
||||
ty::Ref(region, ty, mutbl) => TyKind::RigidTy(RigidTy::Ref(
|
||||
opaque(region),
|
||||
region.stable(tables),
|
||||
tables.intern_ty(*ty),
|
||||
mutbl.stable(tables),
|
||||
)),
|
||||
@ -1077,7 +1089,7 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
|
||||
.iter()
|
||||
.map(|existential_predicate| existential_predicate.stable(tables))
|
||||
.collect(),
|
||||
opaque(region),
|
||||
region.stable(tables),
|
||||
dyn_kind.stable(tables),
|
||||
))
|
||||
}
|
||||
@ -1112,6 +1124,15 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
|
||||
type T = stable_mir::ty::Const;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
let cnst = ConstantKind::from_const(*self, tables.tcx);
|
||||
stable_mir::ty::Const { literal: cnst.stable(tables) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::ParamTy {
|
||||
type T = stable_mir::ty::ParamTy;
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
@ -1238,14 +1259,6 @@ impl<'tcx> Stable<'tcx> for ty::Generics {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for rustc_span::Span {
|
||||
type T = stable_mir::ty::Span;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
opaque(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
|
||||
type T = stable_mir::ty::GenericParamDefKind;
|
||||
|
||||
@ -1276,3 +1289,188 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
|
||||
type T = stable_mir::ty::PredicateKind;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
use ty::PredicateKind;
|
||||
match self {
|
||||
PredicateKind::Clause(clause_kind) => {
|
||||
stable_mir::ty::PredicateKind::Clause(clause_kind.stable(tables))
|
||||
}
|
||||
PredicateKind::ObjectSafe(did) => {
|
||||
stable_mir::ty::PredicateKind::ObjectSafe(tables.trait_def(*did))
|
||||
}
|
||||
PredicateKind::ClosureKind(did, generic_args, closure_kind) => {
|
||||
stable_mir::ty::PredicateKind::ClosureKind(
|
||||
tables.closure_def(*did),
|
||||
generic_args.stable(tables),
|
||||
closure_kind.stable(tables),
|
||||
)
|
||||
}
|
||||
PredicateKind::Subtype(subtype_predicate) => {
|
||||
stable_mir::ty::PredicateKind::SubType(subtype_predicate.stable(tables))
|
||||
}
|
||||
PredicateKind::Coerce(coerce_predicate) => {
|
||||
stable_mir::ty::PredicateKind::Coerce(coerce_predicate.stable(tables))
|
||||
}
|
||||
PredicateKind::ConstEquate(a, b) => {
|
||||
stable_mir::ty::PredicateKind::ConstEquate(a.stable(tables), b.stable(tables))
|
||||
}
|
||||
PredicateKind::Ambiguous => stable_mir::ty::PredicateKind::Ambiguous,
|
||||
PredicateKind::AliasRelate(a, b, alias_relation_direction) => {
|
||||
stable_mir::ty::PredicateKind::AliasRelate(
|
||||
a.unpack().stable(tables),
|
||||
b.unpack().stable(tables),
|
||||
alias_relation_direction.stable(tables),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
|
||||
type T = stable_mir::ty::ClauseKind;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
use ty::ClauseKind::*;
|
||||
match *self {
|
||||
Trait(trait_object) => stable_mir::ty::ClauseKind::Trait(trait_object.stable(tables)),
|
||||
RegionOutlives(region_outlives) => {
|
||||
stable_mir::ty::ClauseKind::RegionOutlives(region_outlives.stable(tables))
|
||||
}
|
||||
TypeOutlives(type_outlives) => {
|
||||
let ty::OutlivesPredicate::<_, _>(a, b) = type_outlives;
|
||||
stable_mir::ty::ClauseKind::TypeOutlives(stable_mir::ty::OutlivesPredicate(
|
||||
tables.intern_ty(a),
|
||||
b.stable(tables),
|
||||
))
|
||||
}
|
||||
Projection(projection_predicate) => {
|
||||
stable_mir::ty::ClauseKind::Projection(projection_predicate.stable(tables))
|
||||
}
|
||||
ConstArgHasType(const_, ty) => stable_mir::ty::ClauseKind::ConstArgHasType(
|
||||
const_.stable(tables),
|
||||
tables.intern_ty(ty),
|
||||
),
|
||||
WellFormed(generic_arg) => {
|
||||
stable_mir::ty::ClauseKind::WellFormed(generic_arg.unpack().stable(tables))
|
||||
}
|
||||
ConstEvaluatable(const_) => {
|
||||
stable_mir::ty::ClauseKind::ConstEvaluatable(const_.stable(tables))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::ClosureKind {
|
||||
type T = stable_mir::ty::ClosureKind;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
use ty::ClosureKind::*;
|
||||
match self {
|
||||
Fn => stable_mir::ty::ClosureKind::Fn,
|
||||
FnMut => stable_mir::ty::ClosureKind::FnMut,
|
||||
FnOnce => stable_mir::ty::ClosureKind::FnOnce,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> {
|
||||
type T = stable_mir::ty::SubtypePredicate;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
let ty::SubtypePredicate { a, b, a_is_expected: _ } = self;
|
||||
stable_mir::ty::SubtypePredicate { a: tables.intern_ty(*a), b: tables.intern_ty(*b) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> {
|
||||
type T = stable_mir::ty::CoercePredicate;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
let ty::CoercePredicate { a, b } = self;
|
||||
stable_mir::ty::CoercePredicate { a: tables.intern_ty(*a), b: tables.intern_ty(*b) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::AliasRelationDirection {
|
||||
type T = stable_mir::ty::AliasRelationDirection;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
use ty::AliasRelationDirection::*;
|
||||
match self {
|
||||
Equate => stable_mir::ty::AliasRelationDirection::Equate,
|
||||
Subtype => stable_mir::ty::AliasRelationDirection::Subtype,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::TraitPredicate<'tcx> {
|
||||
type T = stable_mir::ty::TraitPredicate;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
let ty::TraitPredicate { trait_ref, polarity } = self;
|
||||
stable_mir::ty::TraitPredicate {
|
||||
trait_ref: trait_ref.stable(tables),
|
||||
polarity: polarity.stable(tables),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, A, B, U, V> Stable<'tcx> for ty::OutlivesPredicate<A, B>
|
||||
where
|
||||
A: Stable<'tcx, T = U>,
|
||||
B: Stable<'tcx, T = V>,
|
||||
{
|
||||
type T = stable_mir::ty::OutlivesPredicate<U, V>;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
let ty::OutlivesPredicate(a, b) = self;
|
||||
stable_mir::ty::OutlivesPredicate(a.stable(tables), b.stable(tables))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> {
|
||||
type T = stable_mir::ty::ProjectionPredicate;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
let ty::ProjectionPredicate { projection_ty, term } = self;
|
||||
stable_mir::ty::ProjectionPredicate {
|
||||
projection_ty: projection_ty.stable(tables),
|
||||
term: term.unpack().stable(tables),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
|
||||
type T = stable_mir::ty::ImplPolarity;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
use ty::ImplPolarity::*;
|
||||
match self {
|
||||
Positive => stable_mir::ty::ImplPolarity::Positive,
|
||||
Negative => stable_mir::ty::ImplPolarity::Negative,
|
||||
Reservation => stable_mir::ty::ImplPolarity::Reservation,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
|
||||
type T = stable_mir::ty::Region;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
// FIXME: add a real implementation of stable regions
|
||||
opaque(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for rustc_span::Span {
|
||||
type T = stable_mir::ty::Span;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||
// FIXME: add a real implementation of stable spans
|
||||
opaque(self)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ use std::cell::Cell;
|
||||
|
||||
use crate::rustc_smir::Tables;
|
||||
|
||||
use self::ty::{GenericDef, Generics, ImplDef, ImplTrait, TraitDecl, TraitDef, Ty, TyKind};
|
||||
use self::ty::{
|
||||
GenericDef, Generics, ImplDef, ImplTrait, PredicateKind, Span, TraitDecl, TraitDef, Ty, TyKind,
|
||||
};
|
||||
|
||||
pub mod mir;
|
||||
pub mod ty;
|
||||
@ -38,6 +40,12 @@ pub type TraitDecls = Vec<TraitDef>;
|
||||
/// A list of impl trait decls.
|
||||
pub type ImplTraitDecls = Vec<ImplDef>;
|
||||
|
||||
/// A list of predicates.
|
||||
pub struct GenericPredicates {
|
||||
pub parent: Option<TraitDef>,
|
||||
pub predicates: Vec<(PredicateKind, Span)>,
|
||||
}
|
||||
|
||||
/// Holds information about a crate.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Crate {
|
||||
@ -101,6 +109,10 @@ pub fn trait_impl(trait_impl: &ImplDef) -> ImplTrait {
|
||||
with(|cx| cx.trait_impl(trait_impl))
|
||||
}
|
||||
|
||||
pub fn predicates_of(trait_def: &TraitDef) -> GenericPredicates {
|
||||
with(|cx| cx.predicates_of(trait_def))
|
||||
}
|
||||
|
||||
pub trait Context {
|
||||
fn entry_fn(&mut self) -> Option<CrateItem>;
|
||||
/// Retrieve all items of the local crate that have a MIR associated with them.
|
||||
@ -111,6 +123,7 @@ pub trait Context {
|
||||
fn all_trait_impls(&mut self) -> ImplTraitDecls;
|
||||
fn trait_impl(&mut self, trait_impl: &ImplDef) -> ImplTrait;
|
||||
fn generics_of(&mut self, generic_def: &GenericDef) -> Generics;
|
||||
fn predicates_of(&mut self, trait_def: &TraitDef) -> GenericPredicates;
|
||||
/// Get information about the local crate.
|
||||
fn local_crate(&self) -> Crate;
|
||||
/// Retrieve a list of all external crates.
|
||||
|
@ -22,7 +22,7 @@ pub struct Const {
|
||||
|
||||
type Ident = Opaque;
|
||||
pub(crate) type Region = Opaque;
|
||||
pub type Span = Opaque;
|
||||
pub(crate) type Span = Opaque;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum TyKind {
|
||||
@ -497,3 +497,81 @@ pub struct GenericParamDef {
|
||||
pub pure_wrt_drop: bool,
|
||||
pub kind: GenericParamDefKind,
|
||||
}
|
||||
|
||||
pub struct GenericPredicates {
|
||||
pub parent: Option<DefId>,
|
||||
pub predicates: Vec<PredicateKind>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum PredicateKind {
|
||||
Clause(ClauseKind),
|
||||
ObjectSafe(TraitDef),
|
||||
ClosureKind(ClosureDef, GenericArgs, ClosureKind),
|
||||
SubType(SubtypePredicate),
|
||||
Coerce(CoercePredicate),
|
||||
ConstEquate(Const, Const),
|
||||
Ambiguous,
|
||||
AliasRelate(TermKind, TermKind, AliasRelationDirection),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ClauseKind {
|
||||
Trait(TraitPredicate),
|
||||
RegionOutlives(RegionOutlivesPredicate),
|
||||
TypeOutlives(TypeOutlivesPredicate),
|
||||
Projection(ProjectionPredicate),
|
||||
ConstArgHasType(Const, Ty),
|
||||
WellFormed(GenericArgKind),
|
||||
ConstEvaluatable(Const),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ClosureKind {
|
||||
Fn,
|
||||
FnMut,
|
||||
FnOnce,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SubtypePredicate {
|
||||
pub a: Ty,
|
||||
pub b: Ty,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CoercePredicate {
|
||||
pub a: Ty,
|
||||
pub b: Ty,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum AliasRelationDirection {
|
||||
Equate,
|
||||
Subtype,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TraitPredicate {
|
||||
pub trait_ref: TraitRef,
|
||||
pub polarity: ImplPolarity,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OutlivesPredicate<A, B>(pub A, pub B);
|
||||
|
||||
pub type RegionOutlivesPredicate = OutlivesPredicate<Region, Region>;
|
||||
pub type TypeOutlivesPredicate = OutlivesPredicate<Ty, Region>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ProjectionPredicate {
|
||||
pub projection_ty: AliasTy,
|
||||
pub term: TermKind,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ImplPolarity {
|
||||
Positive,
|
||||
Negative,
|
||||
Reservation,
|
||||
}
|
||||
|
@ -232,11 +232,13 @@ symbols! {
|
||||
NonZeroI32,
|
||||
NonZeroI64,
|
||||
NonZeroI8,
|
||||
NonZeroIsize,
|
||||
NonZeroU128,
|
||||
NonZeroU16,
|
||||
NonZeroU32,
|
||||
NonZeroU64,
|
||||
NonZeroU8,
|
||||
NonZeroUsize,
|
||||
None,
|
||||
Ok,
|
||||
Option,
|
||||
@ -278,6 +280,7 @@ symbols! {
|
||||
RwLock,
|
||||
RwLockReadGuard,
|
||||
RwLockWriteGuard,
|
||||
Saturating,
|
||||
Send,
|
||||
SeqCst,
|
||||
SliceIndex,
|
||||
@ -305,6 +308,7 @@ symbols! {
|
||||
Vec,
|
||||
VecDeque,
|
||||
Wrapper,
|
||||
Wrapping,
|
||||
Yield,
|
||||
_DECLS,
|
||||
_Self,
|
||||
@ -1373,6 +1377,7 @@ symbols! {
|
||||
sanitizer_cfi_normalize_integers,
|
||||
sanitizer_runtime,
|
||||
saturating_add,
|
||||
saturating_div,
|
||||
saturating_sub,
|
||||
self_in_typedefs,
|
||||
self_struct_ctor,
|
||||
@ -1691,7 +1696,10 @@ symbols! {
|
||||
windows_subsystem,
|
||||
with_negative_coherence,
|
||||
wrapping_add,
|
||||
wrapping_div,
|
||||
wrapping_mul,
|
||||
wrapping_rem,
|
||||
wrapping_rem_euclid,
|
||||
wrapping_sub,
|
||||
wreg,
|
||||
write_bytes,
|
||||
|
@ -8,7 +8,7 @@ use crate::os::{
|
||||
solid::ffi::{OsStrExt, OsStringExt},
|
||||
};
|
||||
use crate::path::{self, PathBuf};
|
||||
use crate::sync::RwLock;
|
||||
use crate::sync::{PoisonError, RwLock};
|
||||
use crate::sys::common::small_c_string::run_with_cstr;
|
||||
use crate::vec;
|
||||
|
||||
|
@ -623,7 +623,7 @@ class RustBuild(object):
|
||||
|
||||
def should_fix_bins_and_dylibs(self):
|
||||
"""Whether or not `fix_bin_or_dylib` needs to be run; can only be True
|
||||
on NixOS.
|
||||
on NixOS or if config.toml has `build.patch-binaries-for-nix` set.
|
||||
"""
|
||||
if self._should_fix_bins_and_dylibs is not None:
|
||||
return self._should_fix_bins_and_dylibs
|
||||
@ -643,18 +643,31 @@ class RustBuild(object):
|
||||
if ostype != "Linux":
|
||||
return False
|
||||
|
||||
# If the user has asked binaries to be patched for Nix, then
|
||||
# don't check for NixOS.
|
||||
# If the user has explicitly indicated whether binaries should be
|
||||
# patched for Nix, then don't check for NixOS.
|
||||
if self.get_toml("patch-binaries-for-nix", "build") == "true":
|
||||
return True
|
||||
if self.get_toml("patch-binaries-for-nix", "build") == "false":
|
||||
return False
|
||||
|
||||
# Use `/etc/os-release` instead of `/etc/NIXOS`.
|
||||
# The latter one does not exist on NixOS when using tmpfs as root.
|
||||
try:
|
||||
with open("/etc/os-release", "r") as f:
|
||||
return any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f)
|
||||
is_nixos = any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"')
|
||||
for ln in f)
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
is_nixos = False
|
||||
|
||||
# If not on NixOS, then warn if user seems to be atop Nix shell
|
||||
if not is_nixos:
|
||||
in_nix_shell = os.getenv('IN_NIX_SHELL')
|
||||
if in_nix_shell:
|
||||
print("The IN_NIX_SHELL environment variable is `{}`;".format(in_nix_shell),
|
||||
"you may need to set `patch-binaries-for-nix=true` in config.toml",
|
||||
file=sys.stderr)
|
||||
|
||||
return is_nixos
|
||||
|
||||
answer = self._should_fix_bins_and_dylibs = get_answer()
|
||||
if answer:
|
||||
|
@ -137,7 +137,7 @@ pub struct Config {
|
||||
pub json_output: bool,
|
||||
pub test_compare_mode: bool,
|
||||
pub color: Color,
|
||||
pub patch_binaries_for_nix: bool,
|
||||
pub patch_binaries_for_nix: Option<bool>,
|
||||
pub stage0_metadata: Stage0Metadata,
|
||||
|
||||
pub stdout_is_tty: bool,
|
||||
@ -1339,7 +1339,7 @@ impl Config {
|
||||
set(&mut config.local_rebuild, build.local_rebuild);
|
||||
set(&mut config.print_step_timings, build.print_step_timings);
|
||||
set(&mut config.print_step_rusage, build.print_step_rusage);
|
||||
set(&mut config.patch_binaries_for_nix, build.patch_binaries_for_nix);
|
||||
config.patch_binaries_for_nix = build.patch_binaries_for_nix;
|
||||
|
||||
config.verbose = cmp::max(config.verbose, flags.verbose as usize);
|
||||
|
||||
|
@ -91,8 +91,8 @@ impl Config {
|
||||
// NOTE: this intentionally comes after the Linux check:
|
||||
// - patchelf only works with ELF files, so no need to run it on Mac or Windows
|
||||
// - On other Unix systems, there is no stable syscall interface, so Nix doesn't manage the global libc.
|
||||
if self.patch_binaries_for_nix {
|
||||
return true;
|
||||
if let Some(explicit_value) = self.patch_binaries_for_nix {
|
||||
return explicit_value;
|
||||
}
|
||||
|
||||
// Use `/etc/os-release` instead of `/etc/NIXOS`.
|
||||
@ -105,6 +105,15 @@ impl Config {
|
||||
matches!(l.trim(), "ID=nixos" | "ID='nixos'" | "ID=\"nixos\"")
|
||||
}),
|
||||
};
|
||||
if !is_nixos {
|
||||
let in_nix_shell = env::var("IN_NIX_SHELL");
|
||||
if let Ok(in_nix_shell) = in_nix_shell {
|
||||
eprintln!(
|
||||
"The IN_NIX_SHELL environment variable is `{in_nix_shell}`; \
|
||||
you may need to set `patch-binaries-for-nix=true` in config.toml"
|
||||
);
|
||||
}
|
||||
}
|
||||
is_nixos
|
||||
});
|
||||
if val {
|
||||
|
@ -10,8 +10,8 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
const ENTRY_LIMIT: usize = 900;
|
||||
// FIXME: The following limits should be reduced eventually.
|
||||
const ISSUES_ENTRY_LIMIT: usize = 1891;
|
||||
const ROOT_ENTRY_LIMIT: usize = 866;
|
||||
const ISSUES_ENTRY_LIMIT: usize = 1874;
|
||||
const ROOT_ENTRY_LIMIT: usize = 865;
|
||||
|
||||
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
|
||||
"rs", // test source files
|
||||
|
@ -1,36 +0,0 @@
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:19:1
|
||||
|
|
||||
LL | const UNINIT_INT_0: [u32; 3] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected an integer
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
= note: the raw bytes of the constant (size: 12, align: 4) {
|
||||
__ __ __ __ 01 00 00 00 02 00 00 00 │ ░░░░........
|
||||
}
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:24:1
|
||||
|
|
||||
LL | const UNINIT_INT_1: [u32; 3] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
= note: the raw bytes of the constant (size: 12, align: 4) {
|
||||
00 00 00 00 01 __ 01 01 02 02 __ 02 │ .....░....░.
|
||||
}
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:42:1
|
||||
|
|
||||
LL | const UNINIT_INT_2: [u32; 3] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [2]: encountered uninitialized memory, but expected an integer
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
= note: the raw bytes of the constant (size: 12, align: 4) {
|
||||
00 00 00 00 01 01 01 01 02 02 02 __ │ ...........░
|
||||
}
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
@ -1,4 +1,3 @@
|
||||
// stderr-per-bitwidth
|
||||
//! Test the "array of int" fast path in validity checking, and in particular whether it
|
||||
//! points at the right array element.
|
||||
|
||||
@ -19,7 +18,12 @@ impl<T: Copy> MaybeUninit<T> {
|
||||
const UNINIT_INT_0: [u32; 3] = unsafe {
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
//~| invalid value at [0]
|
||||
mem::transmute([MaybeUninit { uninit: () }, MaybeUninit::new(1), MaybeUninit::new(2)])
|
||||
mem::transmute([
|
||||
MaybeUninit { uninit: () },
|
||||
// Constants chosen to achieve endianness-independent hex dump.
|
||||
MaybeUninit::new(0x11111111),
|
||||
MaybeUninit::new(0x22222222),
|
||||
])
|
||||
};
|
||||
const UNINIT_INT_1: [u32; 3] = unsafe {
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
|
@ -1,16 +1,16 @@
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:19:1
|
||||
--> $DIR/ub-int-array.rs:18:1
|
||||
|
|
||||
LL | const UNINIT_INT_0: [u32; 3] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected an integer
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
= note: the raw bytes of the constant (size: 12, align: 4) {
|
||||
__ __ __ __ 01 00 00 00 02 00 00 00 │ ░░░░........
|
||||
__ __ __ __ 11 11 11 11 22 22 22 22 │ ░░░░....""""
|
||||
}
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:24:1
|
||||
--> $DIR/ub-int-array.rs:28:1
|
||||
|
|
||||
LL | const UNINIT_INT_1: [u32; 3] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
|
||||
@ -21,7 +21,7 @@ LL | const UNINIT_INT_1: [u32; 3] = unsafe {
|
||||
}
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:42:1
|
||||
--> $DIR/ub-int-array.rs:46:1
|
||||
|
|
||||
LL | const UNINIT_INT_2: [u32; 3] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [2]: encountered uninitialized memory, but expected an integer
|
18
tests/ui/rfcs/rfc-2294-if-let-guard/exhaustive.rs
Normal file
18
tests/ui/rfcs/rfc-2294-if-let-guard/exhaustive.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#![feature(if_let_guard)]
|
||||
#![allow(irrefutable_let_patterns)]
|
||||
|
||||
fn match_option(x: Option<u32>) {
|
||||
match x {
|
||||
//~^ ERROR non-exhaustive patterns: `None` not covered
|
||||
Some(_) => {}
|
||||
None if let y = x => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = ();
|
||||
match x {
|
||||
//~^ ERROR non-exhaustive patterns: `()` not covered
|
||||
y if let z = y => {}
|
||||
}
|
||||
}
|
35
tests/ui/rfcs/rfc-2294-if-let-guard/exhaustive.stderr
Normal file
35
tests/ui/rfcs/rfc-2294-if-let-guard/exhaustive.stderr
Normal file
@ -0,0 +1,35 @@
|
||||
error[E0004]: non-exhaustive patterns: `None` not covered
|
||||
--> $DIR/exhaustive.rs:5:11
|
||||
|
|
||||
LL | match x {
|
||||
| ^ pattern `None` not covered
|
||||
|
|
||||
note: `Option<u32>` defined here
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
::: $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: not covered
|
||||
= note: the matched value is of type `Option<u32>`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ None if let y = x => {},
|
||||
LL + None => todo!()
|
||||
|
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `()` not covered
|
||||
--> $DIR/exhaustive.rs:14:11
|
||||
|
|
||||
LL | match x {
|
||||
| ^ pattern `()` not covered
|
||||
|
|
||||
= note: the matched value is of type `()`
|
||||
= note: match arms with guards don't count towards exhaustivity
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ y if let z = y => {},
|
||||
LL + () => todo!()
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
15
tests/ui/rfcs/rfc-2294-if-let-guard/guard-lifetime-1.rs
Normal file
15
tests/ui/rfcs/rfc-2294-if-let-guard/guard-lifetime-1.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// References to by-move bindings in an if-let guard *cannot* be used after the guard.
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
|
||||
fn main() {
|
||||
let x: Option<Option<String>> = Some(Some(String::new()));
|
||||
match x {
|
||||
Some(mut y) if let Some(ref z) = y => {
|
||||
//~^ ERROR: cannot move out of `x.0` because it is borrowed
|
||||
let _z: &String = z;
|
||||
let _y: Option<String> = y;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
15
tests/ui/rfcs/rfc-2294-if-let-guard/guard-lifetime-1.stderr
Normal file
15
tests/ui/rfcs/rfc-2294-if-let-guard/guard-lifetime-1.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error[E0505]: cannot move out of `x.0` because it is borrowed
|
||||
--> $DIR/guard-lifetime-1.rs:8:14
|
||||
|
|
||||
LL | Some(mut y) if let Some(ref z) = y => {
|
||||
| ^^^^^
|
||||
| |
|
||||
| move out of `x.0` occurs here
|
||||
| borrow of `x.0` occurs here
|
||||
LL |
|
||||
LL | let _z: &String = z;
|
||||
| - borrow later used here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0505`.
|
16
tests/ui/rfcs/rfc-2294-if-let-guard/guard-lifetime-2.rs
Normal file
16
tests/ui/rfcs/rfc-2294-if-let-guard/guard-lifetime-2.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// References to by-mutable-ref bindings in an if-let guard *can* be used after the guard.
|
||||
|
||||
// check-pass
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
|
||||
fn main() {
|
||||
let mut x: Option<Option<String>> = Some(Some(String::new()));
|
||||
match x {
|
||||
Some(ref mut y) if let Some(ref z) = *y => {
|
||||
let _z: &String = z;
|
||||
let _y: &mut Option<String> = y;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
14
tests/ui/rfcs/rfc-2294-if-let-guard/guard-mutability-1.rs
Normal file
14
tests/ui/rfcs/rfc-2294-if-let-guard/guard-mutability-1.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Check mutable bindings cannot be mutated by an if-let guard.
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
|
||||
fn main() {
|
||||
let x: Option<Option<i32>> = Some(Some(6));
|
||||
match x {
|
||||
Some(mut y) if let Some(ref mut z) = y => {
|
||||
//~^ ERROR cannot borrow `y.0` as mutable, as it is immutable for the pattern guard
|
||||
let _: &mut i32 = z;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
error[E0596]: cannot borrow `y.0` as mutable, as it is immutable for the pattern guard
|
||||
--> $DIR/guard-mutability-1.rs:8:33
|
||||
|
|
||||
LL | Some(mut y) if let Some(ref mut z) = y => {
|
||||
| ^^^^^^^^^ cannot borrow as mutable
|
||||
|
|
||||
= note: variables bound in patterns are immutable until the end of the pattern guard
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0596`.
|
14
tests/ui/rfcs/rfc-2294-if-let-guard/guard-mutability-2.rs
Normal file
14
tests/ui/rfcs/rfc-2294-if-let-guard/guard-mutability-2.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Check mutable reference bindings cannot be mutated by an if-let guard.
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
|
||||
fn main() {
|
||||
let mut x: Option<Option<i32>> = Some(Some(6));
|
||||
match x {
|
||||
Some(ref mut y) if let Some(ref mut z) = *y => {
|
||||
//~^ ERROR cannot borrow `y.0` as mutable, as it is immutable for the pattern guard
|
||||
let _: &mut i32 = z;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
error[E0596]: cannot borrow `y.0` as mutable, as it is immutable for the pattern guard
|
||||
--> $DIR/guard-mutability-2.rs:8:37
|
||||
|
|
||||
LL | Some(ref mut y) if let Some(ref mut z) = *y => {
|
||||
| ^^^^^^^^^ cannot borrow as mutable
|
||||
|
|
||||
= note: variables bound in patterns are immutable until the end of the pattern guard
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0596`.
|
16
tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.rs
Normal file
16
tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Expression macros can't expand to a let match guard.
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
macro_rules! m {
|
||||
($e:expr) => { let Some(x) = $e }
|
||||
//~^ ERROR expected expression, found `let` statement
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match () {
|
||||
() if m!(Some(5)) => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
13
tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr
Normal file
13
tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr
Normal file
@ -0,0 +1,13 @@
|
||||
error: expected expression, found `let` statement
|
||||
--> $DIR/macro-expanded.rs:7:20
|
||||
|
|
||||
LL | ($e:expr) => { let Some(x) = $e }
|
||||
| ^^^
|
||||
...
|
||||
LL | () if m!(Some(5)) => {}
|
||||
| ----------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
27
tests/ui/rfcs/rfc-2294-if-let-guard/parens.rs
Normal file
27
tests/ui/rfcs/rfc-2294-if-let-guard/parens.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// Parenthesised let "expressions" are not allowed in guards
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
#[cfg(FALSE)]
|
||||
fn un_cfged() {
|
||||
match () {
|
||||
() if let 0 = 1 => {}
|
||||
() if (let 0 = 1) => {}
|
||||
//~^ ERROR expected expression, found `let` statement
|
||||
() if (((let 0 = 1))) => {}
|
||||
//~^ ERROR expected expression, found `let` statement
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match () {
|
||||
() if let 0 = 1 => {}
|
||||
() if (let 0 = 1) => {}
|
||||
//~^ ERROR expected expression, found `let` statement
|
||||
//~| ERROR `let` expressions are not supported here
|
||||
() if (((let 0 = 1))) => {}
|
||||
//~^ ERROR expected expression, found `let` statement
|
||||
//~| ERROR `let` expressions are not supported here
|
||||
}
|
||||
}
|
52
tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr
Normal file
52
tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr
Normal file
@ -0,0 +1,52 @@
|
||||
error: expected expression, found `let` statement
|
||||
--> $DIR/parens.rs:10:16
|
||||
|
|
||||
LL | () if (let 0 = 1) => {}
|
||||
| ^^^
|
||||
|
||||
error: expected expression, found `let` statement
|
||||
--> $DIR/parens.rs:12:18
|
||||
|
|
||||
LL | () if (((let 0 = 1))) => {}
|
||||
| ^^^
|
||||
|
||||
error: expected expression, found `let` statement
|
||||
--> $DIR/parens.rs:20:16
|
||||
|
|
||||
LL | () if (let 0 = 1) => {}
|
||||
| ^^^
|
||||
|
||||
error: expected expression, found `let` statement
|
||||
--> $DIR/parens.rs:23:18
|
||||
|
|
||||
LL | () if (((let 0 = 1))) => {}
|
||||
| ^^^
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/parens.rs:20:16
|
||||
|
|
||||
LL | () if (let 0 = 1) => {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: only supported directly in conditions of `if` and `while` expressions
|
||||
note: `let`s wrapped in parentheses are not supported in a context with let chains
|
||||
--> $DIR/parens.rs:20:16
|
||||
|
|
||||
LL | () if (let 0 = 1) => {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/parens.rs:23:18
|
||||
|
|
||||
LL | () if (((let 0 = 1))) => {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: only supported directly in conditions of `if` and `while` expressions
|
||||
note: `let`s wrapped in parentheses are not supported in a context with let chains
|
||||
--> $DIR/parens.rs:23:18
|
||||
|
|
||||
LL | () if (((let 0 = 1))) => {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
@ -0,0 +1,18 @@
|
||||
// Macros can be used for (parts of) the pattern and expression in an if let guard
|
||||
// check-pass
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
macro_rules! m {
|
||||
(pattern $i:ident) => { Some($i) };
|
||||
(expression $e:expr) => { $e };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match () {
|
||||
() if let m!(pattern x) = m!(expression Some(4)) => {}
|
||||
() if let [m!(pattern y)] = [Some(8 + m!(expression 4))] => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
23
tests/ui/rfcs/rfc-2294-if-let-guard/shadowing.rs
Normal file
23
tests/ui/rfcs/rfc-2294-if-let-guard/shadowing.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Check shadowing in if let guards works as expected.
|
||||
// check-pass
|
||||
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
fn main() {
|
||||
let x: Option<Option<i32>> = Some(Some(6));
|
||||
match x {
|
||||
Some(x) if let Some(x) = x => {
|
||||
let _: i32 = x;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let y: Option<Option<Option<i32>>> = Some(Some(Some(-24)));
|
||||
match y {
|
||||
Some(y) if let Some(y) = y && let Some(y) = y => {
|
||||
let _: i32 = y;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user