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

Rollup of 5 pull requests #59602

Closed
wants to merge 13 commits into from
Closed
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ clone_depth: 2
build: false

install:
# Print which AppVeyor agent version we're running on.
- appveyor version
# If we need to download a custom MinGW, do so here and set the path
# appropriately.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Error Reporting for Anonymous Region Lifetime Errors
//! where one region is named and the other is anonymous.
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::hir::{FunctionRetTy, TyKind};
use crate::ty;
use errors::{Applicability, DiagnosticBuilder};

Expand All @@ -11,9 +12,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
let (span, sub, sup) = self.get_regions();

debug!(
"try_report_named_anon_conflict(sub={:?}, sup={:?})",
"try_report_named_anon_conflict(sub={:?}, sup={:?}, error={:?})",
sub,
sup
sup,
self.error,
);

// Determine whether the sub and sup consist of one named region ('a)
Expand Down Expand Up @@ -84,6 +86,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
{
return None;
}
if let FunctionRetTy::Return(ty) = &fndecl.output {
if let (TyKind::Def(_, _), ty::ReStatic) = (&ty.node, sub) {
// This is an impl Trait return that evaluates de need of 'static.
// We handle this case better in `static_impl_trait`.
return None;
}
}
}

let (error_var, span_label_var) = if let Some(simple_ident) = arg.pat.simple_ident() {
Expand All @@ -103,13 +112,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
error_var
);

diag.span_label(span, format!("lifetime `{}` required", named));
diag.span_suggestion(
new_ty_span,
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
new_ty.to_string(),
Applicability::Unspecified,
)
.span_label(span, format!("lifetime `{}` required", named));
new_ty_span,
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
new_ty.to_string(),
Applicability::Unspecified,
);

Some(diag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}
});
if let Some(i) = best_choice {
if let Some(next) = categorized_path.get(i + 1) {
if categorized_path[i].0 == ConstraintCategory::Return
&& next.0 == ConstraintCategory::OpaqueType
{
// The return expression is being influenced by the return type being
// impl Trait, point at the return type and not the return expr.
return *next;
}
}
return categorized_path[i];
}

Expand Down Expand Up @@ -240,6 +249,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
self.provides_universal_region(r, fr, outlived_fr)
});

debug!("report_error: category={:?} {:?}", category, span);
// Check if we can use one of the "nice region errors".
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
let tables = infcx.tcx.typeck_tables_of(mir_def_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl<'a, 'mir, 'tcx> Eq for EvalSnapshot<'a, 'mir, 'tcx>
impl<'a, 'mir, 'tcx> PartialEq for EvalSnapshot<'a, 'mir, 'tcx>
{
fn eq(&self, other: &Self) -> bool {
// FIXME: This looks to be a *ridicolously expensive* comparison operation.
// FIXME: This looks to be a *ridiculously expensive* comparison operation.
// Doesn't this make tons of copies? Either `snapshot` is very badly named,
// or it does!
self.snapshot() == other.snapshot()
Expand Down
16 changes: 16 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6722,6 +6722,22 @@ impl<'a> Parser<'a> {
self.expect(&token::OpenDelim(token::Brace))?;
let mut trait_items = vec![];
while !self.eat(&token::CloseDelim(token::Brace)) {
if let token::DocComment(_) = self.token {
if self.look_ahead(1,
|tok| tok == &token::Token::CloseDelim(token::Brace)) {
let mut err = self.diagnostic().struct_span_err_with_code(
self.span,
"found a documentation comment that doesn't document anything",
DiagnosticId::Error("E0584".into()),
);
err.help("doc comments must come before what they document, maybe a \
comment was intended with `//`?",
);
err.emit();
self.bump();
continue;
}
}
let mut at_end = false;
match self.parse_trait_item(&mut at_end) {
Ok(item) => trait_items.push(item),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

fn elided(x: &i32) -> impl Copy { x }
//~^ ERROR explicit lifetime required in the type of `x` [E0621]
//~^ ERROR cannot infer an appropriate lifetime

fn explicit<'a>(x: &'a i32) -> impl Copy { x }
//~^ ERROR cannot infer an appropriate lifetime
Expand Down
22 changes: 16 additions & 6 deletions src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/must_outlive_least_region_or_bound.rs:3:23
error: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:3:35
|
LL | fn elided(x: &i32) -> impl Copy { x }
| ---- ^^^^^^^^^ lifetime `'static` required
| |
| help: add explicit lifetime `'static` to the type of `x`: `&'static i32`
| --------- ^ ...but this borrow...
| |
| this return type evaluates to the `'static` lifetime...
|
note: ...can't outlive the anonymous lifetime #1 defined on the function body at 3:1
--> $DIR/must_outlive_least_region_or_bound.rs:3:1
|
LL | fn elided(x: &i32) -> impl Copy { x }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ^^^^^^^^^^^^^^

error: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:6:44
Expand Down Expand Up @@ -67,5 +77,5 @@ LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {

error: aborting due to 5 previous errors

Some errors occurred: E0310, E0621, E0623.
Some errors occurred: E0310, E0623.
For more information about an error, try `rustc --explain E0310`.
2 changes: 1 addition & 1 deletion src/test/ui/nll/ty-outlives/impl-trait-captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ trait Foo<'a> {
impl<'a, T> Foo<'a> for T { }

fn foo<'a, T>(x: &T) -> impl Foo<'a> {
//~^ ERROR explicit lifetime required in the type of `x` [E0621]
x
//~^ ERROR explicit lifetime required in the type of `x` [E0621]
}

fn main() {}
6 changes: 3 additions & 3 deletions src/test/ui/nll/ty-outlives/impl-trait-captures.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/impl-trait-captures.rs:11:5
--> $DIR/impl-trait-captures.rs:10:25
|
LL | x
| ^ lifetime `ReEarlyBound(0, 'a)` required
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
| ^^^^^^^^^^^^ lifetime `ReEarlyBound(0, 'a)` required
help: add explicit lifetime `ReEarlyBound(0, 'a)` to the type of `x`
|
LL | fn foo<'a, T>(x: &ReEarlyBound(0, 'a) T) -> impl Foo<'a> {
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/parser/doc-inside-trait-item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait User{
fn test();
/// empty doc
//~^ ERROR found a documentation comment that doesn't document anything
}
fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/parser/doc-inside-trait-item.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0584]: found a documentation comment that doesn't document anything
--> $DIR/doc-inside-trait-item.rs:3:5
|
LL | /// empty doc
| ^^^^^^^^^^^^^
|
= help: doc comments must come before what they document, maybe a comment was intended with `//`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0584`.
2 changes: 1 addition & 1 deletion src/tools/cargotest/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TEST_REPOS: &'static [Test] = &[
},
Test {
name: "tokei",
repo: "https://github.com/Aaronepower/tokei",
repo: "https://github.com/XAMPPRocky/tokei",
sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
lock: None,
packages: &[],
Expand Down