Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add const qualifier in FnSig (for const fn pointers) #74553

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
Add coercion unsafe
  • Loading branch information
filtsin committed Oct 14, 2020
commit be46b44283c1936e4cbdc1dd1c346116af4e3c98
8 changes: 4 additions & 4 deletions compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
new_sig = self.tcx.signature_not_const_fn(prev_sig);
new_drop_const = true;
}
if prev_sig.unsafety() != new_sig.unsafety() {
prev_sig = prev_sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig });
new_sig = new_sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig });
}
}
if prev_sig.unsafety() != new_sig.unsafety() {
prev_sig = prev_sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig });
new_sig = new_sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig });
Comment on lines +998 to +1000
Copy link
Author

@filtsin filtsin Oct 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this code that compiles on stable:

const fn foo() { }
const fn bar() { }
fn baz() { }


fn main() {
    let x: unsafe fn() = match 2 {
        2 => bar,
        3 => foo,
        _ => baz
    };

}

This code compiles with these changes:

const unsafe fn foo() { }
const fn bar() { }
fn baz() { }


fn main() {
    let x = match 2 {
        2 => bar,
        3 => foo,
        _ => baz
    };

}

but not in stable

}
(Some(prev_sig), Some(new_sig))
}
Expand Down