Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ Crate::as_string () const
return str + "\n";
}

void
Crate::inject_extern_crate (std::string name)
{
items.push_back (std::make_unique<AST::ExternCrate> (
AST::ExternCrate (name, AST::Visibility::create_public (UNKNOWN_LOCATION),
{}, UNKNOWN_LOCATION)));
}

std::string
Attribute::as_string () const
{
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,8 @@ struct Crate : public GlobContainer
// TODO: is this the best way to do this?
}

void inject_extern_crate (std::string name);

NodeId get_node_id () const { return node_id; }
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
Expand Down
15 changes: 15 additions & 0 deletions gcc/rust/rust-session-manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ validate_crate_name (const std::string &crate_name, Error &error)
return true;
}

static bool
has_attribute (AST::Crate crate, std::string attribute)
{
auto &crate_attrs = crate.get_inner_attrs ();
auto has_attr = [&attribute] (AST::Attribute &attr) {
return attr.as_string () == attribute;
};
return std::any_of (crate_attrs.begin (), crate_attrs.end (), has_attr);
}

void
Session::init ()
{
Expand Down Expand Up @@ -658,6 +668,11 @@ Session::compile_crate (const char *filename)

Analysis::AttributeChecker ().go (parsed_crate);

if (!has_attribute (parsed_crate, std::string (Values::Attributes::NO_CORE)))
{
parsed_crate.inject_extern_crate ("core");
}

if (last_step == CompileOptions::CompileStep::Expansion)
return;

Expand Down
1 change: 1 addition & 0 deletions gcc/rust/util/rust-attribute-values.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Attributes
static constexpr auto &MUST_USE = "must_use";
static constexpr auto &LANG = "lang";
static constexpr auto &LINK_NAME = "link_name";
static constexpr auto &NO_CORE = "no_core";
static constexpr auto &LINK_SECTION = "link_section";
static constexpr auto &NO_MANGLE = "no_mangle";
static constexpr auto &EXPORT_NAME = "export_name";
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/position_dependant_outlives.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck" }
#![feature(no_core)]
#![no_core]


pub fn position_dependent_outlives<'a>(x: &'a mut i32, cond: bool) -> &'a mut i32 {
let y = &mut *x;
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/reference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


#![feature(lang_items)]
#[lang = "sized"]
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/return_ref_to_local.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


pub fn return_ref_to_local() -> &'static i32 {
let x = 0;
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/subset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
// { dg-error "subset error, some lifetime constraints need to be added" "" { target *-*-* } .-1 }
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/test_move.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


fn test_move() {
struct A {
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/test_move_behind_reference.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck" }
#![feature(no_core)]
#![no_core]

fn test_move_behind_reference() {
// { dg-error "Cannot move from behind a reference." "" { target *-*-* } .-1 }
struct A {
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/test_move_conditional.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


fn test_move_conditional(b1: bool, b2:bool) {
struct A {
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/tmp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


#![feature(lang_items)]
#[lang = "sized"]
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/use_while_mut.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


pub fn use_while_mut() {
let mut x = 0;
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/use_while_mut_fr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]

pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
let y = &mut *x;
let z = x; //~ ERROR
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/borrowck/well_formed_function_inputs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }
#![feature(no_core)]
#![no_core]


fn foo<'a, 'b>(p: &'b &'a mut usize) -> &'b&'a mut usize {
p
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/abi-options1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

extern "foobar" {
// { dg-error "invalid ABI: found .foobar." "" { target *-*-* } .-1 }
fn printf(s: *const i8, ...);
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/abi-vardaic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// https://doc.rust-lang.org/error_codes/E0045.html
#![feature(no_core)]
#![no_core]

#![allow(unused)]
fn main() {
extern "Rust" {
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/additional-trait-bounds1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/additional-trait-bounds2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/additional-trait-bounds2nr2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/all-cast.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

fn main() {
let x = 5;
let x_is_nonzero = x as bool; // { dg-error "cannot cast .<integer>. as .bool." }
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/array3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

fn foo(state: &mut [u32; 16], a: usize) {
// { dg-warning "function is never used: .foo." "" { target *-*-* } .-1 }
state[a] = 1;
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/array4.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

pub fn foo() {
[0, 1, 2][1];
}
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/array_empty_list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

fn main() {
let arr = [];
// { dg-error "type annotations needed" "" { target *-*-* } .-1 }
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/arrays1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

fn main() {
let xs: [i32; 5] = [1, 2, 3, 4, 5];
let a: bool = xs[0]; // { dg-error "mismatched types, expected .bool. but got .i32." }
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/arrays2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

fn main() {
let array: [i32; 5] = [1, 2, 3];
// { dg-error "mismatched types, expected ..i32; 5.. but got ...integer.; 3.. .E0308." "" { target *-*-* } .-1 }
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/assume.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(intrinsics)]

mod intrinsics {
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr-macro.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

macro_rules! foo {
() => { #[cfg(all())] 12 }
}
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr-mismatch-crate-name.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// { dg-additional-options "-fdump-tree-gimple" }
#![feature(no_core)]
#![no_core]

#![crate_name = "specified_name"]
// { dg-final { scan-tree-dump-times {specified_name::main} 1 gimple } }
fn main() {}
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr_cold.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// { dg-additional-options "-fdump-tree-gimple" }
#![feature(no_core)]
#![no_core]

#[cold]
fn cold_function() -> i32 {
42
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr_deprecated.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#[deprecated(since="1.0", note="do not use this function")]
fn test1() {}

Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr_deprecated_2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#[deprecated(since="1.0")]
fn test1() {}

Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr_malformed_doc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

// { dg-error "valid forms for the attribute are ...doc.hidden.inline....... and ...doc = . string ..." "" { target *-*-* } .+1 }
#[doc]
trait MyTrait {}
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr_malformed_path.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#[cfg_attr(target_arch = "x86_64", path = (target_arch = "x86", path = "x86.rs"))]
mod imp {}
// { dg-error "malformed .path. attribute input" "" { target *-*-* } .-2 }
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/auto_trait.rs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#![feature(no_core)]
#![no_core]

auto trait Valid {} // { dg-error "auto traits are experimental and possibly buggy" }
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/auto_trait_invalid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// #![feature(auto_traits)] // not present in Rust 1.49 yet
#![feature(no_core)]
#![no_core]


#![feature(optin_builtin_traits)]

Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/auto_trait_super_trait.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(optin_builtin_traits)]
trait Cold {}

Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/auto_trait_valid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// #![feature(auto_traits)] // not present in Rust 1.49 yet
#![feature(no_core)]
#![no_core]


#![feature(optin_builtin_traits)]

Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/auto_traits1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// { dg-additional-options "-frust-compile-until=typecheck" }
#![feature(no_core)]
#![no_core]


#![feature(optin_builtin_traits, lang_items)]

Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/auto_traits2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/auto_traits4.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(optin_builtin_traits)]

unsafe auto trait Send {}
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/bad-crate-name1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// { dg-additional-options "-frust-crate=bad+name" }
// { dg-excess-errors "invalid crate name: ...." }
// { dg-excess-errors "unrecognized command-line option ...." }
#![feature(no_core)]
#![no_core]

fn main() {}
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/bad-crate-name2.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#![feature(no_core)]
#![no_core]

#![crate_name = "😅"] // { dg-error "invalid character ...." "" }
fn main() {}
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/bad-rpit1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/bad=file-name.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// { dg-additional-options "-fdump-tree-gimple -frust-crate=good_name" }
#![feature(no_core)]
#![no_core]

pub fn does_nothing() {}
fn main() {
does_nothing()
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/bad_as_bool_char.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

pub fn main ()
{
let t = true;
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/bad_file_name.txt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// { dg-excess-errors "invalid crate name: ...." }
// { dg-bogus "unrecognized command-line option ...." }
#![feature(no_core)]
#![no_core]

fn main() {}
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/bad_inner_doc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![feature(no_core)]
#![no_core]

pub fn main ()
{
//! inner doc allowed
Expand Down
Loading
Loading