Repository: rust
Issue: Documentation targeting nothing emits unrelated errors
Labels: A-diagnostics,T-compiler,D-verbose

Given the following code: <!-- Please provide a link to play.rust-lang.org -->

[doc-issue.zip](https://github.com/rust-lang/rust/files/10210214/doc-issue.zip)


The current output is:

```
error[E0585]: found a documentation comment that doesn't document anything
   --> src/output.rs:111:9
    |
111 |         /// Hello world
    |         ^^^^^^^^^^^^^^^
    |
    = help: doc comments must come before what they document, maybe a comment was intended with `//`?

error[E0432]: unresolved import `aws_smithy_types::error::display`
 --> src/types.rs:5:34
  |
5 | pub use aws_smithy_types::error::display::DisplayErrorContext;
  |                                  ^^^^^^^ could not find `display` in `error`

error[E0433]: failed to resolve: could not find `IntoMakeServiceWithConnectInfo` in `routing`
    --> src/service.rs:2298:42
     |
2298 |         aws_smithy_http_server::routing::IntoMakeServiceWithConnectInfo::new(self)
     |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `IntoMakeServiceWithConnectInfo` in `routing`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1154:49
     |
1154 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1164:49
     |
1164 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1174:49
     |
1174 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1184:49
     |
1184 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1197:49
     |
1197 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1210:49
     |
1210 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1220:60
     |
1220 | ) -> Result<std::vec::Vec<u8>, aws_smithy_http::operation::error::BuildError> {
     |                                                            ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1230:49
     |
1230 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1240:49
     |
1240 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1250:49
     |
1250 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1260:49
     |
1260 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1270:49
     |
1270 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1280:49
     |
1280 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1290:49
     |
1290 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1300:49
     |
1300 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1310:49
     |
1310 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1320:49
     |
1320 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1330:49
     |
1330 | ) -> Result<String, aws_smithy_http::operation::error::SerializationError> {
     |                                                 ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1340:83
     |
1340 | ) -> Result<aws_smithy_http::byte_stream::ByteStream, aws_smithy_http::operation::error::BuildError>
     |                                                                                   ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
    --> src/operation_ser.rs:1347:73
     |
1347 | ) -> std::result::Result<std::vec::Vec<u8>, aws_smithy_http::operation::error::SerializationError> {
     |                                                                         ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
   --> src/http_serde.rs:262:79
    |
262 | ) -> std::result::Result<http::response::Builder, aws_smithy_http::operation::error::BuildError> {
    |                                                                               ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `error` in `operation`
   --> src/http_serde.rs:500:79
    |
500 | ) -> std::result::Result<http::response::Builder, aws_smithy_http::operation::error::BuildError> {
    |                                                                               ^^^^^ could not find `error` in `operation`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
  --> src/json_deser.rs:38:58
   |
38 |                     aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
   |                                                          ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
  --> src/json_deser.rs:48:50
   |
48 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
   |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
  --> src/json_deser.rs:85:58
   |
85 |                     aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
   |                                                          ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
  --> src/json_deser.rs:95:50
   |
95 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
   |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:150:66
    |
150 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
    |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:161:50
    |
161 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:210:50
    |
210 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:606:66
    |
606 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
    |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:617:50
    |
617 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:637:54
    |
637 |                 aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                      ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:643:50
    |
643 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:682:58
    |
682 |                     aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
    |                                                          ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:692:50
    |
692 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:735:66
    |
735 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
    |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:746:50
    |
746 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:822:66
    |
822 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
    |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:833:50
    |
833 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:881:50
    |
881 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:926:50
    |
926 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:968:66
    |
968 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
    |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
   --> src/json_deser.rs:981:50
    |
981 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
    |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1009:66
     |
1009 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
     |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1020:50
     |
1020 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
     |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1050:66
     |
1050 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(
     |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1063:89
     |
1063 | ...   .ok_or_else(|| aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'enumString' cannot be null"))?
     |                                                           ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1079:89
     |
1079 | ...   .ok_or_else(|| aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'constrainedStructure' cannot be null"))?
     |                                                           ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1085:89
     |
1085 | ...                   .ok_or_else(|| aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'conBList' cannot be null"))?
     |                                                                           ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1091:89
     |
1091 | ...                   .ok_or_else(|| aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'conBMap' cannot be null"))?
     |                                                                           ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1094:88
     |
1094 | ...   variant => return Err(aws_smithy_json::deserialize::error::DeserializeError::custom(format!("unexpected union variant: {}", variant)))
     |                                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1099:62
     |
1099 |                         aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
     |                                                              ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1109:54
     |
1109 |                 aws_smithy_json::deserialize::error::DeserializeError::custom(
     |                                                      ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1160:50
     |
1160 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
     |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1204:66
     |
1204 | ...                   aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
     |                                                            ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`

error[E0433]: failed to resolve: could not find `DeserializeError` in `error`
    --> src/json_deser.rs:1215:50
     |
1215 |             aws_smithy_json::deserialize::error::DeserializeError::custom(
     |                                                  ^^^^^^^^^^^^^^^^ could not find `DeserializeError` in `error`
... many more lines with other errors too
```

<!-- The following is not always necessary. -->
Ideally the output should look like:

```
error[E0585]: found a documentation comment that doesn't document anything
   --> src/output.rs:111:9
    |
111 |         /// Hello world
    |         ^^^^^^^^^^^^^^^
    |
    = help: doc comments must come before what they document, maybe a comment was intended with `//`?
```

If you delete the line 111 in `src/output.rs`, which is the one that contains the `/// Hello world` doc comment that targets nothing, the crate compiles.

```
$ rustc --version                                                                                                                                                                                                                                     
rustc 1.63.0 (4b91a6ea7 2022-08-08)
```
Reproduced also in nightly and beta.