Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #68077

Closed
wants to merge 56 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
cc0fbdf
Automatically prefer integer addresses for zst MPlace
oli-obk Dec 21, 2019
5b770b0
Remove a ZST special casing that is not necessary anymore
oli-obk Dec 21, 2019
4a5c35b
Fix an ICE happening due code assuming that `MPlaceTy` cannot have in…
oli-obk Dec 21, 2019
cac6f4c
Move `to_const_value` from `MPlaceTy` to its only use site
oli-obk Dec 26, 2019
4fbe434
Poison any `MemPlace` created from a zst Operand (or otherwise via `M…
oli-obk Dec 26, 2019
23b0c47
Ensure we don't accidentally turn non-zsts into zsts
oli-obk Dec 26, 2019
a1990db
Remove a bunch of dead functions and make some functions private
oli-obk Dec 26, 2019
f7f5952
Add warning label to `try_as_mplace`
oli-obk Dec 27, 2019
29c372b
Add more documentation
oli-obk Jan 7, 2020
d0b24e5
Actually use the poison value
oli-obk Jan 7, 2020
9c0000c
Point at opaque and closure type definitions in type errors
estebank Nov 16, 2019
c556151
review comments
estebank Dec 15, 2019
0dcdbae
Point at the def span of trait refs E0277
estebank Dec 16, 2019
542be6f
review comment: wording
estebank Dec 16, 2019
b522ba0
review comments
estebank Jan 8, 2020
ffcdbad
review comments
estebank Jan 8, 2020
705e087
reduce code duplication
estebank Jan 8, 2020
33ae322
remove unnecessary `Debug`
estebank Jan 8, 2020
bcab59e
lowering: simplify HoFs
Centril Jan 6, 2020
956265d
lowering: elide some lifetimes
Centril Jan 6, 2020
f75ccde
extract pattern lowering -> pat.rs
Centril Jan 6, 2020
ae6e31b
move lower_binding_mode -> pat.rs
Centril Jan 6, 2020
4e6329e
extract path lowering -> path.rs
Centril Jan 6, 2020
2db97ed
refactor 'Output = $ty' & reduce rustc dep
Centril Jan 6, 2020
69b1e5c
{rustc::util -> rustc_data_structures}::captures
Centril Jan 6, 2020
402907f
lowering: rustc::session -> rustc_session
Centril Jan 6, 2020
7472f9e
lowering: remove dep on CrateStore
Centril Jan 6, 2020
b743af6
rename a method in Resolver trait
Centril Jan 8, 2020
5dafa6a
add CStore::item_generics_num_lifetimes
Centril Jan 9, 2020
e632940
Update src/librustc_mir/interpret/place.rs
oli-obk Jan 9, 2020
a4fa5bb
Rename `Unsized` to `Meta`
oli-obk Jan 9, 2020
c5c4fa8
Switch assertion order to be more helpful to ppl that encounter them
oli-obk Jan 9, 2020
010b66d
Allow specifying LLVM args in target specifications
Jan 9, 2020
915db7a
expect `fn` after `const unsafe` / `const extern`
Centril Jan 9, 2020
c751961
Extend support of `_` in type parameters
estebank Jan 9, 2020
6e04cf0
review comments: more tests
estebank Jan 9, 2020
63e2e44
Add `const_trait_impl` feature gate
ecstatic-morse Jan 2, 2020
6fc4158
Add `const_trait_bound_opt_out` feature gate
ecstatic-morse Jan 2, 2020
fd4a6a1
Add a `constness` field to `ast::TraitRef`
ecstatic-morse Jan 2, 2020
1c3fe9d
Parse `impl const Trait for Ty` syntax
ecstatic-morse Jan 2, 2020
0cf52a7
Parse `?const Trait` bound syntax
ecstatic-morse Jan 2, 2020
b390fc4
Error when new syntax is lowered
ecstatic-morse Jan 3, 2020
31edbe9
Reject `const` in inherent impls
ecstatic-morse Jan 4, 2020
d843e00
Check for `?const` in invalid contexts during AST validation
ecstatic-morse Jan 5, 2020
343e157
Add tests for RFC 2632
ecstatic-morse Jan 3, 2020
b6b11f0
Call all visit methods on trait definitions
ecstatic-morse Jan 5, 2020
9950a1f
Add test for `?const` and `?` on the same bound
ecstatic-morse Jan 5, 2020
14730ed
Make `bound_context` more like neighboring functions
ecstatic-morse Jan 6, 2020
fd1c003
Add test for `?const` in nested impl/dyn trait
ecstatic-morse Jan 6, 2020
fd9991c
Rollup merge of #66463 - estebank:point-at-closure-and-opaque-types, …
Centril Jan 10, 2020
79bb166
Rollup merge of #67501 - oli-obk:test-slice-patterns, r=RalfJung
Centril Jan 10, 2020
98e6e05
Rollup merge of #67820 - ecstatic-morse:const-trait, r=oli-obk
Centril Jan 10, 2020
b8b0742
Rollup merge of #67922 - Centril:lowering-cleanup, r=petrochenkov
Centril Jan 10, 2020
0d959ad
Rollup merge of #68059 - jethrogb:jb/target-llvm-args, r=alexcrichton
Centril Jan 10, 2020
25e57f4
Rollup merge of #68071 - estebank:ice-67995, r=Centril
Centril Jan 10, 2020
a33e7c6
Rollup merge of #68073 - Centril:fix-68062, r=estebank
Centril Jan 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Parse ?const Trait bound syntax
The grammar also handles `?const ?Trait` even though this is
semantically redundant.
ecstatic-morse committed Jan 10, 2020
commit 0cf52a7dd8fbe68e85471fd9254d8e2e025a03d8
91 changes: 77 additions & 14 deletions src/librustc_parse/parser/ty.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
use rustc_error_codes::*;
use rustc_errors::{pluralize, struct_span_err, Applicability, PResult};
use rustc_span::source_map::Span;
use rustc_span::symbol::kw;
use rustc_span::symbol::{kw, sym};
use syntax::ast::{
self, BareFnTy, FunctionRetTy, GenericParam, Ident, Lifetime, MutTy, Ty, TyKind,
};
@@ -17,6 +17,24 @@ use syntax::ast::{Mac, Mutability};
use syntax::ptr::P;
use syntax::token::{self, Token};

/// Any `?` or `?const` modifiers that appear at the start of a bound.
struct BoundModifiers {
/// `?Trait`.
maybe: Option<Span>,

/// `?const Trait`.
maybe_const: Option<Span>,
}

impl BoundModifiers {
fn trait_bound_modifier(&self) -> TraitBoundModifier {
match self.maybe {
Some(_) => TraitBoundModifier::Maybe,
None => TraitBoundModifier::None,
}
}
}

/// Returns `true` if `IDENT t` can start a type -- `IDENT::a::b`, `IDENT<u8, u8>`,
/// `IDENT<<u8 as Trait>::AssocTy>`.
///
@@ -195,7 +213,9 @@ impl<'a> Parser<'a> {
lo: Span,
parse_plus: bool,
) -> PResult<'a, TyKind> {
let poly_trait_ref = PolyTraitRef::new(generic_params, path, lo.to(self.prev_span));
assert_ne!(self.token, token::Question);

let poly_trait_ref = PolyTraitRef::new(generic_params, path, None, lo.to(self.prev_span));
let mut bounds = vec![GenericBound::Trait(poly_trait_ref, TraitBoundModifier::None)];
if parse_plus {
self.eat_plus(); // `+`, or `+=` gets split and `+` is discarded
@@ -421,12 +441,15 @@ impl<'a> Parser<'a> {
let has_parens = self.eat(&token::OpenDelim(token::Paren));
let inner_lo = self.token.span;
let is_negative = self.eat(&token::Not);
let question = self.eat(&token::Question).then_some(self.prev_span);

let modifiers = self.parse_ty_bound_modifiers();
let bound = if self.token.is_lifetime() {
self.parse_generic_lt_bound(lo, inner_lo, has_parens, question)?
self.error_lt_bound_with_modifiers(modifiers);
self.parse_generic_lt_bound(lo, inner_lo, has_parens)?
} else {
self.parse_generic_ty_bound(lo, has_parens, question)?
self.parse_generic_ty_bound(lo, has_parens, modifiers)?
};

Ok(if is_negative { Err(anchor_lo.to(self.prev_span)) } else { Ok(bound) })
}

@@ -439,9 +462,7 @@ impl<'a> Parser<'a> {
lo: Span,
inner_lo: Span,
has_parens: bool,
question: Option<Span>,
) -> PResult<'a, GenericBound> {
self.error_opt_out_lifetime(question);
let bound = GenericBound::Outlives(self.expect_lifetime());
if has_parens {
// FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
@@ -451,8 +472,17 @@ impl<'a> Parser<'a> {
Ok(bound)
}

fn error_opt_out_lifetime(&self, question: Option<Span>) {
if let Some(span) = question {
/// Emits an error if any trait bound modifiers were present.
fn error_lt_bound_with_modifiers(&self, modifiers: BoundModifiers) {
if let Some(span) = modifiers.maybe_const {
self.struct_span_err(
span,
"`?const` may only modify trait bounds, not lifetime bounds",
)
.emit();
}

if let Some(span) = modifiers.maybe {
self.struct_span_err(span, "`?` may only modify trait bounds, not lifetime bounds")
.emit();
}
@@ -478,25 +508,58 @@ impl<'a> Parser<'a> {
Ok(())
}

/// Parses the modifiers that may precede a trait in a bound, e.g. `?Trait` or `?const Trait`.
///
/// If no modifiers are present, this does not consume any tokens.
///
/// ```
/// TY_BOUND_MODIFIERS = "?" ["const" ["?"]]
/// ```
fn parse_ty_bound_modifiers(&mut self) -> BoundModifiers {
if !self.eat(&token::Question) {
return BoundModifiers { maybe: None, maybe_const: None };
}

// `? ...`
let first_question = self.prev_span;
if !self.eat_keyword(kw::Const) {
return BoundModifiers { maybe: Some(first_question), maybe_const: None };
}

// `?const ...`
let maybe_const = first_question.to(self.prev_span);
self.sess.gated_spans.gate(sym::const_trait_bound_opt_out, maybe_const);
if !self.eat(&token::Question) {
return BoundModifiers { maybe: None, maybe_const: Some(maybe_const) };
}

// `?const ? ...`
let second_question = self.prev_span;
BoundModifiers { maybe: Some(second_question), maybe_const: Some(maybe_const) }
}

/// Parses a type bound according to:
/// ```
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
/// TY_BOUND_NOPAREN = [?] [for<LT_PARAM_DEFS>] SIMPLE_PATH (e.g., `?for<'a: 'b> m::Trait<'a>`)
/// TY_BOUND_NOPAREN = [TY_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH
/// ```
///
/// For example, this grammar accepts `?const ?for<'a: 'b> m::Trait<'a>`.
fn parse_generic_ty_bound(
&mut self,
lo: Span,
has_parens: bool,
question: Option<Span>,
modifiers: BoundModifiers,
) -> PResult<'a, GenericBound> {
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
let path = self.parse_path(PathStyle::Type)?;
if has_parens {
self.expect(&token::CloseDelim(token::Paren))?;
}
let poly_trait = PolyTraitRef::new(lifetime_defs, path, lo.to(self.prev_span));
let modifier = question.map_or(TraitBoundModifier::None, |_| TraitBoundModifier::Maybe);
Ok(GenericBound::Trait(poly_trait, modifier))

let constness = modifiers.maybe_const.map(|_| ast::Constness::NotConst);
let poly_trait = PolyTraitRef::new(lifetime_defs, path, constness, lo.to(self.prev_span));
Ok(GenericBound::Trait(poly_trait, modifiers.trait_bound_modifier()))
}

/// Optionally parses `for<$generic_params>`.