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 10 pull requests #75474

Closed
wants to merge 39 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
165a6e5
Fix wasi::fs::OpenOptions to imply write when append is on
kawamuray Aug 5, 2020
8a4fecb
Fix some Clippy warnings in librustc_serialize
hirrolot Aug 5, 2020
5b8e177
Create lang item array and add map fn
JulianKnodt Aug 6, 2020
3a5fe37
Add drop guard
JulianKnodt Aug 6, 2020
1d768db
Add Array Impl Lang Item in various places
JulianKnodt Aug 6, 2020
2183237
Swap order of forget
JulianKnodt Aug 6, 2020
946233c
Add recommend changes to array
JulianKnodt Aug 6, 2020
94ec272
Update w/ pickfire's review
JulianKnodt Aug 7, 2020
664e456
Add suggestions from lcnr
JulianKnodt Aug 7, 2020
b7c33ac
Add tracking issue #75243
JulianKnodt Aug 7, 2020
751bdb8
Add note & example about iter order
JulianKnodt Aug 7, 2020
bac7182
Add doc changes
JulianKnodt Aug 7, 2020
43c76d1
Update doc comments
JulianKnodt Aug 7, 2020
48733b4
Rm hiding feature gate & add 1 more example
JulianKnodt Aug 8, 2020
cd5654e
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi
Aug 2, 2020
92ac60d
Update order docs for `map`
JulianKnodt Aug 11, 2020
709d105
Fix minor things in the `f32` primitive docs
LukasKalbertodt Aug 11, 2020
0f7205f
Fix suggestion to use lifetime in type
estebank Aug 10, 2020
7956b1c
Assoc `const`s don't have generics
estebank Aug 10, 2020
b9585fd
When suggesting `for` lts, consider existing lifetime names
estebank Aug 10, 2020
becd479
review comment: simplify code by using slice pat
estebank Aug 11, 2020
6a3deb0
Suggest using `'static` in assoc consts and suggest when multiple lts…
estebank Aug 11, 2020
7291c6d
Update cargo
ehuss Aug 11, 2020
1902983
Move forge platform-support to the rustc book.
ehuss Aug 11, 2020
392116e
Platform Support page updates.
ehuss Aug 11, 2020
ffda53f
merge `as_local_hir_id` with `local_def_id_to_hir_id`
lcnr Aug 12, 2020
0d6ff99
add regression test for #74739 (mir const-prop bug)
RalfJung Aug 12, 2020
ce71747
Add a script to verify the Platform Support page is up-to-date.
ehuss Aug 11, 2020
8e3e270
Add drop check test & MaybeUninit::first_ptr_mut
JulianKnodt Aug 11, 2020
29f508e
Rollup merge of #75115 - chansuke:sys-cloudabi-unsafe, r=KodrAus
Dylan-DPC Aug 13, 2020
bdde294
Rollup merge of #75189 - kawamuray:bugfix-wasi-append, r=KodrAus
Dylan-DPC Aug 13, 2020
0b08283
Rollup merge of #75201 - Hirrolot:hirrolot/fix-clippy-warnings, r=varkor
Dylan-DPC Aug 13, 2020
52995c6
Rollup merge of #75212 - JulianKnodt:array_map, r=LukasKalbertodt
Dylan-DPC Aug 13, 2020
a025fc3
Rollup merge of #75372 - estebank:lt-sugg-in-type, r=lcnr
Dylan-DPC Aug 13, 2020
757d85f
Rollup merge of #75400 - LukasKalbertodt:fix-f32-docs, r=KodrAus
Dylan-DPC Aug 13, 2020
b89f252
Rollup merge of #75426 - ehuss:update-cargo, r=ehuss
Dylan-DPC Aug 13, 2020
2013e11
Rollup merge of #75431 - ehuss:platform-support, r=Mark-Simulacrum
Dylan-DPC Aug 13, 2020
8cb3a0e
Rollup merge of #75448 - lcnr:rn-as_local_hir_id, r=davidtwco
Dylan-DPC Aug 13, 2020
efc4776
Rollup merge of #75449 - RalfJung:const-prop-test, r=wesleywiser
Dylan-DPC Aug 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Suggest using 'static in assoc consts and suggest when multiple lts…
… are needed
estebank committed Aug 11, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 6a3deb0ae04c4cb6400b30fecd1cbbee0506348b
54 changes: 51 additions & 3 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ enum AssocSuggestion {
crate enum MissingLifetimeSpot<'tcx> {
Generics(&'tcx hir::Generics<'tcx>),
HigherRanked { span: Span, span_type: ForLifetimeSpanType },
Static,
}

crate enum ForLifetimeSpanType {
@@ -1186,6 +1187,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
https://doc.rust-lang.org/nomicon/hrtb.html",
);
}
_ => {}
}
}
if nightly_options::is_nightly_build()
@@ -1358,6 +1360,42 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
);
(*span, span_type.suggestion("'a"))
}
MissingLifetimeSpot::Static => {
let (span, sugg) = match snippet.as_deref() {
Some("&") => (span.shrink_to_hi(), "'static ".to_owned()),
Some("'_") => (span, "'static".to_owned()),
Some(snippet) if !snippet.ends_with('>') => {
if snippet == "" {
(
span,
std::iter::repeat("'static")
.take(count)
.collect::<Vec<_>>()
.join(", "),
)
} else {
(
span.shrink_to_hi(),
format!(
"<{}>",
std::iter::repeat("'static")
.take(count)
.collect::<Vec<_>>()
.join(", ")
),
)
}
}
_ => continue,
};
err.span_suggestion_verbose(
span,
"consider using the `'static` lifetime",
sugg.to_string(),
Applicability::MaybeIncorrect,
);
continue;
}
});
for param in params {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span) {
@@ -1408,13 +1446,23 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
([], Some("'_")) if count == 1 => {
suggest_new(err, "'a");
}
([], Some(snippet)) if !snippet.ends_with('>') && count == 1 => {
([], Some(snippet)) if !snippet.ends_with('>') => {
if snippet == "" {
// This happens when we have `type Bar<'a> = Foo<T>` where we point at the space
// before `T`. We will suggest `type Bar<'a> = Foo<'a, T>`.
suggest_new(err, "'a, ");
suggest_new(
err,
&std::iter::repeat("'a, ").take(count).collect::<Vec<_>>().join(""),
);
} else {
suggest_new(err, &format!("{}<'a>", snippet));
suggest_new(
err,
&format!(
"{}<{}>",
snippet,
std::iter::repeat("'a").take(count).collect::<Vec<_>>().join(", ")
),
);
}
}
(lts, ..) if lts.len() > 1 => {
12 changes: 9 additions & 3 deletions src/librustc_resolve/late/lifetimes.rs
Original file line number Diff line number Diff line change
@@ -764,26 +764,30 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
Const(_, _) => {
// Only methods and types support generics.
assert!(trait_item.generics.params.is_empty());
self.missing_named_lifetime_spots.push(MissingLifetimeSpot::Static);
intravisit::walk_trait_item(self, trait_item);
self.missing_named_lifetime_spots.pop();
}
}
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
use self::hir::ImplItemKind::*;
self.missing_named_lifetime_spots.push((&impl_item.generics).into());
match impl_item.kind {
Fn(ref sig, _) => {
self.missing_named_lifetime_spots.push((&impl_item.generics).into());
let tcx = self.tcx;
self.visit_early_late(
Some(tcx.hir().get_parent_item(impl_item.hir_id)),
&sig.decl,
&impl_item.generics,
|this| intravisit::walk_impl_item(this, impl_item),
)
);
self.missing_named_lifetime_spots.pop();
}
TyAlias(ref ty) => {
let generics = &impl_item.generics;
self.missing_named_lifetime_spots.push(generics.into());
let mut index = self.next_early_index();
let mut non_lifetime_count = 0;
debug!("visit_ty: index = {}", index);
@@ -812,14 +816,16 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
this.visit_generics(generics);
this.visit_ty(ty);
});
self.missing_named_lifetime_spots.pop();
}
Const(_, _) => {
// Only methods and types support generics.
assert!(impl_item.generics.params.is_empty());
self.missing_named_lifetime_spots.push(MissingLifetimeSpot::Static);
intravisit::walk_impl_item(self, impl_item);
self.missing_named_lifetime_spots.pop();
}
}
self.missing_named_lifetime_spots.pop();
}

fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
9 changes: 9 additions & 0 deletions src/test/ui/error-codes/E0106.stderr
Original file line number Diff line number Diff line change
@@ -51,6 +51,15 @@ error[E0106]: missing lifetime specifiers
|
LL | buzz: Buzz,
| ^^^^ expected 2 lifetime parameters
|
help: consider introducing a named lifetime parameter
|
LL | struct Quux<'a> {
LL | baz: Baz,
LL |
LL |
LL | buzz: Buzz<'a, 'a>,
|

error: aborting due to 5 previous errors

13 changes: 12 additions & 1 deletion src/test/ui/suggestions/missing-lifetime-in-assoc-const-type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
trait ZstAssert: Sized {
const TYPE_NAME: &str = ""; //~ ERROR missing lifetime specifier
const A: &str = ""; //~ ERROR missing lifetime specifier
const B: S = S { s: &() }; //~ ERROR missing lifetime specifier
const C: &'_ str = ""; //~ ERROR missing lifetime specifier
const D: T = T { a: &(), b: &() }; //~ ERROR missing lifetime specifier
}

struct S<'a> {
s: &'a (),
}
struct T<'a, 'b> {
a: &'a (),
b: &'b (),
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,15 +1,73 @@
error[E0106]: missing lifetime specifier
--> $DIR/missing-lifetime-in-assoc-const-type.rs:2:22
--> $DIR/missing-lifetime-in-assoc-const-type.rs:2:14
|
LL | const TYPE_NAME: &str = "";
| ^ expected named lifetime parameter
LL | const A: &str = "";
| ^ expected named lifetime parameter
|
help: consider using the `'static` lifetime
|
LL | const A: &'static str = "";
| ^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const A: &'a str = "";
|

error[E0106]: missing lifetime specifier
--> $DIR/missing-lifetime-in-assoc-const-type.rs:3:14
|
LL | const B: S = S { s: &() };
| ^ expected named lifetime parameter
|
help: consider using the `'static` lifetime
|
LL | const B: S<'static> = S { s: &() };
| ^^^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const A: &str = "";
LL | const B: S<'a> = S { s: &() };
|

error[E0106]: missing lifetime specifier
--> $DIR/missing-lifetime-in-assoc-const-type.rs:4:15
|
LL | const C: &'_ str = "";
| ^^ expected named lifetime parameter
|
help: consider using the `'static` lifetime
|
LL | const C: &'static str = "";
| ^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const A: &str = "";
LL | const B: S = S { s: &() };
LL | const C: &'a str = "";
|

error[E0106]: missing lifetime specifiers
--> $DIR/missing-lifetime-in-assoc-const-type.rs:5:14
|
LL | const D: T = T { a: &(), b: &() };
| ^ expected 2 lifetime parameters
|
help: consider using the `'static` lifetime
|
LL | const D: T<'static, 'static> = T { a: &(), b: &() };
| ^^^^^^^^^^^^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const TYPE_NAME: &'a str = "";
LL | const A: &str = "";
LL | const B: S = S { s: &() };
LL | const C: &'_ str = "";
LL | const D: T<'a, 'a> = T { a: &(), b: &() };
|

error: aborting due to previous error
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0106`.