Skip to content

Commit 9ed463a

Browse files
committed
Do not suggest restriction on spans originating in macros
1 parent 9c525ee commit 9ed463a

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -977,20 +977,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
977977
};
978978

979979
let mut suggest_restriction = |generics: &hir::Generics, msg| {
980-
err.span_suggestion(
981-
generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
982-
&format!("consider further restricting {}", msg),
983-
format!(
984-
"{} {} ",
985-
if !generics.where_clause.predicates.is_empty() {
986-
","
987-
} else {
988-
" where"
989-
},
990-
trait_ref.to_predicate(),
991-
),
992-
Applicability::MachineApplicable,
993-
);
980+
let span = generics.where_clause.span_for_predicates_or_empty_place();
981+
if !span.from_expansion() && span.desugaring_kind().is_none() {
982+
err.span_suggestion(
983+
generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
984+
&format!("consider further restricting {}", msg),
985+
format!(
986+
"{} {} ",
987+
if !generics.where_clause.predicates.is_empty() {
988+
","
989+
} else {
990+
" where"
991+
},
992+
trait_ref.to_predicate(),
993+
),
994+
Applicability::MachineApplicable,
995+
);
996+
}
994997
};
995998

996999
// FIXME: Add check for trait bound that is already present, particularly `?Sized` so we

src/test/ui/issues/issue-38821.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not sat
22
--> $DIR/issue-38821.rs:23:17
33
|
44
LL | #[derive(Debug, Copy, Clone)]
5-
| ^^^^- help: consider further restricting the associated type: `, <Col as Expression>::SqlType: NotNull`
6-
| |
7-
| the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
5+
| ^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
86
|
97
= note: required because of the requirements on the impl of `IntoNullable` for `<Col as Expression>::SqlType`
108

0 commit comments

Comments
 (0)