8

Add `Convert match to let-else` assist by unexge · Pull Request #13516 · rust-la...

 1 year ago
source link: https://github.com/rust-lang/rust-analyzer/pull/13516
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
@@ -333,6 +333,8 @@ pub struct InferenceResult {

assoc_resolutions: FxHashMap<ExprOrPatId, AssocItemId>,

pub diagnostics: Vec<InferenceDiagnostic>,

pub type_of_expr: ArenaMap<ExprId, Ty>,

/// For each match expr, record diverging arm's expr.

pub diverging_arms: FxHashMap<ExprId, Vec<ExprId>>,

Contributor

Author

@unexge unexge Oct 29, 2022

I've tried to get diverging arms by looking types of arm expressions via hir::semantics::Semantics::type_of_expr but we coerce all match arm expressions and the whole match expression to the Never type when we encounter any diverging arm, so I couldn't find a way to distinguish diverging and non-diverging arms without recording this information.

All reactions

Does it help if you look at the unadjusted type? In an expression like

    match Some(0) {
        Some(_) => {}
        None => return
    }

return has type ! but is adjusted to (), so the unadjusted type should provide the information you need

All reactions

Ah, I found the issue – your tests use Option but don't declare it. I'll push a fix.

All reactions

Contributor

Author

@unexge unexge Nov 1, 2022

ohh sweat_smile great! Thanks for the fix.

All reactions

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK