diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2020-05-19 20:18:39 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2020-05-22 17:38:20 +0100 |
| commit | 187bfb333b6c801eb2a89364b033e9303d88387f (patch) | |
| tree | 264815a5eb7cc621b81749a9c3d1ad0a49c3365a | |
| parent | 33f90f213d4c5495bba988b9d81982d73553096e (diff) | |
| download | rust-187bfb333b6c801eb2a89364b033e9303d88387f.tar.gz rust-187bfb333b6c801eb2a89364b033e9303d88387f.zip | |
Improve the error when an opaque type captures ReEmtpty
| -rw-r--r-- | src/librustc_infer/infer/error_reporting/mod.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index a8d6c01785f..91b8f6d2da4 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -297,7 +297,18 @@ pub fn unexpected_hidden_region_diagnostic( ); // Explain the region we are capturing. - if let ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) = hidden_region { + match hidden_region { + ty::ReEmpty(ty::UniverseIndex::ROOT) => { + // All lifetimes shorter than the function body are `empty` in + // lexical region resolution. The default explanation of "an empty + // lifetime" isn't really accurate here. + let message = format!( + "hidden type `{}` captures lifetime smaller than the function body", + hidden_ty + ); + err.span_note(span, &message); + } + ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) => { // Assuming regionck succeeded (*), we ought to always be // capturing *some* region from the fn header, and hence it // ought to be free. So under normal circumstances, we will go @@ -313,7 +324,8 @@ pub fn unexpected_hidden_region_diagnostic( hidden_region, "", ); - } else { + } + _ => { // Ugh. This is a painful case: the hidden region is not one // that we can easily summarize or explain. This can happen // in a case like @@ -358,6 +370,7 @@ pub fn unexpected_hidden_region_diagnostic( ); } } + } err } |
