Skip to content

non-scalar cast: error message is unclear #31174

Closed
@lygstate

Description

@lygstate
C:\CI-Cor\ks\rust-encoding>cargo build
   Compiling encoding v0.3.0-dev (file:///C:/CI-Cor/ks/rust-encoding)
src\indexes.rs:316:54: 316:63 error: mismatched types:
 expected `T`,
    found `u32`
(expected type parameter,
    found u32) [E0308]
src\indexes.rs:316     let offsetPos = BinarySearch(plane, left, right, codepoint);
                                                                        ^~~~~~~~~
src\indexes.rs:316:54: 316:63 help: run `rustc --explain E0308` to see a detailed explanation
src\indexes.rs:322:37: 322:60 error: non-scalar cast: `T` as `u32`
src\indexes.rs:322     let offset = codepoint as u32 - plane[offsetPos] as u32;
                                                       ^~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
Could not compile `encoding`.

To learn more, run the command again with --verbose.
pub fn indexOfCodePointImpl<T:Ord>(plane: &'static[T], offsets:&[u16], left:usize, right:usize, codepoint: u32) -> u16 {
    let offsetPos = BinarySearch(plane, left, right, codepoint);
    if offsetPos == 0xffff {
        return 0xffff;
    }
    let baseOffset = offsets[offsetPos] as u32;
    let maxOffset = offsets[offsetPos + 1] as u32;
    let offset = codepoint as u32 - plane[offsetPos] as u32;
    let finalOffset = baseOffset + offset as u32;
    if finalOffset >= maxOffset {
        return 0xffff;
    }
    return finalOffset as u16;
}

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions