mappings.get_next_hir_id (crate_num),
mappings.get_next_localdef_id (crate_num));
- auto trait_unsafety = Unsafety::Normal;
- if (trait.is_unsafe ())
- {
- trait_unsafety = Unsafety::Unsafe;
- }
+ auto trait_unsafety
+ = trait.is_unsafe () ? Unsafety::Unsafe : Unsafety::Normal;
HIR::Trait *hir_trait
= new HIR::Trait (mapping, trait.get_identifier (), trait_unsafety,
std::move (generic_params), std::move (type_param_bounds),
where_clause, std::move (trait_items), vis,
trait.get_outer_attrs (), trait.get_locus ());
+
+ if (trait.is_auto ())
+ mappings.insert_auto_trait (hir_trait);
+
translated = hir_trait;
for (auto trait_item_id : trait_item_ids)
// marker traits...
assemble_sized_builtin ();
+
+ // add auto trait bounds
+ for (auto *auto_trait : mappings.get_auto_traits ())
+ add_trait_bound (auto_trait);
}
void
LangItem::ToString (item_type).c_str ());
}
+void
+Mappings::insert_auto_trait (HIR::Trait *trait)
+{
+ auto_traits.emplace_back (trait);
+}
+
+std::vector<HIR::Trait *> &
+Mappings::get_auto_traits ()
+{
+ return auto_traits;
+}
+
} // namespace Analysis
} // namespace Rust
tl::optional<HIR::TraitItem *>
lookup_trait_item_lang_item (LangItem::Kind item, location_t locus);
+ void insert_auto_trait (HIR::Trait *trait);
+ std::vector<HIR::Trait *> &get_auto_traits ();
+
private:
Mappings ();
std::map<HirId, HIR::Trait *> hirTraitItemsToTraitMappings;
std::map<HirId, HIR::Pattern *> hirPatternMappings;
+ // FIXME: Add documentation
+ std::vector<HIR::Trait *> auto_traits;
+
// We need to have two maps here, as lang-items need to be used for both AST
// passes and HIR passes. Thus those two maps are created at different times.
std::map<LangItem::Kind, DefId> lang_item_mappings;
struct S;
impl A for S {
- fn a_method(&self) {}
+ fn a_method(&self) {} // { dg-warning "unused name" }
}
fn main() {
let s = S;
- foo(&s); // { dg-error "bounds not satisfied" }
- // { dg-error "mismatched type" "" { target *-*-* } .-1 }
+ foo(&s);
}
+++ /dev/null
-#![feature(optin_builtin_traits)]
-
-pub unsafe auto trait Send {}
-#[lang = "sync"]
-pub unsafe auto trait Sync {}
-
-trait A {
- fn a_method(&self) {}
-}
-
-fn foo(a: &(dyn A + Send + Sync)) {
- a.a_method();
-}
-
-struct S;
-
-impl A for S {
- fn a_method(&self) {} // { dg-warning "unused" }
-}
-
-// These should not be necessary because they are both auto traits
-// They need to be removed once we figure out the proper implementation for each of them
-// However, it'd be silly to implement other traits in order to ensure the test is okay,
-// as these extra trait bounds are only allowed to use auto traits
-// FIXME: #3327
-// FIXME: #3326
-unsafe impl Send for S {}
-unsafe impl Sync for S {}
-
-fn main() {
- let s = S;
-
- foo(&s);
-}
--- /dev/null
+#![feature(optin_builtin_traits)]
+
+unsafe auto trait Send {}
+unsafe auto trait Sync {}
+
+fn take_send(_: &dyn Send) {}
+fn take_sync(_: &dyn Sync) {}
+
+fn main() {
+ let a = i32;
+
+ take_send(&a);
+ take_sync(&a);
+}
issue-2423.rs
issue-266.rs
additional-trait-bounds2.rs
-auto_traits3.rs
+auto_traits2.rs
+auto_traits4.rs
issue-3140.rs
cmp1.rs
derive_clone_enum1.rs