Skip to content

Commit

Permalink
Merge #1022 #1033
Browse files Browse the repository at this point in the history
1022: attribute expansion: Fix spurious stripping of tail expression r=CohenArthur a=CohenArthur

This commit fixes the issue reported in #391, but highlights another
one, which will be reported.

Closes #391 

1033: Fix bad copy-paste in can equal interface for pointer types r=philberty a=philberty

When we perform method resolution we check if the self arguments can be
matched. Here the bug was that pointer types had a bad vistitor and only
could ever match reference types which is wrong and was a copy paste error.

Fixes #1031
Addresses #849 


Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
  • Loading branch information
3 people authored Mar 17, 2022
3 parents fe13ad4 + b6b5671 + 6e385d2 commit 3ada3d8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
7 changes: 4 additions & 3 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ struct Literal
BYTE_STRING,
INT,
FLOAT,
BOOL
BOOL,
ERROR
};

private:
Expand All @@ -274,11 +275,11 @@ struct Literal

static Literal create_error ()
{
return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN);
return Literal ("", ERROR, PrimitiveCoreType::CORETYPE_UNKNOWN);
}

// Returns whether literal is in an invalid state.
bool is_error () const { return value_as_string == ""; }
bool is_error () const { return type == ERROR; }
};

/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to
Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/hir/rust-ast-lower-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ class ASTLoweringExpr : public ASTLoweringBase
case AST::Literal::LitType::BOOL:
type = HIR::Literal::LitType::BOOL;
break;
// Error literals should have been stripped during expansion
case AST::Literal::LitType::ERROR:
gcc_unreachable ();
break;
}
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/typecheck/rust-tyty-cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ class PointerCmp : public BaseCmp
: BaseCmp (base, emit_errors), base (base)
{}

void visit (const ReferenceType &type) override
void visit (const PointerType &type) override
{
auto base_type = base->get_base ();
auto other_base_type = type.get_base ();
Expand Down
16 changes: 16 additions & 0 deletions gcc/testsuite/rust/compile/issue-1031.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extern "rust-intrinsic" {
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
}

#[lang = "const_ptr"]
impl<T> *const T {
pub const unsafe fn offset(self, count: isize) -> *const T {
// { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
unsafe { offset(self, count) }
}

pub const unsafe fn add(self, count: usize) -> Self {
// { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
unsafe { self.offset(count as isize) }
}
}
6 changes: 4 additions & 2 deletions gcc/testsuite/rust/compile/xfail/slice1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fn foo (e: &str) -> &str {
&"" // { dg-bogus "cannot strip expression in this position - outer attributes not allowed" "#391" { xfail *-*-* } }
// { dg-additional-options "-w" }

fn foo(e: &str) -> &str { // { dg-bogus "expected" "#391" { xfail *-*-* } }
&"" // { dg-bogus "expected" "#391" { xfail *-*-* } }
}

0 comments on commit 3ada3d8

Please sign in to comment.