Skip to content

Commit

Permalink
Do not suggest restriction on spans originating in macros
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 15, 2019
1 parent 9c525ee commit 9ed463a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 17 additions & 14 deletions src/librustc/traits/error_reporting.rs
Expand Up @@ -977,20 +977,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};

let mut suggest_restriction = |generics: &hir::Generics, msg| {
err.span_suggestion(
generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
&format!("consider further restricting {}", msg),
format!(
"{} {} ",
if !generics.where_clause.predicates.is_empty() {
","
} else {
" where"
},
trait_ref.to_predicate(),
),
Applicability::MachineApplicable,
);
let span = generics.where_clause.span_for_predicates_or_empty_place();
if !span.from_expansion() && span.desugaring_kind().is_none() {
err.span_suggestion(
generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
&format!("consider further restricting {}", msg),
format!(
"{} {} ",
if !generics.where_clause.predicates.is_empty() {
","
} else {
" where"
},
trait_ref.to_predicate(),
),
Applicability::MachineApplicable,
);
}
};

// FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/issues/issue-38821.stderr
Expand Up @@ -2,9 +2,7 @@ error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not sat
--> $DIR/issue-38821.rs:23:17
|
LL | #[derive(Debug, Copy, Clone)]
| ^^^^- help: consider further restricting the associated type: `, <Col as Expression>::SqlType: NotNull`
| |
| the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
| ^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
|
= note: required because of the requirements on the impl of `IntoNullable` for `<Col as Expression>::SqlType`

Expand Down

0 comments on commit 9ed463a

Please sign in to comment.