Skip to content

Commit

Permalink
Auto merge of #105579 - matthiaskrgr:rollup-vw5dlqc, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #101648 (Better documentation for env::home_dir()'s broken behaviour)
 - #105283 (Don't call `diagnostic_hir_wf_check` query if we have infer variables)
 - #105369 (Detect spurious ; before assoc fn body)
 - #105472 (Make encode_info_for_trait_item use queries instead of accessing the HIR)
 - #105521 (separate heading from body)
 - #105555 (llvm-wrapper: adapt for LLVM API changes)
 - #105560 (Extend rustdoc hashtag prepended line test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 11, 2022
2 parents bdb07a8 + 427ea68 commit ee6533d
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 18 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ fromRust(LLVMRustCodeModel Model) {
case LLVMRustCodeModel::Large:
return CodeModel::Large;
case LLVMRustCodeModel::None:
#if LLVM_VERSION_LT(16, 0)
return None;
#else
return std::nullopt;
#endif
default:
report_fatal_error("Bad CodeModel.");
}
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ extern "C" LLVMAttributeRef LLVMRustCreateUWTableAttr(LLVMContextRef C, bool Asy
}

extern "C" LLVMAttributeRef LLVMRustCreateAllocSizeAttr(LLVMContextRef C, uint32_t ElementSizeArg) {
return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg, None));
return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg,
#if LLVM_VERSION_LT(16, 0)
None
#else
std::nullopt
#endif
));
}

#if LLVM_VERSION_GE(15, 0)
Expand Down Expand Up @@ -717,7 +723,11 @@ static std::optional<DIFile::ChecksumKind> fromRust(LLVMRustChecksumKind Kind) {
#endif
switch (Kind) {
case LLVMRustChecksumKind::None:
#if LLVM_VERSION_LT(16, 0)
return None;
#else
return std::nullopt;
#endif
case LLVMRustChecksumKind::MD5:
return DIFile::ChecksumKind::CSK_MD5;
case LLVMRustChecksumKind::SHA1:
Expand Down
16 changes: 4 additions & 12 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,24 +1337,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
let tcx = self.tcx;

let ast_item = tcx.hir().expect_trait_item(def_id.expect_local());
self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness);
let impl_defaultness = tcx.impl_defaultness(def_id.expect_local());
self.tables.impl_defaultness.set(def_id.index, impl_defaultness);
let trait_item = tcx.associated_item(def_id);
self.tables.assoc_container.set(def_id.index, trait_item.container);

match trait_item.kind {
ty::AssocKind::Const => {}
ty::AssocKind::Fn => {
let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind else { bug!() };
match *m {
hir::TraitFn::Required(ref names) => {
record_array!(self.tables.fn_arg_names[def_id] <- *names)
}
hir::TraitFn::Provided(body) => {
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body))
}
};
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
record_array!(self.tables.fn_arg_names[def_id] <- tcx.fn_arg_names(def_id));
self.tables.asyncness.set(def_id.index, tcx.asyncness(def_id));
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
}
ty::AssocKind::Type => {
Expand Down
12 changes: 9 additions & 3 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ impl<'a> Parser<'a> {
}
match parse_item(self) {
Ok(None) => {
let is_unnecessary_semicolon = !items.is_empty()
let mut is_unnecessary_semicolon = !items.is_empty()
// When the close delim is `)` in a case like the following, `token.kind` is expected to be `token::CloseDelim(Delimiter::Parenthesis)`,
// but the actual `token.kind` is `token::CloseDelim(Delimiter::Bracket)`.
// but the actual `token.kind` is `token::CloseDelim(Delimiter::Brace)`.
// This is because the `token.kind` of the close delim is treated as the same as
// that of the open delim in `TokenTreesReader::parse_token_tree`, even if the delimiters of them are different.
// Therefore, `token.kind` should not be compared here.
Expand All @@ -727,7 +727,13 @@ impl<'a> Parser<'a> {
.span_to_snippet(self.prev_token.span)
.map_or(false, |snippet| snippet == "}")
&& self.token.kind == token::Semi;
let semicolon_span = self.token.span;
let mut semicolon_span = self.token.span;
if !is_unnecessary_semicolon {
// #105369, Detect spurious `;` before assoc fn body
is_unnecessary_semicolon = self.token == token::OpenDelim(Delimiter::Brace)
&& self.prev_token.kind == token::Semi;
semicolon_span = self.prev_token.span;
}
// We have to bail or we'll potentially never make progress.
let non_item_span = self.token.span;
let is_let = self.token.is_keyword(kw::Let);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,8 @@ impl fmt::Display for Ident {
}
}

/// This is the most general way to print identifiers.
/// The most general type to print identifiers.
///
/// AST pretty-printer is used as a fallback for turning AST structures into token streams for
/// proc macros. Additionally, proc macros may stringify their input and expect it survive the
/// stringification (especially true for proc macro derives written between Rust 1.15 and 1.30).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// can get a better error message by performing HIR-based well-formedness checking.
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
root_obligation.cause.code().peel_derives()
&& !obligation.predicate.has_non_region_infer()
{
if let Some(cause) = self
.tcx
Expand Down
9 changes: 8 additions & 1 deletion library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,13 @@ impl Error for JoinPathsError {
///
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectorya
///
/// # Deprecation
///
/// This function is deprecated because the behaviour on Windows is not correct.
/// The 'HOME' environment variable is not standard on Windows, and may not produce
/// desired results; for instance, under Cygwin or Mingw it will return `/home/you`
/// when it should return `C:\Users\you`.
///
/// # Examples
///
/// ```
Expand All @@ -582,7 +589,7 @@ impl Error for JoinPathsError {
/// ```
#[deprecated(
since = "1.29.0",
note = "This function's behavior is unexpected and probably not what you want. \
note = "This function's behavior may be unexpected on Windows. \
Consider using a crate from crates.io instead."
)]
#[must_use]
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/html/markdown/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ fn test_ascii_with_prepending_hashtag() {
#..#.#....#....#....#..#.
#..#.#....#....#....#..#.
#..#.####.####.####..##..
</code></pre></div>",
);
t(
r#"```markdown
# hello
```"#,
"<div class=\"example-wrap\"><pre class=\"language-markdown\"><code>\
# hello
</code></pre></div>",
);
}
22 changes: 22 additions & 0 deletions src/test/ui/suggestions/issue-105226.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::fmt;

struct S {
}

impl S {
fn hello<P>(&self, val: &P) where P: fmt::Display; {
//~^ ERROR non-item in item list
//~| ERROR associated function in `impl` without body
println!("val: {}", val);
}
}

impl S {
fn hello_empty<P>(&self, val: &P) where P: fmt::Display;
//~^ ERROR associated function in `impl` without body
}

fn main() {
let s = S{};
s.hello(&32);
}
31 changes: 31 additions & 0 deletions src/test/ui/suggestions/issue-105226.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error: non-item in item list
--> $DIR/issue-105226.rs:7:56
|
LL | impl S {
| - item list starts here
LL | fn hello<P>(&self, val: &P) where P: fmt::Display; {
| - ^ non-item starts here
| |
| help: consider removing this semicolon
...
LL | }
| - item list ends here

error: associated function in `impl` without body
--> $DIR/issue-105226.rs:7:5
|
LL | fn hello<P>(&self, val: &P) where P: fmt::Display; {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: provide a definition for the function: `{ <body> }`

error: associated function in `impl` without body
--> $DIR/issue-105226.rs:15:5
|
LL | fn hello_empty<P>(&self, val: &P) where P: fmt::Display;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: provide a definition for the function: `{ <body> }`

error: aborting due to 3 previous errors

18 changes: 18 additions & 0 deletions src/test/ui/wf/hir-wf-canonicalized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// incremental

trait Foo {
type V;
}

trait Callback<T: Foo>: Fn(&Bar<'_, T>, &T::V) {}

struct Bar<'a, T> {
callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
//~^ ERROR the trait bound `Bar<'a, T>: Foo` is not satisfied
//~| ERROR the trait bound `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static): Foo` is not satisfied
//~| ERROR the size for values of type `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)` cannot be known at compilation time
}

impl<T: Foo> Bar<'_, Bar<'_, T>> {}

fn main() {}
32 changes: 32 additions & 0 deletions src/test/ui/wf/hir-wf-canonicalized.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0277]: the trait bound `Bar<'a, T>: Foo` is not satisfied
--> $DIR/hir-wf-canonicalized.rs:10:15
|
LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<'a, T>`

error[E0277]: the trait bound `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static): Foo` is not satisfied
--> $DIR/hir-wf-canonicalized.rs:10:15
|
LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)`

error[E0277]: the size for values of type `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)` cannot be known at compilation time
--> $DIR/hir-wf-canonicalized.rs:10:15
|
LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)`
note: required by a bound in `Bar`
--> $DIR/hir-wf-canonicalized.rs:9:16
|
LL | struct Bar<'a, T> {
| ^ required by this bound in `Bar`
help: consider relaxing the implicit `Sized` restriction
|
LL | struct Bar<'a, T: ?Sized> {
| ++++++++

error: aborting due to 3 previous errors

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

0 comments on commit ee6533d

Please sign in to comment.