diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock new file mode 100644 index 000000000000..f7cbd414caf5 --- /dev/null +++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock @@ -0,0 +1,39 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "datafrog" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69" + +[[package]] +name = "ffi-polonius" +version = "0.1.0" +dependencies = [ + "polonius-engine", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "polonius-engine" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4e8e505342045d397d0b6674dcb82d6faf5cf40484d30eeb88fc82ef14e903f" +dependencies = [ + "datafrog", + "log", + "rustc-hash", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index 47e4ad872319..2b2c44a8ea8c 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -21,6 +21,7 @@ #include "rust-attribute-values.h" #include "rust-ast-visitor.h" #include "rust-feature.h" +#include "rust-ast-full.h" namespace Rust { @@ -75,16 +76,17 @@ FeatureGate::gate (Feature::Name name, location_t loc, if (!valid_features.count (name)) { auto feature = Feature::create (name); - auto issue = feature.issue (); - if (issue > 0) + if (auto issue = feature.issue ()) { + auto issue_number = issue.value (); const char *fmt_str = "%s. see issue %u " " for more " "information. add `#![feature(%s)]` to the crate attributes to " "enable."; rust_error_at (loc, ErrorCode::E0658, fmt_str, error_msg.c_str (), - issue, issue, feature.as_string ().c_str ()); + issue_number, issue_number, + feature.as_string ().c_str ()); } else { @@ -169,7 +171,7 @@ FeatureGate::visit (AST::TraitImpl &impl) "negative_impls are not yet implemented"); AST::DefaultASTVisitor::visit (impl); -}; +} void FeatureGate::visit (AST::BoxExpr &expr) diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 5d02504d9d27..f8a9db78d201 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -20,7 +20,6 @@ #define RUST_FEATURE_GATE_H #include "rust-ast-visitor.h" -#include "rust-ast-full.h" #include "rust-feature.h" namespace Rust { @@ -35,153 +34,18 @@ class FeatureGate : public AST::DefaultASTVisitor void check (AST::Crate &crate); void visit (AST::Crate &crate) override; - void visit (AST::Token &tok) override {} - void visit (AST::DelimTokenTree &delim_tok_tree) override {} - void visit (AST::AttrInputMetaItemContainer &input) override {} - void visit (AST::IdentifierExpr &ident_expr) override {} - void visit (AST::Lifetime &lifetime) override {} void visit (AST::LifetimeParam &lifetime_param) override; void visit (AST::ConstGenericParam &const_param) override; - void visit (AST::PathInExpression &path) override {} - void visit (AST::TypePathSegment &segment) override {} - void visit (AST::TypePathSegmentGeneric &segment) override {} - void visit (AST::TypePathSegmentFunction &segment) override {} - void visit (AST::TypePath &path) override {} - void visit (AST::QualifiedPathInExpression &path) override {} - void visit (AST::QualifiedPathInType &path) override {} - void visit (AST::LiteralExpr &expr) override {} - void visit (AST::AttrInputLiteral &attr_input) override {} - void visit (AST::AttrInputMacro &attr_input) override {} - void visit (AST::MetaItemLitExpr &meta_item) override {} - void visit (AST::MetaItemPathLit &meta_item) override {} void visit (AST::BorrowExpr &expr) override; - void visit (AST::DereferenceExpr &expr) override {} - void visit (AST::ErrorPropagationExpr &expr) override {} - void visit (AST::NegationExpr &expr) override {} - void visit (AST::ArithmeticOrLogicalExpr &expr) override {} - void visit (AST::ComparisonExpr &expr) override {} - void visit (AST::LazyBooleanExpr &expr) override {} - void visit (AST::TypeCastExpr &expr) override {} - void visit (AST::AssignmentExpr &expr) override {} - void visit (AST::CompoundAssignmentExpr &expr) override {} - void visit (AST::GroupedExpr &expr) override {} - void visit (AST::ArrayElemsValues &elems) override {} - void visit (AST::ArrayElemsCopied &elems) override {} - void visit (AST::ArrayExpr &expr) override {} - void visit (AST::ArrayIndexExpr &expr) override {} - void visit (AST::TupleExpr &expr) override {} - void visit (AST::TupleIndexExpr &expr) override {} - void visit (AST::StructExprStruct &expr) override {} - void visit (AST::StructExprFieldIdentifier &field) override {} - void visit (AST::StructExprFieldIdentifierValue &field) override {} - void visit (AST::StructExprFieldIndexValue &field) override {} - void visit (AST::StructExprStructFields &expr) override {} - void visit (AST::StructExprStructBase &expr) override {} - void visit (AST::CallExpr &expr) override {} - void visit (AST::MethodCallExpr &expr) override {} - void visit (AST::FieldAccessExpr &expr) override {} - void visit (AST::ClosureExprInner &expr) override {} - void visit (AST::ClosureExprInnerTyped &expr) override {} - void visit (AST::ContinueExpr &expr) override {} - void visit (AST::BreakExpr &expr) override {} - void visit (AST::RangeFromToExpr &expr) override {} - void visit (AST::RangeFromExpr &expr) override {} - void visit (AST::RangeToExpr &expr) override {} - void visit (AST::RangeFullExpr &expr) override {} - void visit (AST::RangeFromToInclExpr &expr) override {} - void visit (AST::RangeToInclExpr &expr) override {} - void visit (AST::ReturnExpr &expr) override {} void visit (AST::BoxExpr &expr) override; - void visit (AST::UnsafeBlockExpr &expr) override {} - void visit (AST::LoopExpr &expr) override {} - void visit (AST::WhileLoopExpr &expr) override {} - void visit (AST::WhileLetLoopExpr &expr) override {} - void visit (AST::ForLoopExpr &expr) override {} - void visit (AST::IfExpr &expr) override {} - void visit (AST::IfExprConseqElse &expr) override {} - void visit (AST::IfLetExprConseqElse &expr) override {} - void visit (AST::AwaitExpr &expr) override {} - void visit (AST::AsyncBlockExpr &expr) override {} void visit (AST::TypeParam ¶m) override; - void visit (AST::LifetimeWhereClauseItem &item) override {} - void visit (AST::TypeBoundWhereClauseItem &item) override {} - void visit (AST::Module &module) override {} - void visit (AST::ExternCrate &crate) override {} void visit (AST::UseTreeGlob &use_tree) override; - void visit (AST::UseTreeList &use_tree) override {} - void visit (AST::UseTreeRebind &use_tree) override {} - void visit (AST::UseDeclaration &use_decl) override {} void visit (AST::Function &function) override; - void visit (AST::TypeAlias &type_alias) override {} - void visit (AST::StructStruct &struct_item) override {} - void visit (AST::TupleStruct &tuple_struct) override {} - void visit (AST::EnumItem &item) override {} - void visit (AST::EnumItemTuple &item) override {} - void visit (AST::EnumItemStruct &item) override {} - void visit (AST::EnumItemDiscriminant &item) override {} - void visit (AST::Enum &enum_item) override {} - void visit (AST::Union &union_item) override {} - void visit (AST::ConstantItem &const_item) override {} - void visit (AST::StaticItem &static_item) override {} - void visit (AST::TraitItemConst &item) override {} - void visit (AST::TraitItemType &item) override {} void visit (AST::TraitImpl &impl) override; - void visit (AST::Trait &trait) override {} void visit (AST::ExternalTypeItem &item) override; - void visit (AST::ExternalStaticItem &item) override {} void visit (AST::ExternBlock &block) override; - void visit (AST::MacroMatchFragment &match) override {} - void visit (AST::MacroMatchRepetition &match) override {} - void visit (AST::MacroMatcher &matcher) override {} void visit (AST::MacroRulesDefinition &rules_def) override; - void visit (AST::MacroInvocation ¯o_invoc) override {} - void visit (AST::MetaItemPath &meta_item) override {} - void visit (AST::MetaItemSeq &meta_item) override {} - void visit (AST::MetaWord &meta_item) override {} - void visit (AST::MetaNameValueStr &meta_item) override {} - void visit (AST::MetaListPaths &meta_item) override {} - void visit (AST::MetaListNameValueStr &meta_item) override {} - void visit (AST::LiteralPattern &pattern) override {} - void visit (AST::IdentifierPattern &pattern) override {} - void visit (AST::WildcardPattern &pattern) override {} - void visit (AST::RestPattern &pattern) override {} - void visit (AST::RangePatternBoundLiteral &bound) override {} - void visit (AST::RangePatternBoundPath &bound) override {} - void visit (AST::RangePatternBoundQualPath &bound) override {} void visit (AST::RangePattern &pattern) override; - void visit (AST::ReferencePattern &pattern) override {} - void visit (AST::StructPatternFieldTuplePat &field) override {} - void visit (AST::StructPatternFieldIdentPat &field) override {} - void visit (AST::StructPatternFieldIdent &field) override {} - void visit (AST::StructPattern &pattern) override {} - void visit (AST::TupleStructItemsNoRange &tuple_items) override {} - void visit (AST::TupleStructItemsRange &tuple_items) override {} - void visit (AST::TupleStructPattern &pattern) override {} - void visit (AST::TuplePatternItemsMultiple &tuple_items) override {} - void visit (AST::TuplePatternItemsRanged &tuple_items) override {} - void visit (AST::TuplePattern &pattern) override {} - void visit (AST::GroupedPattern &pattern) override {} - void visit (AST::SlicePattern &pattern) override {} - void visit (AST::AltPattern &pattern) override {} - void visit (AST::EmptyStmt &stmt) override {} - void visit (AST::ExprStmt &stmt) override {} - void visit (AST::TraitBound &bound) override {} - void visit (AST::ImplTraitType &type) override {} - void visit (AST::TraitObjectType &type) override {} - void visit (AST::ParenthesisedType &type) override {} - void visit (AST::ImplTraitTypeOneBound &type) override {} - void visit (AST::TraitObjectTypeOneBound &type) override {} - void visit (AST::TupleType &type) override {} - void visit (AST::NeverType &type) override {} - void visit (AST::RawPointerType &type) override {} - void visit (AST::ReferenceType &type) override {} - void visit (AST::ArrayType &type) override {} - void visit (AST::SliceType &type) override {} - void visit (AST::InferredType &type) override {} - void visit (AST::BareFunctionType &type) override {} - void visit (AST::FunctionParam ¶m) override {} - void visit (AST::VariadicParam ¶m) override {} - void visit (AST::SelfParam ¶m) override {} private: void gate (Feature::Name name, location_t loc, const std::string &error_msg); diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc index 587f0e58b8a7..3fab5e5aedcc 100644 --- a/gcc/rust/checks/errors/rust-feature.cc +++ b/gcc/rust/checks/errors/rust-feature.cc @@ -17,50 +17,44 @@ // . #include "rust-feature.h" -#include "rust-session-manager.h" namespace Rust { Feature -Feature::create (Feature::Name name) +Feature::create (Feature::Name f) { - switch (name) + switch (f) { case Feature::Name::ASSOCIATED_TYPE_BOUNDS: return Feature (Feature::Name::ASSOCIATED_TYPE_BOUNDS, Feature::State::ACCEPTED, "associated_type_bounds", - "1.34.0", 52662, tl::nullopt, ""); + "1.34.0", 52662); case Feature::Name::INTRINSICS: - return Feature (Feature::Name::INTRINSICS, Feature::State::ACCEPTED, - "intrinsics", "1.0.0", 0, tl::nullopt, ""); + return Feature (f, Feature::State::ACCEPTED, "intrinsics", "1.0.0"); case Feature::Name::RUSTC_ATTRS: - return Feature (Feature::Name::RUSTC_ATTRS, Feature::State::ACCEPTED, - "rustc_attrs", "1.0.0", 0, tl::nullopt, ""); + return Feature (f, Feature::State::ACCEPTED, "rustc_attrs", "1.0.0"); case Feature::Name::DECL_MACRO: - return Feature (Feature::Name::DECL_MACRO, Feature::State::ACCEPTED, - "decl_macro", "1.0.0", 0, tl::nullopt, ""); + return Feature (f, Feature::State::ACCEPTED, "decl_macro", "1.0.0", + 39412); case Feature::Name::EXTERN_TYPES: - return Feature (Feature::Name::EXTERN_TYPES, Feature::State::ACTIVE, - "extern_types", "1.23.0", 43467, tl::nullopt, ""); + return Feature (f, Feature::State::ACTIVE, "extern_types", "1.23.0", + 43467); case Feature::Name::NEGATIVE_IMPLS: - return Feature (Feature::Name::NEGATIVE_IMPLS, Feature::State::ACTIVE, - "negative_impls", "1.0.0", 68318, tl::nullopt, ""); + return Feature (f, Feature::State::ACTIVE, "negative_impls", "1.0.0", + 68318); case Feature::Name::BOX_SYNTAX: - return Feature (Feature::Name::BOX_SYNTAX, Feature::State::ACTIVE, - "box_syntax", "1.0.0", 49733, tl::nullopt, ""); + return Feature (f, Feature::State::ACTIVE, "box_syntax", "1.0.0", 49733); case Feature::Name::DROPCK_EYEPATCH: - return Feature (Feature::Name::DROPCK_EYEPATCH, Feature::State::ACTIVE, - "dropck_eyepatch", "1.10.0", 34761, tl::nullopt, ""); + return Feature (f, Feature::State::ACTIVE, "dropck_eyepatch", "1.10.0", + 34761); case Feature::Name::RAW_REF_OP: - return Feature (Feature::Name::RAW_REF_OP, Feature::State::ACTIVE, - "raw_ref_op", "1.41.0", 64490, tl::nullopt, ""); + return Feature (f, Feature::State::ACTIVE, "raw_ref_op", "1.41.0", 64490); case Feature::Name::EXCLUSIVE_RANGE_PATTERN: return Feature (Feature::Name::EXCLUSIVE_RANGE_PATTERN, Feature::State::ACTIVE, "exclusive_range_pattern", - "1.11.0", 37854, tl::nullopt, ""); + "1.11.0", 37854); case Feature::Name::PRELUDE_IMPORT: - return Feature (Feature::Name::PRELUDE_IMPORT, Feature::State::ACTIVE, - "prelude_import", "1.0.0", 0, tl::nullopt, ""); + return Feature (f, Feature::State::ACTIVE, "prelude_import", "1.0.0"); default: rust_unreachable (); } diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h index 482c933b0bd8..b4e5f2cef077 100644 --- a/gcc/rust/checks/errors/rust-feature.h +++ b/gcc/rust/checks/errors/rust-feature.h @@ -57,16 +57,17 @@ class Feature Name name () { return m_name; } const std::string &description () { return m_description; } State state () { return m_state; } - unsigned issue () { return m_issue; } + tl::optional issue () { return m_issue; } static tl::optional as_name (const std::string &name); static Feature create (Name name); private: Feature (Name name, State state, const char *name_str, - const char *rustc_since, unsigned issue_number, - const tl::optional &edition, - const char *description) + const char *rustc_since, + tl::optional issue_number = tl::nullopt, + const tl::optional &edition = tl::nullopt, + const char *description = "") : m_state (state), m_name (name), m_name_str (name_str), m_rustc_since (rustc_since), m_issue (issue_number), edition (edition), m_description (description) @@ -76,9 +77,9 @@ class Feature Name m_name; std::string m_name_str; std::string m_rustc_since; - unsigned m_issue; + tl::optional m_issue; tl::optional edition; - std::string m_description; + std::string m_description; // TODO: Switch to optional? static const std::map name_hash_map; }; diff --git a/gcc/testsuite/rust/compile/assume.rs b/gcc/testsuite/rust/compile/assume.rs index 4dc2fefa86ac..f7e0bc855d0a 100644 --- a/gcc/testsuite/rust/compile/assume.rs +++ b/gcc/testsuite/rust/compile/assume.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + mod intrinsics { extern "rust-intrinsic" { pub fn assume(value: bool); diff --git a/gcc/testsuite/rust/compile/issue-1901.rs b/gcc/testsuite/rust/compile/issue-1901.rs index dd41ff89346d..cfd8ef44fcc5 100644 --- a/gcc/testsuite/rust/compile/issue-1901.rs +++ b/gcc/testsuite/rust/compile/issue-1901.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/issue-1981.rs b/gcc/testsuite/rust/compile/issue-1981.rs index b1637ac02602..bfd8d2c3417d 100644 --- a/gcc/testsuite/rust/compile/issue-1981.rs +++ b/gcc/testsuite/rust/compile/issue-1981.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs b/gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs index a5f0c2b78fb4..827569170347 100644 --- a/gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs +++ b/gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-8.rs b/gcc/testsuite/rust/compile/torture/intrinsics-8.rs index deb19bd431cd..b9bd83c76240 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-8.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-8.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/torture/transmute-size-check-1.rs b/gcc/testsuite/rust/compile/torture/transmute-size-check-1.rs index 6d34fb1b0245..7b987797d493 100644 --- a/gcc/testsuite/rust/compile/torture/transmute-size-check-1.rs +++ b/gcc/testsuite/rust/compile/torture/transmute-size-check-1.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/torture/transmute1.rs b/gcc/testsuite/rust/compile/torture/transmute1.rs index b2a0d07a3d7c..be9fb1de56da 100644 --- a/gcc/testsuite/rust/compile/torture/transmute1.rs +++ b/gcc/testsuite/rust/compile/torture/transmute1.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/torture/uninit-intrinsic-1.rs b/gcc/testsuite/rust/compile/torture/uninit-intrinsic-1.rs index cbb92feb4954..fa329c694ad5 100644 --- a/gcc/testsuite/rust/compile/torture/uninit-intrinsic-1.rs +++ b/gcc/testsuite/rust/compile/torture/uninit-intrinsic-1.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/execute/torture/issue-1436.rs b/gcc/testsuite/rust/execute/torture/issue-1436.rs index 4e6996132de9..5d909078b5ec 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1436.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1436.rs @@ -1,4 +1,7 @@ // { dg-options "-w" } + +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/execute/torture/issue-2583.rs b/gcc/testsuite/rust/execute/torture/issue-2583.rs index 46f501ee2d1f..4ff12fca49e7 100644 --- a/gcc/testsuite/rust/execute/torture/issue-2583.rs +++ b/gcc/testsuite/rust/execute/torture/issue-2583.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {}