Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 15, 2023
1 parent d7c0bcd commit 0172d15
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {

match self.angle_brackets {
AngleBrackets::Missing => {
let span = self.path_segment.ident.span;
let span = self.tcx.mark_span_for_resize(self.path_segment.ident.span);

// insert a suggestion of the form "Y<'a, 'b>"
let sugg = format!("<{}>", suggested_args);
Expand All @@ -618,6 +618,15 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
let last_lt = &self.gen_args.args[self.num_provided_lifetime_args() - 1];
(self.tcx.mark_span_for_resize(last_lt.span()).shrink_to_hi(), false)
};
let path_sp = self.path_segment.ident.span.peel_ctxt();
if !self.gen_args.args.iter().all(|arg| {
arg.span().can_be_used_for_suggestions()
&& arg.span().peel_ctxt().ctxt() == path_sp.ctxt()
}) || !path_sp.can_be_used_for_suggestions()
{
// Do not suggest syntax when macros are involved. (#90557)
return;
}
let has_non_lt_args = self.num_provided_type_or_const_args() != 0;
let has_bindings = !self.gen_args.bindings.is_empty();

Expand Down Expand Up @@ -647,7 +656,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {

match self.angle_brackets {
AngleBrackets::Missing | AngleBrackets::Implied => {
let span = self.path_segment.ident.span;
let span = self.tcx.mark_span_for_resize(self.path_segment.ident.span);

// insert a suggestion of the form "Y<T, U>"
let sugg = format!("<{}>", suggested_args);
Expand All @@ -661,6 +670,15 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
);
}
AngleBrackets::Available => {
let path_sp = self.path_segment.ident.span.peel_ctxt();
if !self.gen_args.args.iter().all(|arg| {
arg.span().can_be_used_for_suggestions()
&& arg.span().peel_ctxt().ctxt() == path_sp.ctxt()
}) || !path_sp.can_be_used_for_suggestions()
{
// Do not suggest syntax when macros are involved. (#90557)
return;
}
let gen_args_span = self.tcx.mark_span_for_resize(self.gen_args.span().unwrap());
let sugg_offset =
self.get_lifetime_args_offset() + self.num_provided_type_or_const_args();
Expand Down
1 change: 1 addition & 0 deletions tests/ui/lifetimes/missing-lifetime-in-alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ type C<'a, 'b> = <A<'a> as Trait>::Bar;
//~| NOTE expected named lifetime parameter
//~| NOTE these named lifetimes are available to use
//~| NOTE expected 1 lifetime argument
//~| NOTE in this expansion of desugaring of a resized `Span`

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/macros/issue-90557.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
struct Example<T, U> {
foo: T,
bar: U,
}

macro_rules! impl_example {
($($t:ty)+) => {$(
impl Example<$t> { //~ ERROR struct takes 2 generic arguments but 1 generic argument was supplied
fn baz() {
println!(":)");
}
}
)+}
}

impl_example! { u8 }

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/macros/issue-90557.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0107]: struct takes 2 generic arguments but 1 generic argument was supplied
--> $DIR/issue-90557.rs:8:14
|
LL | impl Example<$t> {
| ^^^^^^^ expected 2 generic arguments
...
LL | impl_example! { u8 }
| --------------------
| | |
| | supplied 1 generic argument
| in this macro invocation
|
note: struct defined here, with 2 generic parameters: `T`, `U`
--> $DIR/issue-90557.rs:1:8
|
LL | struct Example<T, U> {
| ^^^^^^^ - -
= note: this error originates in the macro `impl_example` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.

0 comments on commit 0172d15

Please sign in to comment.