Skip to content

Commit de5f9bc

Browse files
committed
better error messages on cross-crate eiis
1 parent 1b3c13b commit de5f9bc

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

compiler/rustc_hir_analysis/src/check/compare_eii.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
6868
let mut generics_span = None;
6969
let mut bounds_span = vec![];
7070
let mut where_span = None;
71+
7172
if let Some(declaration_node) = tcx.hir_get_if_local(declaration)
7273
&& let Some(declaration_generics) = declaration_node.generics()
7374
{
@@ -83,11 +84,9 @@ fn check_region_bounds_on_impl_item<'tcx>(
8384
}
8485
}
8586
}
86-
if let Some(declaration_node) = tcx.hir_get_if_local(declaration)
87-
&& let Some(declaration_generics) = declaration_node.generics()
88-
{
87+
if let Some(implementation_generics) = tcx.hir_get_generics(external_impl) {
8988
let mut impl_bounds = 0;
90-
for p in declaration_generics.predicates {
89+
for p in implementation_generics.predicates {
9190
if let hir::WherePredicateKind::BoundPredicate(pred) = p.kind {
9291
for b in pred.bounds {
9392
if let hir::GenericBound::Outlives(_) = b {
@@ -98,8 +97,8 @@ fn check_region_bounds_on_impl_item<'tcx>(
9897
}
9998
if impl_bounds == bounds_span.len() {
10099
bounds_span = vec![];
101-
} else if declaration_generics.has_where_clause_predicates {
102-
where_span = Some(declaration_generics.where_clause_span);
100+
} else if implementation_generics.has_where_clause_predicates {
101+
where_span = Some(implementation_generics.where_clause_span);
103102
}
104103
}
105104
}
@@ -145,7 +144,8 @@ fn compare_number_of_method_arguments<'tcx>(
145144
}
146145
})
147146
})
148-
.or_else(|| tcx.hir_span_if_local(declaration));
147+
.or_else(|| tcx.hir_span_if_local(declaration))
148+
.unwrap_or_else(|| tcx.def_span(declaration));
149149

150150
let (_, external_impl_sig, _, _) = &tcx.hir_expect_item(external_impl).expect_fn();
151151
let pos = external_impl_number_args.saturating_sub(1);
@@ -171,15 +171,12 @@ fn compare_number_of_method_arguments<'tcx>(
171171
declaration_number_args
172172
);
173173

174-
if let Some(declaration_span) = declaration_span {
175-
err.span_label(
176-
declaration_span,
177-
format!(
178-
"requires {}",
179-
potentially_plural_count(declaration_number_args, "parameter")
180-
),
181-
);
182-
}
174+
// if let Some(declaration_span) = declaration_span {
175+
err.span_label(
176+
declaration_span,
177+
format!("requires {}", potentially_plural_count(declaration_number_args, "parameter")),
178+
);
179+
// }
183180

184181
err.span_label(
185182
impl_span,
@@ -395,7 +392,11 @@ fn extract_spans_for_error_reporting<'tcx>(
395392
declaration_args.and_then(|mut args| args.nth(i)),
396393
external_impl_name,
397394
),
398-
_ => (cause.span, tcx.hir_span_if_local(declaration), external_impl_name),
395+
_ => (
396+
cause.span,
397+
tcx.hir_span_if_local(declaration).or_else(|| Some(tcx.def_span(declaration))),
398+
external_impl_name,
399+
),
399400
}
400401
}
401402

tests/ui/eii/cross_crate_wrong_ty.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | #[unsafe(cross_crate_eii_declaration::foo)]
55
| ------------------------------------------- required because of this attribute
66
LL | fn other() -> u64 {
77
| ^^^^^^^^^^^^^^^^^ expected 1 parameter, found 0
8+
|
9+
::: $DIR/auxiliary/cross_crate_eii_declaration.rs:13:5
10+
|
11+
LL | pub safe fn bar(x: u64) -> u64;
12+
| ------------------------------- requires 1 parameter
813

914
error: aborting due to 1 previous error
1015

0 commit comments

Comments
 (0)