diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index c97220458757..db9a0ada525b 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -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(); @@ -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, ); @@ -418,25 +418,23 @@ impl<'a> Parser<'a> { /// ``` /// BOUND = TY_BOUND | LT_BOUND /// ``` - fn parse_generic_bound( - &mut self, - ) -> PResult<'a, Result> { + fn parse_generic_bound(&mut self) -> PResult<'a, Result> { 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: @@ -497,16 +495,15 @@ impl<'a> Parser<'a> { lo: Span, has_parens: bool, question: Option, - ) -> 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> { diff --git a/src/test/ui/issues/issue-58857.rs b/src/test/ui/issues/issue-58857.rs index 392e4ea0c2ec..4350d7e5b403 100644 --- a/src/test/ui/issues/issue-58857.rs +++ b/src/test/ui/issues/issue-58857.rs @@ -2,6 +2,6 @@ struct Conj {a : A} trait Valid {} impl Conj{} -//~^ ERROR negative trait bounds are not supported +//~^ ERROR negative bounds are not supported fn main() {} diff --git a/src/test/ui/issues/issue-58857.stderr b/src/test/ui/issues/issue-58857.stderr index ab9a0130c00b..9bc80cc270b0 100644 --- a/src/test/ui/issues/issue-58857.stderr +++ b/src/test/ui/issues/issue-58857.stderr @@ -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 Conj{} - | ^^^^^^^^ 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 diff --git a/src/test/ui/parser/issue-33418.fixed b/src/test/ui/parser/issue-33418.fixed index 2aaa3b5b1ea5..ed885ae14356 100644 --- a/src/test/ui/parser/issue-33418.fixed +++ b/src/test/ui/parser/issue-33418.fixed @@ -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 {} diff --git a/src/test/ui/parser/issue-33418.rs b/src/test/ui/parser/issue-33418.rs index 553315209271..9934284abfbb 100644 --- a/src/test/ui/parser/issue-33418.rs +++ b/src/test/ui/parser/issue-33418.rs @@ -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 {} diff --git a/src/test/ui/parser/issue-33418.stderr b/src/test/ui/parser/issue-33418.stderr index 479e7bed1016..7f361dbe2718 100644 --- a/src/test/ui/parser/issue-33418.stderr +++ b/src/test/ui/parser/issue-33418.stderr @@ -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 diff --git a/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.rs b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.rs new file mode 100644 index 000000000000..5a109ba7c689 --- /dev/null +++ b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.rs @@ -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() {} +//~^ 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 diff --git a/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.stderr b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.stderr new file mode 100644 index 000000000000..74437c1a0081 --- /dev/null +++ b/src/test/ui/parser/issue-67146-negative-outlives-bound-syntactic-fail.stderr @@ -0,0 +1,26 @@ +error: negative bounds are not supported + --> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:7:8 + | +LL | fn f1() {} + | ^^^^^^^^^^ 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 +