Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `invalid_type_param_default` compatibility lint #36887
Comments
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis, could you write a description for this? |
This was referenced Oct 5, 2016
steveklabnik
added
the
A-lint
label
Oct 7, 2016
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov done. |
nrc
added
I-nominated
T-lang
and removed
I-nominated
T-lang
labels
Nov 17, 2016
This comment has been minimized.
This comment has been minimized.
|
Where can I find discussion of this issue? I don't see any on RFC 213, nor its tracking issue (#27336). |
This comment has been minimized.
This comment has been minimized.
|
@nrc perhaps I should have phrased the summary with slightly differently. I think the main thing is that defaults were being accepted in stable code but ignored, unless you opt in to a feature gate, which gives them some semantics (but semantics that I now think I disagree with). |
frewsxcv
referenced this issue
Dec 3, 2016
Closed
Proof of concept: parameterized node traversal methods. #14451
eddyb
referenced this issue
Jan 3, 2017
Closed
Type parameter defaults are not checked correctly #26633
brson
added
the
B-unstable
label
Mar 1, 2017
This comment has been minimized.
This comment has been minimized.
|
Is there a reason this is being phased out on functions? It's sometimes useful to have |
This comment has been minimized.
This comment has been minimized.
|
@RReverser Yes. Because, IIRC, they are basically ignored on stable Rust. On nightly Rust, meanwhile, we were considering various possible meanings, but have not yet found one that we are satisfied with. |
This comment has been minimized.
This comment has been minimized.
|
Ok, I'm now curious... where can I read about other possible meanings? The expectation seems pretty straightforward, just like in case with |
petrochenkov
referenced this issue
May 21, 2017
Merged
Turn sufficiently old compatibility lints into hard errors #42136
bors
added a commit
that referenced
this issue
Jun 1, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Jun 1, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm also curious as to what the issue is for default type arguments in generic functions. I'm running into a case where it would greatly help ergonomics of using a function with an optional generic parameter: https://is.gd/Gy9bXW |
Mark-Simulacrum
added
the
C-future-compatibility
label
Jun 24, 2017
Mark-Simulacrum
added
C-tracking-issue
and removed
C-tracking-issue
labels
Jul 22, 2017
Enet4
referenced this issue
Oct 6, 2017
Closed
Improve to_ndarray with better dimensionality awareness #2
This comment has been minimized.
This comment has been minimized.
|
I think this feature is very useful for API evolution e.g. when you add a generic type parameter and want to keep stability, and I think much better than inferring the type instead. Apparently there are some issues with the implementation. Can they maybe be fixed instead of removing the feature? Would that require an RFC? |
This comment has been minimized.
This comment has been minimized.
|
I think I see what the difficulty is. Bear with me:
So, yes, this is exactly how it works for types and traits, and it is exactly what we don't want for functions. Let's look at @randomPoison's example. Here's what we would love to be able to write, correct? fn main() {
let _ = foo(Some("I'm a string"));
let _ = foo(None); // ERROR: type annotation needed
}
pub fn foo<S = String>(opt: Option<S>) -> String
where S: Into<String>
{
opt.map(Into::into).unwrap_or_default()
}Okay, now, let's assume generic type parameters for functions worked just like those for types. Turns out this code still wouldn't compile. Why? Because it would be equivalent to this: fn main() {
// nothing was specified, so use the default
let _ = foo::<String>(Some("I'm a string")); // ERROR: &str vs String
// nothing was specified, so use the default
let _ = foo::<String>(None);
}when what we really want is this: fn main() {
// infer the type *if possible*...
let _ = foo::<_>(Some("I'm a string"));
// ...otherwise, use a default
let _ = foo::<String>(None);
}which appears to require a far greater application of pixie dust. |
This comment has been minimized.
This comment has been minimized.
|
@ExpHP Personally I'd rather prefer the explicit default to be used in that example over the contextual inference, although I can see some people wanting the opposite. More common usecase would be where type can't be inferred at all, just like currently used for optional type params in structs like HashMap. |
This comment has been minimized.
This comment has been minimized.
|
@ExpHP That's a good point. I guess what I really wanted was more of a default type hint, i.e. "always try to infer the correct type, and if there's not enough information to infer a type, use the specified type as the default. That's probably a different feature than the one being discussed in this issue, though. |
This comment has been minimized.
This comment has been minimized.
It's not clear how exactly this should be done, and this is the single most important blocker for progress on this issue and all related features (e.g. rust-lang/rfcs#2176). |
This comment has been minimized.
This comment has been minimized.
|
Is there a plan to make this work for generic associated types e.g. in the following code (playground link)? At the moment, this trips the #![feature(generic_associated_types)]
use std::ops::Deref;
trait SomeTrait {
type Assoc<T = i32>: Deref<Target = T>;
}
fn main() {
} |
petrochenkov commentedOct 1, 2016
•
edited
This is the summary issue for the
invalid_type_param_defaultfuture-compatibility warning and other related errors. The goal of
this page is describe why this change was made and how you can fix
code that is affected by it. It also provides a place to ask questions
or register a complaint if you feel the change should not be made. For
more information on the policy around future-compatibility warnings,
see our breaking change policy guidelines.
What is the warning for?
Type parameter defaults outside of type declarations were never intended
to be permitted, but some early versions of Rust did accept them. For
example:
When will this warning become a hard error?
At the beginning of each 6-week release cycle, the Rust compiler team
will review the set of outstanding future compatibility warnings and
nominate some of them for Final Comment Period. Toward the end of
the cycle, we will review any comments and make a final determination
whether to convert the warning into a hard error or remove it
entirely.
Current status
invalid_type_param_defaultlint as warn-by-defaultinvalid_type_param_defaultlint deny-by-defaultinvalid_type_param_defaultlint a hard error, but there was still too much breakageinvalid_type_param_defaultlint a hard error