Skip to content

Better error message for trying to call an associated function as a method. #15843

Closed
@emberian

Description

@emberian

For example:

// module shade.rs
pub trait ShaderParam<L> {
    fn create_link<S: ParameterSink>(&mut S) -> Result<L, ParameterSideError<'static>>;
    fn upload<U: Uploader>(&self, &L, &mut U);
}

// module lib.rs
    pub fn bundle_program<L, T: shade::ShaderParam<L>>(&mut self, prog: ProgramHandle, data: T)
            -> Result<shade::ShaderBundle<L, T>, shade::ParameterLinkError<'static>> {
        self.dispatcher.demand(|res| !res.programs[prog].is_pending());
        let mut sink = match self.dispatcher.resource.programs[prog] {
            Loaded(ref m) => shade::MetaSink::new(m),
            _ => return Err(shade::ErrorBadProgram),
        };
        let link = match data.create_link(&mut sink) {
            Ok(l) => l,
            Err(e) => return Err(shade::ErrorProgramInfo(e)),
        };
        match sink.complete() {
            Ok(_) => Ok(BundleInternal::new(prog, data, link)),
            Err(e) => Err(shade::ErrorShaderParam(e)),
        }
    }

Reports that there is no method create_link, which is accurate, but unhelpful. It could check if there is an associated function of the same name and suggest it instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions