Skip to content

Commit 3ada3d8

Browse files
bors[bot]CohenArthurphilberty
authored
Merge #1022 #1033
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 <[email protected]> Co-authored-by: Philip Herron <[email protected]>
3 parents fe13ad4 + b6b5671 + 6e385d2 commit 3ada3d8

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

gcc/rust/ast/rust-ast.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ struct Literal
249249
BYTE_STRING,
250250
INT,
251251
FLOAT,
252-
BOOL
252+
BOOL,
253+
ERROR
253254
};
254255

255256
private:
@@ -274,11 +275,11 @@ struct Literal
274275

275276
static Literal create_error ()
276277
{
277-
return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN);
278+
return Literal ("", ERROR, PrimitiveCoreType::CORETYPE_UNKNOWN);
278279
}
279280

280281
// Returns whether literal is in an invalid state.
281-
bool is_error () const { return value_as_string == ""; }
282+
bool is_error () const { return type == ERROR; }
282283
};
283284

284285
/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to

gcc/rust/hir/rust-ast-lower-expr.h

+4
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ class ASTLoweringExpr : public ASTLoweringBase
359359
case AST::Literal::LitType::BOOL:
360360
type = HIR::Literal::LitType::BOOL;
361361
break;
362+
// Error literals should have been stripped during expansion
363+
case AST::Literal::LitType::ERROR:
364+
gcc_unreachable ();
365+
break;
362366
}
363367
auto crate_num = mappings->get_current_crate ();
364368
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),

gcc/rust/typecheck/rust-tyty-cmp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ class PointerCmp : public BaseCmp
12401240
: BaseCmp (base, emit_errors), base (base)
12411241
{}
12421242

1243-
void visit (const ReferenceType &type) override
1243+
void visit (const PointerType &type) override
12441244
{
12451245
auto base_type = base->get_base ();
12461246
auto other_base_type = type.get_base ();
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extern "rust-intrinsic" {
2+
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
3+
}
4+
5+
#[lang = "const_ptr"]
6+
impl<T> *const T {
7+
pub const unsafe fn offset(self, count: isize) -> *const T {
8+
// { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
9+
unsafe { offset(self, count) }
10+
}
11+
12+
pub const unsafe fn add(self, count: usize) -> Self {
13+
// { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
14+
unsafe { self.offset(count as isize) }
15+
}
16+
}
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
fn foo (e: &str) -> &str {
2-
&"" // { dg-bogus "cannot strip expression in this position - outer attributes not allowed" "#391" { xfail *-*-* } }
1+
// { dg-additional-options "-w" }
2+
3+
fn foo(e: &str) -> &str { // { dg-bogus "expected" "#391" { xfail *-*-* } }
4+
&"" // { dg-bogus "expected" "#391" { xfail *-*-* } }
35
}

0 commit comments

Comments
 (0)