mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 15:18:11 +00:00
Switch Ptr to a C++ pointer using the nonnull attribute (#831)
The advantage is a C++ pointer is special, and this approach eliminates the Ptr class type that was causing problems in conversions. Attribute suggestion was courtesy of chandlerc. We're sticking with the Ptr name because it's shorter than Nonnull, and we're likely to keep this in lots of places.
This commit is contained in:
1 parent
395a331cde
commit
ff319d311a
6 files changed
+28
-62
No files matched your search
@@ -39,7 +39,7 @@ TEST_F(ExpressionTest, EmptyAsExpression) {
|
||||
ParenContents<Expression> contents = {.elements = {},
|
||||
.has_trailing_comma = false};
|
||||
Ptr<const Expression> expression =
|
||||
ExpressionFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(expression->Tag(), Expression::Kind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*expression).Fields(), IsEmpty());
|
||||
@@ -48,8 +48,8 @@ TEST_F(ExpressionTest, EmptyAsExpression) {
|
||||
TEST_F(ExpressionTest, EmptyAsTuple) {
|
||||
ParenContents<Expression> contents = {.elements = {},
|
||||
.has_trailing_comma = false};
|
||||
Ptr<const Expression> tuple = TupleExpressionFromParenContents(
|
||||
PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
Ptr<const Expression> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->Tag(), Expression::Kind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).Fields(), IsEmpty());
|
||||
@@ -68,7 +68,7 @@ TEST_F(ExpressionTest, UnaryNoCommaAsExpression) {
|
||||
.has_trailing_comma = false};
|
||||
|
||||
Ptr<const Expression> expression =
|
||||
ExpressionFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->SourceLoc(), FakeSourceLoc(2));
|
||||
ASSERT_EQ(expression->Tag(), Expression::Kind::IntLiteral);
|
||||
}
|
||||
@@ -79,8 +79,8 @@ TEST_F(ExpressionTest, UnaryNoCommaAsTuple) {
|
||||
.term = arena.New<IntLiteral>(FakeSourceLoc(2), 42)}},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
Ptr<const Expression> tuple = TupleExpressionFromParenContents(
|
||||
PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
Ptr<const Expression> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->Tag(), Expression::Kind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).Fields(),
|
||||
@@ -94,7 +94,7 @@ TEST_F(ExpressionTest, UnaryWithCommaAsExpression) {
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const Expression> expression =
|
||||
ExpressionFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(expression->Tag(), Expression::Kind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*expression).Fields(),
|
||||
@@ -107,8 +107,8 @@ TEST_F(ExpressionTest, UnaryWithCommaAsTuple) {
|
||||
.term = arena.New<IntLiteral>(FakeSourceLoc(2), 42)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const Expression> tuple = TupleExpressionFromParenContents(
|
||||
PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
Ptr<const Expression> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->Tag(), Expression::Kind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).Fields(),
|
||||
@@ -124,7 +124,7 @@ TEST_F(ExpressionTest, BinaryAsExpression) {
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const Expression> expression =
|
||||
ExpressionFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
ExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(expression->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(expression->Tag(), Expression::Kind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*expression).Fields(),
|
||||
@@ -139,8 +139,8 @@ TEST_F(ExpressionTest, BinaryAsTuple) {
|
||||
.term = arena.New<IntLiteral>(FakeSourceLoc(3), 42)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const Expression> tuple = TupleExpressionFromParenContents(
|
||||
PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
Ptr<const Expression> tuple =
|
||||
TupleExpressionFromParenContents(&arena, FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_EQ(tuple->Tag(), Expression::Kind::TupleLiteral);
|
||||
EXPECT_THAT(cast<TupleLiteral>(*tuple).Fields(),
|
||||
|
||||
Reference in new issue
Block a user