Skip to content

Commit a7471f5

Browse files
committed
Bump Rust 1.22 version, get new sources
* '..=' token replaces '...' for inclusive range syntax * support parens around trait bounds * fix diff bug around floating literals like '1.'
1 parent 5f49d0c commit a7471f5

File tree

10 files changed

+45
-14
lines changed

10 files changed

+45
-14
lines changed

get-rust-sources.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ done;
6969
cd ..
7070
rm -rf $TEMP
7171

72+
# Print disclaimer
73+
echo "WARNING: Don't expect the 'rustc-tests' suite to necessarily"
74+
echo " work on all the files this produces. A failure in the"
75+
echo " test suite is only a bug if `rustc` succeeds on the"
76+
echo " same file."
77+

src/Language/Rust/Parser/Internal.y

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import qualified Data.List.NonEmpty as N
9898
-- Structural symbols.
9999
'@' { Spanned At _ }
100100
'...' { Spanned DotDotDot _ }
101+
'..=' { Spanned DotDotEqual _ }
101102
'..' { Spanned DotDot _ }
102103
'.' { Spanned Dot _ }
103104
',' { Spanned Comma _ }
@@ -267,7 +268,7 @@ import qualified Data.List.NonEmpty as N
267268
%nonassoc INFIXRNG
268269
%nonassoc POSTFIXRNG
269270
%nonassoc PREFIXRNG
270-
%nonassoc '..' '...'
271+
%nonassoc '..' '...' '..='
271272
%left '||'
272273
%left '&&'
273274
%left '==' '!=' '<' '>' '<=' '>='
@@ -636,8 +637,9 @@ fn_decl_with_self_named :: { FnDecl Span }
636637

637638
-- parse_ty_param_bounds(BoundParsingMode::Bare) == sep_by1(ty_param_bound,'+')
638639
ty_param_bound :: { TyParamBound Span }
639-
: lifetime { RegionTyParamBound $1 (spanOf $1) }
640-
| poly_trait_ref { TraitTyParamBound $1 None (spanOf $1) }
640+
: lifetime { RegionTyParamBound $1 (spanOf $1) }
641+
| poly_trait_ref { TraitTyParamBound $1 None (spanOf $1) }
642+
| '(' poly_trait_ref ')' { TraitTyParamBound $2 None ($1 # $3) }
641643

642644
poly_trait_ref_mod_bound :: { TyParamBound Span }
643645
: poly_trait_ref { TraitTyParamBound $1 None (spanOf $1) }
@@ -763,6 +765,7 @@ pat :: { Pat Span }
763765
}
764766
| expr_qual_path { PathP (Just (fst (unspan $1))) (snd (unspan $1)) ($1 # $>) }
765767
| lit_or_path '...' lit_or_path { RangeP $1 $3 ($1 # $>) }
768+
| lit_or_path '..=' lit_or_path { RangeP $1 $3 ($1 # $>) }
766769
| expr_path '{' '..' '}' { StructP $1 [] True ($1 # $>) }
767770
| expr_path '{' pat_fields '}' { let (fs,b) = $3 in StructP $1 fs b ($1 # $>) }
768771
| expr_path '(' pat_tup ')' { let (ps,m,_) = $3 in TupleStructP $1 ps m ($1 # $>) }
@@ -849,7 +852,7 @@ binding_mode :: { Spanned BindingMode }
849852
--
850853
-- * 'lhs' - expressions allowed on the left extremity of the term
851854
-- * 'rhs' - expressions allowed on the right extremity of the term
852-
-- * 'rhs2' - expressions allowed on the right extremity following '..'/'...'
855+
-- * 'rhs2' - expressions allowed on the right extremity following '..'/'.../..='
853856
--
854857
-- Precedences are handled by Happy (right at the end of the token section)
855858
gen_expression(lhs,rhs,rhs2) :: { Expr Span }
@@ -876,8 +879,9 @@ gen_expression(lhs,rhs,rhs2) :: { Expr Span }
876879
-- range expressions
877880
| '..' rhs2 %prec PREFIXRNG { Range [] Nothing (Just $2) HalfOpen ($1 # $2) }
878881
| '...' rhs2 %prec PREFIXRNG { Range [] Nothing (Just $2) Closed ($1 # $2) }
882+
| '..=' rhs2 %prec PREFIXRNG { Range [] Nothing (Just $2) Closed ($1 # $2) }
879883
| '..' %prec SINGLERNG { Range [] Nothing Nothing HalfOpen (spanOf $1) }
880-
| '...' %prec SINGLERNG { Range [] Nothing Nothing Closed (spanOf $1) }
884+
| '..=' %prec SINGLERNG { Range [] Nothing Nothing Closed (spanOf $1) }
881885
-- low precedence prefix expressions
882886
| return { Ret [] Nothing (spanOf $1) }
883887
| return rhs { Ret [] (Just $2) ($1 # $2) }
@@ -923,8 +927,10 @@ left_gen_expression(lhs,rhs,rhs2) :: { Expr Span }
923927
-- range expressions
924928
| lhs '..' %prec POSTFIXRNG { Range [] (Just $1) Nothing HalfOpen ($1 # $>) }
925929
| lhs '...' %prec POSTFIXRNG { Range [] (Just $1) Nothing Closed ($1 # $>) }
930+
| lhs '..=' %prec POSTFIXRNG { Range [] (Just $1) Nothing Closed ($1 # $>) }
926931
| lhs '..' rhs2 %prec INFIXRNG { Range [] (Just $1) (Just $3) HalfOpen ($1 # $>) }
927932
| lhs '...' rhs2 %prec INFIXRNG { Range [] (Just $1) (Just $3) Closed ($1 # $>) }
933+
| lhs '..=' rhs2 %prec INFIXRNG { Range [] (Just $1) (Just $3) Closed ($1 # $>) }
928934
-- assignment expressions
929935
| lhs '<-' rhs { InPlace [] $1 $3 ($1 # $>) }
930936
| lhs '=' rhs { Assign [] $1 $3 ($1 # $>) }
@@ -1523,6 +1529,7 @@ token :: { Spanned Token }
15231529
-- Structural symbols.
15241530
| '@' { $1 }
15251531
| '...' { $1 }
1532+
| '..=' { $1 }
15261533
| '..' { $1 }
15271534
| '.' { $1 }
15281535
| ',' { $1 }

src/Language/Rust/Parser/Lexer.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ $white+ { \s -> pure (Space Whitespace s) }
10211021
"." { token Dot }
10221022
".." { token DotDot }
10231023
"..." { token DotDotDot }
1024+
"..=" { token DotDotEqual }
10241025
"," { token Comma }
10251026
";" { token Semicolon }
10261027
":" { token Colon }

src/Language/Rust/Pretty/Internal.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ printToken At = "@"
252252
printToken Dot = "."
253253
printToken DotDot = ".."
254254
printToken DotDotDot = "..."
255+
printToken DotDotEqual = "..="
255256
printToken Comma = ","
256257
printToken Semicolon = ";"
257258
printToken Colon = ":"
@@ -490,7 +491,7 @@ printField (Field ident (Just expr) x) = annotate x (printIdent ident <>":" <+>
490491
-- | Print range limits
491492
printRangeLimits :: RangeLimits -> Doc a
492493
printRangeLimits HalfOpen = ".."
493-
printRangeLimits Closed = "..."
494+
printRangeLimits Closed = "..="
494495

495496
-- | Print a closure function declaration (@print_fn_block_args@)
496497
printFnBlockArgs :: FnDecl a -> Doc a
@@ -864,7 +865,7 @@ printPat (TupleP elts (Just ddpos) _) = let (before,after) = splitAt ddpos elts
864865
printPat (BoxP inner x) = annotate x ("box" <+> printPat inner)
865866
printPat (RefP inner mutbl x) = annotate x ("&" <> printMutability mutbl <+> printPat inner)
866867
printPat (LitP expr x) = annotate x (printExpr expr)
867-
printPat (RangeP lo hi x) = annotate x (printExpr lo <+> "..." <+> printExpr hi)
868+
printPat (RangeP lo hi x) = annotate x (printExpr lo <+> "..=" <+> printExpr hi)
868869
printPat (SliceP pb Nothing pa x) = annotate x ("[" <> commas (pb ++ pa) printPat <> "]")
869870
printPat (SliceP pb (Just ps) pa x) = annotate x ("[" <> commas pb printPat <> ps' <+> commas pa printPat <> "]")
870871
where ps' = hcat [ unless (null pb) ","

src/Language/Rust/Syntax/Token.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ data Token
6868
| At -- ^ @\@@ token
6969
| Dot -- ^ @.@ token
7070
| DotDot -- ^ @..@ token
71+
| DotDotEqual -- ^ @..=@ token
7172
| DotDotDot -- ^ @...@ token
7273
| Comma -- ^ @,@ token
7374
| Semicolon -- ^ @;@ token
@@ -234,6 +235,11 @@ spaceNeeded DotDot Dot = True
234235
spaceNeeded DotDot DotDot = True
235236
spaceNeeded DotDot DotDotDot = True
236237

238+
-- conflicts with 'DotDotEqual'
239+
spaceNeeded DotDot Equal = True
240+
spaceNeeded DotDot EqualEqual = True
241+
spaceNeeded DotDot FatArrow = True
242+
237243
-- conflicts with 'ModSep'
238244
spaceNeeded Colon Colon = True
239245
spaceNeeded Colon ModSep = True
@@ -311,6 +317,7 @@ instance Show Token where
311317
show Dot = "."
312318
show DotDot = ".."
313319
show DotDotDot = "..."
320+
show DotDotEqual = "..="
314321
show Comma = ","
315322
show Semicolon = ";"
316323
show Colon = ":"

test/rustc-tests/Diff.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ instance Diffable Token where
552552
PipePipe === "OrOr" = pure ()
553553
DotDot === "DotDot" = pure ()
554554
DotDotDot === "DotDotDot" = pure ()
555+
DotDotEqual === "DotDotEq" = pure ()
555556
RArrow === "RArrow" = pure ()
556557
LArrow === "LArrow" = pure ()
557558
Question === "Question" = pure ()
@@ -968,7 +969,10 @@ instance Show a => Diffable (Lit a) where
968969
suf === (n ! "fields" ! 1)
969970
("FloatUnsuffixed", Float f Unsuffixed _) -> do
970971
let String j = n ! "fields" ! 0
971-
case readMaybe (T.unpack j) of
972+
str' = case T.unpack j of
973+
str | last str == '.' -> str ++ "0"
974+
| otherwise -> str
975+
case readMaybe str' of
972976
Nothing -> diff "float literal has un-readable value" l val
973977
Just s | s == f -> pure ()
974978
_ -> diff "float literal has two different values" l val

test/rustc-tests/DiffUtils.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ diff :: Show a => String -> a -> Aeson.Value -> IO b
9898
diff explanation v j = throw (DiffError msg)
9999
where msg = unlines [ explanation ++ " in"
100100
, " * parsed AST"
101-
, show (show v)
101+
, cropped (show v)
102102
, " * dumped JSON"
103-
, unpack (Aeson.encode j)
103+
, cropped (unpack (Aeson.encode j))
104104
]
105+
cropped msg' | length msg' > 500 = take 500 msg' ++ "..."
106+
| otherwise = msg'
105107

106108

107109

test/rustc-tests/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Test.Framework.Providers.API
3333
main :: IO ()
3434
main = do
3535
-- Check last time `rustc` version was bumped
36-
let lastDay = fromGregorian 2017 9 25
36+
let lastDay = fromGregorian 2017 10 10
3737
today <- utctDay <$> getCurrentTime
3838
when (diffDays today lastDay > 32) $
3939
putStrLn $ "\x1b[33m" ++ "\nThe version of `rustc' the tests will try to use is older than 1 month" ++ "\x1b[0m"

test/unit-tests/ParserTest.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ parserPatterns = testGroup "parsing patterns"
424424
, testP "math::<i32>::PI" (PathP Nothing (Path False [ ("math", AngleBracketed [] [i32] [] ())
425425
, ("PI", NoParameters ()) ] ()) ())
426426
, testP "1...2" (RangeP (Lit [] (Int Dec 1 Unsuffixed ()) ()) (Lit [] (Int Dec 2 Unsuffixed ()) ()) ())
427+
, testP "1..=2" (RangeP (Lit [] (Int Dec 1 Unsuffixed ()) ()) (Lit [] (Int Dec 2 Unsuffixed ()) ()) ())
427428
, testP "ref mut y@(x,x)" (IdentP (ByRef Mutable) "y" (Just (TupleP [ x, x ] Nothing ())) ())
428429
, testP "ref mut y@_" (IdentP (ByRef Mutable) "y" (Just (WildP ())) ())
429430
, testP "(1,2,..,3)" (TupleP [ LitP (Lit [] (Int Dec 1 Unsuffixed ()) ()) ()
@@ -563,9 +564,11 @@ parserExpressions = testGroup "parsing expressions"
563564
, testP "println!()" (MacExpr [] (Mac (Path False [("println",NoParameters ())] ()) (Stream []) ()) ())
564565
, testP "1..2" (Range [] (Just (Lit [] (Int Dec 1 Unsuffixed ()) ())) (Just (Lit [] (Int Dec 2 Unsuffixed ()) ())) HalfOpen ())
565566
, testP "1...2" (Range [] (Just (Lit [] (Int Dec 1 Unsuffixed ()) ())) (Just (Lit [] (Int Dec 2 Unsuffixed ()) ())) Closed ())
567+
, testP "1..=2" (Range [] (Just (Lit [] (Int Dec 1 Unsuffixed ()) ())) (Just (Lit [] (Int Dec 2 Unsuffixed ()) ())) Closed ())
566568
, testP "1.." (Range [] (Just (Lit [] (Int Dec 1 Unsuffixed ()) ())) Nothing HalfOpen ())
567569
, testP "..2" (Range [] Nothing (Just (Lit [] (Int Dec 2 Unsuffixed ()) ())) HalfOpen ())
568570
, testP "...2" (Range [] Nothing (Just (Lit [] (Int Dec 2 Unsuffixed ()) ())) Closed ())
571+
, testP "..=2" (Range [] Nothing (Just (Lit [] (Int Dec 2 Unsuffixed ()) ())) Closed ())
569572
, testP ".." (Range [] Nothing Nothing HalfOpen ())
570573
, testP "x?" (Try [] (PathExpr [] Nothing (Path False [("x", NoParameters ())] ()) ()) ())
571574
, testP "x.0" (TupField [] (PathExpr [] Nothing (Path False [("x", NoParameters ())] ()) ()) 0 ())

test/unit-tests/PrettyTest.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ prettyPatterns = testGroup "printing patterns"
142142
(Just 2) ()))
143143

144144
, testFlatten "box x" (printPat (BoxP x ()))
145-
, testFlatten "1 ... 2" (printPat (RangeP (Lit [] (Int Dec 1 Unsuffixed ()) ()) (Lit [] (Int Dec 2 Unsuffixed ()) ()) ()))
145+
, testFlatten "1 ..= 2" (printPat (RangeP (Lit [] (Int Dec 1 Unsuffixed ()) ()) (Lit [] (Int Dec 2 Unsuffixed ()) ()) ()))
146146
, testFlatten "&x" (printPat (RefP x Immutable ()))
147147
, testFlatten "&mut x" (printPat (RefP x Mutable ()))
148148
, testFlatten "true" (printPat (LitP (Lit [] (Bool True Unsuffixed ()) ()) ()))
@@ -313,9 +313,9 @@ prettyExpressions = testGroup "printing expressions"
313313
, testFlatten "foo.1" (printExpr (TupField [] foo 1 ()))
314314
, testFlatten "foo[1]" (printExpr (Index [] foo _1 ()))
315315
, testFlatten "foo .. bar" (printExpr (Range [] (Just foo) (Just bar) HalfOpen ()))
316-
, testFlatten "foo ..." (printExpr (Range [] (Just foo) Nothing Closed ()))
316+
, testFlatten "foo ..=" (printExpr (Range [] (Just foo) Nothing Closed ()))
317317
, testFlatten ".. bar" (printExpr (Range [] Nothing (Just bar) HalfOpen ()))
318-
, testFlatten "..." (printExpr (Range [] Nothing Nothing Closed ()))
318+
, testFlatten "..=" (printExpr (Range [] Nothing Nothing Closed ()))
319319
, testFlatten "std::vec::Vec::<i32>" (printExpr (PathExpr [] Nothing (Path False [ std, vec, veci32 ] ()) ()))
320320
, testFlatten "<i32 as std::vec>::Vec::<i32>" (printExpr (PathExpr [] (Just (QSelf i32 2)) (Path False [ std, vec, veci32 ] ()) ()))
321321
, testFlatten "&foo" (printExpr (AddrOf [] Immutable foo ()))

0 commit comments

Comments
 (0)