Use proc_macro::Diagnostic instead of panic! in a few places

Thanks to Antoni Boucher for the tips.
3 jobs from master in 8 minutes and 42 seconds (queued for 23 seconds)
Status Job ID Name Coverage
  Test
passed #24662
nightly:test

04:56

 
  Pages
passed #24663
pages

03:46

 
  Deploy
passed pages:deploy

00:01