From 9bfb0ef818456cce57edcb2463f63f71594e4a13 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Esteban=20K=C3=BCber?= Date: Sun, 10 Mar 2019 19:46:44 -0700 Subject: [PATCH] Tweak unsupported negative trait bounds message --- src/librustc_errors/diagnostic.rs | 2 +- src/libsyntax/parse/parser.rs | 21 +++++++++----- src/test/ui/issues/issue-58857.stderr | 3 +- src/test/ui/parser/issue-33418.fixed | 11 +++++-- src/test/ui/parser/issue-33418.rs | 15 ++++++---- src/test/ui/parser/issue-33418.stderr | 41 +++++++++++++-------------- 6 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 851b19e8177..fc1fd960c4a 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -366,7 +366,7 @@ pub fn span_suggestion_hidden( }], }], msg: msg.to_owned(), - style: SuggestionStyle::HideCodeInline, + style: SuggestionStyle::HideCodeAlways, applicability, }); self diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6ff06aa4b31..99260314054 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5598,8 +5598,14 @@ fn parse_generic_bounds_common(&mut self, if !negative_bounds.is_empty() || was_negative { let plural = negative_bounds.len() > 1; - let mut err = self.struct_span_err(negative_bounds, - "negative trait bounds are not supported"); + let last_span = negative_bounds.last().map(|sp| *sp); + let mut err = self.struct_span_err( + negative_bounds, + "negative trait bounds are not supported", + ); + if let Some(sp) = last_span { + err.span_label(sp, "negative trait 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(); @@ -5612,11 +5618,12 @@ fn parse_generic_bounds_common(&mut self, } new_bound_list = new_bound_list.replacen(" +", ":", 1); } - err.span_suggestion_short(bound_list, - &format!("remove the trait bound{}", - if plural { "s" } else { "" }), - new_bound_list, - Applicability::MachineApplicable); + err.span_suggestion_hidden( + bound_list, + &format!("remove the trait bound{}", if plural { "s" } else { "" }), + new_bound_list, + Applicability::MachineApplicable, + ); } err.emit(); } diff --git a/src/test/ui/issues/issue-58857.stderr b/src/test/ui/issues/issue-58857.stderr index 040e9eb8a65..56e87215a80 100644 --- a/src/test/ui/issues/issue-58857.stderr +++ b/src/test/ui/issues/issue-58857.stderr @@ -2,7 +2,8 @@ error: negative trait bounds are not supported --> $DIR/issue-58857.rs:4:7 | LL | impl Conj{} - | ^^^^^^^^ help: remove the trait bound + | ^^^^^^^^ negative trait bounds are not supported + = help: remove the trait 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 df11f2d855c..2aaa3b5b1ea 100644 --- a/src/test/ui/parser/issue-33418.fixed +++ b/src/test/ui/parser/issue-33418.fixed @@ -1,10 +1,15 @@ // run-rustfix -trait Tr {} //~ ERROR negative trait bounds are not supported -trait Tr2: SuperA {} //~ ERROR negative trait bounds are not supported -trait Tr3: SuperB {} //~ ERROR negative trait bounds are not supported +trait Tr {} +//~^ ERROR negative trait bounds are not supported +trait Tr2: SuperA {} +//~^ ERROR negative trait bounds are not supported +trait Tr3: SuperB {} +//~^ ERROR negative trait bounds are not supported trait Tr4: SuperB + SuperD {} +//~^ ERROR negative trait bounds are not supported trait Tr5 {} +//~^ ERROR negative trait 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 5bb5f2afca3..55331520927 100644 --- a/src/test/ui/parser/issue-33418.rs +++ b/src/test/ui/parser/issue-33418.rs @@ -1,12 +1,17 @@ // run-rustfix -trait Tr: !SuperA {} //~ ERROR negative trait bounds are not supported -trait Tr2: SuperA + !SuperB {} //~ ERROR negative trait bounds are not supported -trait Tr3: !SuperA + SuperB {} //~ ERROR negative trait bounds are not supported -trait Tr4: !SuperA + SuperB //~ ERROR negative trait bounds are not supported +trait Tr: !SuperA {} +//~^ ERROR negative trait bounds are not supported +trait Tr2: SuperA + !SuperB {} +//~^ ERROR negative trait bounds are not supported +trait Tr3: !SuperA + SuperB {} +//~^ ERROR negative trait bounds are not supported +trait Tr4: !SuperA + SuperB + !SuperC + SuperD {} -trait Tr5: !SuperA //~ ERROR negative trait bounds are not supported +//~^ ERROR negative trait bounds are not supported +trait Tr5: !SuperA + !SuperB {} +//~^ ERROR negative trait 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 acbe597ef31..660d9fd30c8 100644 --- a/src/test/ui/parser/issue-33418.stderr +++ b/src/test/ui/parser/issue-33418.stderr @@ -2,41 +2,40 @@ error: negative trait bounds are not supported --> $DIR/issue-33418.rs:3:9 | LL | trait Tr: !SuperA {} - | ^^^^^^^^^ help: remove the trait bound + | ^^^^^^^^^ negative trait bounds are not supported + = help: remove the trait bound error: negative trait bounds are not supported - --> $DIR/issue-33418.rs:4:19 + --> $DIR/issue-33418.rs:5:19 | LL | trait Tr2: SuperA + !SuperB {} - | ---------^^^^^^^^^ - | | - | help: remove the trait bound + | ^^^^^^^^^ negative trait bounds are not supported + = help: remove the trait bound error: negative trait bounds are not supported - --> $DIR/issue-33418.rs:5:10 + --> $DIR/issue-33418.rs:7:10 | LL | trait Tr3: !SuperA + SuperB {} - | ^^^^^^^^^--------- - | | - | help: remove the trait bound + | ^^^^^^^^^ negative trait bounds are not supported + = help: remove the trait bound error: negative trait bounds are not supported - --> $DIR/issue-33418.rs:6:10 + --> $DIR/issue-33418.rs:9:10 | -LL | trait Tr4: !SuperA + SuperB - | __________-^^^^^^^^ -LL | | + !SuperC + SuperD {} - | |_____^^^^^^^^^________- help: remove the trait bounds +LL | trait Tr4: !SuperA + SuperB + | ^^^^^^^^^ +LL | + !SuperC + SuperD {} + | ^^^^^^^^^ negative trait bounds are not supported + = help: remove the trait bounds error: negative trait bounds are not supported - --> $DIR/issue-33418.rs:8:10 + --> $DIR/issue-33418.rs:12:10 | -LL | trait Tr5: !SuperA - | __________-^^^^^^^^ -LL | | + !SuperB {} - | | ^^^^^^^^- - | |_____________| - | help: remove the trait bounds +LL | trait Tr5: !SuperA + | ^^^^^^^^^ +LL | + !SuperB {} + | ^^^^^^^^^ negative trait bounds are not supported + = help: remove the trait bounds error: aborting due to 5 previous errors -- 2.44.0