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 5 pull requests #67479

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2bd28d9
Add regression tests
TommasoBianchi Nov 24, 2019
042d855
Fix too restrictive checks on Drop impls
TommasoBianchi Dec 16, 2019
b08d697
Formatting fixes
TommasoBianchi Dec 16, 2019
020be74
Clean up E0120 long explanation
GuillaumeGomez Dec 19, 2019
94d207f
Clean up E0121 long explanation
GuillaumeGomez Dec 19, 2019
7f0741d
Update E0120.md
Dylan-DPC Dec 20, 2019
dce0f06
Update E0121.md
Dylan-DPC Dec 20, 2019
963f20d
Allow -Cllvm-args to override rustc's default LLVM args.
michaelwoerister Dec 18, 2019
1ca145c
Remove rarely used -Zdisable_instrumentation_preinliner flag.
michaelwoerister Dec 18, 2019
382d370
Make ptr::slice_from_raw_parts a const fn available under a feature flag
DutchGhost Dec 20, 2019
c59588f
extract parse_ty_tuple_or_parens
Centril Dec 8, 2019
e68db0a
refactor parse_ty_tuple_or_parens
Centril Dec 8, 2019
6d678b1
parse_ptr -> parse_ty_ptr & refactor
Centril Dec 8, 2019
f085637
extract parse_array_or_slice_ty
Centril Dec 8, 2019
b42b85f
extract parse_typeof_ty
Centril Dec 8, 2019
d47de3e
extract parse_impl_ty
Centril Dec 8, 2019
1fa8f70
extract parse_dyn_ty
Centril Dec 8, 2019
c0561cf
extract parse_path_start_ty
Centril Dec 8, 2019
6b92be2
extract error_illegal_c_variadic_ty
Centril Dec 8, 2019
0e74022
parse_ty_common: .fatal -> .struct_span_err
Centril Dec 8, 2019
3b63465
parser/ty.rs: minor formatting tweaks
Centril Dec 8, 2019
8e8ac02
extract error_opt_out_lifetime
Centril Dec 8, 2019
56b54fb
extract recover_paren_lifetime
Centril Dec 8, 2019
e8b6769
parse_generic_bounds_common: dedent
Centril Dec 8, 2019
7294804
extract can_begin_bound
Centril Dec 8, 2019
229560b
extract parse_generic_bound
Centril Dec 8, 2019
2ca6181
functionalize parse_generic_bound
Centril Dec 8, 2019
f87ff0f
parse_generic_bound: leave a FIXME
Centril Dec 8, 2019
8f33bdc
extract parse_generic_ty_bound
Centril Dec 8, 2019
8123211
extract parse_generic_lt_bound
Centril Dec 8, 2019
90f7d8b
simplify negative bound diagnostic
Centril Dec 8, 2019
765df3a
simplify 'let question = ...;'
Centril Dec 8, 2019
51bbdeb
parse_generic_bounds: account for negative lifetime bounds
Centril Dec 8, 2019
f02fd50
extract error_negative_bounds
Centril Dec 8, 2019
0ebd421
document parse_late_bound_lifetime_defs
Centril Dec 8, 2019
d977e5b
parse_ty_bare_fn: improve docs
Centril Dec 8, 2019
cabe665
unwrap -> expect
Centril Dec 21, 2019
690b0b3
span_suggestion_hidden -> tool_only_span_suggestion
Centril Dec 21, 2019
abb4234
Rollup merge of #67059 - TommasoBianchi:dropck_fix_pr, r=pnkfelix
Centril Dec 21, 2019
2e44898
Rollup merge of #67148 - Centril:ty-polish, r=estebank
Centril Dec 21, 2019
97d88ed
Rollup merge of #67393 - michaelwoerister:llvm-args-override, r=varkor
Centril Dec 21, 2019
dfe712c
Rollup merge of #67422 - GuillaumeGomez:cleanup-err-codes, r=Dylan-DPC
Centril Dec 21, 2019
a3cc9b4
Rollup merge of #67462 - DutchGhost:const_slice_from_raw_parts, r=dto…
Centril Dec 21, 2019
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_generic_bounds: account for negative lifetime bounds
  • Loading branch information
Centril committed Dec 20, 2019
commit 51bbdeb58871c7aa6324724598d583fbb7a3d4ba
35 changes: 16 additions & 19 deletions src/librustc_parse/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ impl<'a> Parser<'a> {
let last_span = *negative_bounds.last().unwrap();
let mut err = self.struct_span_err(
negative_bounds,
"negative trait bounds are not supported",
"negative bounds are not supported",
);
err.span_label(last_span, "negative trait bounds are not supported");
err.span_label(last_span, "negative bounds are not supported");
if let Some(bound_list) = colon_span {
let bound_list = bound_list.to(self.prev_span);
let mut new_bound_list = String::new();
Expand All @@ -392,7 +392,7 @@ impl<'a> Parser<'a> {
}
err.span_suggestion_hidden(
bound_list,
&format!("remove the trait bound{}", pluralize!(negative_bounds_len)),
&format!("remove the bound{}", pluralize!(negative_bounds_len)),
new_bound_list,
Applicability::MachineApplicable,
);
Expand All @@ -418,25 +418,23 @@ impl<'a> Parser<'a> {
/// ```
/// BOUND = TY_BOUND | LT_BOUND
/// ```
fn parse_generic_bound(
&mut self,
) -> PResult<'a, Result<GenericBound, Span>> {
fn parse_generic_bound(&mut self) -> PResult<'a, Result<GenericBound, Span>> {
let anchor_lo = self.prev_span;
let lo = self.token.span;
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);
if self.token.is_lifetime() {
Ok(Ok(self.parse_generic_lt_bound(lo, inner_lo, has_parens, question)?))
let bound = if self.token.is_lifetime() {
self.parse_generic_lt_bound(lo, inner_lo, has_parens, question)?
} else {
let (poly_span, bound) = self.parse_generic_ty_bound(lo, has_parens, question)?;
if is_negative {
Ok(Err(anchor_lo.to(poly_span)))
} else {
Ok(Ok(bound))
}
}
self.parse_generic_ty_bound(lo, has_parens, question)?
};
Ok(if is_negative {
Err(anchor_lo.to(self.prev_span))
} else {
Ok(bound)
})
}

/// Parses a lifetime ("outlives") bound, e.g. `'a`, according to:
Expand Down Expand Up @@ -497,16 +495,15 @@ impl<'a> Parser<'a> {
lo: Span,
has_parens: bool,
question: Option<Span>,
) -> PResult<'a, (Span, GenericBound)> {
) -> 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_span = lo.to(self.prev_span);
let poly_trait = PolyTraitRef::new(lifetime_defs, path, poly_span);
let poly_trait = PolyTraitRef::new(lifetime_defs, path, lo.to(self.prev_span));
let modifier = question.map_or(TraitBoundModifier::None, |_| TraitBoundModifier::Maybe);
Ok((poly_span, GenericBound::Trait(poly_trait, modifier)))
Ok(GenericBound::Trait(poly_trait, modifier))
}

pub(super) fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec<GenericParam>> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-58857.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ struct Conj<A> {a : A}
trait Valid {}

impl<A: !Valid> Conj<A>{}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported

fn main() {}
6 changes: 3 additions & 3 deletions src/test/ui/issues/issue-58857.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-58857.rs:4:7
|
LL | impl<A: !Valid> Conj<A>{}
| ^^^^^^^^ negative trait bounds are not supported
| ^^^^^^^^ negative bounds are not supported
|
= help: remove the trait bound
= help: remove the bound

error: aborting due to previous error

10 changes: 5 additions & 5 deletions src/test/ui/parser/issue-33418.fixed
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// run-rustfix

trait Tr {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr2: SuperA {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr3: SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr4: SuperB + SuperD {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr5 {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported

trait SuperA {}
trait SuperB {}
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/parser/issue-33418.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// run-rustfix

trait Tr: !SuperA {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr2: SuperA + !SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr3: !SuperA + SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr4: !SuperA + SuperB
+ !SuperC + SuperD {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr5: !SuperA
+ !SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported

trait SuperA {}
trait SuperB {}
Expand Down
30 changes: 15 additions & 15 deletions src/test/ui/parser/issue-33418.stderr
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:3:9
|
LL | trait Tr: !SuperA {}
| ^^^^^^^^^ negative trait bounds are not supported
| ^^^^^^^^^ negative bounds are not supported
|
= help: remove the trait bound
= help: remove the bound

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:5:19
|
LL | trait Tr2: SuperA + !SuperB {}
| ^^^^^^^^^ negative trait bounds are not supported
| ^^^^^^^^^ negative bounds are not supported
|
= help: remove the trait bound
= help: remove the bound

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:7:10
|
LL | trait Tr3: !SuperA + SuperB {}
| ^^^^^^^^^ negative trait bounds are not supported
| ^^^^^^^^^ negative bounds are not supported
|
= help: remove the trait bound
= help: remove the bound

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:9:10
|
LL | trait Tr4: !SuperA + SuperB
| ^^^^^^^^^
LL | + !SuperC + SuperD {}
| ^^^^^^^^^ negative trait bounds are not supported
| ^^^^^^^^^ negative bounds are not supported
|
= help: remove the trait bounds
= help: remove the bounds

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:12:10
|
LL | trait Tr5: !SuperA
| ^^^^^^^^^
LL | + !SuperB {}
| ^^^^^^^^^ negative trait bounds are not supported
| ^^^^^^^^^ negative bounds are not supported
|
= help: remove the trait bounds
= help: remove the bounds

error: aborting due to 5 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// In this regression test for #67146, we check that the
// negative outlives bound `!'a` is rejected by the parser.
// This regression was first introduced in PR #57364.

fn main() {}

fn f1<T: !'static>() {}
//~^ ERROR negative bounds are not supported
fn f2<'a, T: Ord + !'a>() {}
//~^ ERROR negative bounds are not supported
fn f3<'a, T: !'a + Ord>() {}
//~^ ERROR negative bounds are not supported
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: negative bounds are not supported
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:7:8
|
LL | fn f1<T: !'static>() {}
| ^^^^^^^^^^ negative bounds are not supported
|
= help: remove the bound

error: negative bounds are not supported
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:9:18
|
LL | fn f2<'a, T: Ord + !'a>() {}
| ^^^^^ negative bounds are not supported
|
= help: remove the bound

error: negative bounds are not supported
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:11:12
|
LL | fn f3<'a, T: !'a + Ord>() {}
| ^^^^^ negative bounds are not supported
|
= help: remove the bound

error: aborting due to 3 previous errors