Giter Site home page Giter Site logo

Comments (4)

mankinskin avatar mankinskin commented on September 27, 2024 5

It would be even better if the semantics could be less tricky :) Where is the problem with always trying to infer unspecified types and falling back on defaults when they can't be inferred? This is the behaviour I would expect, at least.

from reference.

SilvanCodes avatar SilvanCodes commented on September 27, 2024 2

I would like the first case to work:

struct Foo<T = u8>(T);
    
impl<T: Default> Default for Foo<T> {
    fn default() -> Self {
        Self(Default::default())
    }
}
    
// This breaks with: error[E0282]: type annotations needed for `main::Foo<T>`
let a = Foo::default();

// This works.
let b: Foo = Foo::default();

See it live here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0577801bc59bb19cc6c61039863d130a

from reference.

Havvy avatar Havvy commented on September 27, 2024

You should file an issue against rust-lang/rust about that. The reference just documents what's already there.

from reference.

ehuss avatar ehuss commented on September 27, 2024

See also RFC 213.

And #636.

And https://internals.rust-lang.org/t/interaction-of-user-defined-and-integral-fallbacks-with-inference/2496.

Be sure to mention that Self is not allowed.

from reference.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.