-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Great Generics Generalisation: HIR Followup #51880
The Great Generics Generalisation: HIR Followup #51880
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8b45e20
to
f82e51f
Compare
This comment has been minimized.
This comment has been minimized.
src/librustc_typeck/check/mod.rs
Outdated
|
||
if let Some(ref data) = segments[index].args { | ||
let lifetime_offset = if infer_lifetimes[&index] { | ||
defs.own_counts().lifetimes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be taken out of the loop.
5af5a59
to
e72e03d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
e72e03d
to
0d23eef
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
493fcd4
to
0abb1c5
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -25,5 +25,4 @@ fn main() { | |||
//~| ERROR wrong number of type arguments: expected 1, found 0 | |||
let _: S<'static +, 'static>; | |||
//~^ ERROR lifetime parameters must be declared prior to type parameters | |||
//~| ERROR at least one non-builtin trait is required for an object type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this error is displayed currently is very much dependent on the ad-hoc parameter-separation that currently goes on. Unless it causes more issues, I really don't think it's worth attempting to preserve behaviour here.
@eddyb: this is now ready to be reviewed! |
src/librustc_typeck/check/mod.rs
Outdated
}) | ||
.cloned() | ||
.collect(); | ||
AstConv::prohibit_generics(self, &segs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the only use of the variable segs
? You might want to change prohibit_generics
to take an iterator or something. Either way, having a variable here that's not non_generic_segs
is confusing.
Ping from triage, @varkor any update on this PR? |
src/librustc_typeck/astconv.rs
Outdated
// Provide substitutions for parameters for which (valid) arguments have been provided. | ||
|param, arg| { | ||
match param.kind { | ||
GenericParamDefKind::Lifetime => match arg { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
// Provide substitutions for parameters for which (valid) arguments have been provided. | ||
|param, arg| { | ||
match param.kind { | ||
GenericParamDefKind::Lifetime => match arg { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/librustc_typeck/check/mod.rs
Outdated
for &PathSeg(def_id, index) in &path_segs { | ||
let seg = &segments[index]; | ||
let generics = self.tcx.generics_of(def_id); | ||
// `impl Trait` is treated as a normal generic parameter internally, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
if let Some(&PathSeg(_, index)) = path_segs.iter().find(|&PathSeg(did, _)| { | ||
*did == def_id | ||
}) { | ||
// If we've encountered an `impl Trait`-related error, we're just |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/librustc_typeck/check/mod.rs
Outdated
fn_segment.is_some() as usize; | ||
AstConv::prohibit_generics(self, &segments[..segments.len() - poly_segments]); | ||
|
||
let mut generic_segs = HashSet::new(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/librustc_typeck/check/mod.rs
Outdated
} | ||
} | ||
infer_types_type_seg = seg.infer_types; | ||
let mut suppress_errors = FxHashMap(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/librustc_typeck/check/mod.rs
Outdated
}) { | ||
// If we've encountered an `impl Trait`-related error, we're just | ||
// going to infer the arguments for better error messages. | ||
if !suppress_errors[&index] { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/librustc_typeck/check/mod.rs
Outdated
}, | ||
// Provide substitutions for parameters for which (valid) arguments have been provided. | ||
|param, arg| { | ||
match param.kind { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| | ||
LL | let _ = S::new::<isize,f64>(1, 1.0); | ||
| ^^^ expected 1 type parameter | ||
| ^^^^^^^^^^^^^^^^^^^ unexpected type argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this seems to have regressed, could you somehow use each GenericArg
's individual span?
| | ||
LL | let _: S2 = Trait::<'a,isize>::new::<f64>(1, 1.0); | ||
| ^^ expected 0 lifetime parameters | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unexpected lifetime argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar situation here.
Overall I'm really happy with the progress made here! 🎉 |
aa99c17
to
9ba4b1f
Compare
src/librustc_typeck/astconv.rs
Outdated
@@ -255,9 +256,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { | |||
&empty_args | |||
}, | |||
if is_method_call { | |||
GenericArgPosition::Method | |||
GenericArgPosition::Associated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I was wrong, if it's for the method call syntax, i.e. not Trait::method
, then it should called MethodCall
.
9ba4b1f
to
2d3b1b7
Compare
| | ||
LL | fn f<F:Trait(isize) -> isize>(x: F) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ expected no type arguments | ||
| ^^^^^^^^^^^^^^^^ unexpected type argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this span seems wrong, it should end at the )
, I wonder if that's a bug in how T(A) -> R
turns into T<(A,), Output = R>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this one looked a little weird to me, but I thought it was probably due to function syntax issues that weren't related to this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open an issue so we can maybe clean this up in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #53534.
| | ||
LL | let c: Foo<_, usize> = Foo { r: &5 }; | ||
| ^^^^^^^^^^^^^ expected 1 type argument | ||
| ^^^^^ unexpected type argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement!
2d3b1b7
to
aa3b5c5
Compare
b3f9b83
to
ee9bd0f
Compare
@bors r+ p=42 (we don't want this to bitrot) |
📌 Commit ee9bd0f has been approved by |
…=eddyb The Great Generics Generalisation: HIR Followup Addresses the final comments in #48149. r? @eddyb, but there are a few things I have yet to clean up. Making the PR now to more easily see when things break. cc @yodaldevoid
☀️ Test successful - status-appveyor, status-travis |
Addresses the final comments in #48149.
r? @eddyb, but there are a few things I have yet to clean up. Making the PR now to more easily see when things break.
cc @yodaldevoid